Skip to content

Commit fa12380

Browse files
devversionkirjs
authored andcommitted
build: update api-gen to work with compiler as ts_project (angular#61566)
Compiler now would have `.js` files. Those aren't picked up as ESM, unless we install the `package.json` with `type: module`. Sounds great on paper, but doesn't work in reality because the way the compiler packages are available to `api-gen/` is via the old `rules_nodejs` linker, so the `packages/package.json` wouldn't work; nor do the `package.json`s of the e.g. compiler-cli package work- because those already contain the `exports` of the built npm package. We fix this in a much more reasonable way, and the whole module resolution problem by leveraging the pnpm linking here. This works as expected. PR Close angular#61566
1 parent ef44f67 commit fa12380

10 files changed

Lines changed: 2477 additions & 2475 deletions

File tree

‎.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# Input hashes for repository rule npm_translate_lock(name = "npm2", pnpm_lock = "@//:pnpm-lock.yaml").
33
# This file should be checked into version control along with the pnpm-lock.yaml file.
44
.npmrc=-1406867100
5+
adev/shared-docs/pipeline/api-gen/package.json=939673974
56
package.json=1801177040
67
packages/compiler-cli/package.json=-1344632265
78
packages/compiler/package.json=1190056499
8-
pnpm-lock.yaml=1750394994
9-
pnpm-workspace.yaml=353334404
9+
pnpm-lock.yaml=522942070
10+
pnpm-workspace.yaml=-1822660674
1011
tools/bazel/rules_angular_store/package.json=-239561259
1112
yarn.lock=-1393712141

‎.bazelignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ modules/ssr-benchmarks/node_modules
4040

4141

4242
# For rules_js
43+
adev/shared-docs/pipeline/api-gen/node_modules
4344
packages/compiler/node_modules
4445
packages/compiler-cli/node_modules
4546
tools/bazel/rules_angular_store/node_modules

‎WORKSPACE‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ npm_translate_lock(
109109
data = [
110110
"//:package.json",
111111
"//:pnpm-workspace.yaml",
112+
"//adev/shared-docs/pipeline/api-gen:package.json",
112113
"//packages/compiler:package.json",
113114
"//packages/compiler-cli:package.json",
114115
"//tools/bazel/rules_angular_store:package.json",

‎adev/shared-docs/pipeline/api-gen/BUILD.bazel‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
load("@npm2//:defs.bzl", "npm_link_all_packages")
2+
13
package(default_visibility = ["//visibility:public"])
24

5+
npm_link_all_packages()
6+
37
# Expose the sources in the dev-infra NPM package.
48
filegroup(
59
name = "files",

‎adev/shared-docs/pipeline/api-gen/extraction/BUILD.bazel‎

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
1-
load("@angular//tools/esm-interop:index.bzl", "nodejs_binary")
2-
load("@npm//@angular/build-tooling/bazel/esbuild:index.bzl", "esbuild_esm_bundle")
1+
load("@aspect_rules_js//js:defs.bzl", "js_binary")
32
load("//adev/shared-docs:defaults.bzl", "ts_project")
43

54
package(default_visibility = ["//adev/shared-docs/pipeline/api-gen:__subpackages__"])
65

7-
esbuild_esm_bundle(
8-
name = "bin",
9-
entry_point = ":index.mts",
10-
external = [
11-
"@angular/compiler-cli",
12-
"typescript",
13-
],
14-
metafile = False,
15-
output = "bin.mjs",
16-
platform = "node",
17-
target = "es2022",
18-
deps = [
19-
":extract_api_to_json_lib",
20-
],
21-
)
22-
236
ts_project(
247
name = "extract_api_to_json_lib",
258
srcs = glob(
@@ -28,26 +11,23 @@ ts_project(
2811
"**/*.spec.mts",
2912
],
3013
),
31-
interop_deps = [
32-
"@angular//packages/compiler",
33-
"@angular//packages/compiler-cli",
34-
],
3514
deps = [
15+
# TODO(rules_js): Explore how this could work alternatively at runtime with the module names.
16+
"//adev/shared-docs/pipeline/api-gen:node_modules/@angular/compiler-cli",
17+
"//adev/shared-docs/pipeline/api-gen:node_modules/@angular/compiler",
3618
"//:node_modules/@bazel/runfiles",
3719
"//:node_modules/@types/node",
3820
"//:node_modules/typescript",
3921
],
4022
)
4123

4224
# Action binary for the api_gen bazel rule.
43-
nodejs_binary(
25+
js_binary(
4426
name = "extract_api_to_json",
4527
data = [
46-
"@angular//packages/compiler",
47-
"@angular//packages/compiler-cli:npm_package",
48-
"@npm//typescript",
28+
":extract_api_to_json_lib_rjs",
4929
],
50-
entry_point = "bin.mjs",
30+
entry_point = ":index.mjs",
5131
visibility = ["//visibility:public"],
5232
)
5333

‎adev/shared-docs/pipeline/api-gen/extraction/extract_api_to_json.bzl‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
load("@build_bazel_rules_nodejs//:providers.bzl", "run_node")
2-
31
def _extract_api_to_json(ctx):
42
"""Implementation of the extract_api_to_json rule"""
53

@@ -49,12 +47,15 @@ def _extract_api_to_json(ctx):
4947

5048
# Define an action that runs the nodejs_binary executable. This is
5149
# the main thing that this rule does.
52-
run_node(
53-
ctx = ctx,
50+
ctx.actions.run(
5451
inputs = depset(ctx.files.srcs + ctx.files.extra_entries),
55-
executable = "_extract_api_to_json",
52+
executable = ctx.executable._extract_api_to_json,
5653
outputs = [json_output],
5754
arguments = [args],
55+
env = {
56+
# Note: We don't need to `cd` into the bin-dir as this action deals with execpaths.
57+
"BAZEL_BINDIR": ".",
58+
},
5859
)
5960

6061
# The return value describes what the rule is producing. In this case we need to specify
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dependencies": {
3+
"@angular/compiler": "workspace:*",
4+
"@angular/compiler-cli": "workspace:*"
5+
}
6+
}

‎packages/compiler-cli/BUILD.bazel‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ pkg_npm(
129129
],
130130
visibility = [
131131
"//adev:__pkg__",
132-
"//adev/shared-docs/pipeline/api-gen:__subpackages__",
133132
"//integration:__subpackages__",
134133
"//modules/benchmarks:__subpackages__",
135134
"//modules/playground:__subpackages__",

0 commit comments

Comments
 (0)