From ddaf77b109f678d1bd0a2c2929a636fade391324 Mon Sep 17 00:00:00 2001 From: Petr Plenkov Date: Mon, 9 Jun 2025 11:41:49 +0200 Subject: [PATCH] feat(bundling): use tsconfig.lib.json for rollup.config.ts (#30453) ## Current Behavior Currently when we're using `rollup.config.ts` rollup is picking up wrong tsconfig. Because of this not everything works as expected: - `You are using one of Typescript's compiler options 'declaration', 'declarationMap' or 'composite'. In this case 'outDir' or 'declarationDir' must be specified to generate declaration files.` error appears , because lib tsconfig.json doesn't have outputDir at all - even if we add outDir to `tsconfig.base.json` we'll have another error `[!] (plugin typescript) RollupError: [plugin typescript] @rollup/plugin-typescript TS6377: Cannot write file '/workspaces/abapify-docs/dist/tsconfig.tsbuildinfo' because it will overwrite '.tsbuildinfo' file generated by referenced project '/workspaces/abapify-docs/packages/abap-to-markdown'` This happens becase it tries to write all tsbuildinfo files into a root dist folder. ## Expected Behavior Using rollup.config.ts should just work in a similar way as js|cjs|mjs config work. ## Solution According to docs: > This option supports the same syntax as the [--plugin](https://rollupjs.org/command-line-interface/#p-plugin-plugin-plugin) option i.e., you can specify the option multiple times, you can omit the @rollup/plugin- prefix and just write typescript and you can specify plugin options via ={...}. So it means we can use something like this: ``` rollup -c rollup.config.ts --configPlugin typescript={tsconfig:\'tsconfig.lib.json\'} ``` ## Related Issue(s) Solution is taken from this issue:: https://github.com/rollup/plugins/issues/1713#issuecomment-2201138846 --- .../plugins/__snapshots__/plugin.spec.ts.snap | 16 ++++++++++------ packages/rollup/src/plugins/plugin.ts | 4 +++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap b/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap index 22512d1c33..6e59d3eec8 100644 --- a/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap +++ b/packages/rollup/src/plugins/__snapshots__/plugin.spec.ts.snap @@ -1,6 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`@nx/rollup/plugin non-root project should create nodes 1`] = ` +exports[`@nx/rollup/plugin non-root project should create nodes 1` +] = ` [ [ "mylib/rollup.config.cjs", @@ -67,7 +68,8 @@ exports[`@nx/rollup/plugin non-root project should create nodes 1`] = ` ] `; -exports[`@nx/rollup/plugin non-root project should create nodes 2`] = ` +exports[`@nx/rollup/plugin non-root project should create nodes 2` +] = ` [ [ "mylib/rollup.config.cts", @@ -78,7 +80,7 @@ exports[`@nx/rollup/plugin non-root project should create nodes 2`] = ` "targets": { "build": { "cache": true, - "command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript", + "command": "rollup -c rollup.config.cts --configPlugin typescript={tsconfig:\\'tsconfig.lib.json\\'}", "dependsOn": [ "^build", ], @@ -134,7 +136,8 @@ exports[`@nx/rollup/plugin non-root project should create nodes 2`] = ` ] `; -exports[`@nx/rollup/plugin root project should create nodes 1`] = ` +exports[`@nx/rollup/plugin root project should create nodes 1` +] = ` [ [ "rollup.config.cjs", @@ -200,7 +203,8 @@ exports[`@nx/rollup/plugin root project should create nodes 1`] = ` ] `; -exports[`@nx/rollup/plugin root project should create nodes 2`] = ` +exports[`@nx/rollup/plugin root project should create nodes 2` +] = ` [ [ "rollup.config.cts", @@ -211,7 +215,7 @@ exports[`@nx/rollup/plugin root project should create nodes 2`] = ` "targets": { "build": { "cache": true, - "command": "rollup -c rollup.config.cts --configPlugin @rollup/plugin-typescript", + "command": "rollup -c rollup.config.cts --configPlugin typescript={tsconfig:\\'tsconfig.lib.json\\'}", "dependsOn": [ "^build", ], diff --git a/packages/rollup/src/plugins/plugin.ts b/packages/rollup/src/plugins/plugin.ts index d1d65f83d9..c08c6559ca 100644 --- a/packages/rollup/src/plugins/plugin.ts +++ b/packages/rollup/src/plugins/plugin.ts @@ -188,7 +188,9 @@ async function buildRollupTarget( const targets: Record = {}; targets[options.buildTargetName] = { command: `rollup -c ${basename(configFilePath)}${ - isTsConfig ? ` --configPlugin ${tsConfigPlugin}` : '' + isTsConfig + ? ` --configPlugin typescript={tsconfig:\\'tsconfig.lib.json\\'}` + : '' }`, options: { cwd: projectRoot }, cache: true,