@stencil/cli 5.0.0-alpha.2 → 5.0.0-alpha.21

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,37 +1,37 @@
1
- import * as _$_stencil_core_compiler0 from "@stencil/core/compiler";
2
- import { LogLevel } from "@stencil/core/compiler";
1
+ import * as d from "@stencil/core/compiler";
2
+ import { ConfigCompat, LogLevel, OutputTarget } from "@stencil/core/compiler";
3
3
 
4
4
  //#region src/types.d.ts
5
5
  /**
6
6
  * Supported CLI task commands
7
7
  */
8
- type TaskCommand = 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'prerender' | 'serve' | 'telemetry' | 'test' | 'version';
8
+ type TaskCommand = 'add' | 'build' | 'docs' | 'generate' | 'g' | 'help' | 'info' | 'init' | 'migrate' | 'prerender' | 'serve' | 'telemetry' | 'test' | 'version';
9
9
  //#endregion
10
10
  //#region src/config-flags.d.ts
11
11
  /**
12
12
  * All the Boolean options supported by the Stencil CLI
13
13
  */
14
- declare const BOOLEAN_CLI_FLAGS: readonly ["build", "cache", "checkVersion", "ci", "compare", "debug", "dev", "devtools", "docs", "e2e", "es5", "esm", "help", "log", "open", "prerender", "prerenderExternal", "prod", "profile", "serviceWorker", "screenshot", "serve", "skipNodeCheck", "spec", "ssr", "updateScreenshot", "verbose", "version", "watch", "all", "automock", "bail", "changedFilesWithAncestor", "clearCache", "clearMocks", "collectCoverage", "color", "colors", "coverage", "detectLeaks", "detectOpenHandles", "errorOnDeprecated", "expand", "findRelatedTests", "forceExit", "init", "injectGlobals", "json", "lastCommit", "listTests", "logHeapUsage", "noStackTrace", "notify", "onlyChanged", "onlyFailures", "passWithNoTests", "resetMocks", "resetModules", "restoreMocks", "runInBand", "runTestsByPath", "showConfig", "silent", "skipFilter", "testLocationInResults", "updateSnapshot", "useStderr", "watchAll", "watchman"];
14
+ 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
15
  /**
16
16
  * All the Number options supported by the Stencil CLI
17
17
  */
18
- declare const NUMBER_CLI_FLAGS: readonly ["port", "maxConcurrency", "testTimeout"];
18
+ declare const NUMBER_CLI_FLAGS: readonly ["port"];
19
19
  /**
20
20
  * All the String options supported by the Stencil CLI
21
21
  */
22
- declare const STRING_CLI_FLAGS: readonly ["address", "config", "docsApi", "docsJson", "emulate", "root", "screenshotConnector", "cacheDirectory", "changedSince", "collectCoverageFrom", "coverageDirectory", "coverageThreshold", "env", "filter", "globalSetup", "globalTeardown", "globals", "haste", "moduleNameMapper", "notifyMode", "outputFile", "preset", "prettierPath", "resolver", "rootDir", "runner", "testEnvironment", "testEnvironmentOptions", "testFailureExitCode", "testNamePattern", "testResultsProcessor", "testRunner", "testSequencer", "testURL", "timers", "transform"];
23
- declare const STRING_ARRAY_CLI_FLAGS: readonly ["collectCoverageOnlyFrom", "coveragePathIgnorePatterns", "coverageReporters", "moduleDirectories", "moduleFileExtensions", "modulePathIgnorePatterns", "modulePaths", "projects", "reporters", "roots", "selectProjects", "setupFiles", "setupFilesAfterEnv", "snapshotSerializers", "testMatch", "testPathIgnorePatterns", "testPathPattern", "testRegex", "transformIgnorePatterns", "unmockedModulePathPatterns", "watchPathIgnorePatterns"];
22
+ declare const STRING_CLI_FLAGS: readonly ["address", "config", "docsApi", "docsJson", "emulate", "root"];
23
+ declare const STRING_ARRAY_CLI_FLAGS: readonly [];
24
24
  /**
25
25
  * All the CLI arguments which may have string or number values
26
26
  *
27
- * `maxWorkers` is an argument which is used both by Stencil _and_ by Jest,
28
- * which means that we need to support parsing both string and number values.
27
+ * `maxWorkers` controls the number of concurrent workers for Stencil builds.
28
+ * Supports both string (e.g., "50%") and number values.
29
29
  */
30
30
  declare const STRING_NUMBER_CLI_FLAGS: readonly ["maxWorkers"];
31
31
  /**
32
32
  * All the CLI arguments which may have boolean or string values.
33
33
  */
34
- declare const BOOLEAN_STRING_CLI_FLAGS: readonly ["headless", "stats"];
34
+ declare const BOOLEAN_STRING_CLI_FLAGS: readonly ["stats"];
35
35
  /**
36
36
  * All the LogLevel-type options supported by the Stencil CLI
37
37
  *
@@ -123,7 +123,7 @@ declare const createConfigFlags: (init?: Partial<ConfigFlags>) => ConfigFlags;
123
123
  declare const parseFlags: (args: string[]) => ConfigFlags;
124
124
  //#endregion
125
125
  //#region src/load-compiler.d.ts
126
- type CoreCompiler = typeof _$_stencil_core_compiler0;
126
+ type CoreCompiler = typeof import('@stencil/core/compiler');
127
127
  //#endregion
128
128
  //#region src/run.d.ts
129
129
  /**
@@ -136,7 +136,7 @@ type CoreCompiler = typeof _$_stencil_core_compiler0;
136
136
  * @param init initial CLI options
137
137
  * @returns an empty promise
138
138
  */
139
- declare const run: (init: _$_stencil_core_compiler0.CliInitOptions) => Promise<any>;
139
+ declare const run: (init: d.CliInitOptions) => Promise<any>;
140
140
  /**
141
141
  * Run a specified task
142
142
  *
@@ -148,6 +148,314 @@ declare const run: (init: _$_stencil_core_compiler0.CliInitOptions) => Promise<a
148
148
  * @public
149
149
  * @returns a void promise
150
150
  */
151
- declare const runTask: (coreCompiler: CoreCompiler, config: _$_stencil_core_compiler0.Config, task: TaskCommand, sys: _$_stencil_core_compiler0.CompilerSystem, flags?: ConfigFlags) => Promise<void>;
151
+ declare const runTask: (coreCompiler: CoreCompiler, config: d.Config, task: TaskCommand, sys: d.CompilerSystem, flags?: ConfigFlags) => Promise<void>;
152
152
  //#endregion
153
- export { BOOLEAN_CLI_FLAGS, type ConfigFlags, type TaskCommand, createConfigFlags, parseFlags, run, runTask };
153
+ //#region src/wizard/types.d.ts
154
+ /**
155
+ * Stable, plugin-relevant subset of the compiler's resolved project config.
156
+ * Fields are fully resolved - paths are absolute, defaults are applied.
157
+ * Prefer this over reading `stencil.config.ts` directly.
158
+ */
159
+ interface ProjectConfig {
160
+ /** Absolute path to the project root. */
161
+ rootDir: string;
162
+ /** Absolute path to the source directory (default: `<rootDir>/src`). */
163
+ srcDir: string;
164
+ /** Component namespace, e.g. `"MyLib"`. Used in generated code and registry names. */
165
+ namespace: string;
166
+ /** Filesystem-safe namespace: `namespace.toLowerCase()` unless overridden. Used in output file/directory names. */
167
+ fsNamespace: string;
168
+ /** Fully resolved output targets with all defaults applied. */
169
+ outputTargets: ReadonlyArray<OutputTarget>;
170
+ /** Absolute path to the global script, if configured. */
171
+ globalScript?: string;
172
+ /** Absolute path to the global stylesheet, if configured. */
173
+ globalStyle?: string;
174
+ /** Backwards-compatibility flags (`compat` in stencil.config.ts). */
175
+ compat?: ConfigCompat;
176
+ /** Enable signal-based reactivity backing (top-level in stencil.config.ts). */
177
+ signalBacking?: boolean;
178
+ }
179
+ /**
180
+ * Structured editor for `stencil.config.ts`, backed by the TypeScript compiler API.
181
+ * Obtain one via {@link WizardContext.openStencilConfig}.
182
+ *
183
+ * All mutation methods accumulate edits in memory. Call {@link save} once to
184
+ * write them all back to disk in a single pass.
185
+ *
186
+ * @example
187
+ * const editor = await ctx.openStencilConfig();
188
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
189
+ * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
190
+ * await editor.save();
191
+ */
192
+ interface StencilConfigEditor {
193
+ /**
194
+ * Returns `true` if any import from `moduleSpecifier` already exists in the file.
195
+ *
196
+ * @example
197
+ * if (!editor.hasImport('@stencil/vue-output-target')) {
198
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
199
+ * }
200
+ */
201
+ hasImport(moduleSpecifier: string): boolean;
202
+ /**
203
+ * Adds `import { ...namedImports } from 'moduleSpecifier'` after the last
204
+ * existing import in the file. No-op if any import from `moduleSpecifier`
205
+ * already exists.
206
+ *
207
+ * @param moduleSpecifier - The module to import from, e.g. `'@stencil/sass'`.
208
+ * @param namedImports - At least one named export to import.
209
+ *
210
+ * @example
211
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
212
+ * // > import { vueOutputTarget } from '@stencil/vue-output-target';
213
+ *
214
+ * @example
215
+ * editor.addImport('@stencil/sass', ['sass']);
216
+ * // > import { sass } from '@stencil/sass';
217
+ */
218
+ addImport(moduleSpecifier: string, namedImports: [string, ...string[]]): void;
219
+ /**
220
+ * Returns `true` if `substring` appears anywhere in the text of the
221
+ * `outputTargets` array. Use this to guard against adding the same target twice.
222
+ *
223
+ * @example
224
+ * if (!editor.outputTargetsContains('vueOutputTarget(')) {
225
+ * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
226
+ * }
227
+ */
228
+ outputTargetsContains(substring: string): boolean;
229
+ /**
230
+ * Appends `expression` as a new element in the `outputTargets` array,
231
+ * creating the `outputTargets` property if it is absent from the config.
232
+ *
233
+ * `expression` is a TypeScript expression that is inserted verbatim into
234
+ * the source file. It must evaluate to a value assignable to {@link OutputTarget}
235
+ * - built-in targets use object literal syntax (e.g. `"{ type: 'standalone' }"`),
236
+ * while third-party targets are function calls that return `OutputTargetCustom`
237
+ * (e.g. `"vueOutputTarget({...})"`). Call {@link addImport} first to bring the
238
+ * factory function into scope.
239
+ *
240
+ * @param expression - A TypeScript expression, e.g. `"{ type: 'standalone' }"`
241
+ * or `"vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })"`.
242
+ *
243
+ * @example
244
+ * // Built-in target (object literal):
245
+ * editor.addOutputTarget("{ type: 'standalone' }");
246
+ *
247
+ * @example
248
+ * // Third-party target (OutputTargetCustom - add the import first):
249
+ * editor.addImport('@stencil/vue-output-target', ['vueOutputTarget']);
250
+ * editor.addOutputTarget("vueOutputTarget({ proxiesFile: '../vue-lib/src/components.ts' })");
251
+ */
252
+ addOutputTarget(expression: string): void;
253
+ /**
254
+ * Replaces the first element in the `outputTargets` array whose text contains
255
+ * `substring` with `expression` in-place. Returns `true` if a match was found
256
+ * and replaced, `false` if no element contained `substring`.
257
+ *
258
+ * Useful for the reconfigure flow — the replaced target stays at the same
259
+ * position in the array rather than being moved to the end.
260
+ *
261
+ * @example
262
+ * // Replace if already configured, otherwise append:
263
+ * if (!editor.replaceOutputTarget('vueOutputTarget(', newExpression)) {
264
+ * editor.addOutputTarget(newExpression);
265
+ * }
266
+ */
267
+ replaceOutputTarget(substring: string, expression: string): boolean;
268
+ /**
269
+ * Removes the first element in the `outputTargets` array whose text contains
270
+ * `substring`. Returns `true` if an element was removed, `false` if no match
271
+ * was found.
272
+ *
273
+ * @example
274
+ * editor.removeOutputTarget('vueOutputTarget(');
275
+ */
276
+ removeOutputTarget(substring: string): boolean;
277
+ /**
278
+ * Returns `true` if `substring` appears anywhere in the text of the
279
+ * `plugins` array. Use this to guard against adding the same plugin twice.
280
+ *
281
+ * @example
282
+ * if (!editor.pluginsContains('sass(')) {
283
+ * editor.addPlugin('sass()');
284
+ * }
285
+ */
286
+ pluginsContains(substring: string): boolean;
287
+ /**
288
+ * Appends `expression` as a new element in the `plugins` array,
289
+ * creating the `plugins` property if it is absent from the config.
290
+ *
291
+ * `expression` is a TypeScript expression that is inserted verbatim into
292
+ * the source file. Call {@link addImport} first to bring the plugin factory
293
+ * into scope.
294
+ *
295
+ * @param expression - A TypeScript expression, e.g. `'sass()'` or
296
+ * `"sass({ injectGlobalPaths: ['src/global/variables.scss'] })"`.
297
+ *
298
+ * @example
299
+ * editor.addImport('@stencil/sass', ['sass']);
300
+ * editor.addPlugin('sass()');
301
+ *
302
+ * @example
303
+ * editor.addImport('@stencil/sass', ['sass']);
304
+ * editor.addPlugin("sass({ injectGlobalPaths: ['src/global/variables.scss'] })");
305
+ */
306
+ addPlugin(expression: string): void;
307
+ /**
308
+ * Replaces the first element in the `plugins` array whose text contains
309
+ * `substring` with `expression` in-place. Returns `true` if a match was found
310
+ * and replaced, `false` if no element contained `substring`.
311
+ *
312
+ * @example
313
+ * if (!editor.replacePlugin('sass(', newSassCall)) {
314
+ * editor.addPlugin(newSassCall);
315
+ * }
316
+ */
317
+ replacePlugin(substring: string, expression: string): boolean;
318
+ /**
319
+ * Removes the first element in the `plugins` array whose text contains
320
+ * `substring`. Returns `true` if an element was removed, `false` if no match
321
+ * was found.
322
+ *
323
+ * @example
324
+ * editor.removePlugin('sass(');
325
+ */
326
+ removePlugin(substring: string): boolean;
327
+ /** Write all accumulated edits back to disk. */
328
+ save(): Promise<void>;
329
+ }
330
+ /**
331
+ * Context passed to wizard steps at runtime.
332
+ */
333
+ interface WizardContext {
334
+ /** True when `stencil.config.ts` did not previously exist (fresh scaffold). */
335
+ isNewProject: boolean;
336
+ /** Clack prompts - use instead of importing `@clack/prompts` directly for consistent UX. */
337
+ prompts: typeof import('@clack/prompts');
338
+ /** nypm - use instead of importing `nypm` directly so the package manager is auto-detected. */
339
+ nypm: typeof import('nypm');
340
+ /** Resolved project config. See {@link ProjectConfig} for available fields. */
341
+ config: ProjectConfig;
342
+ /**
343
+ * Absolute path to the monorepo workspace root when the project is part of a
344
+ * workspace, `undefined` for single-package projects.
345
+ *
346
+ * When present, `config.rootDir` is the core Stencil package (e.g.
347
+ * `<workspaceRoot>/packages/core/`). The plugin is responsible for deciding
348
+ * where in the workspace it wants to live and for creating that directory.
349
+ */
350
+ workspaceRoot?: string;
351
+ /**
352
+ * Open the project's `stencil.config.ts` for structured editing.
353
+ * Use the returned {@link StencilConfigEditor} to add imports, output targets,
354
+ * and plugins, then call `save()` to persist.
355
+ *
356
+ * Use {@link ts} directly when you need to manipulate other files or perform
357
+ * operations the editor does not cover.
358
+ */
359
+ openStencilConfig: () => Promise<StencilConfigEditor>;
360
+ /**
361
+ * TypeScript compiler API. Available for advanced AST manipulation beyond
362
+ * what {@link openStencilConfig} covers.
363
+ */
364
+ ts: typeof import('typescript');
365
+ }
366
+ /**
367
+ * A single file a plugin can offer during `stencil generate`.
368
+ */
369
+ interface WizardFileTemplate {
370
+ /** Label shown in the generate prompt checkbox, e.g. `"Spec Test (.spec.tsx)"`. */
371
+ label: string;
372
+ /**
373
+ * File extension used to derive the filename and deduplicate contributions,
374
+ * e.g. `"spec.tsx"` or `"e2e.ts"`.
375
+ */
376
+ extension: string;
377
+ /**
378
+ * Subdirectory within the component directory where the file is placed.
379
+ * e.g. `'test'` to place alongside other test files. Omit for the component root.
380
+ */
381
+ subdirectory?: string;
382
+ /**
383
+ * Returns the file content. `className` is the PascalCase form of `tagName`.
384
+ */
385
+ template: (tagName: string, className: string) => string;
386
+ /** Pre-selected in the generate prompt. Defaults to `true`. */
387
+ selectedByDefault?: boolean;
388
+ }
389
+ /**
390
+ * Context passed to dynamic `fileTemplates` resolvers during `stencil generate`.
391
+ */
392
+ interface GenerateContext {
393
+ /** The dash-case component tag name entered by the user. */
394
+ tagName: string;
395
+ /** Resolved project config. See {@link ProjectConfig} for available fields. */
396
+ config: ProjectConfig;
397
+ /** Clack prompts - use instead of importing `@clack/prompts` directly for consistent UX. */
398
+ prompts: typeof import('@clack/prompts');
399
+ /** nypm - use instead of importing `nypm` directly so the package manager is auto-detected. */
400
+ nypm: typeof import('nypm');
401
+ }
402
+ /**
403
+ * Contribution a package can make to `stencil generate`.
404
+ */
405
+ interface WizardGenerateContribution {
406
+ /**
407
+ * Files this plugin can generate alongside the component.
408
+ *
409
+ * May be a static array or an async function that receives project context
410
+ * (e.g. to read `vitest.config.ts` and offer one template per configured
411
+ * Vitest project). Called after the user enters the component tag name.
412
+ */
413
+ fileTemplates?: ReadonlyArray<WizardFileTemplate> | ((ctx: GenerateContext) => ReadonlyArray<WizardFileTemplate> | Promise<ReadonlyArray<WizardFileTemplate>>);
414
+ /**
415
+ * Additional style extensions this package supports (e.g. `['sass', 'scss']`
416
+ * from `@stencil/sass`). The first entry is used as the default.
417
+ */
418
+ styleExtensions?: ReadonlyArray<string>;
419
+ }
420
+ /**
421
+ * Contribution a package can make to `stencil init`.
422
+ *
423
+ * The plugin owns its entire setup: prompts, peer dep installs, config file
424
+ * generation, example files, package.json script updates, etc.
425
+ */
426
+ interface WizardInitContribution {
427
+ /** Stable identifier used to deduplicate across re-runs. */
428
+ id: string;
429
+ /** Human-readable name shown in the prompt list. */
430
+ displayName: string;
431
+ /** One-line description shown alongside the name. */
432
+ description: string;
433
+ /**
434
+ * Called by the CLI after packages are installed. The plugin is responsible
435
+ * for all further setup: additional prompts, peer dep installs, config file
436
+ * writes, example tests, `.gitignore` and `package.json` script updates, etc.
437
+ */
438
+ run: (context: WizardContext) => Promise<void>;
439
+ }
440
+ /**
441
+ * Interface a package exports to participate in `stencil init` and/or
442
+ * `stencil generate`.
443
+ *
444
+ * Declare the entry point in `package.json`:
445
+ * ```json
446
+ * { "stencil": { "wizard": "./dist/wizard.js" } }
447
+ * ```
448
+ *
449
+ * Export a named `wizard` constant from that module:
450
+ * ```ts
451
+ * export const wizard: StencilWizardPlugin = { ... };
452
+ * ```
453
+ */
454
+ interface StencilWizardPlugin {
455
+ /** Contributions to `stencil generate`. */
456
+ generate?: WizardGenerateContribution;
457
+ /** Contributions to `stencil init`. */
458
+ init?: WizardInitContribution;
459
+ }
460
+ //#endregion
461
+ 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 };