Skip to content

Commit b8b8535

Browse files
josephperrottalxhub
authored andcommitted
build: update tools directory for latest changes in rules_nodejs (angular#40710)
Update the scripts/tooling in the tools directory to handle the changes in the latest version of rules_nodejs. PR Close angular#40710
1 parent 34de89a commit b8b8535

File tree

9 files changed

+31
-21
lines changed

9 files changed

+31
-21
lines changed

packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def partial_compliance_golden(filePath):
2121
entry_point = "//packages/compiler-cli/test/compliance/partial:cli.ts",
2222
templated_args = [
2323
filePath,
24+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
25+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
26+
"--bazel_patch_module_resolver",
2427
],
2528
)
2629

@@ -31,6 +34,9 @@ def partial_compliance_golden(filePath):
3134
visibility = [":__pkg__"],
3235
entry_point = "//packages/compiler-cli/test/compliance/partial:cli.ts",
3336
templated_args = [
37+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
38+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
39+
"--bazel_patch_module_resolver",
3440
"--node_options=--inspect-brk",
3541
filePath,
3642
],

tools/defaults.bzl

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
44
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm")
55
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
6-
load("@npm//@bazel/karma:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
6+
load("@npm//@bazel/concatjs:index.bzl", _concatjs_devserver = "concatjs_devserver", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
77
load("@npm//@bazel/rollup:index.bzl", _rollup_bundle = "rollup_bundle")
88
load("@npm//@bazel/terser:index.bzl", "terser_minified")
9-
load("@npm//@bazel/typescript:index.bzl", _ts_config = "ts_config", _ts_devserver = "ts_devserver", _ts_library = "ts_library")
9+
load("@npm//@bazel/typescript:index.bzl", _ts_config = "ts_config", _ts_library = "ts_library")
1010
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
1111
load("@npm//typescript:index.bzl", "tsc")
1212
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
@@ -88,7 +88,7 @@ def _default_module_name(testonly):
8888
def ts_devserver(**kwargs):
8989
"""Default values for ts_devserver"""
9090
serving_path = kwargs.pop("serving_path", "/app_bundle.js")
91-
_ts_devserver(
91+
_concatjs_devserver(
9292
serving_path = serving_path,
9393
**kwargs
9494
)
@@ -362,7 +362,10 @@ def jasmine_node_test(bootstrap = [], **kwargs):
362362
configuration_env_vars = kwargs.pop("configuration_env_vars", []) + [
363363
"angular_ivy_enabled",
364364
]
365-
templated_args = kwargs.pop("templated_args", [])
365+
366+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
367+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
368+
templated_args = ["--bazel_patch_module_resolver"] + kwargs.pop("templated_args", [])
366369
for label in bootstrap:
367370
deps += [label]
368371
templated_args += ["--node_options=--require=$$(rlocation $(rootpath %s))" % label]

tools/postinstall-patches.js

-7
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ sed('-i', '(\'response\' in xhr)', '(\'response\' in (xhr as any))',
4545
'node_modules/rxjs/src/observable/dom/AjaxObservable.ts');
4646
*/
4747

48-
// make chrome 74 work on OSX with karma under bazel
49-
// remove when we update to the next @bazel/karma release
50-
log('\n# patch: @bazel/karma 0.29.0 to disable chrome sandbox for OSX');
51-
sed('-i', 'process.platform !== \'linux\'',
52-
'process.platform !== \'linux\' && process.platform !== \'darwin\'',
53-
'node_modules/@bazel/karma/karma.conf.js');
54-
5548
// Workaround https://github.com/bazelbuild/rules_nodejs/issues/1033
5649
// TypeScript doesn't understand typings without "declare module" unless
5750
// they are actually resolved by the @types default mechanism

tools/size-tracking/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function main(
4343
return true;
4444
}
4545

46-
const expectedSizeData = <FileSizeData>JSON.parse(readFileSync(goldenSizeMapPath, 'utf8'));
46+
const expectedSizeData = JSON.parse(readFileSync(goldenSizeMapPath, 'utf8')) as FileSizeData;
4747
const differences =
4848
compareFileSizeData(sizeResult, expectedSizeData, {maxByteDiff, maxPercentageDiff});
4949

tools/size-tracking/size_tracker.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {readFileSync} from 'fs';
10-
import {SourceMapConsumer} from 'source-map';
10+
import {RawSourceMap, SourceMapConsumer} from 'source-map';
1111

1212
import {DirectorySizeEntry, FileSizeData, omitCommonPathPrefix, sortFileSizeData} from './file_size_data';
1313

@@ -23,7 +23,8 @@ export class SizeTracker {
2323

2424
constructor(private filePath: string, private sourceMapPath: string) {
2525
this.fileContent = readFileSync(filePath, 'utf8');
26-
this.consumer = new SourceMapConsumer(JSON.parse(readFileSync(sourceMapPath, 'utf8')));
26+
this.consumer =
27+
new SourceMapConsumer(JSON.parse(readFileSync(sourceMapPath, 'utf8')) as RawSourceMap);
2728
this.sizeResult = this._computeSizeResult();
2829
}
2930

tools/symbol-extractor/index.bzl

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
2525
data = all_data,
2626
entry_point = entry_point,
2727
tags = kwargs.pop("tags", []) + ["symbol_extractor"],
28-
templated_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden],
28+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
29+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
30+
templated_args = ["--bazel_patch_module_resolver", "$(rootpath %s)" % src, "$(rootpath %s)" % golden],
2931
configuration_env_vars = ["angular_ivy_enabled"],
3032
**kwargs
3133
)
@@ -36,6 +38,8 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
3638
data = all_data,
3739
entry_point = entry_point,
3840
configuration_env_vars = ["angular_ivy_enabled"],
39-
templated_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
41+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
42+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
43+
templated_args = ["--bazel_patch_module_resolver", "$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
4044
**kwargs
4145
)

tools/symbol-extractor/symbol_extractor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ export class SymbolExtractor {
7474

7575
static diff(actual: Symbol[], expected: string|((Symbol | string)[])): {[name: string]: number} {
7676
if (typeof expected == 'string') {
77-
expected = JSON.parse(expected);
77+
expected = JSON.parse(expected) as string[];
7878
}
7979
const diff: {[name: string]: number} = {};
8080

8181
// All symbols in the golden file start out with a count corresponding to the number of symbols
8282
// with that name. Once they are matched with symbols in the actual output, the count should
8383
// even out to 0.
84-
(expected as (Symbol | string)[]).forEach((nameOrSymbol) => {
84+
expected.forEach(nameOrSymbol => {
8585
const symbolName = typeof nameOrSymbol == 'string' ? nameOrSymbol : nameOrSymbol.name;
8686
diff[symbolName] = (diff[symbolName] || 0) + 1;
8787
});

tools/ts-api-guardian/index.bzl

+5-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def ts_api_guardian_test(
4848
# Needed so that node doesn't walk back to the source directory.
4949
# From there, the relative imports would point to .ts files.
5050
"--node_options=--preserve-symlinks",
51-
# Since version 3, monkey-patch the implementation of require() in NodeJS is opt-in
52-
# https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
51+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
52+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
5353
"--bazel_patch_module_resolver",
5454
]
5555

@@ -112,6 +112,9 @@ def ts_api_guardian_test_npm_package(
112112
"--node_options=--preserve-symlinks",
113113
# We automatically discover the enpoints for our NPM package.
114114
"--autoDiscoverEntrypoints",
115+
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
116+
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
117+
"--bazel_patch_module_resolver",
115118
]
116119

117120
for i in strip_export_pattern:

tools/ts-api-guardian/lib/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function discoverAllEntrypoints(dirPath: string) {
8686

8787
// Get all typings file locations from package.json files
8888
for (const packageJson of packageJsons) {
89-
const packageJsonObj = JSON.parse(fs.readFileSync(packageJson, {encoding: 'utf8'}));
89+
const packageJsonObj = JSON.parse(fs.readFileSync(packageJson, {encoding: 'utf8'})) as any;
9090
const typings = packageJsonObj.typings;
9191
if (typings) {
9292
entryPoints.push(path.join(path.dirname(packageJson), typings));

0 commit comments

Comments
 (0)