feat(generators): wire events entry + e2e test

Add EVENTS_RULE_BLOCK constant, events entry in CORE_PACKAGE_GENERATORS
dispatch table, events choice in prompts, and printEventsNextSteps helper.
Events entry emits 15 template files + transpilePackages splice + ESLint
no-restricted-syntax splice (E1 + J blocks). Add byte-identical e2e test
that strips @repo/core-events deps before pnpm install, scaffolds via
gen core-package events, and diffs against the snapshot.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-09 13:55:49 +02:00
parent 60961f73d0
commit 681fe6ada1
3 changed files with 177 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
import { describe, it, expect } from "vitest";
import { mkdtempSync, cpSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { execSync } from "node:child_process";
import { join, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { computeSnapshot } from "../lib/snapshot";
import expectedSnapshot from "../__snapshots__/core-package/events.snapshot.json";
// Repo root is 2 levels up from turbo/generators/__tests__
const REPO_ROOT = resolve(fileURLToPath(import.meta.url), "..", "..", "..", "..");
/**
* Strip "@repo/core-events" from a package.json file in the tmp tree.
* Required when simulating a fresh scaffold: core-events does not exist yet
* but the snapshot was captured before removal. Feature packages in the
* current tree may still list it as a dependency.
*/
function stripCoreEventsDep(pkgJsonPath: string): void {
const raw = readFileSync(pkgJsonPath, "utf8");
const parsed = JSON.parse(raw) as Record<string, Record<string, string>>;
for (const section of ["dependencies", "devDependencies", "peerDependencies"] as const) {
if (parsed[section]?.["@repo/core-events"]) {
delete parsed[section]["@repo/core-events"];
}
}
writeFileSync(pkgJsonPath, JSON.stringify(parsed, null, 2) + "\n");
}
describe("e2e: core-package events", () => {
it("byte-identical reconstruction matches snapshot", { timeout: 120_000 }, () => {
const tmp = mkdtempSync(join(tmpdir(), "e2e-events-"));
cpSync(REPO_ROOT, tmp, {
recursive: true,
filter: (src) =>
!src.includes("node_modules") &&
!src.includes(".turbo") &&
!src.includes("packages/core-events"),
});
// Strip @repo/core-events from feature package.json files so pnpm install
// succeeds without the package being present (simulating the post-removal state).
const featurePackages = ["auth", "blog", "media", "marketing-pages", "navigation"];
for (const pkg of featurePackages) {
const pkgJson = join(tmp, "packages", pkg, "package.json");
stripCoreEventsDep(pkgJson);
}
// Also strip from apps/web-next
stripCoreEventsDep(join(tmp, "apps", "web-next", "package.json"));
execSync(`cd ${tmp} && pnpm install --frozen-lockfile=false`, { stdio: "ignore" });
execSync(`cd ${tmp} && pnpm turbo gen core-package --args events`, { stdio: "ignore" });
const result = computeSnapshot(join(tmp, "packages/core-events"));
expect(result).toEqual(expectedSnapshot);
});
});