fix(ivy): handle windows drives correctly (#30297)

At the moment the module resolver will end up in an infinite loop in Windows because we are assuming that the root directory is always `/` however in windows this can be any drive letter example `c:/` or `d:/` etc...

With this change we also resolve the drive letter in windows, when using `AbsoluteFsPath.from` for consistence so under `/foo` will be converted to `c:/foo` this is also needed because of relative paths with different drive letters.

PR Close #30297
This commit is contained in:
Alan
2019-04-30 13:44:17 +02:00
committed by Alex Rickabaugh
parent f74373f2dd
commit 3a7bfc721e
4 changed files with 17 additions and 7 deletions

View File

@ -40,6 +40,12 @@ export const AbsoluteFsPath = {
* Convert the path `str` to an `AbsoluteFsPath`, throwing an error if it's not an absolute path.
*/
from: function(str: string): AbsoluteFsPath {
if (str.startsWith('/') && process.platform === 'win32') {
// in Windows if it's absolute path and starts with `/` we shall
// resolve it and return it including the drive.
str = path.resolve(str);
}
const normalized = normalizeSeparators(str);
if (!isAbsolutePath(normalized)) {
throw new Error(`Internal Error: AbsoluteFsPath.from(${str}): path is not absolute`);
@ -80,6 +86,9 @@ export const AbsoluteFsPath = {
*/
resolve: function(basePath: string, ...paths: string[]):
AbsoluteFsPath { return AbsoluteFsPath.from(path.resolve(basePath, ...paths));},
/** Returns true when the path provided is the root path. */
isRoot: function(path: AbsoluteFsPath): boolean { return AbsoluteFsPath.dirname(path) === path;},
};
/**