diff --git a/packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts b/packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts index 5a4d4e4f6d54..69614324ca5f 100644 --- a/packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts +++ b/packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts @@ -30,8 +30,8 @@ function getResourceData(resolveData: any): ResourceData { } = resolveData.createData.resourceResolveData; return { - packageName: descriptionFileData.name, - packageVersion: descriptionFileData.version, + packageName: descriptionFileData?.name, + packageVersion: descriptionFileData?.version, relativePath, resource, }; @@ -40,8 +40,8 @@ function getResourceData(resolveData: any): ResourceData { const { resource, resourceResolveData } = resolveData; return { - packageName: resourceResolveData.descriptionFileData.name, - packageVersion: resourceResolveData.descriptionFileData.version, + packageName: resourceResolveData.descriptionFileData?.name, + packageVersion: resourceResolveData.descriptionFileData?.version, relativePath: resourceResolveData.relativePath, resource: resource, }; 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'); }