From 20fb72b3084cddbe02d05e4f59fd7f2ecde0b5f1 Mon Sep 17 00:00:00 2001 From: EGOIST <0x142857@gmail.com> Date: Sun, 30 Jan 2022 17:21:33 +0800 Subject: [PATCH] fix: ignore non js/ts files in --dts build, closes #554 --- src/rollup.ts | 2 +- test/index.test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/rollup.ts b/src/rollup.ts index 8d34f711..e07ed961 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -126,7 +126,7 @@ const getRollupConfig = async ( const ignoreFiles: Plugin = { name: 'tsup:ignore-files', load(id) { - if (/\.(css|vue|svelte)$/.test(id)) { + if (!/\.(js|cjs|mjs|jsx|ts|tsx|mts|json)$/.test(id)) { return '' } }, diff --git a/test/index.test.ts b/test/index.test.ts index 3aa9ec5d..33cb6665 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -779,3 +779,30 @@ test('multiple targets', async () => { expect(output).toMatchSnapshot() expect(outFiles).toEqual(['input.js']) }) + +test('dts only: ignore files', async () => { + const { outFiles } = await run( + getTestName(), + { + 'input.ts': ` + import './style.scss' + + export const a = 1 + `, + 'style.scss': ` + @keyframes gallery-loading-spinner { + 0% {} + } + `, + }, + { + entry: ['input.ts'], + flags: ['--dts-only'], + } + ) + expect(outFiles).toMatchInlineSnapshot(` + [ + "input.d.ts", + ] + `) +})