Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: fix some errors in esm resolution algorithms #50898

Merged
merged 1 commit into from
Nov 29, 2023

Conversation

chjj
Copy link
Contributor

@chjj chjj commented Nov 24, 2023

Two errors I discovered when implementing the ESM resolution algorithm from scratch.

  1. PACKAGE_EXPORTS_RESOLVE - subpath is already prefixed with ./ due to the calling functions ensuring this.
  2. PACKAGE_TARGET_RESOLVE - A simple typo here. Order should be reversed.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders

@nodejs-github-bot nodejs-github-bot added doc Issues and PRs related to the documentations. esm Issues and PRs related to the ECMAScript Modules implementation. labels Nov 24, 2023
@GeoffreyBooth
Copy link
Member

implementing the ESM resolution algorithm from scratch.

We've been meaning to expose this logic in a helper function. Is that something you'd be interested in implementing?

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 24, 2023
@chjj
Copy link
Contributor Author

chjj commented Nov 24, 2023

@GeoffreyBooth, I don't know if I'd have the time to maintain a pure reference implementation, but my implementation here might be a good starting point for someone. Aside from using paths instead of URLs, it follows the documented algorithms as closely as possible.

@chjj
Copy link
Contributor Author

chjj commented Nov 24, 2023

Force pushed another typo I forgot about. PACKAGE_TARGET_RESOLVE 2.1 should say target instead of exports.

Section 3.3 of the same function also has confusing wording (I had to check the node.js code to implement it properly). I need to consider how to reword it though.

@GeoffreyBooth
Copy link
Member

I just meant exposing ours, like import { defaultResolve } from 'node:module'.

@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Nov 26, 2023
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/50898
✔  Done loading data for nodejs/node/pull/50898
----------------------------------- PR info ------------------------------------
Title      doc: fix some errors in esm resolution algorithms (#50898)
Author     Christopher Jeffrey (JJ)  (@chjj)
Branch     chjj:fix-esm-docs -> nodejs:main
Labels     doc, esm, author ready
Commits    1
 - doc: fix some errors in esm resolution algorithms
Committers 1
 - Christopher Jeffrey 
PR-URL: https://github.com/nodejs/node/pull/50898
Reviewed-By: Guy Bedford 
Reviewed-By: Geoffrey Booth 
Reviewed-By: Luigi Pinca 
Reviewed-By: Antoine du Hamel 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/50898
Reviewed-By: Guy Bedford 
Reviewed-By: Geoffrey Booth 
Reviewed-By: Luigi Pinca 
Reviewed-By: Antoine du Hamel 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last approving review:
   ⚠  - doc: fix some errors in esm resolution algorithms
   ℹ  This PR was created on Fri, 24 Nov 2023 17:13:06 GMT
   ✔  Approvals: 4
   ✔  - Guy Bedford (@guybedford): https://github.com/nodejs/node/pull/50898#pullrequestreview-1748266109
   ✔  - Geoffrey Booth (@GeoffreyBooth) (TSC): https://github.com/nodejs/node/pull/50898#pullrequestreview-1748269208
   ✔  - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/50898#pullrequestreview-1748269330
   ✔  - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/50898#pullrequestreview-1748269950
   ✔  Last GitHub CI successful
   ℹ  Green GitHub CI is sufficient
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/6996996694

@chjj
Copy link
Contributor Author

chjj commented Nov 29, 2023

@GeoffreyBooth, isn't this already going to be more-or-less exposed once import.meta.resolve accepts a parentURL?

I suppose CJS modules could access it if it were part of node:module?

@aduh95 aduh95 added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Nov 29, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Nov 29, 2023
@nodejs-github-bot nodejs-github-bot merged commit 59f57d2 into nodejs:main Nov 29, 2023
19 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 59f57d2

targos pushed a commit that referenced this pull request Dec 4, 2023
PR-URL: #50898
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@targos targos mentioned this pull request Dec 4, 2023
richardlau pushed a commit that referenced this pull request Mar 25, 2024
PR-URL: #50898
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@richardlau richardlau mentioned this pull request Mar 25, 2024
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 pending requests for changes, and a CI started. doc Issues and PRs related to the documentations. esm Issues and PRs related to the ECMAScript Modules implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants