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

Commit 5728a44

Browse files
committed
feat: add --dry-run
Closes #14
1 parent 6169171 commit 5728a44

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

bin/allow-scripts.js

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

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

7-
Allow.run().catch((err) => {
7+
const options = {
8+
dryRun: process.argv.includes('--dry-run')
9+
};
10+
11+
Allow.run(options).catch((err) => {
812

913
console.error(err);
1014
process.exit(1);

lib/index.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,16 @@ internals.queue = (tree) => {
4848
return topo.nodes;
4949
};
5050

51-
internals.runScript = (stage, { pkg, path, cwd, unsafePerm }) => {
51+
internals.runScript = (stage, { pkg, path, cwd, unsafePerm }, options) => {
5252

5353
console.log();
54-
console.log(`==========> ${stage} ${path || pkg.name}...`);
5554

55+
if (options.dryRun) {
56+
console.log(`DRY RUN ==> ${stage} ${path || pkg.name}...`);
57+
return;
58+
}
59+
60+
console.log(`==========> ${stage} ${path || pkg.name}...`);
5661
return Npm.runScript(pkg, stage, Path.join(cwd, path), {
5762
dir: cwd,
5863
unsafePerm, // @todo: find an official way to do this for top level package
@@ -95,7 +100,7 @@ internals.getLockFile = (cwd) => {
95100
}
96101
};
97102

98-
exports.run = async (cmd = 'install') => {
103+
exports.run = async (options) => {
99104

100105
const cwd = process.cwd();
101106
const pkg = require(Path.join(cwd, 'package.json'));
@@ -116,7 +121,7 @@ exports.run = async (cmd = 'install') => {
116121
})
117122
.filter(({ childPkg }) => {
118123

119-
return childPkg.scripts && (childPkg.scripts[cmd] || childPkg.scripts[`pre${cmd}`] || childPkg.scripts[`post${childPkg}`]);
124+
return childPkg.scripts && (childPkg.scripts.install || childPkg.scripts.preinstall || childPkg.scripts.postinstall);
120125
})
121126
.filter(({ path, childPkg }) => {
122127

@@ -133,22 +138,22 @@ exports.run = async (cmd = 'install') => {
133138
return allowScripts[name];
134139
});
135140

136-
await internals.runScript('preinstall', { pkg, path: '', cwd, unsafePerm: true });
141+
await internals.runScript('preinstall', { pkg, path: '', cwd, unsafePerm: true }, options);
137142

138143
for (const { path, childPkg } of allowedScripts) {
139-
await internals.runScript('preinstall', { pkg: childPkg, path, cwd });
144+
await internals.runScript('preinstall', { pkg: childPkg, path, cwd }, options);
140145
}
141146

142147
for (const { path, childPkg } of allowedScripts) {
143-
await internals.runScript('install', { pkg: childPkg, path, cwd });
148+
await internals.runScript('install', { pkg: childPkg, path, cwd }, options);
144149
}
145150

146151
for (const { path, childPkg } of allowedScripts) {
147-
await internals.runScript('postinstall', { pkg: childPkg, path, cwd });
152+
await internals.runScript('postinstall', { pkg: childPkg, path, cwd }, options);
148153
}
149154

150-
await internals.runScript('install', { pkg, path: '', cwd, unsafePerm: true });
151-
await internals.runScript('postinstall', { pkg, path: '', cwd, unsafePerm: true });
152-
await internals.runScript('prepublish', { pkg, path: '', cwd, unsafePerm: true });
153-
await internals.runScript('prepare', { pkg, path: '', cwd, unsafePerm: true });
155+
await internals.runScript('install', { pkg, path: '', cwd, unsafePerm: true }, options);
156+
await internals.runScript('postinstall', { pkg, path: '', cwd, unsafePerm: true }, options);
157+
await internals.runScript('prepublish', { pkg, path: '', cwd, unsafePerm: true }, options);
158+
await internals.runScript('prepare', { pkg, path: '', cwd, unsafePerm: true }, options);
154159
};

0 commit comments

Comments
 (0)