@vttforge/cli 0.11.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.d.mts CHANGED
@@ -224,6 +224,49 @@ export declare class ScaffoldError extends Error {
224
224
  }
225
225
  export declare function runInit(options?: InitOptions): Promise<void>;
226
226
  //#endregion
227
+ //#region src/commands/lint.d.ts
228
+ /**
229
+ * `vttforge lint`: Biome over the project, then the v14 audit.
230
+ *
231
+ * Biome ships as a dependency of this package, so a scaffolded project has
232
+ * a linter and a formatter without installing or configuring one. The
233
+ * config it runs with is `<cli-pkg>/lint/vttforge-biome.json` unless the project
234
+ * has its own `biome.json` / `biome.jsonc` at its root, in which case that
235
+ * one wins and the shipped config is not read at all. A project that wants
236
+ * to tweak a rule copies the shipped file and edits it.
237
+ *
238
+ * `--fix` writes the safe fixes and formats the files; without it the run
239
+ * only reports. The audit runs after Biome either way (`--no-audit` skips
240
+ * it), and the exit code is non-zero when either half fails.
241
+ */
242
+ interface LintOptions {
243
+ /** Project root to lint. Defaults to `process.cwd()`. */
244
+ cwd?: string;
245
+ /** Write the safe fixes and format the files. Default false: report only. */
246
+ fix?: boolean;
247
+ /** Run `vttforge audit` after Biome. Default true. */
248
+ audit?: boolean;
249
+ /** Passed to the audit: any finding fails, not only HIGH. Default false. */
250
+ strict?: boolean;
251
+ /** Custom writer for the audit report (tests). Defaults to process.stdout.write. */
252
+ write?: (chunk: string) => void;
253
+ }
254
+ interface LintResult {
255
+ /** Exit code of the Biome run. */
256
+ biomeExitCode: number;
257
+ /** Exit code of the audit, or `null` when it was skipped. */
258
+ auditExitCode: 0 | 1 | null;
259
+ /** Non-zero when either half failed. */
260
+ exitCode: number;
261
+ /** The shipped Biome config file in use. `null` means the project's own. */
262
+ configPath: string | null;
263
+ }
264
+ /**
265
+ * @experimental Shape is unproven: no consumer has asked for this yet. It can
266
+ * change in a minor.
267
+ */
268
+ export declare function runLintCommand(options?: LintOptions): Promise<LintResult>;
269
+ //#endregion
227
270
  //#region src/zip.d.ts
228
271
  /**
229
272
  * Emit a foundryvtt.com-compatible release zip.
@@ -260,5 +303,5 @@ export declare function emitZip(opts: EmitZipOptions): Promise<EmitZipResult>;
260
303
  //#region src/index.d.ts
261
304
  export declare const VTTFORGE_CLI_VERSION: string;
262
305
  //#endregion
263
- export type { AuditOptions, AuditReport, AuditResult, BuildOptions, DevOptions, EmitZipOptions, EmitZipResult, FoundryManifest, InitOptions, PackageType, ReportFormat, ResolvedInitOptions, RuleFn, RuleResult, RunAuditOptions, Severity, TemplateVariant };
306
+ export type { AuditOptions, AuditReport, AuditResult, BuildOptions, DevOptions, EmitZipOptions, EmitZipResult, FoundryManifest, InitOptions, LintOptions, LintResult, PackageType, ReportFormat, ResolvedInitOptions, RuleFn, RuleResult, RunAuditOptions, Severity, TemplateVariant };
264
307
  //# sourceMappingURL=index.d.mts.map
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as SEVERITY_RANK, a as emitReleaseZip, b as runManifestRules, c as readManifest, d as runAudit, i as runDev, l as runAuditCommand, n as ScaffoldError, o as runBuild, r as runInit, s as emitZip, t as VTTFORGE_CLI_VERSION, u as formatReport, y as runSourceRules } from "./src-CgS7GUiL.mjs";
2
- export { SEVERITY_RANK, ScaffoldError, VTTFORGE_CLI_VERSION, emitReleaseZip, emitZip, formatReport, readManifest, runAudit, runAuditCommand, runBuild, runDev, runInit, runManifestRules, runSourceRules };
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
+ export { SEVERITY_RANK, ScaffoldError, VTTFORGE_CLI_VERSION, emitReleaseZip, emitZip, formatReport, readManifest, runAudit, runAuditCommand, runBuild, runDev, runInit, runLintCommand, runManifestRules, runSourceRules };
@@ -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.11.0";
14
+ var version = "0.13.0";
14
15
  //#endregion
15
16
  //#region src/audit/manifest-rules.ts
16
17
  /**
@@ -339,6 +340,129 @@ async function runManifestRules(cwd) {
339
340
  return results;
340
341
  }
341
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
342
466
  //#region src/audit/source-rules.ts
343
467
  /**
344
468
  * Source-tree audit rules.
@@ -1720,8 +1844,10 @@ async function runV14Rules(cwd) {
1720
1844
  * + cross-check with manifest where needed)
1721
1845
  * - template-rules.ts → VTTF-AUDIT-008 (the Handlebars, cross-checked
1722
1846
  * against which base each sheet is built on)
1723
- * - 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
1724
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/)
1725
1851
  *
1726
1852
  * The orchestrator stays minimal. It knows which rule sets exist, but
1727
1853
  * the rules themselves are responsible for their own file IO. This keeps
@@ -1738,17 +1864,19 @@ async function runAudit(options) {
1738
1864
  if (!existsSync(cwd)) throw new AuditTargetError(`Audit target does not exist: ${cwd}`);
1739
1865
  if (!statSync(cwd).isDirectory()) throw new AuditTargetError(`Audit target is not a directory: ${cwd}`);
1740
1866
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
1741
- const [manifestFindings, sourceFindings, templateFindings, v14Findings] = await Promise.all([
1867
+ const [manifestFindings, sourceFindings, templateFindings, v14Findings, releaseFindings] = await Promise.all([
1742
1868
  runManifestRules(cwd),
1743
1869
  runSourceRules(cwd),
1744
1870
  runTemplateRules(cwd),
1745
- runV14Rules(cwd)
1871
+ runV14Rules(cwd),
1872
+ runReleaseRules(cwd)
1746
1873
  ]);
1747
1874
  const findings = [
1748
1875
  ...manifestFindings,
1749
1876
  ...sourceFindings,
1750
1877
  ...templateFindings,
1751
- ...v14Findings
1878
+ ...v14Findings,
1879
+ ...releaseFindings
1752
1880
  ].sort(compareFindings);
1753
1881
  return {
1754
1882
  cwd,
@@ -3362,6 +3490,110 @@ function runInstall(pm, cwd) {
3362
3490
  });
3363
3491
  }
3364
3492
  //#endregion
3493
+ //#region src/commands/lint.ts
3494
+ /**
3495
+ * `vttforge lint`: Biome over the project, then the v14 audit.
3496
+ *
3497
+ * Biome ships as a dependency of this package, so a scaffolded project has
3498
+ * a linter and a formatter without installing or configuring one. The
3499
+ * config it runs with is `<cli-pkg>/lint/vttforge-biome.json` unless the project
3500
+ * has its own `biome.json` / `biome.jsonc` at its root, in which case that
3501
+ * one wins and the shipped config is not read at all. A project that wants
3502
+ * to tweak a rule copies the shipped file and edits it.
3503
+ *
3504
+ * `--fix` writes the safe fixes and formats the files; without it the run
3505
+ * only reports. The audit runs after Biome either way (`--no-audit` skips
3506
+ * it), and the exit code is non-zero when either half fails.
3507
+ */
3508
+ var BiomeNotFoundError = class extends Error {
3509
+ constructor(message) {
3510
+ super(message);
3511
+ this.name = "BiomeNotFoundError";
3512
+ }
3513
+ };
3514
+ /**
3515
+ * The Biome config shipped with the CLI, resolved from the built module.
3516
+ *
3517
+ * The file is not named `biome.json` on purpose: Biome treats a file with
3518
+ * that name as a nested root config and refuses to run, which would break
3519
+ * a project (or this monorepo) that holds the CLI inside another
3520
+ * Biome-rooted tree. `--config-path` accepts any file path.
3521
+ */
3522
+ const SHIPPED_CONFIG_NAME = "vttforge-biome.json";
3523
+ function shippedConfig() {
3524
+ const here = fileURLToPath(import.meta.url);
3525
+ const fromDist = resolve(here, "..", "..", "lint", SHIPPED_CONFIG_NAME);
3526
+ if (existsSync(fromDist)) return fromDist;
3527
+ return resolve(here, "..", "..", "..", "lint", SHIPPED_CONFIG_NAME);
3528
+ }
3529
+ /** The project's own config wins when it has one. */
3530
+ function projectConfig(cwd) {
3531
+ for (const name of ["biome.json", "biome.jsonc"]) {
3532
+ const file = join(cwd, name);
3533
+ if (existsSync(file)) return file;
3534
+ }
3535
+ return null;
3536
+ }
3537
+ /** The Biome bin shim, resolved from this package's own dependency graph. */
3538
+ function biomeBin() {
3539
+ const require = createRequire(import.meta.url);
3540
+ try {
3541
+ return require.resolve("@biomejs/biome/bin/biome");
3542
+ } catch {
3543
+ throw new BiomeNotFoundError("Could not resolve @biomejs/biome from @vttforge/cli. Reinstall the CLI (it ships Biome as a dependency).");
3544
+ }
3545
+ }
3546
+ /** The argv for Biome: `ci .` to report, `check --write .` to fix. */
3547
+ function biomeArgs(opts) {
3548
+ const args = opts.fix ? [
3549
+ "check",
3550
+ "--write",
3551
+ "."
3552
+ ] : ["ci", "."];
3553
+ if (opts.configPath) args.push(`--config-path=${opts.configPath}`);
3554
+ return args;
3555
+ }
3556
+ function runBiome(cwd, args) {
3557
+ const bin = biomeBin();
3558
+ return new Promise((resolveRun, rejectRun) => {
3559
+ const child = spawn(process.execPath, [bin, ...args], {
3560
+ cwd,
3561
+ stdio: "inherit",
3562
+ env: process.env,
3563
+ shell: false
3564
+ });
3565
+ child.on("error", rejectRun);
3566
+ child.on("exit", (code) => resolveRun(code ?? 1));
3567
+ });
3568
+ }
3569
+ /**
3570
+ * @experimental Shape is unproven: no consumer has asked for this yet. It can
3571
+ * change in a minor.
3572
+ */
3573
+ async function runLintCommand(options = {}) {
3574
+ const cwd = resolve(options.cwd ?? process.cwd());
3575
+ const fix = options.fix === true;
3576
+ const audit = options.audit !== false;
3577
+ if (!existsSync(join(cwd, "package.json"))) throw new Error(`No package.json found at ${cwd}. Run \`vttforge lint\` from inside a scaffolded project.`);
3578
+ const configPath = projectConfig(cwd) === null ? shippedConfig() : null;
3579
+ const biomeExitCode = await runBiome(cwd, biomeArgs({
3580
+ fix,
3581
+ configPath
3582
+ }));
3583
+ let auditExitCode = null;
3584
+ if (audit) auditExitCode = (await runAuditCommand({
3585
+ cwd,
3586
+ strict: options.strict === true,
3587
+ write: options.write
3588
+ })).exitCode;
3589
+ return {
3590
+ biomeExitCode,
3591
+ auditExitCode,
3592
+ exitCode: biomeExitCode !== 0 ? biomeExitCode : auditExitCode ?? 0,
3593
+ configPath
3594
+ };
3595
+ }
3596
+ //#endregion
3365
3597
  //#region src/index.ts
3366
3598
  /**
3367
3599
  * @vttforge/cli: public library exports.
@@ -3386,6 +3618,6 @@ function runInstall(pm, cwd) {
3386
3618
  */
3387
3619
  const VTTFORGE_CLI_VERSION = version;
3388
3620
  //#endregion
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 };
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 };
3390
3622
 
3391
- //# sourceMappingURL=src-CgS7GUiL.mjs.map
3623
+ //# sourceMappingURL=src-5a2deycw.mjs.map