@vttforge/cli 0.10.0 → 0.11.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.
@@ -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.10.0";
13
+ var version = "0.11.0";
14
14
  //#endregion
15
15
  //#region src/audit/manifest-rules.ts
16
16
  /**
@@ -381,6 +381,7 @@ const SOURCE_EXTENSIONS = [
381
381
  ];
382
382
  function isSourceFile(name) {
383
383
  if (name.endsWith(".d.ts") || name.endsWith(".d.mts") || name.endsWith(".d.cts")) return false;
384
+ if (/\.min\.[cm]?js$/.test(name)) return false;
384
385
  return SOURCE_EXTENSIONS.some((ext) => name.endsWith(ext));
385
386
  }
386
387
  async function* walkSourceFiles(cwd) {
@@ -813,7 +814,7 @@ async function rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, c
813
814
  for (const key of ["primaryTokenAttribute", "secondaryTokenAttribute"]) {
814
815
  const value = manifestParsed[key];
815
816
  if (typeof value !== "string" || value.length === 0) continue;
816
- if (!await sourceHasValueMaxSchemaAtPath(sourceFiles, value, actorClasses)) out.push({
817
+ if (!(await sourceHasValueMaxSchemaAtPath(sourceFiles, value, actorClasses) || templateJsonHasValueMax(manifestPath, value))) out.push({
817
818
  ruleId: "VTTF-AUDIT-007",
818
819
  title: `${key} does not resolve to a {value, max} SchemaField`,
819
820
  severity: "MEDIUM",
@@ -825,6 +826,39 @@ async function rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, c
825
826
  }
826
827
  return out;
827
828
  }
829
+ /**
830
+ * The same check against `template.json`, for a system that still declares
831
+ * its types there. Each Actor type is the merge of the templates it lists and
832
+ * its own keys; the path resolves when any type has an object with `value`
833
+ * and `max` at it. Foundry reads the bar the same way, per actor.
834
+ */
835
+ function templateJsonHasValueMax(manifestPath, path) {
836
+ const file = join(dirname(manifestPath), "template.json");
837
+ if (!existsSync(file)) return false;
838
+ let template;
839
+ try {
840
+ template = JSON.parse(readFileSync(file, "utf8"));
841
+ } catch {
842
+ return false;
843
+ }
844
+ const actor = template.Actor;
845
+ if (!actor || typeof actor !== "object") return false;
846
+ const { types = [], templates = {} } = actor;
847
+ for (const type of types) {
848
+ const own = actor[type];
849
+ if (!own || typeof own !== "object") continue;
850
+ const merged = {};
851
+ for (const name of own.templates ?? []) Object.assign(merged, templates[name] ?? {});
852
+ Object.assign(merged, own);
853
+ let node = merged;
854
+ for (const segment of path.split(".")) {
855
+ if (!node || typeof node !== "object") break;
856
+ node = node[segment];
857
+ }
858
+ if (node && typeof node === "object" && "value" in node && "max" in node) return true;
859
+ }
860
+ return false;
861
+ }
828
862
  function lineOfInRaw(raw, key) {
829
863
  const idx = raw.indexOf(`"${key}"`);
830
864
  if (idx < 0) return void 0;
@@ -1206,6 +1240,192 @@ const SEVERITY_RANK = {
1206
1240
  LOW: 2
1207
1241
  };
1208
1242
  //#endregion
1243
+ //#region src/audit/legacy-globals.ts
1244
+ /**
1245
+ * The bare globals v13 turned into aliases of a `foundry.*` path.
1246
+ *
1247
+ * Each still resolves on v14 with a deprecation warning, and none resolves
1248
+ * on v15. The namespaced path is the same object, so a rewrite from one to
1249
+ * the other changes nothing at runtime and removes a removal date. The list
1250
+ * is the part of the public API a system or module is likely to reach for
1251
+ * bare; the canvas shaders and the rest are left out on purpose.
1252
+ *
1253
+ * `Application`, `FormApplication`, `Dialog` and `DocumentSheet` are not
1254
+ * here: those are plain aliases with no warning, and the whole v1 framework
1255
+ * goes in v16, which `VTTF-AUDIT-018` reports.
1256
+ */
1257
+ const LEGACY_GLOBALS = Object.freeze({
1258
+ renderTemplate: "foundry.applications.handlebars.renderTemplate",
1259
+ loadTemplates: "foundry.applications.handlebars.loadTemplates",
1260
+ getTemplate: "foundry.applications.handlebars.getTemplate",
1261
+ ActorSheet: "foundry.appv1.sheets.ActorSheet",
1262
+ ItemSheet: "foundry.appv1.sheets.ItemSheet",
1263
+ JournalSheet: "foundry.appv1.sheets.JournalSheet",
1264
+ JournalPageSheet: "foundry.appv1.sheets.JournalPageSheet",
1265
+ JournalTextPageSheet: "foundry.appv1.sheets.JournalTextPageSheet",
1266
+ TextEditor: "foundry.applications.ux.TextEditor.implementation",
1267
+ ContextMenu: "foundry.applications.ux.ContextMenu.implementation",
1268
+ DragDrop: "foundry.applications.ux.DragDrop.implementation",
1269
+ Draggable: "foundry.applications.ux.Draggable.implementation",
1270
+ FormDataExtended: "foundry.applications.ux.FormDataExtended",
1271
+ SearchFilter: "foundry.applications.ux.SearchFilter",
1272
+ Tabs: "foundry.applications.ux.Tabs",
1273
+ ProseMirrorEditor: "foundry.applications.ux.ProseMirrorEditor",
1274
+ FilePicker: "foundry.applications.apps.FilePicker.implementation",
1275
+ ImagePopout: "foundry.applications.apps.ImagePopout",
1276
+ DocumentSheetConfig: "foundry.applications.apps.DocumentSheetConfig",
1277
+ ActiveEffectConfig: "foundry.applications.sheets.ActiveEffectConfig",
1278
+ TokenConfig: "foundry.applications.sheets.TokenConfig",
1279
+ SceneConfig: "foundry.applications.sheets.SceneConfig",
1280
+ MacroConfig: "foundry.applications.sheets.MacroConfig",
1281
+ SettingsConfig: "foundry.applications.settings.SettingsConfig",
1282
+ Sidebar: "foundry.applications.sidebar.Sidebar",
1283
+ ChatLog: "foundry.applications.sidebar.tabs.ChatLog",
1284
+ CombatTracker: "foundry.applications.sidebar.tabs.CombatTracker",
1285
+ ActorDirectory: "foundry.applications.sidebar.tabs.ActorDirectory",
1286
+ ItemDirectory: "foundry.applications.sidebar.tabs.ItemDirectory",
1287
+ JournalDirectory: "foundry.applications.sidebar.tabs.JournalDirectory",
1288
+ CompendiumDirectory: "foundry.applications.sidebar.tabs.CompendiumDirectory",
1289
+ Compendium: "foundry.applications.sidebar.apps.Compendium",
1290
+ ModuleManagement: "foundry.applications.sidebar.apps.ModuleManagement",
1291
+ Hotbar: "foundry.applications.ui.Hotbar",
1292
+ SceneControls: "foundry.applications.ui.SceneControls",
1293
+ SceneNavigation: "foundry.applications.ui.SceneNavigation",
1294
+ Players: "foundry.applications.ui.Players",
1295
+ Notifications: "foundry.applications.ui.Notifications",
1296
+ TokenHUD: "foundry.applications.hud.TokenHUD",
1297
+ Actors: "foundry.documents.collections.Actors",
1298
+ Items: "foundry.documents.collections.Items",
1299
+ Journal: "foundry.documents.collections.Journal",
1300
+ Macros: "foundry.documents.collections.Macros",
1301
+ Messages: "foundry.documents.collections.ChatMessages",
1302
+ Playlists: "foundry.documents.collections.Playlists",
1303
+ RollTables: "foundry.documents.collections.RollTables",
1304
+ Scenes: "foundry.documents.collections.Scenes",
1305
+ Users: "foundry.documents.collections.Users",
1306
+ Folders: "foundry.documents.collections.Folders",
1307
+ CompendiumCollection: "foundry.documents.collections.CompendiumCollection",
1308
+ CompendiumPacks: "foundry.documents.collections.CompendiumPacks",
1309
+ WorldCollection: "foundry.documents.abstract.WorldCollection",
1310
+ DocumentCollection: "foundry.documents.abstract.DocumentCollection",
1311
+ Canvas: "foundry.canvas.Canvas",
1312
+ CanvasLayer: "foundry.canvas.layers.CanvasLayer",
1313
+ InteractionLayer: "foundry.canvas.layers.InteractionLayer",
1314
+ PlaceablesLayer: "foundry.canvas.layers.PlaceablesLayer",
1315
+ PlaceableObject: "foundry.canvas.placeables.PlaceableObject",
1316
+ Token: "foundry.canvas.placeables.Token",
1317
+ Tile: "foundry.canvas.placeables.Tile",
1318
+ Drawing: "foundry.canvas.placeables.Drawing",
1319
+ Note: "foundry.canvas.placeables.Note",
1320
+ Wall: "foundry.canvas.placeables.Wall",
1321
+ Region: "foundry.canvas.placeables.Region",
1322
+ AmbientLight: "foundry.canvas.placeables.AmbientLight",
1323
+ AmbientSound: "foundry.canvas.placeables.AmbientSound",
1324
+ Ray: "foundry.canvas.geometry.Ray",
1325
+ ClockwiseSweepPolygon: "foundry.canvas.geometry.ClockwiseSweepPolygon",
1326
+ CanvasAnimation: "foundry.canvas.animation.CanvasAnimation",
1327
+ ChatBubbles: "foundry.canvas.animation.ChatBubbles",
1328
+ MouseInteractionManager: "foundry.canvas.interaction.MouseInteractionManager",
1329
+ Ruler: "foundry.canvas.interaction.Ruler",
1330
+ TextureLoader: "foundry.canvas.TextureLoader",
1331
+ getTexture: "foundry.canvas.getTexture",
1332
+ loadTexture: "foundry.canvas.loadTexture",
1333
+ srcExists: "foundry.canvas.srcExists",
1334
+ ClientSettings: "foundry.helpers.ClientSettings",
1335
+ ClientKeybindings: "foundry.helpers.interaction.ClientKeybindings",
1336
+ GameTime: "foundry.helpers.GameTime",
1337
+ Localization: "foundry.helpers.Localization",
1338
+ SocketInterface: "foundry.helpers.SocketInterface",
1339
+ TooltipManager: "foundry.helpers.interaction.TooltipManager.implementation",
1340
+ VideoHelper: "foundry.helpers.media.VideoHelper",
1341
+ ImageHelper: "foundry.helpers.media.ImageHelper",
1342
+ AsyncWorker: "foundry.helpers.AsyncWorker",
1343
+ SortingHelpers: "foundry.utils.SortingHelpers",
1344
+ saveDataToFile: "foundry.utils.saveDataToFile",
1345
+ readTextFromFile: "foundry.utils.readTextFromFile",
1346
+ Module: "foundry.packages.Module",
1347
+ System: "foundry.packages.System",
1348
+ World: "foundry.packages.World",
1349
+ Tour: "foundry.nue.Tour",
1350
+ Tours: "foundry.nue.ToursCollection"
1351
+ });
1352
+ /**
1353
+ * Does the file declare or import the name itself?
1354
+ *
1355
+ * A module that defines its own `Token` class or imports `Tabs` from a
1356
+ * library is using that, not Foundry's global.
1357
+ */
1358
+ function definesName(source, name) {
1359
+ return new RegExp(`(?:\\b(?:class|function|const|let|var)\\s+${name}\\b|import[^;]*\\b${name}\\b|\\b${name}\\s*\\([^)]*\\)\\s*\\{)`).test(source);
1360
+ }
1361
+ /**
1362
+ * A bare use of `name`: not a property (`x.Token`), not an object key
1363
+ * (`{ Token: 1 }`), not part of a longer identifier.
1364
+ */
1365
+ function bareUsePattern(name) {
1366
+ return new RegExp(`(?<![\\w$.])${name}\\b(?!\\s*:(?!:))(?=[\\s.(,;)\\]}]|$)`, "gm");
1367
+ }
1368
+ function maskComments(source, { strings = false } = {}) {
1369
+ const out = source.split("");
1370
+ let quote = null;
1371
+ let lastCode = "";
1372
+ for (let i = 0; i < source.length; i += 1) {
1373
+ const ch = source[i] ?? "";
1374
+ const next = source[i + 1] ?? "";
1375
+ if (quote !== null) {
1376
+ if (ch === "\\") {
1377
+ if (strings) {
1378
+ out[i] = "\0";
1379
+ if (source[i + 1] !== "\n") out[i + 1] = "\0";
1380
+ }
1381
+ i += 1;
1382
+ } else if (ch === quote) quote = null;
1383
+ else if (strings && ch !== "\n") out[i] = "\0";
1384
+ continue;
1385
+ }
1386
+ if (ch === "\"" || ch === "'" || ch === "`") {
1387
+ quote = ch;
1388
+ lastCode = ch;
1389
+ continue;
1390
+ }
1391
+ if (ch === "/" && next === "/") {
1392
+ const end = source.indexOf("\n", i);
1393
+ const stop = end === -1 ? source.length : end;
1394
+ for (let j = i; j < stop; j += 1) out[j] = "\0";
1395
+ i = stop - 1;
1396
+ continue;
1397
+ }
1398
+ if (ch === "/" && next === "*") {
1399
+ const close = source.indexOf("*/", i + 2);
1400
+ const stop = close === -1 ? source.length : close + 2;
1401
+ for (let j = i; j < stop; j += 1) if (source[j] !== "\n") out[j] = "\0";
1402
+ i = stop - 1;
1403
+ continue;
1404
+ }
1405
+ if (ch === "/" && startsRegex(lastCode)) {
1406
+ let inClass = false;
1407
+ let j = i + 1;
1408
+ for (; j < source.length; j += 1) {
1409
+ const c = source[j] ?? "";
1410
+ if (c === "\\") j += 1;
1411
+ else if (c === "\n") break;
1412
+ else if (inClass) inClass = c !== "]";
1413
+ else if (c === "[") inClass = true;
1414
+ else if (c === "/") break;
1415
+ }
1416
+ i = j;
1417
+ lastCode = "/";
1418
+ continue;
1419
+ }
1420
+ if (!/\s/.test(ch)) lastCode = ch;
1421
+ }
1422
+ return out.join("");
1423
+ }
1424
+ /** After one of these a `/` opens a regex literal, not a division. */
1425
+ function startsRegex(lastCode) {
1426
+ return lastCode === "" || "(,=:[!&|?{};+-*%<>~^".includes(lastCode);
1427
+ }
1428
+ //#endregion
1209
1429
  //#region src/audit/v14-rules.ts
1210
1430
  /**
1211
1431
  * Source rules for the v13 code that v14 broke or deprecated.
@@ -1216,11 +1436,16 @@ const SEVERITY_RANK = {
1216
1436
  * VTTF-AUDIT-014 (MEDIUM): `CONFIG.statusEffects = [...]`, which empties the collection first
1217
1437
  * VTTF-AUDIT-015 (MEDIUM): `legacyTransferral`, a flag v14 no longer reads
1218
1438
  * VTTF-AUDIT-016 (MEDIUM): numeric Active Effect modes, replaced by string change types
1439
+ * VTTF-AUDIT-017 (MEDIUM): the jQuery `renderChatMessage` hook, removed in v15
1440
+ * VTTF-AUDIT-018 (LOW) : an Application v1 base class, removed in v16
1441
+ * VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias (`renderTemplate`, `ActorSheet`, ...), removed in v15
1219
1442
  *
1220
1443
  * Regex heuristics like the rest of the source rules, for the same reason:
1221
1444
  * the patterns are short and a TypeScript AST would not make them more
1222
- * precise. Each rule reports the first match per file; one finding is enough
1223
- * to send the reader to the file, and the fix is a search-and-replace there.
1445
+ * precise. Comments are blanked first, so prose that mentions a call is not
1446
+ * a finding. Each rule reports the first match per file; one finding is
1447
+ * enough to send the reader to the file, and the fix is a search-and-replace
1448
+ * there.
1224
1449
  */
1225
1450
  /**
1226
1451
  * VTTF-AUDIT-011 (HIGH): a bare utility global v14 removed.
@@ -1396,6 +1621,79 @@ function rule016(filePath, content) {
1396
1621
  remediation: "Write `{ key, type: \"add\", value }` under `system.changes`; register extra types in `CONFIG.ActiveEffect.changeTypes`."
1397
1622
  }];
1398
1623
  }
1624
+ /**
1625
+ * VTTF-AUDIT-017 (MEDIUM): the `renderChatMessage` hook.
1626
+ *
1627
+ * Deprecated since v13 and removed in v15, one version earlier than the
1628
+ * rest of this list. Its replacement, `renderChatMessageHTML`, hands the
1629
+ * message element instead of a jQuery object, so the handler body changes
1630
+ * too: `html.find(...)` becomes `html.querySelector(...)`.
1631
+ */
1632
+ function rule017(filePath, content) {
1633
+ const pattern = /Hooks\.(?:on|once)\(\s*['"]renderChatMessage['"]/;
1634
+ if (!pattern.test(content)) return [];
1635
+ return [{
1636
+ ruleId: "VTTF-AUDIT-017",
1637
+ title: "renderChatMessage is removed in v15",
1638
+ severity: "MEDIUM",
1639
+ filePath,
1640
+ line: _internal.lineOf(content, pattern),
1641
+ message: "The `renderChatMessage` hook is deprecated since v13 and removed in v15. It hands a jQuery object; `renderChatMessageHTML` hands the element.",
1642
+ remediation: "Listen to `renderChatMessageHTML(message, html, context)` and rewrite the handler against the DOM: `html.find(x)` → `html.querySelector(x)`, `.on(\"click\", f)` → `.addEventListener(\"click\", f)`."
1643
+ }];
1644
+ }
1645
+ /**
1646
+ * VTTF-AUDIT-018 (LOW): an Application v1 base class.
1647
+ *
1648
+ * `Application`, `FormApplication`, `Dialog`, `ActorSheet`, `ItemSheet` and
1649
+ * the rest of `foundry.appv1` are deprecated since v13 and removed in v16.
1650
+ * Nothing breaks on v14, which is why this is LOW; it is the largest piece
1651
+ * of work on the list, which is why it is on the list.
1652
+ */
1653
+ function rule018(filePath, content) {
1654
+ const pattern = /extends\s+(?:foundry\.appv1\.(?:api|sheets)\.)?(?:Application|FormApplication|Dialog|DocumentSheet|ActorSheet|ItemSheet)\b(?!V2)/;
1655
+ if (!pattern.test(content)) return [];
1656
+ return [{
1657
+ ruleId: "VTTF-AUDIT-018",
1658
+ title: "An Application v1 base class",
1659
+ severity: "LOW",
1660
+ filePath,
1661
+ line: _internal.lineOf(content, pattern),
1662
+ message: "This class extends an Application v1 base, deprecated since v13 and removed in v16. It still works on v14.",
1663
+ remediation: "Move to `foundry.applications.api.ApplicationV2` with `HandlebarsApplicationMixin`, or `foundry.applications.sheets.ActorSheetV2` / `ItemSheetV2`; `DialogV2` for dialogs. `@vttforge/core` offers `BaseApplication`, `BaseActorSheet` and `BaseItemSheet` on top of those."
1664
+ }];
1665
+ }
1666
+ /**
1667
+ * VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias.
1668
+ *
1669
+ * v13 moved these under `foundry.*` and kept the bare name as an alias that
1670
+ * warns; v15 removes the alias. Unlike the v12 utilities of rule 011 nothing
1671
+ * throws on v14, but every one of them is a `ReferenceError` one version
1672
+ * out, and the fix is a rename to the same object.
1673
+ */
1674
+ function rule019(filePath, content) {
1675
+ const code = maskComments(content, { strings: true });
1676
+ let first;
1677
+ for (const name of Object.keys(LEGACY_GLOBALS)) {
1678
+ const match = bareUsePattern(name).exec(code);
1679
+ if (!match || definesName(code, name)) continue;
1680
+ if (first === void 0 || match.index < first.index) first = {
1681
+ name,
1682
+ index: match.index
1683
+ };
1684
+ }
1685
+ if (first === void 0) return [];
1686
+ const path = LEGACY_GLOBALS[first.name];
1687
+ return [{
1688
+ ruleId: "VTTF-AUDIT-019",
1689
+ title: "A v13 global alias, removed in v15",
1690
+ severity: "MEDIUM",
1691
+ filePath,
1692
+ line: _internal.lineOf(content, bareUsePattern(first.name)),
1693
+ message: `\`${first.name}\` is a bare alias of \`${path}\`, deprecated since v13 and removed in v15. It warns on every use today and throws ReferenceError on v15.`,
1694
+ remediation: `Use \`${path}\`. \`vttforge migrate\` renames every alias in this list.`
1695
+ }];
1696
+ }
1399
1697
  async function runV14Rules(cwd) {
1400
1698
  const results = [];
1401
1699
  for await (const file of _internal.walkSourceFiles(cwd)) {
@@ -1405,7 +1703,8 @@ async function runV14Rules(cwd) {
1405
1703
  } catch {
1406
1704
  continue;
1407
1705
  }
1408
- results.push(...rule011(file, content), ...rule012(file, content), ...rule013(file, content), ...rule014(file, content), ...rule015(file, content), ...rule016(file, content));
1706
+ content = maskComments(content);
1707
+ 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));
1409
1708
  }
1410
1709
  return results;
1411
1710
  }
@@ -3087,6 +3386,6 @@ function runInstall(pm, cwd) {
3087
3386
  */
3088
3387
  const VTTFORGE_CLI_VERSION = version;
3089
3388
  //#endregion
3090
- export { emitReleaseZip as a, readManifest as c, runAudit as d, REMOVED_UTILS as f, runManifestRules as g, runSourceRules as h, runDev as i, runAuditCommand as l, _internal as m, ScaffoldError as n, runBuild as o, SEVERITY_RANK as p, runInit as r, emitZip as s, VTTFORGE_CLI_VERSION as t, formatReport as u };
3389
+ export { SEVERITY_RANK as _, emitReleaseZip as a, runManifestRules as b, readManifest as c, runAudit as d, REMOVED_UTILS as f, definesName as g, bareUsePattern as h, runDev as i, runAuditCommand as l, LEGACY_GLOBALS as m, ScaffoldError as n, runBuild as o, maskComments as p, runInit as r, emitZip as s, VTTFORGE_CLI_VERSION as t, formatReport as u, _internal as v, runSourceRules as y };
3091
3390
 
3092
- //# sourceMappingURL=src-CZnBIzlF.mjs.map
3391
+ //# sourceMappingURL=src-CgS7GUiL.mjs.map