Skip to content

Commit eb37056

Browse files
committed
fix(@angular-devkit/build-angular): handle undefined descriptionFileData
Closes #18631 (cherry picked from commit 09cfb29)
1 parent 0b7dc58 commit eb37056

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

packages/angular_devkit/build_angular/src/angular-cli-files/plugins/dedupe-module-resolve-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class DedupeModuleResolvePlugin {
5555
const { descriptionFileData, relativePath } = resourceResolveData;
5656

5757
// Empty name or versions are no valid primary entrypoints of a library
58-
if (!descriptionFileData.name || !descriptionFileData.version) {
58+
if (!descriptionFileData?.name || !descriptionFileData?.version) {
5959
return;
6060
}
6161

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
import {updateTsConfig} from '../../utils/project';
2-
import {writeMultipleFiles, appendToFile, createDir, replaceInFile} from '../../utils/fs';
3-
import {ng} from '../../utils/process';
4-
import {stripIndents} from 'common-tags';
1+
import { stripIndents } from 'common-tags';
2+
import { appendToFile, createDir, replaceInFile, rimraf, writeMultipleFiles } from '../../utils/fs';
3+
import { ng } from '../../utils/process';
4+
import { updateTsConfig } from '../../utils/project';
55

6-
7-
export default function() {
8-
// TODO(architect): Delete this test. It is now in devkit/build-angular.
9-
10-
return updateTsConfig(json => {
6+
export default async function () {
7+
await updateTsConfig(json => {
118
json['compilerOptions']['baseUrl'] = './src';
129
json['compilerOptions']['paths'] = {
1310
'@shared': [
14-
'app/shared'
11+
'app/shared',
1512
],
1613
'@shared/*': [
17-
'app/shared/*'
14+
'app/shared/*',
1815
],
1916
'@root/*': [
20-
'./*'
21-
]
17+
'./*',
18+
],
2219
};
23-
})
24-
.then(() => createDir('src/app/shared'))
25-
.then(() => writeMultipleFiles({
20+
});
21+
22+
await createDir('src/app/shared');
23+
await writeMultipleFiles({
2624
'src/meaning-too.ts': 'export var meaning = 42;',
2725
'src/app/shared/meaning.ts': 'export var meaning = 42;',
2826
'src/app/shared/index.ts': `export * from './meaning'`,
29-
}))
30-
.then(() => replaceInFile('src/app/app.module.ts', './app.component', '@root/app/app.component'))
31-
.then(() => ng('build'))
32-
.then(() => updateTsConfig(json => {
27+
});
28+
29+
await replaceInFile('src/app/app.module.ts', './app.component', '@root/app/app.component');
30+
await ng('build');
31+
32+
await updateTsConfig(json => {
3333
json['compilerOptions']['paths']['*'] = [
3434
'*',
35-
'app/shared/*'
35+
'app/shared/*',
3636
];
37-
}))
38-
.then(() => appendToFile('src/app/app.component.ts', stripIndents`
37+
});
38+
39+
await appendToFile('src/app/app.component.ts', stripIndents`
3940
import { meaning } from 'app/shared/meaning';
4041
import { meaning as meaning2 } from '@shared';
4142
import { meaning as meaning3 } from '@shared/meaning';
@@ -49,6 +50,11 @@ export default function() {
4950
console.log(meaning3)
5051
console.log(meaning4)
5152
console.log(meaning5)
52-
`))
53-
.then(() => ng('build'));
53+
`);
54+
55+
await ng('build');
56+
57+
// Simulate no package.json file which causes Webpack to have an undefined 'descriptionFileData'.
58+
await rimraf('package.json');
59+
await ng('build');
5460
}

0 commit comments

Comments
 (0)