@vttforge/cli 0.15.3 → 0.17.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/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, a as runDev, b as runSourceRules, 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, v as SEVERITY_RANK } from "./src-vwmR9t7H.mjs";
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-GF89Qav8.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.15.3";
14
+ var version = "0.17.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",
@@ -1284,6 +1359,41 @@ function lastSegment(path) {
1284
1359
  return idx < 0 ? path : path.slice(idx + 1);
1285
1360
  }
1286
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
+ }
1287
1397
  async function runSourceRules(cwd) {
1288
1398
  if (!existsSync(cwd)) return [];
1289
1399
  if (!(await stat(cwd)).isDirectory()) return [];
@@ -1302,6 +1412,7 @@ async function runSourceRules(cwd) {
1302
1412
  results.push(...rule004(file, content, declared, classToSubtypes));
1303
1413
  }
1304
1414
  results.push(...await rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, classToSubtypes));
1415
+ results.push(...rule022(manifestPath, manifestRaw, manifestParsed, contents));
1305
1416
  return results;
1306
1417
  }
1307
1418
  const _internal = {
@@ -1591,66 +1702,6 @@ function definesName(source, name) {
1591
1702
  function bareUsePattern(name) {
1592
1703
  return new RegExp(`(?<![\\w$.])${name}\\b(?!\\s*:(?!:))(?=[\\s.(,;)\\]}]|$)`, "gm");
1593
1704
  }
1594
- function maskComments(source, { strings = false } = {}) {
1595
- const out = source.split("");
1596
- let quote = null;
1597
- let lastCode = "";
1598
- for (let i = 0; i < source.length; i += 1) {
1599
- const ch = source[i] ?? "";
1600
- const next = source[i + 1] ?? "";
1601
- if (quote !== null) {
1602
- if (ch === "\\") {
1603
- if (strings) {
1604
- out[i] = "\0";
1605
- if (source[i + 1] !== "\n") out[i + 1] = "\0";
1606
- }
1607
- i += 1;
1608
- } else if (ch === quote) quote = null;
1609
- else if (strings && ch !== "\n") out[i] = "\0";
1610
- continue;
1611
- }
1612
- if (ch === "\"" || ch === "'" || ch === "`") {
1613
- quote = ch;
1614
- lastCode = ch;
1615
- continue;
1616
- }
1617
- if (ch === "/" && next === "/") {
1618
- const end = source.indexOf("\n", i);
1619
- const stop = end === -1 ? source.length : end;
1620
- for (let j = i; j < stop; j += 1) out[j] = "\0";
1621
- i = stop - 1;
1622
- continue;
1623
- }
1624
- if (ch === "/" && next === "*") {
1625
- const close = source.indexOf("*/", i + 2);
1626
- const stop = close === -1 ? source.length : close + 2;
1627
- for (let j = i; j < stop; j += 1) if (source[j] !== "\n") out[j] = "\0";
1628
- i = stop - 1;
1629
- continue;
1630
- }
1631
- if (ch === "/" && startsRegex(lastCode)) {
1632
- let inClass = false;
1633
- let j = i + 1;
1634
- for (; j < source.length; j += 1) {
1635
- const c = source[j] ?? "";
1636
- if (c === "\\") j += 1;
1637
- else if (c === "\n") break;
1638
- else if (inClass) inClass = c !== "]";
1639
- else if (c === "[") inClass = true;
1640
- else if (c === "/") break;
1641
- }
1642
- i = j;
1643
- lastCode = "/";
1644
- continue;
1645
- }
1646
- if (!/\s/.test(ch)) lastCode = ch;
1647
- }
1648
- return out.join("");
1649
- }
1650
- /** After one of these a `/` opens a regex literal, not a division. */
1651
- function startsRegex(lastCode) {
1652
- return lastCode === "" || "(,=:[!&|?{};+-*%<>~^".includes(lastCode);
1653
- }
1654
1705
  //#endregion
1655
1706
  //#region src/audit/v14-rules.ts
1656
1707
  /**
@@ -1942,7 +1993,7 @@ async function runV14Rules(cwd) {
1942
1993
  *
1943
1994
  * Rule organisation:
1944
1995
  * - manifest-rules.ts → VTTF-AUDIT-001, 002, 003 (manifest-only)
1945
- * - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007 (source walker
1996
+ * - source-rules.ts → VTTF-AUDIT-004, 005, 006, 007, 022 (source walker
1946
1997
  * + cross-check with manifest where needed)
1947
1998
  * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
1948
1999
  * against which base each sheet is built on)
@@ -3412,8 +3463,10 @@ async function runInit(options = {}) {
3412
3463
  } else if (!PACKAGE_ID_RE.test(name)) bail(`Invalid name "${name}": use only lowercase letters, digits, and dashes (no spaces, slashes, dots).`);
3413
3464
  const dest = resolve(cwd, name);
3414
3465
  if (existsSync(dest)) bail(`Directory already exists: ${dest}`);
3466
+ const requestedType = options.type;
3467
+ if (requestedType !== void 0 && requestedType !== "system" && requestedType !== "module") bail(`--type expects \`system\` or \`module\`, got \`${requestedType}\`.`);
3415
3468
  let type = options.type;
3416
- if (type !== "system" && type !== "module" && !interactive) type = "system";
3469
+ if (type === void 0 && !interactive) type = "system";
3417
3470
  if (type !== "system" && type !== "module") {
3418
3471
  const answer = await p.select({
3419
3472
  message: "What are you building?",
@@ -3429,8 +3482,10 @@ async function runInit(options = {}) {
3429
3482
  if (isCancelled(answer)) bail("Scaffold cancelled.");
3430
3483
  type = answer;
3431
3484
  }
3485
+ const requestedLang = options.lang;
3486
+ if (requestedLang !== void 0 && requestedLang !== "ts" && requestedLang !== "js") bail(`--lang expects \`ts\` or \`js\`, got \`${requestedLang}\`.`);
3432
3487
  let lang = options.lang;
3433
- if (lang !== "ts" && lang !== "js" && !interactive) lang = "ts";
3488
+ if (lang === void 0 && !interactive) lang = "ts";
3434
3489
  if (lang !== "ts" && lang !== "js") {
3435
3490
  const answer = await p.select({
3436
3491
  message: "Language",
@@ -3720,6 +3775,6 @@ async function runLintCommand(options = {}) {
3720
3775
  */
3721
3776
  const VTTFORGE_CLI_VERSION = version;
3722
3777
  //#endregion
3723
- export { runManifestRules as S, definesName as _, runDev as a, runSourceRules as b, emitZip as c, formatReport as d, runAudit as f, bareUsePattern as g, LEGACY_GLOBALS as h, runInit as i, readManifest as l, maskComments 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, SEVERITY_RANK as v, runReleaseRules as x, _internal as y };
3778
+ 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 };
3724
3779
 
3725
- //# sourceMappingURL=src-vwmR9t7H.mjs.map
3780
+ //# sourceMappingURL=src-GF89Qav8.mjs.map