fix(ivy): ngtsc is unable to detect flat module entry-point on windows (#29453)

Currently when building an Angular project with `ngtsc`
and `flatModuleOutFile` enabled, the Ngtsc build will fail
if there are multiple source files as root file names.

Ngtsc and NGC currently determine the entry-point for multiple
root file names by looking for files ending with `/index.ts`.

This functionality is technically deprecated, but still supported
and currently breaks on Windows as the root file names are not
guaranteed to be normalized POSIX-like paths.

In order to make this logic more reliable in the future, this commit
also switches the shim generators and entry-point logic to the branded
path types. This ensures that we don't break this in the future.

PR Close #29453
This commit is contained in:
Paul Gschwendtner
2019-03-26 23:39:12 +01:00
committed by Miško Hevery
parent e57ed61448
commit 1e5a818719
10 changed files with 67 additions and 37 deletions

View File

@ -65,6 +65,7 @@ export class NgtscProgram implements api.Program {
this.closureCompilerEnabled = !!options.annotateForClosureCompiler;
this.resourceManager = new HostResourceLoader(host, options);
const shouldGenerateShims = options.allowEmptyCodegenFiles || false;
const normalizedRootNames = rootNames.map(n => AbsoluteFsPath.from(n));
this.host = host;
if (host.fileNameToModuleName !== undefined) {
this.fileToModuleHost = host as FileToModuleHost;
@ -74,10 +75,10 @@ export class NgtscProgram implements api.Program {
const generators: ShimGenerator[] = [];
if (shouldGenerateShims) {
// Summary generation.
const summaryGenerator = SummaryGenerator.forRootFiles(rootNames);
const summaryGenerator = SummaryGenerator.forRootFiles(normalizedRootNames);
// Factory generation.
const factoryGenerator = FactoryGenerator.forRootFiles(rootNames);
const factoryGenerator = FactoryGenerator.forRootFiles(normalizedRootNames);
const factoryFileMap = factoryGenerator.factoryFileMap;
this.factoryToSourceInfo = new Map<string, FactoryInfo>();
this.sourceToFactorySymbols = new Map<string, Set<string>>();
@ -94,7 +95,7 @@ export class NgtscProgram implements api.Program {
let entryPoint: string|null = null;
if (options.flatModuleOutFile !== undefined) {
entryPoint = findFlatIndexEntryPoint(rootNames);
entryPoint = findFlatIndexEntryPoint(normalizedRootNames);
if (entryPoint === null) {
// This error message talks specifically about having a single .ts file in "files". However
// the actual logic is a bit more permissive. If a single file exists, that will be taken,