You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.5 KiB
45 lines
1.5 KiB
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.spawnChild = void 0;
|
|
const path_1 = __importDefault(require("path"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const execa_1 = require("execa");
|
|
const global_packages_path_1 = require("./global-packages-path");
|
|
const webpack_cli_1 = require("webpack-cli");
|
|
const { getPackageManager } = webpack_cli_1.utils;
|
|
/**
|
|
*
|
|
* Spawns a new process using the respective package manager
|
|
*
|
|
* @param {String} pkg - The dependency to be installed
|
|
* @param {Boolean} isNew - indicates if it needs to be updated or installed
|
|
* @returns {Function} spawn - Installs the package
|
|
*/
|
|
function spawnWithArg(pkg, isNew) {
|
|
const packageManager = getPackageManager();
|
|
let options = [];
|
|
if (packageManager === 'npm') {
|
|
options = [isNew ? 'install' : 'update', '-g', pkg];
|
|
}
|
|
else {
|
|
options = ['global', isNew ? 'add' : 'upgrade', pkg];
|
|
}
|
|
return execa_1.sync(packageManager, options, {
|
|
stdio: 'inherit',
|
|
});
|
|
}
|
|
/**
|
|
*
|
|
* Spawns a new process
|
|
*
|
|
*/
|
|
function spawnChild(pkg) {
|
|
const rootPath = global_packages_path_1.getPathToGlobalPackages();
|
|
const pkgPath = path_1.default.resolve(rootPath, pkg);
|
|
const isNew = !fs_1.default.existsSync(pkgPath);
|
|
return spawnWithArg(pkg, isNew);
|
|
}
|
|
exports.spawnChild = spawnChild;
|
|
|