mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: update api-gen to work with compiler as ts_project (#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 #61566
This commit is contained in:
@@ -2,10 +2,11 @@
|
||||
# Input hashes for repository rule npm_translate_lock(name = "npm2", pnpm_lock = "@//:pnpm-lock.yaml").
|
||||
# This file should be checked into version control along with the pnpm-lock.yaml file.
|
||||
.npmrc=-1406867100
|
||||
adev/shared-docs/pipeline/api-gen/package.json=939673974
|
||||
package.json=1801177040
|
||||
packages/compiler-cli/package.json=-1344632265
|
||||
packages/compiler/package.json=1190056499
|
||||
pnpm-lock.yaml=1750394994
|
||||
pnpm-workspace.yaml=353334404
|
||||
pnpm-lock.yaml=522942070
|
||||
pnpm-workspace.yaml=-1822660674
|
||||
tools/bazel/rules_angular_store/package.json=-239561259
|
||||
yarn.lock=-1393712141
|
||||
|
||||
@@ -40,6 +40,7 @@ modules/ssr-benchmarks/node_modules
|
||||
|
||||
|
||||
# For rules_js
|
||||
adev/shared-docs/pipeline/api-gen/node_modules
|
||||
packages/compiler/node_modules
|
||||
packages/compiler-cli/node_modules
|
||||
tools/bazel/rules_angular_store/node_modules
|
||||
|
||||
@@ -109,6 +109,7 @@ npm_translate_lock(
|
||||
data = [
|
||||
"//:package.json",
|
||||
"//:pnpm-workspace.yaml",
|
||||
"//adev/shared-docs/pipeline/api-gen:package.json",
|
||||
"//packages/compiler:package.json",
|
||||
"//packages/compiler-cli:package.json",
|
||||
"//tools/bazel/rules_angular_store:package.json",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
load("@npm2//:defs.bzl", "npm_link_all_packages")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
npm_link_all_packages()
|
||||
|
||||
# Expose the sources in the dev-infra NPM package.
|
||||
filegroup(
|
||||
name = "files",
|
||||
|
||||
@@ -1,25 +1,8 @@
|
||||
load("@angular//tools/esm-interop:index.bzl", "nodejs_binary")
|
||||
load("@npm//@angular/build-tooling/bazel/esbuild:index.bzl", "esbuild_esm_bundle")
|
||||
load("@aspect_rules_js//js:defs.bzl", "js_binary")
|
||||
load("//adev/shared-docs:defaults.bzl", "ts_project")
|
||||
|
||||
package(default_visibility = ["//adev/shared-docs/pipeline/api-gen:__subpackages__"])
|
||||
|
||||
esbuild_esm_bundle(
|
||||
name = "bin",
|
||||
entry_point = ":index.mts",
|
||||
external = [
|
||||
"@angular/compiler-cli",
|
||||
"typescript",
|
||||
],
|
||||
metafile = False,
|
||||
output = "bin.mjs",
|
||||
platform = "node",
|
||||
target = "es2022",
|
||||
deps = [
|
||||
":extract_api_to_json_lib",
|
||||
],
|
||||
)
|
||||
|
||||
ts_project(
|
||||
name = "extract_api_to_json_lib",
|
||||
srcs = glob(
|
||||
@@ -28,11 +11,10 @@ ts_project(
|
||||
"**/*.spec.mts",
|
||||
],
|
||||
),
|
||||
interop_deps = [
|
||||
"@angular//packages/compiler",
|
||||
"@angular//packages/compiler-cli",
|
||||
],
|
||||
deps = [
|
||||
# TODO(rules_js): Explore how this could work alternatively at runtime with the module names.
|
||||
"//adev/shared-docs/pipeline/api-gen:node_modules/@angular/compiler-cli",
|
||||
"//adev/shared-docs/pipeline/api-gen:node_modules/@angular/compiler",
|
||||
"//:node_modules/@bazel/runfiles",
|
||||
"//:node_modules/@types/node",
|
||||
"//:node_modules/typescript",
|
||||
@@ -40,14 +22,12 @@ ts_project(
|
||||
)
|
||||
|
||||
# Action binary for the api_gen bazel rule.
|
||||
nodejs_binary(
|
||||
js_binary(
|
||||
name = "extract_api_to_json",
|
||||
data = [
|
||||
"@angular//packages/compiler",
|
||||
"@angular//packages/compiler-cli:npm_package",
|
||||
"@npm//typescript",
|
||||
":extract_api_to_json_lib_rjs",
|
||||
],
|
||||
entry_point = "bin.mjs",
|
||||
entry_point = ":index.mjs",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
load("@build_bazel_rules_nodejs//:providers.bzl", "run_node")
|
||||
|
||||
def _extract_api_to_json(ctx):
|
||||
"""Implementation of the extract_api_to_json rule"""
|
||||
|
||||
@@ -49,12 +47,15 @@ def _extract_api_to_json(ctx):
|
||||
|
||||
# Define an action that runs the nodejs_binary executable. This is
|
||||
# the main thing that this rule does.
|
||||
run_node(
|
||||
ctx = ctx,
|
||||
ctx.actions.run(
|
||||
inputs = depset(ctx.files.srcs + ctx.files.extra_entries),
|
||||
executable = "_extract_api_to_json",
|
||||
executable = ctx.executable._extract_api_to_json,
|
||||
outputs = [json_output],
|
||||
arguments = [args],
|
||||
env = {
|
||||
# Note: We don't need to `cd` into the bin-dir as this action deals with execpaths.
|
||||
"BAZEL_BINDIR": ".",
|
||||
},
|
||||
)
|
||||
|
||||
# The return value describes what the rule is producing. In this case we need to specify
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"@angular/compiler": "workspace:*",
|
||||
"@angular/compiler-cli": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -129,7 +129,6 @@ pkg_npm(
|
||||
],
|
||||
visibility = [
|
||||
"//adev:__pkg__",
|
||||
"//adev/shared-docs/pipeline/api-gen:__subpackages__",
|
||||
"//integration:__subpackages__",
|
||||
"//modules/benchmarks:__subpackages__",
|
||||
"//modules/playground:__subpackages__",
|
||||
|
||||
Generated
+2448
-2440
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,6 @@
|
||||
packages:
|
||||
- .
|
||||
- adev/shared-docs/pipeline/api-gen
|
||||
- packages/compiler/
|
||||
- packages/compiler-cli/
|
||||
- tools/bazel/rules_angular_store/
|
||||
|
||||
Reference in New Issue
Block a user