@vttforge/cli 0.5.6 → 0.7.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 +47 -0
- package/README.md +1 -1
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +1 -6
- package/dist/index.mjs +1 -1
- package/dist/{src-Cnb6Trj5.mjs → src-4Yg6Ycyo.mjs} +279 -4
- package/dist/src-4Yg6Ycyo.mjs.map +1 -0
- package/package.json +1 -1
- package/templates/module-js/package.json +2 -2
- package/templates/module-js/templates/item/note-sheet.hbs +8 -2
- package/templates/module-ts/package.json +2 -2
- package/templates/module-ts/templates/item/note-sheet.hbs +8 -2
- package/templates/system-js/README.md +0 -1
- package/templates/system-js/package.json +3 -3
- package/templates/system-js/templates/actor/character-sheet.hbs +8 -2
- package/templates/system-js/templates/item/gear-sheet.hbs +8 -2
- package/templates/system-ts/README.md +0 -1
- package/templates/system-ts/package.json +3 -3
- package/templates/system-ts/templates/actor/character-sheet.hbs +8 -2
- package/templates/system-ts/templates/item/gear-sheet.hbs +8 -2
- package/dist/src-Cnb6Trj5.mjs.map +0 -1
- package/templates/system-js/template.json +0 -8
- package/templates/system-ts/template.json +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @vttforge/cli
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 7169a30: Stop scaffolding `template.json`, and add an audit rule for the damage it does.
|
|
8
|
+
|
|
9
|
+
Foundry reads `template.json` on load and, for every type it lists, replaces that type's entry in `documentTypes` with a fresh object. Into the new object it copies only `htmlFields`, `filePathFields` and `gmOnlyFields`, and it reads them from the document level of `template.json` rather than from the type. So a system that declares this:
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
"documentTypes": { "Actor": { "character": { "htmlFields": ["biography"] } } }
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
loses it the moment `template.json` lists `character` under `Actor`. The scaffolds did both, so every system created from them shipped with its `htmlFields` quietly discarded, taking HTML sanitization, ProseMirror enrichment, asset path migration and search indexing with it. Nothing errors, and the field goes on saving and loading, so the loss shows up much later as a stripped value or a path that never migrated.
|
|
16
|
+
|
|
17
|
+
The types are declared in `system.json` under `documentTypes` and the shape comes from the `TypeDataModel`, so nothing needed the second file. New scaffolds do not ship one.
|
|
18
|
+
|
|
19
|
+
`vttforge audit` reports the collision as `VTTF-AUDIT-010` (HIGH), naming the keys that get dropped. Run it on an existing project:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npx vttforge audit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If you have a `template.json` and no type in it declares one of those three keys in `documentTypes`, nothing changes for you.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- 4f81bfd: Follow the `@vttforge/core` minor in the scaffold's pin, so a new project gets the `onI18nInit` and `onSetup` hooks.
|
|
30
|
+
|
|
31
|
+
On a `0.x` version a caret pins the minor, so `^0.11.0` would have kept new projects on the release before them.
|
|
32
|
+
- e9c184d: Follow the `@vttforge/styles` minor in the scaffold's pin.
|
|
33
|
+
|
|
34
|
+
On a `0.x` version a caret pins the minor, so `^0.3.0` would have kept new projects on the old styles. The templates ship inside this package, so the corrected pin only reaches anyone when the CLI is published too.
|
|
35
|
+
|
|
36
|
+
## 0.6.0
|
|
37
|
+
|
|
38
|
+
### Minor Changes
|
|
39
|
+
|
|
40
|
+
- 65e8c13: `vttforge audit` gains two rules, both for failures a real module shipped.
|
|
41
|
+
|
|
42
|
+
`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.
|
|
43
|
+
|
|
44
|
+
`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.
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- 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.
|
|
49
|
+
|
|
3
50
|
## 0.5.6
|
|
4
51
|
|
|
5
52
|
### 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
|
|
25
|
+
**`audit`** checks the manifest, the source and the templates against ten 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, a declared subtype with no name in any language file, and a `template.json` that erases the metadata `system.json` declares for the same type. `--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-
|
|
2
|
+
import { M as runAuditCommand, c as runDev, n as ScaffoldError, r as runInit, t as VTTFORGE_CLI_VERSION, x as runBuild } from "./src-4Yg6Ycyo.mjs";
|
|
3
3
|
import { defineCommand, runMain } from "citty";
|
|
4
4
|
//#region src/cli.ts
|
|
5
5
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,7 @@ import { ChildProcess } from "node:child_process";
|
|
|
3
3
|
/**
|
|
4
4
|
* Shared types for the `vttforge audit` rule engine.
|
|
5
5
|
*
|
|
6
|
-
* The audit catalog covers
|
|
7
|
-
* spec. Each rule produces zero or more `RuleResult` entries; the
|
|
6
|
+
* The audit catalog covers ten v13 footguns. Each rule produces zero or more `RuleResult` entries; the
|
|
8
7
|
* orchestrator aggregates them into an `AuditReport` which the reporter
|
|
9
8
|
* renders as JSON or markdown.
|
|
10
9
|
*
|
|
@@ -57,10 +56,6 @@ interface RunAuditOptions {
|
|
|
57
56
|
declare function runAudit(options: RunAuditOptions): Promise<AuditReport>;
|
|
58
57
|
//#endregion
|
|
59
58
|
//#region src/audit/manifest-rules.d.ts
|
|
60
|
-
/**
|
|
61
|
-
* Entry point: run every manifest rule against every manifest at the
|
|
62
|
-
* project root.
|
|
63
|
-
*/
|
|
64
59
|
declare function runManifestRules(cwd: string): Promise<RuleResult[]>;
|
|
65
60
|
//#endregion
|
|
66
61
|
//#region src/audit/reporter.d.ts
|
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-
|
|
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-4Yg6Ycyo.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.
|
|
13
|
+
var version = "0.7.0";
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/audit/manifest-rules.ts
|
|
16
16
|
/**
|
|
@@ -23,6 +23,8 @@ var version = "0.5.6";
|
|
|
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
|
|
27
|
+
* VTTF-AUDIT-010 (HIGH) : template.json erasing documentTypes metadata
|
|
26
28
|
*
|
|
27
29
|
* Each rule emits zero or more `RuleResult`s. Line numbers are looked up
|
|
28
30
|
* cheaply by scanning the raw JSON for the offending key. Accurate
|
|
@@ -166,9 +168,164 @@ function ruleStylesShape(manifest) {
|
|
|
166
168
|
}];
|
|
167
169
|
}
|
|
168
170
|
/**
|
|
171
|
+
* VTTF-AUDIT-009 (MEDIUM) — a declared subtype with no name.
|
|
172
|
+
*
|
|
173
|
+
* Foundry looks a subtype's label up under `TYPES.<Document>.<key>`, where a
|
|
174
|
+
* module's key carries its id: `TYPES.Item.my-module.note`. With the label
|
|
175
|
+
* missing it prints that path, so the sheet is titled
|
|
176
|
+
* `TYPES.Item.my-module.note: Rope` and the Create dialog offers
|
|
177
|
+
* `my-module.note` in its type dropdown.
|
|
178
|
+
*
|
|
179
|
+
* Nothing errors. The type works; it just has no name anywhere a reader
|
|
180
|
+
* looks, which is the sort of thing that ships and stays.
|
|
181
|
+
*/
|
|
182
|
+
async function ruleTypeLabels(cwd, manifest) {
|
|
183
|
+
const documentTypes = manifest.parsed.documentTypes;
|
|
184
|
+
if (documentTypes === null || typeof documentTypes !== "object") return [];
|
|
185
|
+
const id = typeof manifest.parsed.id === "string" ? manifest.parsed.id : null;
|
|
186
|
+
if (id === null) return [];
|
|
187
|
+
const isModule = manifest.path.endsWith("module.json");
|
|
188
|
+
const languages = await loadLanguages(cwd, manifest);
|
|
189
|
+
if (languages.length === 0) return [];
|
|
190
|
+
const missing = [];
|
|
191
|
+
for (const [document, subtypes] of Object.entries(documentTypes)) {
|
|
192
|
+
if (subtypes === null || typeof subtypes !== "object") continue;
|
|
193
|
+
for (const subtype of Object.keys(subtypes)) {
|
|
194
|
+
const path = isModule ? [
|
|
195
|
+
"TYPES",
|
|
196
|
+
document,
|
|
197
|
+
id,
|
|
198
|
+
subtype
|
|
199
|
+
] : [
|
|
200
|
+
"TYPES",
|
|
201
|
+
document,
|
|
202
|
+
subtype
|
|
203
|
+
];
|
|
204
|
+
if (!languages.some((catalogue) => readPath(catalogue, path) !== void 0)) missing.push(path.join("."));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (missing.length === 0) return [];
|
|
208
|
+
return [{
|
|
209
|
+
ruleId: "VTTF-AUDIT-009",
|
|
210
|
+
title: "Declared subtype has no name in any language file",
|
|
211
|
+
severity: "MEDIUM",
|
|
212
|
+
filePath: manifest.path,
|
|
213
|
+
line: findKeyLine(manifest.raw, "documentTypes"),
|
|
214
|
+
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.`,
|
|
215
|
+
remediation: `Add the label to a language file, nested: ${nestedExample(missing[0] ?? "")}`
|
|
216
|
+
}];
|
|
217
|
+
}
|
|
218
|
+
/** Every language catalogue the manifest declares, parsed. Unreadable ones are skipped. */
|
|
219
|
+
async function loadLanguages(cwd, manifest) {
|
|
220
|
+
const declared = manifest.parsed.languages;
|
|
221
|
+
if (!Array.isArray(declared)) return [];
|
|
222
|
+
const out = [];
|
|
223
|
+
for (const entry of declared) {
|
|
224
|
+
if (entry === null || typeof entry !== "object") continue;
|
|
225
|
+
const path = entry.path;
|
|
226
|
+
if (typeof path !== "string") continue;
|
|
227
|
+
try {
|
|
228
|
+
out.push(JSON.parse(await readFile(join(cwd, path), "utf8")));
|
|
229
|
+
} catch {}
|
|
230
|
+
}
|
|
231
|
+
return out;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Read a dotted path, allowing for either nesting.
|
|
235
|
+
*
|
|
236
|
+
* Foundry flattens its catalogues, so `{"TYPES.Item.x": "X"}` and the fully
|
|
237
|
+
* nested form both work. A rule that only understood one shape would report
|
|
238
|
+
* a label that is really there.
|
|
239
|
+
*/
|
|
240
|
+
function readPath(catalogue, path) {
|
|
241
|
+
for (let split = path.length; split > 0; split -= 1) {
|
|
242
|
+
const value = catalogue[path.slice(0, split).join(".")];
|
|
243
|
+
if (value === void 0) continue;
|
|
244
|
+
if (split === path.length) return value;
|
|
245
|
+
if (value === null || typeof value !== "object") continue;
|
|
246
|
+
const rest = readPath(value, path.slice(split));
|
|
247
|
+
if (rest !== void 0) return rest;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/** The JSON a reader should paste, for the first missing label. */
|
|
251
|
+
function nestedExample(dotted) {
|
|
252
|
+
const parts = dotted.split(".");
|
|
253
|
+
let json = "\"Some Name\"";
|
|
254
|
+
for (const key of parts.reverse()) json = `{ ${JSON.stringify(key)}: ${json} }`;
|
|
255
|
+
return json;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
169
258
|
* Entry point: run every manifest rule against every manifest at the
|
|
170
259
|
* project root.
|
|
171
260
|
*/
|
|
261
|
+
/**
|
|
262
|
+
* VTTF-AUDIT-010 (HIGH) — `template.json` erases the metadata that
|
|
263
|
+
* `system.json` declares for the same type.
|
|
264
|
+
*
|
|
265
|
+
* On load, Foundry reads `template.json` and, for every type it lists,
|
|
266
|
+
* replaces that type's entry in `documentTypes` with a fresh object. Into the
|
|
267
|
+
* new object it copies only `htmlFields`, `filePathFields` and `gmOnlyFields`,
|
|
268
|
+
* and it reads them from the document level of `template.json`, not from the
|
|
269
|
+
* type. So this in `system.json`:
|
|
270
|
+
*
|
|
271
|
+
* ```json
|
|
272
|
+
* "documentTypes": { "Actor": { "character": { "htmlFields": ["biography"] } } }
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* is thrown away the moment `template.json` lists `character` under `Actor`.
|
|
276
|
+
*
|
|
277
|
+
* Nothing errors, and the type still works. What is lost is every behaviour
|
|
278
|
+
* that keys off those lists: HTML sanitization, ProseMirror enrichment, asset
|
|
279
|
+
* path migration and search indexing. The field goes on saving and loading,
|
|
280
|
+
* so the loss is invisible until a value comes back stripped or a path fails
|
|
281
|
+
* to migrate.
|
|
282
|
+
*
|
|
283
|
+
* A system whose schemas come from `TypeDataModel` does not need
|
|
284
|
+
* `template.json` at all: `documentTypes` declares the types and the data
|
|
285
|
+
* model owns the shape.
|
|
286
|
+
*/
|
|
287
|
+
function ruleTemplateJsonShadowing(cwd, manifest) {
|
|
288
|
+
if (!manifest.path.endsWith("system.json")) return [];
|
|
289
|
+
const templatePath = join(cwd, "template.json");
|
|
290
|
+
if (!existsSync(templatePath)) return [];
|
|
291
|
+
const documentTypes = manifest.parsed.documentTypes;
|
|
292
|
+
if (documentTypes === null || typeof documentTypes !== "object") return [];
|
|
293
|
+
let template;
|
|
294
|
+
try {
|
|
295
|
+
template = JSON.parse(readFileSync(templatePath, "utf8"));
|
|
296
|
+
} catch {
|
|
297
|
+
return [];
|
|
298
|
+
}
|
|
299
|
+
const CARRIED = [
|
|
300
|
+
"htmlFields",
|
|
301
|
+
"filePathFields",
|
|
302
|
+
"gmOnlyFields"
|
|
303
|
+
];
|
|
304
|
+
const results = [];
|
|
305
|
+
for (const [documentName, declared] of Object.entries(documentTypes)) {
|
|
306
|
+
if (declared === null || typeof declared !== "object") continue;
|
|
307
|
+
const templateDoc = template[documentName];
|
|
308
|
+
if (templateDoc === null || typeof templateDoc !== "object") continue;
|
|
309
|
+
const listed = templateDoc.types;
|
|
310
|
+
if (!Array.isArray(listed)) continue;
|
|
311
|
+
for (const [type, meta] of Object.entries(declared)) {
|
|
312
|
+
if (!listed.includes(type)) continue;
|
|
313
|
+
if (meta === null || typeof meta !== "object") continue;
|
|
314
|
+
const lost = CARRIED.filter((key) => key in meta && !(key in templateDoc));
|
|
315
|
+
if (lost.length === 0) continue;
|
|
316
|
+
results.push({
|
|
317
|
+
ruleId: "VTTF-AUDIT-010",
|
|
318
|
+
title: "template.json erases documentTypes metadata",
|
|
319
|
+
severity: "HIGH",
|
|
320
|
+
filePath: "template.json",
|
|
321
|
+
line: findKeyLine(readFileSync(templatePath, "utf8"), documentName),
|
|
322
|
+
message: `template.json lists ${documentName} type "${type}", so Foundry replaces that type's documentTypes entry and drops ${lost.join(", ")} declared in system.json. Sanitization, enrichment and asset migration stop applying to those fields, silently.`,
|
|
323
|
+
remediation: "Delete template.json. Your types are declared in system.json under `documentTypes`, and the schema comes from the TypeDataModel registered on `CONFIG.<Document>.dataModels`. If you still need it, move the lost keys up to the document level of template.json instead of the type."
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return results;
|
|
328
|
+
}
|
|
172
329
|
async function runManifestRules(cwd) {
|
|
173
330
|
const manifests = await loadManifests(cwd);
|
|
174
331
|
const results = [];
|
|
@@ -176,6 +333,8 @@ async function runManifestRules(cwd) {
|
|
|
176
333
|
results.push(...ruleHotReload(manifest));
|
|
177
334
|
results.push(...ruleGridShape(manifest));
|
|
178
335
|
results.push(...ruleStylesShape(manifest));
|
|
336
|
+
results.push(...await ruleTypeLabels(cwd, manifest));
|
|
337
|
+
results.push(...ruleTemplateJsonShadowing(cwd, manifest));
|
|
179
338
|
}
|
|
180
339
|
return results;
|
|
181
340
|
}
|
|
@@ -910,6 +1069,11 @@ function buildClassToSubtypes(fileContents) {
|
|
|
910
1069
|
}
|
|
911
1070
|
return map;
|
|
912
1071
|
}
|
|
1072
|
+
/** Strip a dot-path to its final segment (e.g. `system.biography` → `biography`). */
|
|
1073
|
+
function lastSegment(path) {
|
|
1074
|
+
const idx = path.lastIndexOf(".");
|
|
1075
|
+
return idx < 0 ? path : path.slice(idx + 1);
|
|
1076
|
+
}
|
|
913
1077
|
/** Entry point: gather everything once, then dispatch to the per-file rules. */
|
|
914
1078
|
async function runSourceRules(cwd) {
|
|
915
1079
|
if (!existsSync(cwd)) return [];
|
|
@@ -931,6 +1095,107 @@ async function runSourceRules(cwd) {
|
|
|
931
1095
|
results.push(...await rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, classToSubtypes));
|
|
932
1096
|
return results;
|
|
933
1097
|
}
|
|
1098
|
+
const _internal = {
|
|
1099
|
+
walkSourceFiles,
|
|
1100
|
+
isSourceFile,
|
|
1101
|
+
lastSegment,
|
|
1102
|
+
findClassRanges,
|
|
1103
|
+
EXCLUDED_DIRS
|
|
1104
|
+
};
|
|
1105
|
+
//#endregion
|
|
1106
|
+
//#region src/audit/template-rules.ts
|
|
1107
|
+
/**
|
|
1108
|
+
* Template-scope audit rules.
|
|
1109
|
+
*
|
|
1110
|
+
* VTTF-AUDIT-008 (HIGH): a sheet template that opens its own `<form>`
|
|
1111
|
+
*
|
|
1112
|
+
* The two rules before this read the manifest and the source. This one reads
|
|
1113
|
+
* the Handlebars, because that is where the mistake lives and nothing else
|
|
1114
|
+
* looks there.
|
|
1115
|
+
*/
|
|
1116
|
+
/**
|
|
1117
|
+
* The bases that make the application element a form.
|
|
1118
|
+
*
|
|
1119
|
+
* `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, which is what makes
|
|
1120
|
+
* `submitOnChange` work at all. `BaseApplication` and `BaseDocumentSheet` do
|
|
1121
|
+
* not, and a template of theirs may open a form of its own quite correctly.
|
|
1122
|
+
*/
|
|
1123
|
+
const FORM_TAGGED_BASES = /extends\s+(?:[\w.]+\.)?(?:BaseActorSheet|BaseItemSheet)\s*\(/;
|
|
1124
|
+
/** `template: '.../foo.hbs'`, in a `static PARTS` block or anywhere near one. */
|
|
1125
|
+
const TEMPLATE_RE = /template:\s*[`'"]([^`'"]*\.hbs)[`'"]/g;
|
|
1126
|
+
/** A `<form>` start tag, ignoring what a Handlebars comment says about one. */
|
|
1127
|
+
const FORM_TAG_RE = /<form[\s>]/i;
|
|
1128
|
+
const HANDLEBARS_COMMENT_RE = /\{\{!--[\s\S]*?--\}\}|\{\{![^}]*\}\}/g;
|
|
1129
|
+
/**
|
|
1130
|
+
* The templates a form-tagged sheet declares, as paths inside the project.
|
|
1131
|
+
*
|
|
1132
|
+
* A `PARTS` entry names the path Foundry serves it from, like
|
|
1133
|
+
* `systems/my-system/templates/actor/sheet.hbs`. On disk the package root is
|
|
1134
|
+
* the project root, so the first two segments come off.
|
|
1135
|
+
*/
|
|
1136
|
+
function templatesOfFormSheets(source) {
|
|
1137
|
+
const classes = _internal.findClassRanges(source);
|
|
1138
|
+
const out = [];
|
|
1139
|
+
for (const match of source.matchAll(TEMPLATE_RE)) {
|
|
1140
|
+
if (match.index === void 0) continue;
|
|
1141
|
+
const owner = classes.find((c) => match.index > c.openIdx && match.index < c.endIdx);
|
|
1142
|
+
if (!owner) continue;
|
|
1143
|
+
const header = source.slice(Math.max(0, owner.openIdx - 240), owner.openIdx);
|
|
1144
|
+
if (!FORM_TAGGED_BASES.test(header)) continue;
|
|
1145
|
+
const served = match[1];
|
|
1146
|
+
if (served === void 0) continue;
|
|
1147
|
+
const parts = served.split("/");
|
|
1148
|
+
const local = parts[0] === "systems" || parts[0] === "modules" ? parts.slice(2) : parts;
|
|
1149
|
+
if (local.length > 0) out.push(local.join("/"));
|
|
1150
|
+
}
|
|
1151
|
+
return [...new Set(out)];
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* VTTF-AUDIT-008 (HIGH) — a sheet template that opens its own `<form>`.
|
|
1155
|
+
*
|
|
1156
|
+
* `BaseActorSheet` and `BaseItemSheet` set `tag: 'form'`, so the application
|
|
1157
|
+
* element already is one. A `<form>` inside it owns every field inside it,
|
|
1158
|
+
* and the submit reads the outer element: `new FormData` on it comes back
|
|
1159
|
+
* empty and nothing is written.
|
|
1160
|
+
*
|
|
1161
|
+
* HIGH because of how it fails. There is no error and no warning. The sheet
|
|
1162
|
+
* looks right, accepts what you type, and drops it when the window closes.
|
|
1163
|
+
*/
|
|
1164
|
+
async function runTemplateRules(cwd) {
|
|
1165
|
+
const templates = /* @__PURE__ */ new Set();
|
|
1166
|
+
for await (const file of _internal.walkSourceFiles(cwd)) {
|
|
1167
|
+
let content;
|
|
1168
|
+
try {
|
|
1169
|
+
content = await readFile(file, "utf8");
|
|
1170
|
+
} catch {
|
|
1171
|
+
continue;
|
|
1172
|
+
}
|
|
1173
|
+
for (const template of templatesOfFormSheets(content)) templates.add(template);
|
|
1174
|
+
}
|
|
1175
|
+
const results = [];
|
|
1176
|
+
for (const template of [...templates].sort()) {
|
|
1177
|
+
const path = join(cwd, template);
|
|
1178
|
+
let source;
|
|
1179
|
+
try {
|
|
1180
|
+
source = await readFile(path, "utf8");
|
|
1181
|
+
} catch {
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
const markup = source.replace(HANDLEBARS_COMMENT_RE, "");
|
|
1185
|
+
if (!FORM_TAG_RE.test(markup)) continue;
|
|
1186
|
+
const line = markup.split("\n").findIndex((text) => FORM_TAG_RE.test(text)) + 1;
|
|
1187
|
+
results.push({
|
|
1188
|
+
ruleId: "VTTF-AUDIT-008",
|
|
1189
|
+
title: "Sheet template opens a form the sheet already is",
|
|
1190
|
+
severity: "HIGH",
|
|
1191
|
+
filePath: relative(cwd, path) || template,
|
|
1192
|
+
line: line > 0 ? line : 1,
|
|
1193
|
+
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.",
|
|
1194
|
+
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."
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
return results;
|
|
1198
|
+
}
|
|
934
1199
|
//#endregion
|
|
935
1200
|
//#region src/audit/types.ts
|
|
936
1201
|
/** Severity rank for sorting (HIGH first). */
|
|
@@ -949,6 +1214,8 @@ const SEVERITY_RANK = {
|
|
|
949
1214
|
* - manifest-rules.ts → VTTF-AUDIT-001, 002, 003 (manifest-only)
|
|
950
1215
|
* - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007 (source walker
|
|
951
1216
|
* + cross-check with manifest where needed)
|
|
1217
|
+
* - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
|
|
1218
|
+
* against which base each sheet is built on)
|
|
952
1219
|
*
|
|
953
1220
|
* The orchestrator stays minimal. It knows which rule sets exist, but
|
|
954
1221
|
* the rules themselves are responsible for their own file IO. This keeps
|
|
@@ -965,8 +1232,16 @@ async function runAudit(options) {
|
|
|
965
1232
|
if (!existsSync(cwd)) throw new AuditTargetError(`Audit target does not exist: ${cwd}`);
|
|
966
1233
|
if (!statSync(cwd).isDirectory()) throw new AuditTargetError(`Audit target is not a directory: ${cwd}`);
|
|
967
1234
|
const startedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
968
|
-
const [manifestFindings, sourceFindings] = await Promise.all([
|
|
969
|
-
|
|
1235
|
+
const [manifestFindings, sourceFindings, templateFindings] = await Promise.all([
|
|
1236
|
+
runManifestRules(cwd),
|
|
1237
|
+
runSourceRules(cwd),
|
|
1238
|
+
runTemplateRules(cwd)
|
|
1239
|
+
]);
|
|
1240
|
+
const findings = [
|
|
1241
|
+
...manifestFindings,
|
|
1242
|
+
...sourceFindings,
|
|
1243
|
+
...templateFindings
|
|
1244
|
+
].sort(compareFindings);
|
|
970
1245
|
return {
|
|
971
1246
|
cwd,
|
|
972
1247
|
startedAt,
|
|
@@ -2526,4 +2801,4 @@ const VTTFORGE_CLI_VERSION = version;
|
|
|
2526
2801
|
//#endregion
|
|
2527
2802
|
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
2803
|
|
|
2529
|
-
//# sourceMappingURL=src-
|
|
2804
|
+
//# sourceMappingURL=src-4Yg6Ycyo.mjs.map
|