@stencil/cli 5.0.0-alpha.3 → 5.0.0-alpha.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # @stencil/cli
2
+
3
+ CLI for [Stencil](https://stenciljs.com) — build, test, and generate web components.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install --save-dev @stencil/cli @stencil/core
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```bash
14
+ # Build
15
+ npx stencil build
16
+
17
+ # Build in watch mode
18
+ npx stencil build --watch
19
+
20
+ # Run tests
21
+ npx stencil test --spec
22
+ npx stencil test --e2e
23
+
24
+ # Generate a new component
25
+ npx stencil generate my-component
26
+
27
+ # Start dev server
28
+ npx stencil build --dev --watch --serve
29
+ ```
30
+
31
+ ## Programmatic API
32
+
33
+ ### `run(init)` — invoke the CLI from code
34
+
35
+ Mirrors running `stencil <task>` in the terminal. Parse your own `args` array and Stencil handles the rest.
36
+
37
+ ```ts
38
+ import { run } from '@stencil/cli';
39
+ import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
40
+
41
+ await run({
42
+ args: ['build', '--dev', '--watch'],
43
+ logger: createNodeLogger(),
44
+ sys: createNodeSys(),
45
+ });
46
+ ```
47
+
48
+ ### `runTask(coreCompiler, config, task, sys, flags?)` — lower-level task execution
49
+
50
+ Use this when you need control over the compiler instance or config before running a task. You are responsible for loading the compiler and config yourself.
51
+
52
+ ```ts
53
+ import * as coreCompiler from '@stencil/core/compiler';
54
+ import { runTask, createConfigFlags } from '@stencil/cli';
55
+ import { createNodeLogger, createNodeSys } from '@stencil/core/sys/node';
56
+
57
+ const logger = createNodeLogger();
58
+ const sys = createNodeSys();
59
+
60
+ // Load and validate stencil.config.ts
61
+ const { config, diagnostics } = await coreCompiler.loadConfig({
62
+ configPath: './stencil.config.ts',
63
+ logger,
64
+ sys,
65
+ });
66
+ if (diagnostics.length) logger.printDiagnostics(diagnostics);
67
+
68
+ // Optional: override config flags (e.g. force dev mode)
69
+ const flags = createConfigFlags({ task: 'build', dev: true });
70
+
71
+ await runTask(coreCompiler, config, 'build', sys, flags);
72
+ ```
73
+
74
+ Valid `task` values: `'build'` | `'docs'` | `'generate'` | `'serve'` | `'prerender'` | `'test'` | `'info'` | `'migrate'` | `'init'` | `'add'` | `'telemetry'`
75
+
76
+ `flags` is optional — if omitted, defaults are derived from the task.
package/dist/index.d.mts CHANGED
@@ -1,17 +1,16 @@
1
- import * as _$_stencil_core_compiler0 from "@stencil/core/compiler";
2
- import { LogLevel } from "@stencil/core/compiler";
3
-
1
+ import * as d from "@stencil/core/compiler";
2
+ import { ConfigCompat, LogLevel, OutputTarget } from "@stencil/core/compiler";
4
3
  //#region src/types.d.ts
5
4
  /**
6
5
  * Supported CLI task commands
7
6
  */
8
- type TaskCommand = 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'migrate' | 'prerender' | 'serve' | 'telemetry' | 'test' | 'version';
7
+ type TaskCommand = 'add' | 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'init' | 'migrate' | 'prerender' | 'serve' | 'telemetry' | 'test' | 'version';
9
8
  //#endregion
10
9
  //#region src/config-flags.d.ts
11
10
  /**
12
11
  * All the Boolean options supported by the Stencil CLI
13
12
  */
14
- declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "checkVersion", "ci", "compare", "debug", "dev", "devtools", "docs", "dryRun", "esm", "help", "log", "open", "prerender", "prerenderExternal", "prod", "profile", "serviceWorker", "serve", "skipNodeCheck", "ssr", "verbose", "version", "watch"];
13
+ declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "checkVersion", "ci", "compare", "debug", "dev", "devtools", "docs", "dryRun", "help", "log", "open", "prerender", "prerenderExternal", "profile", "serviceWorker", "serve", "skipNodeCheck", "ssr", "verbose", "version", "watch"];
15
14
  /**
16
15
  * All the Number options supported by the Stencil CLI
17
16
  */
@@ -48,7 +47,7 @@ declare const LOG_LEVEL_CLI_FLAGS: readonly ["logLevel"];
48
47
  * for which we want optional keys, we make all the properties optional (w/ `'?'`)
49
48
  * and possibly null.
50
49
  */
51
- type ObjectFromKeys<K extends ReadonlyArray<string>, T> = { [key in K[number]]?: T | null };
50
+ type ObjectFromKeys<K extends ReadonlyArray<string>, T> = { [key in K[number]]?: T | null; };
52
51
  /**
53
52
  * Type containing the possible Boolean configuration flags, to be included
54
53
  * in ConfigFlags, below
@@ -123,7 +122,7 @@ declare const createConfigFlags: (init?: Partial<ConfigFlags>) => ConfigFlags;
123
122
  declare const parseFlags: (args: string[]) => ConfigFlags;
124
123
  //#endregion
125
124
  //#region src/load-compiler.d.ts
126
- type CoreCompiler = typeof _$_stencil_core_compiler0;
125
+ type CoreCompiler = typeof import('@stencil/core/compiler');
127
126
  //#endregion
128
127
  //#region src/run.d.ts
129
128
  /**
@@ -136,7 +135,7 @@ type CoreCompiler = typeof _$_stencil_core_compiler0;
136
135
  * @param init initial CLI options
137
136
  * @returns an empty promise
138
137
  */
139
- declare const run: (init: _$_stencil_core_compiler0.CliInitOptions) => Promise<any>;
138
+ declare const run: (init: d.CliInitOptions) => Promise<any>;
140
139
  /**
141
140
  * Run a specified task
142
141
  *
@@ -148,6 +147,314 @@ declare const run: (init: _$_stencil_core_compiler0.CliInitOptions) => Promise<a
148
147
  * @public
149
148
  * @returns a void promise
150
149
  */
151
- declare const runTask: (coreCompiler: CoreCompiler, config: _$_stencil_core_compiler0.Config, task: TaskCommand, sys: _$_stencil_core_compiler0.CompilerSystem, flags?: ConfigFlags) => Promise<void>;
150
+ declare const runTask: (coreCompiler: CoreCompiler, config: d.Config, task: TaskCommand, sys: d.CompilerSystem, flags?: ConfigFlags) => Promise<void>;
152
151
  //#endregion
153
- export { BOOLEAN_CLI_FLAGS, type ConfigFlags, type TaskCommand, createConfigFlags, parseFlags, run, runTask };
152
+ //#region src/wizard/types.d.ts
153
+ /**
154
+ * Stable, plugin-relevant subset of the compiler's resolved project config.
155
+ * Fields are fully resolved - paths are absolute, defaults are applied.
156
+ * Prefer this over reading `stencil.config.ts` directly.
157
+ */
158
+ interface ProjectConfig {
159
+ /** Absolute path to the project root. */
160
+ rootDir: string;
161
+ /** Absolute path to the source directory (default: `<rootDir>/src`). */
162
+ srcDir: string;
163
+ /** Component namespace, e.g. `"MyLib"`. Used in generated code and registry names. */
164
+ namespace: string;
165
+ /** Filesystem-safe namespace: `namespace.toLowerCase()` unless overridden. Used in output file/directory names. */
166
+ fsNamespace: string;
167
+ /** Fully resolved output targets with all defaults applied. */
168
+ outputTargets: ReadonlyArray<OutputTarget>;
169
+ /** Absolute path to the global script, if configured. */
170
+ globalScript?: string;
171
+ /** Absolute path to the global stylesheet, if configured. */
172
+ globalStyle?: string;
173
+ /** Backwards-compatibility flags (`compat` in stencil.config.ts). */
174
+ compat?: ConfigCompat;
175
+ /** Enable signal-based reactivity backing (top-level in stencil.config.ts). */
176
+ signalBacking?: boolean;
177
+ }
178
+ /**
179
+ * Structured editor for `stencil.config.ts`, backed by the TypeScript compiler API.
180
+ * Obtain one via {@link WizardContext.openStencilConfig}.
181
+ *
182
+ * All mutation methods accumulate edits in memory. Call {@link save} once to
183
+ * write them all back to disk in a single pass.
184
+ *
185
+ * @example
186
+ * const editor = await ctx.openStencilConfig();
187
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
188
+ * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
189
+ * await editor.save();
190
+ */
191
+ interface StencilConfigEditor {
192
+ /**
193
+ * Returns `true` if any import from `moduleSpecifier` already exists in the file.
194
+ *
195
+ * @example
196
+ * if (!editor.hasImport('@stencil/vue-output-target')) {
197
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
198
+ * }
199
+ */
200
+ hasImport(moduleSpecifier: string): boolean;
201
+ /**
202
+ * Adds `import { ...namedImports } from 'moduleSpecifier'` after the last
203
+ * existing import in the file. No-op if any import from `moduleSpecifier`
204
+ * already exists.
205
+ *
206
+ * @param moduleSpecifier - The module to import from, e.g. `'@stencil/sass'`.
207
+ * @param namedImports - At least one named export to import.
208
+ *
209
+ * @example
210
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
211
+ * // > import { vueOutputTarget } from '@stencil/vue-output-target';
212
+ *
213
+ * @example
214
+ * editor.addImport('@stencil/sass', ['sass']);
215
+ * // > import { sass } from '@stencil/sass';
216
+ */
217
+ addImport(moduleSpecifier: string, namedImports: [string, ...string[]]): void;
218
+ /**
219
+ * Returns `true` if `substring` appears anywhere in the text of the
220
+ * `outputTargets` array. Use this to guard against adding the same target twice.
221
+ *
222
+ * @example
223
+ * if (!editor.outputTargetsContains('vueOutputTarget(')) {
224
+ * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
225
+ * }
226
+ */
227
+ outputTargetsContains(substring: string): boolean;
228
+ /**
229
+ * Appends `expression` as a new element in the `outputTargets` array,
230
+ * creating the `outputTargets` property if it is absent from the config.
231
+ *
232
+ * `expression` is a TypeScript expression that is inserted verbatim into
233
+ * the source file. It must evaluate to a value assignable to {@link OutputTarget}
234
+ * - built-in targets use object literal syntax (e.g. `"{ type: 'standalone' }"`),
235
+ * while third-party targets are function calls that return `OutputTargetCustom`
236
+ * (e.g. `"vueOutputTarget({...})"`). Call {@link addImport} first to bring the
237
+ * factory function into scope.
238
+ *
239
+ * @param expression - A TypeScript expression, e.g. `"{ type: 'standalone' }"`
240
+ * or `"vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"`.
241
+ *
242
+ * @example
243
+ * // Built-in target (object literal):
244
+ * editor.addOutputTarget("{ type: 'standalone' }");
245
+ *
246
+ * @example
247
+ * // Third-party target (OutputTargetCustom - add the import first):
248
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
249
+ * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
250
+ */
251
+ addOutputTarget(expression: string): void;
252
+ /**
253
+ * Replaces the first element in the `outputTargets` array whose text contains
254
+ * `substring` with `expression` in-place. Returns `true` if a match was found
255
+ * and replaced, `false` if no element contained `substring`.
256
+ *
257
+ * Useful for the reconfigure flow — the replaced target stays at the same
258
+ * position in the array rather than being moved to the end.
259
+ *
260
+ * @example
261
+ * // Replace if already configured, otherwise append:
262
+ * if (!editor.replaceOutputTarget('vueOutputTarget(', newExpression)) {
263
+ * editor.addOutputTarget(newExpression);
264
+ * }
265
+ */
266
+ replaceOutputTarget(substring: string, expression: string): boolean;
267
+ /**
268
+ * Removes the first element in the `outputTargets` array whose text contains
269
+ * `substring`. Returns `true` if an element was removed, `false` if no match
270
+ * was found.
271
+ *
272
+ * @example
273
+ * editor.removeOutputTarget('vueOutputTarget(');
274
+ */
275
+ removeOutputTarget(substring: string): boolean;
276
+ /**
277
+ * Returns `true` if `substring` appears anywhere in the text of the
278
+ * `plugins` array. Use this to guard against adding the same plugin twice.
279
+ *
280
+ * @example
281
+ * if (!editor.pluginsContains('sass(')) {
282
+ * editor.addPlugin('sass()');
283
+ * }
284
+ */
285
+ pluginsContains(substring: string): boolean;
286
+ /**
287
+ * Appends `expression` as a new element in the `plugins` array,
288
+ * creating the `plugins` property if it is absent from the config.
289
+ *
290
+ * `expression` is a TypeScript expression that is inserted verbatim into
291
+ * the source file. Call {@link addImport} first to bring the plugin factory
292
+ * into scope.
293
+ *
294
+ * @param expression - A TypeScript expression, e.g. `'sass()'` or
295
+ * `"sass({ injectGlobalPaths: ['src/global/variables.scss'] })"`.
296
+ *
297
+ * @example
298
+ * editor.addImport('@stencil/sass', ['sass']);
299
+ * editor.addPlugin('sass()');
300
+ *
301
+ * @example
302
+ * editor.addImport('@stencil/sass', ['sass']);
303
+ * editor.addPlugin("sass({ injectGlobalPaths: ['src/global/variables.scss'] })");
304
+ */
305
+ addPlugin(expression: string): void;
306
+ /**
307
+ * Replaces the first element in the `plugins` array whose text contains
308
+ * `substring` with `expression` in-place. Returns `true` if a match was found
309
+ * and replaced, `false` if no element contained `substring`.
310
+ *
311
+ * @example
312
+ * if (!editor.replacePlugin('sass(', newSassCall)) {
313
+ * editor.addPlugin(newSassCall);
314
+ * }
315
+ */
316
+ replacePlugin(substring: string, expression: string): boolean;
317
+ /**
318
+ * Removes the first element in the `plugins` array whose text contains
319
+ * `substring`. Returns `true` if an element was removed, `false` if no match
320
+ * was found.
321
+ *
322
+ * @example
323
+ * editor.removePlugin('sass(');
324
+ */
325
+ removePlugin(substring: string): boolean;
326
+ /** Write all accumulated edits back to disk. */
327
+ save(): Promise<void>;
328
+ }
329
+ /**
330
+ * Context passed to wizard steps at runtime.
331
+ */
332
+ interface WizardContext {
333
+ /** True when `stencil.config.ts` did not previously exist (fresh scaffold). */
334
+ isNewProject: boolean;
335
+ /** Clack prompts - use instead of importing `@clack/prompts` directly for consistent UX. */
336
+ prompts: typeof import('@clack/prompts');
337
+ /** nypm - use instead of importing `nypm` directly so the package manager is auto-detected. */
338
+ nypm: typeof import('nypm');
339
+ /** Resolved project config. See {@link ProjectConfig} for available fields. */
340
+ config: ProjectConfig;
341
+ /**
342
+ * Absolute path to the monorepo workspace root when the project is part of a
343
+ * workspace, `undefined` for single-package projects.
344
+ *
345
+ * When present, `config.rootDir` is the core Stencil package (e.g.
346
+ * `<workspaceRoot>/packages/core/`). The plugin is responsible for deciding
347
+ * where in the workspace it wants to live and for creating that directory.
348
+ */
349
+ workspaceRoot?: string;
350
+ /**
351
+ * Open the project's `stencil.config.ts` for structured editing.
352
+ * Use the returned {@link StencilConfigEditor} to add imports, output targets,
353
+ * and plugins, then call `save()` to persist.
354
+ *
355
+ * Use {@link ts} directly when you need to manipulate other files or perform
356
+ * operations the editor does not cover.
357
+ */
358
+ openStencilConfig: () => Promise<StencilConfigEditor>;
359
+ /**
360
+ * TypeScript compiler API. Available for advanced AST manipulation beyond
361
+ * what {@link openStencilConfig} covers.
362
+ */
363
+ ts: typeof import('typescript');
364
+ }
365
+ /**
366
+ * A single file a plugin can offer during `stencil generate`.
367
+ */
368
+ interface WizardFileTemplate {
369
+ /** Label shown in the generate prompt checkbox, e.g. `"Spec Test (.spec.tsx)"`. */
370
+ label: string;
371
+ /**
372
+ * File extension used to derive the filename and deduplicate contributions,
373
+ * e.g. `"spec.tsx"` or `"e2e.ts"`.
374
+ */
375
+ extension: string;
376
+ /**
377
+ * Subdirectory within the component directory where the file is placed.
378
+ * e.g. `'test'` to place alongside other test files. Omit for the component root.
379
+ */
380
+ subdirectory?: string;
381
+ /**
382
+ * Returns the file content. `className` is the PascalCase form of `tagName`.
383
+ */
384
+ template: (tagName: string, className: string) => string;
385
+ /** Pre-selected in the generate prompt. Defaults to `true`. */
386
+ selectedByDefault?: boolean;
387
+ }
388
+ /**
389
+ * Context passed to dynamic `fileTemplates` resolvers during `stencil generate`.
390
+ */
391
+ interface GenerateContext {
392
+ /** The dash-case component tag name entered by the user. */
393
+ tagName: string;
394
+ /** Resolved project config. See {@link ProjectConfig} for available fields. */
395
+ config: ProjectConfig;
396
+ /** Clack prompts - use instead of importing `@clack/prompts` directly for consistent UX. */
397
+ prompts: typeof import('@clack/prompts');
398
+ /** nypm - use instead of importing `nypm` directly so the package manager is auto-detected. */
399
+ nypm: typeof import('nypm');
400
+ }
401
+ /**
402
+ * Contribution a package can make to `stencil generate`.
403
+ */
404
+ interface WizardGenerateContribution {
405
+ /**
406
+ * Files this plugin can generate alongside the component.
407
+ *
408
+ * May be a static array or an async function that receives project context
409
+ * (e.g. to read `vitest.config.ts` and offer one template per configured
410
+ * Vitest project). Called after the user enters the component tag name.
411
+ */
412
+ fileTemplates?: ReadonlyArray<WizardFileTemplate> | ((ctx: GenerateContext) => ReadonlyArray<WizardFileTemplate> | Promise<ReadonlyArray<WizardFileTemplate>>);
413
+ /**
414
+ * Additional style extensions this package supports (e.g. `['sass', 'scss']`
415
+ * from `@stencil/sass`). The first entry is used as the default.
416
+ */
417
+ styleExtensions?: ReadonlyArray<string>;
418
+ }
419
+ /**
420
+ * Contribution a package can make to `stencil init`.
421
+ *
422
+ * The plugin owns its entire setup: prompts, peer dep installs, config file
423
+ * generation, example files, package.json script updates, etc.
424
+ */
425
+ interface WizardInitContribution {
426
+ /** Stable identifier used to deduplicate across re-runs. */
427
+ id: string;
428
+ /** Human-readable name shown in the prompt list. */
429
+ displayName: string;
430
+ /** One-line description shown alongside the name. */
431
+ description: string;
432
+ /**
433
+ * Called by the CLI after packages are installed. The plugin is responsible
434
+ * for all further setup: additional prompts, peer dep installs, config file
435
+ * writes, example tests, `.gitignore` and `package.json` script updates, etc.
436
+ */
437
+ run: (context: WizardContext) => Promise<void>;
438
+ }
439
+ /**
440
+ * Interface a package exports to participate in `stencil init` and/or
441
+ * `stencil generate`.
442
+ *
443
+ * Declare the entry point in `package.json`:
444
+ * ```json
445
+ * { "stencil": { "wizard": "./dist/wizard.js" } }
446
+ * ```
447
+ *
448
+ * Export a named `wizard` constant from that module:
449
+ * ```ts
450
+ * export const wizard: StencilWizardPlugin = { ... };
451
+ * ```
452
+ */
453
+ interface StencilWizardPlugin {
454
+ /** Contributions to `stencil generate`. */
455
+ generate?: WizardGenerateContribution;
456
+ /** Contributions to `stencil init`. */
457
+ init?: WizardInitContribution;
458
+ }
459
+ //#endregion
460
+ 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 };