perf(ivy): ngcc - only render .d.ts analysis when necessary (#26403)
For each package entry-point there is only one format that is used to compile the typings files (.d.ts). This will be either esm2015 or fesm2015 (preferred). So we would not run any dts processing in the renderer if we are not compiling the appropriate format. PR Close #26403
This commit is contained in:
parent
603e7935aa
commit
2f30bbb495
|
@ -85,8 +85,8 @@ export class Transformer {
|
|||
|
||||
console.time(entryPoint.name + '(rendering)');
|
||||
// Transform the source files and source maps.
|
||||
const renderer =
|
||||
this.getRenderer(format, packageProgram, reflectionHost, isCore, r3SymbolsFile);
|
||||
const renderer = this.getRenderer(
|
||||
format, packageProgram, reflectionHost, isCore, r3SymbolsFile, transformDts);
|
||||
const renderedFiles =
|
||||
renderer.renderProgram(packageProgram, decorationAnalyses, switchMarkerAnalyses);
|
||||
console.timeEnd(entryPoint.name + '(rendering)');
|
||||
|
@ -125,14 +125,14 @@ export class Transformer {
|
|||
|
||||
getRenderer(
|
||||
format: string, program: ts.Program, host: NgccReflectionHost, isCore: boolean,
|
||||
rewriteCoreImportsTo: ts.SourceFile|null): Renderer {
|
||||
rewriteCoreImportsTo: ts.SourceFile|null, transformDts: boolean): Renderer {
|
||||
switch (format) {
|
||||
case 'esm2015':
|
||||
case 'esm5':
|
||||
case 'fesm2015':
|
||||
case 'fesm5':
|
||||
return new EsmRenderer(
|
||||
host, isCore, rewriteCoreImportsTo, this.sourcePath, this.targetPath);
|
||||
host, isCore, rewriteCoreImportsTo, this.sourcePath, this.targetPath, transformDts);
|
||||
default:
|
||||
throw new Error(`Renderer for "${format}" not yet implemented.`);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ export class EsmRenderer extends Renderer {
|
|||
constructor(
|
||||
protected host: NgccReflectionHost, protected isCore: boolean,
|
||||
protected rewriteCoreImportsTo: ts.SourceFile|null, protected sourcePath: string,
|
||||
protected targetPath: string) {
|
||||
super(host, isCore, rewriteCoreImportsTo, sourcePath, targetPath);
|
||||
protected targetPath: string, transformDts: boolean) {
|
||||
super(host, isCore, rewriteCoreImportsTo, sourcePath, targetPath, transformDts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,7 +57,7 @@ export abstract class Renderer {
|
|||
constructor(
|
||||
protected host: NgccReflectionHost, protected isCore: boolean,
|
||||
protected rewriteCoreImportsTo: ts.SourceFile|null, protected sourcePath: string,
|
||||
protected targetPath: string) {}
|
||||
protected targetPath: string, protected transformDts: boolean) {}
|
||||
|
||||
renderProgram(
|
||||
program: ts.Program, decorationAnalyses: DecorationAnalyses,
|
||||
|
@ -74,9 +74,11 @@ export abstract class Renderer {
|
|||
}
|
||||
});
|
||||
|
||||
// Transform the .d.ts files
|
||||
const dtsFiles = this.getTypingsFilesToRender(decorationAnalyses);
|
||||
dtsFiles.forEach((classes, file) => renderedFiles.push(...this.renderDtsFile(file, classes)));
|
||||
if (this.transformDts) {
|
||||
// Transform the .d.ts files
|
||||
const dtsFiles = this.getTypingsFilesToRender(decorationAnalyses);
|
||||
dtsFiles.forEach((classes, file) => renderedFiles.push(...this.renderDtsFile(file, classes)));
|
||||
}
|
||||
|
||||
return renderedFiles;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ function setup(file: {name: string, contents: string}, transformDts: boolean = f
|
|||
const decorationAnalyses =
|
||||
new DecorationAnalyzer(program.getTypeChecker(), host, [''], false).analyzeProgram(program);
|
||||
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(program);
|
||||
const renderer = new EsmRenderer(host, false, null, dir, dir);
|
||||
const renderer = new EsmRenderer(host, false, null, dir, dir, false);
|
||||
return {host, program, sourceFile, renderer, decorationAnalyses, switchMarkerAnalyses};
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ function setup(file: {name: string, contents: string}) {
|
|||
const decorationAnalyses =
|
||||
new DecorationAnalyzer(program.getTypeChecker(), host, [''], false).analyzeProgram(program);
|
||||
const switchMarkerAnalyses = new SwitchMarkerAnalyzer(host).analyzeProgram(program);
|
||||
const renderer = new EsmRenderer(host, false, null, '', '');
|
||||
const renderer = new EsmRenderer(host, false, null, '', '', false);
|
||||
return {host, program, sourceFile, renderer, decorationAnalyses, switchMarkerAnalyses};
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import {Esm2015ReflectionHost} from '../../src/host/esm2015_host';
|
|||
import {Renderer} from '../../src/rendering/renderer';
|
||||
|
||||
class TestRenderer extends Renderer {
|
||||
constructor(host: Esm2015ReflectionHost) { super(host, false, null, '/src', '/dist'); }
|
||||
constructor(host: Esm2015ReflectionHost) { super(host, false, null, '/src', '/dist', false); }
|
||||
addImports(output: MagicString, imports: {name: string, as: string}[]) {
|
||||
output.prepend('\n// ADD IMPORTS\n');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue