comlink
comlink copied to clipboard
Specify `exports` in `package.json
Right now, it's not possible to import something like comlink/node-adapter and automatically get CJS or ESM depending on the environment.
node and some bundlers support:
{
"exports": {
".": {
"require": "dist/umd/comlink.js",
"import": "dist/esm/comlink.mjs",
"types": "dist/umd/comlink.d.ts",
},
"./node-adapter": {
"require": "dist/umd/node-adapter.js",
"import": "dist/esm/node-adapter.mjs",
"types": "dist/umd/node-adapter.d.ts"
}
}
}
An alternative would be to add /node-adapter/package.json or /dist/node-adapter/package.json containing:
{
"main": "dist/umd/node-adapter.js",
"module": "dist/esm/node-adapter.mjs",
"types": "dist/umd/node-adapter.d.ts"
}
Does the former seem reasonable? If not, does the latter?
One caveat is that exports can//should prevent importing any other files directly, so we'd need more fields if we want to export the minified versions so they can be used directly in node or bundlers that support exports. (If the minified files are mainly meant for using manually, this is not needed.)
I'm trying to tackle https://github.com/lgarron/web-worker-compat-problems/blob/main/README.md#problem-9-node-workers-differ-from-browsers so I can avoid a source of pain at https://github.com/cubing/jsss/tree/scrambles/src/scrambles/worker/getNodeAdapter :-P