This is a clonable template repository for authoring a npm
module with TypeScript. Out of the box, it:
- Provides minimally-viable
tsconfig.json
settings - Scaffolds a silly arithmetic module (
src/index.ts
) - Scaffolds test suites for full test coverage (
test/index.ts
) - Scaffolds a GitHub Action for Code Integration (CI) that:
- checks if compilation is successful
- runs the test suite(s)
- reports test coverage
- Generates type definitions (
types/*.d.ts
) - Generates multiple distribution formats:
- ES Module (
dist/index.mjs
) - CommonJS (
dist/index.js
) - UMD (
dist/index.min.js
)
- ES Module (
All configuration is accessible via the rollup.config.js
and a few package.json
keys:
name
— the name of your modulemain
— the destination file for your CommonJS buildmodule
— the destination file for your ESM build (optional but recommended)unpkg
— the destination file for your UMD build (optional for unpkg.com)umd:name
— the UMD global name for your module (optional)
- Clone this template
- Replace all instances of
TODO
within thelicense
andpackage.json
files - Create CodeCov account (free for OSS)
- Copy the provided CodeCov token as the
CODECOV_TOKEN
repository secret (for CI reporting) - Replace
src/index.ts
andtest/index.ts
with your own code! 🎉
Builds your module for distribution in multiple formats (ESM, CommonJS, and UMD).
$ npm run build
Runs your test suite(s) (/tests/**
) against your source code (/src/**
).
Doing so allows for accurate code coverage.
Note: Coverage is only collected and reported through the "CI" Github Action (
.github/workflows/ci.yml
).
$ npm test
Important: Please finish Setup before continuing!
Once all TODO
notes have been updated & your new module is ready to be shared, all that's left to do is decide its new version — AKA, do the changes consitute a patch
, minor
, or major
release?
Once decided, you can run the following:
$ npm version <patch|minor|major> && git push origin master --tags && npm publish
# Example:
# npm version patch && git push origin master --tags && npm publish
This command sequence will:
- version your module, updating the
package.json
"version" - create and push a
git
tag (matching the new version) to your repository - build your module (via the
prepublishOnly
script) - publish the module to the npm registry
MIT © Luke Edwards