import fs from "node:fs"; import { ChunkAddon, DepsConfig, InlineConfig, NoExternalFn, TsdownPlugin, UserConfig } from "tsdown"; import { PackageJson } from "pkg-types"; import { AtRule, Container, Root, Rule } from "postcss"; import { CssOptions } from "@tsdown/css"; import { Options } from "cssnano"; import { CompilerOptions } from "typescript"; //#region src/types/tsdown.d.ts type Arrayable = T | T[]; type NoExternalOption = Arrayable | NoExternalFn; type ExternalOption = NonNullable; //#endregion //#region src/utils/general.d.ts declare function isPromise(obj: any): obj is Promise; type Listable = T | false | null | undefined | Listable[] | Promise[]>; declare function resolveListable(raw: Listable): Promise; //#endregion //#region src/utils/tsdown.d.ts type MergeChunkAddonPosition = 'before' | 'after'; declare function mergeChunkAddons(base: ChunkAddon | undefined, override: ChunkAddon | undefined, position?: MergeChunkAddonPosition): ChunkAddon | undefined; /** * Collect the plain string entries from an {@link ExternalOption}, flattening * nested arrays. * * Only string entries can be turned into package-name prefixes for subpath * matching (`RegExp` / function entries are opaque and are skipped). Used to * feed the external-imports plugin so that a `deps.neverBundle` package name * also externalizes its subpath imports (e.g. `pkg/foo.svg`). */ declare function collectExternalStringPrefixes(option: ExternalOption | undefined): string[]; declare function mergeExternals(base: ExternalOption | undefined, override: ExternalOption | undefined): ExternalOption | undefined; declare function mergeNoExternals(base: NoExternalOption | undefined, override: NoExternalOption | undefined): NoExternalOption | undefined; //#endregion //#region src/utils/exit-hook.d.ts type ExitHandler = () => void; declare function exitHook(cb: ExitHandler): () => void; //#endregion //#region src/utils/dts-source-map.d.ts /** * Matches a trailing `//# sourceMappingURL=.d.(m)ts.map` comment at the * end of a declaration file. Capture group 1 is the referenced map file name. * * @see {@link stripDanglingDTSSourceMaps} */ declare const DANGLING_DTS_SOURCE_MAP_RE: RegExp; /** * Remove dangling declaration-map references from the emitted `.d.(m)ts` files * under `distDir`. * * tsdown (rolldown) appends a `//# sourceMappingURL=.d.mts.map` comment to * every declaration file it emits, but does NOT emit the referenced * `.d.mts.map` itself. Consumers' editors/build tools then try to load a * declaration map that does not exist and report a resolution failure. Until * this is fixed upstream, strip the comment so shipped declarations don't point * at a missing map. * * As a safeguard it only strips the comment when the referenced map is genuinely * absent, so it becomes a no-op automatically if a future tsdown starts emitting * real declaration maps. * * Kept intentionally self-contained so this workaround can be removed in one * step: delete this file, its re-export from `../utils`, and the two call sites * (`Builder.build` and plugboy's own `tsdown.config.ts`, which self-builds via * bootstrap tsdown rather than through `Builder`). */ declare function stripDanglingDTSSourceMaps(distDir: string): Promise; //#endregion //#region src/utils/bundled-config.d.ts /** * Compute the temporary output path for a `bundle-require`-bundled plugboy * config file (`plugboy.project.*` / `plugboy.workspace.*`). * * `bundle-require` bundles the config to a throwaway `.mjs` next to the source * before importing it. Its default places that file in the config's own * directory — e.g. `plugboy.project.bundled_.mjs` at the repo root — which * is noisy and can be left behind if the build is force-killed. * * Redirect it under the config's own `node_modules/.plugboy/` instead: * - It lives inside `node_modules`, so it is already gitignored and out of the * consumer's sight (and any straggler after a hard kill stays hidden there). * - Module resolution is unchanged: the bundled file keeps bare imports for * externalized dependencies, and Node resolves them by walking up to the same * `/node_modules` it would have used at the original location. * * The random suffix from the default naming is preserved because turbo runs * many `plugboy build` processes in parallel, each loading the root * `plugboy.project.*`; a fixed name would collide across concurrent builds. */ declare function resolveBundledConfigOutputFile(filepath: string, format: 'esm' | 'cjs'): string; //#endregion //#region src/utils/file.d.ts declare function getFilename(importMetaURL: string): string; declare function getDirname(importMetaURL: string): string; declare function isFileNotFoundException(source: unknown): source is NodeJS.ErrnoException; declare function pathExists(target: string, type?: 'file' | 'dir'): Promise; type FileMatcherFn = (file: fs.Dirent, dir: string) => boolean | Promise; type FileMatcher = string | RegExp | FileMatcherFn; declare function findFile(dir: string, matcher: FileMatcher, recursive?: boolean): Promise; interface FindConfigResult { dir: string; fileName: string; path: string; code: string; } interface FindConfigSettings { fileName: string | string[]; allowMissing?: AllowMissing; test?: (result: FindConfigResult) => boolean; /** * Trace up to how many directories above * @default 10 */ depth?: number; } declare function findConfig(fileNameOrSettings: string | string[] | FindConfigSettings, dir?: string, currentDepth?: number): Promise; declare function rmrf(...paths: string[]): Promise; declare function copyDirSync(srcDir: string, destDir: string): void; declare function writeFileAtomic(filePath: string, content: string): Promise; //#endregion //#region src/utils/expose.d.ts interface ExposeEntriesSettings { dir: string; /** * Path prefix at distribution */ prefix?: string; } type RawExposeEntriesSettings = string | ExposeEntriesSettings; declare function resolveRawExposeEntriesSettings(rawSettings: RawExposeEntriesSettings): ExposeEntriesSettings; declare function exposeEntries(rawSettings: RawExposeEntriesSettings): Promise>; //#endregion //#region src/utils/workspace.d.ts declare function isWorkspacePackageJson(json: PackageJson): json is WorkspacePackageJson; declare function resolveRawWorkspaceEntry(entry: RawWorkspaceEntry): WorkspaceEntry; declare function resolveRawWorkspaceEntries(entries: RawWorkspaceEntries | undefined): WorkspaceEntries; declare function resolveUserWorkspaceConfig(userConfig: UserWorkspaceConfig): Promise; declare function defineWorkspaceConfig(config: UserWorkspaceConfig): Promise; declare function loadWorkspaceConfig(searchDir?: string, depth?: number): Promise; //#endregion //#region src/utils/hook.d.ts declare function resolveUserHooks(...userHooks: (UserHooks | undefined | null | false)[]): Promise; declare function buildHooks(resolvedHooks: ResolvedHooks): BuildedHooks; //#endregion //#region src/utils/plugin.d.ts declare function resolveUserPluginOption(pluginOption: UserPluginOption | undefined): Promise; declare function definePlugin(options: T): T; declare function extractProjectPlugins(searchDir?: string): Promise; declare function findProjectPlugin(pluginName: string, searchDir?: string): Promise; //#endregion //#region src/utils/project.d.ts declare function isProjectPackageJson(json: PackageJson): json is ProjectPackageJson; declare function resolveUserProjectConfig(userConfig: UserProjectConfig): Promise; declare function defineProjectConfig(config: UserProjectConfig): Promise; declare function loadProjectConfig(searchDir?: string, depth?: number): Promise; //#endregion //#region src/path.d.ts declare class Path { private _value; private _stats?; get value(): string; set value(value: string); get dirname(): string; get basename(): string; get extname(): string; get stats(): fs.Stats; get isDirectory(): () => boolean; get isFile(): () => boolean; constructor(value: string); toString(): string; valueOf(): string; toJSON(): string; relative(to: string): Path; join(...paths: string[]): Path; resolve(...paths: string[]): Path; private _join; readdir(...paths: string[]): Promise; readFile(pathAppend?: string, defaults?: D): Promise; readJSON(pathAppend?: string, defaults?: D): Promise; } //#endregion //#region src/types/_utils.d.ts type ObjectLike = Record; type MarkRequired = Required> & Omit; type RequiredPackageJSON = PackageJson & Required>; type MaybePromise = T | Promise; type NullValue = T | undefined | null | void; //#endregion //#region src/project/project.d.ts /** * Plugboy Project * * @remarks This instance is only created if the project consists of a mono-repo. */ declare class PlugboyProject { /** Path instance of the project directory */ readonly dir: Path; /** package.json */ readonly json: ProjectPackageJson; /** * Project Configuration * @see {@link ResolvedProjectConfig} */ readonly config: ResolvedProjectConfig; /** Names of all packages on which the project depends */ readonly dependencies: string[]; /** Directory names of all workspaces owned by the project */ readonly resolvedWorkspaces: string[]; /** * Name of the project's package.json */ get name(): string; /** * Plug-in List * @see {@link ResolvedProjectConfig.plugins} */ get plugins(): Plugin[]; /** * List of all user hook settings * @see {@link UserHooks} */ get hooks(): UserHooks[]; constructor(ctx: ProjectSetupContext); } declare function getProject(searchDir?: string, allowMissing?: AllowMissing, skipLoadConfig?: boolean): Promise; //#endregion //#region src/types/plugin.d.ts interface Plugin extends TsdownPlugin { hooks?: UserHooks; } type UserPluginOption = MaybePromise> | { name: string; } | false | UserPluginOption[]>; //#endregion //#region src/workspace/workspace.d.ts type WorkspaceStubLink = { type: 'js'; from: string; to: string; } | { type: 'css'; from: string; }; type WorkspaceStubLinkType = WorkspaceStubLink['type']; interface WorkspaceObjectExport { src: string; types: string; dtsDest: string; import: { default: string; }; } interface WorkspaceExport { id: string; at: string | WorkspaceObjectExport; stubLink?: WorkspaceStubLink; } declare const WORKSPACE_PACKAGE_SYNC_FIELDS: readonly ["repository", "author", "publishConfig", "license"]; declare function syncWorkspacePackageFields(projectJSON: ProjectPackageJson, workspaceJSON: WorkspacePackageJson): void; declare class PlugboyWorkspace { readonly name: string; readonly dir: Path; readonly config: ResolvedWorkspaceConfig; readonly project: PlugboyProject | null; readonly dirs: WorkspaceDirs; readonly dependencies: string[]; readonly projectDependencies: string[]; readonly neverBundlePrefixes: string[]; readonly meta: WorkspaceMeta; readonly entry: Record; readonly exports: WorkspaceExport[]; readonly builder: Builder; readonly plugins: Plugin[]; readonly hooks: BuildedHooks; readonly dtsFiles: string[]; readonly dts: NormalizedDTSSettings; cssOptions: CssOptions | undefined; readonly optimizeCSSOptions: ResolvedOptimizeCSSOptions | false; private _json; get json(): WorkspacePackageJson; constructor(ctx: WorkspaceSetupContext); clean(withDepsAndCache?: boolean): Promise; preparePackageJSON(): Promise; getStubLinks(): WorkspaceStubLink[]; stub(): Promise; build(): Promise; } declare function getWorkspace(searchDir?: string, allowMissing?: AllowMissing): Promise; //#endregion //#region src/workspace/builder.d.ts interface ResolvedOptions extends InlineConfig {} declare class Builder { readonly workspace: PlugboyWorkspace; private _tsdownOptions?; get entry(): Record; get dts(): NormalizedDTSSettings; constructor(workspace: PlugboyWorkspace); tsdownOptions(overrides?: { watch?: boolean; }): Promise; private _stubLinkJS; private _stubLinkCSS; /** * Copy the workspace's `publicDir` contents into the output directory. * * Owned by plugboy (not tsdown's `copy`) so the result is identical in `build` * and `stub`: both call this with plugboy's own recursive copy. `copyDirSync` * no-ops when the directory is absent, so packages without a public directory * are unaffected. tsdown's `copy` option is left to tsdown and only applies * during a real `build`. */ copyPublicDir(): void; stub(): Promise; normalizeDTSBySettings(dts: string, settings: NormalizedDTSPreserveTypeSettings): string | undefined; normalizeDTSFile(filePath: string): Promise; normalizeDTSFiles(dtsFiles?: string[]): Promise; emitDTSManually(): Promise; build(): Promise; } //#endregion //#region src/workspace/generate.d.ts declare function generateWorkspace(workspaceName?: string, cwd?: string): Promise; //#endregion //#region src/types/dts.d.ts interface EmitDTSOptions { cwd?: string; outDir?: string; } /** * Custom DTS compiler function */ type DTSCompilerFunction = (opts: EmitDTSOptions & { workspace: PlugboyWorkspace; }) => Promise; /** * DTS compiler specification * - 'tsc': TypeScript compiler (default) * - 'vue-tsc': Vue SFC compatible compiler * - function: Custom compiler function */ type DTSCompilerOption = 'tsc' | 'vue-tsc' | DTSCompilerFunction; /** * Type preservation target in declaration file */ interface DTSPreserveTypeTarget { /** Type name */ typeName: string; /** * String to be restored or regular expression to match */ from: string | RegExp; } /** * Type preservation target in declaration file (normalized) * * @see {@link DTSPreserveTypeTarget} */ interface NormalizedDTSPreserveTypeTarget extends Omit { /** Regular expression to match the string to be restored */ from: RegExp; } declare function normalizeDTSPreserveTypeTarget(target: DTSPreserveTypeTarget): NormalizedDTSPreserveTypeTarget; /** * Type preservation setting for declaration files * * @remarks This setting is for restoring type information inlined by the TypeScript compiler to the original type name by string substitution. */ interface DTSPreserveTypeSettings { /** Name of the package to which the type to be restored belongs */ pkg?: string; /** List of preservation targets */ targets: DTSPreserveTypeTarget[]; } /** * Type preservation setting for declaration files (normalized) * * @see {@link DTSPreserveTypeSettings} */ interface NormalizedDTSPreserveTypeSettings extends Omit { /** List of normalized type preservation targets */ targets: NormalizedDTSPreserveTypeTarget[]; } declare function normalizeDTSPreserveTypeSettings(settings: DTSPreserveTypeSettings): NormalizedDTSPreserveTypeSettings; /** * Function to normalize declaration strings * @param dts - Bundled declaration strings * @param builder - Builder */ type DTSNormalizer = (dts: string, builder: Builder) => string | undefined | void | Promise; /** * declaration output setting */ interface DTSSettings { /** * Inline output without bundling declaration * * @default false */ inline?: boolean; /** * DTS compiler specification * @default 'tsc' */ compiler?: DTSCompilerOption; /** * Whether to ignore compiler errors and continue * @default false */ ignoreCompilerErrors?: boolean; /** * list of type preservation settings * * @remarks This setting is for restoring type information inlined by the TypeScript compiler to the original type name by string substitution. * * @see {@link DTSPreserveTypeSettings} */ preserveType?: DTSPreserveTypeSettings[]; /** * list of function to normalize declaration strings */ normalizers?: DTSNormalizer[]; } /** * declaration output setting (normalized) * * @see {@link DTSSettings} */ interface NormalizedDTSSettings { /** * Inline output without bundling declaration */ inline: boolean; /** * DTS compiler specification */ compiler: DTSCompilerOption; /** * Whether to ignore compiler errors and continue */ ignoreCompilerErrors: boolean; /** * list of type preservation settings */ preserveType: NormalizedDTSPreserveTypeSettings[]; /** * list of function to normalize declaration strings */ normalizers: DTSNormalizer[]; } declare function normalizeDTSSettings(settings: DTSSettings): NormalizedDTSSettings; declare function mergeDTSSettingsList(...settingsList: (DTSSettings | undefined)[]): NormalizedDTSSettings; //#endregion //#region src/postcss/plugins/optimize-layer.d.ts type Filter$1 = (layerName: string, rule: AtRule) => boolean; type FilterSpec$1 = string | RegExp | (string | RegExp)[] | Filter$1; interface OptimizeLayerOptions { include?: FilterSpec$1; exclude?: FilterSpec$1; } //#endregion //#region src/postcss/plugins/optimize-media.d.ts interface Media { query: string; rule: AtRule; container: Container; } type Filter = (query: string, media: Media) => boolean; type FilterSpec = string | RegExp | (string | RegExp)[] | Filter; type SortMedia = (a: Media, b: Media) => number; interface OptimizeMediaOptions { include?: FilterSpec; exclude?: FilterSpec; sort?: SortMedia; } //#endregion //#region src/postcss/plugins/combine-rules.d.ts type RuleFilter = string | RegExp; type RuleSpecFn = (rule: Rule) => boolean; type RuleSpec = RuleFilter[] | RuleSpecFn; interface CombineRulesOptions { rules: RuleSpec; } //#endregion //#region src/types/css.d.ts /** * CSS optimization options */ interface OptimizeCSSOptions { /** * Layer optimization options * * Disable the operation with `false`. * * @default true */ layer?: OptimizeLayerOptions | boolean; /** * Media Query Optimization Options * * Disable the operation with `false`. * * @default true */ media?: OptimizeMediaOptions | boolean; /** * Combine rules Options * * If unset, no optimization is performed */ combineRules?: CombineRulesOptions; /** * Options for [cssnano](https://cssnano.co/) * * Disable the operation with `false`. * * @default { preset: ['default', { normalizeWhitespace: false }] } */ cssnano?: Options | boolean; } interface ResolvedOptimizeCSSOptions { layer?: OptimizeLayerOptions; media?: OptimizeMediaOptions; combineRules?: CombineRulesOptions; cssnano?: Options; } declare function resolveOptimizeCSSOptions(options: OptimizeCSSOptions): ResolvedOptimizeCSSOptions; //#endregion //#region src/types/workspace.d.ts declare const WORKSPACE_REQUIRED_FIELDS: readonly ["name", "version"]; type WorkspaceRequiredField = (typeof WORKSPACE_REQUIRED_FIELDS)[number]; /** * Entry setting object */ interface RawWorkspaceEntryObject { /** * Entry file path * @remarks It must be relative to the root directory of the workspace. */ src: string; /** * Set to true if the entry outputs css at the same time * @remarks By doing this, the exports field in package.json will be set automatically. */ css?: boolean; } /** * Entry setting object */ type WorkspaceEntry = MarkRequired; type RawWorkspaceEntry = string | RawWorkspaceEntryObject; /** * Configuration of all entries in the workspace (normalized) * * @see {@link RawWorkspaceEntries} */ type WorkspaceEntries = Record; /** * Configuration of all entries in the workspace * * @remarks The configuration must be `{ [id]: [Entry setting: }`. `"." ` is treated as a special ID and is the target of the main export. */ type RawWorkspaceEntries = Record; declare const TSDOWN_SYNC_OPTIONS: ["define", "skipNodeModulesBundle", "onSuccess", "copy", "deps", "target"]; type TSDownSyncOption = (typeof TSDOWN_SYNC_OPTIONS)[number]; interface TSDownSyncOptions extends Pick {} /** * Workspace User Configuration */ interface UserWorkspaceConfig extends TSDownSyncOptions { /** * Ignore project settings * * @remarks Normally, when processing a workspace, plugboy looks for and merges the settings of the entire project at the same time, but this action can be canceled. */ ignoreProjectConfig?: boolean; /** * Configuration of all entries in the workspace * * @see {@link RawWorkspaceEntries} */ entries?: RawWorkspaceEntries; /** * Hook Setting * @see {@link UserHooks} */ hooks?: UserHooks; /** * Plug-in List * @see {@link UserPluginOption} */ plugins?: UserPluginOption[]; /** * declaration output setting * @see {@link DTSSettings} */ dts?: DTSSettings; /** * Directory whose contents are copied into the output directory (`dist`). * * Owned by plugboy (not tsdown's `copy`) so the copy is performed identically * in both `build` and `stub`. Use tsdown's `copy` for advanced cases that * only need to run during a real build. * * - `true` (default): copy `./public` * - `false`: disable * - string: copy the given directory * * @default true */ publicDir?: string | boolean; /** * tsdown's `copy` option — copy files into the output directory. * * @remarks * Runs during `build` only. `stub` does NOT execute this (it does not run * tsdown). For assets that must also be present in the stub output, use * {@link publicDir}, which plugboy copies identically in both `build` and * `stub`. */ copy?: UserConfig['copy']; /** * tsdown's `target` option — the environment(s) the output syntax is * downleveled for. * * @remarks * Inherited from the project configuration when omitted. A value set here * replaces the project default outright (a target list describes one * environment set, so merging the two would be meaningless). * * Note that this only lowers *syntax*; runtime APIs are never polyfilled. * Unset at both layers, tsdown falls back to `engines.node` of the package, * and applies no transformation at all when that field is absent. * * @example `['node20.19', 'chrome111']` */ target?: UserConfig['target']; /** * tsdown's `css` option — how stylesheets are processed and emitted. * * @remarks * Shallow-merged over the project configuration, so a workspace only needs to * restate the keys it changes. * * Plugins may seed defaults here during workspace setup (e.g. the * vanilla-extract plugin sets `splitting` / `fileName`, which it needs to own * to keep its CSS pipeline intact). A value declared in the configuration * always wins over such a default — consult the plugin's documentation before * overriding a key it manages. * * `css.target` defaults to {@link UserWorkspaceConfig.target}. * * @see {@link CssOptions} */ css?: CssOptions; /** * CSS optimization options * * Disable the operation with `false`. * * @default true * * @see {@link OptimizeCSSOptions} */ optimizeCSS?: OptimizeCSSOptions | boolean; } /** * Workspace Configuration */ interface ResolvedWorkspaceConfig extends Required>, TSDownSyncOptions { /** * Configuration of all entries in the workspace * * @see {@link WorkspaceEntries} */ entries: WorkspaceEntries; /** * Hook Setting * @see {@link UserHooks} */ hooks?: UserHooks; /** * Plug-in List * @see {@link UserPluginOption} */ plugins: Plugin[]; /** * declaration output setting * @see {@link DTSSettings} */ dts?: DTSSettings; /** * Directory whose contents are copied into the output directory (`dist`), * or `false` to disable. Resolved from {@link UserWorkspaceConfig.publicDir} * (`true` → `'public'`). */ publicDir: string | false; /** * tsdown's `css` option — how stylesheets are processed and emitted. * * @see {@link CssOptions} */ css?: CssOptions; /** * CSS optimization options * * Disable the operation with `false`. * * @see {@link OptimizeCSSOptions} */ optimizeCSS: OptimizeCSSOptions | false; } type WorkspacePackageJson = RequiredPackageJSON; /** * Workspace Directory Settings */ interface WorkspaceDirs { /** Path instance of the source directory */ src: Path; /** Path instance of the distribution directory */ dist: Path; } /** * Workspace Meta Information * * @remarks This will be set to a value uniquely extended by the plugin */ interface WorkspaceMeta {} /** * Workspace setup context object * @remarks Objects that are configured when the workspace is set up. Customization can be done before the workspace instance is created by a plug-in or other process. */ interface WorkspaceSetupContext { /** Workspace directory path instance */ dir: Path; /** package.json */ json: WorkspacePackageJson; /** * Workspace Configuration * @see {@link ResolvedWorkspaceConfig} */ config: ResolvedWorkspaceConfig; /** Plugboy Project */ project: PlugboyProject | null; /** Workspace Directory Settings */ dirs: WorkspaceDirs; /** * All package names on which the workspace depends */ dependencies: string[]; /** * Names of all in-project packages on which the workspace depends */ projectDependencies: string[]; /** * Package-name prefixes collected from string `deps.neverBundle` entries. * * Used by the external-imports plugin to externalize a declared package's * subpath imports (`pkg/foo.svg`) without emitting an `UNRESOLVED_IMPORT` * warning. `RegExp` / function externals are opaque and are not collected. */ neverBundlePrefixes: string[]; /** * Workspace Meta Information * @see {@link WorkspaceMeta} */ meta: WorkspaceMeta; /** * Plugin list * @see {@link Plugin} */ plugins: Plugin[]; /** * Map of hook methods that can be initialized and called * @see {@link BuildedHooks} */ hooks: BuildedHooks; /** * declaration output setting * @see {@link NormalizedDTSSettings} */ dts: NormalizedDTSSettings; /** * tsdown's `css` option, seeded from the project and workspace * configurations. * * @remarks * Plugins may extend this during workspace setup, but must merge rather than * assign, and must let the configured value win — a plugin default belongs * *under* `...ctx.css`, never over it. * * @see {@link CssOptions} */ css?: CssOptions; /** * CSS optimization options * * Disable the operation with `false`. * * @see {@link OptimizeCSSOptions} */ optimizeCSS: OptimizeCSSOptions | false; mergeExternals(override: ExternalOption): void; mergeNoExternals(override: NoExternalOption): void; } //#endregion //#region src/types/hook.d.ts type TryGetWorkspace = () => PlugboyWorkspace | undefined; /** plugboy hook definition */ interface HookTypes { /** * Hooks during workspace setup * @remarks Called just before the workspace instance is created * @param ctx - {@link WorkspaceSetupContext Workspace setup context object} */ setupWorkspace: (ctx: WorkspaceSetupContext, getWorkspace: TryGetWorkspace) => any; /** * Hooks after workspace generation * @param workspace - {@link PlugboyWorkspace workspace instance} */ createWorkspace: (workspace: PlugboyWorkspace) => any; /** * Hooks when correcting package.json * @param json - package.json just before it was modified and saved by the plugboy * @param workspace - {@link PlugboyWorkspace workspace instance} */ preparePackageJSON: (json: WorkspacePackageJson, workspace: PlugboyWorkspace) => any; } declare function createHooksDefaults(): ResolvedHooks; type HookName = keyof HookTypes; /** * plugboy user hook definition * @see {@link HookTypes} */ type UserHooks = { [Name in HookName]?: Listable; }; /** * Pre-setup hook definitions * @see {@link HookTypes} */ type ResolvedHooks = { [Name in HookName]: HookTypes[Name][]; }; type HookArgs = Parameters; type UnPromisify = T extends Promise ? U : T; type HookReturnType = UnPromisify>; /** * Map of hook methods that can be initialized and called * @see {@link HookTypes} */ type BuildedHooks = { [Name in HookName]: (...args: HookArgs) => Promise>; }; //#endregion //#region src/types/project.d.ts declare const PROJECT_REQUIRED_FIELDS: readonly ["name"]; type ProjectRequiredField = (typeof PROJECT_REQUIRED_FIELDS)[number]; type TSConfigJSON = { compilerOptions?: CompilerOptions; } & Record; /** * Template for package.json script in workspace */ interface ProjectScriptsTemplate { /** Template Name */ name: string; /** Script Map */ scripts: Record; } /** * Project User Configuration */ interface UserProjectConfig { /** * Directory where the workspace is located * @remarks Used to create a new workspace with the `plugboy gen` CLI command. * @default packages */ workspacesDir?: string; /** * Workspace script templates, or a list of them * @remarks Used to create a new workspace with the `plugboy gen` CLI command. */ scripts?: Record | ProjectScriptsTemplate[]; /** * Workspace tsconfig template * @remarks Used to create a new workspace with the `plugboy gen` CLI command. */ tsconfig?: TSConfigJSON; /** * Workspace README template * @remarks Used to create a new workspace with the `plugboy gen` CLI command. */ readme?: (json: WorkspacePackageJson) => string; /** * Fixes the version of all peer dependencies in the project */ peerDependencies?: Record; /** * Hook Setting * @see {@link UserHooks} */ hooks?: UserHooks; /** * Plug-in List * @see {@link UserPluginOption} */ plugins?: UserPluginOption[]; /** * declaration output setting * @see {@link DTSSettings} */ dts?: DTSSettings; /** * CSS optimization options * * Disable the operation with `false`. * * @default true * * @see {@link OptimizeCSSOptions} */ optimizeCSS?: OptimizeCSSOptions | boolean; /** * tsdown's `target` option — the environment(s) the output syntax is * downleveled for. * * @remarks * Applies to every workspace in the project. A workspace that declares its * own `target` replaces this value outright (a target list describes one * environment set, so merging the two would be meaningless). * * @example `['node20.19', 'chrome111']` */ target?: UserConfig['target']; /** * tsdown's `css` option — how stylesheets are processed and emitted. * * @remarks * Applies to every workspace in the project. A workspace's own `css` is * shallow-merged over this value, so it only needs to restate the keys it * changes. * * @see {@link CssOptions} */ css?: CssOptions; } /** * Project Configuration */ interface ResolvedProjectConfig extends Required> { /** * Workspace script templates list * @remarks Used to create a new workspace with the `plugboy gen` CLI command. */ scripts: ProjectScriptsTemplate[]; /** * Workspace tsconfig template * @remarks Used to create a new workspace with the `plugboy gen` CLI command. */ tsconfig?: TSConfigJSON; /** * Hook Setting * @see {@link UserHooks} */ hooks?: UserHooks; /** * Plug-in List * @see {@link Plugin} */ plugins: Plugin[]; /** * declaration output setting * @see {@link DTSSettings} */ dts?: DTSSettings; /** * CSS optimization options * * Disable the operation with `false`. * * @see {@link OptimizeCSSOptions} */ optimizeCSS: OptimizeCSSOptions | false; /** * tsdown's `target` option applied to every workspace in the project, unless * the workspace declares its own. */ target?: UserConfig['target']; /** * tsdown's `css` option applied to every workspace in the project, with the * workspace's own `css` shallow-merged over it. */ css?: CssOptions; } type ProjectPackageJson = RequiredPackageJSON; /** * Project setup context object * @remarks Objects that are configured when the project is set up. */ interface ProjectSetupContext { /** Project directory path instance */ dir: Path; /** package.json */ json: ProjectPackageJson; /** Project Configuration */ config: ResolvedProjectConfig; /** * List of directory names of workspaces located in the project * @remarks Note that it is the directory name, not the package name. */ resolvedWorkspaces: string[]; } //#endregion //#region src/package.d.ts interface GetProjectPackageJsonResult { dir: Path; json: ProjectPackageJson; } declare function getProjectPackageJson(searchDir?: string, allowMissing?: AllowMissing): Promise; interface GetWorkspacePackageJsonResult { dir: Path; json: WorkspacePackageJson; } declare function getWorkspacePackageJson(searchDir?: string, allowMissing?: AllowMissing): Promise; declare function findWorkspacePackages(dir: string): Promise; //#endregion export { BuildedHooks, Builder, DANGLING_DTS_SOURCE_MAP_RE, DTSCompilerFunction, DTSCompilerOption, DTSNormalizer, DTSPreserveTypeSettings, DTSPreserveTypeTarget, DTSSettings, EmitDTSOptions, ExposeEntriesSettings, ExternalOption, FindConfigResult, GetProjectPackageJsonResult, GetWorkspacePackageJsonResult, HookArgs, HookName, HookReturnType, HookTypes, Listable, NoExternalOption, NormalizedDTSPreserveTypeSettings, NormalizedDTSPreserveTypeTarget, NormalizedDTSSettings, OptimizeCSSOptions, PROJECT_REQUIRED_FIELDS, Path, PlugboyProject, PlugboyWorkspace, Plugin, ProjectPackageJson, ProjectScriptsTemplate, ProjectSetupContext, RawExposeEntriesSettings, RawWorkspaceEntries, RawWorkspaceEntry, RawWorkspaceEntryObject, ResolvedHooks, ResolvedOptimizeCSSOptions, ResolvedProjectConfig, ResolvedWorkspaceConfig, TSConfigJSON, TSDOWN_SYNC_OPTIONS, TryGetWorkspace, type TsdownPlugin, UnPromisify, UserHooks, UserPluginOption, UserProjectConfig, UserWorkspaceConfig, WORKSPACE_PACKAGE_SYNC_FIELDS, WORKSPACE_REQUIRED_FIELDS, WorkspaceDirs, WorkspaceEntries, WorkspaceEntry, WorkspaceExport, WorkspaceMeta, WorkspaceObjectExport, WorkspacePackageJson, WorkspaceSetupContext, WorkspaceStubLink, WorkspaceStubLinkType, buildHooks, collectExternalStringPrefixes, copyDirSync, createHooksDefaults, definePlugin, defineProjectConfig, defineWorkspaceConfig, exitHook, exposeEntries, extractProjectPlugins, findConfig, findFile, findProjectPlugin, findWorkspacePackages, generateWorkspace, getDirname, getFilename, getProject, getProjectPackageJson, getWorkspace, getWorkspacePackageJson, isFileNotFoundException, isProjectPackageJson, isPromise, isWorkspacePackageJson, loadProjectConfig, loadWorkspaceConfig, mergeChunkAddons, mergeDTSSettingsList, mergeExternals, mergeNoExternals, normalizeDTSPreserveTypeSettings, normalizeDTSPreserveTypeTarget, normalizeDTSSettings, pathExists, resolveBundledConfigOutputFile, resolveListable, resolveOptimizeCSSOptions, resolveRawExposeEntriesSettings, resolveRawWorkspaceEntries, resolveRawWorkspaceEntry, resolveUserHooks, resolveUserPluginOption, resolveUserProjectConfig, resolveUserWorkspaceConfig, rmrf, stripDanglingDTSSourceMaps, syncWorkspacePackageFields, writeFileAtomic };