Swatinem/rollup-plugin-dts

Allow using `.d.cts` and `.d.mts` files as input

Comandeer opened this issue · 0 comments

Checklist

  • I can reproduce this issue when running this plugin on its own.
    Other plugins, such as node-resolve are known to cause issues.
  • I am running this plugin on .d.ts files generated by TypeScript.
    The plugin can consume .ts and even .js files (with allowJs: true), but this is known to cause issues.
  • This issue is not related to rolling up @types.
    The plugin ignores these by default, unless respectExternal is set. @types can contain hand-crafted code which is known to cause issues.

Code Snipped

Sample reproduction.

Newer TypeScript versions by default generate a .d.mts file for an .mts file and a .d.cts file for a .cts file. #228 added support for .mjs and .cts files and #196 – support for generating .d.cts and .d.mts files. However, this plugin does not support using .d.cts and .d.mts files as inputs, and it seems like a missing piece of support for new TS file extensions.

Currently, all .d.cts and .d.mts files passed as input are ignored by the plugin, resulting in Rollup throwing an error about unsupported syntax. They need to be renamed to *.d.ts in order to be parsed and bundled.

Sample Rollup config:

import dts from 'rollup-plugin-dts';

export default {
	input: {
		cts: './dist/cjsModule.d.cts',
		mts: './dist/esmModule.d.mts'
	},
	output: {
		dir: './types'
	},
	plugins: [
		dts()
	]
};

Error Message

[!] RollupError: Unexpected token (Note that you need plugins to import files that are not JavaScript)
dist/esmModule.d.mts (1:8)
1: declare function mjsModule(): string;
           ^
2: export default mjsModule;
    at error (/home/comandeer/repos/other/bugs-reports/node_modules/rollup/dist/shared/rollup.js:261:30)
    at Module.error (/home/comandeer/repos/other/bugs-reports/node_modules/rollup/dist/shared/rollup.js:13642:16)
    at Module.tryParse (/home/comandeer/repos/other/bugs-reports/node_modules/rollup/dist/shared/rollup.js:14319:25)
    at Module.setSource (/home/comandeer/repos/other/bugs-reports/node_modules/rollup/dist/shared/rollup.js:13929:39)
    at ModuleLoader.addModuleSource (/home/comandeer/repos/other/bugs-reports/node_modules/rollup/dist/shared/rollup.js:23894:20)