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

process: add process.getBuiltinModule(id) #52762

Closed
wants to merge 7 commits into from

Commits on May 7, 2024

  1. Configuration menu
    Copy the full SHA
    aa54e26 View commit details
    Browse the repository at this point in the history
  2. 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`.
    joyeecheung committed May 7, 2024
    Configuration menu
    Copy the full SHA
    e83917e View commit details
    Browse the repository at this point in the history

Commits on May 10, 2024

  1. Configuration menu
    Copy the full SHA
    06f8432 View commit details
    Browse the repository at this point in the history

Commits on May 20, 2024

  1. Configuration menu
    Copy the full SHA
    4051f58 View commit details
    Browse the repository at this point in the history

Commits on May 21, 2024

  1. fixup! process: add process.getBuiltinModule(id)

    Co-authored-by: Michaël Zasso <[email protected]>
    joyeecheung and targos committed May 21, 2024
    Configuration menu
    Copy the full SHA
    87251ab View commit details
    Browse the repository at this point in the history

Commits on May 22, 2024

  1. Configuration menu
    Copy the full SHA
    0f20ee2 View commit details
    Browse the repository at this point in the history

Commits on May 24, 2024

  1. Configuration menu
    Copy the full SHA
    c07e5e4 View commit details
    Browse the repository at this point in the history