Opinioned scripts for maintaing npm module. Includes linting, testing, transpiling, type checking.
It's like create-react-app
, but for packages or librarires.
To install or update run
npx nmx init
in your package folder.
module-scripts
assumes that your source is stored under src
folder.
Caution: for now it formats the source code with tabs on and semicolons off. Other options are in TODO.
Basically your package.json
starts to look like
"main": "dist/commonjs/index.js",
"module": "dist/module/index.js",
"esnext": "dist/esnext/index.js",
"scripts": {
"compile": "nmx compile",
"clean": "nmx clean",
"types": "nmx types",
"build": "nmx build",
"lint": "nmx lint",
"lint:fix": "nmx lint:fix",
"lint:ci": "nmx lint:ci",
"test": "nmx test",
"test:debug": "nmx test:debug",
"coverage": "nmx coverage",
"prepack": "nmx prepack",
"prepublishOnly": "nmx prepublishOnly"
},
"devDependencies": {
"module-scripts": "...",
No more transpilers, linters and other common noise in devDependencies
.
module-scripts
will add absent scripts for you, but existing scripts you should update manually.
Usage: module-scripts <command>
Compiles the content of the src
folder and creates three folders with compiled stuff. Supports babel macros.
-
dist/commonjs/
transplies imports torequire
and most of modern syntax. -
dist/module/
transplies less syntax and preserves imports. -
dist/esnext/
preserves as much as possible, but still transpiles to standard javascript. Mostly removes type declarations.
Removes dist
folder.
Runs typescript
for type checking and generates type definitions in dist/types/
.
Cleans the folder, lints, compiles and type checks the code.
Checks for lint errors.
Prettifies the code.
Like lint
, but treats all warnings as errors. For CI and prepublishing script.
Runs tests.
Runs tests in debug mode. Opens browser debug tools. Do not forget to insert debug
statement in your test somewhere for break point.
Calculates test coverage.
Builds module after installation from source, e.g. from github and before publishing your package.
Lints the code before incrementing the package version.
Lints and tests to ensure all is ok before publishing.
Pushes commits to remote git.