UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

81 lines 3.55 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var buildOutputPointer_exports = {}; __export(buildOutputPointer_exports, { buildOutputPointerPath: () => buildOutputPointerPath, resolveServeOutDir: () => resolveServeOutDir, writeBuildOutputPointer: () => writeBuildOutputPointer }); module.exports = __toCommonJS(buildOutputPointer_exports); var import_node_path = require("node:path"); var import_fs_extra = __toESM(require("fs-extra"), 1); var import_toAbsolute = require("./toAbsolute.cjs"); const buildOutputPointerPath = (0, import_node_path.join)("node_modules", ".cache", "one", "build-pointer.json"); async function writeBuildOutputPointer(outDir) { try { const pointerPath = (0, import_toAbsolute.toAbsolute)(buildOutputPointerPath); await import_fs_extra.default.ensureDir((0, import_node_path.dirname)(pointerPath)); await import_fs_extra.default.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 (import_fs_extra.default.existsSync("buildInfo.json")) { return "."; } let pointer; try { pointer = await import_fs_extra.default.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 import_fs_extra.default.pathExists((0, import_node_path.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 (!import_fs_extra.default.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"; }