fix(compiler-cli): base synthetic filepaths on input filepath (#28453)
This change is needed to work in google3, where file paths in the ts.Program must always be absolute. PR Close #28453
This commit is contained in:
parent
f2621dbb37
commit
7219639ff3
|
@ -30,7 +30,7 @@ export class SyntheticFilesCompilerHost implements PluginCompilerHost {
|
|||
private rootFiles: string[], private delegate: ts.CompilerHost,
|
||||
generatedFiles: (rootFiles: string[]) => {
|
||||
[fileName: string]: (host: ts.CompilerHost) => ts.SourceFile | undefined
|
||||
}, ) {
|
||||
}) {
|
||||
// Allow ngtsc to contribute in-memory synthetic files, which will be loaded
|
||||
// as if they existed on disk as action inputs.
|
||||
const angularGeneratedFiles = generatedFiles !(rootFiles);
|
||||
|
|
|
@ -11,7 +11,9 @@ import * as ts from 'typescript';
|
|||
|
||||
import {SyntheticFilesCompilerHost} from './synthetic_files_compiler_host';
|
||||
|
||||
// Copied from tsc_wrapped/plugin_api.ts to avoid a runtime dependency on that package
|
||||
// Copied from tsc_wrapped/plugin_api.ts to avoid a runtime dependency on the
|
||||
// @bazel/typescript package - it would be strange for non-Bazel users of
|
||||
// Angular to fetch that package.
|
||||
function createProxy<T>(delegate: T): T {
|
||||
const proxy = Object.create(null);
|
||||
for (const k of Object.keys(delegate)) {
|
||||
|
@ -23,6 +25,20 @@ function createProxy<T>(delegate: T): T {
|
|||
export class NgTscPlugin implements TscPlugin {
|
||||
constructor(private angularCompilerOptions: unknown) {}
|
||||
|
||||
wrapHost(inputFiles: string[], compilerHost: ts.CompilerHost) {
|
||||
return new SyntheticFilesCompilerHost(inputFiles, compilerHost, (rootFiles: string[]) => {
|
||||
// For demo purposes, assume that the first .ts rootFile is the only
|
||||
// one that needs ngfactory.js/d.ts back-compat files produced.
|
||||
const tsInputs = rootFiles.filter(f => f.endsWith('.ts') && !f.endsWith('.d.ts'));
|
||||
const factoryPath: string = tsInputs[0].replace(/\.ts/, '.ngfactory.ts');
|
||||
|
||||
return {
|
||||
factoryPath: (host: ts.CompilerHost) =>
|
||||
ts.createSourceFile(factoryPath, 'contents', ts.ScriptTarget.ES5),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
wrap(program: ts.Program, config: {}, host: ts.CompilerHost) {
|
||||
const proxy = createProxy(program);
|
||||
proxy.getSemanticDiagnostics = (sourceFile: ts.SourceFile) => {
|
||||
|
@ -38,7 +54,7 @@ export class NgTscPlugin implements TscPlugin {
|
|||
category: ts.DiagnosticCategory.Error,
|
||||
code: 12345,
|
||||
// source is the name of the plugin.
|
||||
source: 'Angular',
|
||||
source: 'ngtsc',
|
||||
};
|
||||
result.push(fake);
|
||||
}
|
||||
|
@ -64,15 +80,4 @@ export class NgTscPlugin implements TscPlugin {
|
|||
}];
|
||||
return {afterDeclarations};
|
||||
}
|
||||
|
||||
wrapHost(inputFiles: string[], compilerHost: ts.CompilerHost) {
|
||||
return new SyntheticFilesCompilerHost(inputFiles, compilerHost, this.generatedFiles);
|
||||
}
|
||||
|
||||
generatedFiles(rootFiles: string[]) {
|
||||
return {
|
||||
'file-1.ts': (host: ts.CompilerHost) =>
|
||||
ts.createSourceFile('file-1.ts', 'contents', ts.ScriptTarget.ES5),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue