Skip to content

Commit b3bceef

Browse files
fix: allow extends array to have common dependency (#68)
Co-authored-by: Hiroki Osame <hiroki.osame@gmail.com>
1 parent 33d4f81 commit b3bceef

File tree

3 files changed

+67
-22
lines changed

3 files changed

+67
-22
lines changed

src/parse-tsconfig/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const _parseTsconfig = (
133133
const extendsConfig = resolveExtends(
134134
extendsPath,
135135
directoryPath,
136-
circularExtendsTracker,
136+
new Set(circularExtendsTracker),
137137
cache,
138138
);
139139
const merged = {

tests/specs/parse-tsconfig/extends/resolves/index.ts

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import path from 'path';
22
import { testSuite, expect } from 'manten';
33
import { createFixture } from 'fs-fixture';
4-
import { createTsconfigJson } from '../../../../utils.js';
4+
import { createTsconfigJson, getTscTsconfig } from '../../../../utils.js';
55
import { parseTsconfig } from '#get-tsconfig';
66

77
export default testSuite(({ describe }) => {
8-
describe('resolves', ({ test, runTestSuite }) => {
8+
describe('resolves', ({ test, describe, runTestSuite }) => {
99
test('handles missing extends', async () => {
1010
const fixture = await createFixture({
1111
'file.ts': '',
@@ -21,6 +21,70 @@ export default testSuite(({ describe }) => {
2121
await fixture.rm();
2222
});
2323

24+
describe('circularity', ({ test }) => {
25+
test('self extend', async ({ onTestFinish }) => {
26+
const fixture = await createFixture({
27+
'tsconfig.json': createTsconfigJson({
28+
extends: './tsconfig.json',
29+
}),
30+
'file.ts': '',
31+
});
32+
onTestFinish(() => fixture.rm());
33+
34+
const errorMessage = 'Circularity detected while resolving configuration';
35+
await expect(
36+
getTscTsconfig(fixture.path),
37+
).rejects.toThrow(errorMessage);
38+
expect(
39+
() => parseTsconfig(path.join(fixture.path, 'tsconfig.json')),
40+
).toThrow(errorMessage);
41+
42+
await fixture.rm();
43+
});
44+
45+
test('recursive', async ({ onTestFinish }) => {
46+
const fixture = await createFixture({
47+
'base.json': createTsconfigJson({
48+
extends: './tsconfig.json',
49+
}),
50+
'tsconfig.json': createTsconfigJson({
51+
extends: './base.json',
52+
}),
53+
});
54+
onTestFinish(() => fixture.rm());
55+
56+
expect(
57+
() => parseTsconfig(path.join(fixture.path, 'tsconfig.json')),
58+
).toThrow('Circularity detected while resolving configuration:');
59+
});
60+
});
61+
62+
test('extends array with common base', async ({ onTestFinish }) => {
63+
const fixture = await createFixture({
64+
'base.json': createTsconfigJson({}),
65+
'tsconfig-b.json': createTsconfigJson({
66+
extends: './base.json',
67+
}),
68+
'tsconfig-a.json': createTsconfigJson({
69+
extends: './base.json',
70+
}),
71+
'tsconfig.json': createTsconfigJson({
72+
extends: [
73+
'./tsconfig-a.json',
74+
'./tsconfig-b.json',
75+
],
76+
}),
77+
'file.ts': '',
78+
});
79+
onTestFinish(() => fixture.rm());
80+
81+
const expectedTsconfig = await getTscTsconfig(fixture.path);
82+
delete expectedTsconfig.files;
83+
84+
const tsconfig = parseTsconfig(path.join(fixture.path, 'tsconfig.json'));
85+
expect(tsconfig).toStrictEqual(expectedTsconfig);
86+
});
87+
2488
runTestSuite(import('./relative-path.spec.js'));
2589
runTestSuite(import('./absolute-path.spec.js'));
2690
runTestSuite(import('./node-modules.spec.js'));

tests/specs/parse-tsconfig/extends/resolves/relative-path.spec.ts

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,5 @@ export default testSuite(({ describe }) => {
190190

191191
await fixture.rm();
192192
});
193-
194-
test('circular extends', async () => {
195-
const fixture = await createFixture({
196-
'tsconfig.json': createTsconfigJson({
197-
extends: './tsconfig.json',
198-
}),
199-
'file.ts': '',
200-
});
201-
202-
const errorMessage = 'Circularity detected while resolving configuration';
203-
await expect(
204-
getTscTsconfig(fixture.path),
205-
).rejects.toThrow(errorMessage);
206-
expect(
207-
() => parseTsconfig(path.join(fixture.path, 'tsconfig.json')),
208-
).toThrow(errorMessage);
209-
210-
await fixture.rm();
211-
});
212193
});
213194
});

0 commit comments

Comments
 (0)