Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support composite in tsconfig.json #55

Merged
merged 7 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/utils/get-rollup-configs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
async type(
options: Options,
) {
const dts = await import('rollup-plugin-dts');

Check warning on line 42 in src/utils/get-rollup-configs.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Maximum number of dependencies (15) exceeded

return {
input: [] as string[],
Expand All @@ -49,6 +49,21 @@
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 Expand Up @@ -117,7 +132,7 @@
[T in keyof GetConfig]?: Awaited<ReturnType<GetConfig[T]>>;
};

export async function getRollupConfigs(

Check warning on line 135 in src/utils/get-rollup-configs.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Async function 'getRollupConfigs' has too many parameters (6). Maximum allowed is 5
sourceDirectoryPath: string,
distributionDirectoryPath: string,
inputs: {
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 };');
});
});
});
Loading