Skip to content

Commit

Permalink
fix: allow extends array to have common dependency (#68)
Browse files Browse the repository at this point in the history
Co-authored-by: Hiroki Osame <[email protected]>
  • Loading branch information
13OnTheCode and privatenumber authored Mar 7, 2024
1 parent 33d4f81 commit b3bceef
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/parse-tsconfig/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const _parseTsconfig = (
const extendsConfig = resolveExtends(
extendsPath,
directoryPath,
circularExtendsTracker,
new Set(circularExtendsTracker),
cache,
);
const merged = {
Expand Down
68 changes: 66 additions & 2 deletions tests/specs/parse-tsconfig/extends/resolves/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'path';
import { testSuite, expect } from 'manten';
import { createFixture } from 'fs-fixture';
import { createTsconfigJson } from '../../../../utils.js';
import { createTsconfigJson, getTscTsconfig } from '../../../../utils.js';
import { parseTsconfig } from '#get-tsconfig';

export default testSuite(({ describe }) => {
describe('resolves', ({ test, runTestSuite }) => {
describe('resolves', ({ test, describe, runTestSuite }) => {
test('handles missing extends', async () => {
const fixture = await createFixture({
'file.ts': '',
Expand All @@ -21,6 +21,70 @@ export default testSuite(({ describe }) => {
await fixture.rm();
});

describe('circularity', ({ test }) => {
test('self extend', async ({ onTestFinish }) => {
const fixture = await createFixture({
'tsconfig.json': createTsconfigJson({
extends: './tsconfig.json',
}),
'file.ts': '',
});
onTestFinish(() => fixture.rm());

const errorMessage = 'Circularity detected while resolving configuration';
await expect(
getTscTsconfig(fixture.path),
).rejects.toThrow(errorMessage);
expect(
() => parseTsconfig(path.join(fixture.path, 'tsconfig.json')),
).toThrow(errorMessage);

await fixture.rm();
});

test('recursive', async ({ onTestFinish }) => {
const fixture = await createFixture({
'base.json': createTsconfigJson({
extends: './tsconfig.json',
}),
'tsconfig.json': createTsconfigJson({
extends: './base.json',
}),
});
onTestFinish(() => fixture.rm());

expect(
() => parseTsconfig(path.join(fixture.path, 'tsconfig.json')),
).toThrow('Circularity detected while resolving configuration:');
});
});

test('extends array with common base', async ({ onTestFinish }) => {
const fixture = await createFixture({
'base.json': createTsconfigJson({}),
'tsconfig-b.json': createTsconfigJson({
extends: './base.json',
}),
'tsconfig-a.json': createTsconfigJson({
extends: './base.json',
}),
'tsconfig.json': createTsconfigJson({
extends: [
'./tsconfig-a.json',
'./tsconfig-b.json',
],
}),
'file.ts': '',
});
onTestFinish(() => fixture.rm());

const expectedTsconfig = await getTscTsconfig(fixture.path);
delete expectedTsconfig.files;

const tsconfig = parseTsconfig(path.join(fixture.path, 'tsconfig.json'));
expect(tsconfig).toStrictEqual(expectedTsconfig);
});

runTestSuite(import('./relative-path.spec.js'));
runTestSuite(import('./absolute-path.spec.js'));
runTestSuite(import('./node-modules.spec.js'));
Expand Down
19 changes: 0 additions & 19 deletions tests/specs/parse-tsconfig/extends/resolves/relative-path.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,24 +190,5 @@ export default testSuite(({ describe }) => {

await fixture.rm();
});

test('circular extends', async () => {
const fixture = await createFixture({
'tsconfig.json': createTsconfigJson({
extends: './tsconfig.json',
}),
'file.ts': '',
});

const errorMessage = 'Circularity detected while resolving configuration';
await expect(
getTscTsconfig(fixture.path),
).rejects.toThrow(errorMessage);
expect(
() => parseTsconfig(path.join(fixture.path, 'tsconfig.json')),
).toThrow(errorMessage);

await fixture.rm();
});
});
});

0 comments on commit b3bceef

Please sign in to comment.