timocov / dts-bundle-generator

A tool to generate a single bundle of dts with types tree-shaking
MIT License
762 stars 40 forks source link

Top-level exports comments/JSDocs are stripped when not exported directly #328

Open pylixonly opened 3 months ago

pylixonly commented 3 months ago

Bug report Repository with the entire setup (reproducible): https://github.com/amsyarasyiq/dts-bundle-jsdocs-strip-issue

In below example, function executePlugins and array plugins docs are stripped after getting bundled. Input code

// plugins.ts
export interface TestPlugin {
    /**
     * The unique name of the plugin
     */
    name: string;
    /**
     * Brief description of the plugin
     */
    description: string;
    /**
     * Function to be executed on plugin execution
     */
    execute(): void;
}

/**
 * Responsible of holding all installed plugins
 */
export const plugins: TestPlugin[] = [];

/**
 * Executes all plugins that are not excluded.
 *
 * @param {string[]} excluded - An array of plugin names to exclude.
 * @return {void} This function does not return a value.
 */
export function executePlugins(excluded: string[] = []): void {
    for (const plugin of plugins) {
        if (!excluded.includes(plugin.name)) {
            plugin.execute();
        }
    }
}
// input.ts
export * as plugins from "./plugins";

Expected output

export interface TestPlugin {
    /**
     * The unique name of the plugin
     */
    name: string;
    /**
     * Brief description of the plugin
     */
    description: string;
    /**
     * Function to be executed on plugin execution
     */
    execute(): void;
}
/**
 * Responsible of holding all installed plugins
 */
declare const plugins: TestPlugin[];
/**
 * Executes all plugins that are not excluded.
 *
 * @param {string[]} excluded - An array of plugin names to exclude.
 * @return {void} This function does not return a value.
 */
declare function executePlugins(excluded?: string[]): void;

declare namespace plugins$1 {
    export { TestPlugin, executePlugins, plugins };
}

export {
    plugins$1 as plugins,
};

export {};

Actual output

export interface TestPlugin {
    /**
     * The unique name of the plugin
     */
    name: string;
    /**
     * Brief description of the plugin
     */
    description: string;
    /**
     * Function to be executed on plugin execution
     */
    execute(): void;
}
declare const plugins: TestPlugin[];
declare function executePlugins(excluded?: string[]): void;

declare namespace plugins$1 {
    export { TestPlugin, executePlugins, plugins };
}

export {
    plugins$1 as plugins,
};

export {};

Additional context dts-bundle-generator version: 9.5.1 bun dts-bundle-generator -o ./test/output.d.ts ./test/input.ts --no-check

timocov commented 2 months ago

Hm, at the glance it seems there should be a more complex check in here to make sure that transitive exports (or re-exports, not sure what exactly cases the issue) are also accounted.