Skip to content

Commit 5e293f0

Browse files
committed
fix(@angular-devkit/build-angular): handle undefined descriptionFileData
Closes #18631
1 parent 38023fe commit 5e293f0

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

packages/angular_devkit/build_angular/src/webpack/plugins/dedupe-module-resolve-plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ function getResourceData(resolveData: any): ResourceData {
3030
} = resolveData.createData.resourceResolveData;
3131

3232
return {
33-
packageName: descriptionFileData.name,
34-
packageVersion: descriptionFileData.version,
33+
packageName: descriptionFileData?.name,
34+
packageVersion: descriptionFileData?.version,
3535
relativePath,
3636
resource,
3737
};
@@ -40,8 +40,8 @@ function getResourceData(resolveData: any): ResourceData {
4040
const { resource, resourceResolveData } = resolveData;
4141

4242
return {
43-
packageName: resourceResolveData.descriptionFileData.name,
44-
packageVersion: resourceResolveData.descriptionFileData.version,
43+
packageName: resourceResolveData.descriptionFileData?.name,
44+
packageVersion: resourceResolveData.descriptionFileData?.version,
4545
relativePath: resourceResolveData.relativePath,
4646
resource: resource,
4747
};
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)