Add pkg.bin section for commands to be run
Problem:
Currently commands need to be run from the node_modules path directly, since @linguala/common-dev-dependencies
are installed to install its dependencies, so we have an indirect dependency, which does not install into node_modules/.bin
all the tools we want to have available in pkg.scripts
.
The 'bin' section in package.json
provides a convenient way to just run the command without path with a custom alias, but has to be provided as direct dependency.
babel
for example is currently run in scripts with node_modules/babel-cli/bin/babel.js
instead of babel
. But since it is a symlink we cannot package it in that case. But we can write a 'babel.js'-file which gets packaged on npm and resolves this.
Note: the wrapper code should be written in traditional node-parseable code, no need to pull in more dependencies.
"bin": {
"ava": "./utils/server/ava.js"
}
utils/server/ava.js
// somehow wrap the call to 'node_modules/ava/bin/ava.js'
Another example from @storybook/react/package.json
:
"bin": {
"build-storybook": "./dist/server/build.js",
"start-storybook": "./dist/server/index.js",
"storybook-server": "./dist/server/index.js"
},
This lets you run the commands from the pkg.scripts
like this:
"scripts": {
"storybook": "start-storybook"
}
If the pkg.bin
-section of @storybook/react/package.json
would not be available, it would look like this:
"scripts": {
"storybook": "./dist/server/index.js"
}
Targets:
-
ava (for running unittests in development) -
babel (for running babel-transforms), mainly building to ES5 -
build (for building a lib to be transpiled, so it can be published & imported via npm/git) -
eslint (for linting the source code)