From 4244a44ccd65138f85bcdbdb2ed805fb58d152b1 Mon Sep 17 00:00:00 2001 From: tlq5l <186405119+tlq5l@users.noreply.github.com> Date: Thu, 22 Oct 2026 12:00:44 +0700 Subject: [PATCH] fix(tsc): force declaration when emitting with the compiler (#324) Co-authored-by: Kevin Deng --- __snapshots__/tsnapi/tsc.snapshot.js | 2 +- src/tsc/emit-compiler.ts | 1 + tests/source-map.test.ts | 46 ++++++++++++++++------------ 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/__snapshots__/tsnapi/tsc.snapshot.js b/__snapshots__/tsnapi/tsc.snapshot.js index ed032ae..5e18b42 100644 --- a/__snapshots__/tsnapi/tsc.snapshot.js +++ b/__snapshots__/tsnapi/tsc.snapshot.js @@ -2,5 +2,5 @@ * Generated by tsnapi — public API snapshot of `rolldown-plugin-dts/tsc` */ // #region Re-exports -export { t as tscEmit } from "./tsc-COJ0NoM_.mjs"; +export { t as tscEmit } from "./tsc-D6Vdpmfj.mjs"; // #endregion \ No newline at end of file diff --git a/src/tsc/emit-compiler.ts b/src/tsc/emit-compiler.ts index 64740a6..cebf2d2 100644 --- a/src/tsc/emit-compiler.ts +++ b/src/tsc/emit-compiler.ts @@ -100,6 +100,7 @@ function createTsProgramFromParsedConfig({ const compilerOptions: CompilerOptions = { ...defaultCompilerOptions, ...parsedConfig.options, + declaration: true, $configRaw: parsedConfig.raw, $rootDir: baseDir, // Allow non-TS extensions (e.g. `.vue`) to be used as root files. Without diff --git a/tests/source-map.test.ts b/tests/source-map.test.ts index b55f815..61bb8ec 100644 --- a/tests/source-map.test.ts +++ b/tests/source-map.test.ts @@ -56,25 +56,33 @@ test('oxc', async () => { validateSourceMap(sourcemap) }) -test('tsc', async () => { - const dir = path.join(tempDir, 'source-map-tsc') - await build({ - input, - plugins: [ - dts({ - generator: 'tsc', - tsconfig, - sourcemap: true, - emitDtsOnly: true, - }), - ], - output: { dir }, - write: true, - }) - await expectFilesSnapshot(dir, '__snapshots__/source-map-tsc.md') - const sourcemap = await readFile(path.resolve(dir, 'index.d.ts.map'), 'utf8') - validateSourceMap(sourcemap) -}) +test.each([true, false])( + 'tsc with tsconfig declaration=%s', + async (declaration) => { + const dir = path.join(tempDir, 'source-map-tsc') + await build({ + input, + plugins: [ + dts({ + generator: 'tsc', + tsc: { newContext: true }, + tsconfig, + compilerOptions: { declaration }, + sourcemap: true, + emitDtsOnly: true, + }), + ], + output: { dir }, + write: true, + }) + await expectFilesSnapshot(dir, '__snapshots__/source-map-tsc.md') + const sourcemap = await readFile( + path.resolve(dir, 'index.d.ts.map'), + 'utf8', + ) + validateSourceMap(sourcemap) + }, +) test('tsgo', async () => { const dir = path.join(tempDir, 'source-map-tsgo') -- knotmirror 0.0.1