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.

61 lines
2.4 KiB

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BasePackageManager = void 0;
const spawn_async_1 = __importDefault(require("@expo/spawn-async"));
const assert_1 = __importDefault(require("assert"));
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
class BasePackageManager {
constructor({ silent, log, env = process.env, ...options } = {}) {
this.silent = !!silent;
this.log = log ?? (!silent ? console.log : undefined);
this.options = {
stdio: silent ? undefined : 'inherit',
...options,
env: { ...this.getDefaultEnvironment(), ...env },
};
}
/** Get the default environment variables used when running the package manager. */
getDefaultEnvironment() {
return {
ADBLOCK: '1',
DISABLE_OPENCOLLECTIVE: '1',
};
}
/** Ensure the CWD is set to a non-empty string */
ensureCwdDefined(method) {
const cwd = this.options.cwd?.toString();
const className = this.constructor.name;
const methodName = method ? `.${method}` : '';
(0, assert_1.default)(cwd, `cwd is required for ${className}${methodName}`);
return cwd;
}
runAsync(command) {
this.log?.(`> ${this.name} ${command.join(' ')}`);
return (0, spawn_async_1.default)(this.bin, command, this.options);
}
async versionAsync() {
return await this.runAsync(['--version']).then(({ stdout }) => stdout.trim());
}
async getConfigAsync(key) {
return await this.runAsync(['config', 'get', key]).then(({ stdout }) => stdout.trim());
}
async removeLockfileAsync() {
const cwd = this.ensureCwdDefined('removeLockFile');
const filePath = path_1.default.join(cwd, this.lockFile);
await fs_1.default.promises.rm(filePath, { force: true });
}
installAsync(flags = []) {
return this.runAsync(['install', ...flags]);
}
async uninstallAsync() {
const cwd = this.ensureCwdDefined('uninstallAsync');
const modulesPath = path_1.default.join(cwd, 'node_modules');
await fs_1.default.promises.rm(modulesPath, { force: true, recursive: true });
}
}
exports.BasePackageManager = BasePackageManager;
//# sourceMappingURL=BasePackageManager.js.map