fix(compiler): correctly calculate the outDir if it repeats a parts of the rootDir
. (#19836)
Fixes #19718 PR Close #19836
This commit is contained in:

committed by
Matias Niemelä

parent
8d45fefc31
commit
fc0b1d5b61
@ -6,9 +6,10 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import * as path from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {DEFAULT_ERROR_CODE, Diagnostic, SOURCE} from './api';
|
||||
import {CompilerOptions, DEFAULT_ERROR_CODE, Diagnostic, SOURCE} from './api';
|
||||
|
||||
export const GENERATED_FILES = /(.*?)\.(ngfactory|shim\.ngstyle|ngstyle|ngsummary)\.(js|d\.ts|ts)$/;
|
||||
export const DTS = /\.d\.ts$/;
|
||||
@ -30,3 +31,23 @@ export function createMessageDiagnostic(messageText: string): ts.Diagnostic&Diag
|
||||
source: SOURCE,
|
||||
};
|
||||
}
|
||||
|
||||
export function isInRootDir(fileName: string, options: CompilerOptions) {
|
||||
return !options.rootDir || pathStartsWithPrefix(options.rootDir, fileName);
|
||||
}
|
||||
|
||||
export function relativeToRootDirs(filePath: string, rootDirs: string[]): string {
|
||||
if (!filePath) return filePath;
|
||||
for (const dir of rootDirs || []) {
|
||||
const rel = pathStartsWithPrefix(dir, filePath);
|
||||
if (rel) {
|
||||
return rel;
|
||||
}
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
function pathStartsWithPrefix(prefix: string, fullPath: string): string|null {
|
||||
const rel = path.relative(prefix, fullPath);
|
||||
return rel.startsWith('..') ? null : rel;
|
||||
}
|
||||
|
Reference in New Issue
Block a user