FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

esm: fix emit deprecation on legacy main resolve by aduh95 · Pull Request #48664 · nodejs/node · GitHub

/ node Public

esm: fix emit deprecation on legacy main resolve - #48664

Merged
nodejs-github-bot merged 7 commits into
nodejs:mainfrom
aduh95:fix-dep0151
Jul 11, 2023
Merged

esm: fix emit deprecation on legacy main resolve#48664
nodejs-github-bot merged 7 commits into
nodejs:mainfrom
aduh95:fix-dep0151

Conversation

aduh95 commented Jul 5, 2023

Copy link
Copy Markdown
Contributor

#48325 introduced a bug where the deprecation is thrown for every resolve. This PR fixes that.

Refs: #48325

aduh95 requested a review from anonrig July 5, 2023 18:23

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

nodejs-github-bot added esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run. labels Jul 5, 2023

ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

probably should add a test case of an ESM "main" that omits the leading ./?

Comment thread lib/internal/modules/esm/resolve.js Outdated
anonrig added author ready PRs that have at least one approval, no outstanding review comments, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 5, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 5, 2023

Copy link
Copy Markdown
Collaborator

aduh95 added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 5, 2023
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 5, 2023

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

H4ad commented Jul 6, 2023
edited
Loading

Copy link
Copy Markdown
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 kResolvedByMain, ref: anonrig@a2a8e31#diff-b4c24f634e3741e5ad9e8c29864a48f2bd284a9d66d8fed3d077ccee0c44087bL160-L163

anonrig added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jul 11, 2023
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 11, 2023
nodejs-github-bot merged commit ffb1929 into nodejs:main Jul 11, 2023

Copy link
Copy Markdown
Collaborator

Landed in ffb1929

aduh95 deleted the fix-dep0151 branch July 11, 2023 17:39
juanarbol pushed a commit that referenced this pull request Jul 13, 2023
PR-URL: #48664
Refs: #48325
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
juanarbol mentioned this pull request Jul 13, 2023
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>
ruyadorno pushed a commit that referenced this pull request Sep 11, 2023
PR-URL: #48664
Refs: #48325
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
ruyadorno mentioned this pull request Sep 11, 2023
ruyadorno pushed a commit that referenced this pull request Sep 13, 2023
PR-URL: #48664
Refs: #48325
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
ruyadorno pushed a commit that referenced this pull request Sep 17, 2023
PR-URL: #48664
Refs: #48325
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
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

Labels

author ready PRs that have at least one approval, no outstanding review comments, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. esm Issues and PRs related to the ECMAScript Modules implementation. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants


Back | FazBrowse Home | New Git URL