From c58499786cba7b7cfb37f43bc20c22342a767b77 Mon Sep 17 00:00:00 2001 From: Chuck Jazdzewski Date: Tue, 21 Mar 2017 16:52:21 -0700 Subject: [PATCH] fix(tsc-wrapped): use windows friendly path normalization in bundler (#15374) Fixes #15289 PR Close #15374 --- tools/@angular/tsc-wrapped/src/bundler.ts | 30 +++++------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/tools/@angular/tsc-wrapped/src/bundler.ts b/tools/@angular/tsc-wrapped/src/bundler.ts index 8ecf9fc3cd..b29db71b73 100644 --- a/tools/@angular/tsc-wrapped/src/bundler.ts +++ b/tools/@angular/tsc-wrapped/src/bundler.ts @@ -522,34 +522,16 @@ export class CompilerHostAdapter implements MetadataBundlerHost { function resolveModule(importName: string, from: string): string { 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; } -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 { return o === null || (typeof o !== 'function' && typeof o !== 'object'); }