one
Version:
One is a new React Framework that makes Vite serve both native and web.
85 lines • 3.5 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 devtoolsPlugin_exports = {};
__export(devtoolsPlugin_exports, {
DEVTOOLS_VIRTUAL_ID: () => DEVTOOLS_VIRTUAL_ID,
createDevtoolsPlugin: () => createDevtoolsPlugin
});
module.exports = __toCommonJS(devtoolsPlugin_exports);
var import_node_fs = require("node:fs");
var import_node_path = __toESM(require("node:path"), 1);
var import_resolve = require("@vxrn/resolve");
const DEVTOOLS_VIRTUAL_ID = "/@one/dev.js";
function createDevtoolsPlugin(options = {}) {
const {
includeUI = true
} = options;
return {
name: "one-devtools",
apply: "serve",
// only in dev
configureServer(server) {
server.middlewares.use(async (req, res, next) => {
if (req.url === DEVTOOLS_VIRTUAL_ID) {
try {
const devEntryPath = (0, import_resolve.resolvePath)("one/devtools/dev.mjs");
const devEntry = (0, import_node_fs.readFileSync)(devEntryPath, "utf-8");
let code = devEntry.replace("import './devtools.mjs'", "").replace("import './source-inspector.mjs'", "");
if (includeUI) {
const devtoolsPath = (0, import_resolve.resolvePath)("one/devtools/devtools.mjs");
const sourceInspectorPath = (0, import_resolve.resolvePath)("one/devtools/source-inspector.mjs");
const devtools = (0, import_node_fs.readFileSync)(devtoolsPath, "utf-8");
const sourceInspector = (0, import_node_fs.readFileSync)(sourceInspectorPath, "utf-8");
const projectName = import_node_path.default.basename(process.cwd());
code = `window.__oneProjectRoot="${projectName}";
${code}
${devtools}
${sourceInspector}`;
}
res.setHeader("Content-Type", "application/javascript");
res.setHeader("Cache-Control", "no-store");
res.end(code);
return;
} catch (e) {
console.error("[one] Failed to load devtools script:", e);
}
res.setHeader("Content-Type", "application/javascript");
res.end("// devtools failed to load");
return;
}
next();
});
}
};
}