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

Implement npm@4's prepublish behavior #1499

Closed
wants to merge 1 commit into from
Closed
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
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