Skip to content

Commit

Permalink
fix(extends): baseUrl that points to parent path (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Jun 16, 2022
1 parent c023357 commit a107c72
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/utils/read-tsconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function readTsconfig(
compilerOptions.baseUrl = path.relative(
directoryPath,
path.join(path.dirname(extendsPath), compilerOptions.baseUrl!),
);
) || './';
}

if (extendsConfig.files) {
Expand Down
6 changes: 3 additions & 3 deletions tests/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { describe } from 'manten';

describe('get-tsconfig', ({ runTestSuite }) => {
// runTestSuite(import('./specs/errors.spec'));
// runTestSuite(import('./specs/finds-config.spec'));
runTestSuite(import('./specs/errors.spec'));
runTestSuite(import('./specs/finds-config.spec'));
runTestSuite(import('./specs/extends.spec'));
// runTestSuite(import('./specs/paths.spec'));
runTestSuite(import('./specs/paths.spec'));
});
26 changes: 22 additions & 4 deletions tests/specs/extends.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,6 @@ export default testSuite(({ describe }) => {
const fixture = await createFixture({
'src-a': {
'a.ts': '',
'b.ts': '',
'c.ts': '',
},
'tsconfig.json': tsconfigJson({
compilerOptions: {
Expand All @@ -575,8 +573,6 @@ export default testSuite(({ describe }) => {
project: {
'src-a': {
'a.ts': '',
'b.ts': '',
'c.ts': '',
},
'tsconfig.json': tsconfigJson({
compilerOptions: {
Expand All @@ -597,6 +593,28 @@ export default testSuite(({ describe }) => {

await fixture.cleanup();
});

test('resolves parent baseUrl path', async () => {
const fixture = await createFixture({
'project/tsconfig.json': tsconfigJson({
compilerOptions: {
baseUrl: '..',
},
}),
'tsconfig.json': tsconfigJson({
extends: './project/tsconfig.json',
}),
'a.ts': '',
});

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

const tsconfig = getTsconfig(fixture.path);
expect(tsconfig!.config).toStrictEqual(expectedTsconfig);

await fixture.cleanup();
});
});

test('nested extends', async () => {
Expand Down
31 changes: 31 additions & 0 deletions tests/specs/paths.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,37 @@ export default testSuite(({ describe }) => {
]);
});

test('baseUrl from extends', async () => {
const fixture = await createFixture({
'some-dir/tsconfig.json': tsconfigJson({
compilerOptions: {
baseUrl: '..',
paths: {
$lib: [
'src/lib',
],
'$lib/*': [
'src/lib/*',
],
},
},
}),
'tsconfig.json': tsconfigJson({
extends: './some-dir/tsconfig.json',
}),
});

const tsconfig = getTsconfig(fixture.path);
expect(tsconfig).not.toBeNull();

const matcher = createPathsMatcher(tsconfig!)!;

expect(matcher).not.toBeNull();
expect(matcher('$lib')).toStrictEqual([
path.join(fixture.path, 'src/lib'),
]);
});

test('exact match', async () => {
const fixture = await createFixture({
'tsconfig.json': tsconfigJson({
Expand Down

0 comments on commit a107c72

Please sign in to comment.