build: for bazel, paths in summaries should never contain blaze prefix paths (#18912)
PR Close #18912
This commit is contained in:
parent
fce7ae16f5
commit
667473c32d
@ -63,9 +63,15 @@ export function main(args) {
|
|||||||
ngOptions.annotationsAs = 'static fields';
|
ngOptions.annotationsAs = 'static fields';
|
||||||
}
|
}
|
||||||
|
|
||||||
function relativeToRootDir(filePath: string): string {
|
if (!tsOptions.rootDirs) {
|
||||||
if (tsOptions.rootDir) {
|
throw new Error('rootDirs is not set!');
|
||||||
const rel = path.relative(tsOptions.rootDir, filePath);
|
}
|
||||||
|
|
||||||
|
function relativeToRootDirs(filePath: string, rootDirs: string[]): string {
|
||||||
|
if (!filePath) return filePath;
|
||||||
|
// NB: the rootDirs should have been sorted longest-first
|
||||||
|
for (const dir of rootDirs || []) {
|
||||||
|
const rel = path.relative(dir, filePath);
|
||||||
if (rel.indexOf('.') != 0) return rel;
|
if (rel.indexOf('.') != 0) return rel;
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
@ -77,7 +83,7 @@ export function main(args) {
|
|||||||
tsHost.writeFile =
|
tsHost.writeFile =
|
||||||
(fileName: string, content: string, writeByteOrderMark: boolean,
|
(fileName: string, content: string, writeByteOrderMark: boolean,
|
||||||
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
|
onError?: (message: string) => void, sourceFiles?: ts.SourceFile[]) => {
|
||||||
const relative = relativeToRootDir(fileName);
|
const relative = relativeToRootDirs(fileName, [tsOptions.rootDir]);
|
||||||
const expectedIdx = expectedOuts.findIndex(o => o === relative);
|
const expectedIdx = expectedOuts.findIndex(o => o === relative);
|
||||||
if (expectedIdx >= 0) {
|
if (expectedIdx >= 0) {
|
||||||
expectedOuts.splice(expectedIdx, 1);
|
expectedOuts.splice(expectedIdx, 1);
|
||||||
@ -124,7 +130,7 @@ export function main(args) {
|
|||||||
const ngHost = ng.createCompilerHost({options: ngOptions, tsHost: bazelHost});
|
const ngHost = ng.createCompilerHost({options: ngOptions, tsHost: bazelHost});
|
||||||
|
|
||||||
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) =>
|
ngHost.fileNameToModuleName = (importedFilePath: string, containingFilePath: string) =>
|
||||||
relativeToRootDir(importedFilePath).replace(EXT, '');
|
relativeToRootDirs(importedFilePath, tsOptions.rootDirs).replace(EXT, '');
|
||||||
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) =>
|
ngHost.toSummaryFileName = (fileName: string, referringSrcFileName: string) =>
|
||||||
ngHost.fileNameToModuleName(fileName, referringSrcFileName);
|
ngHost.fileNameToModuleName(fileName, referringSrcFileName);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user