diff --git a/__tests__/fixtures/lifecycle-scripts/lifecycle-scripts/package.json b/__tests__/fixtures/lifecycle-scripts/lifecycle-scripts/package.json new file mode 100644 index 0000000000..482a59e4e4 --- /dev/null +++ b/__tests__/fixtures/lifecycle-scripts/lifecycle-scripts/package.json @@ -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" + } +} diff --git a/__tests__/lifecycle-scripts.js b/__tests__/lifecycle-scripts.js index e8a9c767af..791d14b459 100644 --- a/__tests__/lifecycle-scripts.js +++ b/__tests__/lifecycle-scripts.js @@ -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); +}); diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 79593bf86b..7301c032e0 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -784,5 +784,6 @@ export async function wrapLifecycle(config: Config, flags: Object, factory: () = if (!config.production) { await config.executeLifecycleScript('prepublish'); + await config.executeLifecycleScript('prepare'); } } diff --git a/src/cli/commands/publish.js b/src/cli/commands/publish.js index 81cf014c6b..5e6368040f 100644 --- a/src/cli/commands/publish.js +++ b/src/cli/commands/publish.js @@ -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 = {