mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Replaces the existing ESM loader for dealing with external module imports. This loader was introduced by Aspect for AIO `.mjs` scripts. The loader will be used as foundation for a more extensive loader that also properly handles first-party packages. Additionally another loader is added, all packed as a single loader because our current NodeJS version only supports a single loader per node invocation. So we implement chaining ourselves. The new loader will attempt rewriting `.js` extensions to `.mjs`, also it will add `.mjs` if not already done. This is necessary in the transition phase because we don't/cannot use explicit `.mts` extensions and also we don't specify extensions in imports yet. Long-term we would likely use `.mts` and explicit import extensions, but it's not yet clear how we would sync this into g3 too. PR Close #48521
22 lines
611 B
Python
22 lines
611 B
Python
"""ESM node module loader helpers."""
|
|
|
|
def enable_esm_node_module_loader(
|
|
node_modules_workspace,
|
|
env):
|
|
"""Enables a NodeJS import loader that ensures modules can be resolved from the Bazel repository.
|
|
|
|
Args:
|
|
node_modules_workspace: Name of the workspace in which node modules are available.
|
|
env: Struct of environment variables passed to a binary/test.
|
|
|
|
Returns:
|
|
The updated `env` dictionary.
|
|
"""
|
|
|
|
env = dict(
|
|
env,
|
|
NODE_MODULES_WORKSPACE_NAME = node_modules_workspace,
|
|
ESM_NODE_MODULE_LOADER_ENABLED = "true",
|
|
)
|
|
|
|
return env
|