@vttforge/cli 0.10.1 → 0.12.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 +23 -0
- package/README.md +4 -1
- package/dist/bin.mjs +545 -62
- package/dist/bin.mjs.map +1 -1
- package/dist/index.d.mts +44 -1
- package/dist/index.mjs +2 -2
- package/dist/{src-Bof8_ypF.mjs → src-CzzrhCN-.mjs} +355 -8
- package/dist/src-CzzrhCN-.mjs.map +1 -0
- package/lint/vttforge-biome.json +85 -0
- package/package.json +4 -2
- package/templates/module-js/README.md +3 -1
- package/templates/module-js/package.json +4 -2
- package/templates/module-ts/README.md +3 -1
- package/templates/module-ts/package.json +3 -1
- package/templates/module-ts/scripts/enricher.ts +3 -1
- package/templates/module-ts/tsconfig.json +2 -7
- package/templates/system-js/README.md +3 -1
- package/templates/system-js/package.json +4 -2
- package/templates/system-js/scripts/data/character-data.mjs +28 -4
- package/templates/system-js/scripts/sheets/character-sheet.mjs +3 -1
- package/templates/system-js/scripts/sheets/gear-sheet.mjs +5 -4
- package/templates/system-ts/README.md +3 -1
- package/templates/system-ts/package.json +3 -1
- package/templates/system-ts/scripts/data/character-data.ts +28 -4
- package/templates/system-ts/scripts/sheets/character-sheet.ts +13 -3
- package/templates/system-ts/scripts/sheets/gear-sheet.ts +5 -4
- package/dist/src-Bof8_ypF.mjs.map +0 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import { createWriteStream, existsSync, readFileSync, readdirSync, statSync, watch } from "node:fs";
|
|
2
3
|
import { basename, dirname, extname, join, posix, relative, resolve, sep } from "node:path";
|
|
3
4
|
import { lstat, mkdir, readFile, readdir, readlink, rm, stat, symlink, unlink, writeFile } from "node:fs/promises";
|
|
@@ -10,7 +11,7 @@ import { createServer } from "node:http";
|
|
|
10
11
|
import { homedir } from "node:os";
|
|
11
12
|
import { promisify } from "node:util";
|
|
12
13
|
//#region package.json
|
|
13
|
-
var version = "0.
|
|
14
|
+
var version = "0.12.0";
|
|
14
15
|
//#endregion
|
|
15
16
|
//#region src/audit/manifest-rules.ts
|
|
16
17
|
/**
|
|
@@ -381,6 +382,7 @@ const SOURCE_EXTENSIONS = [
|
|
|
381
382
|
];
|
|
382
383
|
function isSourceFile(name) {
|
|
383
384
|
if (name.endsWith(".d.ts") || name.endsWith(".d.mts") || name.endsWith(".d.cts")) return false;
|
|
385
|
+
if (/\.min\.[cm]?js$/.test(name)) return false;
|
|
384
386
|
return SOURCE_EXTENSIONS.some((ext) => name.endsWith(ext));
|
|
385
387
|
}
|
|
386
388
|
async function* walkSourceFiles(cwd) {
|
|
@@ -813,7 +815,7 @@ async function rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, c
|
|
|
813
815
|
for (const key of ["primaryTokenAttribute", "secondaryTokenAttribute"]) {
|
|
814
816
|
const value = manifestParsed[key];
|
|
815
817
|
if (typeof value !== "string" || value.length === 0) continue;
|
|
816
|
-
if (!await sourceHasValueMaxSchemaAtPath(sourceFiles, value, actorClasses)) out.push({
|
|
818
|
+
if (!(await sourceHasValueMaxSchemaAtPath(sourceFiles, value, actorClasses) || templateJsonHasValueMax(manifestPath, value))) out.push({
|
|
817
819
|
ruleId: "VTTF-AUDIT-007",
|
|
818
820
|
title: `${key} does not resolve to a {value, max} SchemaField`,
|
|
819
821
|
severity: "MEDIUM",
|
|
@@ -825,6 +827,39 @@ async function rule007(manifestPath, manifestRaw, manifestParsed, sourceFiles, c
|
|
|
825
827
|
}
|
|
826
828
|
return out;
|
|
827
829
|
}
|
|
830
|
+
/**
|
|
831
|
+
* The same check against `template.json`, for a system that still declares
|
|
832
|
+
* its types there. Each Actor type is the merge of the templates it lists and
|
|
833
|
+
* its own keys; the path resolves when any type has an object with `value`
|
|
834
|
+
* and `max` at it. Foundry reads the bar the same way, per actor.
|
|
835
|
+
*/
|
|
836
|
+
function templateJsonHasValueMax(manifestPath, path) {
|
|
837
|
+
const file = join(dirname(manifestPath), "template.json");
|
|
838
|
+
if (!existsSync(file)) return false;
|
|
839
|
+
let template;
|
|
840
|
+
try {
|
|
841
|
+
template = JSON.parse(readFileSync(file, "utf8"));
|
|
842
|
+
} catch {
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
const actor = template.Actor;
|
|
846
|
+
if (!actor || typeof actor !== "object") return false;
|
|
847
|
+
const { types = [], templates = {} } = actor;
|
|
848
|
+
for (const type of types) {
|
|
849
|
+
const own = actor[type];
|
|
850
|
+
if (!own || typeof own !== "object") continue;
|
|
851
|
+
const merged = {};
|
|
852
|
+
for (const name of own.templates ?? []) Object.assign(merged, templates[name] ?? {});
|
|
853
|
+
Object.assign(merged, own);
|
|
854
|
+
let node = merged;
|
|
855
|
+
for (const segment of path.split(".")) {
|
|
856
|
+
if (!node || typeof node !== "object") break;
|
|
857
|
+
node = node[segment];
|
|
858
|
+
}
|
|
859
|
+
if (node && typeof node === "object" && "value" in node && "max" in node) return true;
|
|
860
|
+
}
|
|
861
|
+
return false;
|
|
862
|
+
}
|
|
828
863
|
function lineOfInRaw(raw, key) {
|
|
829
864
|
const idx = raw.indexOf(`"${key}"`);
|
|
830
865
|
if (idx < 0) return void 0;
|
|
@@ -1205,7 +1240,133 @@ const SEVERITY_RANK = {
|
|
|
1205
1240
|
MEDIUM: 1,
|
|
1206
1241
|
LOW: 2
|
|
1207
1242
|
};
|
|
1208
|
-
|
|
1243
|
+
//#endregion
|
|
1244
|
+
//#region src/audit/legacy-globals.ts
|
|
1245
|
+
/**
|
|
1246
|
+
* The bare globals v13 turned into aliases of a `foundry.*` path.
|
|
1247
|
+
*
|
|
1248
|
+
* Each still resolves on v14 with a deprecation warning, and none resolves
|
|
1249
|
+
* on v15. The namespaced path is the same object, so a rewrite from one to
|
|
1250
|
+
* the other changes nothing at runtime and removes a removal date. The list
|
|
1251
|
+
* is the part of the public API a system or module is likely to reach for
|
|
1252
|
+
* bare; the canvas shaders and the rest are left out on purpose.
|
|
1253
|
+
*
|
|
1254
|
+
* `Application`, `FormApplication`, `Dialog` and `DocumentSheet` are not
|
|
1255
|
+
* here: those are plain aliases with no warning, and the whole v1 framework
|
|
1256
|
+
* goes in v16, which `VTTF-AUDIT-018` reports.
|
|
1257
|
+
*/
|
|
1258
|
+
const LEGACY_GLOBALS = Object.freeze({
|
|
1259
|
+
renderTemplate: "foundry.applications.handlebars.renderTemplate",
|
|
1260
|
+
loadTemplates: "foundry.applications.handlebars.loadTemplates",
|
|
1261
|
+
getTemplate: "foundry.applications.handlebars.getTemplate",
|
|
1262
|
+
ActorSheet: "foundry.appv1.sheets.ActorSheet",
|
|
1263
|
+
ItemSheet: "foundry.appv1.sheets.ItemSheet",
|
|
1264
|
+
JournalSheet: "foundry.appv1.sheets.JournalSheet",
|
|
1265
|
+
JournalPageSheet: "foundry.appv1.sheets.JournalPageSheet",
|
|
1266
|
+
JournalTextPageSheet: "foundry.appv1.sheets.JournalTextPageSheet",
|
|
1267
|
+
TextEditor: "foundry.applications.ux.TextEditor.implementation",
|
|
1268
|
+
ContextMenu: "foundry.applications.ux.ContextMenu.implementation",
|
|
1269
|
+
DragDrop: "foundry.applications.ux.DragDrop.implementation",
|
|
1270
|
+
Draggable: "foundry.applications.ux.Draggable.implementation",
|
|
1271
|
+
FormDataExtended: "foundry.applications.ux.FormDataExtended",
|
|
1272
|
+
SearchFilter: "foundry.applications.ux.SearchFilter",
|
|
1273
|
+
Tabs: "foundry.applications.ux.Tabs",
|
|
1274
|
+
ProseMirrorEditor: "foundry.applications.ux.ProseMirrorEditor",
|
|
1275
|
+
FilePicker: "foundry.applications.apps.FilePicker.implementation",
|
|
1276
|
+
ImagePopout: "foundry.applications.apps.ImagePopout",
|
|
1277
|
+
DocumentSheetConfig: "foundry.applications.apps.DocumentSheetConfig",
|
|
1278
|
+
ActiveEffectConfig: "foundry.applications.sheets.ActiveEffectConfig",
|
|
1279
|
+
TokenConfig: "foundry.applications.sheets.TokenConfig",
|
|
1280
|
+
SceneConfig: "foundry.applications.sheets.SceneConfig",
|
|
1281
|
+
MacroConfig: "foundry.applications.sheets.MacroConfig",
|
|
1282
|
+
SettingsConfig: "foundry.applications.settings.SettingsConfig",
|
|
1283
|
+
Sidebar: "foundry.applications.sidebar.Sidebar",
|
|
1284
|
+
ChatLog: "foundry.applications.sidebar.tabs.ChatLog",
|
|
1285
|
+
CombatTracker: "foundry.applications.sidebar.tabs.CombatTracker",
|
|
1286
|
+
ActorDirectory: "foundry.applications.sidebar.tabs.ActorDirectory",
|
|
1287
|
+
ItemDirectory: "foundry.applications.sidebar.tabs.ItemDirectory",
|
|
1288
|
+
JournalDirectory: "foundry.applications.sidebar.tabs.JournalDirectory",
|
|
1289
|
+
CompendiumDirectory: "foundry.applications.sidebar.tabs.CompendiumDirectory",
|
|
1290
|
+
Compendium: "foundry.applications.sidebar.apps.Compendium",
|
|
1291
|
+
ModuleManagement: "foundry.applications.sidebar.apps.ModuleManagement",
|
|
1292
|
+
Hotbar: "foundry.applications.ui.Hotbar",
|
|
1293
|
+
SceneControls: "foundry.applications.ui.SceneControls",
|
|
1294
|
+
SceneNavigation: "foundry.applications.ui.SceneNavigation",
|
|
1295
|
+
Players: "foundry.applications.ui.Players",
|
|
1296
|
+
Notifications: "foundry.applications.ui.Notifications",
|
|
1297
|
+
TokenHUD: "foundry.applications.hud.TokenHUD",
|
|
1298
|
+
Actors: "foundry.documents.collections.Actors",
|
|
1299
|
+
Items: "foundry.documents.collections.Items",
|
|
1300
|
+
Journal: "foundry.documents.collections.Journal",
|
|
1301
|
+
Macros: "foundry.documents.collections.Macros",
|
|
1302
|
+
Messages: "foundry.documents.collections.ChatMessages",
|
|
1303
|
+
Playlists: "foundry.documents.collections.Playlists",
|
|
1304
|
+
RollTables: "foundry.documents.collections.RollTables",
|
|
1305
|
+
Scenes: "foundry.documents.collections.Scenes",
|
|
1306
|
+
Users: "foundry.documents.collections.Users",
|
|
1307
|
+
Folders: "foundry.documents.collections.Folders",
|
|
1308
|
+
CompendiumCollection: "foundry.documents.collections.CompendiumCollection",
|
|
1309
|
+
CompendiumPacks: "foundry.documents.collections.CompendiumPacks",
|
|
1310
|
+
WorldCollection: "foundry.documents.abstract.WorldCollection",
|
|
1311
|
+
DocumentCollection: "foundry.documents.abstract.DocumentCollection",
|
|
1312
|
+
Canvas: "foundry.canvas.Canvas",
|
|
1313
|
+
CanvasLayer: "foundry.canvas.layers.CanvasLayer",
|
|
1314
|
+
InteractionLayer: "foundry.canvas.layers.InteractionLayer",
|
|
1315
|
+
PlaceablesLayer: "foundry.canvas.layers.PlaceablesLayer",
|
|
1316
|
+
PlaceableObject: "foundry.canvas.placeables.PlaceableObject",
|
|
1317
|
+
Token: "foundry.canvas.placeables.Token",
|
|
1318
|
+
Tile: "foundry.canvas.placeables.Tile",
|
|
1319
|
+
Drawing: "foundry.canvas.placeables.Drawing",
|
|
1320
|
+
Note: "foundry.canvas.placeables.Note",
|
|
1321
|
+
Wall: "foundry.canvas.placeables.Wall",
|
|
1322
|
+
Region: "foundry.canvas.placeables.Region",
|
|
1323
|
+
AmbientLight: "foundry.canvas.placeables.AmbientLight",
|
|
1324
|
+
AmbientSound: "foundry.canvas.placeables.AmbientSound",
|
|
1325
|
+
Ray: "foundry.canvas.geometry.Ray",
|
|
1326
|
+
ClockwiseSweepPolygon: "foundry.canvas.geometry.ClockwiseSweepPolygon",
|
|
1327
|
+
CanvasAnimation: "foundry.canvas.animation.CanvasAnimation",
|
|
1328
|
+
ChatBubbles: "foundry.canvas.animation.ChatBubbles",
|
|
1329
|
+
MouseInteractionManager: "foundry.canvas.interaction.MouseInteractionManager",
|
|
1330
|
+
Ruler: "foundry.canvas.interaction.Ruler",
|
|
1331
|
+
TextureLoader: "foundry.canvas.TextureLoader",
|
|
1332
|
+
getTexture: "foundry.canvas.getTexture",
|
|
1333
|
+
loadTexture: "foundry.canvas.loadTexture",
|
|
1334
|
+
srcExists: "foundry.canvas.srcExists",
|
|
1335
|
+
ClientSettings: "foundry.helpers.ClientSettings",
|
|
1336
|
+
ClientKeybindings: "foundry.helpers.interaction.ClientKeybindings",
|
|
1337
|
+
GameTime: "foundry.helpers.GameTime",
|
|
1338
|
+
Localization: "foundry.helpers.Localization",
|
|
1339
|
+
SocketInterface: "foundry.helpers.SocketInterface",
|
|
1340
|
+
TooltipManager: "foundry.helpers.interaction.TooltipManager.implementation",
|
|
1341
|
+
VideoHelper: "foundry.helpers.media.VideoHelper",
|
|
1342
|
+
ImageHelper: "foundry.helpers.media.ImageHelper",
|
|
1343
|
+
AsyncWorker: "foundry.helpers.AsyncWorker",
|
|
1344
|
+
SortingHelpers: "foundry.utils.SortingHelpers",
|
|
1345
|
+
saveDataToFile: "foundry.utils.saveDataToFile",
|
|
1346
|
+
readTextFromFile: "foundry.utils.readTextFromFile",
|
|
1347
|
+
Module: "foundry.packages.Module",
|
|
1348
|
+
System: "foundry.packages.System",
|
|
1349
|
+
World: "foundry.packages.World",
|
|
1350
|
+
Tour: "foundry.nue.Tour",
|
|
1351
|
+
Tours: "foundry.nue.ToursCollection"
|
|
1352
|
+
});
|
|
1353
|
+
/**
|
|
1354
|
+
* Does the file declare or import the name itself?
|
|
1355
|
+
*
|
|
1356
|
+
* A module that defines its own `Token` class or imports `Tabs` from a
|
|
1357
|
+
* library is using that, not Foundry's global.
|
|
1358
|
+
*/
|
|
1359
|
+
function definesName(source, name) {
|
|
1360
|
+
return new RegExp(`(?:\\b(?:class|function|const|let|var)\\s+${name}\\b|import[^;]*\\b${name}\\b|\\b${name}\\s*\\([^)]*\\)\\s*\\{)`).test(source);
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* A bare use of `name`: not a property (`x.Token`), not an object key
|
|
1364
|
+
* (`{ Token: 1 }`), not part of a longer identifier.
|
|
1365
|
+
*/
|
|
1366
|
+
function bareUsePattern(name) {
|
|
1367
|
+
return new RegExp(`(?<![\\w$.])${name}\\b(?!\\s*:(?!:))(?=[\\s.(,;)\\]}]|$)`, "gm");
|
|
1368
|
+
}
|
|
1369
|
+
function maskComments(source, { strings = false } = {}) {
|
|
1209
1370
|
const out = source.split("");
|
|
1210
1371
|
let quote = null;
|
|
1211
1372
|
let lastCode = "";
|
|
@@ -1213,8 +1374,14 @@ function maskComments(source) {
|
|
|
1213
1374
|
const ch = source[i] ?? "";
|
|
1214
1375
|
const next = source[i + 1] ?? "";
|
|
1215
1376
|
if (quote !== null) {
|
|
1216
|
-
if (ch === "\\")
|
|
1217
|
-
|
|
1377
|
+
if (ch === "\\") {
|
|
1378
|
+
if (strings) {
|
|
1379
|
+
out[i] = "\0";
|
|
1380
|
+
if (source[i + 1] !== "\n") out[i + 1] = "\0";
|
|
1381
|
+
}
|
|
1382
|
+
i += 1;
|
|
1383
|
+
} else if (ch === quote) quote = null;
|
|
1384
|
+
else if (strings && ch !== "\n") out[i] = "\0";
|
|
1218
1385
|
continue;
|
|
1219
1386
|
}
|
|
1220
1387
|
if (ch === "\"" || ch === "'" || ch === "`") {
|
|
@@ -1270,6 +1437,9 @@ function startsRegex(lastCode) {
|
|
|
1270
1437
|
* VTTF-AUDIT-014 (MEDIUM): `CONFIG.statusEffects = [...]`, which empties the collection first
|
|
1271
1438
|
* VTTF-AUDIT-015 (MEDIUM): `legacyTransferral`, a flag v14 no longer reads
|
|
1272
1439
|
* VTTF-AUDIT-016 (MEDIUM): numeric Active Effect modes, replaced by string change types
|
|
1440
|
+
* VTTF-AUDIT-017 (MEDIUM): the jQuery `renderChatMessage` hook, removed in v15
|
|
1441
|
+
* VTTF-AUDIT-018 (LOW) : an Application v1 base class, removed in v16
|
|
1442
|
+
* VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias (`renderTemplate`, `ActorSheet`, ...), removed in v15
|
|
1273
1443
|
*
|
|
1274
1444
|
* Regex heuristics like the rest of the source rules, for the same reason:
|
|
1275
1445
|
* the patterns are short and a TypeScript AST would not make them more
|
|
@@ -1452,6 +1622,79 @@ function rule016(filePath, content) {
|
|
|
1452
1622
|
remediation: "Write `{ key, type: \"add\", value }` under `system.changes`; register extra types in `CONFIG.ActiveEffect.changeTypes`."
|
|
1453
1623
|
}];
|
|
1454
1624
|
}
|
|
1625
|
+
/**
|
|
1626
|
+
* VTTF-AUDIT-017 (MEDIUM): the `renderChatMessage` hook.
|
|
1627
|
+
*
|
|
1628
|
+
* Deprecated since v13 and removed in v15, one version earlier than the
|
|
1629
|
+
* rest of this list. Its replacement, `renderChatMessageHTML`, hands the
|
|
1630
|
+
* message element instead of a jQuery object, so the handler body changes
|
|
1631
|
+
* too: `html.find(...)` becomes `html.querySelector(...)`.
|
|
1632
|
+
*/
|
|
1633
|
+
function rule017(filePath, content) {
|
|
1634
|
+
const pattern = /Hooks\.(?:on|once)\(\s*['"]renderChatMessage['"]/;
|
|
1635
|
+
if (!pattern.test(content)) return [];
|
|
1636
|
+
return [{
|
|
1637
|
+
ruleId: "VTTF-AUDIT-017",
|
|
1638
|
+
title: "renderChatMessage is removed in v15",
|
|
1639
|
+
severity: "MEDIUM",
|
|
1640
|
+
filePath,
|
|
1641
|
+
line: _internal.lineOf(content, pattern),
|
|
1642
|
+
message: "The `renderChatMessage` hook is deprecated since v13 and removed in v15. It hands a jQuery object; `renderChatMessageHTML` hands the element.",
|
|
1643
|
+
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)`."
|
|
1644
|
+
}];
|
|
1645
|
+
}
|
|
1646
|
+
/**
|
|
1647
|
+
* VTTF-AUDIT-018 (LOW): an Application v1 base class.
|
|
1648
|
+
*
|
|
1649
|
+
* `Application`, `FormApplication`, `Dialog`, `ActorSheet`, `ItemSheet` and
|
|
1650
|
+
* the rest of `foundry.appv1` are deprecated since v13 and removed in v16.
|
|
1651
|
+
* Nothing breaks on v14, which is why this is LOW; it is the largest piece
|
|
1652
|
+
* of work on the list, which is why it is on the list.
|
|
1653
|
+
*/
|
|
1654
|
+
function rule018(filePath, content) {
|
|
1655
|
+
const pattern = /extends\s+(?:foundry\.appv1\.(?:api|sheets)\.)?(?:Application|FormApplication|Dialog|DocumentSheet|ActorSheet|ItemSheet)\b(?!V2)/;
|
|
1656
|
+
if (!pattern.test(content)) return [];
|
|
1657
|
+
return [{
|
|
1658
|
+
ruleId: "VTTF-AUDIT-018",
|
|
1659
|
+
title: "An Application v1 base class",
|
|
1660
|
+
severity: "LOW",
|
|
1661
|
+
filePath,
|
|
1662
|
+
line: _internal.lineOf(content, pattern),
|
|
1663
|
+
message: "This class extends an Application v1 base, deprecated since v13 and removed in v16. It still works on v14.",
|
|
1664
|
+
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."
|
|
1665
|
+
}];
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* VTTF-AUDIT-019 (MEDIUM): a bare v13 global alias.
|
|
1669
|
+
*
|
|
1670
|
+
* v13 moved these under `foundry.*` and kept the bare name as an alias that
|
|
1671
|
+
* warns; v15 removes the alias. Unlike the v12 utilities of rule 011 nothing
|
|
1672
|
+
* throws on v14, but every one of them is a `ReferenceError` one version
|
|
1673
|
+
* out, and the fix is a rename to the same object.
|
|
1674
|
+
*/
|
|
1675
|
+
function rule019(filePath, content) {
|
|
1676
|
+
const code = maskComments(content, { strings: true });
|
|
1677
|
+
let first;
|
|
1678
|
+
for (const name of Object.keys(LEGACY_GLOBALS)) {
|
|
1679
|
+
const match = bareUsePattern(name).exec(code);
|
|
1680
|
+
if (!match || definesName(code, name)) continue;
|
|
1681
|
+
if (first === void 0 || match.index < first.index) first = {
|
|
1682
|
+
name,
|
|
1683
|
+
index: match.index
|
|
1684
|
+
};
|
|
1685
|
+
}
|
|
1686
|
+
if (first === void 0) return [];
|
|
1687
|
+
const path = LEGACY_GLOBALS[first.name];
|
|
1688
|
+
return [{
|
|
1689
|
+
ruleId: "VTTF-AUDIT-019",
|
|
1690
|
+
title: "A v13 global alias, removed in v15",
|
|
1691
|
+
severity: "MEDIUM",
|
|
1692
|
+
filePath,
|
|
1693
|
+
line: _internal.lineOf(content, bareUsePattern(first.name)),
|
|
1694
|
+
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.`,
|
|
1695
|
+
remediation: `Use \`${path}\`. \`vttforge migrate\` renames every alias in this list.`
|
|
1696
|
+
}];
|
|
1697
|
+
}
|
|
1455
1698
|
async function runV14Rules(cwd) {
|
|
1456
1699
|
const results = [];
|
|
1457
1700
|
for await (const file of _internal.walkSourceFiles(cwd)) {
|
|
@@ -1462,7 +1705,7 @@ async function runV14Rules(cwd) {
|
|
|
1462
1705
|
continue;
|
|
1463
1706
|
}
|
|
1464
1707
|
content = maskComments(content);
|
|
1465
|
-
results.push(...rule011(file, content), ...rule012(file, content), ...rule013(file, content), ...rule014(file, content), ...rule015(file, content), ...rule016(file, content));
|
|
1708
|
+
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));
|
|
1466
1709
|
}
|
|
1467
1710
|
return results;
|
|
1468
1711
|
}
|
|
@@ -3120,6 +3363,110 @@ function runInstall(pm, cwd) {
|
|
|
3120
3363
|
});
|
|
3121
3364
|
}
|
|
3122
3365
|
//#endregion
|
|
3366
|
+
//#region src/commands/lint.ts
|
|
3367
|
+
/**
|
|
3368
|
+
* `vttforge lint`: Biome over the project, then the v14 audit.
|
|
3369
|
+
*
|
|
3370
|
+
* Biome ships as a dependency of this package, so a scaffolded project has
|
|
3371
|
+
* a linter and a formatter without installing or configuring one. The
|
|
3372
|
+
* config it runs with is `<cli-pkg>/lint/vttforge-biome.json` unless the project
|
|
3373
|
+
* has its own `biome.json` / `biome.jsonc` at its root, in which case that
|
|
3374
|
+
* one wins and the shipped config is not read at all. A project that wants
|
|
3375
|
+
* to tweak a rule copies the shipped file and edits it.
|
|
3376
|
+
*
|
|
3377
|
+
* `--fix` writes the safe fixes and formats the files; without it the run
|
|
3378
|
+
* only reports. The audit runs after Biome either way (`--no-audit` skips
|
|
3379
|
+
* it), and the exit code is non-zero when either half fails.
|
|
3380
|
+
*/
|
|
3381
|
+
var BiomeNotFoundError = class extends Error {
|
|
3382
|
+
constructor(message) {
|
|
3383
|
+
super(message);
|
|
3384
|
+
this.name = "BiomeNotFoundError";
|
|
3385
|
+
}
|
|
3386
|
+
};
|
|
3387
|
+
/**
|
|
3388
|
+
* The Biome config shipped with the CLI, resolved from the built module.
|
|
3389
|
+
*
|
|
3390
|
+
* The file is not named `biome.json` on purpose: Biome treats a file with
|
|
3391
|
+
* that name as a nested root config and refuses to run, which would break
|
|
3392
|
+
* a project (or this monorepo) that holds the CLI inside another
|
|
3393
|
+
* Biome-rooted tree. `--config-path` accepts any file path.
|
|
3394
|
+
*/
|
|
3395
|
+
const SHIPPED_CONFIG_NAME = "vttforge-biome.json";
|
|
3396
|
+
function shippedConfig() {
|
|
3397
|
+
const here = fileURLToPath(import.meta.url);
|
|
3398
|
+
const fromDist = resolve(here, "..", "..", "lint", SHIPPED_CONFIG_NAME);
|
|
3399
|
+
if (existsSync(fromDist)) return fromDist;
|
|
3400
|
+
return resolve(here, "..", "..", "..", "lint", SHIPPED_CONFIG_NAME);
|
|
3401
|
+
}
|
|
3402
|
+
/** The project's own config wins when it has one. */
|
|
3403
|
+
function projectConfig(cwd) {
|
|
3404
|
+
for (const name of ["biome.json", "biome.jsonc"]) {
|
|
3405
|
+
const file = join(cwd, name);
|
|
3406
|
+
if (existsSync(file)) return file;
|
|
3407
|
+
}
|
|
3408
|
+
return null;
|
|
3409
|
+
}
|
|
3410
|
+
/** The Biome bin shim, resolved from this package's own dependency graph. */
|
|
3411
|
+
function biomeBin() {
|
|
3412
|
+
const require = createRequire(import.meta.url);
|
|
3413
|
+
try {
|
|
3414
|
+
return require.resolve("@biomejs/biome/bin/biome");
|
|
3415
|
+
} catch {
|
|
3416
|
+
throw new BiomeNotFoundError("Could not resolve @biomejs/biome from @vttforge/cli. Reinstall the CLI (it ships Biome as a dependency).");
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
/** The argv for Biome: `ci .` to report, `check --write .` to fix. */
|
|
3420
|
+
function biomeArgs(opts) {
|
|
3421
|
+
const args = opts.fix ? [
|
|
3422
|
+
"check",
|
|
3423
|
+
"--write",
|
|
3424
|
+
"."
|
|
3425
|
+
] : ["ci", "."];
|
|
3426
|
+
if (opts.configPath) args.push(`--config-path=${opts.configPath}`);
|
|
3427
|
+
return args;
|
|
3428
|
+
}
|
|
3429
|
+
function runBiome(cwd, args) {
|
|
3430
|
+
const bin = biomeBin();
|
|
3431
|
+
return new Promise((resolveRun, rejectRun) => {
|
|
3432
|
+
const child = spawn(process.execPath, [bin, ...args], {
|
|
3433
|
+
cwd,
|
|
3434
|
+
stdio: "inherit",
|
|
3435
|
+
env: process.env,
|
|
3436
|
+
shell: false
|
|
3437
|
+
});
|
|
3438
|
+
child.on("error", rejectRun);
|
|
3439
|
+
child.on("exit", (code) => resolveRun(code ?? 1));
|
|
3440
|
+
});
|
|
3441
|
+
}
|
|
3442
|
+
/**
|
|
3443
|
+
* @experimental Shape is unproven: no consumer has asked for this yet. It can
|
|
3444
|
+
* change in a minor.
|
|
3445
|
+
*/
|
|
3446
|
+
async function runLintCommand(options = {}) {
|
|
3447
|
+
const cwd = resolve(options.cwd ?? process.cwd());
|
|
3448
|
+
const fix = options.fix === true;
|
|
3449
|
+
const audit = options.audit !== false;
|
|
3450
|
+
if (!existsSync(join(cwd, "package.json"))) throw new Error(`No package.json found at ${cwd}. Run \`vttforge lint\` from inside a scaffolded project.`);
|
|
3451
|
+
const configPath = projectConfig(cwd) === null ? shippedConfig() : null;
|
|
3452
|
+
const biomeExitCode = await runBiome(cwd, biomeArgs({
|
|
3453
|
+
fix,
|
|
3454
|
+
configPath
|
|
3455
|
+
}));
|
|
3456
|
+
let auditExitCode = null;
|
|
3457
|
+
if (audit) auditExitCode = (await runAuditCommand({
|
|
3458
|
+
cwd,
|
|
3459
|
+
strict: options.strict === true,
|
|
3460
|
+
write: options.write
|
|
3461
|
+
})).exitCode;
|
|
3462
|
+
return {
|
|
3463
|
+
biomeExitCode,
|
|
3464
|
+
auditExitCode,
|
|
3465
|
+
exitCode: biomeExitCode !== 0 ? biomeExitCode : auditExitCode ?? 0,
|
|
3466
|
+
configPath
|
|
3467
|
+
};
|
|
3468
|
+
}
|
|
3469
|
+
//#endregion
|
|
3123
3470
|
//#region src/index.ts
|
|
3124
3471
|
/**
|
|
3125
3472
|
* @vttforge/cli: public library exports.
|
|
@@ -3144,6 +3491,6 @@ function runInstall(pm, cwd) {
|
|
|
3144
3491
|
*/
|
|
3145
3492
|
const VTTFORGE_CLI_VERSION = version;
|
|
3146
3493
|
//#endregion
|
|
3147
|
-
export {
|
|
3494
|
+
export { 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, runManifestRules as x, _internal as y };
|
|
3148
3495
|
|
|
3149
|
-
//# sourceMappingURL=src-
|
|
3496
|
+
//# sourceMappingURL=src-CzzrhCN-.mjs.map
|