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

Commit fe41e26

Browse files
committed
fix: change lifecycle order
Closes #3.
1 parent 72ad57a commit fe41e26

File tree

1 file changed

+27
-37
lines changed

1 file changed

+27
-37
lines changed

lib/index.js

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ internals.queue = (tree) => {
4747
return topo.nodes;
4848
};
4949

50+
internals.runScript = (stage, { childPkg, path, cwd }) => {
51+
52+
console.log();
53+
console.log(`==========> ${stage} ${path}...`);
54+
55+
Npm.runScript(childPkg, stage, Path.join(cwd, path), {
56+
dir: cwd,
57+
log: Object.assign({
58+
pause: () => {},
59+
clearProgress: () => {},
60+
showProgress: () => {},
61+
verbose: () => {},
62+
silly: () => {},
63+
resume: () => {}
64+
}, console),
65+
config: {}
66+
});
67+
};
68+
5069
exports.run = (cmd = 'install') => {
5170

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

59-
const allowed = pkg.allowScripts || {};
78+
const allowScripts = pkg.allowScripts || {};
6079

61-
queue
80+
const allowedScripts = queue
6281
.map((path) => {
6382

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

7493
const name = childPkg.name;
7594

76-
if (allowed[name] === undefined) {
95+
if (allowScripts[name] === undefined) {
7796
throw new Error(`No entry for ${name}`);
7897
}
7998

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

84-
return allowed[name];
85-
})
86-
.forEach(([path, childPkg]) => {
87-
88-
console.log(`==========> install ${path}...`);
89-
90-
Npm.runScript(childPkg, 'install', Path.join(cwd, path), {
91-
dir: cwd,
92-
log: Object.assign({
93-
pause: () => {},
94-
clearProgress: () => {},
95-
showProgress: () => {},
96-
verbose: () => {},
97-
silly: () => {},
98-
resume: () => {}
99-
}, console),
100-
config: {}
101-
});
102-
103-
console.log(`==========> postinstall ${path}...`);
104-
105-
Npm.runScript(childPkg, 'postinstall', Path.join(cwd, path), {
106-
dir: cwd,
107-
log: Object.assign({
108-
pause: () => {},
109-
clearProgress: () => {},
110-
showProgress: () => {},
111-
verbose: () => {},
112-
silly: () => {},
113-
resume: () => {}
114-
}, console),
115-
config: {}
116-
});
103+
return allowScripts[name];
117104
});
105+
106+
allowedScripts.forEach(([path, childPkg]) => internals.runScript('install', { childPkg, path, cwd }));
107+
allowedScripts.forEach(([path, childPkg]) => internals.runScript('postinstall', { childPkg, path, cwd }));
118108
};

0 commit comments

Comments
 (0)