From eb370562b09ac8563f32388e500981e6f0df38a3 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Tue, 29 Sep 2020 09:33:55 +0200 Subject: [PATCH] fix(@angular-devkit/build-angular): handle undefined descriptionFileData Closes #18631 (cherry picked from commit 09cfb29c0747f82db105acf738246536ce3dc3c3) --- .../plugins/dedupe-module-resolve-plugin.ts | 2 +- tests/legacy-cli/e2e/tests/build/ts-paths.ts | 56 ++++++++++--------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.ts b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.ts index 5aeca7fd68e4..256aa3e0822d 100644 --- a/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.ts +++ b/packages/angular_devkit/build_angular/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.ts @@ -55,7 +55,7 @@ export class DedupeModuleResolvePlugin { const { descriptionFileData, relativePath } = resourceResolveData; // Empty name or versions are no valid primary entrypoints of a library - if (!descriptionFileData.name || !descriptionFileData.version) { + if (!descriptionFileData?.name || !descriptionFileData?.version) { return; } diff --git a/tests/legacy-cli/e2e/tests/build/ts-paths.ts b/tests/legacy-cli/e2e/tests/build/ts-paths.ts index d36d5818c822..51f80ba93a39 100644 --- a/tests/legacy-cli/e2e/tests/build/ts-paths.ts +++ b/tests/legacy-cli/e2e/tests/build/ts-paths.ts @@ -1,41 +1,42 @@ -import {updateTsConfig} from '../../utils/project'; -import {writeMultipleFiles, appendToFile, createDir, replaceInFile} from '../../utils/fs'; -import {ng} from '../../utils/process'; -import {stripIndents} from 'common-tags'; +import { stripIndents } from 'common-tags'; +import { appendToFile, createDir, replaceInFile, rimraf, writeMultipleFiles } from '../../utils/fs'; +import { ng } from '../../utils/process'; +import { updateTsConfig } from '../../utils/project'; - -export default function() { - // TODO(architect): Delete this test. It is now in devkit/build-angular. - - return updateTsConfig(json => { +export default async function () { + await updateTsConfig(json => { json['compilerOptions']['baseUrl'] = './src'; json['compilerOptions']['paths'] = { '@shared': [ - 'app/shared' + 'app/shared', ], '@shared/*': [ - 'app/shared/*' + 'app/shared/*', ], '@root/*': [ - './*' - ] + './*', + ], }; - }) - .then(() => createDir('src/app/shared')) - .then(() => writeMultipleFiles({ + }); + + await createDir('src/app/shared'); + await writeMultipleFiles({ 'src/meaning-too.ts': 'export var meaning = 42;', 'src/app/shared/meaning.ts': 'export var meaning = 42;', 'src/app/shared/index.ts': `export * from './meaning'`, - })) - .then(() => replaceInFile('src/app/app.module.ts', './app.component', '@root/app/app.component')) - .then(() => ng('build')) - .then(() => updateTsConfig(json => { + }); + + await replaceInFile('src/app/app.module.ts', './app.component', '@root/app/app.component'); + await ng('build'); + + await updateTsConfig(json => { json['compilerOptions']['paths']['*'] = [ '*', - 'app/shared/*' + 'app/shared/*', ]; - })) - .then(() => appendToFile('src/app/app.component.ts', stripIndents` + }); + + await appendToFile('src/app/app.component.ts', stripIndents` import { meaning } from 'app/shared/meaning'; import { meaning as meaning2 } from '@shared'; import { meaning as meaning3 } from '@shared/meaning'; @@ -49,6 +50,11 @@ export default function() { console.log(meaning3) console.log(meaning4) console.log(meaning5) - `)) - .then(() => ng('build')); + `); + + await ng('build'); + + // Simulate no package.json file which causes Webpack to have an undefined 'descriptionFileData'. + await rimraf('package.json'); + await ng('build'); }