Commit Graph

57 Commits

Author SHA1 Message Date
Colin Ihrig
93c4dc5e5a
module: ensure 'node:'-only modules can access node_modules
This commit allows require() and import to search the
node_modules directories when importing a core module that
must have the node: scheme. This prevents these core modules
from shadowing userland modules with the same name but no
prefix.

PR-URL: https://github.com/nodejs/node/pull/42430
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Beth Griggs <bgriggs@redhat.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
2022-04-14 14:08:55 +01:00
Jacob Smith
5a927ef0c2
esm: emit experimental warnings in common place
PR-URL: https://github.com/nodejs/node/pull/42314
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2022-03-28 22:43:15 +01:00
cjihrig
3c4ee5267a module,repl: support 'node:'-only core modules
This commit makes it possible to add new core modules that can
only be require()'ed and imported when the 'node:' scheme is
used. The 'test' module is the first such module.

These 'node:'-only modules are not included in the list returned
by module.builtinModules.

PR-URL: https://github.com/nodejs/node/pull/42325
Refs: https://github.com/nodejs/node/issues/40954
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-03-21 22:21:09 +00:00
Bradley Farias
a01302b8df
esm: make extension-less errors in type:module actionable
PR-URL: https://github.com/nodejs/node/pull/42301
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-03-15 00:59:32 +00:00
Bradley Farias
68626dc451
esm: improve typings and code coverage
PR-URL: https://github.com/nodejs/node/pull/42305
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
2022-03-14 16:30:26 +01:00
Geoffrey Booth
a30e0de005
esm: add runtime warning for specifier resolution flag
PR-URL: https://github.com/nodejs/node/pull/42252
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2022-03-10 12:43:47 +01:00
Xuguang Mei
02d326fff5
loader: fix esm resolve for symlink file
Fix: https://github.com/nodejs/node/issues/42195

PR-URL: https://github.com/nodejs/node/pull/42197
Fixes: https://github.com/nodejs/node/issues/42195
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2022-03-06 04:11:44 +00:00
Bradley Farias
f860b3810f
esm: fix relative imports for https
PR-URL: https://github.com/nodejs/node/pull/42119
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2022-02-27 09:20:42 +00:00
Bradley Farias
ceadb473e6 esm: support https remotely and http locally under flag
Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com>
Co-authored-by: James M Snell <jasnell@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Co-authored-by: James Sumners <james@sumners.email>
PR-URL: https://github.com/nodejs/node/pull/36328
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
2022-02-09 19:47:12 -08:00
Rich Trott
78a2cd8624 lib: add comments to empty catch statements
PR-URL: https://github.com/nodejs/node/pull/41831
Refs: https://eslint.org/docs/rules/no-empty
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-02-05 12:58:30 +00:00
Gabriel Bota
34e3dd5034
loader: fix package resolution for edge case
this commit solves a regression introduced with PR-40980.
if a resolve call results in a script with .mjs extension the
is automatically set to . This avoids the case where an additional
 in the same directory as the .mjs file would declare the
 to commonjs

PR-URL: https://github.com/nodejs/node/pull/41218
Refs: https://github.com/nodejs/node/pull/40980
Refs: https://github.com/yargs/yargs/issues/2068
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-12-22 18:43:19 +00:00
Rich Trott
23f1b22725
esm: reconcile JSDoc vs. actual parameter name
PR-URL: https://github.com/nodejs/node/pull/41238
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2021-12-21 17:53:47 +00:00
Gabriel Bota
85d4cd3079
loader: return package format from defaultResolve if known
This is a proposed modification of defaultResolve to return the package
format in case it has been found during package resolution.
The format will be returned as described in the documentation:
https://nodejs.org/api/esm.html#resolvespecifier-context-defaultresolve
There is one new unit test as well:
test/es-module/test-esm-resolve-type.js

PR-URL: https://github.com/nodejs/node/pull/40980
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-12-13 20:44:00 +00:00
Rich Trott
88dd9724b0 lib: include return types in JSDoc
Add types to @returns JSDoc annotations where the type is missing.

PR-URL: https://github.com/nodejs/node/pull/41130
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2021-12-12 03:51:00 +00:00
Rich Trott
c241ef1a12 lib: use consistent types in JSDoc @returns
PR-URL: https://github.com/nodejs/node/pull/41089
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2021-12-07 06:23:30 -08:00
Guy Bedford
f0dcac89c7 module: resolver & spec hardening /w refactoring
PR-URL: https://github.com/nodejs/node/pull/40510
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-10-24 14:44:59 -07:00
Francesco Trotta
8ac9aef8b1 lib: fix regular expression to detect / and \
Fixes #40305

PR-URL: https://github.com/nodejs/node/pull/40325
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2021-10-21 14:55:00 +00:00
Guy Bedford
36e2ffe6dc module: subpath folder mappings EOL
PR-URL: https://github.com/nodejs/node/pull/40121
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2021-09-21 23:15:02 -07:00
Guy Bedford
64287e4d45 module: runtime deprecate trailing slash patterns
PR-URL: https://github.com/nodejs/node/pull/40117
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-09-18 21:03:20 -07:00
Guy Bedford
bea8a90e1d module: support pattern trailers for imports field
PR-URL: https://github.com/nodejs/node/pull/40041
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2021-09-15 01:51:29 -07:00
Guy Bedford
7216fb118d module: deprecate trailing slash pattern mappings
PR-URL: https://github.com/nodejs/node/pull/40039
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2021-09-14 23:58:56 -07:00
Guy Bedford
5c1adda0ae module: fix $ pattern replacements
PR-URL: https://github.com/nodejs/node/pull/40044
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu Yang <himself65@outlook.com>
2021-09-12 13:46:14 -07:00
Jacob
df22736d80 esm: consolidate ESM loader hooks
doc: update ESM hook examples

esm: fix unsafe primordial

doc: fix ESM example linting

esm: allow source of type ArrayBuffer

doc: update ESM hook changelog to include resolve format

esm: allow all ArrayBuffers and TypedArrays for load hook source

doc: tidy code & API docs

doc: convert ESM source table header from Title Case to Sentence case

doc: add detailed explanation for getPackageType

esm: add caveat that ESMLoader::import() must NOT be renamed

esm: tidy code declaration of getFormat protocolHandlers

doc: correct ESM doc link (bad conflict resolution)

doc: update ESM hook limitation for CJS

esm: tweak preload description

doc: update ESM getPackageType() example explanation

PR-URL: https://github.com/nodejs/node/pull/37468
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2021-09-11 18:08:35 -07:00
Dominic Elm
a9dd03b1ec src: add option to disable loading native addons
PR-URL: https://github.com/nodejs/node/pull/39977
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
2021-09-10 10:54:39 -05:00
Guy Bedford
18bb2cef83 module: support pattern trailers
PR-URL: https://github.com/nodejs/node/pull/39635
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
2021-08-25 12:49:33 -07:00
Antoine du Hamel
45f98fc60d module: add some typings to internal/modules/esm/resolve
PR-URL: https://github.com/nodejs/node/pull/39504
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2021-08-02 10:21:30 +02:00
Antoine du Hamel
4e17ffc793 module: fix legacy node specifier resolution to resolve "main" field
PR-URL: https://github.com/nodejs/node/pull/38979
Fixes: https://github.com/nodejs/node/issues/32103
Fixes: https://github.com/nodejs/node/issues/38739
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2021-06-13 16:22:34 +02:00
Antoine du Hamel
7b2bad4005 module: clarify CJS global-like variables not defined error message
Fixes: https://github.com/nodejs/node/issues/33741

PR-URL: https://github.com/nodejs/node/pull/37852
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2021-04-13 19:06:48 +02:00
Antoine du Hamel
3cc9aec988 module: runtime deprecate subpath folder mappings
PR-URL: https://github.com/nodejs/node/pull/37215
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2021-03-20 19:14:14 +01:00
Antoine du Hamel
9fab73c73b module: runtime deprecate "main" index and extension lookups
PR-URL: https://github.com/nodejs/node/pull/37206
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2021-03-19 12:38:20 +01:00
cjihrig
d0a92e2c32
esm: update to correct deprecation code
https://github.com/nodejs/node/pull/36918 landed with references
to DEP0150, which is already used for a different deprecation.
This commit updates the code to use DEP0151.

PR-URL: https://github.com/nodejs/node/pull/37147
Refs: https://github.com/nodejs/node/pull/36918
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-01-30 11:37:22 -05:00
Guy Bedford
255d6337cd esm: deprecate legacy main lookup for modules
PR-URL: https://github.com/nodejs/node/pull/36918
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2021-01-30 16:31:49 +02:00
Antoine du Hamel
88153dc175
module: simplify tryStatSync with throwIfNoEntry option
PR-URL: https://github.com/nodejs/node/pull/36971
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2021-01-18 11:04:14 -08:00
Guy Bedford
2e909c4fcc module: fix Windows folder exports deprecation warning
PR-URL: https://github.com/nodejs/node/pull/36859
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2021-01-12 14:45:51 +01:00
Antoine du Hamel
829786088a esm: refactor to use more primordials
PR-URL: https://github.com/nodejs/node/pull/36019
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-11-14 14:46:06 +00:00
Guy Bedford
c9acb9e5b3
module: runtime deprecate subpath folder mappings
PR-URL: https://github.com/nodejs/node/pull/35747
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
2020-10-30 12:12:56 -04:00
Guy Bedford
ee9e3e75aa esm: use "node:" namespace for builtins
PR-URL: https://github.com/nodejs/node/pull/35387
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-09-29 18:20:28 -07:00
Guy Bedford
2d868fe822 module: exports pattern support
PR-URL: https://github.com/nodejs/node/pull/34718
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2020-09-17 18:56:17 -07:00
Guy Bedford
3fb7fcd821 esm: better package.json parser errors
PR-URL: https://github.com/nodejs/node/pull/35117
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-09-11 05:09:44 -07:00
Bradley Farias
4234904232 policy: implement scopes field
PR-URL: https://github.com/nodejs/node/pull/34552
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-08-26 14:35:34 -05:00
Denys Otrishko
a0846326dd esm: improve error message of ERR_UNSUPPORTED_ESM_URL_SCHEME
Refs: https://github.com/nodejs/node/issues/34765

PR-URL: https://github.com/nodejs/node/pull/34795
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2020-08-18 17:56:47 -07:00
Bradley Farias
e155d96014 policy: support conditions for redirects
PR-URL: https://github.com/nodejs/node/pull/34414
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2020-08-13 13:17:40 -05:00
Guy Bedford
f8976a76bb module: share CJS/ESM resolver fns, refactoring
PR-URL: https://github.com/nodejs/node/pull/34744
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-08-13 11:04:24 -07:00
Guy Bedford
77a515c31a module: custom --conditions flag option
PR-URL: https://github.com/nodejs/node/pull/34637
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2020-08-11 14:35:44 -07:00
Daniele Belardi
ec2ffd6b9d module: self referential modules in repl or -r
Load self referential modules from the repl and using the preload flag
`-r`. In both cases the base path used for resolution is the current
`process.cwd()`. Also fixes an internal cycle bug in the REPL exports
resolution.

PR-URL: https://github.com/nodejs/node/pull/32261
Fixes: https://github.com/nodejs/node/issues/31595
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Jan Krems <jan.krems@gmail.com>
2020-07-23 07:50:01 -07:00
Guy Bedford
1237955d41 module: package "imports" field
PR-URL: https://github.com/nodejs/node/pull/34117
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
2020-07-09 19:19:35 -07:00
Kirill Shatskiy
8f10bb2da5 esm: share package.json cache between ESM and CJS loaders
Refs: https://github.com/nodejs/node/issues/30674

PR-URL: https://github.com/nodejs/node/pull/33229
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
2020-05-24 16:22:31 -07:00
Luigi Pinca
b533fb3508 tools: enable no-else-return lint rule
Refs: https://github.com/nodejs/node/pull/32644
Refs: https://github.com/nodejs/node/pull/32662

PR-URL: https://github.com/nodejs/node/pull/32667
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2020-05-16 06:42:16 +02:00
Antoine du Hamel
1cb80d1e05 esm: improve commonjs hint on module not found
Adds hint when module specifier is a file URL.

PR-URL: https://github.com/nodejs/node/pull/33220
Fixes: https://github.com/nodejs/node/issues/33219
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2020-05-15 19:09:01 -07:00
Antoine du HAMEL
985e9c5fe5 module: add specific error for dir import
PR-URL: https://github.com/nodejs/node/pull/33220
Fixes: https://github.com/nodejs/node/issues/33219
Reviewed-By: Guy Bedford <guybedford@gmail.com>
2020-05-15 19:08:39 -07:00