loader: require.resolve should throw for unknown builtin modules#43336
loader: require.resolve should throw for unknown builtin modules#43336aduh95 merged 3 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
|
s/unkonw/unknown/ in commit message |
Can you explain in detail what this means? I'm not very familiar with the nodejs contribution requirements. |
|
It just means there is a typo in your commit message "unkonw" that should be "unknown". |
Oh, thank you very much. I just realized it was a vim shortcut, forgive me for not knowing anything about it. |
| () => require.resolve('node:unknown'), | ||
| { | ||
| code: 'MODULE_NOT_FOUND', | ||
| message: /^Cannot find module 'node:unknown'/, |
There was a problem hiding this comment.
Quote from the documentation:
If the module can not be found, a MODULE_NOT_FOUND error is thrown.
| } | ||
|
|
||
| const filename = Module._resolveFilename(request, parent, isMain); | ||
| if (StringPrototypeStartsWith(filename, 'node:')) { |
There was a problem hiding this comment.
Loading a builtin module prefixed with "node:" expects "ERR_UNKNOWN_BUILTIN_MODULE" to be thrown.
If the "resolve" function is called here, "MODULE_NOT_FOUND" will be thrown.
There was a problem hiding this comment.
ERR_UNKNOWN_BUILTIN_MODULE certainly makes more sense here than MODULE_NOT_FOUND, I agree (although I think both are fine).
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
|
LGTM |
This comment was marked as outdated.
This comment was marked as outdated.
Commit Queue failed- Loading data for nodejs/node/pull/43336 ✔ Done loading data for nodejs/node/pull/43336 ----------------------------------- PR info ------------------------------------ Title loader: require.resolve should throw for unknown builtin modules (#43336) Author 木杉 (@zhmushan) Branch zhmushan:require_resolve -> nodejs:master Labels module, author ready, needs-ci Commits 3 - loader: make require.resolve throw error for unknown builtin modules - Update lib/internal/modules/cjs/loader.js - Update test/parallel/test-require-resolve.js Committers 2 - 木杉 - GitHub PR-URL: https://github.com/nodejs/node/pull/43336 Fixes: https://github.com/nodejs/node/issues/43274 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Luigi Pinca ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/43336 Fixes: https://github.com/nodejs/node/issues/43274 Reviewed-By: Antoine du Hamel Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Luigi Pinca -------------------------------------------------------------------------------- ℹ This PR was created on Tue, 07 Jun 2022 04:12:07 GMT ✔ Approvals: 4 ✔ - Antoine du Hamel (@aduh95) (TSC): https://github.com/nodejs/node/pull/43336#pullrequestreview-999163419 ✔ - Benjamin Gruenbaum (@benjamingr): https://github.com/nodejs/node/pull/43336#pullrequestreview-1000924532 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/43336#pullrequestreview-1003513209 ✔ - Luigi Pinca (@lpinca): https://github.com/nodejs/node/pull/43336#pullrequestreview-1006496775 ✖ Last GitHub CI failed ℹ Last Full PR CI on 2022-06-13T16:59:06Z: https://ci.nodejs.org/job/node-test-pull-request/44498/ - Querying data for job/node-test-pull-request/44498/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ Aborted `git node land` session in /home/runner/work/node/node/.ncuhttps://github.com/nodejs/node/actions/runs/2497846390 |
|
Landed in 7fd4cf4 |
|
Yay! What’s the best way to quickly backport this as far as possible? |
Fixes: nodejs/node#43274 PR-URL: nodejs/node#43336 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Fixes: nodejs/node#43274 PR-URL: nodejs/node#43336 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Fixes: #43274