fix(tsc-wrapped): use windows friendly path normalization in bundler (#15374)
Fixes #15289 PR Close #15374
This commit is contained in:
parent
1bcbcfd56f
commit
c58499786c
|
@ -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');
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue