From 03293c4fec978e0dd7bb5b748e99e42d78380d87 Mon Sep 17 00:00:00 2001 From: Alan Date: Wed, 16 Jan 2019 07:54:39 +0100 Subject: [PATCH] fix(ivy): normalize summary and factory shim files paths (#28173) 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 #28173 --- .../compiler-cli/src/ngtsc/shims/src/factory_generator.ts | 3 ++- .../compiler-cli/src/ngtsc/shims/src/summary_generator.ts | 3 +++ packages/compiler-cli/src/ngtsc/util/src/path.ts | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts index 90829bbaac..d8b94c4e54 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/factory_generator.ts @@ -9,7 +9,7 @@ import * as path from 'path'; import * as ts from 'typescript'; -import {relativePathBetween} from '../../util/src/path'; +import {normalizeSeparators, relativePathBetween} from '../../util/src/path'; import {ShimGenerator} from './host'; import {generatedModuleName, isNonDeclarationTsFile} from './util'; @@ -88,6 +88,7 @@ export class FactoryGenerator implements ShimGenerator { static forRootFiles(files: ReadonlyArray): FactoryGenerator { const map = new Map(); files.filter(sourceFile => isNonDeclarationTsFile(sourceFile)) + .map(sourceFile => normalizeSeparators(sourceFile)) .forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngfactory.ts'), sourceFile)); return new FactoryGenerator(map); } diff --git a/packages/compiler-cli/src/ngtsc/shims/src/summary_generator.ts b/packages/compiler-cli/src/ngtsc/shims/src/summary_generator.ts index 158f0fdba6..5fa103f940 100644 --- a/packages/compiler-cli/src/ngtsc/shims/src/summary_generator.ts +++ b/packages/compiler-cli/src/ngtsc/shims/src/summary_generator.ts @@ -8,6 +8,8 @@ import * as ts from 'typescript'; +import {normalizeSeparators} from '../../util/src/path'; + import {ShimGenerator} from './host'; import {generatedModuleName, isNonDeclarationTsFile} from './util'; @@ -62,6 +64,7 @@ export class SummaryGenerator implements ShimGenerator { static forRootFiles(files: ReadonlyArray): SummaryGenerator { const map = new Map(); files.filter(sourceFile => isNonDeclarationTsFile(sourceFile)) + .map(sourceFile => normalizeSeparators(sourceFile)) .forEach(sourceFile => map.set(sourceFile.replace(/\.ts$/, '.ngsummary.ts'), sourceFile)); return new SummaryGenerator(map); } diff --git a/packages/compiler-cli/src/ngtsc/util/src/path.ts b/packages/compiler-cli/src/ngtsc/util/src/path.ts index 4c5d11c55f..fc8300f017 100644 --- a/packages/compiler-cli/src/ngtsc/util/src/path.ts +++ b/packages/compiler-cli/src/ngtsc/util/src/path.ts @@ -26,3 +26,8 @@ export function relativePathBetween(from: string, to: string): string|null { return relative; } + +export function normalizeSeparators(path: string): string { + // TODO: normalize path only for OS that need it. + return path.replace(/\\/g, '/'); +}