GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — module: refactor to use `normalizeRequirableId` in the CJS module loader by RaisinTen · Pull Request #47896 · nodejs/node

Conversation

@RaisinTen

@RaisinTen RaisinTen commented May 6, 2023

Copy link
Copy Markdown
Member

BuiltinModule.normalizeRequirableId() was introduced in #47779 to fix a bug in the require function of SEAs and Snapshots, so that built-in modules with the node: scheme could be required correctly. This change makes more use of this API instead of BuiltinModule.canBeRequiredByUsers() and BuiltinModule.canBeRequiredWithoutScheme() to reduce chances of such bugs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@RaisinTen
module: refactor to use normalizeRequirableId in the CJS module loader
1b0d145
`BuiltinModule.normalizeRequirableId()` was introduced in
nodejs#47779 to fix a bug in the require
function of SEAs and Snapshots, so that built-in modules with the
`node:` scheme could be required correctly. This change makes more use
of this API instead of `BuiltinModule.canBeRequiredByUsers()` and
`BuiltinModule.canBeRequiredWithoutScheme()` to reduce chances of
such bugs.

Signed-off-by: Darshan Sen <[email protected]>
@nodejs-github-bot

nodejs-github-bot commented May 6, 2023

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/loaders
  • @nodejs/modules
  • @nodejs/startup
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run. labels May 6, 2023
GeoffreyBooth
GeoffreyBooth approved these changes May 6, 2023
View reviewed changes
@GeoffreyBooth

GeoffreyBooth commented May 6, 2023

Copy link
Copy Markdown
Member

And the ESM loader?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anonrig
anonrig approved these changes May 6, 2023
View reviewed changes
@debadree25 debadree25 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels May 6, 2023
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label May 6, 2023
@nodejs-github-bot

nodejs-github-bot commented May 6, 2023

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/51689/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

VoltrexKeyva
VoltrexKeyva approved these changes May 7, 2023
View reviewed changes
@RaisinTen

RaisinTen commented May 7, 2023

Copy link
Copy Markdown
Member Author

@GeoffreyBooth there are still some places both in the ESM loader as well as the CJS loader where canBeRequiredByUsers and canBeRequiredWithoutScheme are being used together, so these could potentially be replaced with normalizeRequirableId:

ESM -

node/lib/internal/modules/esm/hooks.js

Lines 638 to 644 in 6fb10ca

(builtinName) => {
if (BuiltinModule.canBeRequiredByUsers(builtinName) &&
BuiltinModule.canBeRequiredWithoutScheme(builtinName)) {
return require(builtinName);
}
throw new ERR_INVALID_ARG_VALUE('builtinName', builtinName);
},

CJS -

node/lib/internal/modules/cjs/loader.js

Lines 916 to 945 in 6fb10ca

if (StringPrototypeStartsWith(request, 'node:')) {
// Slice 'node:' prefix
const id = StringPrototypeSlice(request, 5);
if (!BuiltinModule.canBeRequiredByUsers(id)) {
throw new ERR_UNKNOWN_BUILTIN_MODULE(request);
}
const module = loadBuiltinModule(id, request);
return module.exports;
}
const filename = Module._resolveFilename(request, parent, isMain);
const cachedModule = Module._cache[filename];
if (cachedModule !== undefined) {
updateChildren(parent, cachedModule, true);
if (!cachedModule.loaded) {
const parseCachedModule = cjsParseCache.get(cachedModule);
if (!parseCachedModule || parseCachedModule.loaded)
return getExportsForCircularRequire(cachedModule);
parseCachedModule.loaded = true;
} else {
return cachedModule.exports;
}
}
if (BuiltinModule.canBeRequiredWithoutScheme(filename)) {
const mod = loadBuiltinModule(filename, request);
return mod.exports;
}

but I wasn't sure how that could be done, so I kept this PR isolated to only these changes. If you have any suggestions on how that could be done, I'd be happy to implement that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen RaisinTen added the commit-queue PRs queued for automated landing through the Commit Queue. label May 8, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label May 8, 2023
@nodejs-github-bot
nodejs-github-bot merged commit 7fe4745 into nodejs:main May 8, 2023
@nodejs-github-bot

nodejs-github-bot commented May 8, 2023

Copy link
Copy Markdown
Collaborator

Landed in 7fe4745

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@RaisinTen
RaisinTen deleted the use-BuiltinModule.normalizeRequirableId-where-possible branch May 8, 2023 08:17
targos pushed a commit that referenced this pull request May 12, 2023
@RaisinTen @targos
module: refactor to use normalizeRequirableId in the CJS module loader
c19385c
`BuiltinModule.normalizeRequirableId()` was introduced in
#47779 to fix a bug in the require
function of SEAs and Snapshots, so that built-in modules with the
`node:` scheme could be required correctly. This change makes more use
of this API instead of `BuiltinModule.canBeRequiredByUsers()` and
`BuiltinModule.canBeRequiredWithoutScheme()` to reduce chances of
such bugs.

Signed-off-by: Darshan Sen <[email protected]>
PR-URL: #47896
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
@targos targos mentioned this pull request May 15, 2023
v20.2.0 release proposal #48020
Merged
@danielleadams danielleadams added the backport-requested-v18.x label Jul 5, 2023
targos pushed a commit that referenced this pull request Nov 10, 2023
@RaisinTen @targos
module: refactor to use normalizeRequirableId in the CJS module loader
6f0458d
`BuiltinModule.normalizeRequirableId()` was introduced in
#47779 to fix a bug in the require
function of SEAs and Snapshots, so that built-in modules with the
`node:` scheme could be required correctly. This change makes more use
of this API instead of `BuiltinModule.canBeRequiredByUsers()` and
`BuiltinModule.canBeRequiredWithoutScheme()` to reduce chances of
such bugs.

Signed-off-by: Darshan Sen <[email protected]>
PR-URL: #47896
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
@targos targos mentioned this pull request Nov 28, 2023
v18.19.0 release proposal #50953
Merged
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
@sercher
module: refactor to use normalizeRequirableId in the CJS
7e5db3d
`BuiltinModule.normalizeRequirableId()` was introduced in
nodejs/node#47779 to fix a bug in the require
function of SEAs and Snapshots, so that built-in modules with the
`node:` scheme could be required correctly. This change makes more use
of this API instead of `BuiltinModule.canBeRequiredByUsers()` and
`BuiltinModule.canBeRequiredWithoutScheme()` to reduce chances of
such bugs.

Signed-off-by: Darshan Sen <[email protected]>
PR-URL: nodejs/node#47896
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
sercher added a commit to sercher/graaljs that referenced this pull request Apr 25, 2024
@sercher
module: refactor to use normalizeRequirableId in the CJS
197530e
`BuiltinModule.normalizeRequirableId()` was introduced in
nodejs/node#47779 to fix a bug in the require
function of SEAs and Snapshots, so that built-in modules with the
`node:` scheme could be required correctly. This change makes more use
of this API instead of `BuiltinModule.canBeRequiredByUsers()` and
`BuiltinModule.canBeRequiredWithoutScheme()` to reduce chances of
such bugs.

Signed-off-by: Darshan Sen <[email protected]>
PR-URL: nodejs/node#47896
Reviewed-By: Geoffrey Booth <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@GeoffreyBooth GeoffreyBooth GeoffreyBooth approved these changes
@anonrig anonrig anonrig approved these changes
+1 more reviewer
@VoltrexKeyva VoltrexKeyva VoltrexKeyva approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. needs-ci PRs that need a full CI run.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@RaisinTen @nodejs-github-bot @GeoffreyBooth @anonrig @VoltrexKeyva @danielleadams @debadree25
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.