From 5a59f896b998e4d993518000cc705bcfbc6d6ba9 Mon Sep 17 00:00:00 2001 From: francisco souza Date: Sun, 1 Mar 2020 23:59:03 -0500 Subject: [PATCH] gobin: make sure GOPATH gets trimmed before use in path.join On Windows, `go env GOPATH` keeps the end-line character, making it unusable (see sample build failure: https://github.com/fsouza/vod-module-sprite/runs/478762225?check_suite_focus=true#step:5:62). --- __tests__/gobin.test.ts | 8 ++++++++ dist/index.js | 2 +- src/gobin.ts | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/__tests__/gobin.test.ts b/__tests__/gobin.test.ts index dc2ee48..336b36f 100644 --- a/__tests__/gobin.test.ts +++ b/__tests__/gobin.test.ts @@ -20,4 +20,12 @@ describe('gobin', () => { const gobinPath = await gobin.getGOBIN('...'); expect(gobinPath).toBe(path.join(gopath, 'bin')); }); + + it('should trim ${GOPATH} before using it', async () => { + let trimmed = gopath; + gopath = `${gopath}\r\n`; + + const gobinPath = await gobin.getGOBIN('...'); + expect(gobinPath).toBe(path.join(trimmed, 'bin')); + }); }); diff --git a/dist/index.js b/dist/index.js index fe283d6..0f27a07 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3280,7 +3280,7 @@ function getGOBIN(installDir) { return __awaiter(this, void 0, void 0, function* () { const goExecutable = path.join(installDir, 'bin', 'go'); const result = yield execFile(goExecutable, ['env', 'GOPATH']); - const gopath = result.stdout; + const gopath = result.stdout.replace(/\s+$/, ''); return path.join(gopath, 'bin'); }); } diff --git a/src/gobin.ts b/src/gobin.ts index 199c878..3677029 100644 --- a/src/gobin.ts +++ b/src/gobin.ts @@ -8,6 +8,6 @@ export async function getGOBIN(installDir: string): Promise { const goExecutable = path.join(installDir, 'bin', 'go'); const result = await execFile(goExecutable, ['env', 'GOPATH']); - const gopath = result.stdout; + const gopath = result.stdout.replace(/\s+$/, ''); return path.join(gopath, 'bin'); }