Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/data.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
5 changes: 3 additions & 2 deletions plugin/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -140,7 +141,7 @@ export const visualizer = (
outputOptions: NormalizedOutputOptions,
outputBundle: OutputBundle,
): Promise<void> {
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);
Expand Down
44 changes: 44 additions & 0 deletions plugin/rollup-types.ts
Original file line number Diff line number Diff line change
@@ -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<void>;
}

export interface OutputChunk {
type: "chunk";
code: string;
map?: unknown;
facadeModuleId?: string | null;
modules: Record<string, { renderedLength: number; code: string | null }>;
}

export type GetModuleInfo = (moduleId: string) => {
isEntry: boolean;
isExternal: boolean;
importedIds: readonly string[];
dynamicallyImportedIds?: readonly string[];
} | null;
2 changes: 1 addition & 1 deletion plugin/sourcemap.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down
Loading