Skip to content

module: make CJS load from ESM loader

This PR adds support for source in the load hook when loading 'commonjs' modules. CJS modules loaded this way will receive a require function that's not the standard CJS one. It implements only a subset of the CJS API, and monkey-patching the CJS API will (mostly1) not affect it. Loading a module using that require function will not call into the CJS loader but the ESM one – and similarly, calling require.resolve will use the ESM resolve hook.

  1. There are still some dependency to the legacy loader. The long-term goal would be to get rid of those.

Merge request reports

Loading