feat: add .ngsummary.ts files to support AOT unit tests
Design doc: https://docs.google.com/document/d/1VmTkz0EbEVSWfEEWEvQ5sXyQXSCvtMOw4t7pKU-jOwc/edit?usp=sharing
This commit is contained in:

committed by
Matias Niemelä

parent
2714644528
commit
547c363473
@ -7,24 +7,27 @@
|
||||
*/
|
||||
|
||||
const STRIP_SRC_FILE_SUFFIXES = /(\.ts|\.d\.ts|\.js|\.jsx|\.tsx)$/;
|
||||
const NG_FACTORY = /\.ngfactory\./;
|
||||
const GENERATED_FILE = /\.ngfactory\.|\.ngsummary\./;
|
||||
const GENERATED_MODULE = /\.ngfactory$|\.ngsummary$/;
|
||||
const JIT_SUMMARY_FILE = /\.ngsummary\./;
|
||||
const JIT_SUMMARY_NAME = /NgSummary$/;
|
||||
|
||||
export function ngfactoryFilePath(filePath: string): string {
|
||||
const urlWithSuffix = splitTypescriptSuffix(filePath);
|
||||
export function ngfactoryFilePath(filePath: string, forceSourceFile = false): string {
|
||||
const urlWithSuffix = splitTypescriptSuffix(filePath, forceSourceFile);
|
||||
return `${urlWithSuffix[0]}.ngfactory${urlWithSuffix[1]}`;
|
||||
}
|
||||
|
||||
export function stripNgFactory(filePath: string): string {
|
||||
return filePath.replace(NG_FACTORY, '.');
|
||||
export function stripGeneratedFileSuffix(filePath: string): string {
|
||||
return filePath.replace(GENERATED_FILE, '.');
|
||||
}
|
||||
|
||||
export function isNgFactoryFile(filePath: string): boolean {
|
||||
return NG_FACTORY.test(filePath);
|
||||
export function isGeneratedFile(filePath: string): boolean {
|
||||
return GENERATED_FILE.test(filePath);
|
||||
}
|
||||
|
||||
export function splitTypescriptSuffix(path: string): string[] {
|
||||
export function splitTypescriptSuffix(path: string, forceSourceFile = false): string[] {
|
||||
if (path.endsWith('.d.ts')) {
|
||||
return [path.slice(0, -5), '.ts'];
|
||||
return [path.slice(0, -5), forceSourceFile ? '.ts' : '.d.ts'];
|
||||
}
|
||||
|
||||
const lastDot = path.lastIndexOf('.');
|
||||
@ -40,3 +43,20 @@ export function summaryFileName(fileName: string): string {
|
||||
const fileNameWithoutSuffix = fileName.replace(STRIP_SRC_FILE_SUFFIXES, '');
|
||||
return `${fileNameWithoutSuffix}.ngsummary.json`;
|
||||
}
|
||||
|
||||
export function summaryForJitFileName(fileName: string, forceSourceFile = false): string {
|
||||
const urlWithSuffix = splitTypescriptSuffix(stripGeneratedFileSuffix(fileName), forceSourceFile);
|
||||
return `${urlWithSuffix[0]}.ngsummary${urlWithSuffix[1]}`;
|
||||
}
|
||||
|
||||
export function stripSummaryForJitFileSuffix(filePath: string): string {
|
||||
return filePath.replace(JIT_SUMMARY_FILE, '.');
|
||||
}
|
||||
|
||||
export function summaryForJitName(symbolName: string): string {
|
||||
return `${symbolName}NgSummary`;
|
||||
}
|
||||
|
||||
export function stripSummaryForJitNameSuffix(symbolName: string): string {
|
||||
return symbolName.replace(JIT_SUMMARY_NAME, '');
|
||||
}
|
Reference in New Issue
Block a user