-
Notifications
You must be signed in to change notification settings - Fork 171
Description
Ref: ipld/js-dag-pb#52
Background
The "new" IPLD stack was designed as a dual-publish - it's written in ESM, with TypeScript annotations and then compiled to CJS & ESM in a dist/ directory and the types are checked and compiled into dist/types/ directory (there may be a case where it's just an index.d.ts, not a types/ directory) and then npm publish
is performed from the dist/ directory only.
So, publish: https://unpkg.com/browse/@ipld/dag-cbor@7.0.2/, doesn't match source: https://github.com/ipld/js-dag-cbor, but it can then be consumed with either require()
or import
and those will then use the correct forms--import
giving you proper ESM so you get the proper static tree that you can shake etc.
Compiling uses ipjs which uses rollup under the hood to compile the code and a bunch of fairly static rules to decide how to create the new dist/ output - including parent package.json, its export map and cjs/ & esm/ directories and their package.json files (for "type": ".."
switching).
But, ipjs locks us into a very singular pattern that has been difficult to evolve, and the latest problem @ ipld/js-dag-pb#52 is that we can't add a new entry to the package.json's "exports"
map because ipjs has opinions about what should be in there so it knows what to compile and what to output. We could fix ipjs (again), or we could drop the compile step entirely and go with ESM-only.
The JS ecosystem has been rapidly embracing ESM, with many popular packages going ESM-only (most notably all of sindresorhus's many and very popular packages are now ESM only, node-fetch is ESM-only, it's getting hard to do pure CJS and rely on current ecosystem packages without awkward breakage). @achingbrain has been converting the libp2p and ipfs JS packages to publish ESM only (as well as fully embracing TypeScript authoring in the process). So .. it's time.
TODO
- We need a repeatable pattern to implement in these repos, there already is a lot of consistency but there's also little bit of variation and switching to ESM could introduce more if we're not careful.
a. A stretch-goal here might be to extract parts of the pattern to unified-ci - mainly the Actions bits. - Build step: we still need to compile the types before publishing, so there should probably still be an
"build"
script that does this. In https://github.com/rvagg/js-bitcoin-block/blob/e91b70c7a38183e9314cb2cb55ee973396724f35/package.json#L24-L31, which doesn't dual-publish, I had a simple"build"
that was included with"lint"
on every"test"
, maybe that's appropriate? An addition to GitHub Actions that checks git state to make sure that post-"build"
doesn't produce different files might be good too. - We need to figure out type definition export settings - currently we have
"types"
in some packages (but not all) and"typesVersions"
in most (all?). fix: add support for node16 module resolution js-dag-pb#52 introduces a"types"
export field as well. Some packages have many exports and some have a single export, hence the difference."typesVersions"
with"*"
mapping was originally introduced to deal with a TS bug (history of this will probably be in js-multiformats somewhere), we may be able to remove that? Moving forward with 3 separate ways to indicate type definition files is not going to be happy.
The following repos are the most important to make the conversion in:
- js-multiformats: v10.0.0 tracking multiformats/js-multiformats#199
- js-dag-cbor
- js-dag-json
- js-dag-pb: feat!: publish as esm-only js-dag-pb#56
- js-car
Additional repos that are actively maintained that can be converted with lower priority:
- js-murmur3
- js-sha3
- js-blake2
- js-printify
- js-ipld-schema (NOTE: this repo needs more work than just ESM, it shouldn't publish until it's back in sync with the fixtures .. so this conversion could be deferred)
Other repos that are currently in my GitHub could probably be included too (I could move these to the ipld org at the same time): iamap, js-ipld-hashmap, js-ipld-garbage, js-ipld-schema-validator
Metadata
Metadata
Assignees
Labels
Type
Projects
Status