diff --git a/plugin/data.ts b/plugin/data.ts index 5a85235..fd7924a 100644 --- a/plugin/data.ts +++ b/plugin/data.ts @@ -1,4 +1,4 @@ -import { GetModuleInfo } from "rollup"; +import type { GetModuleInfo } from "./rollup-types.js"; import { isModuleTree, ModuleLengths, ModuleTree, ModuleTreeLeaf } from "../shared/types.js"; import { ModuleMapper } from "./module-mapper.js"; diff --git a/plugin/index.ts b/plugin/index.ts index 689109e..ae477e1 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -1,7 +1,8 @@ import { promises as fs } from "node:fs"; import path from "node:path"; -import { OutputBundle, Plugin, NormalizedOutputOptions, OutputOptions } from "rollup"; +import type { OutputBundle, NormalizedOutputOptions } from "rollup"; +import type { Plugin, OutputOptions } from "./rollup-types.js"; import opn, { Options as OpenOptions } from "open"; import { ModuleLengths, ModuleTree, ModuleTreeLeaf, VisualizerData } from "../shared/types.js"; @@ -140,7 +141,7 @@ export const visualizer = ( outputOptions: NormalizedOutputOptions, outputBundle: OutputBundle, ): Promise { - opts = typeof opts === "function" ? opts(outputOptions) : opts; + opts = typeof opts === "function" ? opts(outputOptions as unknown as OutputOptions) : opts; if ("json" in opts) { this.warn(WARN_JSON_DEPRECATED); diff --git a/plugin/rollup-types.ts b/plugin/rollup-types.ts new file mode 100644 index 0000000..7af8e12 --- /dev/null +++ b/plugin/rollup-types.ts @@ -0,0 +1,44 @@ +// Structural stubs for rollup/rolldown types. Both bundlers are optional peer +// deps, so the published .d.ts files can't hard-import from either. + +export interface OutputOptions { + dir?: string; + file?: string; + format?: string; + name?: string; + entryFileNames?: string | ((chunkInfo: any) => string); + chunkFileNames?: string | ((chunkInfo: any) => string); + assetFileNames?: string | ((assetInfo: any) => string); + sourcemap?: boolean | "inline" | "hidden"; + banner?: unknown; + footer?: unknown; + intro?: unknown; + outro?: unknown; + globals?: unknown; + exports?: "auto" | "default" | "named" | "none"; +} + +export interface Plugin { + name: string; + generateBundle?: ( + this: any, + options: any, + bundle: any, + isWrite?: boolean, + ) => void | Promise; +} + +export interface OutputChunk { + type: "chunk"; + code: string; + map?: unknown; + facadeModuleId?: string | null; + modules: Record; +} + +export type GetModuleInfo = (moduleId: string) => { + isEntry: boolean; + isExternal: boolean; + importedIds: readonly string[]; + dynamicallyImportedIds?: readonly string[]; +} | null; diff --git a/plugin/sourcemap.ts b/plugin/sourcemap.ts index 6ed061e..4889101 100644 --- a/plugin/sourcemap.ts +++ b/plugin/sourcemap.ts @@ -1,5 +1,5 @@ import path from "node:path"; -import { OutputChunk } from "rollup"; +import type { OutputChunk } from "./rollup-types.js"; import type { RawSourceMap } from "source-map"; import { SourceMapConsumer } from "source-map";