{"version":3,"file":"retire-v1-shell.cjs","names":["Effect","fileExists","readText","writeText","RETIRED_STUB_FILES","removePath"],"sources":["../../../../../src/services/scaffold/upgrade-audit/steps/retire-v1-shell.ts"],"sourcesContent":["import { Effect } from \"effect\";\nimport { fileExists, readText, removePath, writeText } from \"../fs\";\nimport { RETIRED_STUB_FILES } from \"../obsolete-files\";\nimport type { StepResult } from \"./author-config\";\n\nconst RSBUILD_PATH = \"ui/rsbuild.config.ts\";\n\n/**\n * Retires the v1 hand-written UI shells once the generated stubs can take\n * over (ADR 0023):\n *\n * 1. Rewires `ui/rsbuild.config.ts` so the client build entry, the\n *    `./Hydrate` federation expose, the SSR build entry, and the server\n *    `./Router` expose all point at the generated stubs\n *    (`hydrate.gen.tsx` / `router.server.gen.tsx`) instead of the\n *    hand-written shells.\n * 2. Deletes each retired shell only when its generated replacement exists\n *    AND no build config reference remains — they are live build entries on\n *    a v1 tree, so both guards are required.\n *\n * The generated stubs import `everything-dev/ui/hydrate` /\n * `everything-dev/ui/router-server` / `everything-dev/ui/entry`, which are\n * only published by v2 framework releases. The apply train pins the v2\n * catalog (migrate-pnpm) before this step, so resolution succeeds after\n * the post-apply install.\n */\n\nconst rewireConfig = (source: string): { next: string; changes: number } => {\n  let changes = 0;\n  let next = source;\n  for (const [from, to] of [\n    [\"./src/hydrate.tsx\", \"./src/hydrate.gen.tsx\"],\n    [\"./src/router.server.tsx\", \"./src/router.server.gen.tsx\"],\n  ] as const) {\n    if (next.includes(from)) {\n      next = next.replaceAll(from, to);\n      changes += 1;\n    }\n  }\n  return { next, changes };\n};\n\nexport const retireV1Shell = (\n  projectDir: string,\n  dryRun: boolean,\n): Effect.Effect<StepResult, Error> =>\n  Effect.gen(function* () {\n    const writes: string[] = [];\n    const deletes: string[] = [];\n    const notes: string[] = [];\n\n    let configSource: string | null = null;\n    const rsbuildExists = yield* fileExists(projectDir, RSBUILD_PATH);\n    if (rsbuildExists) {\n      const source = yield* readText(projectDir, RSBUILD_PATH);\n      const { next, changes } = rewireConfig(source);\n      // Use the in-memory rewired source for reference guards so dry-run\n      // previews see the post-rewire state, not the stale disk state.\n      configSource = next;\n      if (changes > 0) {\n        if (!dryRun) yield* writeText(projectDir, RSBUILD_PATH, next);\n        writes.push(RSBUILD_PATH);\n        notes.push(\n          `rsbuild config rewired: ${changes} entry/expose reference(s) moved onto the generated stubs (hydrate.gen.tsx / router.server.gen.tsx)`,\n        );\n      } else {\n        notes.push(\"rsbuild config references no v1 shell paths — left untouched\");\n      }\n    } else {\n      notes.push(\"ui/rsbuild.config.ts absent — no entry rewiring possible\");\n    }\n\n    for (const [retired, replacement] of Object.entries(RETIRED_STUB_FILES)) {\n      const retiredExists = yield* fileExists(projectDir, retired);\n      if (!retiredExists) {\n        notes.push(`${retired} absent — nothing to retire`);\n        continue;\n      }\n      const replacementExists = yield* fileExists(projectDir, replacement);\n      if (!replacementExists) {\n        notes.push(\n          `${retired}: replacement ${replacement} not generated yet — retirement deferred (run \\`bos types gen\\`)`,\n        );\n        continue;\n      }\n      if (configSource !== null) {\n        const baseName = retired.slice(retired.lastIndexOf(\"/\") + 1);\n        if (configSource.includes(baseName)) {\n          notes.push(\n            `${retired}: rsbuild config still references ${baseName} — retirement deferred; fix the config first`,\n          );\n          continue;\n        }\n      }\n      if (!dryRun) yield* removePath(projectDir, retired);\n      deletes.push(retired);\n      notes.push(`retired ${retired} (replaced by generated stub ${replacement})`);\n    }\n\n    return { writes, deletes, notes };\n  });\n"],"mappings":";;;;;AAKA,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;AAsBrB,MAAM,gBAAgB,WAAsD;CAC1E,IAAI,UAAU;CACd,IAAI,OAAO;CACX,KAAK,MAAM,CAAC,MAAM,OAAO,CACvB,CAAC,qBAAqB,uBAAuB,GAC7C,CAAC,2BAA2B,6BAA6B,CAC3D,GACE,IAAI,KAAK,SAAS,IAAI,GAAG;EACvB,OAAO,KAAK,WAAW,MAAM,EAAE;EAC/B,WAAW;CACb;CAEF,OAAO;EA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