UNPKG

one

Version:

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

90 lines (88 loc) 3.59 kB
"use strict"; 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_fs = require("fs"); var import_path = __toESM(require("path"), 1); var import_resolve = require("@vxrn/resolve"); var DEVTOOLS_VIRTUAL_ID = "/@one/dev.js"; function createDevtoolsPlugin() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; var { includeUI = true } = options; return { name: "one-devtools", apply: "serve", // only in dev configureServer(server) { server.middlewares.use(async function (req, res, next) { if (req.url === DEVTOOLS_VIRTUAL_ID) { try { var devEntryPath = (0, import_resolve.resolvePath)("one/devtools/dev.mjs"); var devEntry = (0, import_fs.readFileSync)(devEntryPath, "utf-8"); var code = devEntry.replace("import './devtools.mjs'", "").replace("import './source-inspector.mjs'", ""); if (includeUI) { var devtoolsPath = (0, import_resolve.resolvePath)("one/devtools/devtools.mjs"); var sourceInspectorPath = (0, import_resolve.resolvePath)("one/devtools/source-inspector.mjs"); var devtools = (0, import_fs.readFileSync)(devtoolsPath, "utf-8"); var sourceInspector = (0, import_fs.readFileSync)(sourceInspectorPath, "utf-8"); var projectName = import_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(); }); } }; } //# sourceMappingURL=devtoolsPlugin.native.js.map