node-version-use 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Resolve system binaries by searching PATH while excluding ~/.nvu/bin
3
+ * This mirrors the Go binary's findSystemBinary() function
4
+ */ import fs from 'fs';
5
+ import path from 'path';
6
+ import { homedir } from '../compat.js';
7
+ const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
8
+ const nvuBinDir = path.join(homedir(), '.nvu', 'bin');
9
+ /**
10
+ * Check if two paths are equal (case-insensitive on Windows)
11
+ */ function pathsEqual(a, b) {
12
+ if (isWindows) {
13
+ return a.toLowerCase() === b.toLowerCase();
14
+ }
15
+ return a === b;
16
+ }
17
+ /**
18
+ * Check if a path is within the nvu bin directory
19
+ */ function isInNvuBin(filePath) {
20
+ try {
21
+ const realPath = fs.realpathSync(filePath);
22
+ return realPath.indexOf(path.join('.nvu', 'bin')) >= 0 || pathsEqual(path.dirname(realPath), nvuBinDir);
23
+ } catch (_e) {
24
+ return false;
25
+ }
26
+ }
27
+ /**
28
+ * Find a system binary by searching PATH, excluding ~/.nvu/bin
29
+ * Returns the full path to the binary, or null if not found
30
+ */ export function resolveSystemBinary(name) {
31
+ const pathEnv = process.env.PATH || '';
32
+ const pathSep = isWindows ? ';' : ':';
33
+ const dirs = pathEnv.split(pathSep);
34
+ for(let i = 0; i < dirs.length; i++){
35
+ const dir = dirs[i];
36
+ if (!dir) continue;
37
+ // Skip ~/.nvu/bin
38
+ if (pathsEqual(dir, nvuBinDir)) continue;
39
+ // Build candidate path with appropriate extension
40
+ const candidates = isWindows ? [
41
+ path.join(dir, `${name}.exe`),
42
+ path.join(dir, `${name}.cmd`),
43
+ path.join(dir, name)
44
+ ] : [
45
+ path.join(dir, name)
46
+ ];
47
+ for(let j = 0; j < candidates.length; j++){
48
+ const candidate = candidates[j];
49
+ try {
50
+ const stat = fs.statSync(candidate);
51
+ if (!stat.isFile()) continue;
52
+ // Make sure it's not in ~/.nvu/bin (via symlink)
53
+ if (isInNvuBin(candidate)) continue;
54
+ return candidate;
55
+ } catch (_e) {
56
+ // File doesn't exist, continue
57
+ }
58
+ }
59
+ }
60
+ return null;
61
+ }
62
+ /**
63
+ * Get PATH with ~/.nvu/bin removed
64
+ * Used to create an environment for spawning system commands
65
+ */ export function getPathWithoutNvuBin() {
66
+ const pathEnv = process.env.PATH || '';
67
+ const pathSep = isWindows ? ';' : ':';
68
+ const dirs = pathEnv.split(pathSep);
69
+ const filtered = [];
70
+ for(let i = 0; i < dirs.length; i++){
71
+ const dir = dirs[i];
72
+ if (!dir) continue;
73
+ if (pathsEqual(dir, nvuBinDir)) continue;
74
+ if (dir.indexOf(path.join('.nvu', 'bin')) >= 0) continue;
75
+ filtered.push(dir);
76
+ }
77
+ return filtered.join(pathSep);
78
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/lib/resolveSystemBinary.ts"],"sourcesContent":["/**\n * Resolve system binaries by searching PATH while excluding ~/.nvu/bin\n * This mirrors the Go binary's findSystemBinary() function\n */\nimport fs from 'fs';\nimport path from 'path';\nimport { homedir } from '../compat.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst nvuBinDir = path.join(homedir(), '.nvu', 'bin');\n\n/**\n * Check if two paths are equal (case-insensitive on Windows)\n */\nfunction pathsEqual(a: string, b: string): boolean {\n if (isWindows) {\n return a.toLowerCase() === b.toLowerCase();\n }\n return a === b;\n}\n\n/**\n * Check if a path is within the nvu bin directory\n */\nfunction isInNvuBin(filePath: string): boolean {\n try {\n const realPath = fs.realpathSync(filePath);\n return realPath.indexOf(path.join('.nvu', 'bin')) >= 0 || pathsEqual(path.dirname(realPath), nvuBinDir);\n } catch (_e) {\n return false;\n }\n}\n\n/**\n * Find a system binary by searching PATH, excluding ~/.nvu/bin\n * Returns the full path to the binary, or null if not found\n */\nexport function resolveSystemBinary(name: string): string | null {\n const pathEnv = process.env.PATH || '';\n const pathSep = isWindows ? ';' : ':';\n const dirs = pathEnv.split(pathSep);\n\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i];\n if (!dir) continue;\n\n // Skip ~/.nvu/bin\n if (pathsEqual(dir, nvuBinDir)) continue;\n\n // Build candidate path with appropriate extension\n const candidates = isWindows ? [path.join(dir, `${name}.exe`), path.join(dir, `${name}.cmd`), path.join(dir, name)] : [path.join(dir, name)];\n\n for (let j = 0; j < candidates.length; j++) {\n const candidate = candidates[j];\n try {\n const stat = fs.statSync(candidate);\n if (!stat.isFile()) continue;\n\n // Make sure it's not in ~/.nvu/bin (via symlink)\n if (isInNvuBin(candidate)) continue;\n\n return candidate;\n } catch (_e) {\n // File doesn't exist, continue\n }\n }\n }\n\n return null;\n}\n\n/**\n * Get PATH with ~/.nvu/bin removed\n * Used to create an environment for spawning system commands\n */\nexport function getPathWithoutNvuBin(): string {\n const pathEnv = process.env.PATH || '';\n const pathSep = isWindows ? ';' : ':';\n const dirs = pathEnv.split(pathSep);\n\n const filtered: string[] = [];\n for (let i = 0; i < dirs.length; i++) {\n const dir = dirs[i];\n if (!dir) continue;\n if (pathsEqual(dir, nvuBinDir)) continue;\n if (dir.indexOf(path.join('.nvu', 'bin')) >= 0) continue;\n filtered.push(dir);\n }\n\n return filtered.join(pathSep);\n}\n"],"names":["fs","path","homedir","isWindows","process","platform","test","env","OSTYPE","nvuBinDir","join","pathsEqual","a","b","toLowerCase","isInNvuBin","filePath","realPath","realpathSync","indexOf","dirname","_e","resolveSystemBinary","name","pathEnv","PATH","pathSep","dirs","split","i","length","dir","candidates","j","candidate","stat","statSync","isFile","getPathWithoutNvuBin","filtered","push"],"mappings":"AAAA;;;CAGC,GACD,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,SAASC,OAAO,QAAQ,eAAe;AAEvC,MAAMC,YAAYC,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AE;YAC/B,IAAI;gBACF,MAAME,OAAOnC,GAAGoC,QAAQ,CAACF;gBACzB,IAAI,CAACC,KAAKE,MAAM,IAAI;gBAEpB,iDAAiD;gBACjD,IAAItB,WAAWmB,YAAY;gBAE3B,OAAOA;YACT,EAAE,OAAOb,IAAI;YACX,+BAA+B;YACjC;QACF;IACF;IAEA,OAAO;AACT;AAEA;;;CAGC,GACD,OAAO,SAASiB;IACd,MAAMd,UAAUpB,QAAQG,GAAG,CAACkB,IAAI,IAAI;IACpC,MAAMC,UAAUvB,YAAY,MAAM;IAClC,MAAMwB,OAAOH,QAAQI,KAAK,CAACF;IAE3B,MAAMa,WAAqB,EAAE;IAC7B,IAAK,IAAIV,IAAI,GAAGA,IAAIF,KAAKG,MAAM,EAAED,IAAK;QACpC,MAAME,MAAMJ,IAAI,CAACE,EAAE;QACnB,IAAI,CAACE,KAAK;QACV,IAAIpB,WAAWoB,KAAKtB,YAAY;QAChC,IAAIsB,IAAIZ,OAAO,CAAClB,KAAKS,IAAI,CAAC,QAAQ,WAAW,GAAG;QAChD6B,SAASC,IAAI,CAACT;IAChB;IAEA,OAAOQ,SAAS7B,IAAI,CAACgB;AACvB"}
@@ -7,9 +7,10 @@ import Queue from 'queue-cb';
7
7
  import resolveBin from 'resolve-bin-sync';
8
8
  import spawnStreaming from 'spawn-streaming';
9
9
  import { createSession, formatArguments } from 'spawn-term';
10
- import { stringEndsWith } from './compat.js';
10
+ import { objectAssign, stringEndsWith } from './compat.js';
11
11
  import { storagePath } from './constants.js';
12
12
  import loadNodeVersionInstall from './lib/loadNodeVersionInstall.js';
13
+ import { getPathWithoutNvuBin, resolveSystemBinary } from './lib/resolveSystemBinary.js';
13
14
  const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
14
15
  const NODE = isWindows ? 'node.exe' : 'node';
15
16
  // Parse npm-generated .cmd wrapper to extract the JS script path
@@ -43,9 +44,8 @@ function resolveCommand(command, args) {
43
44
  return {
44
45
  command: NODE,
45
46
  args: [
46
- scriptPath,
47
- ...args
48
- ]
47
+ scriptPath
48
+ ].concat(args)
49
49
  };
50
50
  }
51
51
  }
@@ -55,9 +55,8 @@ function resolveCommand(command, args) {
55
55
  return {
56
56
  command: NODE,
57
57
  args: [
58
- binPath,
59
- ...args
60
- ]
58
+ binPath
59
+ ].concat(args)
61
60
  };
62
61
  } catch (_e) {
63
62
  // Not an npm package bin, use original command
@@ -68,6 +67,11 @@ function resolveCommand(command, args) {
68
67
  };
69
68
  }
70
69
  export default function worker(versionExpression, command, args, options, callback) {
70
+ // Handle "system" as a special version that uses system binaries directly
71
+ if (versionExpression === 'system') {
72
+ runWithSystemBinaries(command, args, options, callback);
73
+ return;
74
+ }
71
75
  // Load node-version-install lazily
72
76
  loadNodeVersionInstall((loadErr, installVersion)=>{
73
77
  if (loadErr) return callback(loadErr);
@@ -77,10 +81,9 @@ export default function worker(versionExpression, command, args, options, callba
77
81
  callback(new Error(`No versions found from expression: ${versionExpression}`));
78
82
  return;
79
83
  }
80
- const installOptions = {
81
- storagePath,
82
- ...options
83
- };
84
+ const installOptions = objectAssign({
85
+ storagePath: storagePath
86
+ }, options);
84
87
  const streamingOptions = options;
85
88
  const results = [];
86
89
  const queue = new Queue(1);
@@ -153,3 +156,47 @@ export default function worker(versionExpression, command, args, options, callba
153
156
  });
154
157
  });
155
158
  }
159
+ /**
160
+ * Run command using system binaries (bypassing nvu version management)
161
+ * This handles the "system" version specifier
162
+ */ function runWithSystemBinaries(command, args, options, callback) {
163
+ // Find the system binary for the command
164
+ const systemBinary = resolveSystemBinary(command);
165
+ if (!systemBinary) {
166
+ callback(new Error(`System ${command} not found in PATH`));
167
+ return;
168
+ }
169
+ // Create spawn options with PATH excluding ~/.nvu/bin
170
+ // This ensures any child processes also use system binaries
171
+ const cleanPath = getPathWithoutNvuBin();
172
+ const spawnOptions = objectAssign({}, options);
173
+ spawnOptions.env = objectAssign({}, process.env);
174
+ spawnOptions.env.PATH = cleanPath;
175
+ spawnOptions.stdio = options.stdio || 'inherit';
176
+ // On Windows, resolve npm bin commands to bypass .cmd wrappers
177
+ const resolved = resolveCommand(command, args);
178
+ // For system, use the resolved system binary path
179
+ const finalCommand = resolved.command === command ? systemBinary : resolved.command;
180
+ const finalArgs = resolved.command === command ? args : resolved.args;
181
+ if (!options.silent) {
182
+ console.log(`$ ${formatArguments([
183
+ finalCommand
184
+ ].concat(finalArgs)).join(' ')}`);
185
+ }
186
+ spawn(finalCommand, finalArgs, spawnOptions, (err, res)=>{
187
+ if (err && err.message && err.message.indexOf('ExperimentalWarning') >= 0) {
188
+ res = err;
189
+ err = null;
190
+ }
191
+ const result = {
192
+ install: null,
193
+ command,
194
+ version: 'system',
195
+ error: err,
196
+ result: res
197
+ };
198
+ callback(err, [
199
+ result
200
+ ]);
201
+ });
202
+ }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/worker.ts"],"sourcesContent":["import spawn, { type SpawnOptions } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport resolveVersions, { type VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions } from 'node-version-install';\nimport { spawnOptions as createSpawnOptions } from 'node-version-utils';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\nimport spawnStreaming from 'spawn-streaming';\nimport { createSession, formatArguments } from 'spawn-term';\nimport { stringEndsWith } from './compat.ts';\nimport { storagePath } from './constants.ts';\nimport loadNodeVersionInstall from './lib/loadNodeVersionInstall.ts';\n\nimport type { Options, UseCallback, UseOptions, UseResult } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst NODE = isWindows ? 'node.exe' : 'node';\n\n// Parse npm-generated .cmd wrapper to extract the JS script path\nfunction parseNpmCmdWrapper(cmdPath: string): string | null {\n try {\n const content = fs.readFileSync(cmdPath, 'utf8');\n // Match: \"%_prog%\" \"%dp0%\\node_modules\\...\\cli.js\" %*\n // or: \"%_prog%\" \"%dp0%\\path\\to\\script.js\" %*\n const match = content.match(/\"%_prog%\"\\s+\"?%dp0%\\\\([^\"]+)\"?\\s+%\\*/);\n if (match) {\n const relativePath = match[1];\n const cmdDir = path.dirname(cmdPath);\n return path.join(cmdDir, relativePath);\n }\n } catch (_e) {\n // ignore\n }\n return null;\n}\n\n// On Windows, resolve npm bin commands to their JS entry points to bypass .cmd wrappers\n// This fixes issues with nvm-windows where .cmd wrappers use symlinked node.exe directly\nfunction resolveCommand(command: string, args: string[]): { command: string; args: string[] } {\n if (!isWindows) return { command, args };\n\n // Case 1: Command is a .cmd file path\n if (stringEndsWith(command.toLowerCase(), '.cmd')) {\n const scriptPath = parseNpmCmdWrapper(command);\n if (scriptPath) {\n return { command: NODE, args: [scriptPath, ...args] };\n }\n }\n\n // Case 2: Try to resolve the command as an npm package bin from node_modules\n try {\n const binPath = resolveBin(command);\n return { command: NODE, args: [binPath, ...args] };\n } catch (_e) {\n // Not an npm package bin, use original command\n }\n\n return { command, args };\n}\n\nexport default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void {\n // Load node-version-install lazily\n loadNodeVersionInstall((loadErr, installVersion) => {\n if (loadErr) return callback(loadErr);\n\n resolveVersions(versionExpression, options as VersionOptions, (err?: Error, versions?: string[]) => {\n if (err) return callback(err);\n if (!versions.length) {\n callback(new Error(`No versions found from expression: ${versionExpression}`));\n return;\n }\n\n const installOptions = { storagePath, ...options } as InstallOptions;\n const streamingOptions = options as Options;\n const results: UseResult[] = [];\n const queue = new Queue(1);\n\n // Create session once for all processes (only if multiple versions)\n const interactive = options.interactive !== false;\n const session = versions.length >= 2 && createSession && !streamingOptions.streaming ? createSession({ header: `${command} ${args.join(' ')}`, showStatusBar: true, interactive }) : null;\n\n versions.forEach((version: string) => {\n queue.defer((cb) => {\n installVersion(version, installOptions, (err, installs) => {\n const install = installs && installs.length === 1 ? installs[0] : null;\n if (err || !install) {\n const error = err || new Error(`Unexpected version results for version ${version}. Install ${JSON.stringify(installs)}`);\n results.push({ install, command, version, error, result: null });\n return cb();\n }\n const spawnOptions = createSpawnOptions(install.installPath, options as SpawnOptions);\n const prefix = install.version;\n\n function next(err?, res?): void {\n if (err && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n results.push({ install, command, version, error: err, result: res });\n cb();\n }\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n if (versions.length < 2) {\n // Show command when running single version (no terminal session, unless silent)\n if (!options.silent) console.log(`$ ${formatArguments([resolved.command].concat(resolved.args)).join(' ')}`);\n return spawn(resolved.command, resolved.args, spawnOptions, next);\n }\n if (session) session.spawn(resolved.command, resolved.args, spawnOptions, { group: prefix, expanded: streamingOptions.expanded }, next);\n else spawnStreaming(resolved.command, resolved.args, spawnOptions, { prefix }, next);\n });\n });\n });\n queue.await((err) => {\n if (session) {\n session.waitAndClose(() => {\n err ? callback(err) : callback(null, results);\n });\n } else {\n err ? callback(err) : callback(null, results);\n }\n });\n });\n });\n}\n"],"names":["spawn","fs","resolveVersions","spawnOptions","createSpawnOptions","path","Queue","resolveBin","spawnStreaming","createSession","formatArguments","stringEndsWith","storagePath","loadNodeVersionInstall","isWindows","process","platform","test","env","OSTYPE","NODE","parseNpmCmdWrapper","cmdPath","content","readFileSync","match","relativePath","cmdDir","dirname","join","_e","resolveCommand","command","args","toLowerCase","scriptPath","binPath","worker","versionExpression","options","callback","loadErr","installVersion","err","versions","length","Error","installOptions","streamingOptions","results","queue","interactive","session","streaming","header","showStatusBar","forEach","version","defer","cb","installs","install","error","JSON","stringify","push","result","installPath","prefix","next","res","message","indexOf","resolved","silent","console","log","concat","group","expanded","await","waitAndClose"],"mappings":"AAAA,OAAOA,WAAkC,iBAAiB;AAC1D,OAAOC,QAAQ,KAAK;AACpB,OAAOC,qBAA8C,wBAAwB;AAE7E,SAASC,gBAAgBC,kBAAkB,QAAQ,qBAAqB;AACxE,OAAO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["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/worker.ts"],"sourcesContent":["import spawn, { type SpawnOptions } from 'cross-spawn-cb';\nimport fs from 'fs';\nimport resolveVersions, { type VersionOptions } from 'node-resolve-versions';\nimport type { InstallOptions } from 'node-version-install';\nimport { spawnOptions as createSpawnOptions } from 'node-version-utils';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport resolveBin from 'resolve-bin-sync';\nimport spawnStreaming from 'spawn-streaming';\nimport { createSession, formatArguments } from 'spawn-term';\nimport { objectAssign, stringEndsWith } from './compat.ts';\nimport { storagePath } from './constants.ts';\nimport loadNodeVersionInstall from './lib/loadNodeVersionInstall.ts';\nimport { getPathWithoutNvuBin, resolveSystemBinary } from './lib/resolveSystemBinary.ts';\n\nimport type { Options, UseCallback, UseOptions, UseResult } from './types.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\nconst NODE = isWindows ? 'node.exe' : 'node';\n\n// Parse npm-generated .cmd wrapper to extract the JS script path\nfunction parseNpmCmdWrapper(cmdPath: string): string | null {\n try {\n const content = fs.readFileSync(cmdPath, 'utf8');\n // Match: \"%_prog%\" \"%dp0%\\node_modules\\...\\cli.js\" %*\n // or: \"%_prog%\" \"%dp0%\\path\\to\\script.js\" %*\n const match = content.match(/\"%_prog%\"\\s+\"?%dp0%\\\\([^\"]+)\"?\\s+%\\*/);\n if (match) {\n const relativePath = match[1];\n const cmdDir = path.dirname(cmdPath);\n return path.join(cmdDir, relativePath);\n }\n } catch (_e) {\n // ignore\n }\n return null;\n}\n\n// On Windows, resolve npm bin commands to their JS entry points to bypass .cmd wrappers\n// This fixes issues with nvm-windows where .cmd wrappers use symlinked node.exe directly\nfunction resolveCommand(command: string, args: string[]): { command: string; args: string[] } {\n if (!isWindows) return { command, args };\n\n // Case 1: Command is a .cmd file path\n if (stringEndsWith(command.toLowerCase(), '.cmd')) {\n const scriptPath = parseNpmCmdWrapper(command);\n if (scriptPath) {\n return { command: NODE, args: [scriptPath].concat(args) };\n }\n }\n\n // Case 2: Try to resolve the command as an npm package bin from node_modules\n try {\n const binPath = resolveBin(command);\n return { command: NODE, args: [binPath].concat(args) };\n } catch (_e) {\n // Not an npm package bin, use original command\n }\n\n return { command, args };\n}\n\nexport default function worker(versionExpression: string, command: string, args: string[], options: UseOptions, callback: UseCallback): void {\n // Handle \"system\" as a special version that uses system binaries directly\n if (versionExpression === 'system') {\n runWithSystemBinaries(command, args, options, callback);\n return;\n }\n\n // Load node-version-install lazily\n loadNodeVersionInstall((loadErr, installVersion) => {\n if (loadErr) return callback(loadErr);\n\n resolveVersions(versionExpression, options as VersionOptions, (err?: Error, versions?: string[]) => {\n if (err) return callback(err);\n if (!versions.length) {\n callback(new Error(`No versions found from expression: ${versionExpression}`));\n return;\n }\n\n const installOptions = objectAssign({ storagePath: storagePath }, options) as InstallOptions;\n const streamingOptions = options as Options;\n const results: UseResult[] = [];\n const queue = new Queue(1);\n\n // Create session once for all processes (only if multiple versions)\n const interactive = options.interactive !== false;\n const session = versions.length >= 2 && createSession && !streamingOptions.streaming ? createSession({ header: `${command} ${args.join(' ')}`, showStatusBar: true, interactive }) : null;\n\n versions.forEach((version: string) => {\n queue.defer((cb) => {\n installVersion(version, installOptions, (err, installs) => {\n const install = installs && installs.length === 1 ? installs[0] : null;\n if (err || !install) {\n const error = err || new Error(`Unexpected version results for version ${version}. Install ${JSON.stringify(installs)}`);\n results.push({ install, command, version, error, result: null });\n return cb();\n }\n const spawnOptions = createSpawnOptions(install.installPath, options as SpawnOptions);\n const prefix = install.version;\n\n function next(err?, res?): void {\n if (err && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n results.push({ install, command, version, error: err, result: res });\n cb();\n }\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n if (versions.length < 2) {\n // Show command when running single version (no terminal session, unless silent)\n if (!options.silent) console.log(`$ ${formatArguments([resolved.command].concat(resolved.args)).join(' ')}`);\n return spawn(resolved.command, resolved.args, spawnOptions, next);\n }\n if (session) session.spawn(resolved.command, resolved.args, spawnOptions, { group: prefix, expanded: streamingOptions.expanded }, next);\n else spawnStreaming(resolved.command, resolved.args, spawnOptions, { prefix }, next);\n });\n });\n });\n queue.await((err) => {\n if (session) {\n session.waitAndClose(() => {\n err ? callback(err) : callback(null, results);\n });\n } else {\n err ? callback(err) : callback(null, results);\n }\n });\n });\n });\n}\n\n/**\n * Run command using system binaries (bypassing nvu version management)\n * This handles the \"system\" version specifier\n */\nfunction runWithSystemBinaries(command: string, args: string[], options: UseOptions, callback: UseCallback): void {\n // Find the system binary for the command\n const systemBinary = resolveSystemBinary(command);\n if (!systemBinary) {\n callback(new Error(`System ${command} not found in PATH`));\n return;\n }\n\n // Create spawn options with PATH excluding ~/.nvu/bin\n // This ensures any child processes also use system binaries\n const cleanPath = getPathWithoutNvuBin();\n const spawnOptions: SpawnOptions = objectAssign({}, options as SpawnOptions);\n spawnOptions.env = objectAssign({}, process.env);\n spawnOptions.env.PATH = cleanPath;\n spawnOptions.stdio = options.stdio || 'inherit';\n\n // On Windows, resolve npm bin commands to bypass .cmd wrappers\n const resolved = resolveCommand(command, args);\n\n // For system, use the resolved system binary path\n const finalCommand = resolved.command === command ? systemBinary : resolved.command;\n const finalArgs = resolved.command === command ? args : resolved.args;\n\n if (!options.silent) {\n console.log(`$ ${formatArguments([finalCommand].concat(finalArgs)).join(' ')}`);\n }\n\n spawn(finalCommand, finalArgs, spawnOptions, (err?, res?) => {\n if (err && err.message && err.message.indexOf('ExperimentalWarning') >= 0) {\n res = err;\n err = null;\n }\n\n const result: UseResult = {\n install: null,\n command,\n version: 'system',\n error: err,\n result: res,\n };\n\n callback(err, [result]);\n });\n}\n"],"names":["spawn","fs","resolveVersions","spawnOptions","createSpawnOptions","path","Queue","resolveBin","spawnStreaming","createSession","formatArguments","objectAssign","stringEndsWith","storagePath","loadNodeVersionInstall","getPathWithoutNvuBin","resolveSystemBinary","isWindows","process","platform","test","env","OSTYPE","NODE","parseNpmCmdWrapper","cmdPath","content","readFileSync","match","relativePath","cmdDir","dirname","join","_e","resolveCommand","command","args","toLowerCase","scriptPath","concat","binPath","worker","versionExpression","options","callback","runWithSystemBinaries","loadErr","installVersion","err","versions","length","Error","installOptions","streamingOptions","results","queue","interactive","session","streaming","header","showStatusBar","forEach","version","defer","cb","installs","install","error","JSON","stringify","push","result","installPath","prefix","next","res","message","indexOf","resolved","silent","console","log","group","expanded","await","waitAndClose","systemBinary","cleanPath","PATH","stdio","finalCommand","finalArgs"],"mappings":"AAAA,OAAOA,WAAkC,iBAAiB;AAC1D,OAAOC,QAAQ,KAAK;AACpB,OAAOC,qBAA8C,wBAAwB;AAE7E,SAASC,gBAAgBC,kBAAkB,QAAQ,qBAAqB;AACxE,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,gBAAgB,mBAAmB;AAC1C,OAAOC,oBAAoB,kBAAkB;AAC7C,SAASC,aAAa,EAAEC,eAAe,QAAQ,aAAa;AAC5D,SAASC,YAAY,EAAEC,cAAc,QAAQ,cAAc;AAC3D,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,OAAOC,4BAA4B,kCAAkC;AACrE,SAASC,oBAAoB,EAAEC,mBAAmB,QAAQ,+BAA+B;AAIzF,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAC3F,MAAMC,OAAON,YAAY,aAAa;AAEtC,iEAAiE;AACjE,SAASO,mBAAmBC,OAAe;IACzC,IAAI;QACF,MAAMC,UAAUzB,GAAG0B,YAAY,CAACF,SAAS;QACzC,uDAAuD;QACvD,8CAA8C;QAC9C,MAAMG,QAAQF,QAAQE,KAAK,CAAC;QAC5B,IAAIA,OAAO;YACT,MAAMC,eAAeD,KAAK,CAAC,EAAE;YAC7B,MAAME,SAASzB,KAAK0B,OAAO,CAACN;YAC5B,OAAO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EzC,kDAAkD;IAClD,MAAMsD,eAAeZ,SAAS3C,OAAO,KAAKA,UAAUmD,eAAeR,SAAS3C,OAAO;IACnF,MAAMwD,YAAYb,SAAS3C,OAAO,KAAKA,UAAUC,OAAO0C,SAAS1C,IAAI;IAErE,IAAI,CAACO,QAAQoC,MAAM,EAAE;QACnBC,QAAQC,GAAG,CAAC,CAAC,EAAE,EAAEvE,gBAAgB;YAACgF;SAAa,CAACnD,MAAM,CAACoD,YAAY3D,IAAI,CAAC,MAAM;IAChF;IAEAhC,MAAM0F,cAAcC,WAAWxF,cAAc,CAAC6C,KAAM2B;QAClD,IAAI3B,OAAOA,IAAI4B,OAAO,IAAI5B,IAAI4B,OAAO,CAACC,OAAO,CAAC,0BAA0B,GAAG;YACzEF,MAAM3B;YACNA,MAAM;QACR;QAEA,MAAMuB,SAAoB;YACxBL,SAAS;YACT/B;YACA2B,SAAS;YACTK,OAAOnB;YACPuB,QAAQI;QACV;QAEA/B,SAASI,KAAK;YAACuB;SAAO;IACxB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-version-use",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "description": "Cross-platform solution for using multiple versions of node. Useful for compatibility testing",
5
5
  "keywords": [
6
6
  "node",
@@ -48,8 +48,8 @@
48
48
  "version": "tsds version"
49
49
  },
50
50
  "dependencies": {
51
+ "cpu-arch": "^1.1.1",
51
52
  "cross-spawn-cb": "^3.0.0",
52
- "env-path-key": "^1.0.0",
53
53
  "exit-compat": "^1.0.0",
54
54
  "fs-remove-compat": "^1.0.0",
55
55
  "get-file-compat": "^2.0.0",
@@ -72,6 +72,7 @@
72
72
  "@types/mocha": "*",
73
73
  "@types/node": "*",
74
74
  "cr": "^0.1.0",
75
+ "env-path-key": "^1.1.8",
75
76
  "fs-copy-compat": "^1.0.0",
76
77
  "fs-remove-compat": "^1.0.0",
77
78
  "is-version": "^1.0.9",
package/assets/bin/node DELETED
Binary file