import * as d from "@stencil/core/compiler"; import { ConfigCompat, LogLevel, OutputTarget } from "@stencil/core/compiler"; //#region src/types.d.ts /** * Supported CLI task commands */ type TaskCommand = 'add' | 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'init' | 'migrate' | 'prerender' | 'serve' | 'telemetry' | 'version'; //#endregion //#region src/config-flags.d.ts /** * All the Boolean options supported by the Stencil CLI */ declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "ci", "debug", "dev", "docs", "dryRun", "help", "log", "open", "prerender", "profile", "serviceWorker", "serve", "ssr", "verbose", "version", "watch"]; /** * All the Number options supported by the Stencil CLI */ declare const NUMBER_CLI_FLAGS: readonly ["port"]; /** * All the String options supported by the Stencil CLI */ declare const STRING_CLI_FLAGS: readonly ["address", "config", "docsJson", "root"]; declare const STRING_ARRAY_CLI_FLAGS: readonly []; /** * All the CLI arguments which may have string or number values * * `maxWorkers` controls the number of concurrent workers for Stencil builds. * Supports both string (e.g., "50%") and number values. */ declare const STRING_NUMBER_CLI_FLAGS: readonly ["maxWorkers"]; /** * All the CLI arguments which may have boolean or string values. */ declare const BOOLEAN_STRING_CLI_FLAGS: readonly ["stats"]; /** * All the LogLevel-type options supported by the Stencil CLI * * This is a bit silly since there's only one such argument atm, * but this approach lets us make sure that we're handling all * our arguments in a type-safe way. */ declare const LOG_LEVEL_CLI_FLAGS: readonly ["logLevel"]; /** * Given two types `K` and `T` where `K` extends `ReadonlyArray`, * construct a type which maps the strings in `K` as keys to values of type `T`. * * Because we use types derived this way to construct an interface (`ConfigFlags`) * for which we want optional keys, we make all the properties optional (w/ `'?'`) * and possibly null. */ type ObjectFromKeys, T> = { [key in K[number]]?: T | null; }; /** * Type containing the possible Boolean configuration flags, to be included * in ConfigFlags, below */ type BooleanConfigFlags = ObjectFromKeys; /** * Type containing the possible String configuration flags, to be included * in ConfigFlags, below */ type StringConfigFlags = ObjectFromKeys; /** * Type containing the possible String Array configuration flags. This is * one of the 'constituent types' for `ConfigFlags`. */ type StringArrayConfigFlags = ObjectFromKeys; /** * Type containing the possible numeric configuration flags, to be included * in ConfigFlags, below */ type NumberConfigFlags = ObjectFromKeys; /** * Type containing the configuration flags which may be set to either string * or number values. */ type StringNumberConfigFlags = ObjectFromKeys; /** * Type containing the configuration flags which may be set to either string * or boolean values. */ type BooleanStringConfigFlags = ObjectFromKeys; /** * Type containing the possible LogLevel configuration flags, to be included * in ConfigFlags, below */ type LogLevelFlags = ObjectFromKeys; /** * The configuration flags which can be set by the user on the command line. * This interface captures both known arguments (which are enumerated and then * parsed according to their types) and unknown arguments which the user may * pass at the CLI. * * Note that this interface is constructed by extending `BooleanConfigFlags`, * `StringConfigFlags`, etc. These types are in turn constructed from types * extending `ReadonlyArray` which we declare in another module. This * allows us to record our known CLI arguments in one place, using a * `ReadonlyArray` to get both a type-level representation of what CLI * options we support and a runtime list of strings which can be used to match * on actual flags passed by the user. */ interface ConfigFlags extends BooleanConfigFlags, StringConfigFlags, StringArrayConfigFlags, NumberConfigFlags, StringNumberConfigFlags, BooleanStringConfigFlags, LogLevelFlags { task: TaskCommand | null; args: string[]; knownArgs: string[]; unknownArgs: string[]; } /** * Helper function for initializing a `ConfigFlags` object. Provide any overrides * for default values and off you go! * * @param init an object with any overrides for default values * @returns a complete CLI flag object */ declare const createConfigFlags: (init?: Partial) => ConfigFlags; //#endregion //#region src/parse-flags.d.ts /** * Parse command line arguments into a structured `ConfigFlags` object * * @param args an array of CLI flags * @returns a structured ConfigFlags object */ declare const parseFlags: (args: string[]) => ConfigFlags; //#endregion //#region src/load-compiler.d.ts type CoreCompiler = typeof import('@stencil/core/compiler'); //#endregion //#region src/run.d.ts /** * Main entry point for the Stencil CLI * * Take care of parsing CLI arguments, initializing various components needed * by the rest of the program, and kicking off the correct task (build, test, * etc). * * @param init initial CLI options * @returns an empty promise */ declare const run: (init: d.CliInitOptions) => Promise; /** * Run a specified task * * @param coreCompiler an instance of a minimal, bootstrap compiler for running the specified task * @param config a configuration for the Stencil project to apply to the task run * @param task the task to run * @param sys the {@link d.CompilerSystem} for interacting with the operating system * @param flags the parsed CLI flags (owned by CLI, not passed to Core) * @public * @returns a void promise */ declare const runTask: (coreCompiler: CoreCompiler, config: d.Config, task: TaskCommand, sys: d.CompilerSystem, flags?: ConfigFlags) => Promise; //#endregion //#region src/wizard/types.d.ts /** * Stable, plugin-relevant subset of the compiler's resolved project config. * Fields are fully resolved - paths are absolute, defaults are applied. * Prefer this over reading `stencil.config.ts` directly. */ interface ProjectConfig { /** Absolute path to the project root. */ rootDir: string; /** Absolute path to the source directory (default: `/src`). */ srcDir: string; /** Component namespace, e.g. `"MyLib"`. Used in generated code and registry names. */ namespace: string; /** Filesystem-safe namespace: `namespace.toLowerCase()` unless overridden. Used in output file/directory names. */ fsNamespace: string; /** Fully resolved output targets with all defaults applied. */ outputTargets: ReadonlyArray; /** Absolute path to the global script, if configured. */ globalScript?: string; /** Absolute path to the global stylesheet, if configured. */ globalStyle?: string; /** Backwards-compatibility flags (`compat` in stencil.config.ts). */ compat?: ConfigCompat; /** Enable signal-based reactivity backing (top-level in stencil.config.ts). */ signalBacking?: boolean; } /** * Structured editor for `stencil.config.ts`, backed by the TypeScript compiler API. * Obtain one via {@link WizardContext.openStencilConfig}. * * All mutation methods accumulate edits in memory. Call {@link save} once to * write them all back to disk in a single pass. * * @example * const editor = await ctx.openStencilConfig(); * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']); * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"); * await editor.save(); */ interface StencilConfigEditor { /** * Returns `true` if any import from `moduleSpecifier` already exists in the file. * * @example * if (!editor.hasImport('@stencil/vue-output-target')) { * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']); * } */ hasImport(moduleSpecifier: string): boolean; /** * Adds `import { ...namedImports } from 'moduleSpecifier'` after the last * existing import in the file. No-op if any import from `moduleSpecifier` * already exists. * * @param moduleSpecifier - The module to import from, e.g. `'@stencil/sass'`. * @param namedImports - At least one named export to import. * * @example * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']); * // > import { vueOutputTarget } from '@stencil/vue-output-target'; * * @example * editor.addImport('@stencil/sass', ['sass']); * // > import { sass } from '@stencil/sass'; */ addImport(moduleSpecifier: string, namedImports: [string, ...string[]]): void; /** * Returns `true` if `substring` appears anywhere in the text of the * `outputTargets` array. Use this to guard against adding the same target twice. * * @example * if (!editor.outputTargetsContains('vueOutputTarget(')) { * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"); * } */ outputTargetsContains(substring: string): boolean; /** * Appends `expression` as a new element in the `outputTargets` array, * creating the `outputTargets` property if it is absent from the config. * * `expression` is a TypeScript expression that is inserted verbatim into * the source file. It must evaluate to a value assignable to {@link OutputTarget} * - built-in targets use object literal syntax (e.g. `"{ type: 'standalone' }"`), * while third-party targets are function calls that return `OutputTargetCustom` * (e.g. `"vueOutputTarget({...})"`). Call {@link addImport} first to bring the * factory function into scope. * * @param expression - A TypeScript expression, e.g. `"{ type: 'standalone' }"` * or `"vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"`. * * @example * // Built-in target (object literal): * editor.addOutputTarget("{ type: 'standalone' }"); * * @example * // Third-party target (OutputTargetCustom - add the import first): * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']); * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"); */ addOutputTarget(expression: string): void; /** * Replaces the first element in the `outputTargets` array whose text contains * `substring` with `expression` in-place. Returns `true` if a match was found * and replaced, `false` if no element contained `substring`. * * Useful for the reconfigure flow — the replaced target stays at the same * position in the array rather than being moved to the end. * * @example * // Replace if already configured, otherwise append: * if (!editor.replaceOutputTarget('vueOutputTarget(', newExpression)) { * editor.addOutputTarget(newExpression); * } */ replaceOutputTarget(substring: string, expression: string): boolean; /** * Removes the first element in the `outputTargets` array whose text contains * `substring`. Returns `true` if an element was removed, `false` if no match * was found. * * @example * editor.removeOutputTarget('vueOutputTarget('); */ removeOutputTarget(substring: string): boolean; /** * Returns `true` if `substring` appears anywhere in the text of the * `plugins` array. Use this to guard against adding the same plugin twice. * * @example * if (!editor.pluginsContains('sass(')) { * editor.addPlugin('sass()'); * } */ pluginsContains(substring: string): boolean; /** * Appends `expression` as a new element in the `plugins` array, * creating the `plugins` property if it is absent from the config. * * `expression` is a TypeScript expression that is inserted verbatim into * the source file. Call {@link addImport} first to bring the plugin factory * into scope. * * @param expression - A TypeScript expression, e.g. `'sass()'` or * `"sass({ injectGlobalPaths: ['src/global/variables.scss'] })"`. * * @example * editor.addImport('@stencil/sass', ['sass']); * editor.addPlugin('sass()'); * * @example * editor.addImport('@stencil/sass', ['sass']); * editor.addPlugin("sass({ injectGlobalPaths: ['src/global/variables.scss'] })"); */ addPlugin(expression: string): void; /** * Replaces the first element in the `plugins` array whose text contains * `substring` with `expression` in-place. Returns `true` if a match was found * and replaced, `false` if no element contained `substring`. * * @example * if (!editor.replacePlugin('sass(', newSassCall)) { * editor.addPlugin(newSassCall); * } */ replacePlugin(substring: string, expression: string): boolean; /** * Removes the first element in the `plugins` array whose text contains * `substring`. Returns `true` if an element was removed, `false` if no match * was found. * * @example * editor.removePlugin('sass('); */ removePlugin(substring: string): boolean; /** Write all accumulated edits back to disk. */ save(): Promise; } /** * Context passed to wizard steps at runtime. */ interface WizardContext { /** True when `stencil.config.ts` did not previously exist (fresh scaffold). */ isNewProject: boolean; /** Clack prompts - use instead of importing `@clack/prompts` directly for consistent UX. */ prompts: typeof import('@clack/prompts'); /** nypm - use instead of importing `nypm` directly so the package manager is auto-detected. */ nypm: typeof import('nypm'); /** Resolved project config. See {@link ProjectConfig} for available fields. */ config: ProjectConfig; /** * Absolute path to the monorepo workspace root when the project is part of a * workspace, `undefined` for single-package projects. * * When present, `config.rootDir` is the core Stencil package (e.g. * `/packages/core/`). The plugin is responsible for deciding * where in the workspace it wants to live and for creating that directory. */ workspaceRoot?: string; /** * Open the project's `stencil.config.ts` for structured editing. * Use the returned {@link StencilConfigEditor} to add imports, output targets, * and plugins, then call `save()` to persist. * * Use {@link ts} directly when you need to manipulate other files or perform * operations the editor does not cover. */ openStencilConfig: () => Promise; /** * TypeScript compiler API. Available for advanced AST manipulation beyond * what {@link openStencilConfig} covers. */ ts: typeof import('typescript'); } /** * A single file a plugin can offer during `stencil generate`. */ interface WizardFileTemplate { /** Label shown in the generate prompt checkbox, e.g. `"Spec Test (.spec.tsx)"`. */ label: string; /** * File extension used to derive the filename and deduplicate contributions, * e.g. `"spec.tsx"` or `"e2e.ts"`. */ extension: string; /** * Subdirectory within the component directory where the file is placed. * e.g. `'test'` to place alongside other test files. Omit for the component root. */ subdirectory?: string; /** * Returns the file content. `className` is the PascalCase form of `tagName`. */ template: (tagName: string, className: string) => string; /** Pre-selected in the generate prompt. Defaults to `true`. */ selectedByDefault?: boolean; } /** * Context passed to dynamic `fileTemplates` resolvers during `stencil generate`. */ interface GenerateContext { /** The dash-case component tag name entered by the user. */ tagName: string; /** Resolved project config. See {@link ProjectConfig} for available fields. */ config: ProjectConfig; /** Clack prompts - use instead of importing `@clack/prompts` directly for consistent UX. */ prompts: typeof import('@clack/prompts'); /** nypm - use instead of importing `nypm` directly so the package manager is auto-detected. */ nypm: typeof import('nypm'); } /** * Contribution a package can make to `stencil generate`. */ interface WizardGenerateContribution { /** * Files this plugin can generate alongside the component. * * May be a static array or an async function that receives project context * (e.g. to read `vitest.config.ts` and offer one template per configured * Vitest project). Called after the user enters the component tag name. */ fileTemplates?: ReadonlyArray | ((ctx: GenerateContext) => ReadonlyArray | Promise>); /** * Additional style extensions this package supports (e.g. `['sass', 'scss']` * from `@stencil/sass`). The first entry is used as the default. */ styleExtensions?: ReadonlyArray; } /** * Contribution a package can make to `stencil init`. * * The plugin owns its entire setup: prompts, peer dep installs, config file * generation, example files, package.json script updates, etc. */ interface WizardInitContribution { /** Stable identifier used to deduplicate across re-runs. */ id: string; /** Human-readable name shown in the prompt list. */ displayName: string; /** One-line description shown alongside the name. */ description: string; /** * Called by the CLI after packages are installed. The plugin is responsible * for all further setup: additional prompts, peer dep installs, config file * writes, example tests, `.gitignore` and `package.json` script updates, etc. */ run: (context: WizardContext) => Promise; } /** * Interface a package exports to participate in `stencil init` and/or * `stencil generate`. * * Declare the entry point in `package.json`: * ```json * { "stencil": { "wizard": "./dist/wizard.js" } } * ``` * * Export a named `wizard` constant from that module: * ```ts * export const wizard: StencilWizardPlugin = { ... }; * ``` */ interface StencilWizardPlugin { /** Contributions to `stencil generate`. */ generate?: WizardGenerateContribution; /** Contributions to `stencil init`. */ init?: WizardInitContribution; } //#endregion export { BOOLEAN_CLI_FLAGS, type ConfigFlags, type GenerateContext, type ProjectConfig, type StencilConfigEditor, type StencilWizardPlugin, type TaskCommand, type WizardContext, type WizardFileTemplate, type WizardGenerateContribution, type WizardInitContribution, createConfigFlags, parseFlags, run, runTask };