fix(compiler): properly work on windows

Verified manually on a windows surface tablet.

Fixes #19492
This commit is contained in:
Tobias Bosch 2017-10-03 13:47:39 -07:00 committed by Alex Rickabaugh
parent 0833b59aab
commit 696af79dc7
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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', () => {