Skip to content

Commit 1f979e9

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 1f979e9

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,23 @@ 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+
const tsConfigExists = host.exists('tsconfig.json');
39+
if (tsConfigExists) {
40+
const files = new JSONFile(host, 'tsconfig.json').get(['files']);
41+
if (!(Array.isArray(files) && files.length === 0)) {
42+
logger.info('Migration has already been executed.');
4143

42-
return;
44+
return;
45+
}
4346
}
4447

4548
if (host.exists('tsconfig.base.json')) {
46-
host.overwrite('tsconfig.json', host.read('tsconfig.base.json') || '');
47-
host.delete('tsconfig.base.json');
49+
if (tsConfigExists) {
50+
host.overwrite('tsconfig.json', host.read('tsconfig.base.json') || '');
51+
host.delete('tsconfig.base.json');
52+
} else {
53+
host.rename('tsconfig.base.json', 'tsconfig.json');
54+
}
4855
}
4956

5057
// Iterate over all tsconfig files and change the extends from 'tsconfig.base.json' to 'tsconfig.json'.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,12 @@ describe('Migration to remove "Solution Style" tsconfig', () => {
114114
expect(readJsonFile(newTree, 'src/tsconfig.spec.json').extends).toEqual('./../tsconfig.json');
115115
expect(logs.join('\n')).toContain('Failed to parse "/src/invalid/error.json" as JSON AST Object. InvalidSymbol at location: 43.');
116116
});
117+
118+
it(`should not error when 'tsconfig.json' doesn't exist`, async () => {
119+
tree.delete('tsconfig.json');
120+
const newTree = await schematicRunner.runSchematicAsync(schematicName, {}, tree).toPromise();
121+
122+
expect(readJsonFile(newTree, 'tsconfig.json')['compilerOptions']).toBeTruthy();
123+
expect(newTree.exists('tsconfig.base.json')).toBeFalse();
124+
});
117125
});

0 commit comments

Comments
 (0)