You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

node-version-call-local

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-version-call-local - npm Package Compare versions

Comparing version
0.3.0
to
0.3.1
+39
-53
dist/cjs/index.js

@@ -63,4 +63,6 @@ "use strict";

var SLEEP_MS = 60;
var functionExec = null;
var satisfiesSemverSync = null;
function findExecPath(version, env) {
var satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync;
if (!satisfiesSemverSync) satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync;
var options = env ? {

@@ -83,31 +85,26 @@ env: env

var env = opts.env || process.env;
// Check if current process satisfies the version constraint
var currentSatisfies = version === process.version || _semver.default.satisfies(process.version, version);
if (currentSatisfies) {
// Local execution
if (callbacks) {
var PATH_KEY = (0, _envpathkey.default)();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error("node-version-call-local: options.env missing required ".concat(PATH_KEY));
}
var execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env: env
};
return _require('function-exec-sync').apply(null, [
execOptions,
workerPath
].concat(_to_consumable_array(args)));
}
if (currentSatisfies && !callbacks) {
var fn = _require(workerPath);
return typeof fn === 'function' ? fn.apply(null, args) : fn;
}
// Find Node in PATH
if (!functionExec) functionExec = _require('function-exec-sync');
if (currentSatisfies) {
var PATH_KEY = (0, _envpathkey.default)();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error("node-version-call-local: options.env missing required ".concat(PATH_KEY));
}
var execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env: env
};
return functionExec.apply(null, [
execOptions,
workerPath
].concat(_to_consumable_array(args)));
}
var execPath = findExecPath(version, opts.env);
// Execute in found Node
var functionExec = _require('function-exec-sync');
if (useSpawnOptions) {
// Full environment setup for npm operations
var installPath = (0, _deriveInstallPathts.default)(execPath);

@@ -125,3 +122,2 @@ var execOptions1 = (0, _nodeversionutils.spawnOptions)(installPath, {

}
// Simple execution (like get-file-compat)
var execOptions2 = {

@@ -143,3 +139,2 @@ execPath: execPath,

var env = opts.env || process.env;
// Cache these on first call (lazy)
var initialized = false;

@@ -152,41 +147,32 @@ var currentSatisfies;

}
// Check if last arg is a callback first
var lastArg = args[args.length - 1];
var hasCallback = typeof lastArg === 'function';
var execute = function() {
// Lazy initialization on first call
if (!initialized) {
currentSatisfies = version === process.version || _semver.default.satisfies(process.version, version);
if (!currentSatisfies) {
cachedExecPath = findExecPath(version, opts.env);
}
if (!currentSatisfies) cachedExecPath = findExecPath(version, opts.env);
initialized = true;
}
if (currentSatisfies) {
// Local execution
if (callbacks) {
var PATH_KEY = (0, _envpathkey.default)();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error("node-version-call-local: options.env missing required ".concat(PATH_KEY));
}
var execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env: env
};
return _require('function-exec-sync').apply(null, [
execOptions,
workerPath
].concat(_to_consumable_array(args)));
}
if (currentSatisfies && !callbacks) {
var fn = _require(workerPath);
return typeof fn === 'function' ? fn.apply(null, args) : fn;
}
// Execute in cached Node - cachedExecPath is guaranteed to be set when currentSatisfies is false
if (cachedExecPath === null) {
throw new Error('node-version-call-local: Internal error - execPath should be set');
if (!functionExec) functionExec = _require('function-exec-sync');
if (currentSatisfies) {
var PATH_KEY = (0, _envpathkey.default)();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error("node-version-call-local: options.env missing required ".concat(PATH_KEY));
}
var execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env: env
};
return functionExec.apply(null, [
execOptions,
workerPath
].concat(_to_consumable_array(args)));
}
var execPath = cachedExecPath;
var functionExec = _require('function-exec-sync');
if (useSpawnOptions) {

@@ -193,0 +179,0 @@ var installPath = (0, _deriveInstallPathts.default)(execPath);

@@ -1,1 +0,1 @@

{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-call-local/src/index.ts"],"sourcesContent":["import pathKey from 'env-path-key';\nimport type functionExecSync from 'function-exec-sync';\nimport Module from 'module';\nimport type { satisfiesSemverSyncOptions } from 'node-exec-path';\nimport { type SpawnOptions, spawnOptions } from 'node-version-utils';\nimport semver from 'semver';\nimport deriveInstallPath from './lib/deriveInstallPath.ts';\n\nimport type { BindOptions, BoundCaller, CallerCallback, CallOptions } from './types.ts';\n\nexport type * from './types.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst SLEEP_MS = 60;\n\nfunction findExecPath(version: string, env?: NodeJS.ProcessEnv): string {\n const satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync as (version: string, options?: satisfiesSemverSyncOptions) => string | null;\n const options = env ? { env } : {};\n const execPath = satisfiesSemverSync(version, options);\n if (!execPath) {\n throw new Error(`node-version-call-local: No Node matching \"${version}\" found in PATH`);\n }\n return execPath;\n}\n\n/**\n * Call a function in a Node version found in PATH.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @param args - Arguments to pass to the worker\n */\nexport default function call(version: string, workerPath: string, options?: CallOptions, ...args: unknown[]): unknown {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n // Check if current process satisfies the version constraint\n const currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n\n if (currentSatisfies) {\n // Local execution\n if (callbacks) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return (_require('function-exec-sync') as typeof functionExecSync).apply(null, [execOptions, workerPath, ...args]);\n }\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n // Find Node in PATH\n const execPath = findExecPath(version, opts.env);\n\n // Execute in found Node\n const functionExec = _require('function-exec-sync') as typeof functionExecSync;\n\n if (useSpawnOptions) {\n // Full environment setup for npm operations\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n // Simple execution (like get-file-compat)\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n}\n\n/**\n * Create a bound caller for a specific version and worker.\n * Looks up the execPath ONCE on first call (lazy) and caches it.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @returns A function that calls the worker with the bound version/path/options\n */\nexport function bind(version: string, workerPath: string, options?: BindOptions): BoundCaller {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n // Cache these on first call (lazy)\n let initialized = false;\n let currentSatisfies: boolean;\n let cachedExecPath: string | null = null;\n\n return function boundCaller(...args: unknown[]): unknown {\n // Check if last arg is a callback first\n const lastArg = args[args.length - 1];\n const hasCallback = typeof lastArg === 'function';\n\n const execute = (): unknown => {\n // Lazy initialization on first call\n if (!initialized) {\n currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n if (!currentSatisfies) {\n cachedExecPath = findExecPath(version, opts.env);\n }\n initialized = true;\n }\n\n if (currentSatisfies) {\n // Local execution\n if (callbacks) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return (_require('function-exec-sync') as typeof functionExecSync).apply(null, [execOptions, workerPath, ...args]);\n }\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n // Execute in cached Node - cachedExecPath is guaranteed to be set when currentSatisfies is false\n if (cachedExecPath === null) {\n throw new Error('node-version-call-local: Internal error - execPath should be set');\n }\n const execPath = cachedExecPath;\n const functionExec = _require('function-exec-sync') as typeof functionExecSync;\n\n if (useSpawnOptions) {\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n };\n\n if (hasCallback) {\n const callback = args.pop() as CallerCallback;\n try {\n const result = execute();\n callback(null, result);\n return undefined;\n } catch (err) {\n callback(err);\n return undefined;\n }\n }\n\n return execute();\n };\n}\n"],"names":["bind","call","_require","require","Module","createRequire","SLEEP_MS","findExecPath","version","env","satisfiesSemverSync","options","execPath","Error","workerPath","args","opts","callbacks","useSpawnOptions","spawnOptions","process","currentSatisfies","semver","satisfies","PATH_KEY","pathKey","execOptions","sleep","apply","fn","functionExec","installPath","deriveInstallPath","initialized","cachedExecPath","boundCaller","lastArg","length","hasCallback","execute","callback","pop","result","undefined","err"],"mappings":";;;;;;;;;;;QAmFgBA;eAAAA;;QA1DhB;;;;;;;CAOC,GACD;eAAwBC;;;iEAjCJ;6DAED;gCAE6B;6DAC7B;0EACW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,WAAW;AAEjB,SAASC,aAAaC,OAAe,EAAEC,GAAuB;IAC5D,IAAMC,sBAAsBR,SAAS,kBAAkBQ,mBAAmB;IAC1E,IAAMC,UAAUF,MAAM;QAAEA,KAAAA;IAAI,IAAI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aAAoB,CAAlC,OAA0B,qBAAGC;QAC/D;QAEA,IAAIuB,aAAa;YACf,IAAME,WAAWzB,KAAK0B,GAAG;YACzB,IAAI;gBACF,IAAMC,SAASH;gBACfC,SAAS,MAAME;gBACf,OAAOC;YACT,EAAE,OAAOC,KAAK;gBACZJ,SAASI;gBACT,OAAOD;YACT;QACF;QAEA,OAAOJ;IACT;AACF"}
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-call-local/src/index.ts"],"sourcesContent":["import pathKey from 'env-path-key';\nimport type functionExecSync from 'function-exec-sync';\nimport Module from 'module';\nimport type { satisfiesSemverSyncOptions } from 'node-exec-path';\nimport { type SpawnOptions, spawnOptions } from 'node-version-utils';\nimport semver from 'semver';\nimport deriveInstallPath from './lib/deriveInstallPath.ts';\n\nimport type { BindOptions, BoundCaller, CallerCallback, CallOptions } from './types.ts';\n\nexport type * from './types.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst SLEEP_MS = 60;\n\nlet functionExec: typeof functionExecSync = null;\nlet satisfiesSemverSync: (version: string, options?: satisfiesSemverSyncOptions) => string | null = null;\n\nfunction findExecPath(version: string, env?: NodeJS.ProcessEnv): string {\n if (!satisfiesSemverSync) satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync;\n const options = env ? { env } : {};\n const execPath = satisfiesSemverSync(version, options);\n if (!execPath) {\n throw new Error(`node-version-call-local: No Node matching \"${version}\" found in PATH`);\n }\n return execPath;\n}\n\n/**\n * Call a function in a Node version found in PATH.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @param args - Arguments to pass to the worker\n */\nexport default function call(version: string, workerPath: string, options?: CallOptions, ...args: unknown[]): unknown {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n const currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n\n if (currentSatisfies && !callbacks) {\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n if (!functionExec) functionExec = _require('function-exec-sync');\n\n if (currentSatisfies) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execPath = findExecPath(version, opts.env);\n\n if (useSpawnOptions) {\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n}\n\n/**\n * Create a bound caller for a specific version and worker.\n * Looks up the execPath ONCE on first call (lazy) and caches it.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @returns A function that calls the worker with the bound version/path/options\n */\nexport function bind(version: string, workerPath: string, options?: BindOptions): BoundCaller {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n let initialized = false;\n let currentSatisfies: boolean;\n let cachedExecPath: string | null = null;\n\n return function boundCaller(...args: unknown[]): unknown {\n const lastArg = args[args.length - 1];\n const hasCallback = typeof lastArg === 'function';\n\n const execute = (): unknown => {\n if (!initialized) {\n currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n if (!currentSatisfies) cachedExecPath = findExecPath(version, opts.env);\n initialized = true;\n }\n\n if (currentSatisfies && !callbacks) {\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n if (!functionExec) functionExec = _require('function-exec-sync');\n\n if (currentSatisfies) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execPath = cachedExecPath;\n\n if (useSpawnOptions) {\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n };\n\n if (hasCallback) {\n const callback = args.pop() as CallerCallback;\n try {\n const result = execute();\n callback(null, result);\n return undefined;\n } catch (err) {\n callback(err);\n return undefined;\n }\n }\n\n return execute();\n };\n}\n"],"names":["bind","call","_require","require","Module","createRequire","SLEEP_MS","functionExec","satisfiesSemverSync","findExecPath","version","env","options","execPath","Error","workerPath","args","opts","callbacks","useSpawnOptions","spawnOptions","process","currentSatisfies","semver","satisfies","fn","apply","PATH_KEY","pathKey","execOptions","sleep","installPath","deriveInstallPath","initialized","cachedExecPath","boundCaller","lastArg","length","hasCallback","execute","callback","pop","result","undefined","err"],"mappings":";;;;;;;;;;;QAiFgBA;eAAAA;;QArDhB;;;;;;;CAOC,GACD;eAAwBC;;;iEApCJ;6DAED;gCAE6B;6DAC7B;0EACW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAM9B,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAAMG,WAAW;AAEjB,IAAIC,eAAwC;AAC5C,IAAIC,sBAAgG;AAEpG,SAASC,aAAaC,OAAe,EAAEC,GAAuB;IAC5D,IAAI,CAACH,qBAAqBA,sB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;gBACf,OAAOC;YACT,EAAE,OAAOC,KAAK;gBACZJ,SAASI;gBACT,OAAOD;YACT;QACF;QAEA,OAAOJ;IACT;AACF"}

@@ -8,4 +8,6 @@ import pathKey from 'env-path-key';

const SLEEP_MS = 60;
let functionExec = null;
let satisfiesSemverSync = null;
function findExecPath(version, env) {
const satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync;
if (!satisfiesSemverSync) satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync;
const options = env ? {

@@ -32,32 +34,27 @@ env

const env = opts.env || process.env;
// Check if current process satisfies the version constraint
const currentSatisfies = version === process.version || semver.satisfies(process.version, version);
if (currentSatisfies) {
// Local execution
if (callbacks) {
const PATH_KEY = pathKey();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);
}
const execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env
};
return _require('function-exec-sync').apply(null, [
execOptions,
workerPath,
...args
]);
}
if (currentSatisfies && !callbacks) {
const fn = _require(workerPath);
return typeof fn === 'function' ? fn.apply(null, args) : fn;
}
// Find Node in PATH
if (!functionExec) functionExec = _require('function-exec-sync');
if (currentSatisfies) {
const PATH_KEY = pathKey();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);
}
const execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env
};
return functionExec.apply(null, [
execOptions,
workerPath,
...args
]);
}
const execPath = findExecPath(version, opts.env);
// Execute in found Node
const functionExec = _require('function-exec-sync');
if (useSpawnOptions) {
// Full environment setup for npm operations
const installPath = deriveInstallPath(execPath);

@@ -76,3 +73,2 @@ const execOptions = spawnOptions(installPath, {

}
// Simple execution (like get-file-compat)
const execOptions = {

@@ -103,3 +99,2 @@ execPath,

const env = opts.env || process.env;
// Cache these on first call (lazy)
let initialized = false;

@@ -109,42 +104,33 @@ let currentSatisfies;

return function boundCaller(...args) {
// Check if last arg is a callback first
const lastArg = args[args.length - 1];
const hasCallback = typeof lastArg === 'function';
const execute = ()=>{
// Lazy initialization on first call
if (!initialized) {
currentSatisfies = version === process.version || semver.satisfies(process.version, version);
if (!currentSatisfies) {
cachedExecPath = findExecPath(version, opts.env);
}
if (!currentSatisfies) cachedExecPath = findExecPath(version, opts.env);
initialized = true;
}
if (currentSatisfies) {
// Local execution
if (callbacks) {
const PATH_KEY = pathKey();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);
}
const execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env
};
return _require('function-exec-sync').apply(null, [
execOptions,
workerPath,
...args
]);
}
if (currentSatisfies && !callbacks) {
const fn = _require(workerPath);
return typeof fn === 'function' ? fn.apply(null, args) : fn;
}
// Execute in cached Node - cachedExecPath is guaranteed to be set when currentSatisfies is false
if (cachedExecPath === null) {
throw new Error('node-version-call-local: Internal error - execPath should be set');
if (!functionExec) functionExec = _require('function-exec-sync');
if (currentSatisfies) {
const PATH_KEY = pathKey();
if (opts.env && !opts.env[PATH_KEY]) {
throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);
}
const execOptions = {
execPath: process.execPath,
sleep: SLEEP_MS,
callbacks: true,
env
};
return functionExec.apply(null, [
execOptions,
workerPath,
...args
]);
}
const execPath = cachedExecPath;
const functionExec = _require('function-exec-sync');
if (useSpawnOptions) {

@@ -151,0 +137,0 @@ const installPath = deriveInstallPath(execPath);

@@ -1,1 +0,1 @@

{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-call-local/src/index.ts"],"sourcesContent":["import pathKey from 'env-path-key';\nimport type functionExecSync from 'function-exec-sync';\nimport Module from 'module';\nimport type { satisfiesSemverSyncOptions } from 'node-exec-path';\nimport { type SpawnOptions, spawnOptions } from 'node-version-utils';\nimport semver from 'semver';\nimport deriveInstallPath from './lib/deriveInstallPath.ts';\n\nimport type { BindOptions, BoundCaller, CallerCallback, CallOptions } from './types.ts';\n\nexport type * from './types.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst SLEEP_MS = 60;\n\nfunction findExecPath(version: string, env?: NodeJS.ProcessEnv): string {\n const satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync as (version: string, options?: satisfiesSemverSyncOptions) => string | null;\n const options = env ? { env } : {};\n const execPath = satisfiesSemverSync(version, options);\n if (!execPath) {\n throw new Error(`node-version-call-local: No Node matching \"${version}\" found in PATH`);\n }\n return execPath;\n}\n\n/**\n * Call a function in a Node version found in PATH.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @param args - Arguments to pass to the worker\n */\nexport default function call(version: string, workerPath: string, options?: CallOptions, ...args: unknown[]): unknown {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n // Check if current process satisfies the version constraint\n const currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n\n if (currentSatisfies) {\n // Local execution\n if (callbacks) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return (_require('function-exec-sync') as typeof functionExecSync).apply(null, [execOptions, workerPath, ...args]);\n }\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n // Find Node in PATH\n const execPath = findExecPath(version, opts.env);\n\n // Execute in found Node\n const functionExec = _require('function-exec-sync') as typeof functionExecSync;\n\n if (useSpawnOptions) {\n // Full environment setup for npm operations\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n // Simple execution (like get-file-compat)\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n}\n\n/**\n * Create a bound caller for a specific version and worker.\n * Looks up the execPath ONCE on first call (lazy) and caches it.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @returns A function that calls the worker with the bound version/path/options\n */\nexport function bind(version: string, workerPath: string, options?: BindOptions): BoundCaller {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n // Cache these on first call (lazy)\n let initialized = false;\n let currentSatisfies: boolean;\n let cachedExecPath: string | null = null;\n\n return function boundCaller(...args: unknown[]): unknown {\n // Check if last arg is a callback first\n const lastArg = args[args.length - 1];\n const hasCallback = typeof lastArg === 'function';\n\n const execute = (): unknown => {\n // Lazy initialization on first call\n if (!initialized) {\n currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n if (!currentSatisfies) {\n cachedExecPath = findExecPath(version, opts.env);\n }\n initialized = true;\n }\n\n if (currentSatisfies) {\n // Local execution\n if (callbacks) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return (_require('function-exec-sync') as typeof functionExecSync).apply(null, [execOptions, workerPath, ...args]);\n }\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n // Execute in cached Node - cachedExecPath is guaranteed to be set when currentSatisfies is false\n if (cachedExecPath === null) {\n throw new Error('node-version-call-local: Internal error - execPath should be set');\n }\n const execPath = cachedExecPath;\n const functionExec = _require('function-exec-sync') as typeof functionExecSync;\n\n if (useSpawnOptions) {\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n };\n\n if (hasCallback) {\n const callback = args.pop() as CallerCallback;\n try {\n const result = execute();\n callback(null, result);\n return undefined;\n } catch (err) {\n callback(err);\n return undefined;\n }\n }\n\n return execute();\n };\n}\n"],"names":["pathKey","Module","spawnOptions","semver","deriveInstallPath","_require","require","createRequire","url","SLEEP_MS","findExecPath","version","env","satisfiesSemverSync","options","execPath","Error","call","workerPath","args","opts","callbacks","useSpawnOptions","process","currentSatisfies","satisfies","PATH_KEY","execOptions","sleep","apply","fn","functionExec","installPath","bind","initialized","cachedExecPath","boundCaller","lastArg","length","hasCallback","execute","callback","pop","result","undefined","err"],"mappings":"AAAA,OAAOA,aAAa,eAAe;AAEnC,OAAOC,YAAY,SAAS;AAE5B,SAA4BC,YAAY,QAAQ,qBAAqB;AACrE,OAAOC,YAAY,SAAS;AAC5B,OAAOC,uBAAuB,6BAA6B;AAM3D,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,WAAW;AAEjB,SAASC,aAAaC,OAAe,EAAEC,GAAuB;IAC5D,MAAMC,sBAAsBR,SAAS,kBAAkBQ,mBAAmB;IAC1E,MAAMC,UAAUF,MAAM;QAAEA;IAAI,IAAI,CAAC;IACjC,MAAMG,WAAWF,oBAAoBF,SAASG;IAC9C,IAAI,CAACC,UAAU;QACb,MAAM,IAAIC,MAAM,CAAC,2CAA2C,EAAEL,QAAQ,eAAe,CAAC;IACxF;IACA,OAAOI;AACT;AAEA;;;;;;;CAOC,GACD,eAAe,SAASE,KAAKN,OAAe,EAAEO,UAAkB,EAAEJ,OAAqB,EAAE,GAAGK,IAAe;IAC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ACpB,OAAO,OAAOY,OAAO,aAAaA,GAAGD,KAAK,CAAC,MAAMV,QAAQW;YAC3D;YAEA,iGAAiG;YACjG,IAAIK,mBAAmB,MAAM;gBAC3B,MAAM,IAAInB,MAAM;YAClB;YACA,MAAMD,WAAWoB;YACjB,MAAMJ,eAAe1B,SAAS;YAE9B,IAAIiB,iBAAiB;gBACnB,MAAMU,cAAc5B,kBAAkBW;gBACtC,MAAMY,cAAczB,aAAa8B,aAAa;oBAAEjB;oBAAUa,OAAOnB;oBAAUY;oBAAWT;gBAAI;gBAC1F,OAAOmB,aAAaF,KAAK,CAAC,MAAM;oBAACF;oBAAaT;uBAAeC;iBAAK;YACpE;YAEA,MAAMQ,cAAc;gBAAEZ;gBAAUa,OAAOnB;gBAAUY;gBAAWT;YAAI;YAChE,OAAOmB,aAAaF,KAAK,CAAC,MAAM;gBAACF;gBAAaT;mBAAeC;aAAK;QACpE;QAEA,IAAIoB,aAAa;YACf,MAAME,WAAWtB,KAAKuB,GAAG;YACzB,IAAI;gBACF,MAAMC,SAASH;gBACfC,SAAS,MAAME;gBACf,OAAOC;YACT,EAAE,OAAOC,KAAK;gBACZJ,SAASI;gBACT,OAAOD;YACT;QACF;QAEA,OAAOJ;IACT;AACF"}
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-call-local/src/index.ts"],"sourcesContent":["import pathKey from 'env-path-key';\nimport type functionExecSync from 'function-exec-sync';\nimport Module from 'module';\nimport type { satisfiesSemverSyncOptions } from 'node-exec-path';\nimport { type SpawnOptions, spawnOptions } from 'node-version-utils';\nimport semver from 'semver';\nimport deriveInstallPath from './lib/deriveInstallPath.ts';\n\nimport type { BindOptions, BoundCaller, CallerCallback, CallOptions } from './types.ts';\n\nexport type * from './types.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst SLEEP_MS = 60;\n\nlet functionExec: typeof functionExecSync = null;\nlet satisfiesSemverSync: (version: string, options?: satisfiesSemverSyncOptions) => string | null = null;\n\nfunction findExecPath(version: string, env?: NodeJS.ProcessEnv): string {\n if (!satisfiesSemverSync) satisfiesSemverSync = _require('node-exec-path').satisfiesSemverSync;\n const options = env ? { env } : {};\n const execPath = satisfiesSemverSync(version, options);\n if (!execPath) {\n throw new Error(`node-version-call-local: No Node matching \"${version}\" found in PATH`);\n }\n return execPath;\n}\n\n/**\n * Call a function in a Node version found in PATH.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @param args - Arguments to pass to the worker\n */\nexport default function call(version: string, workerPath: string, options?: CallOptions, ...args: unknown[]): unknown {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n const currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n\n if (currentSatisfies && !callbacks) {\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n if (!functionExec) functionExec = _require('function-exec-sync');\n\n if (currentSatisfies) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execPath = findExecPath(version, opts.env);\n\n if (useSpawnOptions) {\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n}\n\n/**\n * Create a bound caller for a specific version and worker.\n * Looks up the execPath ONCE on first call (lazy) and caches it.\n *\n * @param version - Semver constraint ('>0.12', '>=18', '^16') or exact ('v18.0.0')\n * @param workerPath - Path to the file to execute\n * @param options - Execution options\n * @returns A function that calls the worker with the bound version/path/options\n */\nexport function bind(version: string, workerPath: string, options?: BindOptions): BoundCaller {\n const opts = options || {};\n const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)\n const useSpawnOptions = opts.spawnOptions !== false; // default true\n const env = opts.env || process.env;\n\n let initialized = false;\n let currentSatisfies: boolean;\n let cachedExecPath: string | null = null;\n\n return function boundCaller(...args: unknown[]): unknown {\n const lastArg = args[args.length - 1];\n const hasCallback = typeof lastArg === 'function';\n\n const execute = (): unknown => {\n if (!initialized) {\n currentSatisfies = version === process.version || semver.satisfies(process.version, version);\n if (!currentSatisfies) cachedExecPath = findExecPath(version, opts.env);\n initialized = true;\n }\n\n if (currentSatisfies && !callbacks) {\n const fn = _require(workerPath);\n return typeof fn === 'function' ? fn.apply(null, args) : fn;\n }\n\n if (!functionExec) functionExec = _require('function-exec-sync');\n\n if (currentSatisfies) {\n const PATH_KEY = pathKey();\n if (opts.env && !opts.env[PATH_KEY]) {\n throw new Error(`node-version-call-local: options.env missing required ${PATH_KEY}`);\n }\n const execOptions = { execPath: process.execPath, sleep: SLEEP_MS, callbacks: true, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execPath = cachedExecPath;\n\n if (useSpawnOptions) {\n const installPath = deriveInstallPath(execPath);\n const execOptions = spawnOptions(installPath, { execPath, sleep: SLEEP_MS, callbacks, env } as SpawnOptions);\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n }\n\n const execOptions = { execPath, sleep: SLEEP_MS, callbacks, env };\n return functionExec.apply(null, [execOptions, workerPath, ...args]);\n };\n\n if (hasCallback) {\n const callback = args.pop() as CallerCallback;\n try {\n const result = execute();\n callback(null, result);\n return undefined;\n } catch (err) {\n callback(err);\n return undefined;\n }\n }\n\n return execute();\n };\n}\n"],"names":["pathKey","Module","spawnOptions","semver","deriveInstallPath","_require","require","createRequire","url","SLEEP_MS","functionExec","satisfiesSemverSync","findExecPath","version","env","options","execPath","Error","call","workerPath","args","opts","callbacks","useSpawnOptions","process","currentSatisfies","satisfies","fn","apply","PATH_KEY","execOptions","sleep","installPath","bind","initialized","cachedExecPath","boundCaller","lastArg","length","hasCallback","execute","callback","pop","result","undefined","err"],"mappings":"AAAA,OAAOA,aAAa,eAAe;AAEnC,OAAOC,YAAY,SAAS;AAE5B,SAA4BC,YAAY,QAAQ,qBAAqB;AACrE,OAAOC,YAAY,SAAS;AAC5B,OAAOC,uBAAuB,6BAA6B;AAM3D,MAAMC,WAAW,OAAOC,YAAY,cAAcL,OAAOM,aAAa,CAAC,YAAYC,GAAG,IAAIF;AAC1F,MAAMG,WAAW;AAEjB,IAAIC,eAAwC;AAC5C,IAAIC,sBAAgG;AAEpG,SAASC,aAAaC,OAAe,EAAEC,GAAuB;IAC5D,IAAI,CAACH,qBAAqBA,sBAAsBN,SAAS,kBAAkBM,mBAAmB;IAC9F,MAAMI,UAAUD,MAAM;QAAEA;IAAI,IAAI,CAAC;IACjC,MAAME,WAAWL,oBAAoBE,SAASE;IAC9C,IAAI,CAACC,UAAU;QACb,MAAM,IAAIC,MAAM,CAAC,2CAA2C,EAAEJ,QAAQ,eAAe,CAAC;IACxF;IACA,OAAOG;AACT;AAEA;;;;;;;CAOC,GACD,eAAe,SAASE,KAAKL,OAAe,EAAEM,UAAkB,EAAEJ,OAAqB,EAAE,GAAGK,IAAe;IACzG,MAAMC,OAAON,WAAW,CAAC;IACzB,MAAMO,YAAYD,KAAKC,SAAS,KAAK,MAAM,6CAA6C;IACxF,MAAMC,kBAAkBF,KAAKnB,YAAY,KAAK,OAAO,eAAe;IACpE,MAAMY,MAAMO,KAAKP,GAAG,IAAIU,QAAQV,GAAG;IAEnC,MAAMW,mBAAmBZ,YAAYW,QAAQX,OAAO,IAAIV,OAAOuB,SAAS,CAACF,QAAQX,OAAO,EAAEA;IAE1F,IAAIY,oBAAoB,CAACH,WAAW;QAClC,MAAMK,KAAKtB,SAASc;QACpB,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AImB,aAAa;YACf,MAAME,WAAWrB,KAAKsB,GAAG;YACzB,IAAI;gBACF,MAAMC,SAASH;gBACfC,SAAS,MAAME;gBACf,OAAOC;YACT,EAAE,OAAOC,KAAK;gBACZJ,SAASI;gBACT,OAAOD;YACT;QACF;QAEA,OAAOJ;IACT;AACF"}
{
"name": "node-version-call-local",
"version": "0.3.0",
"version": "0.3.1",
"description": "Call a function in a Node version found in PATH",

@@ -5,0 +5,0 @@ "keywords": [