netxops/scripts/npm-cli.mjs
oliver 9b2166e5b6
Some checks failed
Release package / package (macos-latest) (push) Has been cancelled
Release package / package (ubuntu-latest) (push) Has been cancelled
Release package / package (windows-latest) (push) Has been cancelled
Harden public package installation and release validation
2026-10-11 13:32:36 +08:00

17 lines
787 B
JavaScript

/** Resolve the npm bundled with Node instead of an unrelated global npm shim. */
import assert from 'node:assert/strict'
import { existsSync } from 'node:fs'
import { dirname, join, resolve } from 'node:path'
import { spawnSync } from 'node:child_process'
export function npmRuntime() {
const node = process.versions.bun
? spawnSync('node', ['-p', 'process.execPath'], { encoding: 'utf8', windowsHide: true }).stdout.trim()
: process.execPath
const npm = [process.env.NETXOPS_NPM_CLI,
join(dirname(node), 'node_modules/npm/bin/npm-cli.js'),
resolve(dirname(node), '../lib/node_modules/npm/bin/npm-cli.js'),
].filter(Boolean).find(existsSync)
assert.ok(npm, 'Node.js must include npm to build and test the public installation package.')
return { node, npm }
}