Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds prepare & prepublishOnly lifecycle hooks #3004

Merged
merged 2 commits into from
Mar 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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