-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Yisroel Yakovson edited this page Jan 13, 2021
·
4 revisions
Here are steps that will work to create an npm package. Call it $PACKAGE.
- check that $PACKAGE isn't taken yet on npmjs.
- create a general directory for your $PACKAGE code. e.g. ~/packages/$PACKAGE-all. Then create a global variable $CODE just to follow the instructions below:
CODE=~/packages/$PACKAGE-all/$PACKAGE
. - generate the package:
npm js-packrat $CODE
- install geenee:
npm i -g yalc geenee
- set up your groupings and/or types to export:
geenee settings $CODE
- create (in
src/custom
or in thehelper
section for your grouping files) any code needed - make sure that you can build your lib correctly:
npm run build
.
- if you are copying code from somewhere else, put it into
src/custom
. - Try
depcheck
to see whether the copied code results in your needing to install packages. - remember to run install if you manually insert any dependencies intoyour package json:
cd $CODE && npm i
One difference between a package and front end code or a cli is that you need a consumer of the package to run it. If you like, you can use yalc as a replacement for the npm symlinks proposed below.
- make sure your code compiles:
cd $CODE && npm run build
. - link locally:
cd $CODE && npm link
- set up a separate testing app $TEST that includes $PACKAGE. That could be as simple as:
- create a directory $TEST
- create a package.json file:
cd $TEST && npm init -y
- link to $PACKAGE:
cd $TEST && npm link $PACKAGE
- create a file $TEST/index.ts that imports a grouping or type to test and does something that gets printed with
console.log
- run
tsc $TEST/index.ts
to confirm that it's working
- create the GitHub repo
<yourUserName>/$PACKAGE
- modify your
README.md
file to explain usage - commit to git, push a branch, merge to main (whatever process you prefer with CI etc.)
- checkout main branch, pull and then publish:
cd $CODE && git checkout main && git pull && npm publish