Commit b1094db
esm: phase two of new esm implementation
This PR updates the current `--experimental-modules` implementation
based on the work of the modules team and reflects Phase 2 of our
new modules plan.
The largest differences from the current implementation include
* `packge.type` which can be either `module` or `commonjs`
- `type: "commonjs"`:
- `.js` is parsed as commonjs
- default for entry point without an extension is commonjs
- `type: "module"`:
- `.js` is parsed as esm
- does not support loading JSON or Native Module by default
- default for entry point without an extension is esm
* `--entry-type=[mode]`
- allows you set the type on entry point.
* A new file extension `.cjs`.
- this is specifically to support importing commonjs in the
`module` mode.
- this is only in the esm loader, the commonjs loader remains
untouched, but the extension will work in the old loader if you use
the full file path.
* `--es-module-specifier-resolution=[type]`
- options are `explicit` (default) and `node`
- by default our loader will not allow for optional extensions in
the import, the path for a module must include the extension if
there is one
- by default our loader will not allow for importing directories that
have an index file
- developers can use `--es-module-specifier-resolution=node` to
enable the commonjs specifier resolution algorithm
- This is not a “feature” but rather an implementation for
experimentation. It is expected to change before the flag is
removed
* `--experimental-json-loader`
- the only way to import json when `"type": "module"`
- when enable all `import 'thing.json'` will go through the
experimental loader independent of mode
- based on whatwg/html#4315
* You can use `package.main` to set an entry point for a module
- the file extensions used in main will be resolved based on the
`type` of the module
Refs: https://github.com/nodejs/modules/blob/master/doc/plan-for-new-modules-implementation.md
Refs: https://github.com/GeoffreyBooth/node-import-file-specifier-resolution-proposal
Refs: nodejs/modules#180
Refs: nodejs/ecmascript-modules#6
Refs: nodejs/ecmascript-modules#12
Refs: nodejs/ecmascript-modules#28
Refs: nodejs/modules#255
Refs: whatwg/html#4315
Refs: WICG/webcomponents#770
Co-authored-by: Myles Borins <MylesBorins@google.com>
Co-authored-by: John-David Dalton <john.david.dalton@gmail.com>
Co-authored-by: Evan Plaice <evanplaice@gmail.com>
Co-authored-by: Geoffrey Booth <webmaster@geoffreybooth.com>
Co-authored-by: Michaël Zasso <targos@protonmail.com>
PR-URL: #26745
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>1 parent 3914142 commit b1094db
File tree
124 files changed
+1822
-482
lines changed- doc
- api
- lib/internal
- bootstrap
- main
- modules
- cjs
- esm
- process
- src
- test
- addons/hello-world-esm
- common
- es-module
- fixtures
- es-module-loaders
- es-module-specifiers
- node_modules
- explicit-main
- implicit-main-type-commonjs
- implicit-main-type-module
- implicit-main
- package-type-commonjs
- package-type-module
- es-modules
- json-cache
- package-type-commonjs
- package-type-module
- package-without-type
- pjson-main
- syntax
- message
- parallel
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
124 files changed
+1822
-482
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
134 | 147 | | |
135 | 148 | | |
136 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
137 | 171 | | |
138 | 172 | | |
139 | 173 | | |
| |||
927 | 961 | | |
928 | 962 | | |
929 | 963 | | |
| 964 | + | |
930 | 965 | | |
931 | 966 | | |
932 | 967 | | |
933 | | - | |
| 968 | + | |
934 | 969 | | |
935 | 970 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
844 | 844 | | |
845 | 845 | | |
846 | 846 | | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
847 | 859 | | |
848 | 860 | | |
849 | 861 | | |
| |||
1267 | 1279 | | |
1268 | 1280 | | |
1269 | 1281 | | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
1270 | 1287 | | |
1271 | 1288 | | |
1272 | 1289 | | |
| |||
1440 | 1457 | | |
1441 | 1458 | | |
1442 | 1459 | | |
1443 | | - | |
| 1460 | + | |
1444 | 1461 | | |
1445 | 1462 | | |
1446 | 1463 | | |
| |||
1449 | 1466 | | |
1450 | 1467 | | |
1451 | 1468 | | |
1452 | | - | |
1453 | | - | |
1454 | | - | |
1455 | | - | |
1456 | | - | |
1457 | | - | |
1458 | | - | |
1459 | 1469 | | |
1460 | 1470 | | |
1461 | 1471 | | |
1462 | 1472 | | |
1463 | 1473 | | |
1464 | 1474 | | |
1465 | 1475 | | |
1466 | | - | |
1467 | | - | |
| 1476 | + | |
| 1477 | + | |
1468 | 1478 | | |
1469 | 1479 | | |
1470 | 1480 | | |
1471 | | - | |
| 1481 | + | |
1472 | 1482 | | |
1473 | 1483 | | |
1474 | 1484 | | |
| |||
1555 | 1565 | | |
1556 | 1566 | | |
1557 | 1567 | | |
1558 | | - | |
| 1568 | + | |
1559 | 1569 | | |
1560 | 1570 | | |
1561 | 1571 | | |
| |||
2220 | 2230 | | |
2221 | 2231 | | |
2222 | 2232 | | |
| 2233 | + | |
| 2234 | + | |
| 2235 | + | |
| 2236 | + | |
| 2237 | + | |
| 2238 | + | |
| 2239 | + | |
2223 | 2240 | | |
2224 | 2241 | | |
2225 | 2242 | | |
2226 | | - | |
| 2243 | + | |
2227 | 2244 | | |
2228 | 2245 | | |
2229 | 2246 | | |
| |||
2250 | 2267 | | |
2251 | 2268 | | |
2252 | 2269 | | |
2253 | | - | |
2254 | 2270 | | |
2255 | 2271 | | |
2256 | 2272 | | |
| |||
2293 | 2309 | | |
2294 | 2310 | | |
2295 | 2311 | | |
2296 | | - | |
| 2312 | + | |
2297 | 2313 | | |
2298 | 2314 | | |
2299 | 2315 | | |
| |||
0 commit comments