From 92b25651835da0edf2b8aa9630ea152cbef2e21f Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 13 Jan 2021 16:09:17 -0500 Subject: [PATCH 01/18] module: "type": "module" legacy main deprecate --- doc/api/deprecations.md | 19 +++++++++++++++++-- doc/api/esm.md | 3 +++ lib/internal/modules/esm/resolve.js | 15 ++++++++++++++- .../test-esm-exports-pending-deprecations.mjs | 3 ++- test/es-module/test-esm-exports.mjs | 5 ++++- .../fixtures/node_modules/no_exports/index.js | 1 + .../node_modules/no_exports/package.json | 3 +++ 7 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/node_modules/no_exports/index.js create mode 100644 test/fixtures/node_modules/no_exports/package.json diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index ca1a0c6ba4b4ca..9fcbc51e515411 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2719,13 +2719,28 @@ changes: description: Runtime deprecation. --> -Type: Runtime - The `process.config` property is intended to provide access to configuration settings set when the Node.js binary was compiled. However, the property has been mutable by user code making it impossible to rely on. The ability to change the value has been deprecated and will be disabled in the future. +### DEP0150: Folder index for "type": "module" + + +Type: Runtime + +Previously, `index.js` lookup would apply for `require('pkg')` even for packages +with a `"type": "module"` field in their package.json + +With this deprecation, all packages with `"type": "module"` require an explicit +`"exports"` field entry point to resolve for the main. + + [Legacy URL API]: url.md#url_legacy_url_api [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 diff --git a/doc/api/esm.md b/doc/api/esm.md index 85a7146fc13f46..ad3756ab0ce341 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -1086,6 +1086,9 @@ The resolver can throw the following errors: > **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packageSubpath_, > _pjson.exports_, _defaultConditions_). > 1. Otherwise, if _packageSubpath_ is equal to _"."_, then +> 1. If _pjson_ is not **null** and _pjson_._type_ is equal to _"module"_, +> then, +> 1. Throw a _Package Path Not Exports_ error. > 1. Return the result applying the legacy **LOAD_AS_DIRECTORY** > CommonJS resolver to _packageURL_, throwing a _Module Not Found_ > error for no resolution. diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 5a578902cbb01a..ff634743abedb9 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -90,6 +90,16 @@ function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) { ); } +function emitLegacyIndexTypeModuleDeprecation(packageJSONUrl, base) { + const pkgPath = fileURLToPath(new URL('.', packageJSONUrl)); + const basePath = fileURLToPath(base); + process.emitWarning( + `Package ${pkgPath} has a "type": "module" field in its package.json, but` + + ` does not define an "exports" field, imported from ${basePath}.\nLegacy ` + + 'main resolution lookups are deprecated for packages with "type": "module".' + ); +} + function getConditionsSet(conditions) { if (conditions !== undefined && conditions !== DEFAULT_CONDITIONS) { if (!ArrayIsArray(conditions)) { @@ -681,8 +691,11 @@ function packageResolve(specifier, base, conditions) { return packageExportsResolve( packageJSONUrl, packageSubpath, packageConfig, base, conditions ).resolved; - if (packageSubpath === '.') + if (packageSubpath === '.') { + if (packageConfig.type === 'module') + emitLegacyIndexTypeModuleDeprecation(packageJSONUrl, base); return legacyMainResolve(packageJSONUrl, packageConfig, base); + } return new URL(packageSubpath, packageJSONUrl); // Cross-platform root check. } while (packageJSONPath.length !== lastPath.length); diff --git a/test/es-module/test-esm-exports-pending-deprecations.mjs b/test/es-module/test-esm-exports-pending-deprecations.mjs index edc9ae814a59a8..2d52b01fdbda9f 100644 --- a/test/es-module/test-esm-exports-pending-deprecations.mjs +++ b/test/es-module/test-esm-exports-pending-deprecations.mjs @@ -6,7 +6,8 @@ let curWarning = 0; const expectedWarnings = [ '"./sub/"', '"./fallbackdir/"', - '"./subpath/"' + '"./subpath/"', + 'no_exports' ]; process.addListener('warning', mustCall((warning) => { diff --git a/test/es-module/test-esm-exports.mjs b/test/es-module/test-esm-exports.mjs index d234099732e3aa..7ea64d84a5a3bc 100644 --- a/test/es-module/test-esm-exports.mjs +++ b/test/es-module/test-esm-exports.mjs @@ -35,7 +35,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; ['pkgexports-sugar', { default: 'main' }], // Path patterns ['pkgexports/subpath/sub-dir1', { default: 'main' }], - ['pkgexports/features/dir1', { default: 'main' }] + ['pkgexports/features/dir1', { default: 'main' }], ]); if (isRequire) { @@ -44,6 +44,9 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; validSpecifiers.set('pkgexports/subpath/dir1/', { default: 'main' }); validSpecifiers.set('pkgexports/subpath/dir2', { default: 'index' }); validSpecifiers.set('pkgexports/subpath/dir2/', { default: 'index' }); + } else { + // no exports field + validSpecifiers.set('no_exports', { default: 'main' }); } for (const [validSpecifier, expected] of validSpecifiers) { diff --git a/test/fixtures/node_modules/no_exports/index.js b/test/fixtures/node_modules/no_exports/index.js new file mode 100644 index 00000000000000..748e47637e97fa --- /dev/null +++ b/test/fixtures/node_modules/no_exports/index.js @@ -0,0 +1 @@ +export default 'main' diff --git a/test/fixtures/node_modules/no_exports/package.json b/test/fixtures/node_modules/no_exports/package.json new file mode 100644 index 00000000000000..3dbc1ca591c055 --- /dev/null +++ b/test/fixtures/node_modules/no_exports/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} From 6c21f238f4ad622d36db2f86b8c2cf53aa4a4c0b Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 13 Jan 2021 16:17:38 -0500 Subject: [PATCH 02/18] add pr link --- doc/api/deprecations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 9fcbc51e515411..5e49871abc3597 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2728,7 +2728,7 @@ change the value has been deprecated and will be disabled in the future. From 318b0d0a0cb110c50ba0a9984820de14254cf947 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 13 Jan 2021 17:53:44 -0500 Subject: [PATCH 03/18] put deprecation behind --pending-deprecation --- doc/api/deprecations.md | 2 +- lib/internal/modules/esm/resolve.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 5e49871abc3597..7d6a09c8158526 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2732,7 +2732,7 @@ changes: description: Runtime deprecation. --> -Type: Runtime +Type: Documentation (supports [`--pending-deprecation`][]) Previously, `index.js` lookup would apply for `require('pkg')` even for packages with a `"type": "module"` field in their package.json diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index ff634743abedb9..27020047523ac9 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -91,6 +91,8 @@ function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) { } function emitLegacyIndexTypeModuleDeprecation(packageJSONUrl, base) { + if (!pendingDeprecation) + return; const pkgPath = fileURLToPath(new URL('.', packageJSONUrl)); const basePath = fileURLToPath(base); process.emitWarning( From d6df580cc49457b17b503e86a1c59adf11047c9e Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 12:04:49 -0500 Subject: [PATCH 04/18] deprecate index main and extension lookups instead --- lib/internal/modules/esm/resolve.js | 85 ++++++++++--------- .../test-esm-exports-pending-deprecations.mjs | 3 +- test/es-module/test-esm-exports.mjs | 1 + .../node_modules/default_index/index.js | 1 + .../node_modules/default_index/package.json | 4 + 5 files changed, 53 insertions(+), 41 deletions(-) create mode 100644 test/fixtures/node_modules/default_index/index.js create mode 100644 test/fixtures/node_modules/default_index/package.json diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 27020047523ac9..97a4c5a57c1c5f 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -90,16 +90,29 @@ function emitFolderMapDeprecation(match, pjsonUrl, isExports, base) { ); } -function emitLegacyIndexTypeModuleDeprecation(packageJSONUrl, base) { +function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { if (!pendingDeprecation) return; + const { format } = defaultGetFormat(url); + if (format !== 'module') + return; + const path = fileURLToPath(url); const pkgPath = fileURLToPath(new URL('.', packageJSONUrl)); const basePath = fileURLToPath(base); - process.emitWarning( - `Package ${pkgPath} has a "type": "module" field in its package.json, but` + - ` does not define an "exports" field, imported from ${basePath}.\nLegacy ` + - 'main resolution lookups are deprecated for packages with "type": "module".' - ); + if (main) + process.emitWarning( + `Package ${pkgPath} has a "main" field set to ${JSONStringify(main)}, ` + + `excluding the full extension to the resolved file at "${ + path.slice(pkgPath.length)}", imported from ${basePath}.\n Automatic ` + + 'extension resolution of the "main" field is deprecated for ES modules.' + ); + else + process.emitWarning( + `No "main" or "exports" field defined in the package.json for ${pkgPath + } resolving the main entry point "${path.slice(pkgPath.length)}", ` + + `imported from ${basePath}.\nDefault "index" lookups for the main are ` + + 'deprecated for explicit definitions.' + ); } function getConditionsSet(conditions) { @@ -221,41 +234,33 @@ function legacyMainResolve(packageJSONUrl, packageConfig, base) { if (fileExists(guess = new URL(`./${packageConfig.main}`, packageJSONUrl))) { return guess; - } - if (fileExists(guess = new URL(`./${packageConfig.main}.js`, - packageJSONUrl))) { - return guess; - } - if (fileExists(guess = new URL(`./${packageConfig.main}.json`, - packageJSONUrl))) { - return guess; - } - if (fileExists(guess = new URL(`./${packageConfig.main}.node`, - packageJSONUrl))) { - return guess; - } - if (fileExists(guess = new URL(`./${packageConfig.main}/index.js`, - packageJSONUrl))) { - return guess; - } - if (fileExists(guess = new URL(`./${packageConfig.main}/index.json`, - packageJSONUrl))) { - return guess; - } - if (fileExists(guess = new URL(`./${packageConfig.main}/index.node`, - packageJSONUrl))) { + } else if (fileExists(guess = new URL(`./${packageConfig.main}.js`, + packageJSONUrl))); + else if (fileExists(guess = new URL(`./${packageConfig.main}.json`, + packageJSONUrl))); + else if (fileExists(guess = new URL(`./${packageConfig.main}.node`, + packageJSONUrl))); + else if (fileExists(guess = new URL(`./${packageConfig.main}/index.js`, + packageJSONUrl))); + else if (fileExists(guess = new URL(`./${packageConfig.main}/index.json`, + packageJSONUrl))); + else if (fileExists(guess = new URL(`./${packageConfig.main}/index.node`, + packageJSONUrl))); + else guess = undefined; + if (guess) { + emitLegacyIndexDeprecation(guess, packageJSONUrl, base, + packageConfig.main); return guess; } // Fallthrough. } - if (fileExists(guess = new URL('./index.js', packageJSONUrl))) { - return guess; - } + if (fileExists(guess = new URL('./index.js', packageJSONUrl))); // So fs. - if (fileExists(guess = new URL('./index.json', packageJSONUrl))) { - return guess; - } - if (fileExists(guess = new URL('./index.node', packageJSONUrl))) { + else if (fileExists(guess = new URL('./index.json', packageJSONUrl))); + else if (fileExists(guess = new URL('./index.node', packageJSONUrl))); + else guess = undefined; + if (guess) { + emitLegacyIndexDeprecation(guess, packageJSONUrl, base, packageConfig.main); return guess; } // Not found. @@ -693,11 +698,8 @@ function packageResolve(specifier, base, conditions) { return packageExportsResolve( packageJSONUrl, packageSubpath, packageConfig, base, conditions ).resolved; - if (packageSubpath === '.') { - if (packageConfig.type === 'module') - emitLegacyIndexTypeModuleDeprecation(packageJSONUrl, base); + if (packageSubpath === '.') return legacyMainResolve(packageJSONUrl, packageConfig, base); - } return new URL(packageSubpath, packageJSONUrl); // Cross-platform root check. } while (packageJSONPath.length !== lastPath.length); @@ -906,3 +908,6 @@ module.exports = { packageExportsResolve, packageImportsResolve }; + +// cycle +const { defaultGetFormat } = require('internal/modules/esm/get_format'); diff --git a/test/es-module/test-esm-exports-pending-deprecations.mjs b/test/es-module/test-esm-exports-pending-deprecations.mjs index 2d52b01fdbda9f..ea7665fceb430d 100644 --- a/test/es-module/test-esm-exports-pending-deprecations.mjs +++ b/test/es-module/test-esm-exports-pending-deprecations.mjs @@ -7,7 +7,8 @@ const expectedWarnings = [ '"./sub/"', '"./fallbackdir/"', '"./subpath/"', - 'no_exports' + 'no_exports', + 'default_index' ]; process.addListener('warning', mustCall((warning) => { diff --git a/test/es-module/test-esm-exports.mjs b/test/es-module/test-esm-exports.mjs index 7ea64d84a5a3bc..96ecd7c1ef4d5e 100644 --- a/test/es-module/test-esm-exports.mjs +++ b/test/es-module/test-esm-exports.mjs @@ -47,6 +47,7 @@ import fromInside from '../fixtures/node_modules/pkgexports/lib/hole.js'; } else { // no exports field validSpecifiers.set('no_exports', { default: 'main' }); + validSpecifiers.set('default_index', { default: 'main' }); } for (const [validSpecifier, expected] of validSpecifiers) { diff --git a/test/fixtures/node_modules/default_index/index.js b/test/fixtures/node_modules/default_index/index.js new file mode 100644 index 00000000000000..748e47637e97fa --- /dev/null +++ b/test/fixtures/node_modules/default_index/index.js @@ -0,0 +1 @@ +export default 'main' diff --git a/test/fixtures/node_modules/default_index/package.json b/test/fixtures/node_modules/default_index/package.json new file mode 100644 index 00000000000000..7665d7a8037428 --- /dev/null +++ b/test/fixtures/node_modules/default_index/package.json @@ -0,0 +1,4 @@ +{ + "main": "index", + "type": "module" +} From 7dfb539d6d927b8ba5ea2725161e35a42163f42b Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 12:08:27 -0500 Subject: [PATCH 05/18] update deprecation --- doc/api/deprecations.md | 13 +++++++------ lib/internal/modules/esm/resolve.js | 8 ++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7d6a09c8158526..7fa48a2f60640d 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2724,21 +2724,22 @@ settings set when the Node.js binary was compiled. However, the property has been mutable by user code making it impossible to rely on. The ability to change the value has been deprecated and will be disabled in the future. -### DEP0150: Folder index for "type": "module" +### DEP0XXX: Main index lookup and extension searching + Type: Documentation (supports [`--pending-deprecation`][]) -Previously, `index.js` lookup would apply for `require('pkg')` even for packages -with a `"type": "module"` field in their package.json +Previously, `index.js` and extension searching lookups would apply to +`import 'pkg'` main entry point resolution, even when resolving ES modules. -With this deprecation, all packages with `"type": "module"` require an explicit -`"exports"` field entry point to resolve for the main. +With this deprecation, all ES module main entry point resolutions require +an explicit `"exports"` or `"main"` entry with the exact file extension. [Legacy URL API]: url.md#url_legacy_url_api diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 97a4c5a57c1c5f..530098f39d3fb3 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -104,14 +104,18 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { `Package ${pkgPath} has a "main" field set to ${JSONStringify(main)}, ` + `excluding the full extension to the resolved file at "${ path.slice(pkgPath.length)}", imported from ${basePath}.\n Automatic ` + - 'extension resolution of the "main" field is deprecated for ES modules.' + 'extension resolution of the "main" field is deprecated for ES modules.', + 'DeprecationWarning', + 'DEP0150' ); else process.emitWarning( `No "main" or "exports" field defined in the package.json for ${pkgPath } resolving the main entry point "${path.slice(pkgPath.length)}", ` + `imported from ${basePath}.\nDefault "index" lookups for the main are ` + - 'deprecated for explicit definitions.' + 'deprecated for explicit definitions.', + 'DeprecationWarning', + 'DEP0150' ); } From e1821cfa356c46c8c57ea1af39480ad79b91bb8b Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 12:21:06 -0500 Subject: [PATCH 06/18] remove spec change --- doc/api/esm.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/api/esm.md b/doc/api/esm.md index ad3756ab0ce341..85a7146fc13f46 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -1086,9 +1086,6 @@ The resolver can throw the following errors: > **PACKAGE_EXPORTS_RESOLVE**(_packageURL_, _packageSubpath_, > _pjson.exports_, _defaultConditions_). > 1. Otherwise, if _packageSubpath_ is equal to _"."_, then -> 1. If _pjson_ is not **null** and _pjson_._type_ is equal to _"module"_, -> then, -> 1. Throw a _Package Path Not Exports_ error. > 1. Return the result applying the legacy **LOAD_AS_DIRECTORY** > CommonJS resolver to _packageURL_, throwing a _Module Not Found_ > error for no resolution. From 2ce97400424608cae818d3e40e39b9c73a7dc149 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 14:15:27 -0500 Subject: [PATCH 07/18] Apply suggestions from code review Co-authored-by: Antoine du Hamel --- doc/api/deprecations.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7fa48a2f60640d..20310230454153 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2730,16 +2730,17 @@ change the value has been deprecated and will be disabled in the future. changes: - version: REPLACEME pr-url: https://github.com/nodejs/node/pull/36918 - description: Documentation-only deprecation. + description: Documentation-only deprecation + with `--pending-deprecation` support. --> -Type: Documentation (supports [`--pending-deprecation`][]) +Type: Documentation-only (supports [`--pending-deprecation`][]) Previously, `index.js` and extension searching lookups would apply to `import 'pkg'` main entry point resolution, even when resolving ES modules. With this deprecation, all ES module main entry point resolutions require -an explicit `"exports"` or `"main"` entry with the exact file extension. +an explicit [`"exports"`][] or [`"main"`][] entry with the exact file extension. [Legacy URL API]: url.md#url_legacy_url_api From 7885f07b94cd8c2b6af7fe4be03030ec8816c3e3 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 14:25:54 -0500 Subject: [PATCH 08/18] fixup refs --- doc/api/deprecations.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 20310230454153..e464297a2aecf1 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2740,7 +2740,7 @@ Previously, `index.js` and extension searching lookups would apply to `import 'pkg'` main entry point resolution, even when resolving ES modules. With this deprecation, all ES module main entry point resolutions require -an explicit [`"exports"`][] or [`"main"`][] entry with the exact file extension. +an explicit [`"exports" or "main" entry`] with the exact file extension. [Legacy URL API]: url.md#url_legacy_url_api @@ -2785,6 +2785,7 @@ an explicit [`"exports"`][] or [`"main"`][] entry with the exact file extension. [`ecdh.setPublicKey()`]: crypto.md#crypto_ecdh_setpublickey_publickey_encoding [`emitter.listenerCount(eventName)`]: events.md#events_emitter_listenercount_eventname [`events.listenerCount(emitter, eventName)`]: events.md#events_events_listenercount_emitter_eventname +[`"exports" or "main" entry`]: packages.md#packages_main_entry_point_export [`fs.FileHandle`]: fs.md#fs_class_filehandle [`fs.access()`]: fs.md#fs_fs_access_path_mode_callback [`fs.createReadStream()`]: fs.md#fs_fs_createreadstream_path_options @@ -2869,7 +2870,7 @@ an explicit [`"exports"`][] or [`"main"`][] entry with the exact file extension. [from_string_encoding]: buffer.md#buffer_static_method_buffer_from_string_encoding [legacy `urlObject`]: url.md#url_legacy_urlobject [static methods of `crypto.Certificate()`]: crypto.md#crypto_class_certificate -[subpath exports]: #packages_subpath_exports -[subpath folder mappings]: #packages_subpath_folder_mappings -[subpath imports]: #packages_subpath_imports -[subpath patterns]: #packages_subpath_patterns +[subpath exports]: packages.md#packages_subpath_exports +[subpath folder mappings]: packages.md#packages_subpath_folder_mappings +[subpath imports]: packages.md#packages_subpath_imports +[subpath patterns]: packages.md#packages_subpath_patterns From a8208b2a675978c1dc903f1fd53c499419668f6f Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 14:54:18 -0500 Subject: [PATCH 09/18] Update lib/internal/modules/esm/resolve.js Co-authored-by: Jordan Harband --- lib/internal/modules/esm/resolve.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 530098f39d3fb3..36234e5537f9a1 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -102,7 +102,7 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { if (main) process.emitWarning( `Package ${pkgPath} has a "main" field set to ${JSONStringify(main)}, ` + - `excluding the full extension to the resolved file at "${ + `excluding the full filename and extension to the resolved file at "${ path.slice(pkgPath.length)}", imported from ${basePath}.\n Automatic ` + 'extension resolution of the "main" field is deprecated for ES modules.', 'DeprecationWarning', From 08af32f972c36b3dfab0bb0a5869c28be0683b40 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 14:55:11 -0500 Subject: [PATCH 10/18] Update deprecations.md --- doc/api/deprecations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index e464297a2aecf1..4c0b6776d8a380 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2750,6 +2750,7 @@ an explicit [`"exports" or "main" entry`] with the exact file extension. [`--pending-deprecation`]: cli.md#cli_pending_deprecation [`--throw-deprecation`]: cli.md#cli_throw_deprecation [`--unhandled-rejections`]: cli.md#cli_unhandled_rejections_mode +[`"exports" or "main" entry`]: packages.md#packages_main_entry_point_export [`Buffer.allocUnsafeSlow(size)`]: buffer.md#buffer_static_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.md#buffer_static_method_buffer_from_array [`Buffer.from(buffer)`]: buffer.md#buffer_static_method_buffer_from_buffer @@ -2785,7 +2786,6 @@ an explicit [`"exports" or "main" entry`] with the exact file extension. [`ecdh.setPublicKey()`]: crypto.md#crypto_ecdh_setpublickey_publickey_encoding [`emitter.listenerCount(eventName)`]: events.md#events_emitter_listenercount_eventname [`events.listenerCount(emitter, eventName)`]: events.md#events_events_listenercount_emitter_eventname -[`"exports" or "main" entry`]: packages.md#packages_main_entry_point_export [`fs.FileHandle`]: fs.md#fs_class_filehandle [`fs.access()`]: fs.md#fs_fs_access_path_mode_callback [`fs.createReadStream()`]: fs.md#fs_fs_createreadstream_path_options From 1c079c016ee6445970ed199082926a6a42877443 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 17:11:48 -0500 Subject: [PATCH 11/18] Apply suggestions from code review Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> --- doc/api/deprecations.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 4c0b6776d8a380..7fc735b3f3f892 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2740,17 +2740,17 @@ Previously, `index.js` and extension searching lookups would apply to `import 'pkg'` main entry point resolution, even when resolving ES modules. With this deprecation, all ES module main entry point resolutions require -an explicit [`"exports" or "main" entry`] with the exact file extension. +an explicit [`"exports"` or `"main"` entry][] with the exact file extension. [Legacy URL API]: url.md#url_legacy_url_api [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 [WHATWG URL API]: url.md#url_the_whatwg_url_api +[`"exports"` or `"main"` entry]: packages.md#packages_main_entry_point_export [`--pending-deprecation`]: cli.md#cli_pending_deprecation [`--throw-deprecation`]: cli.md#cli_throw_deprecation [`--unhandled-rejections`]: cli.md#cli_unhandled_rejections_mode -[`"exports" or "main" entry`]: packages.md#packages_main_entry_point_export [`Buffer.allocUnsafeSlow(size)`]: buffer.md#buffer_static_method_buffer_allocunsafeslow_size [`Buffer.from(array)`]: buffer.md#buffer_static_method_buffer_from_array [`Buffer.from(buffer)`]: buffer.md#buffer_static_method_buffer_from_buffer From 64c741ced150e2e8086e5450f2316345e4d532ec Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 18:27:02 -0500 Subject: [PATCH 12/18] Apply suggestions from code review Co-authored-by: Antoine du Hamel --- lib/internal/modules/esm/resolve.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 36234e5537f9a1..3c9edadc21f4f0 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -103,7 +103,7 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { process.emitWarning( `Package ${pkgPath} has a "main" field set to ${JSONStringify(main)}, ` + `excluding the full filename and extension to the resolved file at "${ - path.slice(pkgPath.length)}", imported from ${basePath}.\n Automatic ` + + StringPrototypeSlice(path, pkgPath.length)}", imported from ${basePath}.\n Automatic ` + 'extension resolution of the "main" field is deprecated for ES modules.', 'DeprecationWarning', 'DEP0150' @@ -111,7 +111,7 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { else process.emitWarning( `No "main" or "exports" field defined in the package.json for ${pkgPath - } resolving the main entry point "${path.slice(pkgPath.length)}", ` + + } resolving the main entry point "${StringPrototypeSlice(path, pkgPath.length)}", ` + `imported from ${basePath}.\nDefault "index" lookups for the main are ` + 'deprecated for explicit definitions.', 'DeprecationWarning', From 8a89c77ea856a1dc49625fc5768cd80de88def81 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Fri, 15 Jan 2021 18:33:13 -0500 Subject: [PATCH 13/18] fixup linting --- doc/api/deprecations.md | 1 - lib/internal/modules/esm/resolve.js | 11 ++++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 7fc735b3f3f892..31633868d4a210 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2742,7 +2742,6 @@ Previously, `index.js` and extension searching lookups would apply to With this deprecation, all ES module main entry point resolutions require an explicit [`"exports"` or `"main"` entry][] with the exact file extension. - [Legacy URL API]: url.md#url_legacy_url_api [NIST SP 800-38D]: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf [RFC 6066]: https://tools.ietf.org/html/rfc6066#section-3 diff --git a/lib/internal/modules/esm/resolve.js b/lib/internal/modules/esm/resolve.js index 3c9edadc21f4f0..d3867a07b1336b 100644 --- a/lib/internal/modules/esm/resolve.js +++ b/lib/internal/modules/esm/resolve.js @@ -103,17 +103,18 @@ function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) { process.emitWarning( `Package ${pkgPath} has a "main" field set to ${JSONStringify(main)}, ` + `excluding the full filename and extension to the resolved file at "${ - StringPrototypeSlice(path, pkgPath.length)}", imported from ${basePath}.\n Automatic ` + - 'extension resolution of the "main" field is deprecated for ES modules.', + StringPrototypeSlice(path, pkgPath.length)}", imported from ${ + basePath}.\n Automatic extension resolution of the "main" field is` + + 'deprecated for ES modules.', 'DeprecationWarning', 'DEP0150' ); else process.emitWarning( `No "main" or "exports" field defined in the package.json for ${pkgPath - } resolving the main entry point "${StringPrototypeSlice(path, pkgPath.length)}", ` + - `imported from ${basePath}.\nDefault "index" lookups for the main are ` + - 'deprecated for explicit definitions.', + } resolving the main entry point "${ + StringPrototypeSlice(path, pkgPath.length)}", imported from ${basePath + }.\nDefault "index" lookups for the main are deprecated for ES modules.`, 'DeprecationWarning', 'DEP0150' ); From d80827935391f50156be2acb170e6aceb62f81ac Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 23 Jan 2021 13:11:28 +0200 Subject: [PATCH 14/18] fix rebase issue --- doc/api/deprecations.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 31633868d4a210..259550974a39e3 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2719,6 +2719,8 @@ changes: description: Runtime deprecation. --> +Type: Runtime. + The `process.config` property is intended to provide access to configuration settings set when the Node.js binary was compiled. However, the property has been mutable by user code making it impossible to rely on. The ability to From 915c43381203151194e6133467f5da048f3d878b Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 23 Jan 2021 13:11:54 +0200 Subject: [PATCH 15/18] formatting --- doc/api/deprecations.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 259550974a39e3..1d502cbe4b449b 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2719,7 +2719,7 @@ changes: description: Runtime deprecation. --> -Type: Runtime. +Type: Runtime The `process.config` property is intended to provide access to configuration settings set when the Node.js binary was compiled. However, the property has From ead9e3ac6ced79c82037be9f164aba605ba7eac8 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sat, 23 Jan 2021 14:05:04 +0200 Subject: [PATCH 16/18] Apply suggestions from code review Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> --- doc/api/deprecations.md | 1 - test/es-module/test-esm-exports.mjs | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index 1d502cbe4b449b..092b1a1847834f 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -2727,7 +2727,6 @@ been mutable by user code making it impossible to rely on. The ability to change the value has been deprecated and will be disabled in the future. ### DEP0XXX: Main index lookup and extension searching -