Skip to content

Commit b6268f7

Browse files
devversionclydin
authored andcommitted
build: migrate build_angular to ts_project
This commit updates `build_angular` to the `rules_js` ts_project rule. Notably a few real type issues surfaced but previously didn't surface due to some unknown resolution issues that resulted in `never` types; where every possible value was assignable; so this change improves type safety and a TODO was left for the "brittle code fragment".
1 parent cdf5d86 commit b6268f7

File tree

9 files changed

+108
-73
lines changed

9 files changed

+108
-73
lines changed

.aspect/rules/external_repository_action_cache/npm_translate_lock_MzA5NzUwNzMx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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=-2023857461
5-
package.json=-617490503
6-
pnpm-lock.yaml=633266779
5+
package.json=-851944395
6+
pnpm-lock.yaml=-958480774
77
pnpm-workspace.yaml=1711114604
8-
yarn.lock=-291473705
8+
yarn.lock=481913197

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
"@rollup/plugin-node-resolve": "^13.0.5",
8585
"@stylistic/eslint-plugin": "^2.8.0",
8686
"@types/babel__core": "7.20.5",
87+
"@types/babel__generator": "^7.6.8",
8788
"@types/browser-sync": "^2.27.0",
8889
"@types/express": "^4.16.0",
8990
"@types/http-proxy": "^1.17.4",

packages/angular_devkit/build_angular/BUILD.bazel

+75-62
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
load("@npm//@angular/build-tooling/bazel/api-golden:index.bzl", "api_golden_test_npm_package")
77
load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
8-
load("//tools:defaults.bzl", "pkg_npm", "ts_library")
8+
load("//tools:defaults.bzl", "pkg_npm")
99
load("//tools:interop.bzl", "ts_project")
1010
load("//tools:ts_json_schema.bzl", "ts_json_schema")
1111

@@ -93,6 +93,7 @@ ts_project(
9393
"src/testing/**/*.ts",
9494
],
9595
) + [
96+
"index.ts",
9697
"//packages/angular_devkit/build_angular:src/builders/app-shell/schema.ts",
9798
"//packages/angular_devkit/build_angular:src/builders/browser-esbuild/schema.ts",
9899
"//packages/angular_devkit/build_angular:src/builders/browser/schema.ts",
@@ -147,6 +148,7 @@ ts_project(
147148
"//:root_modules/@babel/runtime",
148149
"//:root_modules/@discoveryjs/json-ext",
149150
"//:root_modules/@types/babel__core",
151+
"//:root_modules/@types/babel__generator",
150152
"//:root_modules/@types/browser-sync",
151153
"//:root_modules/@types/karma",
152154
"//:root_modules/@types/less",
@@ -203,7 +205,7 @@ ts_project(
203205
],
204206
)
205207

206-
ts_library(
208+
ts_project(
207209
name = "build_angular_test_lib",
208210
testonly = True,
209211
srcs = glob(
@@ -215,15 +217,17 @@ ts_library(
215217
],
216218
),
217219
data = glob(["test/**/*"]),
218-
deps = [
219-
":build_angular",
220-
":build_angular_test_utils",
221-
"//packages/angular_devkit/architect/testing",
220+
interop_deps = [
222221
"//packages/angular_devkit/core",
223-
"@npm//fast-glob",
224-
"@npm//prettier",
225-
"@npm//typescript",
226-
"@npm//webpack",
222+
],
223+
deps = [
224+
":build_angular_rjs",
225+
":build_angular_test_utils_rjs",
226+
"//:root_modules/fast-glob",
227+
"//:root_modules/prettier",
228+
"//:root_modules/typescript",
229+
"//:root_modules/webpack",
230+
"//packages/angular_devkit/architect/testing:testing_rjs",
227231
],
228232
)
229233

@@ -268,7 +272,7 @@ api_golden_test_npm_package(
268272

269273
# Large build_angular specs
270274

271-
ts_library(
275+
ts_project(
272276
name = "build_angular_test_utils",
273277
testonly = True,
274278
srcs = glob(
@@ -281,17 +285,19 @@ ts_library(
281285
],
282286
),
283287
data = glob(["test/**/*"]),
284-
tsconfig = "//:tsconfig-test.json",
285-
deps = [
286-
":build_angular",
288+
interop_deps = [
287289
"//modules/testing/builder",
288290
"//packages/angular/build",
289291
"//packages/angular/build:private",
290-
"//packages/angular_devkit/architect",
291-
"//packages/angular_devkit/architect/node",
292-
"//packages/angular_devkit/architect/testing",
293292
"//packages/angular_devkit/core",
294293
"//packages/angular_devkit/core/node",
294+
],
295+
deps = [
296+
":build_angular_rjs",
297+
"//:root_modules/@types/jasmine",
298+
"//packages/angular_devkit/architect:architect_rjs",
299+
"//packages/angular_devkit/architect/node:node_rjs",
300+
"//packages/angular_devkit/architect/testing:testing_rjs",
295301
"@npm//rxjs",
296302
],
297303
)
@@ -302,12 +308,14 @@ LARGE_SPECS = {
302308
"shards": 10,
303309
"size": "large",
304310
"flaky": True,
305-
"extra_deps": [
311+
"extra_interop_deps": [
306312
"//packages/angular_devkit/build_webpack",
307-
"@npm//@types/http-proxy",
308-
"@npm//http-proxy",
309-
"@npm//puppeteer",
310-
"@npm//undici",
313+
],
314+
"extra_deps": [
315+
"//:root_modules/@types/http-proxy",
316+
"//:root_modules/http-proxy",
317+
"//:root_modules/puppeteer",
318+
"//:root_modules/undici",
311319
],
312320
},
313321
"extract-i18n": {},
@@ -316,21 +324,21 @@ LARGE_SPECS = {
316324
"size": "large",
317325
"flaky": True,
318326
"extra_deps": [
319-
"@npm//karma",
320-
"@npm//karma-chrome-launcher",
321-
"@npm//karma-coverage",
322-
"@npm//karma-jasmine",
323-
"@npm//karma-jasmine-html-reporter",
324-
"@npm//puppeteer",
325-
"@npm//webpack",
327+
"//:root_modules/karma",
328+
"//:root_modules/karma-chrome-launcher",
329+
"//:root_modules/karma-coverage",
330+
"//:root_modules/karma-jasmine",
331+
"//:root_modules/karma-jasmine-html-reporter",
332+
"//:root_modules/puppeteer",
333+
"//:root_modules/webpack",
326334
],
327335
},
328336
"protractor": {
329337
"extra_deps": [
330-
"@npm//jasmine-spec-reporter",
331-
"@npm//protractor",
332-
"@npm//puppeteer",
333-
"@npm//ts-node",
338+
"//:root_modules/jasmine-spec-reporter",
339+
"//:root_modules/protractor",
340+
"//:root_modules/puppeteer",
341+
"//:root_modules/ts-node",
334342
],
335343
# NB: does not run on rbe because webdriver manager uses an absolute path to chromedriver
336344
"tags": ["no-remote-exec"],
@@ -340,7 +348,7 @@ LARGE_SPECS = {
340348
"server": {
341349
"size": "large",
342350
"extra_deps": [
343-
"@npm//@angular/animations",
351+
"//:root_modules/@angular/animations",
344352
],
345353
},
346354
"ng-packagr": {},
@@ -349,55 +357,60 @@ LARGE_SPECS = {
349357
"size": "large",
350358
"flaky": True,
351359
"extra_deps": [
352-
"@npm//@angular/animations",
353-
"@npm//@angular/material",
360+
"//:root_modules/@angular/animations",
361+
"//:root_modules/@angular/material",
354362
],
355363
},
356364
"prerender": {},
357365
"browser-esbuild": {},
358366
"ssr-dev-server": {
359-
"extra_deps": [
360-
"@npm//@types/browser-sync",
361-
"@npm//browser-sync",
362-
"@npm//express",
363-
"@npm//undici",
367+
"extra_interop_deps": [
364368
"//packages/angular/ssr/node",
365369
],
370+
"extra_deps": [
371+
"//:root_modules/@types/browser-sync",
372+
"//:root_modules/browser-sync",
373+
"//:root_modules/express",
374+
"//:root_modules/undici",
375+
],
366376
},
367377
}
368378

369379
[
370-
ts_library(
380+
ts_project(
371381
name = "build_angular_" + spec + "_test_lib",
372382
testonly = True,
373383
srcs = glob(["src/builders/" + spec + "/**/*_spec.ts"]),
374-
tsconfig = "//:tsconfig-test.json",
375-
deps = [
384+
interop_deps = [
376385
# Dependencies needed to compile and run the specs themselves.
377-
":build_angular",
378-
":build_angular_test_utils",
386+
"//packages/angular_devkit/core",
387+
"//packages/angular_devkit/core/node",
379388
"//modules/testing/builder",
380389
"//packages/angular/build",
381390
"//packages/angular/build:private",
382-
"//packages/angular_devkit/architect",
383-
"//packages/angular_devkit/architect/node",
384-
"//packages/angular_devkit/architect/testing",
385-
"//packages/angular_devkit/core",
386-
"//packages/angular_devkit/core/node",
391+
] + LARGE_SPECS[spec].get("extra_interop_deps", []),
392+
deps = [
393+
# Dependencies needed to compile and run the specs themselves.
394+
":build_angular_rjs",
395+
":build_angular_test_utils_rjs",
396+
"//packages/angular_devkit/architect:architect_rjs",
397+
"//packages/angular_devkit/architect/node:node_rjs",
398+
"//packages/angular_devkit/architect/testing:testing_rjs",
387399

388400
# Base dependencies for the application in hello-world-app.
389401
# Some tests also require extra dependencies.
390-
"@npm//@angular/common",
391-
"@npm//@angular/compiler",
392-
"@npm//@angular/compiler-cli",
393-
"@npm//@angular/core",
394-
"@npm//@angular/platform-browser",
395-
"@npm//@angular/platform-browser-dynamic",
396-
"@npm//@angular/router",
397-
"@npm//rxjs",
398-
"@npm//tslib",
399-
"@npm//typescript",
400-
"@npm//zone.js",
402+
"//:root_modules/@angular/common",
403+
"//:root_modules/@angular/compiler",
404+
"//:root_modules/@angular/compiler-cli",
405+
"//:root_modules/@angular/core",
406+
"//:root_modules/@angular/platform-browser",
407+
"//:root_modules/@angular/platform-browser-dynamic",
408+
"//:root_modules/@angular/router",
409+
"//:root_modules/rxjs",
410+
"//:root_modules/tslib",
411+
"//:root_modules/typescript",
412+
"//:root_modules/zone.js",
413+
"//:root_modules/@types/jasmine",
401414
] + LARGE_SPECS[spec].get("extra_deps", []),
402415
)
403416
for spec in LARGE_SPECS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
export * from './src/index';

packages/angular_devkit/build_angular/src/tools/webpack/plugins/postcss-cli-resources.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ export default function (options?: PostcssCliResourcesOptions): Plugin {
115115
return;
116116
}
117117

118-
let outputPath = interpolateName({ resourcePath: result }, filename(result), {
119-
content,
120-
context: loader.context || loader.rootContext,
121-
}).replace(/\\|\//g, '-');
118+
let outputPath = interpolateName(
119+
// TODO: Revisit. Previously due to lack of type safety, this object
120+
// was fine, but in practice it doesn't match the type of the loader context.
121+
{ resourcePath: result } as Parameters<typeof interpolateName>[0],
122+
filename(result),
123+
{
124+
content,
125+
context: loader.context || loader.rootContext,
126+
},
127+
).replace(/\\|\//g, '-');
122128

123129
if (resourcesOutputPath) {
124130
outputPath = path.posix.join(resourcesOutputPath, outputPath);

packages/angular_devkit/build_angular/src/tools/webpack/plugins/scripts-webpack-plugin.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ export class ScriptsWebpackPlugin {
194194
const asset = compilation.getAsset(assetName);
195195
if (asset) {
196196
const interpolatedFilename = interpolateName(
197-
{ resourcePath: 'scripts.js' },
197+
// TODO: Revisit. Previously due to lack of type safety, this object
198+
// was fine, but in practice it doesn't match the type of the loader context.
199+
{ resourcePath: 'scripts.js' } as Parameters<typeof interpolateName>[0],
198200
assetName,
199201
{ content: asset.source.source() },
200202
);

pnpm-lock.yaml

+4-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"@angular-devkit/schematics/testing": ["./packages/angular_devkit/schematics/testing/index"],
2727
"@angular-devkit/architect/*": ["./packages/angular_devkit/architect/*/index"],
2828
"@angular-devkit/build-webpack": ["./packages/angular_devkit/build_webpack"],
29+
"@angular-devkit/build-angular": ["./packages/angular_devkit/build_angular"],
2930
"@angular-devkit/*": ["./packages/angular_devkit/*/src"],
3031
"@angular/ssr": ["./packages/angular/ssr"],
3132
"@angular/*": ["./packages/angular/*/src"],

yarn.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ __metadata:
351351
"@rollup/plugin-node-resolve": "npm:^13.0.5"
352352
"@stylistic/eslint-plugin": "npm:^2.8.0"
353353
"@types/babel__core": "npm:7.20.5"
354+
"@types/babel__generator": "npm:^7.6.8"
354355
"@types/browser-sync": "npm:^2.27.0"
355356
"@types/express": "npm:^4.16.0"
356357
"@types/http-proxy": "npm:^1.17.4"
@@ -4180,7 +4181,7 @@ __metadata:
41804181
languageName: node
41814182
linkType: hard
41824183

4183-
"@types/babel__generator@npm:*":
4184+
"@types/babel__generator@npm:*, @types/babel__generator@npm:^7.6.8":
41844185
version: 7.6.8
41854186
resolution: "@types/babel__generator@npm:7.6.8"
41864187
dependencies:

0 commit comments

Comments
 (0)