Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions goldens/public-api/manage.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
const {exec} = require('shelljs');
const {spawnSync} = require('node:child_process');
const {Parser: parser} = require('yargs/helpers');

// Remove all command line flags from the arguments.
const argv = parser(process.argv.slice(2));
// The command the user would like to run, either 'accept' or 'test'
const USER_COMMAND = argv._[0];

// Location of all packages that we'd need to process.
const API_TARGETS_LOCATION = 'packages/...';

// The shell command to query for all Public API guard tests.
const BAZEL_PUBLIC_API_TARGET_QUERY_CMD =
`pnpm --silent bazel query --output label 'kind(js_test, ${API_TARGETS_LOCATION}) ` +
`intersect attr("tags", "api_guard", ${API_TARGETS_LOCATION})'`;
const BAZEL_PUBLIC_API_TARGET_QUERY_CMD = [
'bazel',
'query',
'--output=label',
'kind(js_test, //packages/...) intersect attr("tags", "api_guard", //packages/...)',
];
// Bazel targets for testing Public API goldens
process.stdout.write('Gathering all Public API targets...');
const ALL_PUBLIC_API_TESTS = exec(BAZEL_PUBLIC_API_TARGET_QUERY_CMD, {silent: true})
.trim()
const ALL_PUBLIC_API_TESTS = spawnSync('pnpm', ['--silent', ...BAZEL_PUBLIC_API_TARGET_QUERY_CMD], {
encoding: 'utf-8',
})
.stdout.trim()
.split('\n')
.map((test) => test.trim());
process.stdout.clearLine();
Expand All @@ -28,9 +29,15 @@ const ALL_PUBLIC_API_ACCEPTS = ALL_PUBLIC_API_TESTS.map((test) => `${test}.accep
/** Builds all targets in parallel. */
function buildTargets(targets) {
process.stdout.write('Building all public API targets...');
const commandResult = exec(`pnpm --silent bazel build ${targets.join(' ')}`, {silent: true});
if (commandResult.code) {
const commandResult = spawnSync('pnpm', ['--silent', 'bazel', 'build', ...targets], {
encoding: 'utf-8',
});
if (commandResult.status) {
process.stdout.clearLine();
process.stdout.cursorTo(0);
console.error('Building golden targets failed:');
console.error(commandResult.stdout || commandResult.stderr);
process.exit(1);
} else {
process.stdout.clearLine();
process.stdout.cursorTo(0);
Expand All @@ -43,10 +50,10 @@ function buildTargets(targets) {
function runBazelCommandOnTargets(command, targets, present) {
for (const target of targets) {
process.stdout.write(`${present}: ${target}`);
const commandResult = exec(`pnpm --silent bazel ${command} ${target}`, {silent: true});
const commandResult = spawnSync('pnpm', ['--silent', 'bazel', command, target]);
process.stdout.clearLine();
process.stdout.cursorTo(0);
if (commandResult.code) {
if (commandResult.status) {
console.error(`Failed ${command}: ${target}`);
console.group();
console.error(commandResult.stdout || commandResult.stderr);
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"@types/selenium-webdriver": "3.0.7",
"@types/selenium-webdriver4": "npm:@types/[email protected]",
"@types/semver": "^7.3.4",
"@types/shelljs": "^0.8.6",
"@types/systemjs": "6.15.3",
"@types/yargs": "^17.0.3",
"angular-1.5": "npm:[email protected]",
Expand Down Expand Up @@ -144,7 +143,6 @@
"selenium-webdriver": "3.5.0",
"selenium-webdriver4": "npm:[email protected]",
"semver-dsl": "^1.0.1",
"shelljs": "^0.10.0",
"source-map": "0.7.6",
"source-map-support": "0.5.21",
"systemjs": "0.18.10",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import {exec} from 'shelljs';
import { spawnSync } from "child_process";

const {BUILD_WORKSPACE_DIRECTORY} = process.env;

const rulesResult = exec(
'pnpm --silent bazel query \'filter("\\.update$", kind(rule, //packages/compiler-cli/test/compliance/test_cases:*))\' --output label',
{cwd: BUILD_WORKSPACE_DIRECTORY, env: process.env, silent: true});
const rulesResult = spawnSync(
'pnpm',
['--silent', 'bazel', 'query', 'filter("\\.update$", kind(rule, //packages/compiler-cli/test/compliance/test_cases:*))', '--output=label'],
{cwd: BUILD_WORKSPACE_DIRECTORY, env: process.env, encoding: 'utf-8'});

if (rulesResult.code !== 0) {
if (rulesResult.status !== 0) {
throw new Error('Failed to query Bazel for the update rules:\n' + rulesResult.stderr);
}

for (const rule of rulesResult.split('\n')) {
for (const rule of rulesResult.stdout.split('\n')) {
if (rule.trim() !== '') {
console.log('pnpm bazel run ' + rule);
}
Expand Down
12 changes: 7 additions & 5 deletions packages/compiler-cli/test/compliance/update_all_goldens.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
*/

// tslint:disable:no-console
import shelljs from 'shelljs';
const {exec} = shelljs;
import {execSync, spawnSync} from 'child_process';

process.stdout.write('Gathering all partial golden update targets');
const queryCommand = `pnpm -s bazel query --output label "kind(_write_source_file, //packages/compiler-cli/test/compliance/test_cases:*)"`;
const allUpdateTargets = exec(queryCommand, {silent: true})
const allUpdateTargets = execSync(queryCommand, {encoding: 'utf-8', stdio: 'pipe'})
.trim()
.split('\n')
.map((target) => target.trim())
Expand All @@ -33,10 +32,13 @@ process.stdout.cursorTo(0);
for (const [index, target] of allUpdateTargets.entries()) {
const progress = `${index + 1} / ${allUpdateTargets.length}`;
process.stdout.write(`[${progress}] Running: ${target}`);
const commandResult = exec(`pnpm bazel run ${target}`, {silent: true});
const commandResult = spawnSync('pnpm', ['bazel', 'run', target], {
stdio: 'pipe',
encoding: 'utf-8',
});
process.stdout.clearLine();
process.stdout.cursorTo(0);
if (commandResult.code) {
if (commandResult.status) {
console.error(`[${progress}] Failed run: ${target}`);
console.group();
console.error(commandResult.stdout || commandResult.stderr);
Expand Down
2 changes: 0 additions & 2 deletions packages/core/schematics/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ts_project(
deps = [
"//:node_modules/@angular-devkit/core",
"//:node_modules/@angular-devkit/schematics",
"//:node_modules/@types/shelljs",
"//:node_modules/tslint",
"//packages/core/schematics/utils",
"//packages/core/schematics/utils/tsurge",
Expand All @@ -19,7 +18,6 @@ jasmine_test(
timeout = "moderate",
data = [
":test_lib",
"//:node_modules/shelljs",
"//packages/core/schematics:bundles",
"//packages/core/schematics:schematics_jsons",
"//packages/core/schematics/migrations/control-flow-migration:static_files",
Expand Down
12 changes: 6 additions & 6 deletions packages/core/schematics/test/all-migrations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import {getSystemPath, normalize, virtualFs} from '@angular-devkit/core';
import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {rmSync} from 'node:fs';
import fs from 'fs';
import {resolve} from 'path';
import shx from 'shelljs';

describe('all migrations', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -41,17 +41,17 @@ describe('all migrations', () => {
);
writeFile('/tsconfig.json', `{}`);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);

// Switch into the temporary directory path. This allows us to run
// the schematic against our custom unit test tree.
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

function writeFile(filePath: string, contents: string) {
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('all migrations', () => {
error = e;
}

expect(error).toBe(null);
expect(error).toBe(null, migrationName);
});
}
});
4 changes: 2 additions & 2 deletions packages/core/schematics/test/application_config_core_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {resolve} from 'node:path';
import shx from 'shelljs';
import {execSync} from 'node:child_process';

describe('application-config migration', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -43,7 +43,7 @@ describe('application-config migration', () => {
}),
);

shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

it('should migrate an import of ApplicationConfig', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {resolve} from 'node:path';
import shx from 'shelljs';
import {rmSync} from 'node:fs';

describe('cleanup unused imports schematic', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -45,13 +45,13 @@ describe('cleanup unused imports schematic', () => {
}),
);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);
runner.logger.subscribe((log) => logs.push(log.message));

// Switch into the temporary directory path. This allows us to run
// the schematic against our custom unit test tree.
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);

writeFile(
'directives.ts',
Expand All @@ -71,8 +71,8 @@ describe('cleanup unused imports schematic', () => {
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

it('should clean up an array where some imports are not used', async () => {
Expand Down
18 changes: 9 additions & 9 deletions packages/core/schematics/test/control_flow_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {resolve} from 'path';
import shx from 'shelljs';
import {rmSync} from 'node:fs';

describe('control flow migration (ng update)', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -54,17 +54,17 @@ describe('control flow migration (ng update)', () => {
}),
);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);

// Switch into the temporary directory path. This allows us to run
// the schematic against our custom unit test tree.
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

describe('ngIf', () => {
Expand Down Expand Up @@ -6912,17 +6912,17 @@ describe('control flow migration (ng generate)', () => {
}),
);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);

// Switch into the temporary directory path. This allows us to run
// the schematic against our custom unit test tree.
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

describe('path', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/schematics/test/inject_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {resolve} from 'node:path';
import shx from 'shelljs';
import {rmSync} from 'node:fs';

describe('inject migration', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -50,14 +50,14 @@ describe('inject migration', () => {
}),
);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

['Directive', 'Component', 'Pipe', 'NgModule'].forEach((decorator) => {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/schematics/test/output_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {resolve} from 'node:path';
import shx from 'shelljs';
import {rmSync} from 'node:fs';

describe('output migration', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -43,14 +43,14 @@ describe('output migration', () => {
}),
);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

it('should work', async () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/core/schematics/test/queries_migration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing';
import {HostTree} from '@angular-devkit/schematics';
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing/index.js';
import {resolve} from 'node:path';
import shx from 'shelljs';
import {rmSync} from 'node:fs';

describe('signal queries migration', () => {
let runner: SchematicTestRunner;
Expand Down Expand Up @@ -43,14 +43,14 @@ describe('signal queries migration', () => {
}),
);

previousWorkingDir = shx.pwd();
previousWorkingDir = process.cwd();
tmpDirPath = getSystemPath(host.root);
shx.cd(tmpDirPath);
process.chdir(tmpDirPath);
});

afterEach(() => {
shx.cd(previousWorkingDir);
shx.rm('-r', tmpDirPath);
process.chdir(previousWorkingDir);
rmSync(tmpDirPath, {recursive: true});
});

it('should work', async () => {
Expand Down
Loading