Skip to content

Commit

Permalink
fix(bootstrap): Remove fancy root lifecycle execution, it was foolish
Browse files Browse the repository at this point in the history
Fixes #1857
  • Loading branch information
evocateur committed Jan 9, 2019
1 parent 51fe2c4 commit 9f80722
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 51 deletions.
30 changes: 4 additions & 26 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Expand Up @@ -88,13 +88,9 @@ describe("BootstrapCommand", () => {
await lernaBootstrap(testDir)();

expect(runLifecycle.getOrderedCalls()).toEqual([
["root", "preinstall"],
["package-preinstall", "preinstall"],
["package-postinstall", "postinstall"],
["root", "install"],
["root", "postinstall"],
["package-prepublish", "prepublish"],
["root", "prepare"],
]);
});

Expand All @@ -103,7 +99,10 @@ describe("BootstrapCommand", () => {

await lernaBootstrap(testDir)("--ignore-prepublish");

expect(runLifecycle.getOrderedCalls()).not.toContainEqual(["package-prepublish", "prepublish"]);
expect(runLifecycle.getOrderedCalls()).toEqual([
["package-preinstall", "preinstall"],
["package-postinstall", "postinstall"],
]);
});

it("shouldn't run lifecycle scripts with --ignore-scripts", async () => {
Expand Down Expand Up @@ -133,27 +132,6 @@ describe("BootstrapCommand", () => {

expect(runLifecycle).not.toHaveBeenCalled();
});

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 = event;

await lernaBootstrap(testDir)();

expect(runLifecycle.getOrderedCalls()).toEqual([
["package-preinstall", "preinstall"],
["package-postinstall", "postinstall"],
["package-prepublish", "prepublish"],
]);
});
});

describe("with hoisting", () => {
Expand Down
30 changes: 5 additions & 25 deletions commands/bootstrap/index.js
Expand Up @@ -97,13 +97,6 @@ class BootstrapCommand extends Command {
this.npmConfig.npmClientArgs.unshift("--ignore-scripts");
}

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

this.targetGraph = this.options.forceLocal
? new PackageGraph(this.packageGraph.rawPackageList, "allDependencies", "forceLocal")
: this.packageGraph;
Expand Down Expand Up @@ -150,11 +143,7 @@ class BootstrapCommand extends Command {
const tasks = [];

if (scriptsEnabled) {
tasks.push(
// preinstall scripts run in root before all leaves
() => this.runRootLifecycle("preinstall"),
() => this.runLifecycleInPackages("preinstall")
);
tasks.push(() => this.runLifecycleInPackages("preinstall"));
}

tasks.push(
Expand All @@ -165,25 +154,16 @@ class BootstrapCommand extends Command {

if (scriptsEnabled) {
tasks.push(
// {,post}install scripts run in all leaves before root
() => this.runLifecycleInPackages("install"),
() => this.runLifecycleInPackages("postinstall"),
() => this.runRootLifecycle("install"),
() => this.runRootLifecycle("postinstall")
() => this.runLifecycleInPackages("postinstall")
);

if (!this.options.ignorePrepublish) {
tasks.push(
() => this.runLifecycleInPackages("prepublish"),
() => this.runRootLifecycle("prepublish")
);
tasks.push(() => this.runLifecycleInPackages("prepublish"));
}

tasks.push(
// "run on local npm install without any arguments", AFTER prepublish
() => this.runLifecycleInPackages("prepare"),
() => this.runRootLifecycle("prepare")
);
// "run on local npm install without any arguments", AFTER prepublish
tasks.push(() => this.runLifecycleInPackages("prepare"));
}

return pWaterfall(tasks).then(() => {
Expand Down

0 comments on commit 9f80722

Please sign in to comment.