Skip to content

Project setup for typescript + babel + rollup + jest + circleci

License

Notifications You must be signed in to change notification settings

cirbuk/jslib-scaffolding

Repository files navigation

jslib-scaffolding

Scaffoling for setting up an open source libarary with the following stack

  • code in JS/TypeScript
  • Build with Rollup
  • Test with Jest
  • Publish to npm with CircleCI

Getting Started

Create a new directory and then run:

curl -fsSL https://github.com/cirbuk/jslib-scaffolding/archive/master.tar.gz | tar -xz --strip-components=1

For the discussion below, assume that the code resides in the src folder and the entry point is index.ts/index.ts.

package.json

  • Change the following fields name, version, description, repository, author, license, bugs.url and homepage as required
  • Change/remove main as per requirement.
  • Change/remove module as per requirement.
  • Change/remove browser as per requirement.
  • Run npm install
  • Add additional packages required by the library

Typescript

  • types in package.json should point to the types declaration file generated for the library.
  • Write code in index.ts in src folder
  • Change the tsconfig.json file as required
  • Change all input in rollup.config.js to src/index.ts

JavaScipt

  • Remove types and packages related to TypeScript from devDependencies in package.json
  • Remove tsconfig.json
  • Remove the entry @babel/preset-typescript from .babelrc
  • Write code in index.ts in src folder
  • Remove import typescript from 'rollup-plugin-typescript'; in rollup.config.js
  • Remove typescript() call from plugins in rollup.config.js
  • Change all input in rollup.config.js to src/index.ts

If you have other rollup built libraries as dependencies, and you use some named exports from those libraries, these imports will have to be explicitly declared in your rollup.config.js as named exports. If these dependencies are peer dependencies, you can mark them as external in your rollup.config.js and avoid having to declare all named imports.

Build

npm run build will build the library

Tests

  • Write your tests in the tests directory as files ending in .test.js
  • Change the Jest config as required in jest.config.js
  • npm test will run the tests and print the results

Publish

  • Login into Circle CI and follow the github project where the library resides
  • Change the node version in .circleci/config.yml if required
  • Do npm login in local and extract the auth token from ${HOME}/.npmrc
  • The token can be configured in 2 ways
    • In the Circle CI organization settings, create a context named npm and add and environment variable named npm_TOKEN with the copied auth token as it's value. This is the default approach configured in .circleci/config.yml.
    • Otherwise, create an environment variable npm_TOKEN in Circle CI under project settings and paste the copied auth token as it's value. Afterwards, delete the line context: npm(line 68) from .circleci/config.yml

Once all the above steps have been completed and the library is ready, commit to github.

  • The tests will be run in CircleCI for every branch and tag
  • Publish to npm will happen whenever a commit is tagged with v${versionNumber}.

Before tagging a commit for publish, make sure that the correct version number is updated in package.json

About

Project setup for typescript + babel + rollup + jest + circleci

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published