@guardian/pkgu
Automatically build
@guardian
packages for publishing to NPM inline with our recommendations.
Installation
yarn add -D @guardian/pkgu
or
npm install -D @guardian/pkgu
Usage
@guardian/pkgu
installs a CLI tool called pkgu
that you can use to create your build.
Commands
build
Example
// package.json
{
...,
"scripts": {
"prebuild": "rm -rf dist",
"build": "pkgu build"
},
...,
}
This will compile your project to a dist
directory ready for publishing, performing the following steps:
- Lint your
package.json
andtsconfig.json
files and update/add/remove any fields as necessary. - Compile 3 versions of your project:
- CommonJS version targetting ES2018 (for Node 10+).
- ESM version targetting ES2020 for use by bundlers (see Using
@guardian
NPM packages in the recommendations for more info). - TypeScript declaration files.
- Check that the build artefacts match the
package.json
config. - If your package provides a CLI it will set the permissions needed to make it executable.
You should then be good to publish.
Requirements
- Your source code is written in TypeScript.
- The source code lives in a directory called
src
at the package root level. - There is one entry point:
src/index.ts
.