@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/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export { _ as SEVERITY_RANK, r as ScaffoldError, t as VTTFORGE_CLI_VERSION, o as emitReleaseZip, c as emitZip, d as formatReport, l as readManifest, f as runAudit, u as runAuditCommand, s as runBuild, a as runDev, i as runInit, n as runLintCommand, S as runManifestRules, y as runSourceRules } from "./src-BXQZFdDl.mjs";
1
+ export { _ as SEVERITY_RANK, r as ScaffoldError, t as VTTFORGE_CLI_VERSION, o as emitReleaseZip, c as emitZip, d as formatReport, l as readManifest, f as runAudit, u as runAuditCommand, s as runBuild, a as runDev, i as runInit, n as runLintCommand, S as runManifestRules, y as runSourceRules } from "./src-kJwlrLLX.mjs";
@@ -11,7 +11,7 @@ import { homedir } from "node:os";
11
11
  import { promisify } from "node:util";
12
12
  import { createRequire } from "node:module";
13
13
  // package.json
14
- var version = "0.18.9";
14
+ var version = "0.18.10";
15
15
  // src/audit/manifest-rules.ts
16
16
  /**
17
17
  * Manifest-scope audit rules.
@@ -644,7 +644,7 @@ function rule005(filePath, content) {
644
644
  severity: "MEDIUM",
645
645
  filePath,
646
646
  line: cls.startLine,
647
- message: `Class \`${cls.className}\` extends TypeDataModel directly but does not define prepareBaseData(). Active Effects apply between prepareBaseData and prepareDerivedData; without the hook, AE consumers see uninitialised fields.`,
647
+ message: `Class \`${cls.className}\` extends TypeDataModel directly but does not define prepareBaseData(). Active Effects apply in two phases. The \`initial\` phase runs between prepareBaseData and prepareDerivedData, and the \`final\` phase runs after prepareDerivedData. Without the hook, effects in the \`initial\` phase see uninitialised fields.`,
648
648
  remediation: "Add a no-op `prepareBaseData()` method (or extend `BaseTypeDataModel()` from `@vttforge/core`, which provides the stub)."
649
649
  });
650
650
  }
@@ -694,8 +694,8 @@ function rule006(filePath, content) {
694
694
  severity: "LOW",
695
695
  filePath,
696
696
  line: lineOf(content, /_addDataFieldMigrations\s*\(/),
697
- message: "The plural `_addDataFieldMigrations` is not a real Foundry API. The canonical migration hook is a static `migrateData(source)` override that calls singular `super._addDataFieldMigration(source, oldKey, newKey, apply?)` for each rename. Instance overrides named `_addDataFieldMigrations` never run.",
698
- remediation: "Replace the override with `static migrateData(source) { super._addDataFieldMigration(source, \"oldKey\", \"newKey\"); return super.migrateData(source); }`."
697
+ message: "The plural `_addDataFieldMigrations` is not a real Foundry API. The canonical migration hook is a static `migrateData(source, options)` override that calls singular `super._addDataFieldMigration(source, oldKey, newKey, apply?)` for each rename. Instance overrides named `_addDataFieldMigrations` never run.",
698
+ remediation: "Replace the override with `static migrateData(source, options) { super._addDataFieldMigration(source, \"oldKey\", \"newKey\"); return super.migrateData(source, options); }`. It must end with `return super.migrateData(source, options)`."
699
699
  }];
700
700
  }
701
701
  function findClassRanges(content) {
@@ -943,14 +943,12 @@ function buildSchemaPath(content, idx, fieldName) {
943
943
  if (!parentName) return fieldName;
944
944
  return `${buildSchemaPath(content, lookbackStart + (m.index ?? 0), parentName)}.${fieldName}`;
945
945
  }
946
- /**
947
- * Foundry's manifest convention puts TypeDataModel-driven field paths
948
- * under the `system.` root (`system.biography`). Source-side rich-field
949
- * paths from `buildSchemaPath` don't include that prefix because they
950
- * start from `defineSchema()`'s returned object. Strip it for matching.
951
- */
952
- function normalizeDeclaredPath(path) {
953
- return path.startsWith("system.") ? path.slice(7) : path;
946
+ function emptyDeclaration() {
947
+ return {
948
+ html: /* @__PURE__ */ new Set(),
949
+ filePath: /* @__PURE__ */ new Set(),
950
+ prefixed: /* @__PURE__ */ new Map()
951
+ };
954
952
  }
955
953
  /**
956
954
  * Find one subtype's declarations, accounting for the module prefix.
@@ -972,6 +970,19 @@ function lookupSubtype(declared, doc, subtype) {
972
970
  if (!prefix || !subtype.startsWith(prefix)) return void 0;
973
971
  return declared.perSubtype.get(`${doc}.${subtype.slice(prefix.length)}`);
974
972
  }
973
+ /** An entry written as `system.<path>`: the server prefixes it again. */
974
+ function prefixedFinding(filePath, line, sourcePath, type, where) {
975
+ const effect = type === "HTMLField" ? `the HTML in \`${sourcePath}\` is stored unsanitized` : `the file path in \`${sourcePath}\` is stored unchecked`;
976
+ return {
977
+ ruleId: "VTTF-AUDIT-004",
978
+ title: `${type} declared with a \`system.\` prefix is not sanitized`,
979
+ severity: "HIGH",
980
+ filePath,
981
+ line,
982
+ message: `${where} lists \`system.${sourcePath}\`. The server adds \`system.\` itself and reads \`system.system.${sourcePath}\`, which matches nothing, so ${effect}.`,
983
+ remediation: `Change \`system.${sourcePath}\` to \`${sourcePath}\` in ${where}.`
984
+ };
985
+ }
975
986
  /**
976
987
  * VTTF-AUDIT-004: cross-check source HTMLField/FilePathField usages
977
988
  * against the manifest's documentTypes declarations.
@@ -997,19 +1008,25 @@ function rule004(filePath, content, declared, classToSubtypes) {
997
1008
  });
998
1009
  if (missing.length > 0) {
999
1010
  const locations = missing.map((mapping) => `${mapping.doc}.${mapping.subtype}`).join(", ");
1000
- out.push({
1011
+ const wrong = missing.flatMap((mapping) => lookupSubtype(declared, mapping.doc, mapping.subtype)?.prefixed.get(`${declaredBucketName}:${sourcePath}`) ?? []);
1012
+ out.push(wrong.length > 0 ? prefixedFinding(filePath, usage.line, sourcePath, usage.type, [...new Set(wrong)].join(" and ")) : {
1001
1013
  ruleId: "VTTF-AUDIT-004",
1002
1014
  title: `${usage.type} not declared in manifest documentTypes`,
1003
1015
  severity: "MEDIUM",
1004
1016
  filePath,
1005
1017
  line: usage.line,
1006
1018
  message: `\`${usage.enclosingClass}\` declares \`${sourcePath}\` as ${usage.type}, but documentTypes.${locations}.${declaredBucketName} does not list this path. The Foundry server only sanitises declared paths.`,
1007
- remediation: `Add \`${sourcePath}\` (or \`system.${sourcePath}\`) to documentTypes.${missing[0]?.doc}.${missing[0]?.subtype}.${declaredBucketName} in your manifest.`
1019
+ remediation: `Add \`${sourcePath}\` to documentTypes.${missing[0]?.doc}.${missing[0]?.subtype}.${declaredBucketName} in your manifest. Write it relative to \`system\`.`
1008
1020
  });
1009
1021
  }
1010
1022
  continue;
1011
1023
  }
1012
1024
  if ((usage.type === "HTMLField" ? declared.globalHtml : declared.globalFilePath).has(sourcePath)) continue;
1025
+ const wrong = declared.globalPrefixed.get(`${declaredBucketName}:${sourcePath}`);
1026
+ if (wrong) {
1027
+ out.push(prefixedFinding(filePath, usage.line, sourcePath, usage.type, wrong));
1028
+ continue;
1029
+ }
1013
1030
  out.push({
1014
1031
  ruleId: "VTTF-AUDIT-004",
1015
1032
  title: `${usage.type} not declared in manifest documentTypes`,
@@ -1017,7 +1034,7 @@ function rule004(filePath, content, declared, classToSubtypes) {
1017
1034
  filePath,
1018
1035
  line: usage.line,
1019
1036
  message: `Schema declares \`${sourcePath}\` as ${usage.type}, but no documentTypes.<Doc>.<subtype>.${declaredBucketName} entry lists this path. The Foundry server only sanitises declared paths.`,
1020
- remediation: `Add \`${sourcePath}\` (or \`system.${sourcePath}\`) to documentTypes.<Doc>.<subtype>.${declaredBucketName} in your manifest.`
1037
+ remediation: `Add \`${sourcePath}\` to documentTypes.<Doc>.<subtype>.${declaredBucketName} in your manifest. Write it relative to \`system\`.`
1021
1038
  });
1022
1039
  }
1023
1040
  return out;
@@ -1245,6 +1262,28 @@ async function collectDeclaredRichFields(cwd) {
1245
1262
  const perSubtype = /* @__PURE__ */ new Map();
1246
1263
  const globalHtml = /* @__PURE__ */ new Set();
1247
1264
  const globalFilePath = /* @__PURE__ */ new Set();
1265
+ const globalPrefixed = /* @__PURE__ */ new Map();
1266
+ const declarePaths = (entry, source, where) => {
1267
+ const lists = [[
1268
+ "htmlFields",
1269
+ declaredPaths(source.htmlFields),
1270
+ entry.html,
1271
+ globalHtml
1272
+ ], [
1273
+ "filePathFields",
1274
+ declaredPaths(source.filePathFields),
1275
+ entry.filePath,
1276
+ globalFilePath
1277
+ ]];
1278
+ for (const [bucket, paths, own, all] of lists) for (const path of paths) if (path.startsWith("system.")) {
1279
+ const key = `${bucket}:${path.slice(7)}`;
1280
+ entry.prefixed.set(key, `${where}.${bucket}`);
1281
+ globalPrefixed.set(key, `${where}.${bucket}`);
1282
+ } else {
1283
+ own.add(path);
1284
+ all.add(path);
1285
+ }
1286
+ };
1248
1287
  let manifestPath = null;
1249
1288
  let manifestRaw = null;
1250
1289
  let manifestParsed = null;
@@ -1280,22 +1319,8 @@ async function collectDeclaredRichFields(cwd) {
1280
1319
  if (!subtype || typeof subtype !== "object" || Array.isArray(subtype)) continue;
1281
1320
  const sub = subtype;
1282
1321
  const key = `${docName}.${subName}`;
1283
- const entry = perSubtype.get(key) ?? {
1284
- html: /* @__PURE__ */ new Set(),
1285
- filePath: /* @__PURE__ */ new Set()
1286
- };
1287
- if (Array.isArray(sub.htmlFields)) {
1288
- for (const e of sub.htmlFields) if (typeof e === "string") {
1289
- const normalized = normalizeDeclaredPath(e);
1290
- entry.html.add(normalized);
1291
- globalHtml.add(normalized);
1292
- }
1293
- }
1294
- for (const declaredPath of declaredFilePathKeys(sub.filePathFields)) {
1295
- const normalized = normalizeDeclaredPath(declaredPath);
1296
- entry.filePath.add(normalized);
1297
- globalFilePath.add(normalized);
1298
- }
1322
+ const entry = perSubtype.get(key) ?? emptyDeclaration();
1323
+ declarePaths(entry, sub, `documentTypes.${key}`);
1299
1324
  perSubtype.set(key, entry);
1300
1325
  }
1301
1326
  }
@@ -1310,25 +1335,13 @@ async function collectDeclaredRichFields(cwd) {
1310
1335
  }
1311
1336
  if (template && typeof template === "object" && !Array.isArray(template)) for (const [docName, doc] of Object.entries(template)) {
1312
1337
  if (!doc || typeof doc !== "object" || Array.isArray(doc)) continue;
1313
- const { types, htmlFields, filePathFields } = doc;
1338
+ const { types } = doc;
1314
1339
  if (!Array.isArray(types)) continue;
1315
- const html = Array.isArray(htmlFields) ? htmlFields.filter((e) => typeof e === "string").map(normalizeDeclaredPath) : [];
1316
- const filePath = declaredFilePathKeys(filePathFields).map(normalizeDeclaredPath);
1317
1340
  for (const type of types) {
1318
1341
  if (typeof type !== "string") continue;
1319
1342
  const key = `${docName}.${type}`;
1320
- const entry = perSubtype.get(key) ?? {
1321
- html: /* @__PURE__ */ new Set(),
1322
- filePath: /* @__PURE__ */ new Set()
1323
- };
1324
- for (const path of html) {
1325
- entry.html.add(path);
1326
- globalHtml.add(path);
1327
- }
1328
- for (const path of filePath) {
1329
- entry.filePath.add(path);
1330
- globalFilePath.add(path);
1331
- }
1343
+ const entry = perSubtype.get(key) ?? emptyDeclaration();
1344
+ declarePaths(entry, doc, `template.json ${docName}`);
1332
1345
  perSubtype.set(key, entry);
1333
1346
  }
1334
1347
  }
@@ -1338,7 +1351,8 @@ async function collectDeclaredRichFields(cwd) {
1338
1351
  perSubtype,
1339
1352
  packageId,
1340
1353
  globalHtml,
1341
- globalFilePath
1354
+ globalFilePath,
1355
+ globalPrefixed
1342
1356
  },
1343
1357
  manifestPath,
1344
1358
  manifestRaw,
@@ -1346,15 +1360,12 @@ async function collectDeclaredRichFields(cwd) {
1346
1360
  };
1347
1361
  }
1348
1362
  /**
1349
- * Read the declared file-path keys off one subtype's `filePathFields`.
1350
- *
1351
- * The manifest shape is an object keyed by field path, whose values name
1352
- * the permitted file categories. Older hand-written manifests sometimes
1353
- * carry a bare array instead; that shape does not validate, but reading it
1354
- * costs nothing and avoids reporting a field as undeclared when the author
1355
- * plainly declared it.
1363
+ * The paths one list declares. `htmlFields` is an array. `filePathFields` is an
1364
+ * object keyed by path, whose values name the allowed file categories; some
1365
+ * hand-written manifests carry an array there, and reading it avoids reporting
1366
+ * a field its author declared.
1356
1367
  */
1357
- function declaredFilePathKeys(value) {
1368
+ function declaredPaths(value) {
1358
1369
  if (Array.isArray(value)) return value.filter((e) => typeof e === "string");
1359
1370
  if (value && typeof value === "object") return Object.keys(value);
1360
1371
  return [];
@@ -1747,6 +1758,7 @@ function bareUsePattern(name) {
1747
1758
  * VTTF-AUDIT-017 (MEDIUM): the jQuery `renderChatMessage` hook, removed in v15
1748
1759
  * VTTF-AUDIT-018 (LOW) : an Application v1 base class, removed in v16
1749
1760
  * VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias (`renderTemplate`, `ActorSheet`, ...), removed in v15
1761
+ * VTTF-AUDIT-023 (LOW) : a call on the legacy `Dialog` class (`new Dialog(`, `Dialog.confirm(`), removed in v16
1750
1762
  *
1751
1763
  * Regex heuristics like the rest of the source rules, for the same reason:
1752
1764
  * the patterns are short and a TypeScript AST would not make them more
@@ -1884,7 +1896,7 @@ function rule014(filePath, content) {
1884
1896
  severity: "MEDIUM",
1885
1897
  filePath,
1886
1898
  line: _internal.lineOf(content, pattern),
1887
- message: "Assigning an array to `CONFIG.statusEffects` empties the collection first, which drops the conditions other packages added before this code ran. v14 deprecates the assignment.",
1899
+ message: "Assigning an array to `CONFIG.statusEffects` replaces the whole palette, including the core conditions and the entries other packages added before this code ran. v14 deprecates the assignment.",
1888
1900
  remediation: "Add and remove by id: `CONFIG.statusEffects[\"my-id\"] = { id: \"my-id\", name, img }` and `delete CONFIG.statusEffects.dead`. `registerSystem` and `registerModule` do this for the `statusEffects` option."
1889
1901
  }];
1890
1902
  }
@@ -2002,6 +2014,30 @@ function rule019(filePath, content) {
2002
2014
  remediation: `Use \`${path}\`. \`vttforge migrate\` renames every alias in this list.`
2003
2015
  }];
2004
2016
  }
2017
+ /**
2018
+ * VTTF-AUDIT-023 (LOW): a call on the legacy `Dialog` class.
2019
+ *
2020
+ * Rule 018 catches `class X extends Dialog`. This one catches the callers:
2021
+ * `new Dialog(...)` and the static `Dialog.confirm`, `Dialog.prompt` and
2022
+ * `Dialog.wait`. `DialogV2` is a different name, so `\\b` after the word is
2023
+ * enough to leave it alone. A file that defines or imports its own `Dialog`
2024
+ * is not talking about the Foundry class.
2025
+ */
2026
+ function rule023(filePath, content) {
2027
+ const code = maskComments(content, { strings: true });
2028
+ if (definesName(code, "Dialog")) return [];
2029
+ const pattern = /(?<![\w$.])(?:new\s+(?:foundry\.appv1\.api\.)?Dialog\s*\(|(?:foundry\.appv1\.api\.)?Dialog\s*\.\s*(?:confirm|prompt|wait)\s*\()/;
2030
+ if (!pattern.test(code)) return [];
2031
+ return [{
2032
+ ruleId: "VTTF-AUDIT-023",
2033
+ title: "A call on the legacy Dialog class",
2034
+ severity: "LOW",
2035
+ filePath,
2036
+ line: _internal.lineOf(content, pattern),
2037
+ message: "This code opens a dialog with the Application v1 `Dialog` class, deprecated since v13 and removed in v16. It still works on v14.",
2038
+ remediation: "Use `foundry.applications.api.DialogV2`: `DialogV2.confirm({ window, content })`, `DialogV2.prompt({ ... })`, `DialogV2.wait({ ... })`, or `new DialogV2({ buttons })` for a custom one."
2039
+ }];
2040
+ }
2005
2041
  async function runV14Rules(cwd) {
2006
2042
  const results = [];
2007
2043
  for await (const file of _internal.walkSourceFiles(cwd)) {
@@ -2012,7 +2048,7 @@ async function runV14Rules(cwd) {
2012
2048
  continue;
2013
2049
  }
2014
2050
  content = maskComments(content);
2015
- results.push(...rule011(file, content), ...rule012(file, content), ...rule013(file, content), ...rule014(file, content), ...rule015(file, content), ...rule016(file, content), ...rule017(file, content), ...rule018(file, content), ...rule019(file, content));
2051
+ results.push(...rule011(file, content), ...rule012(file, content), ...rule013(file, content), ...rule014(file, content), ...rule015(file, content), ...rule016(file, content), ...rule017(file, content), ...rule018(file, content), ...rule019(file, content), ...rule023(file, content));
2016
2052
  }
2017
2053
  return results;
2018
2054
  }
@@ -2027,7 +2063,7 @@ async function runV14Rules(cwd) {
2027
2063
  * + cross-check with manifest where needed)
2028
2064
  * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
2029
2065
  * against which base each sheet is built on)
2030
- * - v14-rules.ts → VTTF-AUDIT-011 to 019 (v13 code that v14 broke
2066
+ * - v14-rules.ts → VTTF-AUDIT-011 to 019 and 023 (v13 code that v14 broke
2031
2067
  * or deprecated)
2032
2068
  * - release-rules.ts → VTTF-AUDIT-020 (a release workflow that ships the
2033
2069
  * checkout of a project that builds to dist/)
@@ -3790,4 +3826,4 @@ async function runLintCommand(options = {}) {
3790
3826
  const VTTFORGE_CLI_VERSION = version;
3791
3827
  export { runManifestRules as S, SEVERITY_RANK as _, runDev as a, maskComments as b, emitZip as c, formatReport as d, runAudit as f, definesName as g, bareUsePattern as h, runInit as i, readManifest as l, LEGACY_GLOBALS as m, runLintCommand as n, emitReleaseZip as o, REMOVED_UTILS as p, ScaffoldError as r, runBuild as s, VTTFORGE_CLI_VERSION as t, runAuditCommand as u, _internal as v, runReleaseRules as x, runSourceRules as y };
3792
3828
 
3793
- //# sourceMappingURL=src-BXQZFdDl.mjs.map
3829
+ //# sourceMappingURL=src-kJwlrLLX.mjs.map