@visulima/packem
Version:
A fast and modern bundler for Node.js and TypeScript.
30 lines (29 loc) • 1.42 kB
TypeScript
import type { Plugin, RenderedChunk } from "rollup";
/**
* Options for the `fixDtsDefaultCjsExportsPlugin`.
*/
export type FixDtsDefaultCjsExportsPluginOptions = {
/**
* A function to determine if a chunk should be processed by this plugin.
* Defaults to processing .d.ts, .d.cts, or .d.mts files that are entry chunks and have exports.
* @param info The Rollup RenderedChunk object.
* @returns True if the chunk should be processed, false otherwise.
*/
matcher?: (info: RenderedChunk) => boolean;
};
/**
* A Rollup plugin to fix default exports in TypeScript declaration files (.d.ts)
* to ensure they are CJS compatible (using `export = ...` and namespaces).
* This is particularly useful for libraries that want to support both ESM and CJS consumers correctly.
*
* The plugin handles various scenarios:
* - `export { MyClass as default };`
* - `export { default } from 'some-module';`
* - `export { name as default } from 'some-module';`
* - `export default from 'some-module';` (an mlly quirk)
* - Combinations with named exports (value and type exports), creating namespaces where appropriate.
* - Pure type-only exports like `export { type Foo, type Bar };`
* @param options Optional configuration for the plugin.
* @returns The Rollup plugin object.
*/
export declare const fixDtsDefaultCjsExportsPlugin: (options?: FixDtsDefaultCjsExportsPluginOptions) => Plugin;