Skip to content

Commit 4244a44

Browse files
tlq5lsxzz
andauthored
fix(tsc): force declaration when emitting with the compiler (#324)
Co-authored-by: Kevin Deng <sxzz@sxzz.moe>
1 parent f5d8075 commit 4244a44

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

‎__snapshots__/tsnapi/tsc.snapshot.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
* Generated by tsnapi — public API snapshot of `rolldown-plugin-dts/tsc`
33
*/
44
// #region Re-exports
5-
export { t as tscEmit } from "./tsc-COJ0NoM_.mjs";
5+
export { t as tscEmit } from "./tsc-D6Vdpmfj.mjs";
66
// #endregion

‎src/tsc/emit-compiler.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ function createTsProgramFromParsedConfig({
100100
const compilerOptions: CompilerOptions = {
101101
...defaultCompilerOptions,
102102
...parsedConfig.options,
103+
declaration: true,
103104
$configRaw: parsedConfig.raw,
104105
$rootDir: baseDir,
105106
// Allow non-TS extensions (e.g. `.vue`) to be used as root files. Without

‎tests/source-map.test.ts‎

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,33 @@ test('oxc', async () => {
5656
validateSourceMap(sourcemap)
5757
})
5858

59-
test('tsc', async () => {
60-
const dir = path.join(tempDir, 'source-map-tsc')
61-
await build({
62-
input,
63-
plugins: [
64-
dts({
65-
generator: 'tsc',
66-
tsconfig,
67-
sourcemap: true,
68-
emitDtsOnly: true,
69-
}),
70-
],
71-
output: { dir },
72-
write: true,
73-
})
74-
await expectFilesSnapshot(dir, '__snapshots__/source-map-tsc.md')
75-
const sourcemap = await readFile(path.resolve(dir, 'index.d.ts.map'), 'utf8')
76-
validateSourceMap(sourcemap)
77-
})
59+
test.each([true, false])(
60+
'tsc with tsconfig declaration=%s',
61+
async (declaration) => {
62+
const dir = path.join(tempDir, 'source-map-tsc')
63+
await build({
64+
input,
65+
plugins: [
66+
dts({
67+
generator: 'tsc',
68+
tsc: { newContext: true },
69+
tsconfig,
70+
compilerOptions: { declaration },
71+
sourcemap: true,
72+
emitDtsOnly: true,
73+
}),
74+
],
75+
output: { dir },
76+
write: true,
77+
})
78+
await expectFilesSnapshot(dir, '__snapshots__/source-map-tsc.md')
79+
const sourcemap = await readFile(
80+
path.resolve(dir, 'index.d.ts.map'),
81+
'utf8',
82+
)
83+
validateSourceMap(sourcemap)
84+
},
85+
)
7886

7987
test('tsgo', async () => {
8088
const dir = path.join(tempDir, 'source-map-tsgo')

0 commit comments

Comments
 (0)