build: update tools directory for latest changes in rules_nodejs (#40710)

Update the scripts/tooling in the tools directory to handle the changes in the latest
version of rules_nodejs.

PR Close #40710
This commit is contained in:
Joey Perrott 2021-02-04 14:09:42 -08:00 committed by Alex Rickabaugh
parent 34de89acbd
commit b8b8535f40
9 changed files with 31 additions and 21 deletions

View File

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

View File

@ -3,10 +3,10 @@
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar") load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm") load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", _pkg_npm = "pkg_npm")
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test") load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
load("@npm//@bazel/karma:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite") load("@npm//@bazel/concatjs:index.bzl", _concatjs_devserver = "concatjs_devserver", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
load("@npm//@bazel/rollup:index.bzl", _rollup_bundle = "rollup_bundle") load("@npm//@bazel/rollup:index.bzl", _rollup_bundle = "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified") load("@npm//@bazel/terser:index.bzl", "terser_minified")
load("@npm//@bazel/typescript:index.bzl", _ts_config = "ts_config", _ts_devserver = "ts_devserver", _ts_library = "ts_library") load("@npm//@bazel/typescript:index.bzl", _ts_config = "ts_config", _ts_library = "ts_library")
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite") load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
load("@npm//typescript:index.bzl", "tsc") load("@npm//typescript:index.bzl", "tsc")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package") load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
@ -88,7 +88,7 @@ def _default_module_name(testonly):
def ts_devserver(**kwargs): def ts_devserver(**kwargs):
"""Default values for ts_devserver""" """Default values for ts_devserver"""
serving_path = kwargs.pop("serving_path", "/app_bundle.js") serving_path = kwargs.pop("serving_path", "/app_bundle.js")
_ts_devserver( _concatjs_devserver(
serving_path = serving_path, serving_path = serving_path,
**kwargs **kwargs
) )
@ -362,7 +362,10 @@ def jasmine_node_test(bootstrap = [], **kwargs):
configuration_env_vars = kwargs.pop("configuration_env_vars", []) + [ configuration_env_vars = kwargs.pop("configuration_env_vars", []) + [
"angular_ivy_enabled", "angular_ivy_enabled",
] ]
templated_args = kwargs.pop("templated_args", [])
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
templated_args = ["--bazel_patch_module_resolver"] + kwargs.pop("templated_args", [])
for label in bootstrap: for label in bootstrap:
deps += [label] deps += [label]
templated_args += ["--node_options=--require=$$(rlocation $(rootpath %s))" % label] templated_args += ["--node_options=--require=$$(rlocation $(rootpath %s))" % label]

View File

@ -45,13 +45,6 @@ sed('-i', '(\'response\' in xhr)', '(\'response\' in (xhr as any))',
'node_modules/rxjs/src/observable/dom/AjaxObservable.ts'); 'node_modules/rxjs/src/observable/dom/AjaxObservable.ts');
*/ */
// make chrome 74 work on OSX with karma under bazel
// remove when we update to the next @bazel/karma release
log('\n# patch: @bazel/karma 0.29.0 to disable chrome sandbox for OSX');
sed('-i', 'process.platform !== \'linux\'',
'process.platform !== \'linux\' && process.platform !== \'darwin\'',
'node_modules/@bazel/karma/karma.conf.js');
// Workaround https://github.com/bazelbuild/rules_nodejs/issues/1033 // Workaround https://github.com/bazelbuild/rules_nodejs/issues/1033
// TypeScript doesn't understand typings without "declare module" unless // TypeScript doesn't understand typings without "declare module" unless
// they are actually resolved by the @types default mechanism // they are actually resolved by the @types default mechanism

View File

@ -43,7 +43,7 @@ export function main(
return true; return true;
} }
const expectedSizeData = <FileSizeData>JSON.parse(readFileSync(goldenSizeMapPath, 'utf8')); const expectedSizeData = JSON.parse(readFileSync(goldenSizeMapPath, 'utf8')) as FileSizeData;
const differences = const differences =
compareFileSizeData(sizeResult, expectedSizeData, {maxByteDiff, maxPercentageDiff}); compareFileSizeData(sizeResult, expectedSizeData, {maxByteDiff, maxPercentageDiff});

View File

@ -7,7 +7,7 @@
*/ */
import {readFileSync} from 'fs'; import {readFileSync} from 'fs';
import {SourceMapConsumer} from 'source-map'; import {RawSourceMap, SourceMapConsumer} from 'source-map';
import {DirectorySizeEntry, FileSizeData, omitCommonPathPrefix, sortFileSizeData} from './file_size_data'; import {DirectorySizeEntry, FileSizeData, omitCommonPathPrefix, sortFileSizeData} from './file_size_data';
@ -23,7 +23,8 @@ export class SizeTracker {
constructor(private filePath: string, private sourceMapPath: string) { constructor(private filePath: string, private sourceMapPath: string) {
this.fileContent = readFileSync(filePath, 'utf8'); this.fileContent = readFileSync(filePath, 'utf8');
this.consumer = new SourceMapConsumer(JSON.parse(readFileSync(sourceMapPath, 'utf8'))); this.consumer =
new SourceMapConsumer(JSON.parse(readFileSync(sourceMapPath, 'utf8')) as RawSourceMap);
this.sizeResult = this._computeSizeResult(); this.sizeResult = this._computeSizeResult();
} }

View File

@ -25,7 +25,9 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
data = all_data, data = all_data,
entry_point = entry_point, entry_point = entry_point,
tags = kwargs.pop("tags", []) + ["symbol_extractor"], tags = kwargs.pop("tags", []) + ["symbol_extractor"],
templated_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden], # TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
templated_args = ["--bazel_patch_module_resolver", "$(rootpath %s)" % src, "$(rootpath %s)" % golden],
configuration_env_vars = ["angular_ivy_enabled"], configuration_env_vars = ["angular_ivy_enabled"],
**kwargs **kwargs
) )
@ -36,6 +38,8 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
data = all_data, data = all_data,
entry_point = entry_point, entry_point = entry_point,
configuration_env_vars = ["angular_ivy_enabled"], configuration_env_vars = ["angular_ivy_enabled"],
templated_args = ["$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"], # TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
templated_args = ["--bazel_patch_module_resolver", "$(rootpath %s)" % src, "$(rootpath %s)" % golden, "--accept"],
**kwargs **kwargs
) )

View File

@ -74,14 +74,14 @@ export class SymbolExtractor {
static diff(actual: Symbol[], expected: string|((Symbol | string)[])): {[name: string]: number} { static diff(actual: Symbol[], expected: string|((Symbol | string)[])): {[name: string]: number} {
if (typeof expected == 'string') { if (typeof expected == 'string') {
expected = JSON.parse(expected); expected = JSON.parse(expected) as string[];
} }
const diff: {[name: string]: number} = {}; const diff: {[name: string]: number} = {};
// All symbols in the golden file start out with a count corresponding to the number of symbols // All symbols in the golden file start out with a count corresponding to the number of symbols
// with that name. Once they are matched with symbols in the actual output, the count should // with that name. Once they are matched with symbols in the actual output, the count should
// even out to 0. // even out to 0.
(expected as (Symbol | string)[]).forEach((nameOrSymbol) => { expected.forEach(nameOrSymbol => {
const symbolName = typeof nameOrSymbol == 'string' ? nameOrSymbol : nameOrSymbol.name; const symbolName = typeof nameOrSymbol == 'string' ? nameOrSymbol : nameOrSymbol.name;
diff[symbolName] = (diff[symbolName] || 0) + 1; diff[symbolName] = (diff[symbolName] || 0) + 1;
}); });

View File

@ -48,8 +48,8 @@ def ts_api_guardian_test(
# Needed so that node doesn't walk back to the source directory. # Needed so that node doesn't walk back to the source directory.
# From there, the relative imports would point to .ts files. # From there, the relative imports would point to .ts files.
"--node_options=--preserve-symlinks", "--node_options=--preserve-symlinks",
# Since version 3, monkey-patch the implementation of require() in NodeJS is opt-in # TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
# https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324 # See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
"--bazel_patch_module_resolver", "--bazel_patch_module_resolver",
] ]
@ -112,6 +112,9 @@ def ts_api_guardian_test_npm_package(
"--node_options=--preserve-symlinks", "--node_options=--preserve-symlinks",
# We automatically discover the enpoints for our NPM package. # We automatically discover the enpoints for our NPM package.
"--autoDiscoverEntrypoints", "--autoDiscoverEntrypoints",
# TODO(josephperrott): update dependency usages to no longer need bazel patch module resolver
# See: https://github.com/bazelbuild/rules_nodejs/wiki#--bazel_patch_module_resolver-now-defaults-to-false-2324
"--bazel_patch_module_resolver",
] ]
for i in strip_export_pattern: for i in strip_export_pattern:

View File

@ -86,7 +86,7 @@ export function discoverAllEntrypoints(dirPath: string) {
// Get all typings file locations from package.json files // Get all typings file locations from package.json files
for (const packageJson of packageJsons) { for (const packageJson of packageJsons) {
const packageJsonObj = JSON.parse(fs.readFileSync(packageJson, {encoding: 'utf8'})); const packageJsonObj = JSON.parse(fs.readFileSync(packageJson, {encoding: 'utf8'})) as any;
const typings = packageJsonObj.typings; const typings = packageJsonObj.typings;
if (typings) { if (typings) {
entryPoints.push(path.join(path.dirname(packageJson), typings)); entryPoints.push(path.join(path.dirname(packageJson), typings));