diff --git a/src/utils/get-rollup-configs.ts b/src/utils/get-rollup-configs.ts index e7b4127..b492ff7 100644 --- a/src/utils/get-rollup-configs.ts +++ b/src/utils/get-rollup-configs.ts @@ -49,6 +49,21 @@ const getConfig = { resolveTypescriptMjsCts(), dts.default({ respectExternal: true, + + /** + * https://github.com/privatenumber/pkgroll/pull/54 + * + * I think this is necessary because TypeScript's composite requires + * that all files are passed in via `include`. However, it seems that + * rollup-plugin-dts doesn't read or relay the `include` option in tsconfig. + * + * For now, simply disabling composite does the trick since it doesn't seem + * necessary for dts bundling. + * + * One concern here is that this overwrites the compilerOptions. According to + * the rollup-plugin-dts docs, it reads from baseUrl and paths. + */ + compilerOptions: { composite: false }, }) as Plugin, ], output: [] as unknown as Output, diff --git a/tests/specs/builds/output-types.ts b/tests/specs/builds/output-types.ts index aef5aa2..460f0ef 100644 --- a/tests/specs/builds/output-types.ts +++ b/tests/specs/builds/output-types.ts @@ -219,5 +219,80 @@ export default testSuite(({ describe }, nodePath: string) => { const content = await fixture.readFile('dist/dts.d.ts', 'utf8'); expect(content).toMatch('declare const'); }); + + test('composite monorepos', async ({ onTestFinish }) => { + const fixture = await createFixture({ + packages: { + one: { + 'package.json': JSON.stringify({ + name: '@org/one', + exports: { + types: './dist/index.d.mts', + }, + }), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + composite: true, + }, + include: [ + 'src/index.mts', + 'src/name.mts', + ], + }), + src: { + 'index.mts': 'export { Name } from "./name.mjs";', + 'name.mts': 'export type Name = string;', + }, + }, + two: { + 'package.json': JSON.stringify({ + main: './dist/index.mjs', + dependencies: { + '@org/one': 'workspace:*', + }, + }), + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + composite: true, + }, + include: ['src/index.mts'], + references: [{ path: '../one' }], + }), + 'src/index.mts': ` + import { Name } from '@org/one'; + export function sayHello(name: Name) { + console.log('Hello', name); + } + `, + }, + }, + 'tsconfig.json': JSON.stringify({ + resources: [ + { path: './packages/one' }, + { path: './packages/two' }, + ], + }), + 'package.json': JSON.stringify({ + workspaces: ['packages/*'], + }), + }); + onTestFinish(async () => await fixture.rm()); + + await installTypeScript(fixture.path); + + const pkgrollOne = await pkgroll([], { cwd: `${fixture.path}/packages/one`, nodePath }); + expect(pkgrollOne.exitCode).toBe(0); + expect(pkgrollOne.stderr).toBe(''); + + const contentOne = await fixture.readFile('packages/one/dist/index.d.mts', 'utf8'); + expect(contentOne).toMatch('export type { Name };'); + + const pkgrollTwo = await pkgroll([], { cwd: `${fixture.path}/packages/two`, nodePath }); + expect(pkgrollTwo.exitCode).toBe(0); + expect(pkgrollTwo.stderr).toBe(''); + + const contentTwo = await fixture.readFile('packages/two/dist/index.mjs', 'utf8'); + expect(contentTwo).toMatch('export { sayHello };'); + }); }); });