Skip to content
This repository has been archived by the owner on Aug 18, 2024. It is now read-only.

Commit

Permalink
fix: change lifecycle order
Browse files Browse the repository at this point in the history
Closes #3.
  • Loading branch information
dominykas committed Jan 29, 2019
1 parent 72ad57a commit fe41e26
Showing 1 changed file with 27 additions and 37 deletions.
64 changes: 27 additions & 37 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ internals.queue = (tree) => {
return topo.nodes;
};

internals.runScript = (stage, { childPkg, path, cwd }) => {

console.log();
console.log(`==========> ${stage} ${path}...`);

Npm.runScript(childPkg, stage, Path.join(cwd, path), {
dir: cwd,
log: Object.assign({
pause: () => {},
clearProgress: () => {},
showProgress: () => {},
verbose: () => {},
silly: () => {},
resume: () => {}
}, console),
config: {}
});
};

exports.run = (cmd = 'install') => {

const cwd = process.cwd();
Expand All @@ -56,9 +75,9 @@ exports.run = (cmd = 'install') => {
const tree = Npm.logicalTree(pkg, shrinkwrap);
const queue = internals.queue(tree);

const allowed = pkg.allowScripts || {};
const allowScripts = pkg.allowScripts || {};

queue
const allowedScripts = queue
.map((path) => {

const childPkg = require(Path.join(cwd, path, 'package.json'));
Expand All @@ -73,46 +92,17 @@ exports.run = (cmd = 'install') => {

const name = childPkg.name;

if (allowed[name] === undefined) {
if (allowScripts[name] === undefined) {
throw new Error(`No entry for ${name}`);
}

if (!allowed[name]) {
if (!allowScripts[name]) {
console.warn(`==========> skip ${path} (because it is not allowed in package.json)`);
}

return allowed[name];
})
.forEach(([path, childPkg]) => {

console.log(`==========> install ${path}...`);

Npm.runScript(childPkg, 'install', Path.join(cwd, path), {
dir: cwd,
log: Object.assign({
pause: () => {},
clearProgress: () => {},
showProgress: () => {},
verbose: () => {},
silly: () => {},
resume: () => {}
}, console),
config: {}
});

console.log(`==========> postinstall ${path}...`);

Npm.runScript(childPkg, 'postinstall', Path.join(cwd, path), {
dir: cwd,
log: Object.assign({
pause: () => {},
clearProgress: () => {},
showProgress: () => {},
verbose: () => {},
silly: () => {},
resume: () => {}
}, console),
config: {}
});
return allowScripts[name];
});

allowedScripts.forEach(([path, childPkg]) => internals.runScript('install', { childPkg, path, cwd }));
allowedScripts.forEach(([path, childPkg]) => internals.runScript('postinstall', { childPkg, path, cwd }));
};

0 comments on commit fe41e26

Please sign in to comment.