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

Commit 964ff7e

Browse files
committed
fix: call runScript only when relevant script exists for main package
1 parent d36866a commit 964ff7e

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

lib/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ internals.queue = (tree) => {
5151

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

54+
if (!pkg.scripts || !pkg.scripts[stage]) {
55+
return;
56+
}
57+
5458
console.log();
5559

5660
if (options.dryRun) {
@@ -154,21 +158,15 @@ exports.run = async (options) => {
154158
await internals.runScript('preinstall', { pkg, path: '', cwd, unsafePerm: true }, options);
155159

156160
for (const { path, childPkg } of allowedPackages) {
157-
if (childPkg.scripts.preinstall) {
158-
await internals.runScript('preinstall', { pkg: childPkg, path, cwd }, options);
159-
}
161+
await internals.runScript('preinstall', { pkg: childPkg, path, cwd }, options);
160162
}
161163

162164
for (const { path, childPkg } of allowedPackages) {
163-
if (childPkg.scripts.install) {
164-
await internals.runScript('install', { pkg: childPkg, path, cwd }, options);
165-
}
165+
await internals.runScript('install', { pkg: childPkg, path, cwd }, options);
166166
}
167167

168168
for (const { path, childPkg } of allowedPackages) {
169-
if (childPkg.scripts.postinstall) {
170-
await internals.runScript('postinstall', { pkg: childPkg, path, cwd }, options);
171-
}
169+
await internals.runScript('postinstall', { pkg: childPkg, path, cwd }, options);
172170
}
173171

174172
await internals.runScript('install', { pkg, path: '', cwd, unsafePerm: true }, options);

test/fixtures/deep.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"@example/basic": "*",
77
"@example/with-preinstall-script": "*"
88
},
9+
"scripts": {},
910
"allowScripts": {
1011
"@example/basic": "*",
1112
"@example/with-preinstall-script": "*",

test/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ describe('allow-scripts', () => {
7676
await Allow.run({});
7777

7878
expect(fixture.getActualResult()).to.equal(Fixtures.expectedResults.deep);
79-
expect(fixture.getLog()).not.to.contain('without-scripts');
80-
expect(fixture.getLog()).not.to.contain('without-install-scripts');
79+
80+
const log = fixture.getLog();
81+
expect(log).not.to.contain('without-scripts');
82+
expect(log).not.to.contain('without-install-scripts');
83+
expect(log).not.to.contain('install @example/deep');
8184
});
8285

8386
it('executes allowed scripts (skips cycles)', async () => {

0 commit comments

Comments
 (0)