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.1.0
to
0.2.0
+5
-35
dist/cjs/index.js

@@ -39,15 +39,2 @@ "use strict";

}
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _interop_require_default(obj) {

@@ -64,17 +51,2 @@ return obj && obj.__esModule ? obj : {

}
function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
}
return target;
}
function _to_consumable_array(arr) {

@@ -109,7 +81,7 @@ return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();

var opts = options || {};
var callbacks = opts.callbacks !== false; // default true
var callbacks = opts.callbacks === true; // default false (matches function-exec-sync)
var useSpawnOptions = opts.spawnOptions === true; // default false
var env = opts.env || process.env;
// Check if current process satisfies the version constraint
var currentSatisfies = _semver.default.satisfies(process.version, version);
var currentSatisfies = version === process.version || _semver.default.satisfies(process.version, version);
if (currentSatisfies) {

@@ -167,6 +139,4 @@ // Local execution

function bind(version, workerPath, options) {
var opts = _object_spread({
callbacks: true
}, options);
var callbacks = opts.callbacks !== false;
var opts = options || {};
var callbacks = opts.callbacks === true; // default false (matches function-exec-sync)
var useSpawnOptions = opts.spawnOptions === true;

@@ -188,3 +158,3 @@ var env = opts.env || process.env;

if (!initialized) {
currentSatisfies = _semver.default.satisfies(process.version, version);
currentSatisfies = version === process.version || _semver.default.satisfies(process.version, version);
if (!currentSatisfies) {

@@ -191,0 +161,0 @@ cachedExecPath = findExecPath(version, opts.env);

+1
-1

@@ -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 !== false; // default true\n const useSpawnOptions = opts.spawnOptions === true; // default false\n const env = opts.env || process.env;\n\n // Check if current process satisfies the version constraint\n const currentSatisfies = 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 = { callbacks: true, ...options };\n const callbacks = opts.callbacks !== false;\n const useSpawnOptions = opts.spawnOptions === 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 = 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;A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,WAAAA;gBAAWR,KAAAA;YAAI;YAChE,OAAOqB,aAAaF,KAAK,CAAC,MAAM;gBAACF;gBAAaZ;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\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 === true; // default false\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 === 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,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AAa;oBAAEnB,UAAAA;oBAAUe,OAAOrB;oBAAUW,WAAAA;oBAAWR,KAAAA;gBAAI;gBAC1F,OAAOqB,aAAaF,KAAK,CAAC,MAAM;oBAACF;oBAAaZ;iBAAoB,CAAlC,OAA0B,qBAAGC;YAC/D;YAEA,IAAMW,eAAc;gBAAEd,UAAAA;gBAAUe,OAAOrB;gBAAUW,WAAAA;gBAAWR,KAAAA;YAAI;YAChE,OAAOqB,aAAaF,KAAK,CAAC,MAAM;gBAACF;gBAAaZ;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"}

@@ -28,7 +28,7 @@ import pathKey from 'env-path-key';

const opts = options || {};
const callbacks = opts.callbacks !== false; // default true
const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)
const useSpawnOptions = opts.spawnOptions === true; // default false
const env = opts.env || process.env;
// Check if current process satisfies the version constraint
const currentSatisfies = semver.satisfies(process.version, version);
const currentSatisfies = version === process.version || semver.satisfies(process.version, version);
if (currentSatisfies) {

@@ -97,7 +97,4 @@ // Local execution

*/ export function bind(version, workerPath, options) {
const opts = {
callbacks: true,
...options
};
const callbacks = opts.callbacks !== false;
const opts = options || {};
const callbacks = opts.callbacks === true; // default false (matches function-exec-sync)
const useSpawnOptions = opts.spawnOptions === true;

@@ -116,3 +113,3 @@ const env = opts.env || process.env;

if (!initialized) {
currentSatisfies = semver.satisfies(process.version, version);
currentSatisfies = version === process.version || semver.satisfies(process.version, version);
if (!currentSatisfies) {

@@ -119,0 +116,0 @@ cachedExecPath = findExecPath(version, opts.env);

@@ -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 !== false; // default true\n const useSpawnOptions = opts.spawnOptions === true; // default false\n const env = opts.env || process.env;\n\n // Check if current process satisfies the version constraint\n const currentSatisfies = 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 = { callbacks: true, ...options };\n const callbacks = opts.callbacks !== false;\n const useSpawnOptions = opts.spawnOptions === 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 = 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,IAA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oBACxF,OAAO,AAACP,SAAS,sBAAkDwB,KAAK,CAAC,MAAM;wBAACF;wBAAaT;2BAAeC;qBAAK;gBACnH;gBACA,MAAMW,KAAKzB,SAASa;gBACpB,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\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 === true; // default false\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 === 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;IACzG,MAAMC,OAAON,WAAW,CAAC;IACzB,MAAMO,YAAYD,KAAKC,SAAS,KAAK,MAAM,6C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;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"}
{
"name": "node-version-call-local",
"version": "0.1.0",
"version": "0.2.0",
"description": "Call a function in a Node version found in PATH",

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