@fluid-app/fluid-cli-theme-dev 0.1.508 → 0.1.509
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 +145 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import prompts from "prompts";
|
|
|
4
4
|
import { getAuthToken, gitSyncActorFromMe, gitSyncCommitSubject, readConfig, resolveGitSyncActor, summarizeChanges, updateConfig } from "@fluid-app/fluid-cli";
|
|
5
5
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
6
6
|
import { cpSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
|
-
import { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { basename, dirname, extname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
|
|
8
8
|
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
9
9
|
import http from "node:http";
|
|
10
10
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -1595,6 +1595,7 @@ function findMissingTemplateTypes(presentTypes) {
|
|
|
1595
1595
|
//#region src/theme/file.ts
|
|
1596
1596
|
const NON_TEMPLATE_DIRS = new Set([
|
|
1597
1597
|
"sections",
|
|
1598
|
+
"widgets",
|
|
1598
1599
|
"blocks",
|
|
1599
1600
|
"components",
|
|
1600
1601
|
"layouts",
|
|
@@ -5857,7 +5858,7 @@ function planOmittedMemberFiles(input) {
|
|
|
5857
5858
|
]) if (!Array.isArray(document[field])) throw new Error(`Cannot preserve member files: members_sites.json ${field} must be an array.`);
|
|
5858
5859
|
assertDependencyShape(document);
|
|
5859
5860
|
if (document.sites.length > 0) {
|
|
5860
|
-
for (const path of input.availablePaths) if (/^(sections|blocks|components|snippets|navbar|footer)\//.test(path)) protectedPaths.add(path);
|
|
5861
|
+
for (const path of input.availablePaths) if (/^(sections|widgets|blocks|components|snippets|navbar|footer)\//.test(path)) protectedPaths.add(path);
|
|
5861
5862
|
}
|
|
5862
5863
|
for (const path of memberDependencyPaths(document, input.availablePaths)) {
|
|
5863
5864
|
if (!isThemeResourceKey(path) || path.includes("\\") || [...path].some((character) => character.charCodeAt(0) < 32) || path === "config/members_sites.json") throw new Error(`Cannot preserve member files: invalid dependency path ${path}.`);
|
|
@@ -5882,6 +5883,145 @@ function assertDependencyShape(document) {
|
|
|
5882
5883
|
}
|
|
5883
5884
|
}
|
|
5884
5885
|
//#endregion
|
|
5886
|
+
//#region src/theme/widget-resource-dependencies.ts
|
|
5887
|
+
/** Script execution can construct resource URLs; inert JSON scripts cannot. */
|
|
5888
|
+
function hasExecutableScript(content) {
|
|
5889
|
+
const pending = [parseFragment(content.replace(/{%-?\s*comment\s*-?%}[\s\S]*?{%-?\s*endcomment\s*-?%}/g, ""))];
|
|
5890
|
+
while (pending.length) {
|
|
5891
|
+
const node = pending.pop();
|
|
5892
|
+
if (node.tagName === "script") {
|
|
5893
|
+
const rawType = node.attrs?.find((attribute) => attribute.name === "type")?.value ?? "";
|
|
5894
|
+
const normalizedType = rawType.trim().toLowerCase();
|
|
5895
|
+
const essence = rawType.split(";", 1)[0].trim().toLowerCase();
|
|
5896
|
+
const executable = /{{|{%/.test(rawType) || normalizedType === "" || normalizedType === "module" || /^(?:(?:text|application)\/(?:x-)?(?:java|ecma)script|text\/javascript1\.[0-5]|text\/(?:j|live)script)$/.test(essence);
|
|
5897
|
+
const source = node.attrs?.some((attribute) => attribute.name === "src");
|
|
5898
|
+
const body = node.childNodes?.some((child) => child.value?.trim());
|
|
5899
|
+
if (executable && (source || body)) return true;
|
|
5900
|
+
}
|
|
5901
|
+
pending.push(...node.childNodes ?? []);
|
|
5902
|
+
}
|
|
5903
|
+
return false;
|
|
5904
|
+
}
|
|
5905
|
+
/** Runtime settings can select any local asset; omission cannot authorize pruning them. */
|
|
5906
|
+
function hasResourceSettings(content) {
|
|
5907
|
+
for (const schema of content.matchAll(/{%-?\s*schema\s*-?%}([\s\S]*?){%-?\s*endschema\s*-?%}/g)) {
|
|
5908
|
+
let source;
|
|
5909
|
+
try {
|
|
5910
|
+
source = JSON.parse(schema[1]);
|
|
5911
|
+
} catch {
|
|
5912
|
+
return true;
|
|
5913
|
+
}
|
|
5914
|
+
const pending = [source];
|
|
5915
|
+
while (pending.length) {
|
|
5916
|
+
const current = pending.pop();
|
|
5917
|
+
if (!current || typeof current !== "object") continue;
|
|
5918
|
+
const record = current;
|
|
5919
|
+
const type = record.type ?? record.fieldtype;
|
|
5920
|
+
if (typeof type === "string" && /^(?:image|image_picker|video|video_picker|file|file_picker|asset|icon|url)$/.test(type)) return true;
|
|
5921
|
+
pending.push(...Object.values(record));
|
|
5922
|
+
}
|
|
5923
|
+
}
|
|
5924
|
+
return false;
|
|
5925
|
+
}
|
|
5926
|
+
/** Preserve resources referenced by retained widgets in either local or accepted bytes.
|
|
5927
|
+
* This protects omission recovery without treating local edits as accepted remotely. */
|
|
5928
|
+
async function retainedWidgetResources(retained, available, readVersions) {
|
|
5929
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
5930
|
+
const queue = [...retained].filter((path) => /^(widgets|sections|components|blocks|snippets|navbar|footer)\//.test(path));
|
|
5931
|
+
const visited = /* @__PURE__ */ new Set();
|
|
5932
|
+
const translations = /* @__PURE__ */ new Set();
|
|
5933
|
+
let dynamicTranslations = false;
|
|
5934
|
+
let dynamicAssets = false;
|
|
5935
|
+
for (const path of queue) {
|
|
5936
|
+
if (visited.has(path)) continue;
|
|
5937
|
+
visited.add(path);
|
|
5938
|
+
if (/\.m?js$/i.test(path)) dynamicAssets = true;
|
|
5939
|
+
if (!/\.(liquid|json|css|js|mjs|svg)$/.test(path)) continue;
|
|
5940
|
+
for (const bytes of await readVersions(path)) {
|
|
5941
|
+
if (!bytes) continue;
|
|
5942
|
+
const content = bytes.toString("utf8");
|
|
5943
|
+
if (!dynamicAssets && hasExecutableScript(content)) dynamicAssets = true;
|
|
5944
|
+
if (hasResourceSettings(content)) dynamicAssets = true;
|
|
5945
|
+
const executable = content.replace(/{%\s*-?\s*(comment|raw)\b[^%]*%}[\s\S]*?{%\s*-?\s*end\1\s*-?%}/g, "");
|
|
5946
|
+
for (const tag of executable.matchAll(/{{-?([\s\S]*?)-?}}|{%-?([\s\S]*?)-?%}/g)) {
|
|
5947
|
+
const expression = tag[1] ?? tag[2];
|
|
5948
|
+
const unquoted = expression.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g, (literal) => " ".repeat(literal.length));
|
|
5949
|
+
for (const filter of unquoted.matchAll(/\|\s*(t|asset_url|inline_asset_content)\b/g)) {
|
|
5950
|
+
const input = expression.slice(0, filter.index).trim();
|
|
5951
|
+
if (/^(["'])[^"']*\1$/.test(input)) continue;
|
|
5952
|
+
if (filter[1] === "t") dynamicTranslations = true;
|
|
5953
|
+
else dynamicAssets = true;
|
|
5954
|
+
}
|
|
5955
|
+
}
|
|
5956
|
+
const addAsset = (reference) => {
|
|
5957
|
+
if (/{{|{%/.test(reference)) {
|
|
5958
|
+
dynamicAssets = true;
|
|
5959
|
+
return;
|
|
5960
|
+
}
|
|
5961
|
+
const name = reference.split(/[?#]/)[0] ?? "";
|
|
5962
|
+
if (!name || /^(?:[a-z]+:|\/\/|#)/i.test(name)) return;
|
|
5963
|
+
const candidate = name.startsWith("/assets/") ? name.slice(1) : name.startsWith("assets/") ? name : posix.normalize(posix.join(path.startsWith("assets/") ? posix.dirname(path) : "assets", name));
|
|
5964
|
+
if (!candidate.startsWith("assets/") || !isThemeResourceKey(candidate) || !available.has(candidate)) return;
|
|
5965
|
+
dependencies.add(candidate);
|
|
5966
|
+
queue.push(candidate);
|
|
5967
|
+
};
|
|
5968
|
+
for (const match of content.matchAll(/["']([^"']+)["']\s*\|\s*(?:asset_url|inline_asset_content)\b/g)) addAsset(match[1]);
|
|
5969
|
+
for (const match of content.matchAll(/\b(src|srcset|href|poster|background|style)\s*=\s*["']([^"']+)["']/gi)) {
|
|
5970
|
+
const reference = match[2];
|
|
5971
|
+
if (match[1].toLowerCase() === "srcset" && !/{{|{%/.test(reference)) for (const entry of reference.split(",")) addAsset(entry.trim().split(/\s+/, 1)[0]);
|
|
5972
|
+
else addAsset(reference);
|
|
5973
|
+
}
|
|
5974
|
+
if (/\b(?:src|srcset|href|poster|background|style)\s*=\s*(?:{{|{%)/i.test(content)) dynamicAssets = true;
|
|
5975
|
+
for (const match of content.matchAll(/(?:url\(\s*["']?([^\s"')]+)["']?\s*\)|@import\s+["']([^"']+)["'])/gi)) addAsset(match[1] ?? match[2]);
|
|
5976
|
+
for (const match of content.matchAll(/["']([^"']+)["']\s*\|\s*t\b/g)) translations.add(match[1]);
|
|
5977
|
+
for (const match of content.matchAll(/{%-?\s*(section|render|include|render_block)\s+["']([^"']+)["']/g)) {
|
|
5978
|
+
const kind = match[1] === "section" ? "sections" : match[1] === "render_block" ? "blocks" : "components";
|
|
5979
|
+
for (const candidate of [`${kind}/${match[2]}/index.liquid`, `${kind}/${match[2]}.liquid`]) if (available.has(candidate) && isThemeResourceKey(candidate)) {
|
|
5980
|
+
dependencies.add(candidate);
|
|
5981
|
+
queue.push(candidate);
|
|
5982
|
+
for (const sibling of ["variables.json", "styles.css"]) {
|
|
5983
|
+
const sidecar = candidate.replace(/index\.liquid$/, sibling);
|
|
5984
|
+
if (available.has(sidecar)) {
|
|
5985
|
+
dependencies.add(sidecar);
|
|
5986
|
+
queue.push(sidecar);
|
|
5987
|
+
}
|
|
5988
|
+
}
|
|
5989
|
+
}
|
|
5990
|
+
}
|
|
5991
|
+
}
|
|
5992
|
+
}
|
|
5993
|
+
for (const path of available) {
|
|
5994
|
+
if (dynamicAssets && path.startsWith("assets/") && isThemeResourceKey(path)) dependencies.add(path);
|
|
5995
|
+
if (!/^locales\/[^/]+\.json$/.test(path)) continue;
|
|
5996
|
+
if (dynamicTranslations) {
|
|
5997
|
+
dependencies.add(path);
|
|
5998
|
+
continue;
|
|
5999
|
+
}
|
|
6000
|
+
if (translations.size === 0) continue;
|
|
6001
|
+
for (const bytes of await readVersions(path)) {
|
|
6002
|
+
if (!bytes) continue;
|
|
6003
|
+
const content = bytes.toString("utf8");
|
|
6004
|
+
let document;
|
|
6005
|
+
try {
|
|
6006
|
+
document = JSON.parse(content);
|
|
6007
|
+
} catch {
|
|
6008
|
+
dependencies.add(path);
|
|
6009
|
+
continue;
|
|
6010
|
+
}
|
|
6011
|
+
if ([...translations].some((key) => hasTranslation(document, key))) dependencies.add(path);
|
|
6012
|
+
}
|
|
6013
|
+
}
|
|
6014
|
+
return dependencies;
|
|
6015
|
+
}
|
|
6016
|
+
function hasTranslation(document, key) {
|
|
6017
|
+
let current = document;
|
|
6018
|
+
for (const segment of key.split(".")) {
|
|
6019
|
+
if (!current || typeof current !== "object" || !(segment in current)) return false;
|
|
6020
|
+
current = current[segment];
|
|
6021
|
+
}
|
|
6022
|
+
return current !== void 0;
|
|
6023
|
+
}
|
|
6024
|
+
//#endregion
|
|
5885
6025
|
//#region src/theme/merge-pull.ts
|
|
5886
6026
|
/** `write(..., RESOLVES_CONFLICT)`: this write is the chosen side of a conflict. */
|
|
5887
6027
|
const RESOLVES_CONFLICT = true;
|
|
@@ -5980,6 +6120,8 @@ async function mergePull(input) {
|
|
|
5980
6120
|
incomingPaths: remoteKeys,
|
|
5981
6121
|
ignored: (path) => themeRoot.ignore.ignore(path)
|
|
5982
6122
|
});
|
|
6123
|
+
const widgetResources = await retainedWidgetResources(retainedMemberPaths, new Set([...themeRoot.files().map((file) => file.relativePath), ...await shadow.headPaths()]), async (path) => [readIfExists(themeRoot.file(path).absolutePath), await shadow.blobAtHead(path)]);
|
|
6124
|
+
for (const path of widgetResources) if (!remoteKeys.has(path) || themeRoot.ignore.ignore(path)) retainedMemberPaths.add(path);
|
|
5983
6125
|
} catch (error) {
|
|
5984
6126
|
result.errors.push(errMsg(error));
|
|
5985
6127
|
result.baselinePreserved = true;
|
|
@@ -6633,7 +6775,7 @@ function findCartCodeDiagnostics(relativePath, content) {
|
|
|
6633
6775
|
//#region src/commands/lint.ts
|
|
6634
6776
|
function sectionNameOf(relativePath) {
|
|
6635
6777
|
const parts = relativePath.split(/[/\\]/);
|
|
6636
|
-
if (parts[0] === "sections" && parts.length >= 2) return parts[1].replace(/\.liquid$/, "");
|
|
6778
|
+
if ((parts[0] === "sections" || parts[0] === "widgets") && parts.length >= 2) return parts[1].replace(/\.liquid$/, "");
|
|
6637
6779
|
return null;
|
|
6638
6780
|
}
|
|
6639
6781
|
function createLintCommand() {
|