@vttforge/cli 0.15.2 → 0.16.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 +49 -0
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-3yl_b4Xd.mjs → src-DK2hXzBk.mjs} +125 -64
- package/dist/src-DK2hXzBk.mjs.map +1 -0
- package/package.json +1 -1
- package/templates/module-js/package.json +2 -2
- package/templates/module-js/scripts/main.mjs +2 -2
- package/templates/module-ts/package.json +2 -2
- package/templates/module-ts/scripts/main.ts +2 -2
- package/templates/system-js/package.json +2 -2
- package/templates/system-js/scripts/main.mjs +2 -2
- package/templates/system-ts/package.json +2 -2
- package/templates/system-ts/scripts/main.ts +2 -2
- package/dist/src-3yl_b4Xd.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @vttforge/cli
|
|
2
2
|
|
|
3
|
+
## 0.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3c56de9: `vttforge audit` gains VTTF-AUDIT-022: source that talks on the package socket
|
|
8
|
+
channel while the manifest has no `"socket": true`.
|
|
9
|
+
|
|
10
|
+
Foundry opens the `module.<id>` / `system.<id>` channel only for a package that
|
|
11
|
+
declares the flag. Without it `emit` returns without throwing, the message
|
|
12
|
+
never leaves the client, and nothing is logged. The listener on the other
|
|
13
|
+
machine is bound and correct and never fires, so the search goes to the
|
|
14
|
+
handler, the payload and the user permissions, and the manifest is the last
|
|
15
|
+
place anyone looks.
|
|
16
|
+
|
|
17
|
+
The rule wants the package channel. Core events ride the same socket under
|
|
18
|
+
their own names and need no flag, so `game.socket.on('userActivity', ...)` on
|
|
19
|
+
its own is not a finding. A file that names `module.<id>` or `system.<id>`, or
|
|
20
|
+
that calls `registerSocket`, is. Calls quoted in comments are skipped.
|
|
21
|
+
|
|
22
|
+
The project templates pin `@vttforge/cli` by minor, so they move to the
|
|
23
|
+
release that carries the rule.
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- 14b29cc: Point the project templates at the `@vttforge/core` minor that carries
|
|
28
|
+
`inject()`. On a 0.x line a caret pins the minor, so the old pin would have
|
|
29
|
+
scaffolded a project that cannot see it.
|
|
30
|
+
- 86b64fa: Point the project templates at the `@vttforge/core` minor that carries the
|
|
31
|
+
`api` option and the module-api helpers. On a 0.x line a caret pins the minor,
|
|
32
|
+
so the old pin would have scaffolded a project that cannot see them.
|
|
33
|
+
- ac59e0a: Point the project templates at the `@vttforge/core` minor that renames
|
|
34
|
+
`SystemConfig` to `PackageConfig`, and switch the scaffolded code to the new
|
|
35
|
+
name. On a 0.x line a caret pins the minor, so the old pin would have
|
|
36
|
+
scaffolded a project that cannot resolve it.
|
|
37
|
+
- a5623a0: Point the project templates at the `@vttforge/core` minor that carries
|
|
38
|
+
`registerSocket()`. On a 0.x line a caret pins the minor, so the old pin would
|
|
39
|
+
have scaffolded a project that cannot see the new API.
|
|
40
|
+
- 7e77931: Point the project templates at the `@vttforge/core` minor that carries
|
|
41
|
+
`convertSubTypes()`. On a 0.x line a caret pins the minor, so the old pin would
|
|
42
|
+
have scaffolded a project that cannot see it.
|
|
43
|
+
|
|
44
|
+
## 0.15.3
|
|
45
|
+
|
|
46
|
+
### Patch Changes
|
|
47
|
+
|
|
48
|
+
- 6ad9da6: Audit rule 007 reads `resourceField()` from `@vttforge/core` as a `{ value, max }` field, at the top level or nested in a SchemaField, so a system using it is not flagged. The scaffold templates pin `@vttforge/core` at the version this release publishes.
|
|
49
|
+
- e5567cb: The scaffold templates pin `@vttforge/core` at the version this release publishes.
|
|
50
|
+
- e5567cb: The scaffold templates pin `@vttforge/core` at the version this release publishes.
|
|
51
|
+
|
|
3
52
|
## 0.15.2
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
package/dist/bin.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
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-DK2hXzBk.mjs";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { dirname, join, relative, resolve } from "node:path";
|
|
5
5
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
package/dist/index.d.mts
CHANGED
|
@@ -62,7 +62,6 @@ type ReportFormat = 'json' | 'markdown';
|
|
|
62
62
|
export declare function formatReport(report: AuditReport, format: ReportFormat): string;
|
|
63
63
|
//#endregion
|
|
64
64
|
//#region src/audit/source-rules.d.ts
|
|
65
|
-
/** Entry point: gather everything once, then dispatch to the per-file rules. */
|
|
66
65
|
export declare function runSourceRules(cwd: string): Promise<RuleResult[]>;
|
|
67
66
|
//#endregion
|
|
68
67
|
//#region src/commands/audit.d.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { S as runManifestRules,
|
|
1
|
+
import { S as runManifestRules, _ as SEVERITY_RANK, a as runDev, c as emitZip, d as formatReport, f as runAudit, i as runInit, l as readManifest, n as runLintCommand, o as emitReleaseZip, r as ScaffoldError, s as runBuild, t as VTTFORGE_CLI_VERSION, u as runAuditCommand, y as runSourceRules } from "./src-DK2hXzBk.mjs";
|
|
2
2
|
export { SEVERITY_RANK, ScaffoldError, VTTFORGE_CLI_VERSION, emitReleaseZip, emitZip, formatReport, readManifest, runAudit, runAuditCommand, runBuild, runDev, runInit, runLintCommand, runManifestRules, runSourceRules };
|
|
@@ -11,7 +11,7 @@ import { createServer } from "node:http";
|
|
|
11
11
|
import { homedir } from "node:os";
|
|
12
12
|
import { promisify } from "node:util";
|
|
13
13
|
//#region package.json
|
|
14
|
-
var version = "0.
|
|
14
|
+
var version = "0.16.0";
|
|
15
15
|
//#endregion
|
|
16
16
|
//#region src/audit/manifest-rules.ts
|
|
17
17
|
/**
|
|
@@ -462,6 +462,66 @@ async function runReleaseRules(cwd) {
|
|
|
462
462
|
}
|
|
463
463
|
return findings;
|
|
464
464
|
}
|
|
465
|
+
function maskComments(source, { strings = false } = {}) {
|
|
466
|
+
const out = source.split("");
|
|
467
|
+
let quote = null;
|
|
468
|
+
let lastCode = "";
|
|
469
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
470
|
+
const ch = source[i] ?? "";
|
|
471
|
+
const next = source[i + 1] ?? "";
|
|
472
|
+
if (quote !== null) {
|
|
473
|
+
if (ch === "\\") {
|
|
474
|
+
if (strings) {
|
|
475
|
+
out[i] = "\0";
|
|
476
|
+
if (source[i + 1] !== "\n") out[i + 1] = "\0";
|
|
477
|
+
}
|
|
478
|
+
i += 1;
|
|
479
|
+
} else if (ch === quote) quote = null;
|
|
480
|
+
else if (strings && ch !== "\n") out[i] = "\0";
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
484
|
+
quote = ch;
|
|
485
|
+
lastCode = ch;
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
if (ch === "/" && next === "/") {
|
|
489
|
+
const end = source.indexOf("\n", i);
|
|
490
|
+
const stop = end === -1 ? source.length : end;
|
|
491
|
+
for (let j = i; j < stop; j += 1) out[j] = "\0";
|
|
492
|
+
i = stop - 1;
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if (ch === "/" && next === "*") {
|
|
496
|
+
const close = source.indexOf("*/", i + 2);
|
|
497
|
+
const stop = close === -1 ? source.length : close + 2;
|
|
498
|
+
for (let j = i; j < stop; j += 1) if (source[j] !== "\n") out[j] = "\0";
|
|
499
|
+
i = stop - 1;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (ch === "/" && startsRegex(lastCode)) {
|
|
503
|
+
let inClass = false;
|
|
504
|
+
let j = i + 1;
|
|
505
|
+
for (; j < source.length; j += 1) {
|
|
506
|
+
const c = source[j] ?? "";
|
|
507
|
+
if (c === "\\") j += 1;
|
|
508
|
+
else if (c === "\n") break;
|
|
509
|
+
else if (inClass) inClass = c !== "]";
|
|
510
|
+
else if (c === "[") inClass = true;
|
|
511
|
+
else if (c === "/") break;
|
|
512
|
+
}
|
|
513
|
+
i = j;
|
|
514
|
+
lastCode = "/";
|
|
515
|
+
continue;
|
|
516
|
+
}
|
|
517
|
+
if (!/\s/.test(ch)) lastCode = ch;
|
|
518
|
+
}
|
|
519
|
+
return out.join("");
|
|
520
|
+
}
|
|
521
|
+
/** After one of these a `/` opens a regex literal, not a division. */
|
|
522
|
+
function startsRegex(lastCode) {
|
|
523
|
+
return lastCode === "" || "(,=:[!&|?{};+-*%<>~^".includes(lastCode);
|
|
524
|
+
}
|
|
465
525
|
//#endregion
|
|
466
526
|
//#region src/audit/source-rules.ts
|
|
467
527
|
/**
|
|
@@ -476,12 +536,27 @@ async function runReleaseRules(cwd) {
|
|
|
476
536
|
* VTTF-AUDIT-006 (LOW) : `_addDataFieldMigrations` override (wrong signature)
|
|
477
537
|
* VTTF-AUDIT-007 (MEDIUM): manifest primary/secondaryTokenAttribute not matched
|
|
478
538
|
* by a `value`/`max` SchemaField in source
|
|
539
|
+
* VTTF-AUDIT-022 (HIGH) : source talks over the socket, manifest does not
|
|
540
|
+
* declare `"socket": true`
|
|
479
541
|
*
|
|
480
542
|
* Regex-based on purpose: avoids pulling in a TypeScript AST dependency
|
|
481
543
|
* for what amount to four pattern checks. The trade-off is occasional
|
|
482
544
|
* false negatives on heavily-formatted code; the alternative would be a
|
|
483
545
|
* 30MB+ runtime dep for marginal gains.
|
|
484
546
|
*/
|
|
547
|
+
/**
|
|
548
|
+
* `registerSocket` binds `game.socket.on` on the package channel and emits on
|
|
549
|
+
* it, so it carries the manifest requirement on its own.
|
|
550
|
+
*/
|
|
551
|
+
const REGISTER_SOCKET = /\bregisterSocket\s*\(/;
|
|
552
|
+
/** A raw `game.socket.emit(` or `game.socket.on(`. */
|
|
553
|
+
const RAW_SOCKET_CALL = /\bgame\s*\.\s*socket\s*\.\s*(?:emit|on)\s*\(/;
|
|
554
|
+
/**
|
|
555
|
+
* The package channel, in a string or a template literal. Core events travel
|
|
556
|
+
* the same socket under their own names, and those need no manifest flag, so
|
|
557
|
+
* a raw call only counts when the file also names a package channel.
|
|
558
|
+
*/
|
|
559
|
+
const PACKAGE_CHANNEL = /['"`](?:module|system)\.[^'"`\s]*/;
|
|
485
560
|
/** Directories we never descend into; they are not user source. */
|
|
486
561
|
const EXCLUDED_DIRS = /* @__PURE__ */ new Set([
|
|
487
562
|
"node_modules",
|
|
@@ -1028,6 +1103,7 @@ async function sourceHasValueMaxSchemaAtPath(sourceFiles, targetPath, actorClass
|
|
|
1028
1103
|
const owner = classes.find((c) => decl.index > c.openIdx && decl.index < c.endIdx);
|
|
1029
1104
|
if (owner && !actorClasses.has(owner.className)) continue;
|
|
1030
1105
|
}
|
|
1106
|
+
if (decl.resource) return true;
|
|
1031
1107
|
const topKeys = extractTopLevelKeys(decl.body);
|
|
1032
1108
|
if (topKeys.has("value") && topKeys.has("max")) return true;
|
|
1033
1109
|
}
|
|
@@ -1036,6 +1112,15 @@ async function sourceHasValueMaxSchemaAtPath(sourceFiles, targetPath, actorClass
|
|
|
1036
1112
|
}
|
|
1037
1113
|
function findAllSchemaFields(content) {
|
|
1038
1114
|
const out = [];
|
|
1115
|
+
for (const m of content.matchAll(/(\w+)\s*:\s*(?:[\w.]+\.)?resourceField\s*\(/g)) {
|
|
1116
|
+
if (m.index === void 0) continue;
|
|
1117
|
+
out.push({
|
|
1118
|
+
path: buildSchemaPath(content, m.index, m[1] ?? ""),
|
|
1119
|
+
body: "",
|
|
1120
|
+
index: m.index,
|
|
1121
|
+
resource: true
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1039
1124
|
for (const m of content.matchAll(/(\w+)\s*:\s*new\s+(?:[\w.]+\.)?SchemaField\s*\(\s*\{/g)) {
|
|
1040
1125
|
if (m.index === void 0) continue;
|
|
1041
1126
|
const fieldName = m[1] ?? "";
|
|
@@ -1274,6 +1359,41 @@ function lastSegment(path) {
|
|
|
1274
1359
|
return idx < 0 ? path : path.slice(idx + 1);
|
|
1275
1360
|
}
|
|
1276
1361
|
/** Entry point: gather everything once, then dispatch to the per-file rules. */
|
|
1362
|
+
/**
|
|
1363
|
+
* VTTF-AUDIT-022 (HIGH): the source uses the package socket, the manifest
|
|
1364
|
+
* does not declare it.
|
|
1365
|
+
*
|
|
1366
|
+
* Foundry only opens the `module.<id>` / `system.<id>` channel for a package
|
|
1367
|
+
* whose manifest carries `"socket": true`. Without the flag, `emit` returns
|
|
1368
|
+
* without throwing and the message never leaves the client. Nothing is
|
|
1369
|
+
* logged. The listener on the other machine is bound and correct, and it
|
|
1370
|
+
* never fires, so the search goes to the handler and the payload shape and
|
|
1371
|
+
* the user permissions, and the manifest is the last place anyone looks.
|
|
1372
|
+
*/
|
|
1373
|
+
function rule022(manifestPath, manifestRaw, manifestParsed, contents) {
|
|
1374
|
+
if (!manifestPath || !manifestRaw || !manifestParsed) return [];
|
|
1375
|
+
if (manifestParsed.socket === true) return [];
|
|
1376
|
+
const manifestName = basename(manifestPath);
|
|
1377
|
+
const out = [];
|
|
1378
|
+
for (const [file, content] of contents) {
|
|
1379
|
+
const code = maskComments(content);
|
|
1380
|
+
const registered = REGISTER_SOCKET.exec(code);
|
|
1381
|
+
const raw = PACKAGE_CHANNEL.test(code) ? RAW_SOCKET_CALL.exec(code) : null;
|
|
1382
|
+
const match = registered ?? raw;
|
|
1383
|
+
if (match?.index === void 0) continue;
|
|
1384
|
+
const call = match[0].replace(/\s*\($/, "").replaceAll(/\s+/g, "");
|
|
1385
|
+
out.push({
|
|
1386
|
+
ruleId: "VTTF-AUDIT-022",
|
|
1387
|
+
title: "Socket use with no \"socket\": true in the manifest",
|
|
1388
|
+
severity: "HIGH",
|
|
1389
|
+
filePath: file,
|
|
1390
|
+
line: content.slice(0, match.index).split("\n").length,
|
|
1391
|
+
message: `This file calls \`${call}\`, and ${manifestName} has no \`"socket": true\`. Foundry never opens the package channel, so every emit is dropped without an error and no listener on any other client fires.`,
|
|
1392
|
+
remediation: "Add `\"socket\": true` to the manifest, then restart the world. Foundry reads the flag when the package loads, so a running world keeps the old answer."
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
return out;
|
|
1396
|
+
}
|
|
1277
1397
|
async function runSourceRules(cwd) {
|
|
1278
1398
|
if (!existsSync(cwd)) return [];
|
|
1279
1399
|
if (!(await stat(cwd)).isDirectory()) return [];
|
|
@@ -1292,6 +1412,7 @@ async function runSourceRules(cwd) {
|
|
|
1292
1412
|
results.push(...rule004(file, content, declared, classToSubtypes));
|
|
1293
1413
|
}
|
|
1294
1414
|
results.push(...await rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, classToSubtypes));
|
|
1415
|
+
results.push(...rule022(manifestPath, manifestRaw, manifestParsed, contents));
|
|
1295
1416
|
return results;
|
|
1296
1417
|
}
|
|
1297
1418
|
const _internal = {
|
|
@@ -1581,66 +1702,6 @@ function definesName(source, name) {
|
|
|
1581
1702
|
function bareUsePattern(name) {
|
|
1582
1703
|
return new RegExp(`(?<![\\w$.])${name}\\b(?!\\s*:(?!:))(?=[\\s.(,;)\\]}]|$)`, "gm");
|
|
1583
1704
|
}
|
|
1584
|
-
function maskComments(source, { strings = false } = {}) {
|
|
1585
|
-
const out = source.split("");
|
|
1586
|
-
let quote = null;
|
|
1587
|
-
let lastCode = "";
|
|
1588
|
-
for (let i = 0; i < source.length; i += 1) {
|
|
1589
|
-
const ch = source[i] ?? "";
|
|
1590
|
-
const next = source[i + 1] ?? "";
|
|
1591
|
-
if (quote !== null) {
|
|
1592
|
-
if (ch === "\\") {
|
|
1593
|
-
if (strings) {
|
|
1594
|
-
out[i] = "\0";
|
|
1595
|
-
if (source[i + 1] !== "\n") out[i + 1] = "\0";
|
|
1596
|
-
}
|
|
1597
|
-
i += 1;
|
|
1598
|
-
} else if (ch === quote) quote = null;
|
|
1599
|
-
else if (strings && ch !== "\n") out[i] = "\0";
|
|
1600
|
-
continue;
|
|
1601
|
-
}
|
|
1602
|
-
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
1603
|
-
quote = ch;
|
|
1604
|
-
lastCode = ch;
|
|
1605
|
-
continue;
|
|
1606
|
-
}
|
|
1607
|
-
if (ch === "/" && next === "/") {
|
|
1608
|
-
const end = source.indexOf("\n", i);
|
|
1609
|
-
const stop = end === -1 ? source.length : end;
|
|
1610
|
-
for (let j = i; j < stop; j += 1) out[j] = "\0";
|
|
1611
|
-
i = stop - 1;
|
|
1612
|
-
continue;
|
|
1613
|
-
}
|
|
1614
|
-
if (ch === "/" && next === "*") {
|
|
1615
|
-
const close = source.indexOf("*/", i + 2);
|
|
1616
|
-
const stop = close === -1 ? source.length : close + 2;
|
|
1617
|
-
for (let j = i; j < stop; j += 1) if (source[j] !== "\n") out[j] = "\0";
|
|
1618
|
-
i = stop - 1;
|
|
1619
|
-
continue;
|
|
1620
|
-
}
|
|
1621
|
-
if (ch === "/" && startsRegex(lastCode)) {
|
|
1622
|
-
let inClass = false;
|
|
1623
|
-
let j = i + 1;
|
|
1624
|
-
for (; j < source.length; j += 1) {
|
|
1625
|
-
const c = source[j] ?? "";
|
|
1626
|
-
if (c === "\\") j += 1;
|
|
1627
|
-
else if (c === "\n") break;
|
|
1628
|
-
else if (inClass) inClass = c !== "]";
|
|
1629
|
-
else if (c === "[") inClass = true;
|
|
1630
|
-
else if (c === "/") break;
|
|
1631
|
-
}
|
|
1632
|
-
i = j;
|
|
1633
|
-
lastCode = "/";
|
|
1634
|
-
continue;
|
|
1635
|
-
}
|
|
1636
|
-
if (!/\s/.test(ch)) lastCode = ch;
|
|
1637
|
-
}
|
|
1638
|
-
return out.join("");
|
|
1639
|
-
}
|
|
1640
|
-
/** After one of these a `/` opens a regex literal, not a division. */
|
|
1641
|
-
function startsRegex(lastCode) {
|
|
1642
|
-
return lastCode === "" || "(,=:[!&|?{};+-*%<>~^".includes(lastCode);
|
|
1643
|
-
}
|
|
1644
1705
|
//#endregion
|
|
1645
1706
|
//#region src/audit/v14-rules.ts
|
|
1646
1707
|
/**
|
|
@@ -1932,7 +1993,7 @@ async function runV14Rules(cwd) {
|
|
|
1932
1993
|
*
|
|
1933
1994
|
* Rule organisation:
|
|
1934
1995
|
* - manifest-rules.ts → VTTF-AUDIT-001, 002, 003 (manifest-only)
|
|
1935
|
-
* - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007 (source walker
|
|
1996
|
+
* - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007, 022 (source walker
|
|
1936
1997
|
* + cross-check with manifest where needed)
|
|
1937
1998
|
* - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
|
|
1938
1999
|
* against which base each sheet is built on)
|
|
@@ -3710,6 +3771,6 @@ async function runLintCommand(options = {}) {
|
|
|
3710
3771
|
*/
|
|
3711
3772
|
const VTTFORGE_CLI_VERSION = version;
|
|
3712
3773
|
//#endregion
|
|
3713
|
-
export { runManifestRules as S,
|
|
3774
|
+
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 };
|
|
3714
3775
|
|
|
3715
|
-
//# sourceMappingURL=src-
|
|
3776
|
+
//# sourceMappingURL=src-DK2hXzBk.mjs.map
|