fix(ivy): ngcc - handle pathMappings to files rather then directories (#30525)
Paths can be mapped directly to files, which was not being taken into account when computing `basePaths` for the `EntryPointFinder`s. Now if a `pathMapping` pattern does not exist or is a file, then we try the containing folder instead. Fixes #31424 PR Close #30525
This commit is contained in:

committed by
Jason Aden

parent
a581773887
commit
207f9b6017
@ -5,7 +5,7 @@
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
import {AbsoluteFsPath, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {AbsoluteFsPath, getFileSystem, join, resolve} from '../../../src/ngtsc/file_system';
|
||||
import {PathMappings} from '../utils';
|
||||
|
||||
/**
|
||||
@ -29,11 +29,17 @@ import {PathMappings} from '../utils';
|
||||
*/
|
||||
export function getBasePaths(
|
||||
sourceDirectory: AbsoluteFsPath, pathMappings: PathMappings | undefined): AbsoluteFsPath[] {
|
||||
const basePaths = [sourceDirectory];
|
||||
const fs = getFileSystem();
|
||||
let basePaths = [sourceDirectory];
|
||||
if (pathMappings) {
|
||||
const baseUrl = resolve(pathMappings.baseUrl);
|
||||
Object.values(pathMappings.paths).forEach(paths => paths.forEach(path => {
|
||||
basePaths.push(join(baseUrl, extractPathPrefix(path)));
|
||||
// We only want base paths that exist and are not files
|
||||
let basePath = join(baseUrl, extractPathPrefix(path));
|
||||
while (basePath !== baseUrl && (!fs.exists(basePath) || fs.stat(basePath).isFile())) {
|
||||
basePath = fs.dirname(basePath);
|
||||
}
|
||||
basePaths.push(basePath);
|
||||
}));
|
||||
}
|
||||
basePaths.sort(); // Get the paths in order with the shorter ones first.
|
||||
|
Reference in New Issue
Block a user