{"version":3,"file":"migration-ts.mjs","names":[],"sources":["../../src/migration-ts.ts","../../src/runtime-detection.ts"],"sourcesContent":["/**\n * Utilities for reading/writing `migration.ts` files.\n *\n * Rendering migration.ts source is the target's responsibility — the CLI\n * obtains source strings from a planner's `plan.renderTypeScript()`. The\n * helper here is limited to file I/O: writing the returned source with the\n * right executable bit and probing for existence.\n */\n\nimport { stat, writeFile } from 'node:fs/promises';\nimport { join } from 'pathe';\nimport { format } from 'prettier';\n\nconst MIGRATION_TS_FILE = 'migration.ts';\n\n/**\n * Writes a pre-rendered `migration.ts` source string to the given package\n * directory. If the source begins with a shebang, the file is written with\n * executable permissions (0o755) so it can be run directly via\n * `./migration.ts` — the rendered scaffold ends with\n * `MigrationCLI.run(import.meta.url, M)` from\n * `@prisma-next/cli/migration-cli` (re-exported by the postgres facade),\n * which guards on the entrypoint and serializes when the file is the main\n * module.\n *\n * The source is run through prettier before writing so migration renderers\n * can produce structurally-correct but loosely-indented source and rely on\n * a single canonical format on disk. Matches what `@prisma-next/emitter`\n * already does for generated `contract.d.ts`.\n */\nexport async function writeMigrationTs(packageDir: string, content: string): Promise<void> {\n  const formatted = await formatMigrationTsSource(content);\n  const isExecutable = formatted.startsWith('#!');\n  await writeFile(\n    join(packageDir, MIGRATION_TS_FILE),\n    formatted,\n    isExecutable ? { mode: 0o755 } : undefined,\n  );\n}\n\nasync function formatMigrationTsSource(source: string): Promise<string> {\n  return format(source, {\n    parser: 'typescript',\n    singleQuote: true,\n    semi: true,\n    printWidth: 100,\n  });\n}\n\n/**\n * Checks whether a migration.ts file exists in the package directory.\n */\nexport async function hasMigrationTs(packageDir: string): Promise<boolean> {\n  try {\n    const s = await stat(join(packageDir, MIGRATION_TS_FILE));\n    return s.isFile();\n  } catch {\n    return false;\n  }\n}\n","export type ScaffoldRuntime = 'node' | 'bun' | 'deno';\n\nexport function detectScaffoldRuntime(): ScaffoldRuntime {\n  if (typeof (globalThis as { Bun?: unknown }).Bun !== 'undefined') return 'bun';\n  if (typeof (globalThis as { Deno?: unknown }).Deno !== 'undefined') return 'deno';\n  return 'node';\n}\n\nexport function shebangLineFor(runtime: ScaffoldRuntime): string {\n  switch (runtime) {\n    case 'bun':\n      return '#!/usr/bin/env -S bun';\n    case 'deno':\n      return '#!/usr/bin/env -S deno run -A';\n    case 'node':\n      return '#!/usr/bin/env -S node';\n  }\n}\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,oBAAoB;;;;;;;;;;;;;;;;AAiB1B,eAAsB,iBAAiB,YAAoB,SAAgC;CACzF,MAAM,YAAY,MAAM,wBAAwB,OAAO;CACvD,MAAM,eAAe,UAAU,WAAW,IAAI;CAC9C,MAAM,UACJ,KAAK,YAAY,iBAAiB,GAClC,WACA,eAAe,EAAE,MAAM,IAAM,IAAI,KAAA,CACnC;AACF;AAEA,eAAe,wBAAwB,QAAiC;CACtE,OAAO,OAAO,QAAQ;EACpB,QAAQ;EACR,aAAa;EACb,MAAM;EACN,YAAY;CACd,CAAC;AACH;;;;AAKA,eAAsB,eAAe,YAAsC;CACzE,IAAI;EAEF,QAAO,MADS,KAAK,KAAK,YAAY,iBAAiB,CAAC,EAAA,CAC/C,OAAO;CAClB,QAAQ;EACN,OAAO;CACT;AACF;;;ACzDA,SAAgB,wBAAyC;CACvD,IAAI,OAAQ,WAAiC,QAAQ,aAAa,OAAO;CACzE,IAAI,OAAQ,WAAkC,SAAS,aAAa,OAAO;CAC3E,OAAO;AACT;AAEA,SAAgB,eAAe,SAAkC;CAC/D,QAAQ,SAAR;EACE,KAAK,OACH,OAAO;EACT,KAAK,QACH,OAAO;EACT,KAAK,QACH,OAAO;CACX;AACF"}