← Files Flows by plugin.spaceARCHIVED FILE
lib/node-runtime.mjs
1.52 KB · Nov 30, 2026 · 00:17 UTC
import { existsSync, realpathSync } from 'node:fs';
import { delimiter, dirname, join, resolve } from 'node:path';
export const MIN_NODE_VERSION = '22.13.0';
export const launcherCommand = command => process.platform === 'win32'
? `& "<PLUGIN_ROOT>/scripts/run.ps1" ${command}`
: `sh "<PLUGIN_ROOT>/scripts/run.sh" ${command}`;
export function supportedNodeVersion(version) {
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
if (!match) return false;
const [, major, minor] = match.map(Number);
return major > 22 || (major === 22 && minor >= 13);
}
// Execute npm's JavaScript with our Node, including on Windows where npm.cmd
// cannot be spawned directly without a shell. Never depend on a global npm.
export function findNpmCli(execPath = process.execPath, path = process.env.PATH || '', platform = process.platform) {
const bin = dirname(execPath);
const candidates = [join(bin, 'node_modules/npm/bin/npm-cli.js'), resolve(bin, '../lib/node_modules/npm/bin/npm-cli.js')];
for (const entry of path.split(delimiter).filter(Boolean)) {
if (platform === 'win32') candidates.push(join(entry, 'node_modules/npm/bin/npm-cli.js'));
else {
try { candidates.push(realpathSync(join(entry, 'npm'))); } catch { /* Not an npm installation. */ }
}
}
return candidates.find(file => file.endsWith(`${platform === 'win32' ? '\\' : '/'}npm-cli.js`) && existsSync(file)) || null;
}
export function nodeEnvironment() {
return { ...process.env, PATH: `${dirname(process.execPath)}${delimiter}${process.env.PATH || ''}` };
}
SHA-256: 23a77e7dd90d9ede3cb0527a9c2117543e52c1dee5806e8d169c592891ec5788