0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
Commit Graph

107 Commits

Author SHA1 Message Date
Guy Bedford
fc4e413554
module: unflag conditional exports
PR-URL: https://github.com/nodejs/node/pull/31001
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2020-01-15 20:48:52 -05:00
Guy Bedford
405e7b4557 module: logical conditional exports ordering
PR-URL: https://github.com/nodejs/node/pull/31008
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2020-01-07 06:14:19 +02:00
Geoffrey Booth
2551a21553 module: loader getSource, getFormat, transform hooks
PR-URL: https://github.com/nodejs/node/pull/30986
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
2020-01-07 01:31:05 +02:00
Thomas
a25a628452
esm: better error message for unsupported URL
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: https://github.com/nodejs/node/pull/31129
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2020-01-03 15:33:16 +01:00
Guy Bedford
c7f328f0df
module: unflag resolve self
PR-URL: https://github.com/nodejs/node/pull/31002
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2020-01-02 17:53:47 +01:00
Bradley Farias
baa3621bb1 esm: empty ext from pkg type/main doesnt affect format
This ensures files with unknown extensions like foo.bar are not
loaded as CJS/ESM when imported as a main entry point and makes
sure that those files would maintain the same format even if loaded
after the main entrypoint.

PR-URL: https://github.com/nodejs/node/pull/31021
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-12-31 09:11:11 -06:00
Ruben Bridgewater
e038d6a1cd
test: refactor common.expectsError
This completely refactors the `expectsError` behavior: so far it's
almost identical to `assert.throws(fn, object)` in case it was used
with a function as first argument. It had a magical property check
that allowed to verify a functions `type` in case `type` was passed
used in the validation object. This pattern is now completely removed
and `assert.throws()` should be used instead.

The main intent for `common.expectsError()` is to verify error cases
for callback based APIs. This is now more flexible by accepting all
validation possibilites that `assert.throws()` accepts as well. No
magical properties exist anymore. This reduces surprising behavior
for developers who are not used to the Node.js core code base.

This has the side effect that `common` is used significantly less
frequent.

PR-URL: https://github.com/nodejs/node/pull/31092
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-12-31 15:54:20 +01:00
Guy Bedford
8a96d05ec7 module: self resolve bug fix and esm ordering
PR-URL: https://github.com/nodejs/node/pull/31009
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2019-12-29 11:17:21 -05:00
Ruben Bridgewater
ac2fc0dd5f
errors: improve ERR_INVALID_ARG_TYPE
ERR_INVALID_ARG_TYPE is the most common error used throughout the
code base. This improves the error message by providing more details
to the user and by indicating more precisely which values are allowed
ones and which ones are not.

It adds the actual input to the error message in case it's a primitive.
If it's a class instance, it'll print the class name instead of
"object" and "falsy" or similar entries are not named "type" anymore.

PR-URL: https://github.com/nodejs/node/pull/29675
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-12-20 03:10:13 +01:00
Richard Lau
e23aebc684
test: use tmpdir.refresh() in test-esm-windows.js
Use `tmpdir.refresh()` in `test/es-module/test-esm-windows.js` so
that the temporary directory is cleaned before use and when the test
exits.

PR-URL: https://github.com/nodejs/node/pull/30997
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-12-18 09:23:49 -05:00
Guy Bedford
357a99293e module: conditional exports import condition
PR-URL: https://github.com/nodejs/node/pull/30799
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-12-12 17:35:08 -05:00
qualitymanifest
7ab21b2f57 lib: add parent to ERR_UNKNOWN_FILE_EXTENSION
- default_resolve updated to pass parentURL into error
- ERR_UNKNOWN_FILE_EXTENSION updated to include parentURL
- test added to check for import message in error

PR-URL: https://github.com/nodejs/node/pull/30728
Fixes: https://github.com/nodejs/node/issues/30721
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-12-06 23:59:39 -05:00
Juan José Arboleda
6669cd138e lib: add warning on dynamic import es modules
PR-URL: https://github.com/nodejs/node/pull/30720
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-12-06 23:07:56 -05:00
Guy Bedford
781e41df61 module: fixup lint and test regressions
PR-URL: https://github.com/nodejs/node/pull/30802
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: João Reis <reis@janeasystems.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-12-05 02:49:17 -05:00
Juan José Arboleda
81ac3023b3 lib,test: improves ERR_REQUIRE_ESM message
PR-URL: https://github.com/nodejs/node/pull/30694
Fixes: https://github.com/nodejs/node/issues/30599
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-12-04 23:25:10 -05:00
Rongjian Zhang
aa4c57ae7e module: add warnings for experimental flags
PR-URL: https://github.com/nodejs/node/pull/30617
Fixes: https://github.com/nodejs/node/issues/30600
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-12-04 22:36:37 -05:00
Myles Borins
ee953d813b
esm: make specifier flag clearly experimental
`--es-module-specifier-resolution` is the only flagged portion of the
ESM implementation that does not have the word experimental in the flag
name. This commit changes the flag to:

`--experimental-specifier-resolution`

`--es-module-specifier-resolution` remains as an alias for backwards
compatibility but it is no longer documented.

PR-URL: https://github.com/nodejs/node/pull/30678
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-12-04 13:21:41 -08:00
Rich Trott
359766b2c3 benchmark,doc,lib,test: prepare for padding lint rule
Upcoming lint rule will require a blank line between consecutive
functions. Add it in the places where we don't have it already.

PR-URL: https://github.com/nodejs/node/pull/30696
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2019-11-30 06:28:29 -08:00
Rongjian Zhang
f5ef7cd222 module: fix specifier resolution algorithm
Fixes: https://github.com/nodejs/node/issues/30520

PR-URL: https://github.com/nodejs/node/pull/30574
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-11-28 10:22:53 -08:00
Bradley Farias
568968e39b esm: data URLs should ignore unknown parameters
PR-URL: https://github.com/nodejs/node/pull/30593
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-11-26 11:00:33 -06:00
Guy Bedford
250a995656
esm: disable non-js exts outside package scopes
PR-URL: https://github.com/nodejs/node/pull/30501
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-11-16 23:26:49 -08:00
Guy Bedford
796f3d0af4
esm: unflag --experimental-modules
PR-URL: https://github.com/nodejs/node/pull/29866
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-11-12 14:04:55 -08:00
Guy Bedford
2367474db4 module: conditional exports with flagged conditions
PR-URL: https://github.com/nodejs/node/pull/29978
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-11-08 17:26:26 -05:00
Guy Bedford
1eee0b8bf8 module: fix for empty object in InternalModuleReadJSON
Fixes: https://github.com/nodejs/node/issues/30245
PR-URL: https://github.com/nodejs/node/pull/30256
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2019-11-08 04:50:02 -08:00
Jan Krems
71bcd05232 module: resolve self-references
Adds the ability to `import` or `require` a package from within its
own source code. This allows tests and examples to be written using
the package name, making them easier to reuse by consumers of the
package.

Assuming the `name` field in `package.json` is set to `my-pkg`, its
test could use `require('my-pkg')` or `import 'my-pkg'` even if
there's no `node_modules/my-pkg` while testing the package itself.

An important difference between this and relative specifiers like
`require('../')` is that self-references use the public interface
of the package as defined in the `exports` field while relative
specifiers don't.

This behavior is guarded by a new experimental flag
(`--experimental-resolve-self`).

PR-URL: https://github.com/nodejs/node/pull/29327
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2019-10-24 15:14:38 -07:00
Myles Borins
1e5ed9a5db esm: modify resolution order for specifier flag
Currently `--es-module-specifier-resolution=node` has an alternative
resolution order than the default in common.js, this causes
inconsistencies. As discussed in @nodejs/modules we want to preserve
resolution order between implementations.

PR-URL: https://github.com/nodejs/node/pull/29974
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2019-10-16 22:01:19 -04:00
Bradley Farias
a6b030d5ac module: refactor modules bootstrap
PR-URL: https://github.com/nodejs/node/pull/29937
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2019-10-16 21:50:05 -04:00
Guy Bedford
aca1c283bd module: warn on require of .js inside type: module
PR-URL: https://github.com/nodejs/node/pull/29909
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-10-11 17:37:46 -04:00
Guy Bedford
c0437d2633 Revert "esm: remove experimental status from JSON modules"
This reverts commit ec8776da6f.

PR-URL: https://github.com/nodejs/node/pull/29754
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-10-08 21:18:04 -07:00
Bradley Farias
0b495a899b esm: remove proxy for builtin exports
PR-URL: https://github.com/nodejs/node/pull/29737
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2019-10-05 20:11:15 -04:00
Thomas
6265e4166a src: fix ESM path resolution on Windows
Windows has some reserved file names such as "con", "prn",
"nul", etc. Such files can be accessed only if the path is
prefixed with "\\.\"

PR-URL: https://github.com/nodejs/node/pull/29574
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-10-03 20:46:53 -07:00
Alex Aubuchon
15fb02a515 src: rename --loader to --experimental-loader
Renames the `--loader` cli argument to `--experimental-loader`.  This is
to clearly indicate the esm loader feature as experimental even after
esm is no longer experimental.

Also minorly alters the `--experimental-loader` docs to say that the
passed loader can be an esm module.

Refs: https://github.com/nodejs/modules/issues/351#issuecomment-535189524

PR-URL: https://github.com/nodejs/node/pull/29752
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-09-30 21:47:01 -07:00
Guy Bedford
2825e1183d module: move cjs type check behind flag
PR-URL: https://github.com/nodejs/node/pull/29732
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
2019-09-28 11:56:39 -07:00
Guy Bedford
4396bebfe1 module: error for CJS .js load within type: module
PR-URL: https://github.com/nodejs/node/pull/29492
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2019-09-19 15:24:50 -07:00
Guy Bedford
3f3ad38c87 module: reintroduce package exports dot main
This reintroduces the dot main in exports as discussed in the previous
Node.js modules meeting.

The implementation includes both CommonJS and ES module resolution with
the associated documentation and resolver specification changes.

In addition to the dot main, "exports" as a string or direct fallback
array is supported as well.

Co-Authored-By: Geoffrey Booth <GeoffreyBooth@users.noreply.github.com>
PR-URL: https://github.com/nodejs/node/pull/29494
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2019-09-17 18:54:44 -07:00
Bradley Farias
cdebd32461 esm: make dynamic import work in the REPL
PR-URL: https://github.com/nodejs/node/pull/29437
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: David Carlier <devnexen@gmail.com>
2019-09-06 11:47:32 -05:00
Bradley Farias
9fd9efa492 esm: support loading data URLs
Co-Authored-By: Jan Olaf Krems <jan.krems@gmail.com>

PR-URL: https://github.com/nodejs/node/pull/28614
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2019-08-20 09:34:18 -05:00
Giorgos Ntemiris
427e5348a2 module: add warning when import,export is detected in CJS context
This will allow users to know how to change their project to support
ES modules.

PR-URL: https://github.com/nodejs/node/pull/28950
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2019-08-13 11:19:48 -07:00
Guy Bedford
2103ae4835 module: pkg exports validations and fallbacks
PR-URL: https://github.com/nodejs/node/pull/28949
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2019-08-12 06:24:28 -04:00
Guy Bedford
0e03c449e3 module: refine package name validation
PR-URL: https://github.com/nodejs/node/pull/28965
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-08-07 19:56:11 -07:00
Guy Bedford
452b393c1f module: exports error as MODULE_NOT_FOUND
PR-URL: https://github.com/nodejs/node/pull/28905
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-08-01 20:36:27 -07:00
Jan Krems
61f3a5c60a module: unify package exports test for CJS and ESM
Refs: https://github.com/nodejs/modules/issues/358

PR-URL: https://github.com/nodejs/node/pull/28831
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-07-31 13:33:46 -07:00
Jan Krems
dcb6929183 module: implement "exports" proposal for CommonJS
Refs: https://github.com/jkrems/proposal-pkg-exports/issues/36
Refs: https://github.com/nodejs/node/pull/28568

PR-URL: https://github.com/nodejs/node/pull/28759
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
2019-07-23 16:11:20 -07:00
Alex Ramirez
6948a95562 test: fix assertion argument order in test-esm-namespace
PR-URL: https://github.com/nodejs/node/pull/28474
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-07-20 22:33:14 -07:00
Guy Bedford
6df7b6a4f9 esm: implement "pkg-exports" proposal
Refs: https://github.com/jkrems/proposal-pkg-exports/issues/36

PR-URL: https://github.com/nodejs/node/pull/28568
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2019-07-18 14:54:16 -07:00
Myles Borins
c3f72510c8
esm: remove experimental status from JSON modules
The HTML spec has officially landed JSON Modules and as such I think
we can move them out of the "experimental" status. They will still
be behind the `--experimental-modules` flag until the entire esm
implementation moves out of experimental.

Refs: https://html.spec.whatwg.org/#creating-a-json-module-script

PR-URL: https://github.com/nodejs/node/pull/27752
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-05-22 04:06:34 -04:00
cjihrig
873c372e67
esm: use correct error arguments
ERR_UNKNOWN_FILE_EXTENSION expects a single argument. This
commit fixes the argument count.

PR-URL: https://github.com/nodejs/node/pull/27763
Fixes: https://github.com/nodejs/node/issues/27761
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2019-05-20 10:26:23 -04:00
Myles Borins
bbc254db5d esm: --experimental-wasm-modules integration support
PR-URL: https://github.com/nodejs/node/pull/27659
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2019-05-17 02:25:20 +02:00
Antoine du HAMEL
ac3b98cd26 test: clearing require cache crashes esm loader
This test shows the regression introduced in v11.4.0: clearing out the
require.cache crashes node when using the `--experimental-modules` flag.
Refs: https://github.com/nodejs/node/issues/25482

PR-URL: https://github.com/nodejs/node/pull/25491
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-05-14 16:17:34 +08:00
ZYSzys
dcc5e51e1c tools: force common be required before any other modules
PR-URL: https://github.com/nodejs/node/pull/27650
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2019-05-13 19:39:34 +08:00