diff --git a/server/package-lock.json b/server/package-lock.json index 58b8f6c08..b5c9f5034 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -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", diff --git a/server/src/plugin/plugin-npm-dependencies.ts b/server/src/plugin/plugin-npm-dependencies.ts index e6400efaf..b16449fd9 100644 --- a/server/src/plugin/plugin-npm-dependencies.ts +++ b/server/src/plugin/plugin-npm-dependencies.ts @@ -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', });