Skip to content

Commit 464c1c4

Browse files
devversionzarend
authored andcommitted
build: update linker integration test to work with Angular v13
Updates the linker integration test to no logner use deep imports into the stict ESM package of `@angular/compiler-cli`. The linker integration test tooling is now using ESM as well; in order to be able to import into the compiler-cli.
1 parent f0142aa commit 464c1c4

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

integration/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ package(default_visibility = ["//visibility:public"])
66
# available in the runfiles of an action.
77
js_library(
88
name = "npm-packages-from-runfiles",
9-
srcs = ["npm-packages-from-runfiles.js"],
9+
srcs = ["npm-packages-from-runfiles.mjs"],
1010
)

integration/linker/BUILD.bazel

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_test")
55
nodejs_test(
66
name = "linker",
77
data = [
8+
"link-packages-test.mjs",
89
"//integration:npm-packages-from-runfiles",
910
"//src/cdk:npm_package",
1011
"//src/cdk-experimental:npm_package",
@@ -18,6 +19,6 @@ nodejs_test(
1819
"@npm//chalk",
1920
"@npm//glob",
2021
],
21-
entry_point = "link-packages-test.js",
22+
entry_point = "link-packages-test.mjs",
2223
tags = ["partial-compilation-integration"],
2324
)

integration/linker/link-packages-test.js renamed to integration/linker/link-packages-test.mjs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
* declarations to the corresponding definitions.
44
*/
55

6-
const {NodeJSFileSystem} = require('@angular/compiler-cli/src/ngtsc/file_system');
7-
const {ConsoleLogger, LogLevel} = require('@angular/compiler-cli/src/ngtsc/logging');
8-
const {createEs2015LinkerPlugin} = require('@angular/compiler-cli/linker/babel');
9-
const {getNpmPackagesFromRunfiles} = require('../npm-packages-from-runfiles');
10-
const {readFileSync} = require('fs');
11-
const {join} = require('path');
12-
const babel = require('@babel/core');
13-
const {default: traverse} = require('@babel/traverse');
14-
const glob = require('glob');
15-
const chalk = require('chalk');
6+
import {createEs2015LinkerPlugin} from '@angular/compiler-cli/linker/babel';
7+
import {NodeJSFileSystem, ConsoleLogger, LogLevel} from '@angular/compiler-cli';
8+
import {getNpmPackagesFromRunfiles} from '../npm-packages-from-runfiles.mjs';
9+
import fs from 'fs';
10+
import path from 'path';
11+
import babel from '@babel/core';
12+
import traverse from '@babel/traverse';
13+
import glob from 'glob';
14+
import chalk from 'chalk';
1615

1716
/** File system used by the Angular linker plugin. */
1817
const fileSystem = new NodeJSFileSystem();
@@ -65,9 +64,9 @@ function testPackage(pkg) {
6564
// Iterate through each entry point and confirm that all partial declarations can be linked
6665
// to their corresponding Angular definitions without errors.
6766
for (const fesmFileName of entryPointFesmFiles) {
68-
const diskFilePath = join(pkg.pkgPath, fesmFileName);
69-
const debugFileName = join(pkg.name, fesmFileName);
70-
const fileContent = readFileSync(diskFilePath, 'utf8');
67+
const diskFilePath = path.join(pkg.pkgPath, fesmFileName);
68+
const debugFileName = path.join(pkg.name, fesmFileName);
69+
const fileContent = fs.readFileSync(diskFilePath, 'utf8');
7170
const linkerPlugin = createEs2015LinkerPlugin({fileSystem, logger});
7271

7372
// Babel throws errors if the transformation fails. We catch these so that we

integration/npm-packages-from-runfiles.js renamed to integration/npm-packages-from-runfiles.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* integration tests.
44
*/
55

6-
const {relative, sep, join} = require('path');
7-
const {readdirSync, readFileSync, existsSync} = require('fs');
6+
import path from 'path';
7+
import fs from 'fs';
88

99
/**
1010
* Gets all built Angular NPM package artifacts by querying the Bazel runfiles.
@@ -13,24 +13,24 @@ const {readdirSync, readFileSync, existsSync} = require('fs');
1313
* within the real filesystem.
1414
* TODO: Simplify if Bazel on Windows uses runfile symlinking.
1515
*/
16-
exports.getNpmPackagesFromRunfiles = function() {
16+
export function getNpmPackagesFromRunfiles() {
1717
// Path to the Bazel runfiles manifest if present. This file is present if runfiles are
1818
// not symlinked into the runfiles directory.
1919
const runfilesManifestPath = process.env.RUNFILES_MANIFEST_FILE;
2020
const workspacePath = 'angular_material/src';
2121
if (!runfilesManifestPath) {
22-
const packageRunfilesDir = join(process.env.RUNFILES, workspacePath);
23-
return readdirSync(packageRunfilesDir)
24-
.map(name => ({name, pkgPath: join(packageRunfilesDir, name, 'npm_package/')}))
25-
.filter(({pkgPath}) => existsSync(pkgPath));
22+
const packageRunfilesDir = path.join(process.env.RUNFILES, workspacePath);
23+
return fs.readdirSync(packageRunfilesDir)
24+
.map(name => ({name, pkgPath: path.join(packageRunfilesDir, name, 'npm_package/')}))
25+
.filter(({pkgPath}) => fs.existsSync(pkgPath));
2626
}
2727
const workspaceManifestPathRegex = new RegExp(`^${workspacePath}/[\\w-]+/npm_package$`);
28-
return readFileSync(runfilesManifestPath, 'utf8')
28+
return fs.readFileSync(runfilesManifestPath, 'utf8')
2929
.split('\n')
3030
.map(mapping => mapping.split(' '))
3131
.filter(([runfilePath]) => runfilePath.match(workspaceManifestPathRegex))
3232
.map(([runfilePath, realPath]) => ({
33-
name: relative(workspacePath, runfilePath).split(sep)[0],
33+
name: path.relative(workspacePath, runfilePath).split(path.sep)[0],
3434
pkgPath: realPath,
3535
}));
3636
}

0 commit comments

Comments
 (0)