import type { LegacyOptions as SassLegacyOptions, Options as SassOptions, } from "sass"; import { IsomorphicRollupFs } from "../fs-iface"; interface StyleSheetIdAndContent { id?: string; content?: string; } export type RollupPluginSassOutputFn = ( styles: string, styleNodes: StyleSheetIdAndContent[], ) => unknown; export type RollupPluginSassProcessorFnOutput = | string | { css: string; /** If provided, the default export of the CSS file will be the map returned here */ cssModules?: Record; // User processor might add additional exports [key: string]: unknown; }; export type RollupPluginSassProcessorFn = (styles: string, id: string) => Promise | T; interface RollupPluginSassSharedOptions { fs?: IsomorphicRollupFs; /** * File globs to "exclude" from processing. Default 'node_modules/**'. */ exclude?: string | string[]; /** * File globs to include in processing. Default `['**\/*.sass', '**\/*.scss']`, */ include?: string | string[]; /** * Controls whether to insert generated styles into a style tag on (html) page's `head` or not. */ insert?: boolean; processor?: RollupPluginSassProcessorFn; /** * Controls where sass output is generated to. If `false`, the default, output is generated at the resolved location * by rollup; E.g., content is output to your rollup `output` configs format, and location; E.g., @todo add example * * If `true` the bundle is output as '*.css' file, at location where bundle would've been generated to originally. * * If is a function, control of where, or how, the bundle is generated is left to the user; * ```typescript * output(styles: string[], styleNodes: {id: string, content: string}[]): void { * writeFileSync('bundle.css', styles); * } * ``` */ output?: boolean | string | RollupPluginSassOutputFn; /** * Sass runtime instance - sass, node-sass or other etc.. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any runtime?: any; shouldExtract?: (filePath: string, fileContent: string) => boolean; getExtractNameAndUrl?: ( filePath: string, contentHash: string, fs: IsomorphicRollupFs, ) => { name: string; url: string } | Promise<{ name: string; url: string }>; /** * When provided, `filePath` is resolved through any pnpm (or other * symlink-based package manager) `node_modules` symlink before being * passed to `getExtractNameAndUrl`. This turns a symlink-resolved real * path with no `node_modules` ancestor (what pnpm workspaces hand rollup) * back into one that does, so callers computing a `node_modules`-relative * extracted name see a clean `node_modules/@pkg/...` path instead of a * `../../..` traversal. * * The `node_modules` directory is found by walking up from `rootDir`. Not * required if `filePath` already has a `node_modules` ancestor, or if * `getExtractNameAndUrl` doesn't compute a `node_modules`-relative name. */ rootDir?: string; } export type RollupPluginSassModernOptions = Omit< SassOptions<"async">, "sourceMap" // sourcemaps are handled by rollup > & { data?: string; }; export type RollupPluginSassLegacyOptions = Omit< SassLegacyOptions<"async">, "data" // data is assembled and always passed via plugin `transform` > & { data?: string; }; export type RollupPluginSassOptions = | (RollupPluginSassSharedOptions & { api: "modern"; options?: RollupPluginSassModernOptions; }) | (RollupPluginSassSharedOptions & { api?: "legacy"; options?: RollupPluginSassLegacyOptions; }); export type RollupPluginSassState = { // Stores interim bundle objects styles: StyleSheetIdAndContent[]; // ""; Used, currently to ensure that we're not pushing style objects representing // the same file-path into `pluginState.styles` more than once. styleMaps: { [index: string]: StyleSheetIdAndContent; }; };