derive-pkg
v1.0.0
Published
A helper utility for publishing transpiled code to npm
Downloads
7
Readme
derive-pkg
A helper utility for publishing transpiled code to npm
Turn require('your-module/lib/submodule')
into require('your-module/submodule')
What is this for?
The standard convention when publishing code transpiled with Babel is to place source code into src/
and transpiled code into lib/
. Unfortunately, this makes consuming individual submodules inconvenient because they don't exist at the root of the package, e.g. one must require('the-module/lib/some-submodule.js')
.
This utility derives npm package metadata from your root directory and copies it to your build directory so you can publish it instead. Now lib/
is the root of your package!
derive-pkg
does the following:
- Copies
package.json
from root with the changes below- Rebase
main
,bin
, andbrowser
field entry paths fromlib/
to/
- Omit
devDependencies
- Rebase
- Copies files from root that npm will never ignore and should be included when publishing (e.g. readme, license, and changelog)
- Copies
.gitignore
/.npmignore
from root as.npmignore
Install
npm install derive-pkg --save-dev
Quick Example
babel-cli src -d lib
derive-pkg -d lib
npm publish lib
Usage
Usage: derive-pkg [directory] [options]
Options:
directory The base directory containing the package.json (default: ".")
--out-dir, -d The output directory for the derived package.json
--name, -n Override the name field of the derived package.json
--version, -v Override the version field of the derived package.json
FAQ
Couldn't this just be a shell script?
Yep, but derive-pkg
is cross-platform and has unit tests.