server: add hook for npm exec in non-node environment (electron)

This commit is contained in:
Koushik Dutta
2023-04-06 08:21:37 -07:00
parent 7abdb06b66
commit ce2ea63be7
2 changed files with 16 additions and 6 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@scrypted/server",
"version": "0.7.46",
"version": "0.7.47",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@scrypted/server",
"version": "0.7.46",
"version": "0.7.47",
"license": "ISC",
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",

View File

@@ -9,6 +9,19 @@ import rimraf from "rimraf";
import semver from 'semver';
import { ensurePluginVolume } from "./plugin-volume";
export function defaultNpmExec(args: string[], options: child_process.SpawnOptions) {
let npm = 'npm';
if (os.platform() === 'win32')
npm += '.cmd';
const cp = child_process.spawn(npm, args, options);
return cp;
}
let npmExecFunction = defaultNpmExec;
export function setNpmExecFunction(f: typeof npmExecFunction) {
npmExecFunction = f;
}
export function getPluginNodePath(name: string) {
const pluginVolume = ensurePluginVolume(name);
const nodeMajorVersion = semver.parse(process.version).major;
@@ -56,10 +69,7 @@ export async function installOptionalDependencies(console: Console, packageJson:
mkdirp.sync(nodePrefix);
fs.writeFileSync(packageJsonPath, JSON.stringify(reduced));
let npm = 'npm';
if (os.platform() === 'win32')
npm += '.cmd';
const cp = child_process.spawn(npm, ['--prefix', nodePrefix, 'install'], {
const cp = npmExecFunction(['--prefix', nodePrefix, 'install'], {
cwd: nodePrefix,
stdio: 'inherit',
});