July 2017
Intermediate to advanced
656 pages
16h 1m
English
Along with arbitrary commands and the special test field, the scripts section of the package.json file supports hooks.
The prepublish field can be useful for catching mistakes before we send our code out into the world.
Let's add a prepublish script that runs npm ls and npm test:
"scripts": { "prepublish": "npm ls && npm test", "test": "npm run lint && tap --cov test", "lint": "standard"},
Now, npm should check for extraneous dependencies, run our linter, and run our test suite automatically before each publish.
Let's test it real quick by adding an extraneous dependency, as in the preceding section.
This time, our extraneous dependency ...