UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

1 lines • 3.51 kB
{"version":3,"file":"devtoolsPlugin.js","names":[],"sources":["esm/vite/plugins/devtoolsPlugin.js"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { resolvePath } from \"@vxrn/resolve\";\nconst DEVTOOLS_VIRTUAL_ID = \"/@one/dev.js\";\nfunction createDevtoolsPlugin(options = {}) {\n const { includeUI = true } = options;\n return {\n name: \"one-devtools\",\n apply: \"serve\",\n // only in dev\n configureServer(server) {\n const isBundledDev = !!server.config.experimental?.bundledDev;\n server.middlewares.use(async (req, res, next) => {\n if (req.url === DEVTOOLS_VIRTUAL_ID) {\n try {\n const devEntryPath = resolvePath(\"one/devtools/dev.mjs\");\n const devEntry = readFileSync(devEntryPath, \"utf-8\");\n let code = devEntry.replace(\"import './devtools.mjs'\", \"\").replace(\"import './source-inspector.mjs'\", \"\");\n if (isBundledDev) {\n code = code.replace(\n \"import { createHotContext } from '/@vite/client'\",\n \"const createHotContext = () => ({ on() {}, off() {}, accept() {}, dispose() {}, prune() {}, send() {}, invalidate() {} })\"\n ).replace(\n \"import { injectIntoGlobalHook } from '/@react-refresh'\",\n \"const injectIntoGlobalHook = () => {}\"\n );\n }\n if (includeUI) {\n const devtoolsPath = resolvePath(\"one/devtools/devtools.mjs\");\n const sourceInspectorPath = resolvePath(\"one/devtools/source-inspector.mjs\");\n const devtools = readFileSync(devtoolsPath, \"utf-8\");\n const sourceInspector = readFileSync(sourceInspectorPath, \"utf-8\");\n const projectName = path.basename(process.cwd());\n code = `window.__oneProjectRoot=\"${projectName}\";\n${code}\n${devtools}\n${sourceInspector}`;\n }\n res.setHeader(\"Content-Type\", \"application/javascript\");\n res.setHeader(\"Cache-Control\", \"no-store\");\n res.end(code);\n return;\n } catch (e) {\n console.error(\"[one] Failed to load devtools script:\", e);\n }\n res.setHeader(\"Content-Type\", \"application/javascript\");\n res.end(\"// devtools failed to load\");\n return;\n }\n next();\n });\n }\n };\n}\nexport {\n DEVTOOLS_VIRTUAL_ID,\n createDevtoolsPlugin\n};\n//# sourceMappingURL=devtoolsPlugin.js.map\n"],"mappings":";;;;;AAGA,MAAM,sBAAsB;AAC5B,SAAS,qBAAqB,UAAU,CAAC,GAAG;CAC1C,MAAM,EAAE,YAAY,SAAS;CAC7B,OAAO;EACL,MAAM;EACN,OAAO;EAEP,gBAAgB,QAAQ;GACtB,MAAM,eAAe,CAAC,CAAC,OAAO,OAAO,cAAc;GACnD,OAAO,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;IAC/C,IAAI,IAAI,wBAA6B;KACnC,IAAI;MACF,MAAM,eAAe,YAAY,sBAAsB;MACvD,MAAM,WAAW,aAAa,cAAc,OAAO;MACnD,IAAI,OAAO,SAAS,QAAQ,2BAA2B,EAAE,CAAC,CAAC,QAAQ,mCAAmC,EAAE;MACxG,IAAI,cAAc;OAChB,OAAO,KAAK,QACV,oDACA,2HACF,CAAC,CAAC,QACA,0DACA,uCACF;MACF;MACA,IAAI,WAAW;OACb,MAAM,eAAe,YAAY,2BAA2B;OAC5D,MAAM,sBAAsB,YAAY,mCAAmC;OAC3E,MAAM,WAAW,aAAa,cAAc,OAAO;OACnD,MAAM,kBAAkB,aAAa,qBAAqB,OAAO;OACjE,MAAM,cAAc,KAAK,SAAS,QAAQ,IAAI,CAAC;OAC/C,OAAO,4BAA4B,YAAY;EAC3D,KAAK;EACL,SAAS;EACT;MACU;MACA,IAAI,UAAU,gBAAgB,wBAAwB;MACtD,IAAI,UAAU,iBAAiB,UAAU;MACzC,IAAI,IAAI,IAAI;MACZ;KACF,SAAS,GAAG;MACV,QAAQ,MAAM,yCAAyC,CAAC;KAC1D;KACA,IAAI,UAAU,gBAAgB,wBAAwB;KACtD,IAAI,IAAI,4BAA4B;KACpC;IACF;IACA,KAAK;GACP,CAAC;EACH;CACF;AACF"}