From 94297140baece9d753434f98734e4bde7222ca7f Mon Sep 17 00:00:00 2001 From: yinz Date: Thu, 24 Oct 2024 14:45:58 +0800 Subject: [PATCH] fix: generate types when using custom tsconfig path. (#99) --- src/utils/get-rollup-configs.ts | 1 + tests/specs/builds/output-types.ts | 32 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/utils/get-rollup-configs.ts b/src/utils/get-rollup-configs.ts index ce254c5..bf11abe 100644 --- a/src/utils/get-rollup-configs.ts +++ b/src/utils/get-rollup-configs.ts @@ -80,6 +80,7 @@ const getConfig = { module: ts.default.ModuleKind.Preserve, moduleResolution: ts.default.ModuleResolutionKind.Bundler, }, + tsconfig: tsconfig?.path, }) as Plugin, ], output: [] as unknown as Output, diff --git a/tests/specs/builds/output-types.ts b/tests/specs/builds/output-types.ts index 11a9e95..151e528 100644 --- a/tests/specs/builds/output-types.ts +++ b/tests/specs/builds/output-types.ts @@ -450,5 +450,37 @@ export default testSuite(({ describe }, nodePath: string) => { expect(types).toMatch('\'dep-a\''); expect(types).toMatch('.data'); }); + + test('custom tsconfig.json path', async () => { + await using fixture = await createFixture({ + ...packageFixture({ + installTypeScript: true, + installReact: true, + }), + 'package.json': createPackageJson({ + types: './dist/component.d.ts', + peerDependencies: { + react: '*', + }, + }), + 'tsconfig.custom.json': createTsconfigJson({ + compilerOptions: { + jsx: 'react-jsx', + }, + }), + }); + + const pkgrollProcess = await pkgroll(['-p', 'tsconfig.custom.json'], { + cwd: fixture.path, + nodePath, + }); + + expect(pkgrollProcess.exitCode).toBe(0); + expect(pkgrollProcess.stderr).toBe(''); + + const content = await fixture.readFile('dist/component.d.ts', 'utf8'); + expect(content).toMatch('declare const Component: () => react_jsx_runtime.JSX.Element'); + expect(content).toMatch('export { Component }'); + }); }); });