diff --git a/src/parse-tsconfig/resolve-extends-path.ts b/src/parse-tsconfig/resolve-extends-path.ts index b59939d..50656bd 100644 --- a/src/parse-tsconfig/resolve-extends-path.ts +++ b/src/parse-tsconfig/resolve-extends-path.ts @@ -144,7 +144,7 @@ export const resolveExtendsPath = ( } const packagePath = findUp( - directoryPath, + path.resolve(directoryPath), path.join('node_modules', packageName), cache, ); diff --git a/tests/specs/parse-tsconfig/extends/resolves/node-modules.spec.ts b/tests/specs/parse-tsconfig/extends/resolves/node-modules.spec.ts index d395e9b..ceae549 100644 --- a/tests/specs/parse-tsconfig/extends/resolves/node-modules.spec.ts +++ b/tests/specs/parse-tsconfig/extends/resolves/node-modules.spec.ts @@ -348,6 +348,44 @@ export default testSuite(({ describe }) => { expect(tsconfig).toStrictEqual(expectedTsconfig); }); + // https://github.com/privatenumber/get-tsconfig/issues/76 + test('resolves config in parent node_modules', async () => { + await using fixture = await createFixture({ + library: { + src: { + 'a.ts': '', + 'b.ts': '', + 'c.ts': '', + }, + 'tsconfig.json': createTsconfigJson({ + extends: '@monorepo/tsconfig/tsconfig.base.json', + include: ['src'], + }), + }, + + 'node_modules/@monorepo/tsconfig': { + 'tsconfig.base.json': createTsconfigJson({ + compilerOptions: { + module: 'commonjs', + }, + }), + }, + }); + + const originalCwd = process.cwd(); + try { + process.chdir(fixture.getPath('library')); + const expectedTsconfig = await getTscTsconfig('.'); + delete expectedTsconfig.files; + + const tsconfig = parseTsconfig('./tsconfig.json'); + + expect(tsconfig).toStrictEqual(expectedTsconfig); + } finally { + process.chdir(originalCwd); + } + }); + describe('package.json#tsconfig', ({ test }) => { test('package.json#tsconfig', async () => { await using fixture = await createFixture({