Skip to content

Commit

Permalink
Adds prepare & prepublishOnly lifecycle hooks (yarnpkg#3004)
Browse files Browse the repository at this point in the history
* Adds prepare & prepublishOnly lifecycle hooks

* Adds tests
  • Loading branch information
arcanis authored and bestander committed Mar 28, 2017
1 parent 0ce2d81 commit 9a743d7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "lifecycle-scripts",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"prepublish": "echo running the prepublish hook",
"prepublishOnly": "echo running the prepublishOnly hook",
"prepare": "echo running the prepare hook"
}
}
9 changes: 9 additions & 0 deletions __tests__/lifecycle-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ test('should only expose non-internal configs', async () => {
expect(val).toBeDefined();
});
});

test('should run both prepublish and prepare when installing, but not prepublishOnly', async () => {
let stdout = await execCommand('install', 'lifecycle-scripts');

expect(stdout).toMatch(/^running the prepublish hook$/m);
expect(stdout).toMatch(/^running the prepare hook$/m);

expect(stdout).not.toMatch(/^running the prepublishOnly hook$/m);
});
1 change: 1 addition & 0 deletions src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,6 @@ export async function wrapLifecycle(config: Config, flags: Object, factory: () =

if (!config.production) {
await config.executeLifecycleScript('prepublish');
await config.executeLifecycleScript('prepare');
}
}
2 changes: 2 additions & 0 deletions src/cli/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ async function publish(

// TODO this might modify package.json, do we need to reload it?
await config.executeLifecycleScript('prepublish');
await config.executeLifecycleScript('prepublishOnly');
await config.executeLifecycleScript('prepare');

// create body
const root = {
Expand Down

0 comments on commit 9a743d7

Please sign in to comment.