one
Version:
One is a new React Framework that makes Vite serve both native and web.
44 lines (43 loc) • 1.78 kB
JavaScript
import { dirname, join } from "node:path";
import FSExtra from "fs-extra";
import { toAbsolute } from "./toAbsolute.mjs";
const buildOutputPointerPath = join("node_modules", ".cache", "one", "build-pointer.json");
async function writeBuildOutputPointer(outDir) {
try {
const pointerPath = toAbsolute(buildOutputPointerPath);
await FSExtra.ensureDir(dirname(pointerPath));
await FSExtra.writeJSON(pointerPath, {
outDir
});
} catch (err) {
console.warn(`[one build] could not write build-output pointer (${buildOutputPointerPath}). \`one serve\` will fall back to 'dist/' unless you pass --outDir.`, err instanceof Error ? err.message : err);
}
}
async function resolveServeOutDir(outDir) {
if (outDir) {
return outDir;
}
if (FSExtra.existsSync("buildInfo.json")) {
return ".";
}
let pointer;
try {
pointer = await FSExtra.readJSON(buildOutputPointerPath);
} catch (err) {
if (err?.code && err.code !== "ENOENT") {
console.warn(`[one serve] could not read build-output pointer (${buildOutputPointerPath}):`, err.message ?? err);
}
}
if (pointer?.outDir) {
if (await FSExtra.pathExists(join(pointer.outDir, "buildInfo.json"))) {
return pointer.outDir;
}
console.warn(`[one serve] build-pointer.json points to '${pointer.outDir}/' but no buildInfo.json was found there. run \`one build\` to refresh the marker.`);
}
if (!FSExtra.existsSync("dist/buildInfo.json")) {
console.warn(`[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.`);
}
return "dist";
}
export { buildOutputPointerPath, resolveServeOutDir, writeBuildOutputPointer };
//# sourceMappingURL=buildOutputPointer.mjs.map