{"version":3,"file":"index.cjs","names":["path","manifestName","DOOM_PACKAGE_NAME","fileURLToPath","piExtensionDispatcherPath","piExtensionDispatcherIsCurrent","writePiExtensionDispatcher"],"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,YAAYA,UAAAA,QAAK,QAAQ,KAAK;CAClC,OAAO,MAAM;EACX,KAAA,GAAIC,oCAAAA,aAAAA,CAAa,SAAS,MAAMC,oCAAAA,mBAAmB,OAAO;EAC1D,MAAM,SAASF,UAAAA,QAAK,QAAQ,SAAS;EACrC,IAAI,WAAW,WACb,MAAM,IAAI,MAAM,8BAA8BE,oCAAAA,kBAAkB,gBAAgB,OAAO;EAEzF,YAAY;CACd;AACF;;AAGA,SAAgB,kBAAkB,YAAA,QAAA,KAAA,CAAA,CAAA,cAAA,UAAA,CAAA,CAAA,MAAqC;CACrE,OAAO,mBAAmBF,UAAAA,QAAK,SAAA,GAAQG,SAAAA,cAAAA,CAAc,SAAS,CAAC,CAAC;AAClE;;AAGA,SAAgB,qBAAqB,aAA6B;CAChE,OAAOC,cAAAA,0BAA0B,WAAW;AAC9C;;AAGA,SAAgB,0BAA0B,aAAqB,eAAe,kBAAkB,GAAY;CAC1G,OAAOC,cAAAA,+BAA+B,WAAW;AACnD;;AAGA,SAAgB,sBAAsB,aAAqB,cAAc,kBAAkB,GAAW;CACpG,KAAA,GAAIJ,oCAAAA,aAAAA,CAAa,WAAW,MAAMC,oCAAAA,mBAChC,MAAM,IAAI,MAAM,qBAAqBA,oCAAAA,kBAAkB,6BAA6B,aAAa;CAEnG,OAAOI,cAAAA,2BAA2B,WAAW;AAC/C"}