@fluid-app/fluid-cli-theme-dev 0.1.850 → 0.1.851

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/dist/index.mjs CHANGED
@@ -1628,12 +1628,15 @@ function findDuplicateBlocksKeys(jsonText) {
1628
1628
  }
1629
1629
  return count;
1630
1630
  }
1631
+ function schemaJsonText(text) {
1632
+ const match = stripLiquidComments(text).match(/\{%-?\s*schema\s*-?%\}([\s\S]*?)\{%-?\s*endschema\s*-?%\}/);
1633
+ return match ? match[1] ?? "" : null;
1634
+ }
1631
1635
  function validateSchemaText(text, options) {
1632
1636
  const blocksSchemaType = options?.blocksSchemaType ?? "unknown";
1633
1637
  const diagnostics = [];
1634
- const match = stripLiquidComments(text).match(/\{%-?\s*schema\s*-?%\}([\s\S]*?)\{%-?\s*endschema\s*-?%\}/);
1635
- if (!match) return diagnostics;
1636
- const jsonText = match[1] ?? "";
1638
+ const jsonText = schemaJsonText(text);
1639
+ if (jsonText === null) return diagnostics;
1637
1640
  let schema;
1638
1641
  try {
1639
1642
  schema = JSON.parse(jsonText);
@@ -2123,6 +2126,74 @@ function findLiquidBlockTagDiagnostics(content) {
2123
2126
  return diagnostics;
2124
2127
  }
2125
2128
  //#endregion
2129
+ //#region ../../platform/theme-schema/src/translation-tags.ts
2130
+ const TRANSLATION_TAG = /\{\{-?\s*(['"])([^'"]*)\1\s*\|\s*t\b/g;
2131
+ const HAS_TRANSLATION_TAG = new RegExp(TRANSLATION_TAG.source);
2132
+ const WHOLE_VALUE_TAG = /^\{\{\s*['"][^'"]*['"]\s*\|\s*t\s*\}\}$/;
2133
+ const MAX_EXAMPLES = 3;
2134
+ /**
2135
+ * Warns about translations the storefront renders but the Page Editor can't
2136
+ * show: keys that aren't two-part `group.key`, and schema values that hold a
2137
+ * `t` tag but aren't exactly one plain tag.
2138
+ */
2139
+ function findTranslationTagDiagnostics(content) {
2140
+ const diagnostics = [];
2141
+ const schema = scanSchemaValues(content);
2142
+ const badKeys = [...new Set([...keysIn(stripLiquidComments(content)), ...schema.keys])].filter((key) => !isGroupKey(key));
2143
+ if (badKeys.length > 0) diagnostics.push({
2144
+ severity: "warning",
2145
+ message: `Translation keys aren't group.key: ${examples(badKeys)}. Only a two-part key resolves both on the storefront and in the Page Editor.`
2146
+ });
2147
+ if (schema.notWholeTag.length > 0) diagnostics.push({
2148
+ severity: "warning",
2149
+ message: `Schema values aren't one plain {{ 'group.key' | t }} tag: ${examples(schema.notWholeTag)}. The Page Editor shows the raw tag unless the value is exactly that tag, with no text, HTML, filter arguments or whitespace control; move any HTML into the locale value.`
2150
+ });
2151
+ return diagnostics;
2152
+ }
2153
+ function keysIn(text) {
2154
+ return Array.from(text.matchAll(TRANSLATION_TAG), (match) => match[2]);
2155
+ }
2156
+ function isGroupKey(key) {
2157
+ const parts = key.split(".");
2158
+ return parts.length === 2 && parts.every(Boolean);
2159
+ }
2160
+ function scanSchemaValues(content) {
2161
+ const keys = [];
2162
+ const notWholeTag = [];
2163
+ const jsonText = schemaJsonText(content);
2164
+ if (jsonText === null) return {
2165
+ keys,
2166
+ notWholeTag
2167
+ };
2168
+ let schema;
2169
+ try {
2170
+ schema = JSON.parse(jsonText);
2171
+ } catch {
2172
+ return {
2173
+ keys,
2174
+ notWholeTag
2175
+ };
2176
+ }
2177
+ const walk = (value, path) => {
2178
+ if (typeof value === "string") {
2179
+ if (!HAS_TRANSLATION_TAG.test(value)) return;
2180
+ keys.push(...keysIn(value));
2181
+ if (!WHOLE_VALUE_TAG.test(value.trim())) notWholeTag.push(path);
2182
+ } else if (Array.isArray(value)) value.forEach((item, index) => walk(item, `${path}[${index}]`));
2183
+ else if (value !== null && typeof value === "object") for (const [key, item] of Object.entries(value)) walk(item, path ? `${path}.${key}` : key);
2184
+ };
2185
+ walk(schema, "");
2186
+ return {
2187
+ keys,
2188
+ notWholeTag
2189
+ };
2190
+ }
2191
+ function examples(items) {
2192
+ const shown = items.slice(0, MAX_EXAMPLES).map((item) => `'${item}'`).join(", ");
2193
+ const more = items.length - MAX_EXAMPLES;
2194
+ return more > 0 ? `${shown} and ${more} more` : shown;
2195
+ }
2196
+ //#endregion
2126
2197
  //#region src/theme/file.ts
2127
2198
  const NON_TEMPLATE_DIRS = new Set([
2128
2199
  "sections",
@@ -4911,7 +4982,7 @@ async function startDevServer(api, theme, themeRoot, opts, onReady) {
4911
4982
  console.log(` ✓ synced ${uploadedFile.relativePath} (${timestamp()})`);
4912
4983
  if (isStylesheetKey(uploadedFile.relativePath)) console.warn(` ⚠ ${uploadedFile.relativePath}: the storefront inlines this CSS from a published asset, so it serves the previous bytes until the stylesheet asset sync finishes`);
4913
4984
  if (uploadedFile.isLiquid && uploadedContent !== null && hasUnbalancedLiquidDelimiters(uploadedContent)) console.warn(` ⚠ ${uploadedFile.relativePath}: unbalanced liquid delimiters — the storefront may silently serve stale content for this section`);
4914
- if (uploadedFile.isLiquid && uploadedContent !== null) for (const diagnostic of findLiquidBlockTagDiagnostics(uploadedContent)) console.warn(` ⚠ ${uploadedFile.relativePath}: ${diagnostic.message}`);
4985
+ if (uploadedFile.isLiquid && uploadedContent !== null) for (const diagnostic of [...findLiquidBlockTagDiagnostics(uploadedContent), ...findTranslationTagDiagnostics(uploadedContent)]) console.warn(` ⚠ ${uploadedFile.relativePath}: ${diagnostic.message}`);
4915
4986
  }
4916
4987
  } catch (e) {
4917
4988
  if (e instanceof PushConflictError) {
@@ -7787,6 +7858,7 @@ function createLintCommand() {
7787
7858
  const blocksSchemaType = file.isTemplate ? "object" : "array";
7788
7859
  for (const diagnostic of validateSchemaText(content, { blocksSchemaType })) record(file.relativePath, diagnostic);
7789
7860
  for (const diagnostic of findLiquidBlockTagDiagnostics(content)) record(file.relativePath, diagnostic);
7861
+ for (const diagnostic of findTranslationTagDiagnostics(content)) record(file.relativePath, diagnostic);
7790
7862
  }
7791
7863
  for (const { file, content } of [...liquidFiles, ...scriptFiles]) for (const diagnostic of findCartCodeDiagnostics(file.relativePath, content)) record(file.relativePath, diagnostic);
7792
7864
  const existingSectionNames = /* @__PURE__ */ new Set();