diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts
index 4fd486ece7f..234937d1c1b 100644
--- a/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts
+++ b/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts
@@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
///
-import * as fs from 'fs';
+import fs from 'fs';
import module from 'module';
import * as p from 'path';
import {fileURLToPath} from 'url';
diff --git a/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts b/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts
index 0e8c89e7a27..3881abc8175 100644
--- a/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts
+++ b/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts
@@ -9,7 +9,8 @@
// named exports being modified if we apply jasmine spies on `realFs`. Using
// the default export gives us an object where we can patch properties on.
import realFs from 'fs';
-import * as os from 'os';
+import os from 'os';
+import url from 'url';
import {NodeJSFileSystem, NodeJSPathManipulation, NodeJSReadonlyFileSystem} from '../src/node_js_file_system';
import {AbsoluteFsPath, PathSegment} from '../src/types';
@@ -57,7 +58,8 @@ describe('NodeJSReadonlyFileSystem', () => {
describe('isCaseSensitive()', () => {
it('should return true if the FS is case-sensitive', () => {
- const isCaseSensitive = !realFs.existsSync(__filename.toUpperCase());
+ const currentFilename = url.fileURLToPath(import.meta.url);
+ const isCaseSensitive = !realFs.existsSync(currentFilename.toUpperCase());
expect(fs.isCaseSensitive()).toEqual(isCaseSensitive);
});
});
diff --git a/packages/compiler-cli/src/ngtsc/testing/BUILD.bazel b/packages/compiler-cli/src/ngtsc/testing/BUILD.bazel
index 7294e83e839..be931746adc 100644
--- a/packages/compiler-cli/src/ngtsc/testing/BUILD.bazel
+++ b/packages/compiler-cli/src/ngtsc/testing/BUILD.bazel
@@ -15,6 +15,7 @@ ts_library(
"//packages/compiler-cli/src/ngtsc/file_system/testing",
"//packages/compiler-cli/src/ngtsc/reflection",
"//packages/compiler-cli/src/ngtsc/util",
+ "@npm//@bazel/runfiles",
"@npm//typescript",
],
)
diff --git a/packages/compiler-cli/src/ngtsc/testing/src/mock_file_loading.ts b/packages/compiler-cli/src/ngtsc/testing/src/mock_file_loading.ts
index 53804633ed9..15633698dad 100644
--- a/packages/compiler-cli/src/ngtsc/testing/src/mock_file_loading.ts
+++ b/packages/compiler-cli/src/ngtsc/testing/src/mock_file_loading.ts
@@ -13,7 +13,7 @@ import {resolve} from 'path';
import {AbsoluteFsPath, FileSystem, getFileSystem} from '../../file_system';
import {Folder, MockFileSystemPosix, TestFile} from '../../file_system/testing';
-import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from './runfile_helpers';
+import {getAngularPackagesFromRunfiles, resolveFromRunfiles} from './runfile_helpers';
export function loadTestFiles(files: TestFile[]) {
const fs = getFileSystem();
@@ -39,9 +39,10 @@ class CachedFolder {
}
}
-const typescriptFolder = new CachedFolder(() => loadFolder(resolveNpmTreeArtifact('typescript')));
+const typescriptFolder =
+ new CachedFolder(() => loadFolder(resolveFromRunfiles('npm/node_modules/typescript')));
const angularFolder = new CachedFolder(loadAngularFolder);
-const rxjsFolder = new CachedFolder(() => loadFolder(resolveNpmTreeArtifact('rxjs')));
+const rxjsFolder = new CachedFolder(() => loadFolder(resolveFromRunfiles('npm/node_modules/rxjs')));
export function loadStandardTestFiles(
{fakeCore = true, fakeCommon = false, rxjs = false}:
@@ -72,21 +73,21 @@ export function loadStandardTestFiles(
export function loadTsLib(fs: FileSystem, basePath: string = '/') {
loadTestDirectory(
- fs, resolveNpmTreeArtifact('tslib'), fs.resolve(basePath, 'node_modules/tslib'));
+ fs, resolveFromRunfiles('npm/node_modules/tslib'),
+ fs.resolve(basePath, 'node_modules/tslib'));
}
export function loadFakeCore(fs: FileSystem, basePath: string = '/') {
loadTestDirectory(
fs,
- resolveNpmTreeArtifact(
- 'angular/packages/compiler-cli/src/ngtsc/testing/fake_core/npm_package'),
+ resolveFromRunfiles('angular/packages/compiler-cli/src/ngtsc/testing/fake_core/npm_package'),
fs.resolve(basePath, 'node_modules/@angular/core'));
}
export function loadFakeCommon(fs: FileSystem, basePath: string = '/') {
loadTestDirectory(
fs,
- resolveNpmTreeArtifact(
+ resolveFromRunfiles(
'angular/packages/compiler-cli/src/ngtsc/testing/fake_common/npm_package'),
fs.resolve(basePath, 'node_modules/@angular/common'));
}
diff --git a/packages/compiler-cli/src/ngtsc/testing/src/runfile_helpers.ts b/packages/compiler-cli/src/ngtsc/testing/src/runfile_helpers.ts
index 3fe31c15b5c..21a32440769 100644
--- a/packages/compiler-cli/src/ngtsc/testing/src/runfile_helpers.ts
+++ b/packages/compiler-cli/src/ngtsc/testing/src/runfile_helpers.ts
@@ -7,6 +7,7 @@
*/
///
+import {runfiles} from '@bazel/runfiles';
import * as fs from 'fs';
import * as path from 'path';
@@ -39,11 +40,7 @@ export function getAngularPackagesFromRunfiles() {
}));
}
-/**
- * Resolves a NPM package from the Bazel runfiles. We need to resolve the Bazel tree
- * artifacts using a "resolve file" because the NodeJS module resolution does not allow
- * resolving to directory paths.
- */
-export function resolveNpmTreeArtifact(manifestPath: string, resolveFile = 'package.json') {
- return path.dirname(require.resolve(path.posix.join(manifestPath, resolveFile)));
+/** Resolves a file or directory from the Bazel runfiles. */
+export function resolveFromRunfiles(manifestPath: string) {
+ return runfiles.resolve(manifestPath);
}
diff --git a/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts b/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts
index 7ee96cc3ef4..daa1dee0245 100644
--- a/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts
+++ b/packages/compiler-cli/test/compliance/linked/linked_compile_spec.ts
@@ -5,9 +5,10 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
+import babel, {PluginObj} from '@babel/core';
+
import {needsLinking} from '../../../linker';
import {createEs2015LinkerPlugin} from '../../../linker/babel';
-import {PluginObj, transformSync} from '../../../linker/babel/src/babel_core';
import {AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system';
import {ConsoleLogger, LogLevel} from '../../../src/ngtsc/logging';
import {MapAndPath, RawSourceMap, SourceFileLoader} from '../../../src/ngtsc/sourcemaps';
@@ -88,7 +89,7 @@ function applyLinker(
if (!filename.endsWith('.js') || !needsLinking(filename, source)) {
return {linkedSource: source, linkedSourceMap: sourceMap};
}
- const result = transformSync(source, {
+ const result = babel.transformSync(source, {
cwd,
filename,
sourceMaps: !!sourceMap,
diff --git a/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl b/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl
index b294a4ad592..4df086fec8b 100644
--- a/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl
+++ b/packages/compiler-cli/test/compliance/partial/partial_compliance_goldens.bzl
@@ -17,7 +17,8 @@ def partial_compliance_golden(filePath):
nodejs_binary(
name = generate_partial_name,
testonly = True,
- data = data + [filePath],
+ data = data,
+ data_for_args = [filePath],
visibility = [":__pkg__"],
entry_point = "//packages/compiler-cli/test/compliance/partial:cli.ts",
templated_args = ["$(execpath %s)" % filePath],
diff --git a/packages/compiler-cli/test/test_support.ts b/packages/compiler-cli/test/test_support.ts
index 7e5423d5fee..da557771aa3 100644
--- a/packages/compiler-cli/test/test_support.ts
+++ b/packages/compiler-cli/test/test_support.ts
@@ -12,7 +12,7 @@ import ts from 'typescript';
import * as ng from '../index';
import {NodeJSFileSystem, setFileSystem} from '../src/ngtsc/file_system';
-import {getAngularPackagesFromRunfiles, resolveNpmTreeArtifact} from '../src/ngtsc/testing';
+import {getAngularPackagesFromRunfiles, resolveFromRunfiles} from '../src/ngtsc/testing';
// TEST_TMPDIR is always set by Bazel.
const tmpdir = process.env.TEST_TMPDIR!;
@@ -132,14 +132,14 @@ export function setupBazelTo(tmpDirPath: string) {
});
// Link typescript
- const typeScriptSource = resolveNpmTreeArtifact('npm/node_modules/typescript');
+ const typeScriptSource = resolveFromRunfiles('npm/node_modules/typescript');
const typescriptDest = path.join(nodeModulesPath, 'typescript');
fs.symlinkSync(typeScriptSource, typescriptDest, 'junction');
// Link "rxjs" if it has been set up as a runfile. "rxjs" is linked optionally because
// not all compiler-cli tests need "rxjs" set up.
try {
- const rxjsSource = resolveNpmTreeArtifact('rxjs', 'index.js');
+ const rxjsSource = resolveFromRunfiles('npm/node_modules/rxjs');
const rxjsDest = path.join(nodeModulesPath, 'rxjs');
fs.symlinkSync(rxjsSource, rxjsDest, 'junction');
} catch (e: any) {