fix(ngcc): correctly identify relative Windows-style import paths (#36372)

Previously, `isRelativePath()` assumed paths are *nix-style. This caused
Windows-style paths (such as `C:\foo\some-package\some-file.js`) to not
be recognized as "relative" imports.

This commit fixes this by using the OS-agnostic `isRooted()` helper and
also accounting for both styles of path delimiters: `/` and `\`

PR Close #36372
This commit is contained in:
George Kalpakas
2020-04-01 17:31:04 +03:00
committed by Kara Erickson
parent ffa4e11db1
commit 0daa48800e
5 changed files with 58 additions and 29 deletions

View File

@ -7,7 +7,7 @@
*/
import * as ts from 'typescript';
import {absoluteFrom, AbsoluteFsPath, FileSystem} from '../../src/ngtsc/file_system';
import {absoluteFrom, AbsoluteFsPath, FileSystem, isRooted} from '../../src/ngtsc/file_system';
import {KnownDeclaration} from '../../src/ngtsc/reflection';
/**
@ -85,10 +85,11 @@ export type PathMappings = {
/**
* Test whether a path is "relative".
*
* Relative paths start with `/`, `./` or `../`; or are simply `.` or `..`.
* Relative paths start with `/`, `./` or `../` (or the Windows equivalents); or are simply `.` or
* `..`.
*/
export function isRelativePath(path: string): boolean {
return /^\/|^\.\.?($|\/)/.test(path);
return isRooted(path) || /^\.\.?(\/|\\|$)/.test(path);
}
/**