@mui/internal-docs-infra
Version:
MUI Infra - internal documentation creation tools.
72 lines • 3.16 kB
text/typescript
import type { LoaderContext } from 'webpack';
import type { EnhanceCodeEmphasisOptions } from "../parseSource/calculateFrameRanges.mjs";
export type LoaderOptions = {
performance?: {
logging?: boolean;
notableMs?: number;
showWrapperMeasures?: boolean;
};
output?: 'hast' | 'hastJson' | 'hastCompressed';
/**
* Options for the code emphasis enhancer (padding frames, focus frames, etc.).
* Passed to `createEnhanceCodeEmphasis`.
*/
emphasisOptions?: EnhanceCodeEmphasisOptions;
/**
* Prefixes for comments that should be stripped from the source output.
* Comments starting with these prefixes will be removed from the returned source.
* They can still be collected via `notableCommentsPrefix`.
* @example ['@highlight', '@internal']
*/
removeCommentsWithPrefix?: string[];
/**
* Prefixes for notable comments that should be collected and included in the result.
* Comments starting with these prefixes will be returned in the `comments` field,
* which can be used by sourceEnhancers to modify the highlighted output.
* @example ['@highlight', '@focus']
*/
notableCommentsPrefix?: string[];
/**
* Marker option consumed by `pnpm docs-infra validate` (not by this loader).
*
* When set on a demo `index.ts` rule, the validate command ensures every
* matched demo has a sibling `client.ts` that imports `createDemoClient`
* from this specifier and that the demo's `create*` factory call receives
* a `ClientProvider` entry in its meta object.
*
* Bare specifiers are written verbatim. Relative specifiers are resolved
* against the directory containing `next.config.{js,mjs,ts}` and rewritten
* to be relative to each generated `client.ts`.
*/
requireClient?: string;
/**
* Marker option consumed by `pnpm docs-infra validate` (not by this loader).
*
* When `true` on a demo `index.ts` rule, the validate command ensures every
* matched demo has a sibling `page.tsx` that renders the demo as the route's
* default export, so each demo is browsable on its own page.
*
* Existing `page.tsx`/`page.ts` files are never overwritten.
*/
requirePage?: boolean;
/**
* When `true`, registers the `TypescriptToJavascriptTransformer` so that
* TypeScript variants also produce a JavaScript counterpart at build time.
*
* Defaults to `false` because the transform is comparatively expensive;
* enable it when the rendered demos need both TS and JS sources.
*/
transformTypescriptToJavascript?: boolean;
};
/**
* Webpack loader that processes demo files and precomputes variant data.
*
* Finds createDemo calls, loads and processes all variants with syntax highlighting
* and TypeScript transformation, then injects the precomputed data back into the source.
*
* Supports single component syntax: createDemo(import.meta.url, Component)
* And object syntax: createDemo(import.meta.url, { Component1, Component2 })
*
* Automatically skips processing if skipPrecompute: true is set.
*/
export declare function loadPrecomputedCodeHighlighter(this: LoaderContext<LoaderOptions>, source: string): Promise<void>;