Skip to content

Commit

Permalink
fix: support composite in tsconfig.json (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: Austin Ziegler <[email protected]>
  • Loading branch information
privatenumber and halostatue authored Mar 7, 2024
1 parent dcec5fe commit 743f26f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/utils/get-rollup-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
75 changes: 75 additions & 0 deletions tests/specs/builds/output-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };');
});
});
});

0 comments on commit 743f26f

Please sign in to comment.