Created
June 6, 2016 23:54
-
-
Save sophistifunk/9ebefcc134f47e310adfd3d077fa8c00 to your computer and use it in GitHub Desktop.
Pre-publish POC to block "npm publish" from command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
const npm_config_argv = process.env.npm_config_argv; | |
if (!npm_config_argv) { | |
console.error("This script should only be run via npm trigger -- npm_config_argv not found in ENV"); | |
process.exit(1); | |
} | |
let isInstall = false; | |
let isPublish = false; | |
// We will set the "is_running_publish_script" env in custom publish script | |
const isTriggeredByPublishScript = !!(process.env.is_running_publish_script); | |
try { | |
let command = JSON.parse(npm_config_argv) | |
.original // An array of invocation commands | |
.map(function(c){return c.toLowerCase()}); | |
isInstall = command.indexOf("install") >= 0; | |
isPublish = command.indexOf("publish") >= 0; | |
} catch (e) { | |
console.error("This script should only be run via npm trigger -- npm_config_argv is not JSON or command missing"); | |
console.error(e); | |
process.exit(1); | |
} | |
if (isPublish && !isTriggeredByPublishScript) { | |
console.error("Please run 'scripts/publish.js' instead of 'npm publish'"); | |
process.exit(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment