From 9537b2ff8459c445f05545520e3076ab1b5c2bbd Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 5 Aug 2019 23:12:58 +0300 Subject: [PATCH] refactor(ivy): ngcc - fix return type on `makeEntryPointBundle()` (#32052) In commit 7b55ba58b (part of PR #29092), the implementation of `makeEntryPointBundle()` was changed such that it now always return `EntryPointBundle` (and not `null`). However, the return type was not updated and as result we continued to unnecessarily handle `null` as a potential return value in some places. This commit fixes the return type to reflect the implementation and removes the redundant code that was dealing with `null`. PR Close #32052 --- packages/compiler-cli/ngcc/src/main.ts | 27 ++++++++----------- .../ngcc/src/packages/entry_point_bundle.ts | 4 +-- .../test/packages/entry_point_bundle_spec.ts | 6 ++--- .../new_entry_point_file_writer_spec.ts | 2 +- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/packages/compiler-cli/ngcc/src/main.ts b/packages/compiler-cli/ngcc/src/main.ts index 4868c0bb8c..2b78f893b0 100644 --- a/packages/compiler-cli/ngcc/src/main.ts +++ b/packages/compiler-cli/ngcc/src/main.ts @@ -134,24 +134,19 @@ export function mainNgcc( fileSystem, entryPoint, formatPath, isCore, property, format, processDts, pathMappings, true); - if (bundle) { - logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`); - const transformedFiles = transformer.transform(bundle); - fileWriter.writeBundle(entryPoint, bundle, transformedFiles); - compiledFormats.add(formatPath); + logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`); + const transformedFiles = transformer.transform(bundle); + fileWriter.writeBundle(entryPoint, bundle, transformedFiles); + compiledFormats.add(formatPath); - const propsToMarkAsProcessed = pathToPropsMap.get(formatPath) !; - if (processDts) { - propsToMarkAsProcessed.push('typings'); - processDts = false; - } - - markAsProcessed( - fileSystem, entryPointPackageJson, entryPointPackageJsonPath, propsToMarkAsProcessed); - } else { - logger.warn( - `Skipping ${entryPoint.name} : ${format} (no valid entry point file for this format).`); + const propsToMarkAsProcessed = pathToPropsMap.get(formatPath) !; + if (processDts) { + propsToMarkAsProcessed.push('typings'); + processDts = false; } + + markAsProcessed( + fileSystem, entryPointPackageJson, entryPointPackageJsonPath, propsToMarkAsProcessed); } } diff --git a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts index 18229512dd..b623011f44 100644 --- a/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts +++ b/packages/compiler-cli/ngcc/src/packages/entry_point_bundle.ts @@ -44,7 +44,7 @@ export interface EntryPointBundle { export function makeEntryPointBundle( fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean, formatProperty: EntryPointJsonProperty, format: EntryPointFormat, transformDts: boolean, - pathMappings?: PathMappings, mirrorDtsFromSrc: boolean = false): EntryPointBundle|null { + pathMappings?: PathMappings, mirrorDtsFromSrc: boolean = false): EntryPointBundle { // Create the TS program and necessary helpers. const options: ts.CompilerOptions = { allowJs: true, @@ -88,4 +88,4 @@ function computePotentialDtsFilesFromJsFiles( } } return additionalFiles; -} \ No newline at end of file +} diff --git a/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts b/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts index ee137b809f..d3594c1e76 100644 --- a/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts +++ b/packages/compiler-cli/ngcc/test/packages/entry_point_bundle_spec.ts @@ -145,7 +145,7 @@ runInEachFileSystem(() => { compiledByAngular: true, }; const esm5bundle = - makeEntryPointBundle(fs, entryPoint, './index.js', false, 'esm5', 'esm5', true) !; + makeEntryPointBundle(fs, entryPoint, './index.js', false, 'esm5', 'esm5', true); expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) .toEqual(jasmine.arrayWithExactContents([ @@ -193,7 +193,7 @@ runInEachFileSystem(() => { }; const esm5bundle = makeEntryPointBundle( fs, entryPoint, './index.js', false, 'esm5', 'esm5', /* transformDts */ true, - /* pathMappings */ undefined, /* mirrorDtsFromSrc */ true) !; + /* pathMappings */ undefined, /* mirrorDtsFromSrc */ true); expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) .toContain(absoluteFrom('/node_modules/test/internal.js')); expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName)) @@ -214,7 +214,7 @@ runInEachFileSystem(() => { }; const esm5bundle = makeEntryPointBundle( fs, entryPoint, './index.js', false, 'esm5', 'esm5', /* transformDts */ true, - /* pathMappings */ undefined, /* mirrorDtsFromSrc */ false) !; + /* pathMappings */ undefined, /* mirrorDtsFromSrc */ false); expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName)) .toContain(absoluteFrom('/node_modules/test/internal.js')); expect(esm5bundle.dts !.program.getSourceFiles().map(sf => sf.fileName)) diff --git a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts index 1432feea32..443d618d85 100644 --- a/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts +++ b/packages/compiler-cli/ngcc/test/writing/new_entry_point_file_writer_spec.ts @@ -357,6 +357,6 @@ runInEachFileSystem(() => { format: EntryPointFormat): EntryPointBundle { return makeEntryPointBundle( fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, formatProperty, format, - true) !; + true); } });