refactor: update compiler-cli to work with ESM (#48521)

Updates compiler-cli & tests to be full ESM compatible. Tests
no longer with CommonJS.

PR Close #48521
This commit is contained in:
Paul Gschwendtner
2022-12-13 17:33:35 +00:00
parent 619f0900a2
commit decae5b8e9
8 changed files with 26 additions and 23 deletions
@@ -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,
@@ -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],
+3 -3
View File
@@ -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) {