{"version":3,"file":"buildOutputPointer.js","names":[],"sources":["esm/utils/buildOutputPointer.js"],"sourcesContent":["import { dirname, join } from \"node:path\";\nimport FSExtra from \"fs-extra\";\nimport { toAbsolute } from \"./toAbsolute\";\nconst buildOutputPointerPath = join(\n  \"node_modules\",\n  \".cache\",\n  \"one\",\n  \"build-pointer.json\"\n);\nasync function writeBuildOutputPointer(outDir) {\n  try {\n    const pointerPath = toAbsolute(buildOutputPointerPath);\n    await FSExtra.ensureDir(dirname(pointerPath));\n    await FSExtra.writeJSON(pointerPath, { outDir });\n  } catch (err) {\n    console.warn(\n      `[one build] could not write build-output pointer (${buildOutputPointerPath}). \\`one serve\\` will fall back to 'dist/' unless you pass --outDir.`,\n      err instanceof Error ? err.message : err\n    );\n  }\n}\nasync function resolveServeOutDir(outDir) {\n  if (outDir) {\n    return outDir;\n  }\n  if (FSExtra.existsSync(\"buildInfo.json\")) {\n    return \".\";\n  }\n  let pointer;\n  try {\n    pointer = await FSExtra.readJSON(buildOutputPointerPath);\n  } catch (err) {\n    if (err?.code && err.code !== \"ENOENT\") {\n      console.warn(\n        `[one serve] could not read build-output pointer (${buildOutputPointerPath}):`,\n        err.message ?? err\n      );\n    }\n  }\n  if (pointer?.outDir) {\n    if (await FSExtra.pathExists(join(pointer.outDir, \"buildInfo.json\"))) {\n      return pointer.outDir;\n    }\n    console.warn(\n      `[one serve] build-pointer.json points to '${pointer.outDir}/' but no buildInfo.json was found there. run \\`one build\\` to refresh the marker.`\n    );\n  }\n  if (!FSExtra.existsSync(\"dist/buildInfo.json\")) {\n    console.warn(\n      `[one serve] no build-output pointer and no 'dist/buildInfo.json'. did \\`one build\\` run from this cwd? pass --outDir to point at the build output.`\n    );\n  }\n  return \"dist\";\n}\nexport {\n  buildOutputPointerPath,\n  resolveServeOutDir,\n  writeBuildOutputPointer\n};\n//# sourceMappingURL=buildOutputPointer.js.map\n"],"mappings":";;;;;AAGA,MAAM,yBAAyB,KAC7B,gBACA,UACA,OACA,oBACF;AACA,eAAe,wBAAwB,QAAQ;CAC7C,IAAI;EACF,MAAM,cAAc,WAAW,sBAAsB;EACrD,MAAM,QAAQ,UAAU,QAAQ,WAAW,CAAC;EAC5C,MAAM,QAAQ,UAAU,aAAa,EAAE,OAAO,CAAC;CACjD,SAAS,KAAK;EACZ,QAAQ,KACN,qDAAqD,uBAAuB,uEAC5E,eAAe,QAAQ,IAAI,UAAU,GACvC;CACF;AACF;AACA,eAAe,mBAAmB,QAAQ;CACxC,IAAI,QAAQ;EACV,OAAO;CACT;CACA,IAAI,QAAQ,WAAW,gBAAgB,GAAG;EACxC,OAAO;CACT;CACA,IAAI;CACJ,IAAI;EACF,UAAU,MAAM,QAAQ,SAAS,sBAAsB;CACzD,SAAS,KAAK;EACZ,IAAI,KAAK,QAAQ,IAAI,SAAS,UAAU;GACtC,QAAQ,KACN,oDAAoD,uBAAuB,KAC3E,IAAI,WAAW,GACjB;EACF;CACF;CACA,IAAI,SAAS,QAAQ;EACnB,IAAI,MAAM,QAAQ,WAAW,KAAK,QAAQ,QAAQ,gBAAgB,CAAC,GAAG;GACpE,OAAO,QAAQ;EACjB;EACA,QAAQ,KACN,6CAA6C,QAAQ,OAAO,mFAC9D;CACF;CACA,IAAI,CAAC,QAAQ,WAAW,qBAAqB,GAAG;EAC9C,QAAQ,KACN,oJACF;CACF;CACA,OAAO;AACT"}