From 5414e871d8baad9d36241abe5503730e7e21c261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 1 Feb 2026 22:37:28 +0100 Subject: [PATCH 1/6] Rewrite extensions in generated import statements --- src/index.ts | 2 + src/plugins/rewrite-import-extensions.ts | 32 +++++++ test/index.test.ts | 115 +++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 src/plugins/rewrite-import-extensions.ts diff --git a/src/index.ts b/src/index.ts index 64a1d690..497a6bb2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -29,6 +29,7 @@ import { terserPlugin } from './plugins/terser' import { runTypeScriptCompiler } from './tsc' import { runDtsRollup } from './api-extractor' import { cjsInterop } from './plugins/cjs-interop' +import { rewriteImportExtensions } from './plugins/rewrite-import-extensions' import type { Format, KILL_SIGNAL, NormalizedOptions, Options } from './options' export type { Format, Options, NormalizedOptions } @@ -313,6 +314,7 @@ export async function build(_options: Options) { ...options.format.map(async (format, index) => { const pluginContainer = new PluginContainer([ shebang(), + rewriteImportExtensions(), ...(options.plugins || []), treeShakingPlugin({ treeshake: options.treeshake, diff --git a/src/plugins/rewrite-import-extensions.ts b/src/plugins/rewrite-import-extensions.ts new file mode 100644 index 00000000..af240dce --- /dev/null +++ b/src/plugins/rewrite-import-extensions.ts @@ -0,0 +1,32 @@ +import type { Plugin } from '../plugin' + +const getOutputExtension = (tsExt: string, outputPath: string): string => { + if (tsExt === '.mts') return '.mjs' + if (tsExt === '.cts') return '.cjs' + if (outputPath.endsWith('.mjs')) return '.mjs' + if (outputPath.endsWith('.cjs')) return '.cjs' + return '.js' +} + +const RELATIVE_IMPORT_PATTERN = + /(?<=(?:from\s+|import\s*\(|require\s*\()['"])(\.\.?\/[^'"]*)(\.(?:ts|tsx|mts|cts))(?=['"])/g + +export const rewriteImportExtensions = (): Plugin => { + return { + name: 'rewrite-import-extensions', + + renderChunk(code, info) { + if (!/\.(js|mjs|cjs)$/.test(info.path)) return + + const rewritten = code.replace( + RELATIVE_IMPORT_PATTERN, + (_, pathWithoutExt, tsExt) => + pathWithoutExt + getOutputExtension(tsExt, info.path), + ) + + if (rewritten === code) return + + return { code: rewritten } + }, + } +} diff --git a/test/index.test.ts b/test/index.test.ts index 5b42572e..cc12a790 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -925,3 +925,118 @@ test('generate sourcemap with --treeshake', async () => { }), ) }) + +test('rewrite .ts import extensions with bundle:false', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `import { foo } from './foo.ts';\nexport { foo };`, + 'foo.ts': `export const foo = 'foo'`, + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'foo.ts'], + }, + ) + expect(outFiles).toContain('input.js') + expect(outFiles).toContain('foo.js') + const output = await getFileContent('dist/input.js') + expect(output).toContain('./foo.js') + expect(output).not.toContain('./foo.ts') +}) + +test('rewrite .ts import extensions to .mjs for esm format', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `import { foo } from './foo.ts';\nexport { foo };`, + 'foo.ts': `export const foo = 'foo'`, + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'foo.ts'], + flags: ['--format', 'esm'], + }, + ) + expect(outFiles).toContain('input.mjs') + const output = await getFileContent('dist/input.mjs') + expect(output).toContain('./foo.mjs') + expect(output).not.toContain('./foo.ts') +}) + +test('rewrite .ts import extensions to .cjs for cjs format with type:module', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `import { foo } from './foo.ts';\nexport { foo };`, + 'foo.ts': `export const foo = 'foo'`, + 'package.json': JSON.stringify({ type: 'module' }), + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'foo.ts'], + flags: ['--format', 'cjs'], + }, + ) + expect(outFiles).toContain('input.cjs') + const output = await getFileContent('dist/input.cjs') + expect(output).toContain('./foo.cjs') + expect(output).not.toContain('./foo.ts') +}) + +test('rewrite .mts and .cts import extensions', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `import { foo } from './foo.mts';\nimport { bar } from './bar.cts';\nexport { foo, bar };`, + 'foo.mts': `export const foo = 'foo'`, + 'bar.cts': `export const bar = 'bar'`, + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'foo.mts', 'bar.cts'], + }, + ) + expect(outFiles).toContain('input.js') + const output = await getFileContent('dist/input.js') + expect(output).toContain('./foo.mjs') + expect(output).toContain('./bar.cjs') + expect(output).not.toContain('.mts') + expect(output).not.toContain('.cts') +}) + +test('rewrite export from with .ts extension', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `export { foo } from './foo.ts';`, + 'foo.ts': `export const foo = 'foo'`, + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'foo.ts'], + }, + ) + expect(outFiles).toContain('input.js') + const output = await getFileContent('dist/input.js') + expect(output).toContain('./foo.js') + expect(output).not.toContain('./foo.ts') +}) + +test('rewrite dynamic import with .ts extension', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `export const load = () => import('./foo.ts');`, + 'foo.ts': `export const foo = 'foo'`, + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'foo.ts'], + }, + ) + expect(outFiles).toContain('input.js') + const output = await getFileContent('dist/input.js') + expect(output).toContain('./foo.js') + expect(output).not.toContain('./foo.ts') +}) From 89e967fed8ac0a00903bb0f73d8578c8775f11e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 1 Feb 2026 22:38:13 +0100 Subject: [PATCH 2/6] optimize --- src/plugins/rewrite-import-extensions.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/rewrite-import-extensions.ts b/src/plugins/rewrite-import-extensions.ts index af240dce..23741582 100644 --- a/src/plugins/rewrite-import-extensions.ts +++ b/src/plugins/rewrite-import-extensions.ts @@ -18,13 +18,17 @@ export const rewriteImportExtensions = (): Plugin => { renderChunk(code, info) { if (!/\.(js|mjs|cjs)$/.test(info.path)) return + let touched = false + const rewritten = code.replace( RELATIVE_IMPORT_PATTERN, - (_, pathWithoutExt, tsExt) => - pathWithoutExt + getOutputExtension(tsExt, info.path), + (_, pathWithoutExt, tsExt) => { + touched = true + return pathWithoutExt + getOutputExtension(tsExt, info.path) + }, ) - if (rewritten === code) return + if (!touched) return return { code: rewritten } }, From 2a79b97635e7e1879578b5790ac2e3d6a1f8945b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 1 Feb 2026 22:46:26 +0100 Subject: [PATCH 3/6] handle queries --- src/plugins/rewrite-import-extensions.ts | 6 +++--- test/index.test.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/plugins/rewrite-import-extensions.ts b/src/plugins/rewrite-import-extensions.ts index 23741582..3d77078d 100644 --- a/src/plugins/rewrite-import-extensions.ts +++ b/src/plugins/rewrite-import-extensions.ts @@ -9,7 +9,7 @@ const getOutputExtension = (tsExt: string, outputPath: string): string => { } const RELATIVE_IMPORT_PATTERN = - /(?<=(?:from\s+|import\s*\(|require\s*\()['"])(\.\.?\/[^'"]*)(\.(?:ts|tsx|mts|cts))(?=['"])/g + /(?<=(?:from\s+|import\s*\(|require\s*\()['"])(\.\.?\/[^'"]*)(\.(?:ts|tsx|mts|cts))(\?[^'"]*)?(?=['"])/g export const rewriteImportExtensions = (): Plugin => { return { @@ -22,9 +22,9 @@ export const rewriteImportExtensions = (): Plugin => { const rewritten = code.replace( RELATIVE_IMPORT_PATTERN, - (_, pathWithoutExt, tsExt) => { + (_, pathWithoutExt, tsExt, query = '') => { touched = true - return pathWithoutExt + getOutputExtension(tsExt, info.path) + return pathWithoutExt + getOutputExtension(tsExt, info.path) + query }, ) diff --git a/test/index.test.ts b/test/index.test.ts index cc12a790..d6a9b7b1 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1040,3 +1040,21 @@ test('rewrite dynamic import with .ts extension', async () => { expect(output).toContain('./foo.js') expect(output).not.toContain('./foo.ts') }) + +test('rewrite .ts import extensions with query string', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'input.ts': `import data from './data.ts?raw';\nexport { data };`, + 'data.ts': `export default 'data'`, + 'tsup.config.ts': `export default { bundle: false }`, + }, + { + entry: ['input.ts', 'data.ts'], + }, + ) + expect(outFiles).toContain('input.js') + const output = await getFileContent('dist/input.js') + expect(output).toContain('./data.js?raw') + expect(output).not.toContain('./data.ts') +}) From 98a27117f57e44acd5a3836987d17b3c7c23a373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 1 Feb 2026 23:14:21 +0100 Subject: [PATCH 4/6] rewrite in dts --- src/rollup.ts | 28 ++++++++++++++++++++ test/dts.test.ts | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/src/rollup.ts b/src/rollup.ts index 90aef3be..d47aaa30 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -15,6 +15,33 @@ import { FixDtsDefaultCjsExportsPlugin } from 'fix-dts-default-cjs-exports/rollu const logger = createLogger() +const RELATIVE_TS_IMPORT_PATTERN = + /(?<=(?:from\s+|import\s*\(|require\s*\()['"])(\.\.?\/[^'"]*)(\.(?:ts|tsx|mts|cts))(\?[^'"]*)?(?=['"])/g + +const getOutputExtension = (tsExt: string, outputPath: string): string => { + if (tsExt === '.mts') return '.mjs' + if (tsExt === '.cts') return '.cjs' + if (outputPath.endsWith('.mjs') || outputPath.endsWith('.d.mts')) return '.mjs' + if (outputPath.endsWith('.cjs') || outputPath.endsWith('.d.cts')) return '.cjs' + return '.js' +} + +const rewriteDtsImportExtensionsPlugin = (): Plugin => ({ + name: 'tsup:rewrite-dts-import-extensions', + renderChunk(code, chunk) { + let touched = false + const rewritten = code.replace( + RELATIVE_TS_IMPORT_PATTERN, + (_, pathWithoutExt, tsExt, query = '') => { + touched = true + return pathWithoutExt + getOutputExtension(tsExt, chunk.fileName) + query + }, + ) + if (!touched) return null + return { code: rewritten, map: null } + }, +}) + const parseCompilerOptions = (compilerOptions?: any) => { if (!compilerOptions) return {} const { options } = ts.parseJsonConfigFileContent( @@ -149,6 +176,7 @@ const getRollupConfig = async ( entryFileNames: `[name]${outputExtension}`, chunkFileNames: `[name]-[hash]${outputExtension}`, plugins: [ + rewriteDtsImportExtensionsPlugin(), format === 'cjs' && options.cjsInterop && FixDtsDefaultCjsExportsPlugin(), diff --git a/test/dts.test.ts b/test/dts.test.ts index 941db49d..e36c168c 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -480,3 +480,70 @@ test('declaration files with multiple entrypoints #316', async () => { 'dist/bar/index.d.ts', ).toMatchSnapshot() }) + +test('dts chunks should have proper js extensions in imports', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'src/entry1.ts': ` + import type { SharedType } from './shared.ts' + export function fn1(value: SharedType) { return value } + `, + 'src/entry2.ts': ` + import type { SharedType } from './shared.ts' + export function fn2(value: SharedType) { return value } + `, + 'src/shared.ts': `export type SharedType = string`, + 'tsup.config.ts': ` + export default { + entry: ['src/entry1.ts', 'src/entry2.ts'], + format: ['esm'], + dts: true + } + `, + }, + { entry: [] }, + ) + expect(outFiles).toContain('entry1.d.mts') + expect(outFiles).toContain('entry2.d.mts') + const sharedChunk = outFiles.find( + (f) => f.startsWith('shared-') && f.endsWith('.d.mts'), + ) + expect(sharedChunk).toBeDefined() + + const entry1Dts = await getFileContent('dist/entry1.d.mts') + expect(entry1Dts).toMatch(/from ['"]\.\/shared-[^'"]+\.mjs['"]/) + expect(entry1Dts).not.toContain('.ts') +}) + +test('dts chunks should have proper js extensions (type: module)', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'src/entry1.ts': ` + import type { SharedType } from './shared.ts' + export function fn1(value: SharedType) { return value } + `, + 'src/entry2.ts': ` + import type { SharedType } from './shared.ts' + export function fn2(value: SharedType) { return value } + `, + 'src/shared.ts': `export type SharedType = string`, + 'package.json': `{ "type": "module" }`, + 'tsup.config.ts': ` + export default { + entry: ['src/entry1.ts', 'src/entry2.ts'], + format: ['esm'], + dts: true + } + `, + }, + { entry: [] }, + ) + expect(outFiles).toContain('entry1.d.ts') + expect(outFiles).toContain('entry2.d.ts') + + const entry1Dts = await getFileContent('dist/entry1.d.ts') + expect(entry1Dts).toMatch(/from ['"]\.\/shared-[^'"]+\.js['"]/) + expect(entry1Dts).not.toContain('.ts') +}) From f08bc2c3f57c794d38a4c3ec13fff830875e832a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 1 Feb 2026 23:34:50 +0100 Subject: [PATCH 5/6] tests --- src/rollup.ts | 10 ++++-- test/dts.test.ts | 82 +++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/rollup.ts b/src/rollup.ts index d47aaa30..6e439454 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -21,8 +21,10 @@ const RELATIVE_TS_IMPORT_PATTERN = const getOutputExtension = (tsExt: string, outputPath: string): string => { if (tsExt === '.mts') return '.mjs' if (tsExt === '.cts') return '.cjs' - if (outputPath.endsWith('.mjs') || outputPath.endsWith('.d.mts')) return '.mjs' - if (outputPath.endsWith('.cjs') || outputPath.endsWith('.d.cts')) return '.cjs' + if (outputPath.endsWith('.mjs') || outputPath.endsWith('.d.mts')) + return '.mjs' + if (outputPath.endsWith('.cjs') || outputPath.endsWith('.d.cts')) + return '.cjs' return '.js' } @@ -34,7 +36,9 @@ const rewriteDtsImportExtensionsPlugin = (): Plugin => ({ RELATIVE_TS_IMPORT_PATTERN, (_, pathWithoutExt, tsExt, query = '') => { touched = true - return pathWithoutExt + getOutputExtension(tsExt, chunk.fileName) + query + return ( + pathWithoutExt + getOutputExtension(tsExt, chunk.fileName) + query + ) }, ) if (!touched) return null diff --git a/test/dts.test.ts b/test/dts.test.ts index e36c168c..ccc59515 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -481,69 +481,73 @@ test('declaration files with multiple entrypoints #316', async () => { ).toMatchSnapshot() }) -test('dts chunks should have proper js extensions in imports', async () => { +test('dts should rewrite .ts import extensions to .mjs for esm format', async () => { const { getFileContent, outFiles } = await run( getTestName(), { - 'src/entry1.ts': ` - import type { SharedType } from './shared.ts' - export function fn1(value: SharedType) { return value } - `, - 'src/entry2.ts': ` - import type { SharedType } from './shared.ts' - export function fn2(value: SharedType) { return value } - `, - 'src/shared.ts': `export type SharedType = string`, + 'src/input.ts': `export type { Foo } from './types.ts'`, + 'src/types.ts': `export type Foo = string`, 'tsup.config.ts': ` export default { - entry: ['src/entry1.ts', 'src/entry2.ts'], + entry: ['src/input.ts'], format: ['esm'], - dts: true + dts: { only: true }, + external: [/\\.\\/types/] } `, }, { entry: [] }, ) - expect(outFiles).toContain('entry1.d.mts') - expect(outFiles).toContain('entry2.d.mts') - const sharedChunk = outFiles.find( - (f) => f.startsWith('shared-') && f.endsWith('.d.mts'), - ) - expect(sharedChunk).toBeDefined() - - const entry1Dts = await getFileContent('dist/entry1.d.mts') - expect(entry1Dts).toMatch(/from ['"]\.\/shared-[^'"]+\.mjs['"]/) - expect(entry1Dts).not.toContain('.ts') + expect(outFiles).toContain('input.d.mts') + const dts = await getFileContent('dist/input.d.mts') + expect(dts).toContain('./types.mjs') + expect(dts).not.toContain('./types.ts') }) -test('dts chunks should have proper js extensions (type: module)', async () => { +test('dts should rewrite .ts import extensions to .cjs for cjs format with type:module', async () => { const { getFileContent, outFiles } = await run( getTestName(), { - 'src/entry1.ts': ` - import type { SharedType } from './shared.ts' - export function fn1(value: SharedType) { return value } - `, - 'src/entry2.ts': ` - import type { SharedType } from './shared.ts' - export function fn2(value: SharedType) { return value } + 'src/input.ts': `export type { Foo } from './types.ts'`, + 'src/types.ts': `export type Foo = string`, + 'package.json': `{ "type": "module" }`, + 'tsup.config.ts': ` + export default { + entry: ['src/input.ts'], + format: ['cjs'], + dts: { only: true }, + external: [/\\.\\/types/] + } `, - 'src/shared.ts': `export type SharedType = string`, + }, + { entry: [] }, + ) + expect(outFiles).toContain('input.d.cts') + const dts = await getFileContent('dist/input.d.cts') + expect(dts).toContain('./types.cjs') + expect(dts).not.toContain('./types.ts') +}) + +test('dts should rewrite .ts import extensions to .js for esm format with type:module', async () => { + const { getFileContent, outFiles } = await run( + getTestName(), + { + 'src/input.ts': `export type { Foo } from './types.ts'`, + 'src/types.ts': `export type Foo = string`, 'package.json': `{ "type": "module" }`, 'tsup.config.ts': ` export default { - entry: ['src/entry1.ts', 'src/entry2.ts'], + entry: ['src/input.ts'], format: ['esm'], - dts: true + dts: { only: true }, + external: [/\\.\\/types/] } `, }, { entry: [] }, ) - expect(outFiles).toContain('entry1.d.ts') - expect(outFiles).toContain('entry2.d.ts') - - const entry1Dts = await getFileContent('dist/entry1.d.ts') - expect(entry1Dts).toMatch(/from ['"]\.\/shared-[^'"]+\.js['"]/) - expect(entry1Dts).not.toContain('.ts') + expect(outFiles).toContain('input.d.ts') + const dts = await getFileContent('dist/input.d.ts') + expect(dts).toContain('./types.js') + expect(dts).not.toContain('./types.ts') }) From 89d05ef67142a54efa7029411295a4d68300dfdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 2 Feb 2026 00:00:42 +0100 Subject: [PATCH 6/6] move plugin --- src/plugins/rewrite-dts-import-extensions.ts | 32 ++++++++++++++++++++ src/rollup.ts | 32 +------------------- 2 files changed, 33 insertions(+), 31 deletions(-) create mode 100644 src/plugins/rewrite-dts-import-extensions.ts diff --git a/src/plugins/rewrite-dts-import-extensions.ts b/src/plugins/rewrite-dts-import-extensions.ts new file mode 100644 index 00000000..fcb5a897 --- /dev/null +++ b/src/plugins/rewrite-dts-import-extensions.ts @@ -0,0 +1,32 @@ +import type { Plugin } from 'rollup' + +const RELATIVE_TS_IMPORT_PATTERN = + /(?<=(?:from\s+|import\s*\(|require\s*\()['"])(\.\.?\/[^'"]*)(\.(?:ts|tsx|mts|cts))(\?[^'"]*)?(?=['"])/g + +const getOutputExtension = (tsExt: string, outputPath: string): string => { + if (tsExt === '.mts') return '.mjs' + if (tsExt === '.cts') return '.cjs' + if (outputPath.endsWith('.mjs') || outputPath.endsWith('.d.mts')) + return '.mjs' + if (outputPath.endsWith('.cjs') || outputPath.endsWith('.d.cts')) + return '.cjs' + return '.js' +} + +export const rewriteDtsImportExtensionsPlugin = (): Plugin => ({ + name: 'tsup:rewrite-dts-import-extensions', + renderChunk(code, chunk) { + let touched = false + const rewritten = code.replace( + RELATIVE_TS_IMPORT_PATTERN, + (_, pathWithoutExt, tsExt, query = '') => { + touched = true + return ( + pathWithoutExt + getOutputExtension(tsExt, chunk.fileName) + query + ) + }, + ) + if (!touched) return null + return { code: rewritten, map: null } + }, +}) diff --git a/src/rollup.ts b/src/rollup.ts index 6e439454..b78889e6 100644 --- a/src/rollup.ts +++ b/src/rollup.ts @@ -12,40 +12,10 @@ import { reportSize } from './lib/report-size' import type { NormalizedOptions } from './' import type { InputOptions, OutputOptions, Plugin } from 'rollup' import { FixDtsDefaultCjsExportsPlugin } from 'fix-dts-default-cjs-exports/rollup' +import { rewriteDtsImportExtensionsPlugin } from './plugins/rewrite-dts-import-extensions' const logger = createLogger() -const RELATIVE_TS_IMPORT_PATTERN = - /(?<=(?:from\s+|import\s*\(|require\s*\()['"])(\.\.?\/[^'"]*)(\.(?:ts|tsx|mts|cts))(\?[^'"]*)?(?=['"])/g - -const getOutputExtension = (tsExt: string, outputPath: string): string => { - if (tsExt === '.mts') return '.mjs' - if (tsExt === '.cts') return '.cjs' - if (outputPath.endsWith('.mjs') || outputPath.endsWith('.d.mts')) - return '.mjs' - if (outputPath.endsWith('.cjs') || outputPath.endsWith('.d.cts')) - return '.cjs' - return '.js' -} - -const rewriteDtsImportExtensionsPlugin = (): Plugin => ({ - name: 'tsup:rewrite-dts-import-extensions', - renderChunk(code, chunk) { - let touched = false - const rewritten = code.replace( - RELATIVE_TS_IMPORT_PATTERN, - (_, pathWithoutExt, tsExt, query = '') => { - touched = true - return ( - pathWithoutExt + getOutputExtension(tsExt, chunk.fileName) + query - ) - }, - ) - if (!touched) return null - return { code: rewritten, map: null } - }, -}) - const parseCompilerOptions = (compilerOptions?: any) => { if (!compilerOptions) return {} const { options } = ts.parseJsonConfigFileContent(