From e8041431830b194c3d686cc39db306a95faafed8 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 15 Oct 2018 17:08:44 +0100 Subject: [PATCH] perf(ivy): ngcc - use flat file for dependency sorting if available (#26403) Previously we always used the non-flat format because we thought that this was the one that would always be available. It turns out that this is not the case and that only one of the flat and non-flat formats may be available. Therefore we should use whichever is available, defaulting to the flat format if that exists, since that will be faster to parse. PR Close #26403 --- .../ngcc/src/packages/dependency_resolver.ts | 5 +++-- .../test/packages/dependency_resolver_spec.ts | 17 +++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/compiler-cli/src/ngcc/src/packages/dependency_resolver.ts b/packages/compiler-cli/src/ngcc/src/packages/dependency_resolver.ts index b825553c33..49f23f8c80 100644 --- a/packages/compiler-cli/src/ngcc/src/packages/dependency_resolver.ts +++ b/packages/compiler-cli/src/ngcc/src/packages/dependency_resolver.ts @@ -79,9 +79,10 @@ export class DependencyResolver { // Now add the dependencies between them entryPoints.forEach(entryPoint => { - const entryPointPath = entryPoint.esm2015; + const entryPointPath = entryPoint.fesm2015 || entryPoint.esm2015; if (!entryPointPath) { - throw new Error(`Esm2015 format missing in '${entryPoint.path}' entry-point.`); + throw new Error( + `ESM2015 format (flat and non-flat) missing in '${entryPoint.path}' entry-point.`); } const dependencies = new Set(); diff --git a/packages/compiler-cli/src/ngcc/test/packages/dependency_resolver_spec.ts b/packages/compiler-cli/src/ngcc/test/packages/dependency_resolver_spec.ts index f534f36da5..7570f32311 100644 --- a/packages/compiler-cli/src/ngcc/test/packages/dependency_resolver_spec.ts +++ b/packages/compiler-cli/src/ngcc/test/packages/dependency_resolver_spec.ts @@ -10,7 +10,7 @@ import {DependencyHost} from '../../src/packages/dependency_host'; import {DependencyResolver} from '../../src/packages/dependency_resolver'; import {EntryPoint} from '../../src/packages/entry_point'; -describe('DepencencyResolver', () => { +describe('DependencyResolver', () => { let host: DependencyHost; let resolver: DependencyResolver; beforeEach(() => { @@ -18,11 +18,11 @@ describe('DepencencyResolver', () => { resolver = new DependencyResolver(host); }); describe('sortEntryPointsByDependency()', () => { - const first = { path: 'first', esm2015: 'first/index.ts' } as EntryPoint; + const first = { path: 'first', fesm2015: 'first/index.ts' } as EntryPoint; const second = { path: 'second', esm2015: 'second/index.ts' } as EntryPoint; - const third = { path: 'third', esm2015: 'third/index.ts' } as EntryPoint; + const third = { path: 'third', fesm2015: 'third/index.ts' } as EntryPoint; const fourth = { path: 'fourth', esm2015: 'fourth/index.ts' } as EntryPoint; - const fifth = { path: 'fifth', esm2015: 'fifth/index.ts' } as EntryPoint; + const fifth = { path: 'fifth', fesm2015: 'fifth/index.ts' } as EntryPoint; const dependencies = { 'first/index.ts': {resolved: ['second', 'third', 'ignored-1'], missing: []}, @@ -80,10 +80,11 @@ describe('DepencencyResolver', () => { ]); }); - it('should error if the entry point does not have the esm2015 format', () => { - expect(() => resolver.sortEntryPointsByDependency([{ path: 'first' } as EntryPoint])) - .toThrowError(`Esm2015 format missing in 'first' entry-point.`); - }); + it('should error if the entry point does not have either the fesm2015 nor esm2015 formats', + () => { + expect(() => resolver.sortEntryPointsByDependency([{ path: 'first' } as EntryPoint])) + .toThrowError(`ESM2015 format (flat and non-flat) missing in 'first' entry-point.`); + }); it('should capture any dependencies that were ignored', () => { spyOn(host, 'computeDependencies').and.callFake(createFakeComputeDependencies(dependencies));