Skip to content

Commit

Permalink
Implement npm@4's prepublish behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo Franco (Kovensky) committed Nov 5, 2016
1 parent ea35fe9 commit e169b7b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ export async function run(
await wrapLifecycle(config, flags, async () => {
const install = new Install(flags, config, reporter, lockfile);
await install.init();

if (await config.hasLifecycleScript('prepublish')) {
reporter.warn(reporter.lang('prepublishOnInstall'));
}
});
}

Expand All @@ -707,5 +711,6 @@ export async function wrapLifecycle(config: Config, flags: Object, factory: () =

if (!flags.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
17 changes: 17 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,23 @@ export default class Config {
}
}

/**
* Returns whether the given lifecycle script is defined in the manifest.
* Always false when --ignore-scripts has been passed.
*/

async hasLifecycleScript(commandName: string, cwd?: string): Promise<bool> {
if (this.ignoreScripts) {
return false;
} else {
const pkg = await this.readManifest(cwd || this.cwd);
if (!pkg.scripts) {
return false;
}
return commandName in pkg.scripts;
}
}

/**
* Generate an absolute temporary filename location based on the input filename.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ const messages = {
fetchBadHash: 'Bad hash. Expected $0 but got $1 ',
fetchErrorCorrupt: '$0. Mirror tarball appears to be corrupt. You can resolve this by running:\n\n $ rm -rf $1\n $ yarn install',
errorDecompressingTarball: '$0. Error decompressing $1, it appears to be corrupt.',

prepublishOnInstall: '`prepublish` on install is deprecated and will stop running in the future.',
};

export type LanguageKeys = $Keys<typeof messages>;
Expand Down

0 comments on commit e169b7b

Please sign in to comment.