gobin: use execFile instead of exec to query GOPATH

Should fix the behavior on Windows.
This commit is contained in:
francisco souza 2020-03-01 22:06:59 -05:00
parent 0dbc2e7f12
commit 4241f446d8
No known key found for this signature in database
GPG key ID: 3F6AA3B701F20B3E
3 changed files with 7 additions and 7 deletions

View file

@ -6,12 +6,12 @@ jest.mock('child_process');
describe('gobin', () => { describe('gobin', () => {
const childProcess = require('child_process'); const childProcess = require('child_process');
let execSpy: jest.SpyInstance; let execFileSpy: jest.SpyInstance;
let gopath = path.join('home', 'user', 'go'); let gopath = path.join('home', 'user', 'go');
beforeEach(() => { beforeEach(() => {
execSpy = jest.spyOn(childProcess, 'exec'); execFileSpy = jest.spyOn(childProcess, 'execFile');
execSpy.mockImplementation((_command, callback) => { execFileSpy.mockImplementation((_file, _args, callback) => {
callback('', {stdout: gopath, stderr: ''}); callback('', {stdout: gopath, stderr: ''});
}); });
}); });

4
dist/index.js vendored
View file

@ -3275,11 +3275,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
const childProcess = __importStar(__webpack_require__(129)); const childProcess = __importStar(__webpack_require__(129));
const path = __importStar(__webpack_require__(622)); const path = __importStar(__webpack_require__(622));
const util_1 = __webpack_require__(669); const util_1 = __webpack_require__(669);
const exec = util_1.promisify(childProcess.exec); const execFile = util_1.promisify(childProcess.execFile);
function getGOBIN(installDir) { function getGOBIN(installDir) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const goExecutable = path.join(installDir, 'bin', 'go'); const goExecutable = path.join(installDir, 'bin', 'go');
const result = yield exec(`${goExecutable} env GOPATH`); const result = yield execFile(goExecutable, ['env', 'GOPATH']);
const gopath = result.stdout; const gopath = result.stdout;
return path.join(gopath, 'bin'); return path.join(gopath, 'bin');
}); });

View file

@ -2,12 +2,12 @@ import * as childProcess from 'child_process';
import * as path from 'path'; import * as path from 'path';
import {promisify} from 'util'; import {promisify} from 'util';
const exec = promisify(childProcess.exec); const execFile = promisify(childProcess.execFile);
export async function getGOBIN(installDir: string): Promise<string> { export async function getGOBIN(installDir: string): Promise<string> {
const goExecutable = path.join(installDir, 'bin', 'go'); const goExecutable = path.join(installDir, 'bin', 'go');
const result = await exec(`${goExecutable} env GOPATH`); const result = await execFile(goExecutable, ['env', 'GOPATH']);
const gopath = result.stdout; const gopath = result.stdout;
return path.join(gopath, 'bin'); return path.join(gopath, 'bin');
} }