Skip to content

Commit 8bf0e03

Browse files
committed
build: update ts-compat integration test to work with ESM
We updated the linker integration test to ESM, so that it works with the Angular compiler-cli ESM package. For this, the integration test utils are now ESM as well. This means that the ts-compat test relying on these ESM files needs to use ESM as well. The error didn't surface because with APF v13 switch we acidentally stopped running the test.
1 parent 1b1d366 commit 8bf0e03

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

integration/ts-compat/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ typescript_version_packages = [
2222
name = ts_pkg_name,
2323
args = [ts_pkg_name],
2424
data = [
25-
"helpers.js",
26-
"test.js",
25+
"helpers.mjs",
26+
"test.mjs",
2727
":import-all-entry-points-file",
2828
"//integration:npm-packages-from-runfiles",
2929
"//src/cdk:npm_package",
@@ -37,7 +37,7 @@ typescript_version_packages = [
3737
"@npm//%s" % ts_pkg_name,
3838
"@npm//@types/node",
3939
],
40-
entry_point = "test.js",
40+
entry_point = "test.mjs",
4141
)
4242
for ts_pkg_name in typescript_version_packages
4343
]

integration/ts-compat/helpers.js renamed to integration/ts-compat/helpers.mjs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
const {join} = require('path');
2-
const {unlinkSync} = require('fs');
3-
const {set, ln, rm, mkdir} = require('shelljs');
4-
const {fork} = require('child_process');
5-
const {getNpmPackagesFromRunfiles} = require('../npm-packages-from-runfiles');
6-
const {runfiles} = require('@bazel/runfiles');
1+
import {join} from 'path';
2+
import {unlinkSync} from 'fs';
3+
import shelljs from 'shelljs';
4+
import {fork} from 'child_process';
5+
import {getNpmPackagesFromRunfiles} from '../npm-packages-from-runfiles.mjs';
6+
import {runfiles} from '@bazel/runfiles';
77

88
// Exit if any command fails.
9-
set('-e');
9+
shelljs.set('-e');
1010

1111
// List of NPM packages that have been built for the current test target.
1212
const npmPackages = getNpmPackagesFromRunfiles();
@@ -21,18 +21,18 @@ const testFilePath = runfiles.resolveWorkspaceRelative(
2121
* compatibility test, links the built release packages into `node_modules` and
2222
* compiles a test file using the specified tsc binary which imports all entry-points.
2323
*/
24-
exports.runTypeScriptCompatibilityTest = async (tscBinPath) => {
24+
export async function runTypeScriptCompatibilityTest(tscBinPath) {
2525
return new Promise((resolve, reject) => {
2626
const angularDir = join(nodeModulesDir, '@angular/');
2727

2828
// Create the `node_modules/@angular` directory in case it's not present.
29-
mkdir('-p', angularDir);
29+
shelljs.mkdir('-p', angularDir);
3030

3131
// Symlink npm packages into `node_modules/` so that the project can
3232
// be compiled without path mappings (simulating a real project).
3333
for (const {name, pkgPath} of npmPackages) {
3434
console.info(`Linking "@angular/${name}" into node modules..`);
35-
ln('-sf', pkgPath, join(angularDir, name));
35+
shelljs.ln('-sf', pkgPath, join(angularDir, name));
3636
}
3737

3838
const tscArgs = [
@@ -55,7 +55,7 @@ exports.runTypeScriptCompatibilityTest = async (tscBinPath) => {
5555
for (const {name} of npmPackages) {
5656
console.info(`Removing link for "@angular/${name}"..`);
5757
unlinkSync(join(angularDir, name));
58-
rm('-rf', join(angularDir, name));
58+
shelljs.rm('-rf', join(angularDir, name));
5959
}
6060
exitCode === 0 ? resolve() : reject();
6161
});

integration/ts-compat/test.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

integration/ts-compat/test.mjs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Test script that runs the TypeScript compatibility tests against a specified
3+
* TypeScript package that is passed through command line. The script is executed
4+
* by a Bazel `nodejs_test` target and relies on Bazel runfile resolution.
5+
*/
6+
7+
import {runfiles} from '@bazel/runfiles';
8+
import {runTypeScriptCompatibilityTest} from './helpers.mjs';
9+
10+
const [pkgName] = process.argv.slice(2);
11+
if (!pkgName) {
12+
console.error('No TypeScript package specified. Exiting..');
13+
process.exit(1);
14+
}
15+
16+
const tscBin = runfiles.resolve(`npm/node_modules/${pkgName}/bin/tsc`);
17+
18+
runTypeScriptCompatibilityTest(tscBin).catch(e => {
19+
console.error(e);
20+
process.exit(1);
21+
});

0 commit comments

Comments
 (0)