1"use strict"; 2var __importDefault = (this && this.__importDefault) || function (mod) { 3 return (mod && mod.__esModule) ? mod : { "default": mod }; 4}; 5Object.defineProperty(exports, "__esModule", { value: true }); 6exports.BasePackageManager = void 0; 7const spawn_async_1 = __importDefault(require("@expo/spawn-async")); 8const assert_1 = __importDefault(require("assert")); 9const fs_1 = __importDefault(require("fs")); 10const path_1 = __importDefault(require("path")); 11class BasePackageManager { 12 silent; 13 log; 14 options; 15 constructor({ silent, log, env = process.env, ...options } = {}) { 16 this.silent = !!silent; 17 this.log = log ?? (!silent ? console.log : undefined); 18 this.options = { 19 stdio: silent ? undefined : 'inherit', 20 ...options, 21 env: { ...this.getDefaultEnvironment(), ...env }, 22 }; 23 } 24 /** Get the default environment variables used when running the package manager. */ 25 getDefaultEnvironment() { 26 return { 27 ADBLOCK: '1', 28 DISABLE_OPENCOLLECTIVE: '1', 29 }; 30 } 31 /** Ensure the CWD is set to a non-empty string */ 32 ensureCwdDefined(method) { 33 const cwd = this.options.cwd?.toString(); 34 const className = this.constructor.name; 35 const methodName = method ? `.${method}` : ''; 36 (0, assert_1.default)(cwd, `cwd is required for ${className}${methodName}`); 37 return cwd; 38 } 39 runAsync(command) { 40 this.log?.(`> ${this.name} ${command.join(' ')}`); 41 return (0, spawn_async_1.default)(this.bin, command, this.options); 42 } 43 async versionAsync() { 44 return await this.runAsync(['--version']).then(({ stdout }) => stdout.trim()); 45 } 46 async getConfigAsync(key) { 47 return await this.runAsync(['config', 'get', key]).then(({ stdout }) => stdout.trim()); 48 } 49 async removeLockfileAsync() { 50 const cwd = this.ensureCwdDefined('removeLockFile'); 51 const filePath = path_1.default.join(cwd, this.lockFile); 52 await fs_1.default.promises.rm(filePath, { force: true }); 53 } 54 installAsync(flags = []) { 55 return this.runAsync(['install', ...flags]); 56 } 57 async uninstallAsync() { 58 const cwd = this.ensureCwdDefined('uninstallAsync'); 59 const modulesPath = path_1.default.join(cwd, 'node_modules'); 60 await fs_1.default.promises.rm(modulesPath, { force: true, recursive: true }); 61 } 62} 63exports.BasePackageManager = BasePackageManager; 64//# sourceMappingURL=BasePackageManager.js.map