Skip to content

Commit 7686a39

Browse files
authored
fix(core): fix solution tsconfig migration (#3312)
1 parent a6db5fa commit 7686a39

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

packages/workspace/src/migrations/update-10-0-0/solution-tsconfigs.spec.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ describe('Solution Tsconfigs Migration', () => {
2121
compilerOptions: {
2222
module: 'commonjs',
2323
},
24+
files: ['src/index.ts'],
25+
include: ['**/*.ts'],
26+
})),
27+
tree
28+
);
29+
tree = await callRule(
30+
updateJsonInTree('apps/app1/tsconfig.app.json', () => ({
31+
extends: './tsconfig.json',
32+
compilerOptions: {
33+
module: 'esnext',
34+
types: [],
35+
},
2436
})),
2537
tree
2638
);
@@ -30,6 +42,7 @@ describe('Solution Tsconfigs Migration', () => {
3042
compilerOptions: {
3143
module: 'esnext',
3244
},
45+
include: ['**/*.spec.ts'],
3346
})),
3447
tree
3548
);
@@ -62,10 +75,40 @@ describe('Solution Tsconfigs Migration', () => {
6275
files: [],
6376
include: [],
6477
references: [
78+
{
79+
path: './tsconfig.app.json',
80+
},
6581
{
6682
path: './tsconfig.spec.json',
6783
},
6884
],
6985
});
7086
});
87+
88+
it('should update tsconfig.app.json', async () => {
89+
const result = await runMigration('solution-tsconfigs', {}, tree);
90+
const json = readJsonInTree(result, 'apps/app1/tsconfig.app.json');
91+
expect(json).toEqual({
92+
extends: './tsconfig.json',
93+
compilerOptions: {
94+
module: 'esnext',
95+
types: [],
96+
},
97+
files: ['src/index.ts'],
98+
include: ['**/*.ts'],
99+
});
100+
});
101+
102+
it('should update tsconfig.spec.json', async () => {
103+
const result = await runMigration('solution-tsconfigs', {}, tree);
104+
const json = readJsonInTree(result, 'apps/app1/tsconfig.spec.json');
105+
expect(json).toEqual({
106+
extends: './tsconfig.json',
107+
compilerOptions: {
108+
module: 'esnext',
109+
},
110+
files: ['src/index.ts'],
111+
include: ['**/*.spec.ts'],
112+
});
113+
});
71114
});

packages/workspace/src/migrations/update-10-0-0/solution-tsconfigs.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,20 @@ function visitNotIgnoredFiles(
5353
}
5454

5555
function moveIncludesToProjectTsconfig(
56-
file: string,
56+
file: Path,
5757
extendedTsconfigPath: Path,
5858
extendedTsconfig: any
5959
) {
6060
return updateJsonInTree(file, (json) => {
6161
json.files =
6262
json.files ||
6363
extendedTsconfig.files?.map((p: string) =>
64-
relative(file, join(extendedTsconfigPath, p))
64+
relative(dirname(file), join(dirname(extendedTsconfigPath), p))
6565
);
6666
json.include =
6767
json.include ||
6868
extendedTsconfig.include?.map((p: string) =>
69-
relative(file, join(extendedTsconfigPath, p))
69+
relative(dirname(file), join(dirname(extendedTsconfigPath), p))
7070
);
7171
return json;
7272
});
@@ -105,6 +105,8 @@ function updateExtend(file: Path): Rule {
105105
});
106106
}
107107

108+
const originalExtendedTsconfigMap = new Map<string, any>();
109+
108110
export default function (schema: any): Rule {
109111
return chain([
110112
renameRootTsconfig,
@@ -122,7 +124,17 @@ export default function (schema: any): Rule {
122124
if (extendedTsconfigPath === normalize('tsconfig.json')) {
123125
return updateExtend(file);
124126
} else if (basename(json.extends) === 'tsconfig.json') {
125-
const extendedTsconfig = readJsonInTree(host, extendedTsconfigPath);
127+
let extendedTsconfig = originalExtendedTsconfigMap.get(
128+
extendedTsconfigPath
129+
);
130+
131+
if (!extendedTsconfig) {
132+
extendedTsconfig = readJsonInTree(host, extendedTsconfigPath);
133+
originalExtendedTsconfigMap.set(
134+
extendedTsconfigPath,
135+
extendedTsconfig
136+
);
137+
}
126138
return chain([
127139
moveIncludesToProjectTsconfig(
128140
file,

0 commit comments

Comments
 (0)