@vttforge/cli 0.18.8 → 0.18.10

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/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @vttforge/cli
2
2
 
3
+ ## 0.18.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 150f05b: `vttforge audit` now reports a `system.`-prefixed `htmlFields` path as HIGH under rule 004. The server adds `system.` itself, so such an entry matches nothing and the HTML is stored unsanitized. Write the path relative to `system`: `"biography"`, not `"system.biography"`. The same goes for the keys of `filePathFields`, and for both lists in a `template.json`. Rule 004 no longer recommends the prefixed form.
8
+
9
+ New rule `VTTF-AUDIT-023` flags `new Dialog(` and `Dialog.confirm`, `Dialog.prompt` and `Dialog.wait` (the Application v1 class, removed in v16). The remediation text of rules 005, 006 and 014 is corrected: Active Effects have an `initial` and a `final` phase, `migrateData` takes `(source, options)` and returns `super.migrateData(source, options)`, and assigning an array to `CONFIG.statusEffects` replaces the whole palette.
10
+
11
+ `vttforge migrate` no longer renames a `rollMode` inside `messageOptions`. `Combat#rollInitiative` ignores `messageOptions.messageMode`, so the rename turned a GM-only roll public. The key stays, still works with a warning, and the report says where to move it. The status effects note now says that core conditions stay. `--data-models` carries `htmlFields`, `filePathFields` and `gmOnlyFields` per type and lists every inferred `HTMLField` path, so the generated project passes rule 004.
12
+ - e45e328: The system templates run migrations on the active Gamemaster's client. They checked `isGM`, which is true on every Gamemaster's client at once.
13
+
14
+ The TypeScript templates ask for `@vttforge/types` 0.12, which this release brings.
15
+
16
+ ## 0.18.9
17
+
18
+ ### Patch Changes
19
+
20
+ - 2609f3f: The character sheet in the system templates no longer prints a version in its footer. It said `@vttforge/styles · v0.2` whatever version the project had installed.
21
+
3
22
  ## 0.18.8
4
23
 
5
24
  ### Patch Changes
package/dist/bin.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
- import { a as runDev, b as maskComments, g as definesName, h as bareUsePattern, i as runInit, m as LEGACY_GLOBALS, n as runLintCommand, p as REMOVED_UTILS, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, v as _internal, x as runReleaseRules } from "./src-CezN6cK3.mjs";
3
- import { existsSync } from "node:fs";
2
+ import { defineCittyPlugin, defineCommand, runMain } from "citty";
3
+ import { a as runDev, b as maskComments, g as definesName, h as bareUsePattern, i as runInit, m as LEGACY_GLOBALS, n as runLintCommand, p as REMOVED_UTILS, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, v as _internal, x as runReleaseRules } from "./src-kJwlrLLX.mjs";
4
4
  import { dirname, join, relative, resolve } from "node:path";
5
+ import { existsSync } from "node:fs";
5
6
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
6
- import { defineCittyPlugin, defineCommand, runMain } from "citty";
7
7
  import { parse } from "@babel/parser";
8
- //#region src/migrate/data-models.ts
8
+ // src/migrate/data-models.ts
9
9
  const RICH_TEXT_KEYS = /^(description|biography|bio|notes|details)$/i;
10
10
  function fieldFor(key, value, path, notes, indent) {
11
11
  const next = `${indent} `;
@@ -22,7 +22,7 @@ function fieldFor(key, value, path, notes, indent) {
22
22
  if (first === void 0) notes.push(`${path}: an empty array in the template; it is an ArrayField of ObjectField. Name the element's shape if it has one.`);
23
23
  return "new f.ArrayField(new f.ObjectField())";
24
24
  }
25
- return `new f.ArrayField(${fieldFor(key, first, `${path}[]`, notes, indent)})`;
25
+ return `new f.ArrayField(${fieldFor("", first, `${path}[]`, notes, indent)})`;
26
26
  }
27
27
  if (value !== null && typeof value === "object") {
28
28
  const entries = Object.entries(value);
@@ -35,6 +35,21 @@ function fieldFor(key, value, path, notes, indent) {
35
35
  notes.push(`${path}: null in the template; it is an ObjectField. Pick the real field.`);
36
36
  return "new f.ObjectField()";
37
37
  }
38
+ /** The paths `fieldFor` turns into an `HTMLField`, relative to `system`. */
39
+ function inferredHtmlPaths(data, prefix = "") {
40
+ const out = [];
41
+ for (const [key, value] of Object.entries(data)) {
42
+ if (prefix === "" && key === "templates") continue;
43
+ const path = `${prefix}${key}`;
44
+ if (typeof value === "string" && RICH_TEXT_KEYS.test(key)) out.push(path);
45
+ else if (value !== null && typeof value === "object" && !Array.isArray(value)) out.push(...inferredHtmlPaths(value, `${path}.`));
46
+ }
47
+ return out;
48
+ }
49
+ /** Paths in a template.json list are relative to `system`; a stray prefix is dropped. */
50
+ function bare(path) {
51
+ return path.startsWith("system.") ? path.slice(7) : path;
52
+ }
38
53
  function safeKey(key) {
39
54
  return /^[A-Za-z_$][\w$]*$/.test(key) ? key : JSON.stringify(key);
40
55
  }
@@ -96,8 +111,23 @@ function planDataModels(template, { style = "plain", lang = "js", dir = "scripts
96
111
  source: classSource
97
112
  });
98
113
  const meta = {};
99
- const html = (doc.htmlFields ?? []).filter((k) => k in own || listed.some((t) => k in (templates[t] ?? {})));
114
+ const fragments = listed.filter((t) => t in templates).map((t) => templates[t] ?? {});
115
+ const declared = (doc.htmlFields ?? []).map(bare);
116
+ const inferred = [own, ...fragments].flatMap((data) => inferredHtmlPaths(data));
117
+ const html = [.../* @__PURE__ */ new Set([...declared, ...inferred])];
100
118
  if (html.length) meta.htmlFields = html;
119
+ if (Array.isArray(doc.filePathFields)) {
120
+ const paths = doc.filePathFields.map(bare);
121
+ if (paths.length) {
122
+ meta.filePathFields = Object.fromEntries(paths.map((p) => [p, ["IMAGE"]]));
123
+ notes.push(`${document}.${type}: template.json lists filePathFields without file categories. The manifest wants a category list per path, and this wrote ["IMAGE"] for each. Change it where the field holds audio, video or text.`);
124
+ }
125
+ } else if (doc.filePathFields && typeof doc.filePathFields === "object") {
126
+ const entries = Object.entries(doc.filePathFields);
127
+ if (entries.length) meta.filePathFields = Object.fromEntries(entries.map(([p, c]) => [bare(p), c]));
128
+ }
129
+ const gmOnly = (doc.gmOnlyFields ?? []).map(bare);
130
+ if (gmOnly.length) meta.gmOnlyFields = gmOnly;
101
131
  documentTypes[document][type] = meta;
102
132
  modelNames.push(`${type}: ${className}`);
103
133
  registrations.push(`import { ${className} } from './${docDir.replace(/^scripts\//, "")}/${type}-data.${ext === "ts" ? "js" : "mjs"}';`);
@@ -112,8 +142,7 @@ function planDataModels(template, { style = "plain", lang = "js", dir = "scripts
112
142
  notes
113
143
  };
114
144
  }
115
- //#endregion
116
- //#region src/migrate/sheet-templates.ts
145
+ // src/migrate/sheet-templates.ts
117
146
  /**
118
147
  * One opening tag: the name, the attribute run, and the self-closing slash.
119
148
  * Exactly three capture groups — `editTemplate` reads the replacer's `offset`
@@ -234,8 +263,7 @@ function editTemplate(template, opts) {
234
263
  formRoot: /^\s*<form\b/.test(template)
235
264
  };
236
265
  }
237
- //#endregion
238
- //#region src/migrate/parse.ts
266
+ // src/migrate/parse.ts
239
267
  /**
240
268
  * The parse side of `migrate --sheets`: an AST for the class structure, and
241
269
  * the few lookups the planner needs. Bodies are never re-printed from the
@@ -343,8 +371,7 @@ function methodOf(cls, name, opts = {}) {
343
371
  }
344
372
  return null;
345
373
  }
346
- //#endregion
347
- //#region src/migrate/sheet-bodies.ts
374
+ // src/migrate/sheet-bodies.ts
348
375
  /**
349
376
  * Text rewrites applied to method bodies carried over from an Application v1
350
377
  * sheet. Each one is scoped to the slice the planner hands it, so a pattern
@@ -865,8 +892,7 @@ function rewriteDialogs(code) {
865
892
  todos
866
893
  };
867
894
  }
868
- //#endregion
869
- //#region src/migrate/sheet-listeners.ts
895
+ // src/migrate/sheet-listeners.ts
870
896
  const EVENTS = /* @__PURE__ */ new Set([
871
897
  "click",
872
898
  "dblclick",
@@ -1057,8 +1083,7 @@ function extractListeners(cls, source) {
1057
1083
  visit(method.body.body);
1058
1084
  return out;
1059
1085
  }
1060
- //#endregion
1061
- //#region src/migrate/sheet-options.ts
1086
+ // src/migrate/sheet-options.ts
1062
1087
  function keyName(p) {
1063
1088
  if (p.key.type === "Identifier") return p.key.name;
1064
1089
  if (p.key.type === "StringLiteral") return p.key.value;
@@ -1238,8 +1263,7 @@ function renderStatics(opts, tabIds, todo, kind = "sheet", className) {
1238
1263
  lines.push(" };");
1239
1264
  return lines.join("\n");
1240
1265
  }
1241
- //#endregion
1242
- //#region src/migrate/sheets.ts
1266
+ // src/migrate/sheets.ts
1243
1267
  /** v1 lifecycle methods a sheet used to override; V2 has other hooks for the same jobs. */
1244
1268
  const V1_LIFECYCLE = /* @__PURE__ */ new Set([
1245
1269
  "setPosition",
@@ -1479,8 +1503,7 @@ function planSheetFile(relPath, source, opts) {
1479
1503
  notes
1480
1504
  };
1481
1505
  }
1482
- //#endregion
1483
- //#region src/migrate/transforms.ts
1506
+ // src/migrate/transforms.ts
1484
1507
  /**
1485
1508
  * The rewrites `vttforge migrate` applies to a v13 source file.
1486
1509
  *
@@ -1694,6 +1717,65 @@ const ROLL_MODE_CONSTANTS = {
1694
1717
  BLIND: "blind",
1695
1718
  SELF: "self"
1696
1719
  };
1720
+ /** Keeps the rollMode passes away from a key left in place on purpose. */
1721
+ const KEEP = "";
1722
+ /**
1723
+ * Leave every `rollMode` inside a `messageOptions` object as it is, with a note.
1724
+ *
1725
+ * `rollInitiative` hands `messageOptions` on, still reads a `rollMode` there
1726
+ * with a warning, and ignores a `messageMode` there. Renaming the key in place
1727
+ * would turn a GM-only roll public. The mode belongs one level up, next to
1728
+ * `messageOptions`, and where that is depends on code this pass cannot see.
1729
+ *
1730
+ * Covers the inline object, a `messageOptions` variable, and any variable a
1731
+ * `messageOptions:` key names in the same file.
1732
+ */
1733
+ function keepMessageOptions(source) {
1734
+ const code = maskComments(source, { strings: true });
1735
+ const names = /* @__PURE__ */ new Set(["messageOptions"]);
1736
+ for (const match of code.matchAll(/\bmessageOptions[\s\0]*:[\s\0]*([A-Za-z_$][\w$]*)/g)) if (match[1]) names.add(match[1]);
1737
+ const kept = /* @__PURE__ */ new Set();
1738
+ for (const name of names) {
1739
+ const head = new RegExp(`(?<![\\w$])${name.replaceAll("$", "\\$")}[\\s\\0]*(?::[^=;,(){}]*=|[:=])(?![=>])[\\s\\0]*`, "g");
1740
+ for (const match of code.matchAll(head)) {
1741
+ const from = (match.index ?? 0) + match[0].length;
1742
+ const value = code.slice(from, scanExpressionEnd(code, from));
1743
+ for (const key of value.matchAll(/\brollMode\b/g)) kept.add(from + (key.index ?? 0));
1744
+ }
1745
+ }
1746
+ const at = [...kept].sort((a, b) => a - b);
1747
+ let output = "";
1748
+ let cursor = 0;
1749
+ for (const index of at) {
1750
+ const end = index + 8;
1751
+ output += source.slice(cursor, end) + KEEP;
1752
+ cursor = end;
1753
+ }
1754
+ return {
1755
+ output: output + source.slice(cursor),
1756
+ changes: [],
1757
+ notes: at.map((index) => ({
1758
+ line: lineAt(source, index),
1759
+ rule: "roll-mode",
1760
+ message: "`rollInitiative` ignores `messageOptions.messageMode`, so this `rollMode` was left alone. It still works, with a warning. Move it out of `messageOptions` and write `messageMode` with the v14 name (`gm`, `blind`, `self`, `public`) next to it."
1761
+ }))
1762
+ };
1763
+ }
1764
+ /** Index just past the expression at `from`. `code` has comments and strings masked. */
1765
+ function scanExpressionEnd(code, from) {
1766
+ const braced = code[from] === "{";
1767
+ let depth = 0;
1768
+ for (let i = from; i < code.length; i += 1) {
1769
+ const ch = code[i];
1770
+ if (ch === "{" || ch === "[" || ch === "(") depth += 1;
1771
+ else if (ch === "}" || ch === "]" || ch === ")") {
1772
+ depth -= 1;
1773
+ if (depth < 0) return i;
1774
+ if (depth === 0 && braced) return i + 1;
1775
+ } else if ((ch === "," || ch === ";") && depth === 0) return i;
1776
+ }
1777
+ return code.length;
1778
+ }
1697
1779
  /**
1698
1780
  * `rollMode` → `messageMode`, with the value mapped when it is a literal.
1699
1781
  *
@@ -1704,11 +1786,16 @@ const ROLL_MODE_CONSTANTS = {
1704
1786
  * wrap is safe whatever the expression yields.
1705
1787
  */
1706
1788
  const rollMode = (source) => {
1707
- const option = rewrite(source, /\brollMode\s*:\s*(['"])(publicroll|gmroll|blindroll|selfroll|roll)\1/g, (_m, quote, value) => value === "roll" ? "messageMode: undefined" : `messageMode: ${quote}${ROLL_MODE_VALUES[value]}${quote}`, "roll-mode");
1789
+ const guarded = keepMessageOptions(source);
1790
+ const option = rewrite(guarded.output, /\brollMode\s*:\s*(['"])(publicroll|gmroll|blindroll|selfroll|roll)\1/g, (_m, quote, value) => value === "roll" ? "messageMode: undefined" : `messageMode: ${quote}${ROLL_MODE_VALUES[value]}${quote}`, "roll-mode");
1708
1791
  const expressions = wrapRollModeExpressions(option.output);
1709
1792
  const setting = rewrite(expressions.output, /(['"])core\1\s*,\s*(['"])rollMode\2/g, (_m, q1, q2) => `${q1}core${q1}, ${q2}messageMode${q2}`, "roll-mode");
1710
1793
  const modes = rewrite(setting.output, /\bCONFIG\.Dice\.rollModes\b/g, "CONFIG.ChatMessage.modes", "roll-mode");
1711
- return merge(option, expressions, setting, modes, rewrite(modes.output, /\bCONST\.DICE_ROLL_MODES\.(PUBLIC|PRIVATE|BLIND|SELF)\b/g, (_m, name) => `"${ROLL_MODE_CONSTANTS[name]}"`, "roll-mode"));
1794
+ const merged = merge(guarded, option, expressions, setting, modes, rewrite(modes.output, /\bCONST\.DICE_ROLL_MODES\.(PUBLIC|PRIVATE|BLIND|SELF)\b/g, (_m, name) => `"${ROLL_MODE_CONSTANTS[name]}"`, "roll-mode"));
1795
+ return {
1796
+ ...merged,
1797
+ output: merged.output.replaceAll(KEEP, "")
1798
+ };
1712
1799
  };
1713
1800
  /** `rollMode: <expr>` → `messageMode: Roll._mapLegacyRollMode(<expr>)`. */
1714
1801
  function wrapRollModeExpressions(source) {
@@ -1930,10 +2017,13 @@ const legacyTransferral = (source) => {
1930
2017
  /** v14 registers no core Actor or Item sheet, so there is nothing to unregister. */
1931
2018
  const unregisterCoreSheets = (source) => rewrite(source, /^[ \t]*(?:foundry\.documents\.collections\.)?(?:Actors|Items)\.unregisterSheet\(\s*['"]core['"][^\n]*\n?/gm, "", "unregister-core-sheets");
1932
2019
  /**
1933
- * `CONFIG.statusEffects = list;` → add each entry by id. The setter empties
1934
- * the collection first, which wipes what other packages added.
2020
+ * `CONFIG.statusEffects = list;` → add each entry by id. The assignment
2021
+ * replaces the whole palette, which wipes what other packages added. The
2022
+ * rewrite adds entries instead, so the core conditions stay, and a condition
2023
+ * the old array left out has to be deleted by id.
1935
2024
  */
1936
2025
  const statusEffectsAssignment = (source) => {
2026
+ const notes = [];
1937
2027
  const changes = [];
1938
2028
  let output = "";
1939
2029
  let cursor = 0;
@@ -1946,6 +2036,11 @@ const statusEffectsAssignment = (source) => {
1946
2036
  const end = scanStatementEnd(source, valueStart);
1947
2037
  if (end === -1) continue;
1948
2038
  const after = `for (const effect of ${source.slice(valueStart, end).trim()}) CONFIG.statusEffects[effect.id] = effect;`;
2039
+ notes.push({
2040
+ line: lineAt(source, start),
2041
+ rule: "status-effects",
2042
+ message: "The old assignment replaced the whole palette. This loop adds entries and keeps the core conditions. If the array left a core condition out on purpose, delete it by id: `delete CONFIG.statusEffects.<id>`. Entries use `name` and `img`; rename any `label` and `icon`."
2043
+ });
1949
2044
  output += source.slice(cursor, start) + after;
1950
2045
  cursor = end + 1;
1951
2046
  changes.push({
@@ -1959,7 +2054,7 @@ const statusEffectsAssignment = (source) => {
1959
2054
  return {
1960
2055
  output,
1961
2056
  changes,
1962
- notes: []
2057
+ notes
1963
2058
  };
1964
2059
  };
1965
2060
  /** Index of the `;` that ends a statement starting at `from`, brackets balanced. */
@@ -2186,8 +2281,7 @@ function topLevelKey(json, key) {
2186
2281
  }
2187
2282
  return null;
2188
2283
  }
2189
- //#endregion
2190
- //#region src/migrate/index.ts
2284
+ // src/migrate/index.ts
2191
2285
  /**
2192
2286
  * `vttforge migrate`: rewrite a v13 project for v14.
2193
2287
  *
@@ -2477,8 +2571,7 @@ function oneLine(text) {
2477
2571
  const flat = text.replace(/\s+/g, " ").trim();
2478
2572
  return flat.length > 100 ? `${flat.slice(0, 97)}...` : flat;
2479
2573
  }
2480
- //#endregion
2481
- //#region src/commands/migrate.ts
2574
+ // src/commands/migrate.ts
2482
2575
  /**
2483
2576
  * `vttforge migrate`: the CLI surface over the v13 → v14 rewrite.
2484
2577
  *
@@ -2513,8 +2606,7 @@ async function runMigrateCommand(options = {}) {
2513
2606
  exitCode: 0
2514
2607
  };
2515
2608
  }
2516
- //#endregion
2517
- //#region src/strict-args.ts
2609
+ // src/strict-args.ts
2518
2610
  /**
2519
2611
  * Refuse a flag the command does not define.
2520
2612
  *
@@ -2572,8 +2664,7 @@ const strictArgs = defineCittyPlugin({
2572
2664
  process.exit(1);
2573
2665
  }
2574
2666
  });
2575
- //#endregion
2576
- //#region src/cli.ts
2667
+ // src/cli.ts
2577
2668
  /**
2578
2669
  * vttforge command tree.
2579
2670
  *
@@ -2878,8 +2969,7 @@ const main = defineCommand({
2878
2969
  migrate
2879
2970
  }
2880
2971
  });
2881
- //#endregion
2882
- //#region src/bin.ts
2972
+ // src/bin.ts
2883
2973
  /**
2884
2974
  * vttforge bin: the executable entry.
2885
2975
  *
@@ -2887,7 +2977,6 @@ const main = defineCommand({
2887
2977
  * import it without running the CLI.
2888
2978
  */
2889
2979
  runMain(main);
2890
- //#endregion
2891
2980
  export {};
2892
2981
 
2893
2982
  //# sourceMappingURL=bin.mjs.map