@stencil/cli 5.0.0-alpha.23 → 5.0.0-alpha.25

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.
Files changed (2) hide show
  1. package/dist/index.mjs +80 -6
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { LOG_LEVELS } from "@stencil/core/compiler";
2
- import { buildError, catchError, hasError, isFunction, isOutputTargetDocs, isOutputTargetSsr, isOutputTargetWww, isString, normalizePath, readOnlyArrayHasStringMember, result, shouldIgnoreError, toCamelCase, validateComponentTag } from "@stencil/core/compiler/utils";
2
+ import { buildError, catchError, hasError, isFunction, isOutputTargetDistLazy, isOutputTargetDocs, isOutputTargetSsr, isOutputTargetStandalone, isOutputTargetWww, isString, normalizePath, readOnlyArrayHasStringMember, result, shouldIgnoreError, toCamelCase, validateComponentTag } from "@stencil/core/compiler/utils";
3
3
  import { basename, dirname, join, parse, relative, resolve } from "node:path";
4
4
  import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
5
5
  import * as p from "@clack/prompts";
@@ -12,7 +12,7 @@ import { pathToFileURL } from "node:url";
12
12
  import { existsSync } from "node:fs";
13
13
  import { homedir } from "node:os";
14
14
  import { dirname as dirname$1, isAbsolute, join as join$1, relative as relative$1 } from "path";
15
- import { generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getStyleBoilerplate, getTemplatePath, toPascalCase } from "@stencil/templates";
15
+ import { generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase } from "@stencil/templates";
16
16
  import { start } from "@stencil/dev-server";
17
17
  //#region src/config-flags.ts
18
18
  /**
@@ -694,8 +694,9 @@ async function openStencilConfig(configPath) {
694
694
  if (lastProp) {
695
695
  let insertPos = lastProp.getEnd();
696
696
  const trailingComma = text.slice(insertPos).match(/^\s*,/);
697
+ const separator = trailingComma ? "" : ",";
697
698
  if (trailingComma) insertPos += trailingComma[0].length;
698
- text = `${text.slice(0, insertPos)},\n${propIndent}${newProp}${text.slice(insertPos)}`;
699
+ text = `${text.slice(0, insertPos)}${separator}\n${propIndent}${newProp}${text.slice(insertPos)}`;
699
700
  } else {
700
701
  const insertPos = configObj.getEnd() - 1;
701
702
  text = `${text.slice(0, insertPos)}\n${propIndent}${newProp},\n${text.slice(insertPos)}`;
@@ -1193,7 +1194,7 @@ async function isExistingStencilProject(dir) {
1193
1194
  }
1194
1195
  //#endregion
1195
1196
  //#region src/wizard/splash.ts
1196
- const CLI_VERSION = "5.0.0-alpha.23";
1197
+ const CLI_VERSION = "5.0.0-alpha.25";
1197
1198
  const isTTY = process.stdout.isTTY;
1198
1199
  const noColor = !isTTY || "NO_COLOR" in process.env;
1199
1200
  const RESET = noColor ? "" : "\x1B[0m";
@@ -3525,6 +3526,48 @@ const taskDocs = async (coreCompiler, config) => {
3525
3526
  await compiler.destroy();
3526
3527
  };
3527
3528
  //#endregion
3529
+ //#region src/resolve-entry-script.ts
3530
+ /**
3531
+ * Resolves the server-relative src for the project's browser entry bundle, from validated
3532
+ * output targets alone (no build required) - the same dev-mode, unhashed filename conventions
3533
+ * the compiler itself uses (see `getAbsoluteBuildDir` in `packages/core/src/compiler/html/html-utils.ts`
3534
+ * and the dev server's `getLoaderUrl` in `packages/dev-server/src/server/dev-preview.ts`, which
3535
+ * this mirrors for use before a build has happened).
3536
+ *
3537
+ * Preference order matches what actually gets built:
3538
+ * 1. `www` - always emits its own entry bundle at `{buildDir}/{fsNamespace}.js`, regardless of
3539
+ * `bundleMode`, so it's resolved directly from the `www` target rather than the `dist-lazy` /
3540
+ * `standalone` target it internally synthesizes.
3541
+ * 2. `loader-bundle` (no `www`) - synthesizes a `dist-lazy` build for CDN usage, servable from
3542
+ * the project root when there's no `www` target to claim the server root instead.
3543
+ * 3. `standalone` with `autoLoader` enabled (the default) - falls back to its auto-loader script.
3544
+ *
3545
+ * Returns `null` if the project has no browser-loadable output target at all (e.g. an SSR-only
3546
+ * project) - the caller should omit the script tag in that case.
3547
+ *
3548
+ * @param config - Validated Stencil config.
3549
+ * @returns Server-relative script src, or `null` if none of the configured output targets
3550
+ * produce a browser-loadable entry.
3551
+ */
3552
+ function resolveEntryScriptSrc(config) {
3553
+ const outputTargets = config.outputTargets;
3554
+ const wwwTarget = outputTargets.find(isOutputTargetWww);
3555
+ if (wwwTarget?.dir && wwwTarget.buildDir) return toUrl(wwwTarget.dir, wwwTarget.buildDir, `${config.fsNamespace}.js`);
3556
+ const distLazyTarget = outputTargets.find(isOutputTargetDistLazy);
3557
+ const distLazyDir = distLazyTarget?.esmDir ?? distLazyTarget?.dir;
3558
+ if (distLazyDir) return toUrl(config.rootDir, distLazyDir, `${config.fsNamespace}.js`);
3559
+ const standaloneTarget = outputTargets.find(isOutputTargetStandalone);
3560
+ if (standaloneTarget?.dir && standaloneTarget.autoLoader !== false) {
3561
+ const fileName = typeof standaloneTarget.autoLoader === "object" ? standaloneTarget.autoLoader.fileName || "loader" : "loader";
3562
+ return toUrl(config.rootDir, standaloneTarget.dir, `${fileName}.js`);
3563
+ }
3564
+ return null;
3565
+ }
3566
+ function toUrl(base, dir, fileName) {
3567
+ const relativeDir = normalizePath(relative(base, dir), false);
3568
+ return `/${relativeDir ? `${relativeDir}/` : ""}${fileName}`;
3569
+ }
3570
+ //#endregion
3528
3571
  //#region src/task-generate.ts
3529
3572
  async function resolveFileTemplates(contrib, ctx) {
3530
3573
  const { fileTemplates } = contrib;
@@ -3576,6 +3619,26 @@ const taskGenerate = async (config, flags) => {
3576
3619
  });
3577
3620
  cancelIfAborted(stylePick);
3578
3621
  const styleExtension = stylePick || void 0;
3622
+ const demoPick = await p.select({
3623
+ message: "Demo:",
3624
+ options: [
3625
+ {
3626
+ value: "usage",
3627
+ label: "Usage example",
3628
+ hint: "usage/example.md - rendered in docs and the dev server auto-preview"
3629
+ },
3630
+ {
3631
+ value: "preview",
3632
+ label: "Preview page",
3633
+ hint: "index.html - full control, opts out of the dev server auto-preview"
3634
+ },
3635
+ {
3636
+ value: "",
3637
+ label: "None"
3638
+ }
3639
+ ]
3640
+ });
3641
+ cancelIfAborted(demoPick);
3579
3642
  const generateCtx = {
3580
3643
  tagName: componentName,
3581
3644
  config: toProjectConfig(config),
@@ -3617,6 +3680,14 @@ const taskGenerate = async (config, flags) => {
3617
3680
  content: tmpl.template(componentName, className)
3618
3681
  });
3619
3682
  }
3683
+ if (demoPick === "usage") filesToWrite.push({
3684
+ absPath: normalizePath(join(outDir, "usage", "example.md")),
3685
+ content: getUsageExampleBoilerplate(componentName)
3686
+ });
3687
+ else if (demoPick === "preview") filesToWrite.push({
3688
+ absPath: normalizePath(join(outDir, "index.html")),
3689
+ content: getPreviewHtmlBoilerplate(componentName, resolveEntryScriptSrc(config))
3690
+ });
3620
3691
  const wouldOverwrite = (await Promise.all(filesToWrite.map(async ({ absPath }) => await config.sys.readFile(absPath) !== void 0 ? absPath : null))).filter((f) => f !== null);
3621
3692
  if (wouldOverwrite.length > 0) {
3622
3693
  config.logger.error("Generating code would overwrite the following files:", ...wouldOverwrite.map((path) => " " + normalizePath(path)));
@@ -3757,7 +3828,7 @@ async function copyTemplate(rootDir, projectName, namespace, stencilVersion) {
3757
3828
  recursive: true,
3758
3829
  withFileTypes: true
3759
3830
  });
3760
- const resolvedStencilVersion = stencilVersion ? `^${stencilVersion}` : "^5.0.0";
3831
+ const resolvedStencilVersion = stencilVersion ?? "^5.0.0";
3761
3832
  for (const entry of entries) {
3762
3833
  if (!entry.isFile()) continue;
3763
3834
  const srcPath = join(entry.parentPath, entry.name);
@@ -3918,7 +3989,10 @@ async function scaffoldWorkspaceRoot(cwd, projectName) {
3918
3989
  pkg.name ??= `${projectName}-workspace`;
3919
3990
  pkg.version ??= "0.0.1";
3920
3991
  pkg.private = true;
3921
- pkg.scripts ??= { build: workspaceBuildScript(pm?.name) };
3992
+ pkg.scripts = {
3993
+ build: workspaceBuildScript(pm?.name),
3994
+ ...pkg.scripts
3995
+ };
3922
3996
  if (!usePnpmYaml) pkg.workspaces = ["packages/*"];
3923
3997
  delete pkg.dependencies;
3924
3998
  delete pkg.devDependencies;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/cli",
3
- "version": "5.0.0-alpha.23",
3
+ "version": "5.0.0-alpha.25",
4
4
  "description": "CLI for Stencil - Web component compiler",
5
5
  "keywords": [
6
6
  "components",
@@ -41,16 +41,16 @@
41
41
  "nypm": "^0.3.12",
42
42
  "std-env": "^3.8.0",
43
43
  "typescript": ">4.0.0 <7.0.0",
44
- "@stencil/dev-server": "5.0.0-alpha.23",
45
- "@stencil/templates": "5.0.0-alpha.23"
44
+ "@stencil/dev-server": "5.0.0-alpha.25",
45
+ "@stencil/templates": "5.0.0-alpha.25"
46
46
  },
47
47
  "devDependencies": {
48
48
  "tsdown": ">=0.21.0 <1.0.0",
49
49
  "vitest": "^4.1.7",
50
- "@stencil/core": "5.0.0-alpha.23"
50
+ "@stencil/core": "5.0.0-alpha.25"
51
51
  },
52
52
  "peerDependencies": {
53
- "@stencil/core": "^5.0.0 || 5.0.0-alpha.23"
53
+ "@stencil/core": "^5.0.0 || 5.0.0-alpha.25"
54
54
  },
55
55
  "volta": {
56
56
  "extends": "../../package.json"