mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
build: fix symbol extractor script (#61407)
* Fixes that the symbol extractor approval script was broken after some recent build changes. * Fixes the `run_all_symbol_extractor_tests` script which wasn't resolving any targets, because the rule name changed. PR Close #61407
This commit is contained in:
committed by
Jessica Janiuk
parent
ca700e1def
commit
92cbd7a412
@@ -7,9 +7,9 @@ ts_project(
|
||||
name = "lib",
|
||||
testonly = True,
|
||||
srcs = glob(
|
||||
["**/*.ts"],
|
||||
["**/*.mts"],
|
||||
exclude = [
|
||||
"**/*_spec.ts",
|
||||
"**/*_spec.mts",
|
||||
"**/*_spec",
|
||||
],
|
||||
),
|
||||
@@ -25,7 +25,7 @@ ts_project(
|
||||
name = "test_lib",
|
||||
testonly = 1,
|
||||
srcs = glob(
|
||||
["**/*_spec.ts"],
|
||||
["**/*_spec.mts"],
|
||||
exclude = ["symbol_extractor_spec/**"],
|
||||
),
|
||||
tsconfig = "//tools:tsconfig_test",
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
|
||||
import {runfiles} from '@bazel/runfiles';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import {SymbolExtractor} from './symbol_extractor';
|
||||
import {SymbolExtractor} from './symbol_extractor.mjs';
|
||||
|
||||
const args = process.argv.slice(2) as [string, string];
|
||||
process.exitCode = main(args) ? 0 : 1;
|
||||
@@ -24,19 +25,19 @@ process.exitCode = main(args) ? 0 : 1;
|
||||
function main(argv: [string, string, string] | [string, string]): boolean {
|
||||
const javascriptFilePath = runfiles.resolveWorkspaceRelative(argv[0]);
|
||||
const goldenFilePath = runfiles.resolveWorkspaceRelative(argv[1]);
|
||||
const doUpdate = argv[2] == '--accept';
|
||||
const doUpdate = argv[2] === '--accept';
|
||||
|
||||
console.info('Input javascript file:', javascriptFilePath);
|
||||
|
||||
const javascriptContent = fs.readFileSync(javascriptFilePath).toString();
|
||||
const goldenContent = fs.readFileSync(goldenFilePath).toString();
|
||||
|
||||
const symbolExtractor = new SymbolExtractor(javascriptFilePath, javascriptContent);
|
||||
|
||||
let passed: boolean = false;
|
||||
let passed = false;
|
||||
if (doUpdate) {
|
||||
fs.writeFileSync(goldenFilePath, JSON.stringify(symbolExtractor.actual, undefined, 2));
|
||||
console.error('Updated gold file:', goldenFilePath);
|
||||
const goldenOutFilePath = path.join(process.env['BUILD_WORKING_DIRECTORY']!, argv[1]);
|
||||
fs.writeFileSync(goldenOutFilePath, JSON.stringify(symbolExtractor.actual, undefined, 2));
|
||||
console.error('Updated gold file:', goldenOutFilePath);
|
||||
passed = true;
|
||||
} else {
|
||||
passed = symbolExtractor.compareAndPrintError(goldenContent);
|
||||
@@ -17,7 +17,7 @@ def js_expected_symbol_test(name, src, golden, data = [], **kwargs):
|
||||
src,
|
||||
golden,
|
||||
]
|
||||
entry_point = "//tools/symbol-extractor:cli.js"
|
||||
entry_point = "//tools/symbol-extractor:cli.mjs"
|
||||
|
||||
js_test(
|
||||
name = name,
|
||||
|
||||
@@ -23,21 +23,25 @@ const USER_COMMAND = argv._[0];
|
||||
// The shell command to query for all tests.
|
||||
// Bazel targets for testing goldens
|
||||
process.stdout.write('Gathering all symbol extractor targets...');
|
||||
|
||||
const BAZEL_QUERY =
|
||||
`'kind(js_test, ${TEST_TARGETS_LOCATION}) ` +
|
||||
`intersect attr("tags", "symbol_extractor", ${TEST_TARGETS_LOCATION})'`;
|
||||
const ALL_TEST_TARGETS = spawnSync(
|
||||
'yarn',
|
||||
[
|
||||
'-s',
|
||||
'bazel',
|
||||
'query',
|
||||
'--output',
|
||||
'label',
|
||||
`'kind(nodejs_test, ${TEST_TARGETS_LOCATION}) intersect attr("tags", "symbol_extractor", ${TEST_TARGETS_LOCATION})'`,
|
||||
],
|
||||
['-s', 'bazel', 'query', '--output', 'label', BAZEL_QUERY],
|
||||
{encoding: 'utf8', shell: true, cwd: path.resolve(__dirname, '../..')},
|
||||
)
|
||||
.stdout.trim()
|
||||
.split('\n')
|
||||
.map((line) => line.trim());
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line.length > 0);
|
||||
|
||||
if (ALL_TEST_TARGETS.length === 0) {
|
||||
console.error(`Could not find any symbol test targets matching query: ${BAZEL_QUERY}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
process.stdout.clearLine();
|
||||
process.stdout.cursorTo(0);
|
||||
// Bazel targets for generating goldens
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import {runfiles} from '@bazel/runfiles';
|
||||
import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
|
||||
import {SymbolExtractor} from './symbol_extractor';
|
||||
import {SymbolExtractor} from './symbol_extractor.mjs';
|
||||
|
||||
describe('scenarios', () => {
|
||||
const symbolExtractorSpecDir = path.dirname(
|
||||
Reference in New Issue
Block a user