esm: fix emit deprecation on legacy main resolve#48664
Merged
nodejs-github-bot merged 7 commits intonodejs:mainfrom Jul 11, 2023
Merged
esm: fix emit deprecation on legacy main resolve#48664nodejs-github-bot merged 7 commits intonodejs:mainfrom
nodejs-github-bot merged 7 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
ljharb
approved these changes
Jul 5, 2023
Member
ljharb
left a comment
There was a problem hiding this comment.
probably should add a test case of an ESM "main" that omits the leading ./?
anonrig
reviewed
Jul 5, 2023
anonrig
approved these changes
Jul 5, 2023
Trott
approved these changes
Jul 5, 2023
Collaborator
Collaborator
RafaelGSS
approved these changes
Jul 6, 2023
Collaborator
Member
|
I think this change can be simplified to: /**
* Legacy CommonJS main resolution:
* 1. let M = pkg_url + (json main field)
* 2. TRY(M, M.js, M.json, M.node)
* 3. TRY(M/index.js, M/index.json, M/index.node)
* 4. TRY(pkg_url/index.js, pkg_url/index.json, pkg_url/index.node)
* 5. NOT_FOUND
* @param {URL} packageJSONUrl
* @param {PackageConfig} packageConfig
* @param {string | URL | undefined} base
* @returns {URL}
*/
function legacyMainResolve(packageJSONUrl, packageConfig, base) {
const packageJsonUrlString = packageJSONUrl.href;
if (typeof packageJsonUrlString !== 'string') {
throw new ERR_INVALID_ARG_TYPE('packageJSONUrl', ['URL'], packageJSONUrl);
}
const baseStringified = isURL(base) ? base.href : base;
const resolvedOption = FSLegacyMainResolve(packageJsonUrlString, packageConfig.main, baseStringified);
const baseUrl = resolvedOption <= legacyMainResolveExtensionsIndexes.kResolvedByMainIndexNode ? `./${packageConfig.main}` : '';
const resolvedUrl = new URL(baseUrl + legacyMainResolveExtensions[resolvedOption], packageJSONUrl);
+ if (resolvedOption !== legacyMainResolveExtensionsIndexes.kResolvedByMain)
emitLegacyIndexDeprecation(resolvedUrl, packageJSONUrl, base, packageConfig.main);
return resolvedUrl;
}The deprecation should be emitted for every case except from |
This was referenced Jul 7, 2023
H4ad
requested changes
Jul 11, 2023
H4ad
approved these changes
Jul 11, 2023
Collaborator
|
Landed in ffb1929 |
Merged
Ceres6
pushed a commit
to Ceres6/node
that referenced
this pull request
Aug 14, 2023
PR-URL: nodejs#48664 Refs: nodejs#48325 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Ceres6
pushed a commit
to Ceres6/node
that referenced
this pull request
Aug 14, 2023
PR-URL: nodejs#48664 Refs: nodejs#48325 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Merged
H4ad
pushed a commit
to H4ad/node
that referenced
this pull request
Dec 3, 2023
PR-URL: nodejs#48664 Refs: nodejs#48325 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Backport-PR-URL: nodejs#48664
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#48325 introduced a bug where the deprecation is thrown for every resolve. This PR fixes that.
Refs: #48325