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

Basis for supporting ESM jasmine node tests #48418

Merged
merged 13 commits into from
Dec 10, 2022

Conversation

devversion
Copy link
Member

See individual commits

… use ESM

The `__ESM_IMPORT_META_URL__` trick was used because we used both ESM
and CommonJS in this repo. It was an interop needed because
`import.meta.url` syntax couldn't be used as it woud have caused syntax
errors.

We still need to keep the CommonJS/ESM interop in the compiler-cli
because g3 relies on the compiler and uses CommonJS. This affects very
few places, just in the compiler- so this is acceptable.
…y/test`

The Bazel NodeJS rules will always use the `.js` files as entry-points.
Since we only rely on the `.mjs` output going-forward, we need to teach
`nodejs_binary` and `nodejs_test` to use the `.mjs` extensions if
intended.

Our `defaults.bzl` macros will set `use_esm = True`, but other targets
from e.g. external repositories should keep the original behavior.
The `nodejs_binary` rule already prioritizes the `.mjs` output as
of the recent commits. The `nodejs_test` rule should do the same,
and also set `use_esm = True`
Removes `shelljs` which is a known ESM-problematic dependency.
We don't need it anyway.
@angular-robot angular-robot bot added the area: build & ci Related the build and CI infrastructure of the project label Dec 9, 2022
@ngbot ngbot bot added this to the Backlog milestone Dec 9, 2022
We modified the macros of `nodejs_binary/test` to have a rule
in between that requests the `.mjs` output. This works fine but
breaks make variable substitution for `templated_args` because
Bazel requires referenced labels to be part of the explicit `data`.

The rule in between breaks this, so we add a new argument that
can be used for such "template"/"args" data dependencies.

This can be removed when everything is ESM and we don't need
the rule in between.
@devversion devversion force-pushed the esm-first-migration branch 2 times, most recently from f15ae38 to f2bb7ac Compare December 9, 2022 16:50
@devversion devversion added PullApprove: disable target: feature This PR is targeted for a feature branch (outside of main and semver branches) labels Dec 9, 2022
@devversion devversion added the action: review The PR is still awaiting reviews from at least one requested reviewer label Dec 9, 2022
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

tools/esm-interop/index.bzl Outdated Show resolved Hide resolved
This is necessary for e.g. JSON files from the CLDR data repository.
Otherwise these could not be added to the runfiles of the
binaries/tests.
The underlyijng nodejs tests of the rule now also use the ESM
output, so normal `.js` artifacts are not even available there.
…bzl`

We introduced a loader that supports ESM with Bazel. This loader can
only be enabled as part of our `nodejs_binary` defaults.bzl test. This
works fine, but there might be other binaries/tests e.g. from
`@angular/build-tooling` that should be able to use ESM & might need to
for importing the `compiler-cli`.

We move the logic for installing the patch into a `rules_nodejs` patch.
There is an existing one that is just updated to "enable ESM support".
For every `ts_library` target we expose a shorthand that grants
access to the JS files because `DefaultInfo` of a ts library
only exposes the `.d.ts` files.

We rename this away from `es2015` since in practice it's a much
higher target these days. Additionally we no longer use the devmode
output but rather use the prodmode output which has the explicit
`.mjs` output- compatible with ESM.
Note: `--require` does not work for ESM. `--import` does not exist
in the current Node versions. Started being available in NodeJS v19.

A custom entry-point script, already supported by dev-infra, simplifies
the whole logic and solves the ESM case.
The prodmode compilation pipeline -that we intend to use more heavily
now given it emitting files with the `.mjs` extension- exposes an
additional tsickle closure externs file. This file is empty most
of the time anyway since tsickle is not wired up.

We remove this generation as otherwise convenient `$(location` of
such ts library targets break because there always is more than 1 file.
@devversion devversion marked this pull request as ready for review December 10, 2022 13:33
@devversion devversion added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Dec 10, 2022
@devversion devversion merged commit e4fb24b into angular:esm-stage-1 Dec 10, 2022
@devversion devversion deleted the esm-first-migration branch December 10, 2022 13:38
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: build & ci Related the build and CI infrastructure of the project PullApprove: disable target: feature This PR is targeted for a feature branch (outside of main and semver branches)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants