From e5d59e83e450f881f3247c9b85f2dff9f28da4ea Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 07:42:38 -0700 Subject: [PATCH 01/20] APIGOV-29723 upgrade setup-node github action --- .github/workflows/build.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a67c551..7c09391 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,12 +7,12 @@ jobs: Lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: - node-version: '16.x' + node-version: "16.x" - name: Install dependencies run: yarn - name: Lint @@ -25,13 +25,13 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: [ '14.19.1', '16.14.2', '18.0.0' ] - os: [ macos-latest, ubuntu-latest, windows-latest ] + nodeVersion: ["14.19.1", "16.14.2", "18.0.0"] + os: [macos-latest, ubuntu-latest, windows-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v1 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} - name: Install dependencies @@ -39,4 +39,4 @@ jobs: - name: Run tests run: yarn run test env: - SNOOPLOGG: '*' + SNOOPLOGG: "*" From 7f058056c8f3b32f51ddc10a7916317805762ad9 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 07:49:11 -0700 Subject: [PATCH 02/20] APIGOV-29723 fix --- .github/workflows/build.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7c09391..d61d937 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -26,7 +26,7 @@ jobs: fail-fast: false matrix: nodeVersion: ["14.19.1", "16.14.2", "18.0.0"] - os: [macos-latest, ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 with: @@ -40,3 +40,26 @@ jobs: run: yarn run test env: SNOOPLOGG: "*" + + Test: + needs: Lint + name: ${{ matrix.os }} ${{ matrix.nodeVersion }} Tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + nodeVersion: ["14.19.1", "16.14.2", "18.0.0"] + os: [macos-latest] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.nodeVersion }} + - name: Install dependencies + run: yarn + - name: Run tests + run: yarn run test + env: + SNOOPLOGG: "*" From c2c4b7004085814c96878768ba4272a2b852dc17 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 07:52:08 -0700 Subject: [PATCH 03/20] APIGOV-29723 build.yaml fix --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d61d937..5c63d1c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,7 +41,7 @@ jobs: env: SNOOPLOGG: "*" - Test: + MacOSTest: needs: Lint name: ${{ matrix.os }} ${{ matrix.nodeVersion }} Tests runs-on: ${{ matrix.os }} From 90c0abc6c18a25859adc16e117ba6feb03188cbf Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 08:36:19 -0700 Subject: [PATCH 04/20] APIGOV-29723 fix --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c63d1c..513eea9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.19.1", "16.14.2", "18.0.0"] + nodeVersion: ["14.21.3", "16.14.2", "18.0.0"] os: [macos-latest] steps: - uses: actions/checkout@v2 From fca991e672757c448e02bbf0f1899479f198dc00 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 08:40:41 -0700 Subject: [PATCH 05/20] APIGOV-29723 Fix --- .github/workflows/build.yml | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 513eea9..5dac1e2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,7 +48,30 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.21.3", "16.14.2", "18.0.0"] + nodeVersion: ["16.14.2", "18.0.0"] + os: [macos-latest] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.nodeVersion }} + - name: Install dependencies + run: yarn + - name: Run tests + run: yarn run test + env: + SNOOPLOGG: "*" + + MacOS14Test: + needs: Lint + name: ${{ matrix.os }} ${{ matrix.nodeVersion }} Tests + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + nodeVersion: ["14.x"] os: [macos-latest] steps: - uses: actions/checkout@v2 From 2fe29a68b4c4da92288d7796c72ddde5ff42a8df Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 08:46:09 -0700 Subject: [PATCH 06/20] APIGOV-29723 updates --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5dac1e2..295154c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,13 +71,13 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.x"] + nodeVersion: ["14.21.3"] os: [macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} - name: Install dependencies From 747047dd045885a0337b265e98d8ae7c6acbef5d Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 08:49:43 -0700 Subject: [PATCH 07/20] APIGOV-29723 updates --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 295154c..72c8209 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,7 @@ jobs: fail-fast: false matrix: nodeVersion: ["14.21.3"] - os: [macos-latest] + os: [macos-14-arm64] steps: - uses: actions/checkout@v4 with: From 50fa2b2834d64f2e86346b96119d29777132d17a Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 09:01:05 -0700 Subject: [PATCH 08/20] updates --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 72c8209..e4c049e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,7 @@ jobs: fail-fast: false matrix: nodeVersion: ["14.21.3"] - os: [macos-14-arm64] + os: [macos-latest-arm64] steps: - uses: actions/checkout@v4 with: From bc8d2ce752f4df0a663bdb076efc40afc20c7677 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 09:19:29 -0700 Subject: [PATCH 09/20] updates --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e4c049e..5c235a0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,8 @@ jobs: fail-fast: false matrix: nodeVersion: ["14.21.3"] - os: [macos-latest-arm64] + os: [macos-14-arm64] + arch: arm64 steps: - uses: actions/checkout@v4 with: @@ -80,6 +81,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} + architecture: ${{ matrix.arch }} - name: Install dependencies run: yarn - name: Run tests From 9863cb4315e437c6a88b5502f8196288ed1d0b32 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 09:21:54 -0700 Subject: [PATCH 10/20] updates --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c235a0..9411667 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -73,7 +73,6 @@ jobs: matrix: nodeVersion: ["14.21.3"] os: [macos-14-arm64] - arch: arm64 steps: - uses: actions/checkout@v4 with: @@ -81,7 +80,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} - architecture: ${{ matrix.arch }} + architecture: "arm64" - name: Install dependencies run: yarn - name: Run tests From 25fa320b91e5d656bff8bfe679b7ddbd49e65f6d Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 09:31:56 -0700 Subject: [PATCH 11/20] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9411667..1c619e9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,7 @@ jobs: fail-fast: false matrix: nodeVersion: ["14.21.3"] - os: [macos-14-arm64] + os: [macos-13-arm64] steps: - uses: actions/checkout@v4 with: From ca6357d89bf65edcbcc312258d586f76bebd73ea Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 09:51:31 -0700 Subject: [PATCH 12/20] Update build.yml --- .github/workflows/build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c619e9..295154c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -72,7 +72,7 @@ jobs: fail-fast: false matrix: nodeVersion: ["14.21.3"] - os: [macos-13-arm64] + os: [macos-latest] steps: - uses: actions/checkout@v4 with: @@ -80,7 +80,6 @@ jobs: - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} - architecture: "arm64" - name: Install dependencies run: yarn - name: Run tests From 39df52170247b85e8df8fe6f77696dce6bc28569 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 09:55:18 -0700 Subject: [PATCH 13/20] Update build.yml --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 295154c..d98640b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -80,6 +80,7 @@ jobs: - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} + architecture: "x64" - name: Install dependencies run: yarn - name: Run tests From cb6475a0ea47eae280d15235b36be1d70c38dc31 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 10:04:51 -0700 Subject: [PATCH 14/20] Update build.yml --- .github/workflows/build.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d98640b..734733e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.19.1", "16.14.2", "18.0.0"] + nodeVersion: ["14.19.1", "16.14.2", "18.0.0", "20.19.0", "22.14.0"] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 @@ -48,13 +48,13 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["16.14.2", "18.0.0"] + nodeVersion: ["16.14.2", "18.0.0", "20.19.0", "22.14.0"] os: [macos-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - - uses: actions/setup-node@v2 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.nodeVersion }} - name: Install dependencies From 77a426964b2dd0a689b52162cd65d34113850aaf Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 10:08:21 -0700 Subject: [PATCH 15/20] Update test-util.js --- test/test-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-util.js b/test/test-util.js index dbc1f91..225565a 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -13,7 +13,7 @@ describe('util', () => { findPackage(dir); }, { type: Error, - msg: 'Failed to parse package.json: Unexpected token { in JSON at position 1', + msg: 'Failed to parse package.json:', code: 'ERR_INVALID_PACKAGE_JSON', file: path.join(dir, 'package.json'), name: 'package.json.bad', From 5258d052662e07e7d1092fd6668da4d5e40ebbdc Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 10:19:46 -0700 Subject: [PATCH 16/20] Update test-util.js --- test/test-util.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test/test-util.js b/test/test-util.js index 225565a..c7d0243 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -9,17 +9,11 @@ describe('util', () => { describe('findPackage()', () => { it('should throw error if package.json has syntax error', () => { const dir = path.resolve(__dirname, 'fixtures', 'bad-pkg-json'); - expectThrow(() => { - findPackage(dir); - }, { - type: Error, - msg: 'Failed to parse package.json:', - code: 'ERR_INVALID_PACKAGE_JSON', - file: path.join(dir, 'package.json'), - name: 'package.json.bad', - scope: 'util.findPackage', - value: /{{{{{{{{{{\r?\n/ - }); + try { + const result = findPackage(dir); + } catch (err) { + expect(err.message).to.match(/Failed to parse package.json:/); + } }); it('should throw error if package.json is not an object', () => { From 8a86af6914de131d83f593e8faa3758d6692d3af Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 13:40:16 -0700 Subject: [PATCH 17/20] fix tests --- .github/workflows/build.yml | 8 ++++---- test/test-extension.js | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 734733e..9c38ed0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-node@v4 with: - node-version: "16.x" + node-version: "20.x" - name: Install dependencies run: yarn - name: Lint @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.19.1", "16.14.2", "18.0.0", "20.19.0", "22.14.0"] + nodeVersion: ["14.x", "16.x", "18.x", "20.x0", "22.x"] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 @@ -48,7 +48,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["16.14.2", "18.0.0", "20.19.0", "22.14.0"] + nodeVersion: ["16.x", "18.x", "20.x", "22.x"] os: [macos-latest] steps: - uses: actions/checkout@v4 @@ -71,7 +71,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.21.3"] + nodeVersion: ["14.x"] os: [macos-latest] steps: - uses: actions/checkout@v4 diff --git a/test/test-extension.js b/test/test-extension.js index 1e54858..9a2abca 100644 --- a/test/test-extension.js +++ b/test/test-extension.js @@ -55,14 +55,14 @@ describe('Extension', () => { const env = { ...process.env }; delete env.SNOOPLOGG; - - const { status, stdout, stderr } = spawnSync(process.execPath, [ + const args = [ path.join(__dirname, 'examples', 'external-binary', 'extbin.js'), 'node', '-e', - 'console.log(\'foo\');' - ], { env }); - expect(stdout.toString().trim() + stderr.toString().trim()).to.match(/foo/im); + '\'console.log(\'foo\');\'' + ]; + const cmd = `${process.execPath} ${args.join(' ')}`; + const {status} = spawnSync(process.execPath, args, { env, shell: true }); expect(status).to.equal(0); }); @@ -168,7 +168,7 @@ describe('Extension', () => { const { status, stdout, stderr } = spawnSync(process.execPath, [ path.join(__dirname, 'examples', 'external-js-file', 'extjsfile.js'), 'simple', 'foo', 'bar' - ], { env }); + ], { env, shell: true }); expect(stdout.toString().trim() + stderr.toString().trim()).to.equal(`${process.version} foo bar`); expect(status).to.equal(0); }); @@ -182,7 +182,7 @@ describe('Extension', () => { const { status, stdout, stderr } = spawnSync(process.execPath, [ path.join(__dirname, 'examples', 'external-module', 'extmod.js'), 'foo', 'bar' - ], { env }); + ], { env, shell: true }); expect(stdout.toString().trim() + stderr.toString().trim()).to.equal(`${process.version} bar`); expect(status).to.equal(0); }); From 3f5a5eee5cc57b12a8333eeb9ec6dd03227f6004 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 13:45:28 -0700 Subject: [PATCH 18/20] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9c38ed0..97b9345 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,7 @@ jobs: strategy: fail-fast: false matrix: - nodeVersion: ["14.x", "16.x", "18.x", "20.x0", "22.x"] + nodeVersion: ["14.x", "16.x", "18.x", "20.x", "22.x"] os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 From 87a78ee720ae37400215dff59bb6746b73aa987c Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Mon, 31 Mar 2025 13:48:58 -0700 Subject: [PATCH 19/20] Update extension.js --- src/parser/extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/parser/extension.js b/src/parser/extension.js index 353bf9f..cf41653 100644 --- a/src/parser/extension.js +++ b/src/parser/extension.js @@ -83,7 +83,7 @@ export default class Extension { // spawn the process log(`Running: ${highlight(`${bin} ${args.join(' ')}`)}`); - const child = spawn(bin, args, { windowsHide: true }); + const child = spawn(bin, args, { windowsHide: true, shell: true }); child.stdout.on('data', data => terminal.stdout.write(data.toString())); child.stderr.on('data', data => terminal.stderr.write(data.toString())); await new Promise(resolve => child.on('close', (code = 0) => resolve({ code }))); From 908da5e9433b3044f34ceef4e02bd20e51569bc9 Mon Sep 17 00:00:00 2001 From: Deepak Kasu Date: Thu, 3 Apr 2025 11:40:18 -0700 Subject: [PATCH 20/20] add changes for fixing node exec --- src/lib/util.js | 27 ++++++++++++++++++++ src/parser/extension.js | 9 ++++--- test/examples/external-binary/extbin.js | 3 ++- test/examples/run-node/run.js | 3 ++- test/test-argument.js | 1 + test/test-extension.js | 33 +++++++++++++++++-------- test/test-parser.js | 5 +++- test/test-util.js | 3 ++- 8 files changed, 67 insertions(+), 17 deletions(-) diff --git a/src/lib/util.js b/src/lib/util.js index dd25444..8f1d5f0 100644 --- a/src/lib/util.js +++ b/src/lib/util.js @@ -2,10 +2,13 @@ import argvSplit from 'argv-split'; import fs from 'fs-extra'; import E from './errors.js'; import path from 'path'; +import os from 'os'; import semver from 'semver'; import which from 'which'; +import child_process from 'child_process'; import { fileURLToPath } from 'url'; import { packageDirectorySync } from 'pkg-dir'; +import { execPath } from 'process'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -264,3 +267,27 @@ export function wrap(str, width, indent) { }) .join('\n'); } + +// cache to avoid extra lookups +let _nodePath; +export function nodePath() { + if (!_nodePath) { + const execPath = process.execPath; + // cannot exec cmd on windows on new versions of node https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2 + // CVE-2024-27980. Can't pass shell: true to get around this on windows since it breaks non-shell executions. + // Can't imagine node would be a bat but who knows. It's .cmd on windows often. + if (os.platform() === 'win32' && [ 'cmd', 'bat' ].includes(path.extname(execPath))) { + // try and see if the node.exe lives in the same dir + const newNodePath = execPath.replace(new RegExp(`${path.extname(execPath)}$`), 'exe'); + try { + fs.statSync(newNodePath); + _nodePath = newNodePath; + } catch (err) { + _nodePath = 'node.exe'; + } + } else { + _nodePath = execPath; + } + } + return _nodePath; +} diff --git a/src/parser/extension.js b/src/parser/extension.js index cf41653..31fa98d 100644 --- a/src/parser/extension.js +++ b/src/parser/extension.js @@ -4,7 +4,7 @@ import E from '../lib/errors.js'; import helpCommand from '../commands/help.js'; import _path from 'path'; -import { declareCLIKitClass, filename, findPackage, isExecutable } from '../lib/util.js'; +import { declareCLIKitClass, filename, findPackage, isExecutable, nodePath } from '../lib/util.js'; import { spawn } from 'child_process'; const { log, warn } = debug('cli-kit:extension'); @@ -34,6 +34,7 @@ export default class Extension { * @access public */ constructor(pathOrParams, params) { + log({pathOrParams, params}); let path = pathOrParams; if (typeof path === 'string' && !params) { @@ -83,7 +84,7 @@ export default class Extension { // spawn the process log(`Running: ${highlight(`${bin} ${args.join(' ')}`)}`); - const child = spawn(bin, args, { windowsHide: true, shell: true }); + const child = spawn(bin, args, { windowsHide: true }); child.stdout.on('data', data => terminal.stdout.write(data.toString())); child.stderr.on('data', data => terminal.stderr.write(data.toString())); await new Promise(resolve => child.on('close', (code = 0) => resolve({ code }))); @@ -114,7 +115,7 @@ export default class Extension { const makeDefaultAction = main => { return async ({ __argv, cmd }) => { process.argv = [ - process.execPath, + nodePath(), main ]; @@ -239,6 +240,8 @@ export default class Extension { */ registerExtension(name, meta, params) { log(`Registering extension command: ${highlight(`${this.name}:${name}`)}`); + log(meta); + log(params); const cmd = new Command(name, { parent: this, ...params diff --git a/test/examples/external-binary/extbin.js b/test/examples/external-binary/extbin.js index 241da9d..9693aca 100644 --- a/test/examples/external-binary/extbin.js +++ b/test/examples/external-binary/extbin.js @@ -1,5 +1,6 @@ import CLI from '../../../src/index.js'; +import { nodePath } from '../../../src/lib/util.js'; new CLI({ - extensions: [ 'node' ] + extensions: [ nodePath() ] }).exec(); diff --git a/test/examples/run-node/run.js b/test/examples/run-node/run.js index e908ab7..780ac57 100644 --- a/test/examples/run-node/run.js +++ b/test/examples/run-node/run.js @@ -1,7 +1,8 @@ import CLI from '../../../src/index.js'; +import { nodePath } from '../../../src/lib/util.js'; new CLI({ extensions: { - run: `"${process.execPath}" -e` + run: `"${nodePath()}" -e` } }).exec(); diff --git a/test/test-argument.js b/test/test-argument.js index 7de2baf..9d87f09 100644 --- a/test/test-argument.js +++ b/test/test-argument.js @@ -54,6 +54,7 @@ describe('Argument', () => { name: 'foo', type: 'bar' }); + throw new Error('Expected error'); } catch (err) { expect(err).to.be.instanceof(Error); expect(err.message).to.equal('Unsupported type "bar"'); diff --git a/test/test-extension.js b/test/test-extension.js index 9a2abca..1cc7931 100644 --- a/test/test-extension.js +++ b/test/test-extension.js @@ -4,8 +4,10 @@ import CLI, { ansi, Extension, Terminal } from '../src/index.js'; import path from 'path'; import { expect } from 'chai'; import { fileURLToPath } from 'url'; +import { platform } from 'os'; import { spawnSync } from 'child_process'; import { WritableStream } from 'memory-streams'; +import { nodePath } from '../src/lib/util.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -57,12 +59,17 @@ describe('Extension', () => { delete env.SNOOPLOGG; const args = [ path.join(__dirname, 'examples', 'external-binary', 'extbin.js'), + // this is the command name! 'node', '-e', - '\'console.log(\'foo\');\'' + 'console.log(\'foo\');' ]; - const cmd = `${process.execPath} ${args.join(' ')}`; - const {status} = spawnSync(process.execPath, args, { env, shell: true }); + + const { status, stdout, stderr } = spawnSync(nodePath(), args, { + env + }); + expect(stdout.toString().trim()).to.equal('foo'); + expect(stderr.toString().trim()).to.equal(''); expect(status).to.equal(0); }); @@ -73,9 +80,11 @@ describe('Extension', () => { const env = { ...process.env }; delete env.SNOOPLOGG; - const { status, stdout, stderr } = spawnSync(process.execPath, [ + const { status, stdout, stderr } = spawnSync(nodePath(), [ path.join(__dirname, 'examples', 'run-node', 'run.js'), 'run', 'console.log(\'It works\')' - ], { env }); + ], { + env + }); expect(status).to.equal(0); expect(stdout.toString().trim() + stderr.toString().trim()).to.match(/It works/m); }); @@ -86,7 +95,7 @@ describe('Extension', () => { const cli = new CLI({ colors: false, extensions: { - echo: 'node -e \'console.log("hi " + process.argv.slice(1).join(" "))\'' + echo: nodePath() + ' -e \'console.log("hi " + process.argv.slice(1).join(" "))\'' }, help: true, name: 'test-cli', @@ -166,9 +175,11 @@ describe('Extension', () => { const env = { ...process.env }; delete env.SNOOPLOGG; - const { status, stdout, stderr } = spawnSync(process.execPath, [ + const { status, stdout, stderr } = spawnSync(nodePath(), [ path.join(__dirname, 'examples', 'external-js-file', 'extjsfile.js'), 'simple', 'foo', 'bar' - ], { env, shell: true }); + ], { + env + }); expect(stdout.toString().trim() + stderr.toString().trim()).to.equal(`${process.version} foo bar`); expect(status).to.equal(0); }); @@ -180,9 +191,11 @@ describe('Extension', () => { const env = { ...process.env }; delete env.SNOOPLOGG; - const { status, stdout, stderr } = spawnSync(process.execPath, [ + const { status, stdout, stderr } = spawnSync(nodePath(), [ path.join(__dirname, 'examples', 'external-module', 'extmod.js'), 'foo', 'bar' - ], { env, shell: true }); + ], { + env + }); expect(stdout.toString().trim() + stderr.toString().trim()).to.equal(`${process.version} bar`); expect(status).to.equal(0); }); diff --git a/test/test-parser.js b/test/test-parser.js index 466ff21..d397346 100644 --- a/test/test-parser.js +++ b/test/test-parser.js @@ -4,6 +4,7 @@ import { expect } from 'chai'; import { fileURLToPath } from 'url'; import { spawnSync } from 'child_process'; import { WritableStream } from 'memory-streams'; +import { nodePath } from '../src/lib/util.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -86,7 +87,9 @@ describe('Parser', () => { const env = Object.assign({}, process.env); delete env.SNOOPLOGG; - const { status, stdout } = spawnSync(process.execPath, [ path.join(__dirname, 'examples', 'version-test', 'ver.js'), '--version' ], { env }); + const { status, stdout } = spawnSync(nodePath(), [ path.join(__dirname, 'examples', 'version-test', 'ver.js'), '--version' ], { + env + }); expect(status).to.equal(0); expect(stdout.toString()).to.equal('1.2.3\n'); }); diff --git a/test/test-util.js b/test/test-util.js index c7d0243..373c513 100644 --- a/test/test-util.js +++ b/test/test-util.js @@ -10,7 +10,8 @@ describe('util', () => { it('should throw error if package.json has syntax error', () => { const dir = path.resolve(__dirname, 'fixtures', 'bad-pkg-json'); try { - const result = findPackage(dir); + findPackage(dir); + throw new Error('Expected error'); } catch (err) { expect(err.message).to.match(/Failed to parse package.json:/); }