one
Version:
One is a new React Framework that makes Vite serve both native and web.
52 lines (51 loc) • 2.19 kB
JavaScript
import { dirname, join } from "path";
import FSExtra from "fs-extra";
import { toAbsolute } from "./toAbsolute.native.js";
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
var buildOutputPointerPath = join("node_modules", ".cache", "one", "build-pointer.json");
async function writeBuildOutputPointer(outDir) {
try {
var 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.`, _instanceof(err, Error) ? err.message : err);
}
}
async function resolveServeOutDir(outDir) {
if (outDir) {
return outDir;
}
if (FSExtra.existsSync("buildInfo.json")) {
return ".";
}
var pointer;
try {
pointer = await FSExtra.readJSON(buildOutputPointerPath);
} catch (err) {
if ((err === null || err === void 0 ? void 0 : err.code) && err.code !== "ENOENT") {
var _err_message;
console.warn(`[one serve] could not read build-output pointer (${buildOutputPointerPath}):`, (_err_message = err.message) !== null && _err_message !== void 0 ? _err_message : err);
}
}
if (pointer === null || pointer === void 0 ? void 0 : 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.native.js.map