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

Commit 77c8c4c

Browse files
committed
fix: wait for scripts to finish before running the next one
1 parent 04dd93c commit 77c8c4c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

bin/allow-scripts.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44

55
const Allow = require('..');
66

7-
Allow.run();
7+
Allow.run().catch((err) => {
8+
9+
console.error(err);
10+
process.exit(1);
11+
});

lib/index.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ internals.runScript = (stage, { childPkg, path, cwd }) => {
5252
console.log();
5353
console.log(`==========> ${stage} ${path}...`);
5454

55-
Npm.runScript(childPkg, stage, Path.join(cwd, path), {
55+
return Npm.runScript(childPkg, stage, Path.join(cwd, path), {
5656
dir: cwd,
5757
log: Object.assign({
5858
pause: () => {},
@@ -66,7 +66,7 @@ internals.runScript = (stage, { childPkg, path, cwd }) => {
6666
});
6767
};
6868

69-
exports.run = (cmd = 'install') => {
69+
exports.run = async (cmd = 'install') => {
7070

7171
const cwd = process.cwd();
7272
const pkg = require(Path.join(cwd, 'package.json'));
@@ -103,7 +103,15 @@ exports.run = (cmd = 'install') => {
103103
return allowScripts[name];
104104
});
105105

106-
allowedScripts.forEach(([path, childPkg]) => internals.runScript('preinstall', { childPkg, path, cwd }));
107-
allowedScripts.forEach(([path, childPkg]) => internals.runScript('install', { childPkg, path, cwd }));
108-
allowedScripts.forEach(([path, childPkg]) => internals.runScript('postinstall', { childPkg, path, cwd }));
106+
for (const [path, childPkg] of allowedScripts) {
107+
await internals.runScript('preinstall', { childPkg, path, cwd });
108+
}
109+
110+
for (const [path, childPkg] of allowedScripts) {
111+
await internals.runScript('install', { childPkg, path, cwd });
112+
}
113+
114+
for (const [path, childPkg] of allowedScripts) {
115+
await internals.runScript('postinstall', { childPkg, path, cwd });
116+
}
109117
};

0 commit comments

Comments
 (0)