Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): handle undefined descriptionFileData
Browse files Browse the repository at this point in the history
Closes #18631

(cherry picked from commit 09cfb29)
  • Loading branch information
alan-agius4 committed Sep 29, 2020
1 parent 0b7dc58 commit eb37056
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
Expand Up @@ -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;
}

Expand Down
56 changes: 31 additions & 25 deletions 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';
Expand All @@ -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');
}

0 comments on commit eb37056

Please sign in to comment.