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

Commit

Permalink
fix: call runScript only when relevant script exists for main package
Browse files Browse the repository at this point in the history
  • Loading branch information
dominykas committed Feb 11, 2019
1 parent d36866a commit 964ff7e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 7 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ internals.queue = (tree) => {

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

if (!pkg.scripts || !pkg.scripts[stage]) {
return;
}

console.log();

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

for (const { path, childPkg } of allowedPackages) {
if (childPkg.scripts.preinstall) {
await internals.runScript('preinstall', { pkg: childPkg, path, cwd }, options);
}
await internals.runScript('preinstall', { pkg: childPkg, path, cwd }, options);
}

for (const { path, childPkg } of allowedPackages) {
if (childPkg.scripts.install) {
await internals.runScript('install', { pkg: childPkg, path, cwd }, options);
}
await internals.runScript('install', { pkg: childPkg, path, cwd }, options);
}

for (const { path, childPkg } of allowedPackages) {
if (childPkg.scripts.postinstall) {
await internals.runScript('postinstall', { pkg: childPkg, path, cwd }, options);
}
await internals.runScript('postinstall', { pkg: childPkg, path, cwd }, options);
}

await internals.runScript('install', { pkg, path: '', cwd, unsafePerm: true }, options);
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/deep.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@example/basic": "*",
"@example/with-preinstall-script": "*"
},
"scripts": {},
"allowScripts": {
"@example/basic": "*",
"@example/with-preinstall-script": "*",
Expand Down
7 changes: 5 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ describe('allow-scripts', () => {
await Allow.run({});

expect(fixture.getActualResult()).to.equal(Fixtures.expectedResults.deep);
expect(fixture.getLog()).not.to.contain('without-scripts');
expect(fixture.getLog()).not.to.contain('without-install-scripts');

const log = fixture.getLog();
expect(log).not.to.contain('without-scripts');
expect(log).not.to.contain('without-install-scripts');
expect(log).not.to.contain('install @example/deep');
});

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

0 comments on commit 964ff7e

Please sign in to comment.