@vttforge/cli 0.5.5 → 0.6.0

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,25 @@
1
1
  # @vttforge/cli
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 65e8c13: `vttforge audit` gains two rules, both for failures a real module shipped.
8
+
9
+ `VTTF-AUDIT-008` (HIGH) flags a sheet template that opens its own `<form>`. `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, so the application element already is one, and a nested form owns the fields inside it: the submit reads the outer element, finds nothing, and every edit is dropped when the window closes. No error, no warning. It only looks at templates those two bases name in their `PARTS`, so a `BaseApplication` that legitimately builds a form is left alone.
10
+
11
+ `VTTF-AUDIT-009` (MEDIUM) flags a subtype declared in `documentTypes` with no `TYPES` label. Foundry prints the raw key instead, so the sheet is titled `TYPES.Item.my-module.note` and the Create dialog offers the same string in its type dropdown. A label written nested or flattened both count, because Foundry reads both.
12
+
13
+ ### Patch Changes
14
+
15
+ - 65e8c13: The scaffolding sheet templates no longer open a `<form>` the sheet already is. `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, so the application element is the form; the nested one owned every field inside it, and the submit read the outer element and found nothing. A scaffolded project's sheets accepted every edit and dropped it when the window closed, with no error. Found by the new `VTTF-AUDIT-008`, which reported it against all four templates the first time it ran.
16
+
17
+ ## 0.5.6
18
+
19
+ ### Patch Changes
20
+
21
+ - 8a7ade5: Declare the Foundry globals with `var` so a consumer's own declarations can coexist. A package that adds `@vttforge/testing` to a typechecked project already declares `foundry`, `game`, `CONFIG`, `Hooks` and `ui` for its own source, and two `declare global` blocks only merge when both use `var`. With `const` on either side `tsc` stopped with `TS2451: Cannot redeclare block-scoped variable`, which is what a real consumer hit the first time it tried to typecheck its tests. The scaffolding templates are corrected the same way.
22
+
3
23
  ## 0.5.5
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -22,7 +22,7 @@ vttforge audit [dir] [--json] [--strict]
22
22
 
23
23
  **`build`** runs the production build and writes `<id>-<version>.zip` at the project root with the manifest at the top level, which is what foundryvtt.com expects. `LICENSE`, `README.md` and `CHANGELOG.md` go in when present.
24
24
 
25
- **`audit`** checks the manifest and source against seven v13 breakages that fail quietly: the `flags.hotReload` shape, deprecated grid fields, the v12 `styles` shape, `HTMLField`/`FilePathField` paths missing from `documentTypes`, `TypeDataModel` without `prepareBaseData`, a bad `_addDataFieldMigrations` override, and token attributes that do not point at a `{ value, max }` field. `--json` for machines; `--strict` exits non-zero on any finding rather than only on HIGH.
25
+ **`audit`** checks the manifest, the source and the templates against nine v13 breakages that fail quietly: the `flags.hotReload` shape, deprecated grid fields, the v12 `styles` shape, `HTMLField`/`FilePathField` paths missing from `documentTypes`, `TypeDataModel` without `prepareBaseData`, a bad `_addDataFieldMigrations` override, token attributes that do not point at a `{ value, max }` field, a sheet template that opens a `<form>` the sheet already is, and a declared subtype with no name in any language file. `--json` for machines; `--strict` exits non-zero on any finding rather than only on HIGH.
26
26
 
27
27
  ## As a library
28
28
 
package/dist/bin.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { M as runAuditCommand, c as runDev, n as ScaffoldError, r as runInit, t as VTTFORGE_CLI_VERSION, x as runBuild } from "./src-C1qMqkzC.mjs";
2
+ import { M as runAuditCommand, c as runDev, n as ScaffoldError, r as runInit, t as VTTFORGE_CLI_VERSION, x as runBuild } from "./src-CHdyBA95.mjs";
3
3
  import { defineCommand, runMain } from "citty";
4
4
  //#region src/cli.ts
5
5
  /**
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { A as installCommand, C as ViteNotInstalledError, D as detectPackageManager, E as spawnViteWatch, F as SEVERITY_RANK, I as runSourceRules, L as runManifestRules, M as runAuditCommand, N as formatReport, O as detectProjectPackageManager, P as runAudit, S as emitZip, T as runViteBuildOnce, _ as createLink, a as substitute, b as emitReleaseZip, c as runDev, d as configPath, f as foundryPackagesDir, g as saveConfig, h as resolveFoundryDataDir, i as scaffold, j as readManifest, k as execInvocation, l as setupDevSymlink, m as looksLikeFoundryDataDir, n as ScaffoldError, o as templatesRoot, p as loadConfig, r as runInit, s as cleanupDevSymlink, t as VTTFORGE_CLI_VERSION, u as autoDetectFoundryDataDir, v as readLinkTarget, w as resolveViteInvocation, x as runBuild, y as removeLink } from "./src-C1qMqkzC.mjs";
1
+ import { A as installCommand, C as ViteNotInstalledError, D as detectPackageManager, E as spawnViteWatch, F as SEVERITY_RANK, I as runSourceRules, L as runManifestRules, M as runAuditCommand, N as formatReport, O as detectProjectPackageManager, P as runAudit, S as emitZip, T as runViteBuildOnce, _ as createLink, a as substitute, b as emitReleaseZip, c as runDev, d as configPath, f as foundryPackagesDir, g as saveConfig, h as resolveFoundryDataDir, i as scaffold, j as readManifest, k as execInvocation, l as setupDevSymlink, m as looksLikeFoundryDataDir, n as ScaffoldError, o as templatesRoot, p as loadConfig, r as runInit, s as cleanupDevSymlink, t as VTTFORGE_CLI_VERSION, u as autoDetectFoundryDataDir, v as readLinkTarget, w as resolveViteInvocation, x as runBuild, y as removeLink } from "./src-CHdyBA95.mjs";
2
2
  export { SEVERITY_RANK, ScaffoldError, VTTFORGE_CLI_VERSION, ViteNotInstalledError, autoDetectFoundryDataDir, cleanupDevSymlink, configPath, createLink, detectPackageManager, detectProjectPackageManager, emitReleaseZip, emitZip, execInvocation, formatReport, foundryPackagesDir, installCommand, loadConfig, looksLikeFoundryDataDir, readLinkTarget, readManifest, removeLink, resolveFoundryDataDir, resolveViteInvocation, runAudit, runAuditCommand, runBuild, runDev, runInit, runManifestRules, runSourceRules, runViteBuildOnce, saveConfig, scaffold, setupDevSymlink, spawnViteWatch, substitute, templatesRoot };
@@ -10,7 +10,7 @@ import { createServer } from "node:http";
10
10
  import { homedir } from "node:os";
11
11
  import { promisify } from "node:util";
12
12
  //#region package.json
13
- var version = "0.5.5";
13
+ var version = "0.6.0";
14
14
  //#endregion
15
15
  //#region src/audit/manifest-rules.ts
16
16
  /**
@@ -23,6 +23,7 @@ var version = "0.5.5";
23
23
  * VTTF-AUDIT-001 (HIGH) : flags.hotReload shape
24
24
  * VTTF-AUDIT-002 (MEDIUM): deprecated gridDistance/gridUnits
25
25
  * VTTF-AUDIT-003 (LOW) : styles array of strings (v12 shape)
26
+ * VTTF-AUDIT-009 (MEDIUM): a documentTypes subtype with no TYPES label
26
27
  *
27
28
  * Each rule emits zero or more `RuleResult`s. Line numbers are looked up
28
29
  * cheaply by scanning the raw JSON for the offending key. Accurate
@@ -166,6 +167,93 @@ function ruleStylesShape(manifest) {
166
167
  }];
167
168
  }
168
169
  /**
170
+ * VTTF-AUDIT-009 (MEDIUM) — a declared subtype with no name.
171
+ *
172
+ * Foundry looks a subtype's label up under `TYPES.<Document>.<key>`, where a
173
+ * module's key carries its id: `TYPES.Item.my-module.note`. With the label
174
+ * missing it prints that path, so the sheet is titled
175
+ * `TYPES.Item.my-module.note: Rope` and the Create dialog offers
176
+ * `my-module.note` in its type dropdown.
177
+ *
178
+ * Nothing errors. The type works; it just has no name anywhere a reader
179
+ * looks, which is the sort of thing that ships and stays.
180
+ */
181
+ async function ruleTypeLabels(cwd, manifest) {
182
+ const documentTypes = manifest.parsed.documentTypes;
183
+ if (documentTypes === null || typeof documentTypes !== "object") return [];
184
+ const id = typeof manifest.parsed.id === "string" ? manifest.parsed.id : null;
185
+ if (id === null) return [];
186
+ const isModule = manifest.path.endsWith("module.json");
187
+ const languages = await loadLanguages(cwd, manifest);
188
+ if (languages.length === 0) return [];
189
+ const missing = [];
190
+ for (const [document, subtypes] of Object.entries(documentTypes)) {
191
+ if (subtypes === null || typeof subtypes !== "object") continue;
192
+ for (const subtype of Object.keys(subtypes)) {
193
+ const path = isModule ? [
194
+ "TYPES",
195
+ document,
196
+ id,
197
+ subtype
198
+ ] : [
199
+ "TYPES",
200
+ document,
201
+ subtype
202
+ ];
203
+ if (!languages.some((catalogue) => readPath(catalogue, path) !== void 0)) missing.push(path.join("."));
204
+ }
205
+ }
206
+ if (missing.length === 0) return [];
207
+ return [{
208
+ ruleId: "VTTF-AUDIT-009",
209
+ title: "Declared subtype has no name in any language file",
210
+ severity: "MEDIUM",
211
+ filePath: manifest.path,
212
+ line: findKeyLine(manifest.raw, "documentTypes"),
213
+ message: `No language file names ${missing.join(", ")}. Foundry falls back to printing the key, so the sheet title and the type dropdown read the raw path instead of a name.`,
214
+ remediation: `Add the label to a language file, nested: ${nestedExample(missing[0] ?? "")}`
215
+ }];
216
+ }
217
+ /** Every language catalogue the manifest declares, parsed. Unreadable ones are skipped. */
218
+ async function loadLanguages(cwd, manifest) {
219
+ const declared = manifest.parsed.languages;
220
+ if (!Array.isArray(declared)) return [];
221
+ const out = [];
222
+ for (const entry of declared) {
223
+ if (entry === null || typeof entry !== "object") continue;
224
+ const path = entry.path;
225
+ if (typeof path !== "string") continue;
226
+ try {
227
+ out.push(JSON.parse(await readFile(join(cwd, path), "utf8")));
228
+ } catch {}
229
+ }
230
+ return out;
231
+ }
232
+ /**
233
+ * Read a dotted path, allowing for either nesting.
234
+ *
235
+ * Foundry flattens its catalogues, so `{"TYPES.Item.x": "X"}` and the fully
236
+ * nested form both work. A rule that only understood one shape would report
237
+ * a label that is really there.
238
+ */
239
+ function readPath(catalogue, path) {
240
+ for (let split = path.length; split > 0; split -= 1) {
241
+ const value = catalogue[path.slice(0, split).join(".")];
242
+ if (value === void 0) continue;
243
+ if (split === path.length) return value;
244
+ if (value === null || typeof value !== "object") continue;
245
+ const rest = readPath(value, path.slice(split));
246
+ if (rest !== void 0) return rest;
247
+ }
248
+ }
249
+ /** The JSON a reader should paste, for the first missing label. */
250
+ function nestedExample(dotted) {
251
+ const parts = dotted.split(".");
252
+ let json = "\"Some Name\"";
253
+ for (const key of parts.reverse()) json = `{ ${JSON.stringify(key)}: ${json} }`;
254
+ return json;
255
+ }
256
+ /**
169
257
  * Entry point: run every manifest rule against every manifest at the
170
258
  * project root.
171
259
  */
@@ -176,6 +264,7 @@ async function runManifestRules(cwd) {
176
264
  results.push(...ruleHotReload(manifest));
177
265
  results.push(...ruleGridShape(manifest));
178
266
  results.push(...ruleStylesShape(manifest));
267
+ results.push(...await ruleTypeLabels(cwd, manifest));
179
268
  }
180
269
  return results;
181
270
  }
@@ -910,6 +999,11 @@ function buildClassToSubtypes(fileContents) {
910
999
  }
911
1000
  return map;
912
1001
  }
1002
+ /** Strip a dot-path to its final segment (e.g. `system.biography` → `biography`). */
1003
+ function lastSegment(path) {
1004
+ const idx = path.lastIndexOf(".");
1005
+ return idx < 0 ? path : path.slice(idx + 1);
1006
+ }
913
1007
  /** Entry point: gather everything once, then dispatch to the per-file rules. */
914
1008
  async function runSourceRules(cwd) {
915
1009
  if (!existsSync(cwd)) return [];
@@ -931,6 +1025,107 @@ async function runSourceRules(cwd) {
931
1025
  results.push(...await rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, classToSubtypes));
932
1026
  return results;
933
1027
  }
1028
+ const _internal = {
1029
+ walkSourceFiles,
1030
+ isSourceFile,
1031
+ lastSegment,
1032
+ findClassRanges,
1033
+ EXCLUDED_DIRS
1034
+ };
1035
+ //#endregion
1036
+ //#region src/audit/template-rules.ts
1037
+ /**
1038
+ * Template-scope audit rules.
1039
+ *
1040
+ * VTTF-AUDIT-008 (HIGH): a sheet template that opens its own `<form>`
1041
+ *
1042
+ * The two rules before this read the manifest and the source. This one reads
1043
+ * the Handlebars, because that is where the mistake lives and nothing else
1044
+ * looks there.
1045
+ */
1046
+ /**
1047
+ * The bases that make the application element a form.
1048
+ *
1049
+ * `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, which is what makes
1050
+ * `submitOnChange` work at all. `BaseApplication` and `BaseDocumentSheet` do
1051
+ * not, and a template of theirs may open a form of its own quite correctly.
1052
+ */
1053
+ const FORM_TAGGED_BASES = /extends\s+(?:[\w.]+\.)?(?:BaseActorSheet|BaseItemSheet)\s*\(/;
1054
+ /** `template: '.../foo.hbs'`, in a `static PARTS` block or anywhere near one. */
1055
+ const TEMPLATE_RE = /template:\s*[`'"]([^`'"]*\.hbs)[`'"]/g;
1056
+ /** A `<form>` start tag, ignoring what a Handlebars comment says about one. */
1057
+ const FORM_TAG_RE = /<form[\s>]/i;
1058
+ const HANDLEBARS_COMMENT_RE = /\{\{!--[\s\S]*?--\}\}|\{\{![^}]*\}\}/g;
1059
+ /**
1060
+ * The templates a form-tagged sheet declares, as paths inside the project.
1061
+ *
1062
+ * A `PARTS` entry names the path Foundry serves it from, like
1063
+ * `systems/my-system/templates/actor/sheet.hbs`. On disk the package root is
1064
+ * the project root, so the first two segments come off.
1065
+ */
1066
+ function templatesOfFormSheets(source) {
1067
+ const classes = _internal.findClassRanges(source);
1068
+ const out = [];
1069
+ for (const match of source.matchAll(TEMPLATE_RE)) {
1070
+ if (match.index === void 0) continue;
1071
+ const owner = classes.find((c) => match.index > c.openIdx && match.index < c.endIdx);
1072
+ if (!owner) continue;
1073
+ const header = source.slice(Math.max(0, owner.openIdx - 240), owner.openIdx);
1074
+ if (!FORM_TAGGED_BASES.test(header)) continue;
1075
+ const served = match[1];
1076
+ if (served === void 0) continue;
1077
+ const parts = served.split("/");
1078
+ const local = parts[0] === "systems" || parts[0] === "modules" ? parts.slice(2) : parts;
1079
+ if (local.length > 0) out.push(local.join("/"));
1080
+ }
1081
+ return [...new Set(out)];
1082
+ }
1083
+ /**
1084
+ * VTTF-AUDIT-008 (HIGH) — a sheet template that opens its own `<form>`.
1085
+ *
1086
+ * `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, so the application
1087
+ * element already is one. A `<form>` inside it owns every field inside it,
1088
+ * and the submit reads the outer element: `new FormData` on it comes back
1089
+ * empty and nothing is written.
1090
+ *
1091
+ * HIGH because of how it fails. There is no error and no warning. The sheet
1092
+ * looks right, accepts what you type, and drops it when the window closes.
1093
+ */
1094
+ async function runTemplateRules(cwd) {
1095
+ const templates = /* @__PURE__ */ new Set();
1096
+ for await (const file of _internal.walkSourceFiles(cwd)) {
1097
+ let content;
1098
+ try {
1099
+ content = await readFile(file, "utf8");
1100
+ } catch {
1101
+ continue;
1102
+ }
1103
+ for (const template of templatesOfFormSheets(content)) templates.add(template);
1104
+ }
1105
+ const results = [];
1106
+ for (const template of [...templates].sort()) {
1107
+ const path = join(cwd, template);
1108
+ let source;
1109
+ try {
1110
+ source = await readFile(path, "utf8");
1111
+ } catch {
1112
+ continue;
1113
+ }
1114
+ const markup = source.replace(HANDLEBARS_COMMENT_RE, "");
1115
+ if (!FORM_TAG_RE.test(markup)) continue;
1116
+ const line = markup.split("\n").findIndex((text) => FORM_TAG_RE.test(text)) + 1;
1117
+ results.push({
1118
+ ruleId: "VTTF-AUDIT-008",
1119
+ title: "Sheet template opens a form the sheet already is",
1120
+ severity: "HIGH",
1121
+ filePath: relative(cwd, path) || template,
1122
+ line: line > 0 ? line : 1,
1123
+ message: "This template is rendered by a sheet built on BaseActorSheet or BaseItemSheet, which set `tag: \"form\"`, so the application element already is a form. A nested form owns the fields inside it, so the submit reads the outer element and finds nothing. Every edit is dropped when the window closes, with no error.",
1124
+ remediation: "Replace the `<form>` wrapper with a `<div>`, or drop it entirely. The fields belong to the application element, and `submitOnChange` saves them as they change."
1125
+ });
1126
+ }
1127
+ return results;
1128
+ }
934
1129
  //#endregion
935
1130
  //#region src/audit/types.ts
936
1131
  /** Severity rank for sorting (HIGH first). */
@@ -949,6 +1144,8 @@ const SEVERITY_RANK = {
949
1144
  * - manifest-rules.ts → VTTF-AUDIT-001, 002, 003 (manifest-only)
950
1145
  * - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007 (source walker
951
1146
  * + cross-check with manifest where needed)
1147
+ * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
1148
+ * against which base each sheet is built on)
952
1149
  *
953
1150
  * The orchestrator stays minimal. It knows which rule sets exist, but
954
1151
  * the rules themselves are responsible for their own file IO. This keeps
@@ -965,8 +1162,16 @@ async function runAudit(options) {
965
1162
  if (!existsSync(cwd)) throw new AuditTargetError(`Audit target does not exist: ${cwd}`);
966
1163
  if (!statSync(cwd).isDirectory()) throw new AuditTargetError(`Audit target is not a directory: ${cwd}`);
967
1164
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
968
- const [manifestFindings, sourceFindings] = await Promise.all([runManifestRules(cwd), runSourceRules(cwd)]);
969
- const findings = [...manifestFindings, ...sourceFindings].sort(compareFindings);
1165
+ const [manifestFindings, sourceFindings, templateFindings] = await Promise.all([
1166
+ runManifestRules(cwd),
1167
+ runSourceRules(cwd),
1168
+ runTemplateRules(cwd)
1169
+ ]);
1170
+ const findings = [
1171
+ ...manifestFindings,
1172
+ ...sourceFindings,
1173
+ ...templateFindings
1174
+ ].sort(compareFindings);
970
1175
  return {
971
1176
  cwd,
972
1177
  startedAt,
@@ -2526,4 +2731,4 @@ const VTTFORGE_CLI_VERSION = version;
2526
2731
  //#endregion
2527
2732
  export { installCommand as A, ViteNotInstalledError as C, detectPackageManager as D, spawnViteWatch as E, SEVERITY_RANK as F, runSourceRules as I, runManifestRules as L, runAuditCommand as M, formatReport as N, detectProjectPackageManager as O, runAudit as P, emitZip as S, runViteBuildOnce as T, createLink as _, substitute as a, emitReleaseZip as b, runDev as c, configPath as d, foundryPackagesDir as f, saveConfig as g, resolveFoundryDataDir as h, scaffold as i, readManifest as j, execInvocation as k, setupDevSymlink as l, looksLikeFoundryDataDir as m, ScaffoldError as n, templatesRoot as o, loadConfig as p, runInit as r, cleanupDevSymlink as s, VTTFORGE_CLI_VERSION as t, autoDetectFoundryDataDir as u, readLinkTarget as v, resolveViteInvocation as w, runBuild as x, removeLink as y };
2528
2733
 
2529
- //# sourceMappingURL=src-C1qMqkzC.mjs.map
2734
+ //# sourceMappingURL=src-CHdyBA95.mjs.map