Skip to content

Commit 8ea0967

Browse files
committed
fix(@schematics/angular): remove solution style throw an error
remove-solution-style-tsconfig migration fail when upgrading from version 10.0.* to 10.1.* with the following error: [error] Error: Could not read 'tsconfig.json'
1 parent 6e9c962 commit 8ea0967

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

packages/schematics/angular/migrations/update-10/remove-solution-style-tsconfig.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ export default function (): Rule {
3535
return (host, context) => {
3636
const logger = context.logger;
3737

38-
const files = new JSONFile(host, 'tsconfig.json').get(['files']);
39-
if (!(Array.isArray(files) && files.length === 0)) {
40-
logger.info('Migration has already been executed.');
38+
try {
39+
const files = new JSONFile(host, 'tsconfig.json').get(['files']);
4140

42-
return;
41+
if (!(Array.isArray(files) && files.length === 0)) {
42+
logger.info('Migration has already been executed.');
43+
44+
return;
45+
}
46+
} catch {
47+
host.create('tsconfig.json', '');
4348
}
4449

4550
if (host.exists('tsconfig.base.json')) {

packages/schematics/angular/migrations/update-10/remove-solution-style-tsconfig_spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ describe('Migration to remove "Solution Style" tsconfig', () => {
7070

7171
// Create tsconfigs
7272
const compilerOptions = { target: 'es2015' };
73-
createJsonFile(tree, 'tsconfig.json', { files: [] });
7473
createJsonFile(tree, 'tsconfig.base.json', { compilerOptions });
7574
createJsonFile(tree, 'tsconfig.common.json', { compilerOptions });
7675
createJsonFile(tree, 'src/tsconfig.json', { extends: './../tsconfig.base.json', compilerOptions });
@@ -82,9 +81,13 @@ describe('Migration to remove "Solution Style" tsconfig', () => {
8281
});
8382

8483
it(`should rename 'tsconfig.base.json' to 'tsconfig.json'`, async () => {
84+
const logs: string[] = [];
85+
schematicRunner.logger.subscribe((m) => logs.push(m.message));
86+
8587
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
8688
expect(readJsonFile(newTree, 'tsconfig.json')['compilerOptions']).toBeTruthy();
8789
expect(newTree.exists('tsconfig.base.json')).toBeFalse();
90+
expect(logs.join('\n')).toEqual('');
8891
});
8992

9093
it(`should update extends from 'tsconfig.base.json' to 'tsconfig.json'`, async () => {

0 commit comments

Comments
 (0)