@stencil/cli 5.0.0-beta.20 → 5.0.0-beta.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.
Files changed (2) hide show
  1. package/dist/index.mjs +109 -65
  2. package/package.json +5 -5
package/dist/index.mjs CHANGED
@@ -1265,7 +1265,7 @@ function clearInheritedProductionEnv() {
1265
1265
  }
1266
1266
  //#endregion
1267
1267
  //#region src/wizard/splash.ts
1268
- const CLI_VERSION = "5.0.0-beta.20";
1268
+ const CLI_VERSION = "5.0.0-beta.21";
1269
1269
  const isTTY = process.stdout.isTTY;
1270
1270
  const noColor = !isTTY || "NO_COLOR" in process.env;
1271
1271
  const RESET = noColor ? "" : "\x1B[0m";
@@ -2022,11 +2022,23 @@ const formAssociatedRule = {
2022
2022
  * Migration mapping:
2023
2023
  * - `addGlobalStyleToComponents: true` → `inject: 'all'`
2024
2024
  * - `addGlobalStyleToComponents: 'client'` → `inject: 'client'`
2025
- * - `addGlobalStyleToComponents: false` → omit (default is 'none')
2025
+ * - `addGlobalStyleToComponents: false` → `inject: 'none'` (a stylesheet from `globalStyle` defaults
2026
+ * to `'client'`, so omitting it would start injecting)
2026
2027
  *
2027
- * Note: This migration only acts on explicitly set `addGlobalStyleToComponents`.
2028
- * Users who relied on the implicit v4 default ('client') will need to manually
2029
- * add `inject: 'client'` to their global-style output target if desired.
2028
+ * The top-level `globalStyle` option moves into the new output target as well, so the config
2029
+ * isn't left describing one stylesheet in two places:
2030
+ *
2031
+ * ```ts
2032
+ * { type: 'global-style', input: 'src/global/app.css', fileName: 'my-lib.css', inject: 'none', copyToLoaderBrowser: true }
2033
+ * ```
2034
+ *
2035
+ * `fileName` is written (from `namespace`) because a target with an explicit `input` otherwise
2036
+ * names its output after the input file, where `globalStyle` used `{namespace}.css`.
2037
+ * When `globalStyle` isn't a string literal in the config (e.g. the stylesheet is auto-detected
2038
+ * from `src/global.*`), only `{ type: 'global-style', inject }` is written.
2039
+ *
2040
+ * Note: This migration only acts on explicitly set `addGlobalStyleToComponents`. A config
2041
+ * without it keeps `globalStyle` as it is, which still injects on the client as v4 did.
2030
2042
  */
2031
2043
  const globalStyleInjectRule = {
2032
2044
  id: "global-style-inject",
@@ -2058,79 +2070,97 @@ const globalStyleInjectRule = {
2058
2070
  return matches;
2059
2071
  },
2060
2072
  transform(sourceFile, matches) {
2061
- if (matches.length === 0) return sourceFile.getFullText();
2062
- let text = sourceFile.getFullText();
2073
+ const original = sourceFile.getFullText();
2074
+ if (matches.length === 0) return original;
2063
2075
  const matchNode = matches[0].node;
2064
- if (!ts.isPropertyAssignment(matchNode)) return text;
2076
+ if (!ts.isPropertyAssignment(matchNode)) return original;
2065
2077
  let injectValue = null;
2066
2078
  if (matchNode.initializer.kind === ts.SyntaxKind.TrueKeyword) injectValue = "all";
2067
2079
  else if (ts.isStringLiteral(matchNode.initializer) && matchNode.initializer.text === "client") injectValue = "client";
2068
- let insertionOffset = 0;
2069
- if (injectValue) {
2070
- const result = addGlobalStyleOutputTarget(text, sourceFile, injectValue);
2071
- insertionOffset = result.length - text.length;
2072
- text = result;
2073
- }
2074
- let start = matchNode.getStart();
2075
- let end = matchNode.getEnd();
2076
- const outputTargetsEnd = findOutputTargetsEnd(sourceFile);
2077
- if (insertionOffset !== 0 && outputTargetsEnd !== null && matchNode.getStart() > outputTargetsEnd) {
2078
- start += insertionOffset;
2079
- end += insertionOffset;
2080
- }
2081
- const afterProp = text.slice(end).match(/^\s*,/);
2082
- if (afterProp) end = end + afterProp[0].length;
2083
- else {
2084
- const beforeProp = text.slice(0, start).match(/,\s*$/);
2085
- if (beforeProp) {
2086
- text = text.slice(0, start - beforeProp[0].length) + text.slice(end);
2087
- end = -1;
2080
+ else if (matchNode.initializer.kind === ts.SyntaxKind.FalseKeyword) injectValue = "none";
2081
+ const edits = [removalOf(original, matchNode)];
2082
+ const outputTargets = findTopLevelProperty(sourceFile, "outputTargets");
2083
+ const hasGlobalStyleTarget = original.includes("type: 'global-style'");
2084
+ if (injectValue && !hasGlobalStyleTarget && outputTargets && ts.isArrayLiteralExpression(outputTargets.initializer)) {
2085
+ const globalStyle = findTopLevelProperty(sourceFile, "globalStyle");
2086
+ const namespace = findTopLevelProperty(sourceFile, "namespace");
2087
+ const props = [`type: 'global-style'`];
2088
+ if (globalStyle && ts.isStringLiteralLike(globalStyle.initializer)) {
2089
+ props.push(`input: ${globalStyle.initializer.getText()}`);
2090
+ if (namespace && ts.isStringLiteralLike(namespace.initializer)) props.push(`fileName: '${namespace.initializer.text.toLowerCase().trim()}.css'`);
2091
+ edits.push(removalOf(original, globalStyle));
2088
2092
  }
2093
+ props.push(`inject: '${injectValue}'`);
2094
+ if (props.length > 2) props.push(`copyToLoaderBrowser: true`);
2095
+ edits.push(insertionOfOutputTarget(original, outputTargets.initializer, props));
2089
2096
  }
2090
- if (end !== -1) text = text.slice(0, start) + text.slice(end);
2091
- text = cleanupEmptyExtras$1(text);
2092
- return text;
2097
+ let text = original;
2098
+ for (const edit of edits.sort((a, b) => b.start - a.start)) text = text.slice(0, edit.start) + edit.text + text.slice(edit.end);
2099
+ return cleanupEmptyExtras$1(text);
2093
2100
  }
2094
2101
  };
2095
2102
  /**
2096
- * Find the end position of the outputTargets array in the source file.
2103
+ * Find a property of the exported config object, e.g. `globalStyle` or `outputTargets`.
2097
2104
  * @param sourceFile The source file to search
2098
- * @returns The end position of the outputTargets array, or null if not found
2105
+ * @param name The property name
2106
+ * @returns The property assignment, or null if the config has no such top-level property
2099
2107
  */
2100
- function findOutputTargetsEnd(sourceFile) {
2101
- let endPos = null;
2102
- const visit = (node) => {
2103
- if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "outputTargets") endPos = node.getEnd();
2104
- ts.forEachChild(node, visit);
2108
+ function findTopLevelProperty(sourceFile, name) {
2109
+ let found = null;
2110
+ const visit = (node, depth) => {
2111
+ if (found) return;
2112
+ if (ts.isObjectLiteralExpression(node)) {
2113
+ if (depth > 0) return;
2114
+ for (const prop of node.properties) if (ts.isPropertyAssignment(prop) && ts.isIdentifier(prop.name) && prop.name.text === name) {
2115
+ found = prop;
2116
+ return;
2117
+ }
2118
+ return;
2119
+ }
2120
+ ts.forEachChild(node, (child) => visit(child, depth));
2105
2121
  };
2106
- visit(sourceFile);
2107
- return endPos;
2122
+ visit(sourceFile, 0);
2123
+ return found;
2108
2124
  }
2109
2125
  /**
2110
- * Clean up empty extras object after removing addGlobalStyleToComponents.
2111
- * @param text The source text to clean up
2112
- * @returns The cleaned up text with empty extras removed
2126
+ * Build the edit that removes a property, together with its trailing comma and its own line.
2127
+ * @param text The original source text
2128
+ * @param node The property to remove
2129
+ * @returns The edit
2113
2130
  */
2114
- function cleanupEmptyExtras$1(text) {
2115
- return text.replace(/,?\s*extras\s*:\s*\{\s*\},?/g, "");
2131
+ function removalOf(text, node) {
2132
+ let start = node.getStart();
2133
+ let end = node.getEnd();
2134
+ const trailingComma = text.slice(end).match(/^\s*,/);
2135
+ if (trailingComma) end += trailingComma[0].length;
2136
+ else {
2137
+ const leadingComma = text.slice(0, start).match(/,\s*$/);
2138
+ if (leadingComma) return {
2139
+ start: start - leadingComma[0].length,
2140
+ end,
2141
+ text: ""
2142
+ };
2143
+ }
2144
+ const lineStart = text.lastIndexOf("\n", start - 1) + 1;
2145
+ const restOfLine = text.slice(end).match(/^[ \t]*\n/);
2146
+ if (/^[ \t]*$/.test(text.slice(lineStart, start)) && restOfLine) {
2147
+ start = lineStart;
2148
+ end += restOfLine[0].length;
2149
+ }
2150
+ return {
2151
+ start,
2152
+ end,
2153
+ text: ""
2154
+ };
2116
2155
  }
2117
2156
  /**
2118
- * Add a global-style output target with the specified inject value.
2119
- * @param text The source text to modify
2120
- * @param sourceFile The source file for position info
2121
- * @param injectValue The inject value to set on the new global-style output target
2122
- * @returns The modified text with the new global-style output target added
2157
+ * Build the edit that appends a `global-style` output target to the `outputTargets` array.
2158
+ * @param text The original source text
2159
+ * @param array The `outputTargets` array
2160
+ * @param props The new output target's properties, as source text
2161
+ * @returns The edit
2123
2162
  */
2124
- function addGlobalStyleOutputTarget(text, sourceFile, injectValue) {
2125
- if (text.includes("type: 'global-style'")) return text;
2126
- let outputTargetsArray = null;
2127
- const findOutputTargets = (node) => {
2128
- if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "outputTargets" && ts.isArrayLiteralExpression(node.initializer)) outputTargetsArray = node.initializer;
2129
- ts.forEachChild(node, findOutputTargets);
2130
- };
2131
- findOutputTargets(sourceFile);
2132
- if (!outputTargetsArray) return text;
2133
- const array = outputTargetsArray;
2163
+ function insertionOfOutputTarget(text, array, props) {
2134
2164
  let indent = " ";
2135
2165
  if (array.elements.length > 0) {
2136
2166
  const elemStart = array.elements[0].getStart();
@@ -2138,19 +2168,33 @@ function addGlobalStyleOutputTarget(text, sourceFile, injectValue) {
2138
2168
  const leadingWhitespace = text.slice(lineStart, elemStart);
2139
2169
  if (/^\s+$/.test(leadingWhitespace)) indent = leadingWhitespace;
2140
2170
  }
2171
+ const newTarget = `{\n${props.map((prop) => `${indent} ${prop},\n`).join("")}${indent}}`;
2141
2172
  const lastElement = array.elements[array.elements.length - 1];
2142
2173
  if (!lastElement) {
2143
2174
  const arrayStart = array.getStart() + 1;
2144
- const newTarget = `\n${indent}{\n${indent} type: 'global-style',\n${indent} inject: '${injectValue}',\n${indent}}\n${indent.slice(2)}`;
2145
- return text.slice(0, arrayStart) + newTarget + text.slice(arrayStart);
2175
+ return {
2176
+ start: arrayStart,
2177
+ end: arrayStart,
2178
+ text: `\n${indent}${newTarget}\n${indent.slice(2)}`
2179
+ };
2146
2180
  }
2147
2181
  let insertPos = lastElement.getEnd();
2148
2182
  const afterLastElement = text.slice(insertPos).match(/^(\s*,)?/);
2149
2183
  const hasTrailingComma = afterLastElement && afterLastElement[1];
2150
2184
  if (hasTrailingComma) insertPos += afterLastElement[0].length;
2151
- const newTarget = `{\n${indent} type: 'global-style',\n${indent} inject: '${injectValue}',\n${indent}}`;
2152
- const insertion = (hasTrailingComma ? "" : ",") + "\n" + indent + newTarget;
2153
- return text.slice(0, insertPos) + insertion + text.slice(insertPos);
2185
+ return {
2186
+ start: insertPos,
2187
+ end: insertPos,
2188
+ text: (hasTrailingComma ? "" : ",") + "\n" + indent + newTarget
2189
+ };
2190
+ }
2191
+ /**
2192
+ * Clean up empty extras object after removing addGlobalStyleToComponents.
2193
+ * @param text The source text to clean up
2194
+ * @returns The cleaned up text with empty extras removed
2195
+ */
2196
+ function cleanupEmptyExtras$1(text) {
2197
+ return text.replace(/,?\s*extras\s*:\s*\{\s*\},?/g, "");
2154
2198
  }
2155
2199
  //#endregion
2156
2200
  //#region src/migrations/rules/hash-file-names.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/cli",
3
- "version": "5.0.0-beta.20",
3
+ "version": "5.0.0-beta.21",
4
4
  "description": "CLI for Stencil - Web component compiler",
5
5
  "keywords": [
6
6
  "components",
@@ -42,16 +42,16 @@
42
42
  "nypm": "^0.3.12",
43
43
  "std-env": "^3.10.0",
44
44
  "typescript": ">5.0.0 <7.0.0",
45
- "@stencil/dev-server": "5.0.0-beta.20",
46
- "@stencil/templates": "5.0.0-beta.20"
45
+ "@stencil/dev-server": "5.0.0-beta.21",
46
+ "@stencil/templates": "5.0.0-beta.21"
47
47
  },
48
48
  "devDependencies": {
49
49
  "tsdown": "^0.22.14",
50
50
  "vitest": "^4.1.10",
51
- "@stencil/core": "5.0.0-beta.20"
51
+ "@stencil/core": "5.0.0-beta.21"
52
52
  },
53
53
  "peerDependencies": {
54
- "@stencil/core": "^5.0.0 || 5.0.0-beta.20"
54
+ "@stencil/core": "^5.0.0 || 5.0.0-beta.21"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=22.0.0"