@vttforge/cli 0.18.9 → 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,18 @@
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
+
3
16
  ## 0.18.9
4
17
 
5
18
  ### Patch Changes
package/dist/bin.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
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-BXQZFdDl.mjs";
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
5
  import { existsSync } from "node:fs";
6
6
  import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
@@ -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"}';`);
@@ -1687,6 +1717,65 @@ const ROLL_MODE_CONSTANTS = {
1687
1717
  BLIND: "blind",
1688
1718
  SELF: "self"
1689
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
+ }
1690
1779
  /**
1691
1780
  * `rollMode` → `messageMode`, with the value mapped when it is a literal.
1692
1781
  *
@@ -1697,11 +1786,16 @@ const ROLL_MODE_CONSTANTS = {
1697
1786
  * wrap is safe whatever the expression yields.
1698
1787
  */
1699
1788
  const rollMode = (source) => {
1700
- 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");
1701
1791
  const expressions = wrapRollModeExpressions(option.output);
1702
1792
  const setting = rewrite(expressions.output, /(['"])core\1\s*,\s*(['"])rollMode\2/g, (_m, q1, q2) => `${q1}core${q1}, ${q2}messageMode${q2}`, "roll-mode");
1703
1793
  const modes = rewrite(setting.output, /\bCONFIG\.Dice\.rollModes\b/g, "CONFIG.ChatMessage.modes", "roll-mode");
1704
- 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
+ };
1705
1799
  };
1706
1800
  /** `rollMode: <expr>` → `messageMode: Roll._mapLegacyRollMode(<expr>)`. */
1707
1801
  function wrapRollModeExpressions(source) {
@@ -1923,10 +2017,13 @@ const legacyTransferral = (source) => {
1923
2017
  /** v14 registers no core Actor or Item sheet, so there is nothing to unregister. */
1924
2018
  const unregisterCoreSheets = (source) => rewrite(source, /^[ \t]*(?:foundry\.documents\.collections\.)?(?:Actors|Items)\.unregisterSheet\(\s*['"]core['"][^\n]*\n?/gm, "", "unregister-core-sheets");
1925
2019
  /**
1926
- * `CONFIG.statusEffects = list;` → add each entry by id. The setter empties
1927
- * 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.
1928
2024
  */
1929
2025
  const statusEffectsAssignment = (source) => {
2026
+ const notes = [];
1930
2027
  const changes = [];
1931
2028
  let output = "";
1932
2029
  let cursor = 0;
@@ -1939,6 +2036,11 @@ const statusEffectsAssignment = (source) => {
1939
2036
  const end = scanStatementEnd(source, valueStart);
1940
2037
  if (end === -1) continue;
1941
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
+ });
1942
2044
  output += source.slice(cursor, start) + after;
1943
2045
  cursor = end + 1;
1944
2046
  changes.push({
@@ -1952,7 +2054,7 @@ const statusEffectsAssignment = (source) => {
1952
2054
  return {
1953
2055
  output,
1954
2056
  changes,
1955
- notes: []
2057
+ notes
1956
2058
  };
1957
2059
  };
1958
2060
  /** Index of the `;` that ends a statement starting at `from`, brackets balanced. */