{"version":3,"file":"index.mjs","names":[],"sources":["../../../../src/builders/cli/piExtensionAlias/index.ts"],"sourcesContent":["import path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { DOOM_PACKAGE_NAME, manifestName } from '@agimon-ai/doompi-core/doom-package';\n\nimport {\n  piExtensionDispatcherIsCurrent,\n  piExtensionDispatcherPath,\n  writePiExtensionDispatcher,\n} from '../piExtensionDispatcher';\n\nfunction nearestPackageRoot(start: string): string {\n  let directory = path.resolve(start);\n  while (true) {\n    if (manifestName(directory) === DOOM_PACKAGE_NAME) return directory;\n    const parent = path.dirname(directory);\n    if (parent === directory) {\n      throw new Error(`Could not locate installed ${DOOM_PACKAGE_NAME} package from ${start}`);\n    }\n    directory = parent;\n  }\n}\n\n/** Installed package root for the source or compiled module executing sync. */\nexport function doomPiPackageRoot(moduleUrl = import.meta.url): string {\n  return nearestPackageRoot(path.dirname(fileURLToPath(moduleUrl)));\n}\n\n/** Compatibility name for the stable package path now occupied by the dispatcher. */\nexport function piExtensionAliasPath(piDirectory: string): string {\n  return piExtensionDispatcherPath(piDirectory);\n}\n\n/** Compatibility name for init-owned dispatcher readiness. */\nexport function piExtensionAliasIsCurrent(piDirectory: string, _packageRoot = doomPiPackageRoot()): boolean {\n  return piExtensionDispatcherIsCurrent(piDirectory);\n}\n\n/** Compatibility name retained while callers migrate from the legacy symlink. */\nexport function writePiExtensionAlias(piDirectory: string, packageRoot = doomPiPackageRoot()): string {\n  if (manifestName(packageRoot) !== DOOM_PACKAGE_NAME) {\n    throw new Error(`Cannot initialize ${DOOM_PACKAGE_NAME} from a different package: ${packageRoot}`);\n  }\n  return writePiExtensionDispatcher(piDirectory);\n}\n"],"mappings":";;;;;AAWA,SAAS,mBAAmB,OAAuB;CACjD,IAAI,YAAY,KAAK,QAAQ,KAAK;CAClC,OAAO,MAAM;EACX,IAAI,aAAa,SAAS,MAAM,mBAAmB,OAAO;EAC1D,MAAM,SAAS,KAAK,QAAQ,SAAS;EACrC,IAAI,WAAW,WACb,MAAM,IAAI,MAAM,8BAA8B,kBAAkB,gBAAgB,OAAO;EAEzF,YAAY;CACd;AACF;;AAGA,SAAgB,kBAAkB,YAAY,YAAY,KAAa;CACrE,OAAO,mBAAmB,KAAK,QAAQ,cAAc,SAAS,CAAC,CAAC;AAClE;;AAGA,SAAgB,qBAAqB,aAA6B;CAChE,OAAO,0BAA0B,WAAW;AAC9C;;AAGA,SAAgB,0BAA0B,aAAqB,eAAe,kBAAkB,GAAY;CAC1G,OAAO,+BAA+B,WAAW;AACnD;;AAGA,SAAgB,sBAAsB,aAAqB,cAAc,kBAAkB,GAAW;CACpG,IAAI,aAAa,WAAW,MAAM,mBAChC,MAAM,IAAI,MAAM,qBAAqB,kBAAkB,6BAA6B,aAAa;CAEnG,OAAO,2BAA2B,WAAW;AAC/C"}