@vttforge/cli 0.12.0 → 0.13.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-5a2deycw.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.13.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.
@@ -1721,8 +1844,10 @@ async function runV14Rules(cwd) {
1721
1844
  * + cross-check with manifest where needed)
1722
1845
  * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
1723
1846
  * against which base each sheet is built on)
1724
- * - v14-rules.ts → VTTF-AUDIT-011 to 016 (v13 code that v14 broke
1847
+ * - v14-rules.ts → VTTF-AUDIT-011 to 019 (v13 code that v14 broke
1725
1848
  * or deprecated)
1849
+ * - release-rules.ts → VTTF-AUDIT-020 (a release workflow that ships the
1850
+ * checkout of a project that builds to dist/)
1726
1851
  *
1727
1852
  * The orchestrator stays minimal. It knows which rule sets exist, but
1728
1853
  * the rules themselves are responsible for their own file IO. This keeps
@@ -1739,17 +1864,19 @@ async function runAudit(options) {
1739
1864
  if (!existsSync(cwd)) throw new AuditTargetError(`Audit target does not exist: ${cwd}`);
1740
1865
  if (!statSync(cwd).isDirectory()) throw new AuditTargetError(`Audit target is not a directory: ${cwd}`);
1741
1866
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
1742
- const [manifestFindings, sourceFindings, templateFindings, v14Findings] = await Promise.all([
1867
+ const [manifestFindings, sourceFindings, templateFindings, v14Findings, releaseFindings] = await Promise.all([
1743
1868
  runManifestRules(cwd),
1744
1869
  runSourceRules(cwd),
1745
1870
  runTemplateRules(cwd),
1746
- runV14Rules(cwd)
1871
+ runV14Rules(cwd),
1872
+ runReleaseRules(cwd)
1747
1873
  ]);
1748
1874
  const findings = [
1749
1875
  ...manifestFindings,
1750
1876
  ...sourceFindings,
1751
1877
  ...templateFindings,
1752
- ...v14Findings
1878
+ ...v14Findings,
1879
+ ...releaseFindings
1753
1880
  ].sort(compareFindings);
1754
1881
  return {
1755
1882
  cwd,
@@ -3491,6 +3618,6 @@ async function runLintCommand(options = {}) {
3491
3618
  */
3492
3619
  const VTTFORGE_CLI_VERSION = version;
3493
3620
  //#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 };
3621
+ 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
3622
 
3496
- //# sourceMappingURL=src-CzzrhCN-.mjs.map
3623
+ //# sourceMappingURL=src-5a2deycw.mjs.map