Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nodejs/node
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 30b859f2207517477e7b19aa1cbc70c661eed8ec
Choose a base ref
...
head repository: nodejs/node
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7625dc4927fc3a5e721b4d997a757b978d61a233
Choose a head ref
  • 6 commits
  • 95 files changed
  • 3 contributors

Commits on Aug 8, 2024

  1. module: support require()ing synchronous ESM graphs

    This patch adds `require()` support for synchronous ESM graphs under
    the flag `--experimental-require-module`
    
    This is based on the the following design aspect of ESM:
    
    - The resolution can be synchronous (up to the host)
    - The evaluation of a synchronous graph (without top-level await) is
      also synchronous, and, by the time the module graph is instantiated
      (before evaluation starts), this is is already known.
    
    If `--experimental-require-module` is enabled, and the ECMAScript
    module being loaded by `require()` meets the following requirements:
    
    - Explicitly marked as an ES module with a `"type": "module"` field in
      the closest package.json or a `.mjs` extension.
    - Fully synchronous (contains no top-level `await`).
    
    `require()` will load the requested module as an ES Module, and return
    the module name space object. In this case it is similar to dynamic
    `import()` but is run synchronously and returns the name space object
    directly.
    
    ```mjs
    // point.mjs
    export function distance(a, b) {
      return (b.x - a.x) ** 2 + (b.y - a.y) ** 2;
    }
    class Point {
      constructor(x, y) { this.x = x; this.y = y; }
    }
    export default Point;
    ```
    
    ```cjs
    const required = require('./point.mjs');
    // [Module: null prototype] {
    //   default: [class Point],
    //   distance: [Function: distance]
    // }
    console.log(required);
    
    (async () => {
      const imported = await import('./point.mjs');
      console.log(imported === required);  // true
    })();
    ```
    
    If the module being `require()`'d contains top-level `await`, or the
    module graph it `import`s contains top-level `await`,
    [`ERR_REQUIRE_ASYNC_MODULE`][] will be thrown. In this case, users
    should load the asynchronous module using `import()`.
    
    If `--experimental-print-required-tla` is enabled, instead of throwing
    `ERR_REQUIRE_ASYNC_MODULE` before evaluation, Node.js will evaluate the
    module, try to locate the top-level awaits, and print their location to
    help users fix them.
    
    PR-URL: #51977
    Backport-PR-URL: #53500
    Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Guy Bedford <guybedford@gmail.com>
    Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
    Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
    joyeecheung authored and marco-ippolito committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    cad46af View commit details
    Browse the repository at this point in the history
  2. module: centralize SourceTextModule compilation for builtin loader

    This refactors the code that compiles SourceTextModule for the
    built-in ESM loader to use a common routine so that it's easier
    to customize cache handling for the ESM loader. In addition
    this introduces a common symbol for import.meta and import()
    so that we don't need to create additional closures as handlers,
    since we can get all the information we need from the V8 callback
    already. This should reduce the memory footprint of ESM as well.
    
    PR-URL: #52291
    Backport-PR-URL: #53500
    Refs: #47472
    Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
    Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
    joyeecheung authored and marco-ippolito committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    4dae68c View commit details
    Browse the repository at this point in the history
  3. module: disallow CJS <-> ESM edges in a cycle from require(esm)

    This patch disallows CJS <-> ESM edges when they come from
    require(esm) requested in ESM evalaution.
    
    Drive-by: don't reuse the cache for imported CJS modules to stash
    source code of required ESM because the former is also used for
    cycle detection.
    
    PR-URL: #52264
    Backport-PR-URL: #53500
    Fixes: #52145
    Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
    Reviewed-By: Guy Bedford <guybedford@gmail.com>
    Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
    joyeecheung authored and marco-ippolito committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    51b88fa View commit details
    Browse the repository at this point in the history
  4. lib: convert WeakMaps in cjs loader with private symbol properties

    Symbol properties are typically more GC-efficient than using WeakMaps,
    since WeakMap requires ephemeron GC. `module[kModuleExportNames]`
    would be easier to read than `importedCJSCache.get(module).exportNames`
    as well.
    
    PR-URL: #52095
    Backport-PR-URL: #53500
    Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
    Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
    Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
    legendecas authored and marco-ippolito committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    3a2d8bf View commit details
    Browse the repository at this point in the history
  5. module: tidy code and comments

    PR-URL: #52437
    Backport-PR-URL: #53500
    Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
    Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
    Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
    Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
    Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
    Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
    Reviewed-By: Feng Yu <F3n67u@outlook.com>
    JakobJingleheimer authored and marco-ippolito committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    6c4f477 View commit details
    Browse the repository at this point in the history
  6. module: fix submodules loaded by require() and import()

    Previously there is an edge case where submodules loaded by require()
    may not be loaded by import() again from different intermediate
    edges in the graph. This patch fixes that, added tests, and added
    debug logs.
    
    Drive-by: make loader a private field so it doesn't show up in logs.
    PR-URL: #52487
    Backport-PR-URL: #53500
    Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
    Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
    joyeecheung authored and marco-ippolito committed Aug 8, 2024
    Configuration menu
    Copy the full SHA
    7625dc4 View commit details
    Browse the repository at this point in the history
Loading