fix(ivy): normalize summary and factory shim files paths (#28006)

At the moment, paths stored in `maps` are not normalized and in Windows is causing files not to be found when enabling factory shimming.

For example, the map contents will be
```
Map {
  'C:\\git\\cli-repos\\ng-factory-shims\\index.ngfactory.ts' => 'C:\\git\\cli-repos\\ng-factory-shims\\index.ts' }
```

However, ts compiler normalized the paths and is causing;
```
error TS6053: File 'C:/git/cli-repos/ng-factory-shims/index.ngfactory.ts' not found.
error TS6053: File 'C:/git/cli-repos/ng-factory-shims/index.ngsummary.ts' not found.
```

The changes normalized the paths that are stored within the factory and summary maps.

PR Close #28006
This commit is contained in:
Alan 2019-01-10 07:51:01 +01:00 committed by Andrew Kushnir
parent 6072ca87e1
commit bc02e31185
3 changed files with 9 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import * as path from 'path';
import * as ts from 'typescript'; import * as ts from 'typescript';
import {ImportRewriter} from '../../imports'; import {ImportRewriter} from '../../imports';
import {normalizeSeparators} from '../../util/src/path';
import {isNonDeclarationTsPath} from '../../util/src/typescript'; import {isNonDeclarationTsPath} from '../../util/src/typescript';
import {ShimGenerator} from './host'; import {ShimGenerator} from './host';
@ -89,6 +90,7 @@ export class FactoryGenerator implements ShimGenerator {
static forRootFiles(files: ReadonlyArray<string>): FactoryGenerator { static forRootFiles(files: ReadonlyArray<string>): FactoryGenerator {
const map = new Map<string, string>(); const map = new Map<string, string>();
files.filter(sourceFile => isNonDeclarationTsPath(sourceFile)) files.filter(sourceFile => isNonDeclarationTsPath(sourceFile))
.map(sourceFile => normalizeSeparators(sourceFile))
.forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngfactory.ts'), sourceFile)); .forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngfactory.ts'), sourceFile));
return new FactoryGenerator(map); return new FactoryGenerator(map);
} }

View File

@ -8,6 +8,7 @@
import * as ts from 'typescript'; import * as ts from 'typescript';
import {normalizeSeparators} from '../../util/src/path';
import {isNonDeclarationTsPath} from '../../util/src/typescript'; import {isNonDeclarationTsPath} from '../../util/src/typescript';
import {ShimGenerator} from './host'; import {ShimGenerator} from './host';
@ -64,6 +65,7 @@ export class SummaryGenerator implements ShimGenerator {
static forRootFiles(files: ReadonlyArray<string>): SummaryGenerator { static forRootFiles(files: ReadonlyArray<string>): SummaryGenerator {
const map = new Map<string, string>(); const map = new Map<string, string>();
files.filter(sourceFile => isNonDeclarationTsPath(sourceFile)) files.filter(sourceFile => isNonDeclarationTsPath(sourceFile))
.map(sourceFile => normalizeSeparators(sourceFile))
.forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngsummary.ts'), sourceFile)); .forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngsummary.ts'), sourceFile));
return new SummaryGenerator(map); return new SummaryGenerator(map);
} }

View File

@ -26,3 +26,8 @@ export function relativePathBetween(from: string, to: string): string|null {
return relative; return relative;
} }
export function normalizeSeparators(path: string): string {
// TODO: normalize path only for OS that need it.
return path.replace(/\\/g, '/');
}