one
Version:
One is a new React Framework that makes Vite serve both native and web.
93 lines (91 loc) • 4 kB
JavaScript
;
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_path = require("path");
var import_fs_extra = __toESM(require("fs-extra"), 1);
var import_toAbsolute = require("./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 = (0, import_path.join)("node_modules", ".cache", "one", "build-pointer.json");
async function writeBuildOutputPointer(outDir) {
try {
var pointerPath = (0, import_toAbsolute.toAbsolute)(buildOutputPointerPath);
await import_fs_extra.default.ensureDir((0, import_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.`, _instanceof(err, Error) ? err.message : err);
}
}
async function resolveServeOutDir(outDir) {
if (outDir) {
return outDir;
}
if (import_fs_extra.default.existsSync("buildInfo.json")) {
return ".";
}
var pointer;
try {
pointer = await import_fs_extra.default.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 import_fs_extra.default.pathExists((0, import_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";
}
//# sourceMappingURL=buildOutputPointer.native.js.map