Skip to content

Commit

Permalink
feat(esm): Add exports within package.json to enable scoped package l…
Browse files Browse the repository at this point in the history
…oading.

In order for module resolution to work with .mjs or package: module code
we need to utilize the conditional export feature of node.

> The current specifier resolution does not support all default behavior of the CommonJS loader. One of the behavior differences is automatic resolution of file extensions and the ability to import directories that have an index file.

https://nodejs.org/api/esm.html#esm_customizing_esm_specifier_resolution_algorithm
https://nodejs.org/api/packages.html#packages_conditional_exports

This directly enables rxjs to work with mjs code and commonjs code since
mjs does not support loading bare folder paths.

This is a fix to:
sveltejs/kit#612

and is directly related to the conversation in this issue within node
core nodejs/node#27408
  • Loading branch information
samccone committed Mar 30, 2021
1 parent c41f65b commit 3c34f42
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,33 @@
"es2015": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts",
"sideEffects": false,
"exports": {
".": {
"node": "./dist/cjs/index.js",
"default": "./dist/esm5/index.js"
},
"./ajax": {
"node": "./dist/cjs/ajax/index.js",
"default": "./dist/dist/esm5/ajax/index.js"
},
"./fetch": {
"node": "./dist/cjs/fetch/index.js",
"default": "./dist/dist/esm5/fetch/index.js"
},
"./operators": {
"node": "./dist/cjs/operators/index.js",
"default": "./dist/dist/esm5/operators/index.js"
},
"./testing": {
"node": "./dist/cjs/testing/index.js",
"default": "./dist/dist/esm5/testing/index.js"
},
"./webSocket": {
"node": "./dist/cjs/webSocket/index.js",
"default": "./dist/dist/esm5/webSocket/index.js"
},
"./package.json": "./package.json"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
Expand Down

0 comments on commit 3c34f42

Please sign in to comment.