- Node 16
pnpm
Three main files to be aware of:
- The library's entrypoint
npm-package-deep-dive/lib/index.js
Lines 1 to 13 in 2cb150c
- The Website's script where
getContributors
is usednpm-package-deep-dive/web/src/main.ts
Lines 1 to 25 in 2cb150c
- The CLI's entrypoint where
getContributors
is usednpm-package-deep-dive/cli/index.js
Lines 1 to 19 in 2cb150c
Next, publish the first version of the NPM package.
pnpm publish --no-git-checks
Install in the web
and cli
package, make sure they work.
Node 16 doesn't include the fetch
API. If we want to support Node 16, we'll need to use a library, like ofetch
.
- Install
ofetch
and use it in thelib/index.js
file - Publish a new version
- Install latest version in
web
andcli
packages, make sure they work
Ref: https://github.com/aaronklinker-st/npm-package-deep-dive/commit/ef8444364c865aad4d0b5ae1b9db4c310eec54b8 & https://github.com/aaronklinker-st/npm-package-deep-dive/commit/58facc2f71c3c96a2b61d26bee73caea0df1a887
The package will not work in a CJS project.
Return to presentation to talk about modules.
So lets convert our CLI to CJS, and publish both a CJS, ESM, and for kicks and giggles, IIFE.
Follow this diff: https://github.com/aaronklinker-st/npm-package-deep-dive/commit/ef8444364c865aad4d0b5ae1b9db4c310eec54b8
Then:
- Install TSUP
- Add
build
andprepublish
scriptnpm-package-deep-dive/lib/package.json
Lines 15 to 16 in 58facc2
- Discuss flags for build script
- Make additional changes to the
package.json
https://github.com/aaronklinker-st/npm-package-deep-dive/commit/58facc2f71c3c96a2b61d26bee73caea0df1a887#diff-1e946220773aef913945326261b7ee8d08b8ec29ccc66ef7c348950439212ffb - Publish new version
- Show that it works with
cli
, a CJS project, andweb
, an ESM project
Return to slides talk about typescript.
- Add declaration file
- Publish new version
- Show how types are now provided to consumers and on NPM
Fully convert the project to typescript: https://github.com/aaronklinker-st/npm-package-deep-dive/commit/0a1694b022e4e9a8e8454034e717ecce35153785
- Convert the JS file to TS
- Delete the declaration file
- Build declaration file
- Include package types field
- Add TS config file