fix(ngcc): correctly detect external files from nested node_modules/
(#36559)
Previously, when we needed to detect whether a file is external to a package, we only checked whether the relative path to the file from the package's root started with `..`. This would detect external imports when the packages were siblings (e.g. peer dependencies or hoisted to the top of `node_modules/` by the package manager), but would fail to detect imports from packages located in nested `node_modules/` as external. For example, importing `node_modules/foo/node_modules/bar` from a file in `node_modules/foo/` would be considered internal to the `foo` package. This could result in processing/analyzing more files than necessary. More importantly it could lead to errors due to trying to analyze non-Angular packages that were direct dependencies of Angular packages. This commit fixes it by also verifying that the relative path to a file does not start with `node_modules/`. Jira issue: [FW-2068](https://angular-team.atlassian.net/browse/FW-2068) Fixes #36526 PR Close #36559
This commit is contained in:
@ -11,7 +11,8 @@ import {absoluteFromSourceFile, AbsoluteFsPath, relative} from '../../../src/ngt
|
||||
import {DependencyTracker} from '../../../src/ngtsc/incremental/api';
|
||||
|
||||
export function isWithinPackage(packagePath: AbsoluteFsPath, sourceFile: ts.SourceFile): boolean {
|
||||
return !relative(packagePath, absoluteFromSourceFile(sourceFile)).startsWith('..');
|
||||
const relativePath = relative(packagePath, absoluteFromSourceFile(sourceFile));
|
||||
return !relativePath.startsWith('..') && !relativePath.startsWith('node_modules/');
|
||||
}
|
||||
|
||||
class NoopDependencyTracker implements DependencyTracker {
|
||||
|
Reference in New Issue
Block a user