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: update module customization hooks docs #49265

Conversation

GeoffreyBooth
Copy link
Member

@GeoffreyBooth GeoffreyBooth commented Aug 21, 2023

This PR builds on and follows up #49261.

The aim here was to implement most of this to-do list. In particular:

  • I hopefully removed all references to the “Loaders API” and similar nomenclature, in favor of “module customization hooks” or “hooks” or similar.

  • I moved most of the “how to use this API” text out of the module.register() section and into a new section “Enabling” under the “Customization Hooks” heading.

  • I removed all references to --experimental-loader except in cli.md, rewriting to recommend --import with register() instead. We’re considering removing the --experimental-loader flag, but for now at least we want to discourage its use. (We anticipate that most third-party libraries like ts-node will need code on the main thread, which --import with register() can enable but --experimental-loader cannot, so people should get familiar with the more powerful approach and we don’t need a secondary, less capable method.)

  • I added CommonJS versions of all code samples that could support them (so anything running on the main thread, since the hooks module needs to export specific named functions).

  • I classified the overall Module Customization Hooks API as stability level “1.1 - Active development” and the resolve and load hooks as “1.2 - Release candidate,” and globalPreload as “1.0 - Early development” (since I can’t mark it as deprecated, but its end is near whenever esm: remove globalPreload hook (superseded by initialize) #49144 lands).

  • I added some mentions that parts of this work for CommonJS modules and require as well.

  • The CoffeeScript example seemed to have gotten out of date, so I rewrote it to how I think it should be now that CommonJS is supported.

  • Miscellaneous cleanup.

What’s left for follow-up PRs:

  • Remove the globalPreload section as part of esm: remove globalPreload hook (superseded by initialize) #49144.

  • Remove the mention of --experimental-loader from cli.md?

  • Update --experimental-loader to print a warning that it may be removed in the future, and users should use --import with register instead; this warning could even generate example code that shows --import with a data URL that includes the value of what was passed to --experimental-loader (similar to how we have a fancy error message with suggested new code for unknown named exports from CommonJS modules).

Also fixes #49282.

cc @nodejs/loaders @nodejs/modules @aduh95 @JakobJingleheimer

@GeoffreyBooth GeoffreyBooth added doc Issues and PRs related to the documentations. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders labels Aug 21, 2023
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules

@GeoffreyBooth GeoffreyBooth force-pushed the update-module-customization-hooks-docs branch 2 times, most recently from e96232b to 0a327aa Compare August 21, 2023 04:40
doc/api/cli.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
@aduh95
Copy link
Contributor

aduh95 commented Aug 22, 2023

Maybe we could address #49282 as part of this PR?

@GeoffreyBooth GeoffreyBooth force-pushed the update-module-customization-hooks-docs branch from 5686941 to aa414fa Compare August 22, 2023 22:13
@GeoffreyBooth
Copy link
Member Author

GeoffreyBooth commented Aug 22, 2023

Maybe we could address #49282 as part of this PR?

How, exactly? The examples already show the functions’ signatures as being async.

Edit: The resolve example was sync, but this PR adds the async keyword even though it’s unnecessary for this particular example (since the example resolve here doesn’t await anything). This PR also adds a an overview of the hooks’ signatures in https://github.com/nodejs/node/pull/49265/files#diff-4e8f3cce79719e4a337f58575b20c998b093eb64164b847ca0eb9ba884d8a801R341-R351, showing them all as async.

doc/api/module.md Outdated Show resolved Hide resolved
`second.mjs` define a `resolve` hook, both will be called, in the order they
were registered. The same applies to all the other hooks.

### Communication between main and hooks threads
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep calling it the loader thread?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think so. It's the thread where the hooks run. One term is better than two.

Copy link
Member

Choose a reason for hiding this comment

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

Orchestrator/orchestration threads?

Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like "hooks threads", especially if the goal is to make room for hooks in other core modules. Let's keep "loader thread" until we find a better name?

Suggested change
### Communication between main and hooks threads
### Communication between main and loader threads

Copy link
Member Author

Choose a reason for hiding this comment

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

Customization thread?

I wasn't assuming we'd need a thread like this (or use this one) for other systems, but who knows?

doc/api/module.md Outdated Show resolved Hide resolved
GeoffreyBooth and others added 7 commits August 23, 2023 21:01
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com>
@GeoffreyBooth GeoffreyBooth force-pushed the update-module-customization-hooks-docs branch from 4937898 to 230124d Compare August 24, 2023 04:02
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Outdated Show resolved Hide resolved
doc/api/module.md Show resolved Hide resolved
`second.mjs` define a `resolve` hook, both will be called, in the order they
were registered. The same applies to all the other hooks.

### Communication between main and hooks threads
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like "hooks threads", especially if the goal is to make room for hooks in other core modules. Let's keep "loader thread" until we find a better name?

Suggested change
### Communication between main and hooks threads
### Communication between main and loader threads

doc/api/module.md Outdated Show resolved Hide resolved
Comment on lines +505 to +506
`resolve`); if `resolve` provides a `format`, a custom `load` hook is required
even if only to pass the value to the Node.js default `load` hook.
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're editing this, we should consider rephrase that, I don't understand what it means.

GeoffreyBooth and others added 2 commits August 24, 2023 09:44
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
@GeoffreyBooth GeoffreyBooth 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. author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Aug 24, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 24, 2023
@nodejs-github-bot nodejs-github-bot merged commit 33710e7 into nodejs:main Aug 24, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 33710e7

UlisesGascon pushed a commit that referenced this pull request Sep 10, 2023
PR-URL: #49265
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@UlisesGascon UlisesGascon mentioned this pull request Sep 10, 2023
alexfernandez pushed a commit to alexfernandez/node that referenced this pull request Nov 1, 2023
PR-URL: nodejs#49265
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
targos pushed a commit to targos/node that referenced this pull request Nov 11, 2023
PR-URL: nodejs#49265
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
@targos targos added the backported-to-v18.x PRs backported to the v18.x-staging branch. label Nov 23, 2023
targos pushed a commit that referenced this pull request Nov 23, 2023
PR-URL: #49265
Backport-PR-URL: #50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#49265
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
PR-URL: nodejs/node#49265
Backport-PR-URL: nodejs/node#50669
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
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. backported-to-v18.x PRs backported to the v18.x-staging branch. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. doc Issues and PRs related to the documentations. esm Issues and PRs related to the ECMAScript Modules implementation. loaders Issues and PRs related to ES module loaders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESM Hooks: nextResolve & nextLoad can return promises which is not reflected in documentation
5 participants