Skip to content

Commit

Permalink
fix(bootstrap): Prevent recursive execution from all install lifecycles
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Jan 8, 2019
1 parent e602838 commit ea9dbbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Expand Up @@ -134,10 +134,17 @@ describe("BootstrapCommand", () => {
expect(runLifecycle).not.toHaveBeenCalled();
});

it("should not recurse from root install lifecycle", async () => {
test.each`
event
${"preinstall"}
${"install"}
${"postinstall"}
${"prepublish"}
${"prepare"}
`("should not recurse from root $event lifecycle", async ({ event }) => {
const testDir = await initFixture("lifecycle-scripts");

process.env.npm_lifecycle_event = "install";
process.env.npm_lifecycle_event = event;

await lernaBootstrap(testDir)();

Expand Down
4 changes: 2 additions & 2 deletions commands/bootstrap/index.js
Expand Up @@ -98,9 +98,9 @@ class BootstrapCommand extends Command {
}

// don't execute recursively if run from a poorly-named script
this.runRootLifecycle = /^(pre|post)?install$/.test(process.env.npm_lifecycle_event)
this.runRootLifecycle = /^(prepare|prepublish|(pre|post)?install)$/.test(process.env.npm_lifecycle_event)
? stage => {
this.logger.warn("lifecycle", "Skipping root %j because it has already been called", stage);
this.logger.info("lifecycle", "Skipping root %j because it has already been called", stage);
}
: stage => this.runPackageLifecycle(this.project.manifest, stage);

Expand Down

0 comments on commit ea9dbbe

Please sign in to comment.