Skip to content

Commit

Permalink
Add a warning if the user is trying to use lockspot in postinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
chee committed May 28, 2019
1 parent 8c8ba53 commit 02779db
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions index.js
Expand Up @@ -2,17 +2,38 @@
import path from "path"
import yargs from "yargs"

let lifecycleWarningMessage = `
Hey! it looks like you're running lockspot in the "postinstall" or "install"
hook! this can create some confusion, because the package-lock may not have been
generated yet!
to prevent this, you can use the "postshrinkwrap" lifecycle hook instead, like
this:
"scripts": {
"postshrinkwrap": "lockspot ${process.argv.slice(2).join(' ')}"
}
See this issue for further info: https://github.com/npm/npm/issues/18798
`

switch (process.env.npm_lifecycle_event) {
case "postinstall":
case "install": {
process.stderr.write(lifecycleWarningMessage)
}
}

let commandDir = path.resolve(__dirname, "commands")

yargs
.option("file", {
describe: "the package-lock.json to operate on",
type: "string"
type: "string",
})
.commandDir(commandDir)
.demandCommand()
.help()
.epilogue("💖 🐕")
.showHelpOnFail(false)
.strict()
.argv
.strict().argv

0 comments on commit 02779db

Please sign in to comment.