fix(tsc-wrapped): use windows friendly path normalization in bundler (#15374)

Fixes #15289

PR Close #15374
This commit is contained in:
Chuck Jazdzewski 2017-03-21 16:52:21 -07:00 committed by Miško Hevery
parent 1bcbcfd56f
commit c58499786c
1 changed files with 6 additions and 24 deletions

View File

@ -522,34 +522,16 @@ export class CompilerHostAdapter implements MetadataBundlerHost {
function resolveModule(importName: string, from: string): string { function resolveModule(importName: string, from: string): string {
if (importName.startsWith('.') && from) { if (importName.startsWith('.') && from) {
return normalize(path.join(path.dirname(from), importName)); const normalPath = path.normalize(path.join(path.dirname(from), importName));
if (!normalPath.startsWith('.') && from.startsWith('.')) {
// path.normalize() preserves leading '../' but not './'. This adds it back.
return `.${path.sep}${normalPath}`;
}
return normalPath;
} }
return importName; return importName;
} }
function normalize(path: string): string {
const parts = path.split('/');
const segments: string[] = [];
for (const part of parts) {
switch (part) {
case '':
case '.':
continue;
case '..':
segments.pop();
break;
default:
segments.push(part);
}
}
if (segments.length) {
segments.unshift(path.startsWith('/') ? '' : '.');
return segments.join('/');
} else {
return '.';
}
}
function isPrimitive(o: any): o is boolean|string|number { function isPrimitive(o: any): o is boolean|string|number {
return o === null || (typeof o !== 'function' && typeof o !== 'object'); return o === null || (typeof o !== 'function' && typeof o !== 'object');
} }