@vttforge/cli 0.12.0 → 0.15.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.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { 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, x as runManifestRules } from "./src-CzzrhCN-.mjs";
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-BK9BmFiZ.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.12.0";
14
+ var version = "0.15.0";
15
15
  //#endregion
16
16
  //#region src/audit/manifest-rules.ts
17
17
  /**
@@ -340,6 +340,129 @@ async function runManifestRules(cwd) {
340
340
  return results;
341
341
  }
342
342
  //#endregion
343
+ //#region src/audit/release-rules.ts
344
+ /**
345
+ * VTTF-AUDIT-020 (HIGH): the release workflow ships the checkout, but the
346
+ * project builds to `dist/`.
347
+ *
348
+ * A project on the vite plugin runs from `dist/`: the entry is bundled, the
349
+ * manifest is copied and rewritten there. A release workflow written for the
350
+ * old layout zips `system.json` and a list of source folders straight from
351
+ * the checkout, and the published package has no entry file at all. Nothing
352
+ * fails until a player installs it. This rule reads `.github/workflows` for
353
+ * a workflow that publishes a zip and checks that it builds first and zips
354
+ * `dist/`.
355
+ */
356
+ const RULE_ID = "VTTF-AUDIT-020";
357
+ const TITLE = "Release workflow ships the checkout, not dist/";
358
+ const VITE_CONFIGS = [
359
+ "vite.config.js",
360
+ "vite.config.mjs",
361
+ "vite.config.ts",
362
+ "vite.config.mts",
363
+ "vite.config.cjs"
364
+ ];
365
+ /** A line that runs the build. */
366
+ const BUILD_STEP = /\b(?:vttforge\s+build|vite\s+build|(?:pnpm|npm|yarn|bun)\s+(?:run\s+)?build)\b/;
367
+ /** A line that makes or names the artifact. */
368
+ const ZIP_COMMAND = /\bzip\s+(?:-\S+\s+)*\S+\.zip\b|\bzip\s+-r\b/;
369
+ const ARTIFACT_LIST = /^\s*(?:artifacts|files|asset_path|path)\s*:/;
370
+ const MANIFEST = /\b(?:system|module)\.json\b/;
371
+ const RELEASE_ACTION = /(?:release-action|action-gh-release|upload-release-asset)/;
372
+ /** Whether this project builds through the vite plugin (or a `build` script that runs vite). */
373
+ async function buildsToDist(cwd) {
374
+ for (const name of VITE_CONFIGS) {
375
+ const path = join(cwd, name);
376
+ if (!existsSync(path)) continue;
377
+ const text = await readFile(path, "utf8");
378
+ if (/@vttforge\/vite-plugin|vttforge\s*\(/.test(text)) return true;
379
+ }
380
+ const pkg = join(cwd, "package.json");
381
+ if (!existsSync(pkg)) return false;
382
+ try {
383
+ const build = JSON.parse(await readFile(pkg, "utf8")).scripts?.build ?? "";
384
+ return /vttforge\s+build|vite\s+build/.test(build);
385
+ } catch {
386
+ return false;
387
+ }
388
+ }
389
+ async function workflowFiles(cwd) {
390
+ const dir = join(cwd, ".github", "workflows");
391
+ if (!existsSync(dir)) return [];
392
+ return (await readdir(dir, { withFileTypes: true })).filter((e) => e.isFile() && /\.ya?ml$/.test(e.name)).map((e) => join(dir, e.name)).sort();
393
+ }
394
+ /** The first step that ships a package, or null when the workflow ships nothing. */
395
+ function shippingStep(text) {
396
+ const lines = text.split("\n");
397
+ let builtBefore = false;
398
+ let inArtifactList = false;
399
+ for (let i = 0; i < lines.length; i += 1) {
400
+ const line = lines[i] ?? "";
401
+ if (BUILD_STEP.test(line)) builtBefore = true;
402
+ if (ZIP_COMMAND.test(line)) {
403
+ const fromDist = /\bdist\b/.test(line) || /\bcd\s+dist\b/.test(lines.slice(Math.max(0, i - 3), i).join("\n"));
404
+ return {
405
+ line: i + 1,
406
+ fromDist,
407
+ builtBefore
408
+ };
409
+ }
410
+ if (ARTIFACT_LIST.test(line)) {
411
+ inArtifactList = true;
412
+ const inline = line.slice(line.indexOf(":") + 1);
413
+ if (MANIFEST.test(inline) || /\.zip\b/.test(inline)) return {
414
+ line: i + 1,
415
+ fromDist: /\bdist\//.test(inline),
416
+ builtBefore
417
+ };
418
+ continue;
419
+ }
420
+ if (inArtifactList) {
421
+ if (/^\s*-?\s*\S/.test(line) && !/^\s*-\s/.test(line) && !/^\s{4,}\S/.test(line)) inArtifactList = false;
422
+ else if (MANIFEST.test(line) || /\.zip\b/.test(line)) return {
423
+ line: i + 1,
424
+ fromDist: /\bdist\//.test(line),
425
+ builtBefore
426
+ };
427
+ }
428
+ }
429
+ return null;
430
+ }
431
+ /**
432
+ * VTTF-AUDIT-020: a release workflow that publishes a zip must build first
433
+ * and ship `dist/`.
434
+ */
435
+ async function runReleaseRules(cwd) {
436
+ if (!await buildsToDist(cwd)) return [];
437
+ const findings = [];
438
+ for (const file of await workflowFiles(cwd)) {
439
+ const text = await readFile(file, "utf8");
440
+ if (!(RELEASE_ACTION.test(text) || /\brelease\s*:/.test(text) || /\btags\s*:/.test(text))) continue;
441
+ const ship = shippingStep(text);
442
+ if (!ship) continue;
443
+ const relPath = relative(cwd, file);
444
+ if (!ship.builtBefore) findings.push({
445
+ ruleId: RULE_ID,
446
+ title: TITLE,
447
+ severity: "HIGH",
448
+ filePath: relPath,
449
+ line: ship.line,
450
+ message: "The release workflow zips the checkout without building it. This project bundles to dist/, so the published package has no entry file and no world can start on it.",
451
+ remediation: "Install and build before the artifact step (`pnpm install --frozen-lockfile` then `pnpm build`), rewrite the manifest URLs in dist/system.json, and zip from inside dist/ so system.json and main.mjs sit at the zip root."
452
+ });
453
+ else if (!ship.fromDist) findings.push({
454
+ ruleId: RULE_ID,
455
+ title: TITLE,
456
+ severity: "HIGH",
457
+ filePath: relPath,
458
+ line: ship.line,
459
+ message: "The release workflow builds, then zips the source tree instead of dist/. The published package carries the unbundled entry and misses what the build wrote.",
460
+ remediation: "Point the artifact step at dist/: rewrite the manifest URLs in dist/system.json and zip from inside dist/ (`cd dist && zip -r ../system.zip .`)."
461
+ });
462
+ }
463
+ return findings;
464
+ }
465
+ //#endregion
343
466
  //#region src/audit/source-rules.ts
344
467
  /**
345
468
  * Source-tree audit rules.
@@ -385,6 +508,14 @@ function isSourceFile(name) {
385
508
  if (/\.min\.[cm]?js$/.test(name)) return false;
386
509
  return SOURCE_EXTENSIONS.some((ext) => name.endsWith(ext));
387
510
  }
511
+ /** Every `.hbs` / `.html` in the project, outside the build and dependency folders. */
512
+ async function* walkTemplateFiles(cwd) {
513
+ const entries = await readdir(cwd, { withFileTypes: true });
514
+ for (const entry of entries) if (entry.isDirectory()) {
515
+ if (EXCLUDED_DIRS.has(entry.name)) continue;
516
+ yield* walkTemplateFiles(join(cwd, entry.name));
517
+ } else if (entry.isFile() && /\.(?:hbs|html)$/.test(entry.name)) yield join(cwd, entry.name);
518
+ }
388
519
  async function* walkSourceFiles(cwd) {
389
520
  const entries = await readdir(cwd, { withFileTypes: true });
390
521
  for (const entry of entries) {
@@ -895,7 +1026,7 @@ async function sourceHasValueMaxSchemaAtPath(sourceFiles, targetPath, actorClass
895
1026
  if (decl.path !== targetPath) continue;
896
1027
  if (actorClasses.size > 0) {
897
1028
  const owner = classes.find((c) => decl.index > c.openIdx && decl.index < c.endIdx);
898
- if (!owner || !actorClasses.has(owner.className)) continue;
1029
+ if (owner && !actorClasses.has(owner.className)) continue;
899
1030
  }
900
1031
  const topKeys = extractTopLevelKeys(decl.body);
901
1032
  if (topKeys.has("value") && topKeys.has("max")) return true;
@@ -1132,6 +1263,7 @@ async function runSourceRules(cwd) {
1132
1263
  }
1133
1264
  const _internal = {
1134
1265
  walkSourceFiles,
1266
+ walkTemplateFiles,
1135
1267
  isSourceFile,
1136
1268
  lineOf,
1137
1269
  lastSegment,
@@ -1162,6 +1294,10 @@ const TEMPLATE_RE = /template:\s*[`'"]([^`'"]*\.hbs)[`'"]/g;
1162
1294
  /** A `<form>` start tag, ignoring what a Handlebars comment says about one. */
1163
1295
  const FORM_TAG_RE = /<form[\s>]/i;
1164
1296
  const HANDLEBARS_COMMENT_RE = /\{\{!--[\s\S]*?--\}\}|\{\{![^}]*\}\}/g;
1297
+ /** Blank out Handlebars comments, keeping their newlines so line numbers still point at the source. */
1298
+ function withoutComments(source) {
1299
+ return source.replace(HANDLEBARS_COMMENT_RE, (m) => m.replace(/[^\n]/g, ""));
1300
+ }
1165
1301
  /**
1166
1302
  * The templates a form-tagged sheet declares, as paths inside the project.
1167
1303
  *
@@ -1197,7 +1333,53 @@ function templatesOfFormSheets(source) {
1197
1333
  * HIGH because of how it fails. There is no error and no warning. The sheet
1198
1334
  * looks right, accepts what you type, and drops it when the window closes.
1199
1335
  */
1336
+ /**
1337
+ * VTTF-AUDIT-021 (HIGH) — a Handlebars helper v14 removed.
1338
+ *
1339
+ * `{{#select}}` and `{{colorPicker}}` are gone. A template that still calls
1340
+ * one fails to render with "Missing helper", and the sheet, dialog or settings
1341
+ * form it belongs to never opens. Every `.hbs` / `.html` in the project is
1342
+ * read, since the failing template can belong to anything.
1343
+ */
1344
+ const REMOVED_HELPERS = [{
1345
+ pattern: /\{\{#?select\b/,
1346
+ name: "{{#select}}",
1347
+ fix: "Replace the block with `{{selectOptions choices selected=value}}` (add `localize=true` when the labels are keys), or write the `<option>` list with `{{#each}}` and a `selected` attribute you compute yourself."
1348
+ }, {
1349
+ pattern: /\{\{colorPicker\b/,
1350
+ name: "{{colorPicker}}",
1351
+ fix: "Replace it with the `<color-picker>` element, `<color-picker name=\"...\" value=\"{{value}}\"></color-picker>`."
1352
+ }];
1353
+ async function runRemovedHelperRule(cwd) {
1354
+ const results = [];
1355
+ const files = [];
1356
+ for await (const file of _internal.walkTemplateFiles(cwd)) files.push(file);
1357
+ for (const path of files.sort()) {
1358
+ let source;
1359
+ try {
1360
+ source = await readFile(path, "utf8");
1361
+ } catch {
1362
+ continue;
1363
+ }
1364
+ const markup = withoutComments(source);
1365
+ for (const helper of REMOVED_HELPERS) {
1366
+ if (!helper.pattern.test(markup)) continue;
1367
+ const line = markup.split("\n").findIndex((text) => helper.pattern.test(text)) + 1;
1368
+ results.push({
1369
+ ruleId: "VTTF-AUDIT-021",
1370
+ title: "Template calls a Handlebars helper v14 removed",
1371
+ severity: "HIGH",
1372
+ filePath: relative(cwd, path),
1373
+ line: line > 0 ? line : 1,
1374
+ message: `${helper.name} was removed in v14. Rendering this template throws "Missing helper", so whatever renders it never opens.`,
1375
+ remediation: helper.fix
1376
+ });
1377
+ }
1378
+ }
1379
+ return results;
1380
+ }
1200
1381
  async function runTemplateRules(cwd) {
1382
+ const removedHelpers = await runRemovedHelperRule(cwd);
1201
1383
  const templates = /* @__PURE__ */ new Set();
1202
1384
  for await (const file of _internal.walkSourceFiles(cwd)) {
1203
1385
  let content;
@@ -1217,7 +1399,7 @@ async function runTemplateRules(cwd) {
1217
1399
  } catch {
1218
1400
  continue;
1219
1401
  }
1220
- const markup = source.replace(HANDLEBARS_COMMENT_RE, "");
1402
+ const markup = withoutComments(source);
1221
1403
  if (!FORM_TAG_RE.test(markup)) continue;
1222
1404
  const line = markup.split("\n").findIndex((text) => FORM_TAG_RE.test(text)) + 1;
1223
1405
  results.push({
@@ -1227,10 +1409,10 @@ async function runTemplateRules(cwd) {
1227
1409
  filePath: relative(cwd, path) || template,
1228
1410
  line: line > 0 ? line : 1,
1229
1411
  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.",
1230
- 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."
1412
+ remediation: "Replace the `<form>` wrapper with a `<div>`. Keep one root element: a part that renders several top-level elements fails to render. The fields belong to the application element, and `submitOnChange` saves them as they change."
1231
1413
  });
1232
1414
  }
1233
- return results;
1415
+ return [...results, ...removedHelpers];
1234
1416
  }
1235
1417
  //#endregion
1236
1418
  //#region src/audit/types.ts
@@ -1721,8 +1903,10 @@ async function runV14Rules(cwd) {
1721
1903
  * + cross-check with manifest where needed)
1722
1904
  * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
1723
1905
  * against which base each sheet is built on)
1724
- * - v14-rules.ts → VTTF-AUDIT-011 to 016 (v13 code that v14 broke
1906
+ * - v14-rules.ts → VTTF-AUDIT-011 to 019 (v13 code that v14 broke
1725
1907
  * or deprecated)
1908
+ * - release-rules.ts → VTTF-AUDIT-020 (a release workflow that ships the
1909
+ * checkout of a project that builds to dist/)
1726
1910
  *
1727
1911
  * The orchestrator stays minimal. It knows which rule sets exist, but
1728
1912
  * the rules themselves are responsible for their own file IO. This keeps
@@ -1739,17 +1923,19 @@ async function runAudit(options) {
1739
1923
  if (!existsSync(cwd)) throw new AuditTargetError(`Audit target does not exist: ${cwd}`);
1740
1924
  if (!statSync(cwd).isDirectory()) throw new AuditTargetError(`Audit target is not a directory: ${cwd}`);
1741
1925
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
1742
- const [manifestFindings, sourceFindings, templateFindings, v14Findings] = await Promise.all([
1926
+ const [manifestFindings, sourceFindings, templateFindings, v14Findings, releaseFindings] = await Promise.all([
1743
1927
  runManifestRules(cwd),
1744
1928
  runSourceRules(cwd),
1745
1929
  runTemplateRules(cwd),
1746
- runV14Rules(cwd)
1930
+ runV14Rules(cwd),
1931
+ runReleaseRules(cwd)
1747
1932
  ]);
1748
1933
  const findings = [
1749
1934
  ...manifestFindings,
1750
1935
  ...sourceFindings,
1751
1936
  ...templateFindings,
1752
- ...v14Findings
1937
+ ...v14Findings,
1938
+ ...releaseFindings
1753
1939
  ].sort(compareFindings);
1754
1940
  return {
1755
1941
  cwd,
@@ -3491,6 +3677,6 @@ async function runLintCommand(options = {}) {
3491
3677
  */
3492
3678
  const VTTFORGE_CLI_VERSION = version;
3493
3679
  //#endregion
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 };
3680
+ 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 };
3495
3681
 
3496
- //# sourceMappingURL=src-CzzrhCN-.mjs.map
3682
+ //# sourceMappingURL=src-BK9BmFiZ.mjs.map