Skip to content

Commit b111d4f

Browse files
authored
build: fix size-test integration tooling (#22619)
Even though the size integration tests do not run in a blocking way on CI, we should ensure they can be run and do not fail. The tests are still useful for local debugging and comparisons. This commit fixes that NodeJS throws about `webpack` not being found. The build optimizer imports from webpack if we go through the public entry-point. Also simplifies the logic for finding the `angular_ivy_enabled.js` file.
1 parent 58a7421 commit b111d4f

File tree

4 files changed

+8
-16
lines changed

4 files changed

+8
-16
lines changed

integration/size-test/BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ts_library(
1212
name = "check-size",
1313
srcs = ["check-size.ts"],
1414
deps = [
15+
"@npm//@bazel/runfiles",
1516
"@npm//@types/node",
1617
"@npm//@types/yaml",
1718
"@npm//chalk",

integration/size-test/check-size.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import * as chalk from 'chalk';
88
import {readFileSync, statSync, writeFileSync} from 'fs';
99
import {parse, stringify} from 'yaml';
10+
import {runfiles} from '@bazel/runfiles';
1011

1112
/**
1213
* Absolute byte deviation from the expected value that is allowed. If the
@@ -30,8 +31,8 @@ type Golden = {[testId: string]: number};
3031
* with the actual measured size.
3132
*/
3233
const [testId, testFileRootpath, isApprove] = process.argv.slice(2);
33-
const testFilePath = require.resolve(`angular_material/${testFileRootpath}`);
34-
const goldenFilePath = require.resolve('../../goldens/size-test.yaml');
34+
const testFilePath = runfiles.resolveWorkspaceRelative(testFileRootpath);
35+
const goldenFilePath = runfiles.resolveWorkspaceRelative('goldens/size-test.yaml');
3536

3637
const golden: Golden = parse(readFileSync(goldenFilePath, 'utf8')) || {};
3738
const fileStat = statSync(testFilePath);

integration/size-test/index.bzl

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ def size_test(name, file, deps):
5252
"@npm//rollup-plugin-node-resolve",
5353
"@npm//@angular-devkit/build-optimizer",
5454
],
55+
# Link the workspace root so that files can be loaded from the workspace.
56+
link_workspace_root = True,
5557
sourcemap = "false",
5658
)
5759

integration/size-test/rollup.config.js

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
const {buildOptimizer} = require('@angular-devkit/build-optimizer');
1+
const {buildOptimizer} = require('@angular-devkit/build-optimizer/src/build-optimizer/build-optimizer');
22
const node = require('rollup-plugin-node-resolve');
3-
const path = require('path');
4-
const {ivyEnabled} = require(getIvyEnabledHelperPath());
3+
const {ivyEnabled} = require('angular_material/tools/angular_ivy_enabled');
54

65
console.info(`Processing rollup bundle in ${ivyEnabled ? 'Ivy' : 'View Engine'} mode.`);
76

@@ -37,14 +36,3 @@ module.exports = {
3736
}),
3837
],
3938
};
40-
41-
function getIvyEnabledHelperPath() {
42-
const parts = path.normalize(__dirname).split(path.sep);
43-
const binIndex = parts.indexOf('bin');
44-
45-
if (binIndex === -1) {
46-
throw Error('Cannot resolve Ivy helper path.');
47-
}
48-
49-
return path.join(parts.slice(0, binIndex).join(path.sep), 'bin/tools/angular_ivy_enabled');
50-
}

0 commit comments

Comments
 (0)