Commit graph

2337 commits

Author SHA1 Message Date
Paul Gschwendtner
f44b322113 build: override schematics to be built and tested using CommonJS (#48521)
The Angular CLI does not yet support schematics running as ESM. For
this reason we switch the schematics BUILD targets to explicitly
use ESM (as an exception in the repo).

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
57a0499529 build: bundle tests for karma web test suites (#48521)
Since Karma with Bazel does not support ESM natively, we bundle the
tests using ESBuild into a single AMD file. This not only solves the
ESM issue until we can run browser ESM tests natively (also pending
in the components repo - the esbuild generation follows ESM semantics
but since collapsed we don't rely on the real module system).

A benefit of bundling is also faster and more reliable Karma browser
tests since only a single file needs to be loaded- compared to hundreds
of individual files.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
d7fa04fd98 build: update dev-infra build tooling to leverage recent ESM changes (#48521)
Update dev-infra's build-tooling since multiple ESM changes have
landed there. e.g. not relying on `require.main === module` for API
bundling. This will allow us to also execute all dev-infra rules
in ESM because we plan on applying our ESM patching to `ts_library`
(which would also affect build-tooling then).

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
810351ab4c refactor: update symbol extractor test tool to work with ESM (#48521)
The symbol extractor test tool now runs with ESM too. This commit
makes it ESM compatible.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
c8e021ef4a build: support esbuild configurations using ESM dependencies (#48521)
We use `bazel/esbuild` in various places (e.g. for app bundling tests).
These tests rely on the Angular Compiler-CLI itself for e.g. linking
or the Terser configuration. Since everything in this repo is now
strict ESM, the ESBuild configs (which are already ESM-supported)
need to import from `//packages/compiler-cli`. We also need to be
able to leverage our existing ESM Bazel loader for this though as
otherwise resolution would fail.

Long-term we can remove this if everything in the compiler-cli
would use `.mjs` extensions and the import paths would also specify
an explicit extension. See: https://nodejs.org/api/esm.html#mandatory-file-extensions

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
64f5ed89e8 build: update esm nodejs loader to properly handle subpaths (#48521)
The ESM loader when used with patched Bazel module resolution
handled subpaths incorrectly. e.g.
`@bazel/concatjs/tsc_wrapped/internal/index.js` could be incorrectly
resolved to `@bazel/concatjs/index.js`.

This commit fixes the flawed logic. Also we prioritize the ESM attempts
before the original specifier. This is necessary because otherwise
the default Node resolution (using `require.resolve`) may incorrectly
prefer the `index.js` file over a `index.mjs` when a directory is
imported.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
211d178f0d refactor(platform-server): use proper ESM-compatible import to domino (#48521)
Now that everything runs from within ESM, we need to use the proper
default-import variant to be able to load `domino` from ESM.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
985dbdb511 build: remove unnecessary import to @bazel/jasmine (#48521)
Since we no properly initialize as part of the spec-entrypoint
the hacky logic starting Jasmine can be removed. The init
file now runs before tests run, but after Jasmine is initialized.

Calling `boot` while Jasmine is already initialized results in
tests executing in a different context and before other
initialization work completes.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
c9415e4d75 build: ensure bootstrap transitive runfiles are made available (#48521)
Since we generate a `.mjs` file as entry-point for jasmine tests,
a couple of issues prevented the transitive dependencies from
bootstrap targets to be brought in (causing resolution errors):

1. The `_files` (previously `_esm2015`) targets are no longer needed,
   and they also miss all the information on runfiles.
2. The aspect for computing linker mappings does not respect the
   `bootstrap` attribute from the `spec_entrypoint` so we manually
   add the extract ESM output targets (this rule works with the aspect
   and forwards linker mappings).

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
369091839f build: fix loader and support rxjs to be used in NodeJS ESM (#48521)
RxJS currently ships ESM output that cannot be executed directly
in NodeJS. This is because RxJS ships ESM as `.js` files but does
not have a `package.json` which instructs Node to execute these as ESM.

RxJS would either need to use the explicit `.mjs` extension, or add
a `type: module` `package.json` next to the `.js` sources.

We manually patch RxJS to do this, while we wait on the upstream fix
to land. See: #7130.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
83dbed0a52 build: patch ts_library to not emit a tsickle extern file (#48521)
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.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
4b2cbc0334 build: update jasmine_node_test macro to support ESM (#48521)
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.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
20551503fa build: replace _es2015 shorthand with more flexible _files suffix (#48521)
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.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
0d83e89217 build: support enabling esm interop loader even outside of defaults.bzl (#48521)
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".

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
63b2421f3b build: include default files when extracting ESM outputs (#48521)
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.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
07c3157e4f build: move nodejs binary patch into more obvious place (#48521)
For the ESM interop patches we expect to have two types
of patches:

* Patches for `node_modules`
* Patches for Bazel repositories.

We move the patches in respective folders to make it very clear
where a patch is used/applied to.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
eac5280bec build: support template make variables in nodejs_binary/test (#48521)
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.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
c6d48c5366 build: prioritize ESM output in nodejs_test similar to binary-variant (#48521)
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`

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
553d42c86f build: patch rules_nodejs to prioritize ESM files for nodejs_binary/test (#48521)
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.

PR Close #48521
2022-12-19 19:50:41 +00:00
Paul Gschwendtner
9cd89569f5 build: create NodeJS ESM loader for supporting Bazel setup (#48521)
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
2022-12-19 19:50:40 +00:00
Paul Gschwendtner
fe6dcd1f5c build: rename esm-loader.mjs to a more specific filename (#48521)
This is in prearation for having a proper diff when this loader
is adjusted to support more situations than just simple external
node modules. See next commit.

Also the file is formatted to make the diff less verbose later.
The file was never formatted correctly and we don't lint `.mjs` files.

PR Close #48521
2022-12-19 19:50:40 +00:00
Paul Gschwendtner
ba5fe263b5 build: switch ng_module and ts_library devmode to ES2020 ESM (#48521)
Currently the devmode output for `ng_module` and `ts_library` is
using ES5 CommonJS UMD. To bring it in sync with prodmode and
to start with our long-term migration to full ESM- the devmode
is updated to to ES2020 ES modules too.

This will require more tricks to make devmod work with the bazel
setup and also tests may need to be refactored given them relying
on ES5 CJS features, like for `spyOn` jasmine patching etc.

PR Close #48521
2022-12-19 19:50:40 +00:00
Paul Gschwendtner
50a3046e4b build: patch rules_nodejs to ensure nodejs_binary targets can be used as tools in RBE (#48316)
See full explanation in: https://github.com/bazelbuild/rules_nodejs/pull/3605

PR Close #48316
2022-12-02 08:57:43 -08:00
Paul Gschwendtner
35151ea0ca build: hide --loader warning when ESM import patch is installed (#48282)
Similar to the Rules NodeJS require patch, we have an ESM import patch
as of the AIO Bazel migration (to support ESM scripts better).

This script uses `--loader`, an experimental NodeJS flag. This is
similar to how `ts-node` uses it. We should disable the warnings
as it results in a lot of unreadable Bazel output and the warnings
are okay to be ignored. Note that we cannot fine-grain disable
the specific warning so all others would be disabled too.

Realistically we haven't seen any in the past and long-term we will
be not relying on patched resolution anyway (looking at `rules_js`).

PR Close #48282
2022-11-29 09:39:26 -08:00
Derek Cormier
808ca8937d build(bazel): update rnj and remove launcher patch
rules_nodejs released  a fix for the RUNFILES issue.
2022-11-22 13:51:16 -07:00
Derek Cormier
a442f8f8a4 build(bazel): fix a bug where the esm loader did not point to
node_modules in runfiles

Was passing locally previously due to escaping to the source tree.
2022-11-22 13:51:16 -07:00
Derek Cormier
e4b82cea26 build(bazel): clean up pathing in aio build tooling
Make use of process.env.RUNFILES.
2022-11-22 13:51:16 -07:00
Derek Cormier
c64b63a18b build(bazel): remove old patch rules_nodejs patch
Patch contents included in rules_nodejs 5.6.0.
2022-11-22 13:51:16 -07:00
Derek Cormier
40c5a11055 build(bazel): fix windows regression caused by absolute esm loader path
The --loader argument can't handle absolute windows paths.
2022-11-22 13:51:16 -07:00
Derek Cormier
c75ef48087 build(bazel): fix a bug where the esm loader could not determine the
runfiles dir on bazel run

Was relying RUNFILES_DIR but that seems to not be available when calling
bazel run.
2022-11-22 13:51:16 -07:00
Derek Cormier
3c24466cd3 build(bazel): fix linting errors
Exclude third_party vendored code from linting to preserve original form
2022-11-22 13:51:16 -07:00
Derek Cormier
b4c40c5d55 build(bazel): merge aio/tools/defaults.bzl and tools/defaults.bzl
Detect the correct workspace for the source maps dep.
2022-11-22 13:51:16 -07:00
Derek Cormier
4cc881e7eb build(bazel): clean up manual build contents for aio example deps
This avoids the need to depend on "node_modules" and "node_modules/.bin"
separately.
2022-11-22 13:51:16 -07:00
Derek Cormier
22a317de3d build(bazel): stamp targets to build, test, and serve aio against
first party deps

Architect is not compatible with disabling the rules_nodejs linker so
these targets must use npm_link to link first party deps
2022-11-22 13:51:16 -07:00
Derek Cormier
8015d467fd build(bazel): remove rules_nodejs patch
This patch was added to remove an unnecessary wrapper script around
nodejs binaries which prevented running esm scripts when the linker
was disabled.
2022-11-22 13:51:16 -07:00
Derek Cormier
07126ae40f build(bazel): fix race conditions in windows aio build
Disables the rules_nodejs linker and adds a custom esm module resolver
2022-11-22 13:51:16 -07:00
Paul Gschwendtner
7a3e200e7b build: temporarily patch @bazel/concatjs to unblock tsickle update (#47018)
Temporary patch until
https://github.com/bazelbuild/rules_nodejs/pull/3517 is available in
another `rules_nodejs` release.

We can remove this patch, but for now it doesn't hurt. On the external
side the tsickle code path is not hit at all anyway, but we need to
satisfy the TypeScript checker.

PR Close #47018
2022-08-03 17:36:18 -07:00
Paul Gschwendtner
b757b1387c build: update dev-infra packages and account for build-tooling split from ng-dev (#46976)
The dev-infra build tooling is now decoupled from `ng-dev`. This will
make it easier to update `ng-dev` without necessarily needing to upgrade
the whole build system, Bazel etc. This is useful when e.g. new release
tool features have been added and should also be ported to active LTS
branches.

PR Close #46976
2022-08-02 09:37:37 -07:00
Paul Gschwendtner
f6859e8da2 build: replace size-tracking test with rule from shared dev-infra (#46802)
The JS size-tracking logic has been moved into the dev-infra repository
and the rule has been updated to work better with Bazel labels. The
Starlark target is updated accordingly in this commit.

PR Close #46802
2022-07-12 19:06:30 +00:00
Paul Gschwendtner
c8b0127f31 build: remove unused inline-package-json-deps.js script (#46798)
This script was used back when dev-infra code was part of
the Angular framework repository. The script is now unused
and can be deleted.

PR Close #46798
2022-07-12 15:54:51 +00:00
Paul Gschwendtner
1596902825 build: move jasmine seed generation logic to karma config (#46798)
The jasmine seed generator is only used in a single karma configuration
file. Used by the legacy build and the Saucelabs/ZoneJS Karma jobs.

We should move the separate script code directly into the config to make
it clear that the seed generation is not used elsewhere, and to simplify
the Starlark code.

PR Close #46798
2022-07-12 15:54:51 +00:00
Paul Gschwendtner
5f942717e8 build: account for app_bundle rule location change (#46642)
The `app_bundle` rule from the shared dev-infra package is no longer in
the benchmarking folder, but instead is part of the general Bazel rules
exposed by `dev-infra`. This commit accounts for this location change.

PR Close #46642
2022-07-01 10:20:51 -07:00
Joey Perrott
d5c2169f62 build: remove the unused source-map-test (#46518)
As source-map-test is unused and obsolete at this point, removing it from the repository.

PR Close #46518
2022-06-27 15:42:43 -07:00
Paul Gschwendtner
0360cde473 build: remove unused script from legacy build scripts (#46506)
Removes an unused `file2modulename` script and removes the folder
in `tools` since it's now empty.

PR Close #46506
2022-06-27 09:06:15 -07:00
Paul Gschwendtner
fbb1d56a9c build: remove unused check-node-modules script (#46507)
We now validate/enforce Yarn through the `npmrc` strict engines
setting. This script can be removed as it is not used anywhere.

PR Close #46507
2022-06-27 09:05:38 -07:00
Paul Gschwendtner
05254f53ff build: replace extract_typings rule with shared rule from dev-infra (#46508)
This replaces the `extract_typings` rule with the shared rule from
dev-infra, avoiding us having to maintain two rules.

PR Close #46508
2022-06-27 09:05:09 -07:00
Derek Cormier
d2648d9d77 build(bazel): remove tsec patch to enable runfiles on Windows (#46447)
tsec previously did not use runfiles on Windows even when the flag was enabled.
The latest version now adds an option to force its usage.

PR Close #46447
2022-06-21 12:19:53 -07:00
Paul Gschwendtner
3b077c05c4 build: update dev-infra package to latest version with full ESM (#46437)
Updates `angular/dev-infra` to the latest version which is now full ESM.

PR Close #46437
2022-06-21 11:48:03 -07:00
Derek Cormier
2c8fd2b57b build(bazel): enable runfiles (#46313)
Patches are required for tsec and rules_webtesting. The fix for
rules_webtesting was merged to that repo
(581b1557e3)
but it's unclear when a release will be cut.

PR Close #46313
2022-06-14 16:58:19 +00:00
Paul Gschwendtner
95555658cf build: disable bazel nodejs linker to improve stability on windows (#45872)
The NodeJS Bazel linker does not work well on Windows because there
is no sandboxing and linker processes from different tests will attempt
to modify the same `node_modules`, causing concurrency race conditions
and resulting in flakiness.

PR Close #45872
2022-05-04 16:20:57 -07:00