diff --git a/packages/compiler-cli/src/transformers/compiler_host.ts b/packages/compiler-cli/src/transformers/compiler_host.ts index acdf9f5c0d..ab1e664b20 100644 --- a/packages/compiler-cli/src/transformers/compiler_host.ts +++ b/packages/compiler-cli/src/transformers/compiler_host.ts @@ -108,7 +108,8 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter extends private resolveModuleName(moduleName: string, containingFile: string): ts.ResolvedModule |undefined { const rm = ts.resolveModuleName( - moduleName, containingFile, this.options, this, this.moduleResolutionCache) + moduleName, containingFile.replace(/\\/g, '/'), this.options, this, + this.moduleResolutionCache) .resolvedModule; if (rm && this.isSourceFile(rm.resolvedFileName)) { // Case: generateCodeForLibraries = true and moduleName is diff --git a/packages/compiler-cli/test/transformers/compiler_host_spec.ts b/packages/compiler-cli/test/transformers/compiler_host_spec.ts index d597fb8ce2..b9d354bebd 100644 --- a/packages/compiler-cli/test/transformers/compiler_host_spec.ts +++ b/packages/compiler-cli/test/transformers/compiler_host_spec.ts @@ -41,16 +41,18 @@ describe('NgCompilerHost', () => { basePath: '/tmp', moduleResolution: ts.ModuleResolutionKind.NodeJs, }, + rootNames = ['/tmp/index.ts'], ngHost = createNgHost({files}), librarySummaries = [], }: { files?: Directory, options?: CompilerOptions, + rootNames?: string[], ngHost?: CompilerHost, librarySummaries?: LibrarySummary[] } = {}) { return new TsCompilerAotCompilerTypeCheckHostAdapter( - ['/tmp/index.ts'], options, ngHost, new MetadataCollector(), codeGenerator, + rootNames, options, ngHost, new MetadataCollector(), codeGenerator, new Map(librarySummaries.map(entry => [entry.fileName, entry] as[string, LibrarySummary]))); } @@ -143,6 +145,15 @@ describe('NgCompilerHost', () => { const host = createHost({ngHost}); expect(host.moduleNameToFileName('a', 'b')).toBe('someResult'); }); + + it('should work well with windows paths', () => { + const host = createHost({ + rootNames: ['\\tmp\\index.ts'], + options: {basePath: '\\tmp'}, + files: {'tmp': {'node_modules': {'@core': {'index.d.ts': dummyModule}}}} + }); + expect(host.moduleNameToFileName('@core/index')).toBe('/tmp/node_modules/@core/index.d.ts'); + }); }); describe('resourceNameToFileName', () => {