-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
process: add process.getBuiltinModule(id) #52762
Closed
Closed
Commits on May 7, 2024
-
Configuration menu - View commit details
-
Copy full SHA for aa54e26 - Browse repository at this point
Copy the full SHA aa54e26View commit details -
process: add process.getBuiltinModule(id)
`process.getBuiltinModule(id)` provides a way to load built-in modules in a globally available function. ES Modules that need to support other environments can use it to conditionally load a Node.js built-in when it is run in Node.js, without having to deal with the resolution error that can be thrown by `import` in a non-Node.js environment or having to use dynamic `import()` which either turns the module into an asynchronous module, or turns a synchronous API into an asynchronous one. ```mjs if (globalThis.process.getBuiltinModule) { // Run in Node.js, use the Node.js fs module. const fs = globalThis.process.getBuiltinModule('fs'); // If `require()` is needed to load user-modules, use // createRequire() const module = globalThis.process.getBuiltinModule('module'); const require = module.createRequire(import.meta.url); const foo = require('foo'); } ``` If `id` specifies a built-in module available in the current Node.js process, `process.getBuiltinModule(id)` method returns the corresponding built-in module. If `id` does not correspond to any built-in module, `undefined` is returned. `process.getBuiltinModule(id)` accept built-in module IDs that are recognized by `module.isBuiltin(id)`. Some built-in modules must be loaded with the `node:` prefix. The built-in modules returned by `process.getBuiltinModule(id)` are always the original modules - that is, it's not affected by `require.cache`.
Configuration menu - View commit details
-
Copy full SHA for e83917e - Browse repository at this point
Copy the full SHA e83917eView commit details
Commits on May 10, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 06f8432 - Browse repository at this point
Copy the full SHA 06f8432View commit details
Commits on May 20, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 4051f58 - Browse repository at this point
Copy the full SHA 4051f58View commit details
Commits on May 21, 2024
-
fixup! process: add process.getBuiltinModule(id)
Co-authored-by: Michaël Zasso <targos@protonmail.com>
Configuration menu - View commit details
-
Copy full SHA for 87251ab - Browse repository at this point
Copy the full SHA 87251abView commit details
Commits on May 22, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 0f20ee2 - Browse repository at this point
Copy the full SHA 0f20ee2View commit details
Commits on May 24, 2024
-
Configuration menu - View commit details
-
Copy full SHA for c07e5e4 - Browse repository at this point
Copy the full SHA c07e5e4View commit details
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.