@randy.tarampi/install-dependencies
Version:
Builds node modules to a spectified path 📦
60 lines • 2.98 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.installDependencies = void 0;
const tslib_1 = require("tslib");
const fs = tslib_1.__importStar(require("fs"));
const child_process_1 = require("child_process");
const path_1 = tslib_1.__importDefault(require("path"));
function installDependencies({ config, dest, debug = false, process = null, }) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
if (!config) {
if (debug)
console.error({
'@monorepo-utilities/install-dependencies:error:config': config,
});
if (process)
process.exit(1);
}
const configPath = path_1.default.resolve(process.cwd(), config);
const configJson = fs.existsSync(configPath) ? fs.readFileSync(configPath).toString() : '';
const jsonContent = JSON.parse(configJson);
if (!jsonContent || typeof jsonContent !== 'object') {
if (debug)
console.error({
'@monorepo-utilities/install-dependencies:error:packageJsonContent': jsonContent,
});
if (process)
process.exit(1);
}
/**
* Bread and butter 🍞 🧈
* --------------------------------
* @description construct a dependency list
* 1. dependencies
* 2. filter packages to be ignored
* 3. spread in packages to include
* --------------------------------
* @note ignored packages may not have a version!
* @note packages to include will override dependencies!
*/
const { dependencies = {}, installDependencies: { ignore = [], include = {} } = {} } = jsonContent;
const dependenciesToInclude = Object.keys(include);
const filteredDependencyList = Object.entries(dependencies)
.filter((dependency) => {
const isIgnoredDependency = ignore.some((itemToIgnore) => dependency[0] === itemToIgnore);
const isPriorityIncludedDependency = dependenciesToInclude.some((dependencyToInclude) => dependency[0] === dependencyToInclude);
return !isIgnoredDependency && !isPriorityIncludedDependency;
})
.map((dependency) => dependency.join('@'));
const priorityDependencyList = Object.entries(include).map((dependency) => dependency.join('@'));
const dependenciesToInstall = [...filteredDependencyList, ...priorityDependencyList];
yield Promise.all(dependenciesToInstall.map((dependency) => tslib_1.__awaiter(this, void 0, void 0, function* () { return yield child_process_1.exec(`npm install --prefix ${dest} ${dependency} -S`); })));
return {
deependenciesInstalled: dependenciesToInstall,
config,
dest,
};
});
}
exports.installDependencies = installDependencies;
//# sourceMappingURL=install-dependencies.js.map