Skip to content

Commit 62f4370

Browse files
authored
build: update bazel setup to latest dev-infra and rules_nodejs version (#23973)
Updates the Bazel setup to the latest dev-infra and rules_nodejs version. This includes: * The removal of the spec-bundling code as that has been moved over to the shared dev-infra code. * The remoal of the AMD esbuild and devmode JS source extraction as these rules have been moved to the shared dev-infra logic. * The removal of the Angular linker ESBuild plugin creation as this logic is now exposed as shared script in the shared dev-infra package.
1 parent e5b4dd9 commit 62f4370

22 files changed

+258
-565
lines changed

.github/workflows/dev-infra.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
runs-on: ubuntu-latest
1010
steps:
1111
- uses: actions/checkout@v2
12-
- uses: angular/dev-infra/github-actions/commit-message-based-labels@589f402fa601c4c8ab006bdfb337564b3ea32338
12+
- uses: angular/dev-infra/github-actions/commit-message-based-labels@f0f363cb4ce5b5faf14e3d3bb7eeb7c7aee72da7
1313
with:
1414
angular-robot-key: ${{ secrets.ANGULAR_ROBOT_PRIVATE_KEY }}

.github/workflows/lock-closed.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
lock_closed:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: angular/dev-infra/github-actions/lock-closed@3f4646c252bc54b2ae93b4e322ebde9030de30b2
12+
- uses: angular/dev-infra/github-actions/lock-closed@f0f363cb4ce5b5faf14e3d3bb7eeb7c7aee72da7
1313
with:
1414
lock-bot-key: ${{ secrets.LOCK_BOT_PRIVATE_KEY }}

WORKSPACE

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
99
http_archive(
1010
name = "build_bazel_rules_nodejs",
1111
patches = ["//tools:multiple-node-versions.patch"],
12-
sha256 = "3635797a96c7bfcd0d265dacd722a07335e64d6ded9834af8d3f1b7ba5a25bba",
13-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.3.0/rules_nodejs-4.3.0.tar.gz"],
12+
sha256 = "f7037c8e295fdc921f714962aee7c496110052511e2b14076bd8e2d46bc9819c",
13+
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/4.4.5/rules_nodejs-4.4.5.tar.gz"],
1414
)
1515

1616
# Add sass rules

package.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,24 @@
7272
"@angular/bazel": "13.0.1",
7373
"@angular/cli": "13.0.2",
7474
"@angular/compiler-cli": "13.0.1",
75-
"@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#2cfe4b98a157927b319a3a00b467ff6233dc3337",
75+
"@angular/dev-infra-private": "https://github.com/angular/dev-infra-private-builds.git#c55a3937d45945489714273bfbbe9b803ceff89e",
7676
"@angular/localize": "13.0.1",
7777
"@angular/platform-browser-dynamic": "13.0.1",
7878
"@angular/platform-server": "13.0.1",
7979
"@angular/router": "13.0.1",
8080
"@axe-core/webdriverjs": "^4.1.0",
8181
"@babel/core": "^7.16.0",
8282
"@bazel/bazelisk": "1.10.1",
83-
"@bazel/buildifier": "4.2.1",
84-
"@bazel/concatjs": "4.3.0",
85-
"@bazel/esbuild": "4.3.0",
83+
"@bazel/buildifier": "4.2.3",
84+
"@bazel/concatjs": "4.4.5",
85+
"@bazel/esbuild": "4.4.5",
8686
"@bazel/ibazel": "0.15.10",
87-
"@bazel/jasmine": "4.2.0",
88-
"@bazel/protractor": "4.3.0",
89-
"@bazel/rollup": "4.3.0",
90-
"@bazel/runfiles": "4.3.0",
91-
"@bazel/terser": "4.3.0",
92-
"@bazel/typescript": "4.3.0",
87+
"@bazel/jasmine": "4.4.5",
88+
"@bazel/protractor": "4.4.5",
89+
"@bazel/rollup": "4.4.5",
90+
"@bazel/runfiles": "4.4.5",
91+
"@bazel/terser": "4.4.5",
92+
"@bazel/typescript": "4.4.5",
9393
"@firebase/app-types": "^0.6.1",
9494
"@material/animation": "14.0.0-canary.1af7c1c4a.0",
9595
"@material/auto-init": "14.0.0-canary.1af7c1c4a.0",

scripts/create-legacy-tests-bundle.mjs

+2-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#!/usr/bin/env node
22

3-
import {ConsoleLogger, LogLevel, NodeJSFileSystem} from '@angular/compiler-cli';
4-
import {createEs2015LinkerPlugin} from '@angular/compiler-cli/linker/babel';
5-
import {transformAsync} from '@babel/core';
3+
import {createLinkerEsbuildPlugin} from '@angular/dev-infra-private/shared-scripts/angular-linker/esbuild-plugin.mjs';
64
import child_process from 'child_process';
75
import esbuild from 'esbuild';
86
import fs from 'fs';
@@ -37,7 +35,7 @@ async function main() {
3735
await compileProjectWithNgtsc();
3836

3937
const specEntryPointFile = await createEntryPointSpecFile();
40-
const esbuildLinkerPlugin = await createLinkerEsbuildPlugin();
38+
const esbuildLinkerPlugin = await createLinkerEsbuildPlugin(/fesm2020/, false);
4139
const esbuildResolvePlugin = await createResolveEsbuildPlugin();
4240

4341
const result = await esbuild.build({
@@ -175,33 +173,6 @@ async function createResolveEsbuildPlugin() {
175173
};
176174
}
177175

178-
/** Creates an ESBuild plugin that runs the Angular linker on framework packages. */
179-
async function createLinkerEsbuildPlugin() {
180-
const linkerBabelPlugin = createEs2015LinkerPlugin({
181-
fileSystem: new NodeJSFileSystem(),
182-
logger: new ConsoleLogger(LogLevel.warn),
183-
// We enable JIT mode as unit tests also will rely on the linked ESM files.
184-
linkerJitMode: true,
185-
});
186-
187-
return {
188-
name: 'ng-linker-esbuild',
189-
setup: build => {
190-
build.onLoad({filter: /fesm2020/}, async args => {
191-
const filePath = args.path;
192-
const content = await fs.promises.readFile(filePath, 'utf8');
193-
const {code} = await transformAsync(content, {
194-
filename: filePath,
195-
filenameRelative: filePath,
196-
plugins: [linkerBabelPlugin],
197-
sourceMaps: 'inline',
198-
});
199-
return {contents: code};
200-
});
201-
},
202-
};
203-
}
204-
205176
/**
206177
* Retrieves the `fs.Stats` results for the given path gracefully.
207178
* If the file does not exist, returns `null`.

src/cdk/testing/tests/webdriver-test.bzl

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
load("//tools:defaults.bzl", "jasmine_node_test")
1+
load("//tools:defaults.bzl", "jasmine_node_test", "spec_bundle")
22
load("@io_bazel_rules_webtesting//web:web.bzl", "web_test")
33
load("//tools/server-test:index.bzl", "server_test")
4-
load("//tools/spec-bundling:index.bzl", "spec_bundle")
54

65
def webdriver_test(name, deps, tags = [], **kwargs):
76
spec_bundle(

src/dev-app/BUILD.bazel

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
2-
load("//tools:defaults.bzl", "ng_module", "sass_binary")
2+
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "ng_module", "sass_binary")
33
load("//tools/dev-server:index.bzl", "dev_server")
4-
load("//tools/esbuild:index.bzl", "esbuild", "esbuild_config")
54
load("//src/components-examples:config.bzl", "ALL_EXAMPLES")
65
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
76

@@ -111,7 +110,7 @@ esbuild_config(
111110
config_file = "esbuild.config.mjs",
112111
)
113112

114-
esbuild(
113+
devmode_esbuild(
115114
name = "bundles",
116115
config = ":esbuild_config",
117116
entry_points = [":main.ts"] + ["%s:index.ts" % e for e in ALL_EXAMPLES],

src/e2e-app/BUILD.bazel

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load("//tools/dev-server:index.bzl", "dev_server")
2-
load("//tools:defaults.bzl", "ng_module", "sass_binary")
3-
load("//tools/esbuild:index.bzl", "esbuild", "esbuild_config")
2+
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "ng_module", "sass_binary")
43
load("//src/components-examples:config.bzl", "ALL_EXAMPLES")
54
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
65

@@ -103,7 +102,7 @@ esbuild_config(
103102
config_file = "esbuild.config.mjs",
104103
)
105104

106-
esbuild(
105+
devmode_esbuild(
107106
name = "bundles",
108107
testonly = True,
109108
config = ":esbuild_config",

src/universal-app/BUILD.bazel

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ load("//src/cdk:config.bzl", "CDK_TARGETS")
33
load("//src/cdk-experimental:config.bzl", "CDK_EXPERIMENTAL_TARGETS")
44
load("//src/material:config.bzl", "MATERIAL_TARGETS")
55
load("//src/material-experimental:config.bzl", "MATERIAL_EXPERIMENTAL_TARGETS")
6-
load("//tools:defaults.bzl", "ng_module", "sass_binary", "ts_library")
7-
load("//tools/esbuild:index.bzl", "esbuild")
6+
load("//tools:defaults.bzl", "devmode_esbuild", "ng_module", "sass_binary", "ts_library")
87
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
98

109
package(default_visibility = ["//visibility:public"])
@@ -56,7 +55,7 @@ sass_binary(
5655
],
5756
)
5857

59-
esbuild(
58+
devmode_esbuild(
6059
name = "server_bundle",
6160
entry_point = ":prerender.ts",
6261
platform = "node",

tools/angular/BUILD.bazel

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
1-
load("@build_bazel_rules_nodejs//:index.bzl", "js_library")
2-
load("//tools/esbuild:index.bzl", "esbuild_config")
1+
load("@npm//@angular/dev-infra-private/bazel/esbuild:index.bzl", "esbuild_config")
32
load(":index.bzl", "create_angular_bundle_targets")
43

54
package(default_visibility = ["//visibility:public"])
65

7-
js_library(
8-
name = "create_linker_esbuild_plugin",
9-
srcs = ["create_linker_esbuild_plugin.mjs"],
10-
deps = [
11-
"@npm//@angular/compiler-cli",
12-
"@npm//@babel/core",
13-
],
14-
)
15-
166
esbuild_config(
177
name = "esbuild_config",
188
config_file = "esbuild.config.mjs",
199
deps = [
20-
":create_linker_esbuild_plugin",
10+
"@npm//@angular/dev-infra-private/shared-scripts/angular-linker:js_lib",
2111
],
2212
)
2313

tools/angular/create_linker_esbuild_plugin.mjs

-85
This file was deleted.

tools/angular/esbuild.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {createLinkerEsbuildPlugin} from './create_linker_esbuild_plugin.mjs';
9+
import {createLinkerEsbuildPlugin} from '@angular/dev-infra-private/shared-scripts/angular-linker/esbuild-plugin.mjs';
1010

1111
export default {
1212
// Note: We support `.mjs` here as this is the extension used by Angular APF packages.

tools/angular/index.bzl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//:packages.bzl", "ANGULAR_PACKAGES")
2-
load("//tools/esbuild:index.bzl", "esbuild")
2+
load("@npm//@angular/dev-infra-private/bazel/esbuild:index.bzl", "esbuild")
33
load("@build_bazel_rules_nodejs//internal/linker:link_node_modules.bzl", "LinkerPackageMappingInfo")
44
load("@build_bazel_rules_nodejs//:providers.bzl", "ExternalNpmPackageInfo", "JSModuleInfo")
55

tools/defaults.bzl

+60-1
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,17 @@ load("@build_bazel_rules_nodejs//:index.bzl", _pkg_npm = "pkg_npm")
55
load("@io_bazel_rules_sass//:defs.bzl", _npm_sass_library = "npm_sass_library", _sass_binary = "sass_binary", _sass_library = "sass_library")
66
load("@npm//@angular/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
77
load("@npm//@angular/dev-infra-private/bazel/integration:index.bzl", _integration_test = "integration_test")
8+
load("@npm//@angular/dev-infra-private/bazel/esbuild:index.bzl", _esbuild = "esbuild", _esbuild_config = "esbuild_config")
9+
load("@npm//@angular/dev-infra-private/bazel/spec-bundling:index.bzl", _spec_bundle = "spec_bundle")
10+
load("@npm//@angular/dev-infra-private/bazel:extract_js_module_output.bzl", "extract_js_module_output")
811
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
912
load("@npm//@bazel/concatjs:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
1013
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
1114
load("@npm//@bazel/typescript:index.bzl", _ts_library = "ts_library")
1215
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")
1316
load("//:pkg-externals.bzl", "PKG_EXTERNALS")
1417
load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html")
15-
load("//tools/spec-bundling:index.bzl", "spec_bundle")
18+
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
1619

1720
_DEFAULT_TSCONFIG_BUILD = "//src:bazel-tsconfig-build.json"
1821
_DEFAULT_TSCONFIG_TEST = "//src:tsconfig-test"
@@ -25,6 +28,8 @@ npmPackageSubstitutions = select({
2528
# Re-exports to simplify build file load statements
2629
markdown_to_html = _markdown_to_html
2730
integration_test = _integration_test
31+
esbuild = _esbuild
32+
esbuild_config = _esbuild_config
2833

2934
def _compute_module_name(testonly):
3035
current_pkg = native.package_name()
@@ -400,3 +405,57 @@ def ng_web_test_suite(deps = [], static_css = [], exclude_init_script = False, *
400405
bootstrap = bootstrap,
401406
**kwargs
402407
)
408+
409+
def spec_bundle(name, deps, **kwargs):
410+
# TODO: Rename once devmode and prodmode have been combined.
411+
# For spec bundling we also only consume devmode output as it is ESM in this repository.
412+
# This helps speeding up development experience as ESBuild (used internally by the rule)
413+
# would request both devmode and prodmode output flavor (resulting in 2x TS compilations).
414+
extract_js_module_output(
415+
name = "%s_devmode_deps" % name,
416+
deps = deps,
417+
provider = "JSModuleInfo",
418+
forward_linker_mappings = True,
419+
include_external_npm_packages = True,
420+
include_default_files = False,
421+
include_declarations = False,
422+
testonly = True,
423+
)
424+
425+
_spec_bundle(
426+
name = name,
427+
# For specs, we always add the pre-processed linker FW packages so that these
428+
# are resolved instead of the unprocessed FW entry-points through the `node_modules`.
429+
deps = ["%s_devmode_deps" % name] + LINKER_PROCESSED_FW_PACKAGES,
430+
workspace_name = "angular_material",
431+
run_angular_linker = select({
432+
# Pass through whether partial compilation is enabled or not. This is helpful
433+
# for our integration tests which run all tests in partial compilation mode.
434+
"//tools:partial_compilation_enabled": True,
435+
"//conditions:default": False,
436+
}),
437+
**kwargs
438+
)
439+
440+
# TODO: Rename once devmode and prodmode have been combined.
441+
def devmode_esbuild(name, deps, testonly = False, **kwargs):
442+
"""Extension of the default `@bazel/esbuild` rule so that only devmode ESM output
443+
is requested. This is done to speed up local development because the ESBuild rule
444+
by default requests all possible output flavors/modes."""
445+
extract_js_module_output(
446+
name = "%s_devmode_deps" % name,
447+
deps = deps,
448+
testonly = testonly,
449+
forward_linker_mappings = True,
450+
include_external_npm_packages = True,
451+
include_default_files = False,
452+
include_declarations = False,
453+
provider = "JSModuleInfo",
454+
)
455+
456+
_esbuild(
457+
name = name,
458+
deps = ["%s_devmode_deps" % name],
459+
testonly = testonly,
460+
**kwargs
461+
)

tools/esbuild/BUILD.bazel

-1
This file was deleted.

0 commit comments

Comments
 (0)