Skip to content

Commit

Permalink
build: sniff npm publish for npm v7
Browse files Browse the repository at this point in the history
  • Loading branch information
sgtcoolguy committed Mar 12, 2021
1 parent 23bbbc2 commit d1322f6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions bin/build-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ let isPublish = false;

// Determine if we got invoked via an `npm prepare` through `npm publish`
if (process.env.npm_lifecycle_event === 'prepare') {
const argv = JSON.parse(process.env.npm_config_argv);
isPublish = argv.cooked.indexOf('publish') !== -1;
if (process.env.npm_command) { // npm v7+
isPublish = process.env.npm_command === 'publish';
} else if (process.env.npm_config_argv) { // npm v6-
const argv = JSON.parse(process.env.npm_config_argv);
isPublish = argv.cooked.indexOf('publish') !== -1;
} else { // future-proof if npm changes again
console.error('Unable to determine if `npm prepare` was called indirectly via `npm publish`. Has npm changed?');
process.exit(1);
}

if (isPublish) {
actions.push('package');
}
Expand Down

0 comments on commit d1322f6

Please sign in to comment.