Small CLI to help to split big JS codebases into packages.
Moves dirs, creates boilerplate and creates the "dependencies" field of the new package with these benefits:
- 🧹 dependencies used in the code but missing from the package.json are added.
- ➕ only dependencies used in the code are listed.
- ➖ dependencies not used in the code are removed.
Node.js v16.13 or newer is required.
Via the yarn client:
$ yarn global add dir2pkg
Via the npm client:
$ npm install -g dir2pkg
$ dir2pkg --in-dir some-dir --out-dir packages/some-dir --pkg-json-name "@org/new-pkg" --pkg-json-path ./package.json
$ dir2pkg --in-dir some-dir
In directory
$ dir2pkg --out-dir packages/some-dir
Out directory
$ dir2pkg --pkg-json-name "@org/new-pkg"
Package name
$ dir2pkg --pkg-json-path ./package.json
Host package.json path
$ dir2pkg --ignore "shared" --ignore "@org/internal-alias"
List of dependencies to ignore. Useful for ignoring internal alias that can't be resolved to one node_modules dep.
$ dir2pkg --force-peer-dep react --force-peer-dep react-dom
List of dependencies to force as peer dependencies. Useful for libraries like react.
# install deps
$ yarn
# build and watch for changes
$ yarn build --watch
# link dir2pkg globally
$ yarn link
# enjoy!
$ dir2pkg --help