@amaster.ai/vite-plugins 1.0.0-beta.12 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var crypto=require('crypto'),g=require('fs'),b=require('path'),url=require('url'),H=require('process');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var b__default=/*#__PURE__*/_interopDefault(b);var H__default=/*#__PURE__*/_interopDefault(H);function _(t,e){let n=`${t}:${e}`;return crypto.createHash("md5").update(n).digest("hex").substring(0,12)}var T=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function m(){let t=false;return {name:"vite-plugin-component-id",enforce:"pre",configResolved(e){t=e.command==="serve";},transform(e,n){if(!t||!/\.(tsx|jsx)$/.test(n)||n.includes("node_modules")||!/<[a-z]/.test(e))return null;try{let r=e,o=/<([a-z][\da-z]*)(?=[\s/>])/g,a,i=[];for(;(a=o.exec(e))!==null;){let s=a[1];if(!s)continue;let d=a.index,c=a.index+a[0].length;if(!T.has(s))continue;let u=c,p=!1,f=!1;for(;u<e.length&&!p;)e[u]===">"&&(p=!0,e.substring(d,u).includes("data-node-component-id")&&(f=!0)),u++;f||i.push({index:d,tag:s,tagEndIndex:c});}let l=e;for(let s=i.length-1;s>=0;s--){let d=i[s];if(!d)continue;let{index:c,tagEndIndex:u}=d,p=_(n,c),f=l.substring(0,u),y=l.substring(u);r=`${f} data-node-component-id="${p}"${y}`,l=r;}return {code:r,map:null}}catch{return null}}}}var E=`<script>
1
+ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var crypto=require('crypto'),g=require('fs'),b=require('path'),url=require('url'),P=require('process');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var g__default=/*#__PURE__*/_interopDefault(g);var b__default=/*#__PURE__*/_interopDefault(b);var P__default=/*#__PURE__*/_interopDefault(P);function w(r,e){let n=`${r}:${e}`;return crypto.createHash("md5").update(n).digest("hex").substring(0,12)}var T=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function m(){let r=false;return {name:"vite-plugin-component-id",enforce:"pre",configResolved(e){r=e.command==="serve";},transform(e,n){if(!r||!/\.(tsx|jsx)$/.test(n)||n.includes("node_modules")||!/<[a-z]/.test(e))return null;try{let t=e,o=/<([a-z][\da-z]*)(?=[\s/>])/g,a,s=[];for(;(a=o.exec(e))!==null;){let i=a[1];if(!i)continue;let d=a.index,c=a.index+a[0].length;if(!T.has(i))continue;let l=c,p=!1,f=!1;for(;l<e.length&&!p;)e[l]===">"&&(p=!0,e.substring(d,l).includes("data-node-component-id")&&(f=!0)),l++;f||s.push({index:d,tag:i,tagEndIndex:c});}let u=e;for(let i=s.length-1;i>=0;i--){let d=s[i];if(!d)continue;let{index:c,tagEndIndex:l}=d,p=w(n,c),f=u.substring(0,l),y=u.substring(l);t=`${f} data-node-component-id="${p}"${y}`,u=t;}return {code:t,map:null}}catch{return null}}}}var I=`<script>
2
2
  document.addEventListener("click", (e) => {
3
3
  const element = e.target;
4
4
  const noJumpOut = document.body.classList.contains("forbid-jump-out")
@@ -16,15 +16,15 @@ document.addEventListener("click", (e) => {
16
16
  e.preventDefault();
17
17
  }
18
18
  });
19
- </script>`;function I(){try{let t=url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),e=b.dirname(t),n=b.resolve(e,"../dist/bridge.bridge.js");return `<script>
19
+ </script>`;function q(){try{let r=url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))),e=b.dirname(r),n=b.resolve(e,"../dist/bridge.bridge.js");return `<script>
20
20
  ${g.readFileSync(n,"utf-8")}
21
- </script>`}catch(t){return console.warn("Failed to read bridge script:",t),""}}function h(){let t=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){t=n.command==="serve",t&&(e=I());},transformIndexHtml(n){let o=`${E}${t?e:""}</body>`;return n.replace("</body>",o)}}}function v(t){let e=false,n=t?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(r){e=r.command==="serve";},transform(r,o){if(!e||!o.endsWith(n))return null;try{return r.includes("window.__APP_ROUTES__")?null:{code:`${r}
21
+ </script>`}catch(r){return console.warn("Failed to read bridge script:",r),""}}function h(){let r=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){r=n.command==="serve",r&&(e=q());},transformIndexHtml(n){let o=`${I}${r?e:""}</body>`;return n.replace("</body>",o)}}}function v(r){let e=false,n=r?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(t){e=t.command==="serve";},transform(t,o){if(!e||!o.endsWith(n))return null;try{return t.includes("window.__APP_ROUTES__")?null:{code:`${t}
22
22
 
23
23
  // Development mode: Expose routes to window.__APP_ROUTES__
24
24
  if (typeof window !== 'undefined') {
25
25
  window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
26
26
  }
27
- `,map:null}}catch{return null}}}}function w(){let t="",e=`
27
+ `,map:null}}catch{return null}}}}function _(){let r="",e=`
28
28
  <script>
29
29
  (function() {
30
30
  'use strict';
@@ -600,6 +600,6 @@ if (typeof window !== 'undefined') {
600
600
 
601
601
  originalConsole.log('[BrowserLogs] Log collection started');
602
602
  })();
603
- </script>`;return {name:"vite-plugin-browser-logs",configResolved(n){let r=n.root||H__default.default.cwd();t=b__default.default.join(r,"browser.log");},configureServer(n){n.middlewares.use((r,o,a)=>{if(r.url==="/__browser__"&&r.method==="POST"){let i=r.headers.origin||"*",l="";r.on("data",s=>{l+=s.toString();}),r.on("end",()=>{try{let s=b__default.default.dirname(t);g__default.default.existsSync(s)||g__default.default.mkdirSync(s,{recursive:!0}),g__default.default.appendFileSync(t,`${l}
604
- `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(s){console.error("[BrowserLogs] Write error:",s),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(s)}));}});}else if(r.url==="/__browser__"&&r.method==="OPTIONS"){let i=r.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(r.url==="/__browser__"){let i=r.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":i}),o.end(JSON.stringify({error:"Method not allowed"}));}else a();}),console.log("[BrowserLogs] Logs will be written to:",t);},transformIndexHtml(n){return n.replace(/<head([^>]*)>/i,`<head$1>${e}`)}}}function L(t={}){let e=[m(),h(),v()];return H__default.default.env.WORKSPACE_GIT_REPO&&e.push(w()),e}exports.componentIdPlugin=m;exports.default=L;exports.editorBridgePlugin=h;exports.routesExposePlugin=v;//# sourceMappingURL=index.cjs.map
603
+ </script>`;return {name:"vite-plugin-browser-logs",configResolved(n){let t=n.root||P__default.default.cwd();r=b__default.default.join(t,"browser.log");},configureServer(n){n.middlewares.use((t,o,a)=>{if(t.url==="/__browser__"&&t.method==="POST"){let s=t.headers.origin||"*",u="";t.on("data",i=>{u+=i.toString();}),t.on("end",()=>{try{let i=b__default.default.dirname(r);g__default.default.existsSync(i)||g__default.default.mkdirSync(i,{recursive:!0}),g__default.default.appendFileSync(r,`${u}
604
+ `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":s,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(i){console.error("[BrowserLogs] Write error:",i),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":s,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(i)}));}});}else if(t.url==="/__browser__"&&t.method==="OPTIONS"){let s=t.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":s,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(t.url==="/__browser__"){let s=t.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":s}),o.end(JSON.stringify({error:"Method not allowed"}));}else a();}),console.log("[BrowserLogs] Logs will be written to:",r);},transformIndexHtml(n){return n.replace(/<head([^>]*)>/i,`<head$1>${e}`)}}}function L(r={}){let{additional:e=[],autoInjectTaroApp:n=true,autoInjectVite:t=true}=r,o={},a=new Set(e);return n&&Object.keys(process.env).forEach(s=>{s.startsWith("TARO_APP_")&&a.add(s);}),t&&Object.keys(process.env).forEach(s=>{s.startsWith("VITE_")&&a.add(s);}),a.forEach(s=>{let u=process.env[s]||"";o[`process.env.${s}`]=JSON.stringify(u);}),o}function R(){return {"process.env.TARO_APP_API_BASE_URL":JSON.stringify(process.env.TARO_APP_API_BASE_URL||""),"process.env.VITE_API_BASE_URL":JSON.stringify(process.env.VITE_API_BASE_URL||"")}}function k(r={}){let e=[m(),h(),v()];return P__default.default.env.WORKSPACE_GIT_REPO&&e.push(_()),e}exports.componentIdPlugin=m;exports.default=k;exports.editorBridgePlugin=h;exports.injectAmasterEnv=R;exports.injectTaroEnv=L;exports.routesExposePlugin=v;//# sourceMappingURL=index.cjs.map
605
605
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component-id.ts","../src/editor-bridge.ts","../src/routes-expose.ts","../src/browser-logs.ts","../src/index.ts"],"names":["generateUniqueId","filePath","position","key","createHash","HTML_TAGS","componentIdPlugin","isDev","config","code","id","transformedCode","jsxOpenTagRegex","match","matches","tag","tagStartIndex","tagEndIndex","checkIndex","foundClosing","hasComponentId","currentCode","i","item","index","uniqueId","before","after","clickHandlerScript","getBridgeScriptContent","__filename","fileURLToPath","__dirname","dirname","bridgePath","resolve","readFileSync","error","editorBridgePlugin","bridgeScript","html","scriptsToInject","routesExposePlugin","options","routesPath","browserLogsPlugin","logFilePath","injectedScript","root","process","path","devServer","req","res","next","origin","body","chunk","logDir","fs","devTools","_options","plugins"],"mapp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AIO,kBAAAA,CAAQ,IAAI,kBAAA,EACZa,CAAAA,CAAQ,KAAKjB,CAAAA,EAAmB,EAG7BiB,CACX","file":"index.cjs","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Plugin } from \"vite\";\n\nfunction generateUniqueId(filePath: string, position: number): string {\n const key = `${filePath}:${position}`;\n return createHash(\"md5\").update(key).digest(\"hex\").substring(0, 12);\n}\n\nconst HTML_TAGS = new Set([\n \"a\", \"abbr\", \"address\", \"area\", \"article\", \"aside\", \"audio\", \"b\", \"base\", \"bdi\", \"bdo\",\n \"blockquote\", \"body\", \"br\", \"button\", \"canvas\", \"caption\", \"cite\", \"code\", \"col\",\n \"colgroup\", \"data\", \"datalist\", \"dd\", \"del\", \"details\", \"dfn\", \"dialog\", \"div\", \"dl\",\n \"dt\", \"em\", \"embed\", \"fieldset\", \"figcaption\", \"figure\", \"footer\", \"form\", \"h1\", \"h2\",\n \"h3\", \"h4\", \"h5\", \"h6\", \"head\", \"header\", \"hgroup\", \"hr\", \"html\", \"i\", \"iframe\", \"img\",\n \"input\", \"ins\", \"kbd\", \"label\", \"legend\", \"li\", \"link\", \"main\", \"map\", \"mark\", \"meta\",\n \"meter\", \"nav\", \"noscript\", \"object\", \"ol\", \"optgroup\", \"option\", \"output\", \"p\", \"param\",\n \"picture\", \"pre\", \"progress\", \"q\", \"rp\", \"rt\", \"ruby\", \"s\", \"samp\", \"script\", \"section\",\n \"select\", \"small\", \"source\", \"span\", \"strong\", \"style\", \"sub\", \"summary\", \"sup\", \"svg\",\n \"table\", \"tbody\", \"td\", \"template\", \"textarea\", \"tfoot\", \"th\", \"thead\", \"time\", \"title\",\n \"tr\", \"track\", \"u\", \"ul\", \"var\", \"video\", \"wbr\",\n]);\n\n/**\n * Vite plugin: Add data-node-component-id to React components\n * Only enabled in development mode\n */\nexport function componentIdPlugin(): Plugin {\n let isDev = false;\n\n return {\n name: \"vite-plugin-component-id\",\n enforce: \"pre\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!/\\.(tsx|jsx)$/.test(id)) {\n return null;\n }\n\n if (id.includes(\"node_modules\")) {\n return null;\n }\n\n if (!/<[a-z]/.test(code)) {\n return null;\n }\n\n try {\n let transformedCode = code;\n const jsxOpenTagRegex = /<([a-z][\\da-z]*)(?=[\\s/>])/g;\n\n let match: RegExpExecArray | null;\n const matches: Array<{ index: number; tag: string; tagEndIndex: number }> = [];\n\n while ((match = jsxOpenTagRegex.exec(code)) !== null) {\n const tag = match[1];\n if (!tag) continue;\n \n const tagStartIndex = match.index;\n const tagEndIndex = match.index + match[0].length;\n\n if (!HTML_TAGS.has(tag)) {\n continue;\n }\n\n let checkIndex = tagEndIndex;\n let foundClosing = false;\n let hasComponentId = false;\n\n while (checkIndex < code.length && !foundClosing) {\n const char = code[checkIndex];\n if (char === \">\") {\n foundClosing = true;\n const tagContent = code.substring(tagStartIndex, checkIndex);\n if (tagContent.includes(\"data-node-component-id\")) {\n hasComponentId = true;\n }\n }\n checkIndex++;\n }\n\n if (hasComponentId) {\n continue;\n }\n\n matches.push({\n index: tagStartIndex,\n tag,\n tagEndIndex,\n });\n }\n\n let currentCode = code;\n for (let i = matches.length - 1; i >= 0; i--) {\n const item = matches[i];\n if (!item) continue;\n \n const { index, tagEndIndex } = item;\n const uniqueId = generateUniqueId(id, index);\n\n const before = currentCode.substring(0, tagEndIndex);\n const after = currentCode.substring(tagEndIndex);\n\n transformedCode = `${before} data-node-component-id=\"${uniqueId}\"${after}`;\n currentCode = transformedCode;\n }\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { readFileSync } from \"fs\";\nimport { resolve, dirname } from \"path\";\nimport { fileURLToPath } from \"url\";\n\nconst clickHandlerScript = `<script>\ndocument.addEventListener(\"click\", (e) => {\n const element = e.target;\n const noJumpOut = document.body.classList.contains(\"forbid-jump-out\")\n if (element.hasAttribute(\"data-link-href\") && !noJumpOut) {\n const href = element.getAttribute(\"data-link-href\");\n const target = element.getAttribute(\"data-link-target\");\n if (href) {\n if (target === \"_blank\") {\n window.open(href, \"_blank\");\n } else {\n window.location.href = href;\n }\n }\n } else if(noJumpOut && element.tagName === \"A\") {\n e.preventDefault();\n }\n});\n</script>`;\n\n/**\n * 读取构建后的 bridge 脚本内容\n */\nfunction getBridgeScriptContent(): string {\n try {\n // 获取当前模块的目录\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n \n // 读取构建后的 bridge.bridge.js 文件\n const bridgePath = resolve(__dirname, \"../dist/bridge.bridge.js\");\n const bridgeContent = readFileSync(bridgePath, \"utf-8\");\n \n return `<script>\\n${bridgeContent}\\n</script>`;\n } catch (error) {\n console.warn(\"Failed to read bridge script:\", error);\n return \"\";\n }\n}\n\n/**\n * Vite plugin: Inject editor bridge script\n * Injects bridge.js in development mode by reading the built bridge script\n */\nexport function editorBridgePlugin(): Plugin {\n let isDev = false;\n let bridgeScript = \"\";\n\n return {\n name: \"vite-plugin-editor-bridge\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n \n // 在开发模式下读取 bridge 脚本内容\n if (isDev) {\n bridgeScript = getBridgeScriptContent();\n }\n },\n\n transformIndexHtml(html) {\n // 在开发模式下注入 bridge 脚本\n const devScript = isDev ? bridgeScript : \"\";\n\n const scriptsToInject = `${clickHandlerScript}${devScript}</body>`;\n\n return html.replace(\"</body>\", scriptsToInject);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Vite plugin: Expose routes to window.__APP_ROUTES__\n * Only enabled in development mode\n */\nexport function routesExposePlugin(options?: { routesFilePath?: string }): Plugin {\n let isDev = false;\n const routesPath = options?.routesFilePath || \"src/routes.tsx\";\n\n return {\n name: \"vite-plugin-routes-expose\",\n enforce: \"post\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!id.endsWith(routesPath)) {\n return null;\n }\n\n try {\n if (code.includes(\"window.__APP_ROUTES__\")) {\n return null;\n }\n\n const transformedCode = `${code}\n\n// Development mode: Expose routes to window.__APP_ROUTES__\nif (typeof window !== 'undefined') {\n window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];\n}\n`;\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\n/**\n * Browser logs collection plugin\n * Injects script into HTML head to collect console logs and network requests\n * Logs are written directly to browser.log file (same level as index.html)\n */\nexport function browserLogsPlugin(): Plugin {\n let logFilePath = \"\";\n\n // Script to inject into browser\n const injectedScript = `\n<script>\n(function() {\n 'use strict';\n \n // Log API path (provided by Vite dev server)\n var LOG_API_PATH = '/__browser__';\n \n // Write queue to ensure sequential writes\n var writeQueue = [];\n var isWriting = false;\n \n // Process write queue to ensure sequential writes\n function processWriteQueue() {\n if (isWriting || writeQueue.length === 0) return;\n \n isWriting = true;\n var entry = writeQueue.shift();\n var logText = JSON.stringify(entry);\n \n fetch(LOG_API_PATH, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: logText\n })\n .then(function(response) {\n isWriting = false;\n if (!response.ok) {\n console.warn('[BrowserLogs] Failed to write log:', response.status);\n }\n // Continue processing next item in queue\n processWriteQueue();\n })\n .catch(function(error) {\n console.warn('[BrowserLogs] Failed to write log:', error.message);\n // On failure, put log back to queue head for retry\n writeQueue.unshift(entry);\n isWriting = false;\n // Retry after delay\n setTimeout(processWriteQueue, 1000);\n });\n }\n \n // Limit headers object size\n function truncateHeaders(headers) {\n if (!headers) return headers;\n var jsonStr = JSON.stringify(headers);\n if (jsonStr.length <= MAX_HEADER_SIZE) return headers;\n return '[Headers truncated, size: ' + jsonStr.length + ']';\n }\n \n // Truncate oversized log entries\n function truncateLogEntry(entry) {\n var jsonStr = JSON.stringify(entry);\n if (jsonStr.length <= MAX_LOG_ENTRY_SIZE) {\n return entry;\n }\n \n // If oversized, progressively truncate non-critical fields\n var truncated = Object.assign({}, entry);\n \n // 1. Truncate response body first\n if (truncated.responseBody && typeof truncated.responseBody === 'string') {\n truncated.responseBody = truncated.responseBody.substring(0, 500) + '... [truncated]';\n }\n \n // 2. Truncate request body\n if (truncated.requestBody && typeof truncated.requestBody === 'string') {\n truncated.requestBody = truncated.requestBody.substring(0, 500) + '... [truncated]';\n }\n \n // 3. Truncate message\n if (truncated.message && typeof truncated.message === 'string' && truncated.message.length > 1000) {\n truncated.message = truncated.message.substring(0, 1000) + '... [truncated]';\n }\n \n // 4. Truncate stack\n if (truncated.stack && Array.isArray(truncated.stack) && truncated.stack.length > 3) {\n truncated.stack = truncated.stack.slice(0, 3);\n }\n \n // Add truncation marker\n truncated._truncated = true;\n truncated._originalSize = jsonStr.length;\n \n return truncated;\n }\n \n // Add log and send immediately (ensure order)\n function addLog(entry) {\n var truncatedEntry = truncateLogEntry(entry);\n writeQueue.push(truncatedEntry);\n processWriteQueue();\n }\n \n // ============================================\n // Console log collection\n // ============================================\n var originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n debug: console.debug\n };\n \n function getStackTrace() {\n var stack = new Error().stack || '';\n var lines = stack.split('\\\\n').slice(3);\n // Limit stack lines\n return lines.slice(0, MAX_STACK_LINES).map(function(line) { return line.trim(); });\n }\n \n function formatMessage(args) {\n return Array.from(args).map(function(arg) {\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n if (typeof arg === 'object') {\n try {\n return JSON.stringify(arg);\n } catch (e) {\n return String(arg);\n }\n }\n return String(arg);\n }).join(' ');\n }\n \n function createLogEntry(level, args) {\n return {\n type: 'console',\n timestamp: new Date().toISOString(),\n level: level,\n message: formatMessage(args),\n stack: getStackTrace()\n };\n }\n \n // Check if message should be filtered (contains [vite] text)\n function shouldFilterConsoleLog(args) {\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n if (typeof arg === 'string' && arg.indexOf('[vite]') !== -1) {\n return true;\n }\n }\n return false;\n }\n \n function wrapConsoleMethod(method, level) {\n return function() {\n var args = arguments;\n // Filter out logs containing [vite]\n if (shouldFilterConsoleLog(args)) {\n return originalConsole[method].apply(console, args);\n }\n var entry = createLogEntry(level, args);\n addLog(entry);\n return originalConsole[method].apply(console, args);\n };\n }\n \n console.log = wrapConsoleMethod('log', 'log');\n console.info = wrapConsoleMethod('info', 'info');\n console.warn = wrapConsoleMethod('warn', 'warn');\n console.error = wrapConsoleMethod('error', 'error');\n console.debug = wrapConsoleMethod('debug', 'debug');\n \n // ============================================\n // Network request collection (exclude SSE and log API requests)\n // ============================================\n \n var MAX_BODY_SIZE = 2000;\n var MAX_LOG_ENTRY_SIZE = 3000; // Max single log entry length\n var MAX_HEADER_SIZE = 500; // Max single header object length\n var MAX_STACK_LINES = 5; // Max stack lines to keep\n const FILTERED_URLS = ['/__browser__', '/builtin']; // Filter out log API and Vite built-in requests\n \n function isSSERequest(url, headers) {\n var sseUrlPatterns = ['/events', '/sse', '/stream', 'text/event-stream'];\n var urlStr = String(url).toLowerCase();\n for (var i = 0; i < sseUrlPatterns.length; i++) {\n if (urlStr.indexOf(sseUrlPatterns[i]) !== -1) {\n return true;\n }\n }\n \n if (headers) {\n if (typeof headers.get === 'function') {\n var accept = headers.get('Accept') || headers.get('accept');\n if (accept && accept.indexOf('text/event-stream') !== -1) {\n return true;\n }\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n if (key.toLowerCase() === 'accept' && headers[key].indexOf('text/event-stream') !== -1) {\n return true;\n }\n }\n }\n }\n \n return false;\n }\n \n function shouldFilterRequest(url) {\n return FILTERED_URLS.some(function(filteredUrl) {\n return String(url).indexOf(filteredUrl) !== -1;\n });\n }\n \n function formatRequestBody(body) {\n if (!body) return null;\n \n try {\n if (typeof body === 'string') {\n return body.substring(0, MAX_BODY_SIZE);\n }\n if (body instanceof FormData) {\n var formDataObj = {};\n body.forEach(function(value, key) {\n if (value instanceof File) {\n formDataObj[key] = '[File: ' + value.name + ', size: ' + value.size + ']';\n } else {\n formDataObj[key] = String(value).substring(0, 1000);\n }\n });\n return JSON.stringify(formDataObj);\n }\n if (body instanceof Blob) {\n return '[Blob: size=' + body.size + ', type=' + body.type + ']';\n }\n if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {\n return '[Binary: size=' + body.byteLength + ']';\n }\n if (body instanceof URLSearchParams) {\n return body.toString().substring(0, MAX_BODY_SIZE);\n }\n return String(body).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading body: ' + e.message + ']';\n }\n }\n \n function formatResponseBody(response, responseType) {\n if (!response) return null;\n \n try {\n if (responseType === '' || responseType === 'text') {\n return String(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'json') {\n return JSON.stringify(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'document') {\n return '[Document]';\n }\n if (responseType === 'blob') {\n return '[Blob: size=' + response.size + ']';\n }\n if (responseType === 'arraybuffer') {\n return '[ArrayBuffer: size=' + response.byteLength + ']';\n }\n return String(response).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading response: ' + e.message + ']';\n }\n }\n \n // Intercept XMLHttpRequest\n var originalXHROpen = XMLHttpRequest.prototype.open;\n var originalXHRSend = XMLHttpRequest.prototype.send;\n var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;\n \n XMLHttpRequest.prototype.open = function(method, url, async, user, password) {\n this.__requestInfo__ = {\n method: method,\n url: url,\n startTime: null,\n headers: {}\n };\n return originalXHROpen.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.setRequestHeader = function(name, value) {\n if (this.__requestInfo__ && this.__requestInfo__.headers) {\n this.__requestInfo__.headers[name] = value;\n }\n return originalXHRSetRequestHeader.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.send = function(body) {\n var xhr = this;\n var requestInfo = xhr.__requestInfo__;\n \n if (requestInfo) {\n // Skip SSE requests and filtered requests\n if (isSSERequest(requestInfo.url, requestInfo.headers) || shouldFilterRequest(requestInfo.url)) {\n return originalXHRSend.apply(this, arguments);\n }\n \n requestInfo.startTime = Date.now();\n requestInfo.requestBody = formatRequestBody(body);\n \n xhr.addEventListener('loadend', function() {\n var contentType = xhr.getResponseHeader('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return;\n }\n \n var responseHeaders = {};\n var allHeaders = xhr.getAllResponseHeaders();\n if (allHeaders) {\n allHeaders.split('\\\\r\\\\n').forEach(function(line) {\n var parts = line.split(': ');\n if (parts.length === 2) {\n responseHeaders[parts[0]] = parts[1];\n }\n });\n }\n \n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'xhr',\n method: requestInfo.method,\n url: requestInfo.url,\n status: xhr.status,\n statusText: xhr.statusText,\n duration: Date.now() - requestInfo.startTime,\n requestHeaders: truncateHeaders(requestInfo.headers),\n requestBody: requestInfo.requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseType: xhr.responseType,\n responseBody: formatResponseBody(xhr.response, xhr.responseType),\n responseSize: xhr.response ? (typeof xhr.response === 'string' ? xhr.response.length : (xhr.response.byteLength || xhr.response.size || null)) : null\n };\n \n addLog(entry);\n });\n }\n \n return originalXHRSend.apply(this, arguments);\n };\n \n // Intercept Fetch API\n var originalFetch = window.fetch;\n \n function headersToObject(headers) {\n var obj = {};\n if (!headers) return obj;\n \n if (typeof headers.forEach === 'function') {\n headers.forEach(function(value, key) {\n obj[key] = value;\n });\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n obj[key] = headers[key];\n }\n }\n return obj;\n }\n \n window.fetch = function(input, init) {\n var startTime = Date.now();\n var method = (init && init.method) || 'GET';\n var url = typeof input === 'string' ? input : input.url;\n var headers = init && init.headers;\n \n // Skip SSE requests and filtered requests\n if (isSSERequest(url, headers) || shouldFilterRequest(url)) {\n return originalFetch.apply(this, arguments);\n }\n \n var requestHeaders = headersToObject(headers);\n var requestBody = formatRequestBody(init && init.body);\n \n return originalFetch.apply(this, arguments)\n .then(function(response) {\n var contentType = response.headers.get('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return response;\n }\n \n var clonedResponse = response.clone();\n var responseHeaders = headersToObject(response.headers);\n \n clonedResponse.text().then(function(bodyText) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: bodyText ? bodyText.substring(0, MAX_BODY_SIZE) : null,\n responseSize: bodyText ? bodyText.length : null,\n ok: response.ok\n };\n \n addLog(entry);\n }).catch(function(e) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: '[Unable to read: ' + e.message + ']',\n responseSize: null,\n ok: response.ok\n };\n \n addLog(entry);\n });\n \n return response;\n })\n .catch(function(error) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: 0,\n statusText: 'Network Error',\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: null,\n responseBody: null,\n error: error.message\n };\n \n addLog(entry);\n throw error;\n });\n };\n \n // ============================================\n // Global error capture\n // ============================================\n window.addEventListener('error', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: event.message,\n stack: event.error ? event.error.stack : 'at ' + event.filename + ':' + event.lineno + ':' + event.colno\n };\n addLog(entry);\n });\n \n // ============================================\n // Vite deps 504 error capture using PerformanceObserver\n // Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)\n // ============================================\n if (typeof PerformanceObserver !== 'undefined') {\n var reportedUrls = {}; // Track reported URLs to avoid duplicates\n \n var perfObserver = new PerformanceObserver(function(list) {\n var entries = list.getEntries();\n for (var i = 0; i < entries.length; i++) {\n var perfEntry = entries[i];\n // Only check script resources\n if (perfEntry.initiatorType !== 'script') {\n continue;\n }\n \n var resourceUrl = perfEntry.name || '';\n // Only report errors for node_modules/.vite resources\n if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {\n continue;\n }\n \n // Check if response status is 504 (Gateway Timeout)\n // responseStatus is available in Resource Timing Level 2\n var status = perfEntry.responseStatus;\n if (status === 504) {\n // Avoid duplicate reports\n if (reportedUrls[resourceUrl]) {\n continue;\n }\n reportedUrls[resourceUrl] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: resourceUrl,\n status: 504,\n message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,\n duration: perfEntry.duration,\n transferSize: perfEntry.transferSize\n };\n addLog(entry);\n }\n }\n });\n \n try {\n perfObserver.observe({ type: 'resource', buffered: true });\n } catch (e) {\n // Fallback for browsers that don't support the options\n try {\n perfObserver.observe({ entryTypes: ['resource'] });\n } catch (e2) {\n originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);\n }\n }\n }\n \n window.addEventListener('unhandledrejection', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: 'Unhandled Promise Rejection: ' + (event.reason ? (event.reason.message || String(event.reason)) : 'Unknown'),\n stack: event.reason && event.reason.stack ? event.reason.stack : ''\n };\n addLog(entry);\n });\n \n // ============================================\n // Send remaining logs on page unload\n // ============================================\n window.addEventListener('beforeunload', function() {\n if (writeQueue.length > 0) {\n // Use sendBeacon to ensure logs are sent\n writeQueue.forEach(function(entry) {\n navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));\n });\n writeQueue = [];\n }\n });\n \n // ============================================\n // Provide manual flush method\n // ============================================\n window.__flushBrowserLogs__ = function() {\n return new Promise(function(resolve) {\n // Wait for queue to finish processing\n function checkQueue() {\n if (writeQueue.length === 0 && !isWriting) {\n resolve();\n } else {\n setTimeout(checkQueue, 100);\n }\n }\n checkQueue();\n });\n };\n \n // Provide method to get queue status\n window.__getBrowserLogsStatus__ = function() {\n return {\n queueLength: writeQueue.length,\n isWriting: isWriting\n };\n };\n \n originalConsole.log('[BrowserLogs] Log collection started');\n})();\n</script>`;\n\n return {\n name: \"vite-plugin-browser-logs\",\n\n configResolved(config) {\n // Determine log file path: same level as index.html\n const root = config.root || process.cwd();\n logFilePath = path.join(root, \"browser.log\");\n },\n\n configureServer(devServer) {\n // Add log write API\n devServer.middlewares.use((req, res, next) => {\n if (req.url === \"/__browser__\" && req.method === \"POST\") {\n // Get request origin, dynamically set CORS headers to avoid protocol mismatch\n const origin = req.headers.origin || \"*\";\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString();\n });\n req.on(\"end\", () => {\n try {\n // Ensure log directory exists\n const logDir = path.dirname(logFilePath);\n if (!fs.existsSync(logDir)) {\n fs.mkdirSync(logDir, { recursive: true });\n }\n // Append to log file\n fs.appendFileSync(logFilePath, `${body}\\n`, \"utf-8\");\n res.writeHead(200, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: true }));\n } catch (error) {\n console.error(\"[BrowserLogs] Write error:\", error);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: false, error: String(error) }));\n }\n });\n } else if (req.url === \"/__browser__\" && req.method === \"OPTIONS\") {\n // Handle CORS preflight request\n const origin = req.headers.origin || \"*\";\n res.writeHead(204, {\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Max-Age\": \"86400\",\n });\n res.end();\n } else if (req.url === \"/__browser__\") {\n const origin = req.headers.origin || \"*\";\n res.writeHead(405, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n });\n res.end(JSON.stringify({ error: \"Method not allowed\" }));\n } else {\n next();\n }\n });\n\n console.log(\"[BrowserLogs] Logs will be written to:\", logFilePath);\n },\n\n transformIndexHtml(html) {\n // Insert script after <head> tag to ensure earliest execution\n return html.replace(/<head([^>]*)>/i, `<head$1>${injectedScript}`);\n },\n };\n}\n","import { componentIdPlugin } from \"./component-id\";\nimport { editorBridgePlugin } from \"./editor-bridge\";\nimport { routesExposePlugin } from \"./routes-expose\";\nimport { browserLogsPlugin } from \"./browser-logs\";\nimport process from \"node:process\";\nimport type { Plugin } from \"vite\";\n\n// 预留配置项目,目前没有可配置的\nexport interface DevToolsOptions {\n // 未来可添加配置项\n}\n\n/**\n * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可\n * @param _options 预留参数,用于未来扩展配置(例如可选择性启用某些插件)\n * @returns Plugin[] Vite 插件数组\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\nexport default function devTools(_options: DevToolsOptions = {}): Plugin[] {\n const plugins: Plugin[] = [\n componentIdPlugin(),\n editorBridgePlugin(),\n routesExposePlugin()\n ]\n\n // process.env.WORKSPACE_GIT_REPO 有这个表示是在 sandbox 里面运行,启用浏览器日志插件\n if (process.env.WORKSPACE_GIT_REPO) {\n plugins.push(browserLogsPlugin());\n }\n\n return plugins;\n}\n\nexport {\n componentIdPlugin,\n editorBridgePlugin,\n routesExposePlugin\n}"]}
1
+ {"version":3,"sources":["../src/component-id.ts","../src/editor-bridge.ts","../src/routes-expose.ts","../src/browser-logs.ts","../src/taro-env-inject.ts","../src/index.ts"],"names":["generateUniqueId","filePath","position","key","createHash","HTML_TAGS","componentIdPlugin","isDev","config","code","id","transformedCode","jsxOpenTagRegex","match","matches","tag","tagStartIndex","tagEndIndex","checkIndex","foundClosing","hasComponentId","currentCode","item","index","uniqueId","before","after","clickHandlerScript","getBridgeScriptContent","__filename","fileURLToPath","__dirname","dirname","bridgePath","resolve","readFileSync","error","editorBridgePlugin","bridgeScript","html","scriptsToInject","routesExposePlugin","options","routesPath","browserLogsPlugin","logFilePath","injectedScript","root","process","path","devServer","req","res","next","origin","body","chunk","logDir","fs","injectTaroEnv","additional","autoInjectTaroApp","autoInjectVite","constants","varsToInject","varName","value","injectAmasterEnv","devTools","_options","plugins"],"mappings":"gdAGA,SAASA,CAAAA,CAAiBC,CAAAA,CAAkBC,EAA0B,CACpE,IAAMC,EAAM,CAAA,EAAGF,CAAQ,IAAIC,CAAQ,CAAA,CAAA,CACnC,OAAOE,iBAAAA,CAAW,KAAK,EAAE,MAAA,CAAOD,CAAG,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA,CAAE,SAAA,CAAU,EAAG,EAAE,CACpE,CAEA,IAAME,CAAAA,CAAY,IAAI,GAAA,CAAI,CACxB,IAAK,MAAA,CAAQ,SAAA,CAAW,OAAQ,SAAA,CAAW,OAAA,CAAS,QAAS,GAAA,CAAK,MAAA,CAAQ,KAAA,CAAO,KAAA,CACjF,aAAc,MAAA,CAAQ,IAAA,CAAM,SAAU,QAAA,CAAU,SAAA,CAAW,OAAQ,MAAA,CAAQ,KAAA,CAC3E,WAAY,MAAA,CAAQ,UAAA,CAAY,KAAM,KAAA,CAAO,SAAA,CAAW,MAAO,QAAA,CAAU,KAAA,CAAO,KAChF,IAAA,CAAM,IAAA,CAAM,OAAA,CAAS,UAAA,CAAY,aAAc,QAAA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QC,CAAAA,EAAW,CAC9B,IAAMC,EAAQ,OAAA,CAAQ,GAAA,CAAID,CAAO,CAAA,EAAK,EAAA,CACtCF,CAAAA,CAAU,CAAA,YAAA,EAAeE,CAAO,EAAE,CAAA,CAAI,IAAA,CAAK,SAAA,CAAUC,CAAK,EAC5D,CAAC,CAAA,CAEMH,CACT,CAQO,SAASI,CAAAA,EAA2C,CACzD,OAAO,CACL,mCAAA,CAAqC,IAAA,CAAK,SAAA,CAAU,OAAA,CAAQ,IAAI,qBAAA,EAAyB,EAAE,CAAA,CAC3F,+BAAA,CAAiC,IAAA,CAAK,SAAA,CAAU,OAAA,CAAQ,GAAA,CAAI,mBAAqB,EAAE,CACrF,CACF,CC7Ee,SAARC,CAAAA,CAA0BC,CAAAA,CAA4B,EAAC,CAAa,CACvE,IAAMC,CAAAA,CAAoB,CACtBhE,CAAAA,EAAkB,CAClB+B,CAAAA,EAAmB,CACnBI,CAAAA,EACJ,CAAA,CAGA,OAAIO,kBAAAA,CAAQ,GAAA,CAAI,oBACZsB,CAAAA,CAAQ,IAAA,CAAK1B,CAAAA,EAAmB,EAG7B0B,CACX","file":"index.cjs","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Plugin } from \"vite\";\n\nfunction generateUniqueId(filePath: string, position: number): string {\n const key = `${filePath}:${position}`;\n return createHash(\"md5\").update(key).digest(\"hex\").substring(0, 12);\n}\n\nconst HTML_TAGS = new Set([\n \"a\", \"abbr\", \"address\", \"area\", \"article\", \"aside\", \"audio\", \"b\", \"base\", \"bdi\", \"bdo\",\n \"blockquote\", \"body\", \"br\", \"button\", \"canvas\", \"caption\", \"cite\", \"code\", \"col\",\n \"colgroup\", \"data\", \"datalist\", \"dd\", \"del\", \"details\", \"dfn\", \"dialog\", \"div\", \"dl\",\n \"dt\", \"em\", \"embed\", \"fieldset\", \"figcaption\", \"figure\", \"footer\", \"form\", \"h1\", \"h2\",\n \"h3\", \"h4\", \"h5\", \"h6\", \"head\", \"header\", \"hgroup\", \"hr\", \"html\", \"i\", \"iframe\", \"img\",\n \"input\", \"ins\", \"kbd\", \"label\", \"legend\", \"li\", \"link\", \"main\", \"map\", \"mark\", \"meta\",\n \"meter\", \"nav\", \"noscript\", \"object\", \"ol\", \"optgroup\", \"option\", \"output\", \"p\", \"param\",\n \"picture\", \"pre\", \"progress\", \"q\", \"rp\", \"rt\", \"ruby\", \"s\", \"samp\", \"script\", \"section\",\n \"select\", \"small\", \"source\", \"span\", \"strong\", \"style\", \"sub\", \"summary\", \"sup\", \"svg\",\n \"table\", \"tbody\", \"td\", \"template\", \"textarea\", \"tfoot\", \"th\", \"thead\", \"time\", \"title\",\n \"tr\", \"track\", \"u\", \"ul\", \"var\", \"video\", \"wbr\",\n]);\n\n/**\n * Vite plugin: Add data-node-component-id to React components\n * Only enabled in development mode\n */\nexport function componentIdPlugin(): Plugin {\n let isDev = false;\n\n return {\n name: \"vite-plugin-component-id\",\n enforce: \"pre\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!/\\.(tsx|jsx)$/.test(id)) {\n return null;\n }\n\n if (id.includes(\"node_modules\")) {\n return null;\n }\n\n if (!/<[a-z]/.test(code)) {\n return null;\n }\n\n try {\n let transformedCode = code;\n const jsxOpenTagRegex = /<([a-z][\\da-z]*)(?=[\\s/>])/g;\n\n let match: RegExpExecArray | null;\n const matches: Array<{ index: number; tag: string; tagEndIndex: number }> = [];\n\n while ((match = jsxOpenTagRegex.exec(code)) !== null) {\n const tag = match[1];\n if (!tag) continue;\n \n const tagStartIndex = match.index;\n const tagEndIndex = match.index + match[0].length;\n\n if (!HTML_TAGS.has(tag)) {\n continue;\n }\n\n let checkIndex = tagEndIndex;\n let foundClosing = false;\n let hasComponentId = false;\n\n while (checkIndex < code.length && !foundClosing) {\n const char = code[checkIndex];\n if (char === \">\") {\n foundClosing = true;\n const tagContent = code.substring(tagStartIndex, checkIndex);\n if (tagContent.includes(\"data-node-component-id\")) {\n hasComponentId = true;\n }\n }\n checkIndex++;\n }\n\n if (hasComponentId) {\n continue;\n }\n\n matches.push({\n index: tagStartIndex,\n tag,\n tagEndIndex,\n });\n }\n\n let currentCode = code;\n for (let i = matches.length - 1; i >= 0; i--) {\n const item = matches[i];\n if (!item) continue;\n \n const { index, tagEndIndex } = item;\n const uniqueId = generateUniqueId(id, index);\n\n const before = currentCode.substring(0, tagEndIndex);\n const after = currentCode.substring(tagEndIndex);\n\n transformedCode = `${before} data-node-component-id=\"${uniqueId}\"${after}`;\n currentCode = transformedCode;\n }\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { readFileSync } from \"fs\";\nimport { resolve, dirname } from \"path\";\nimport { fileURLToPath } from \"url\";\n\nconst clickHandlerScript = `<script>\ndocument.addEventListener(\"click\", (e) => {\n const element = e.target;\n const noJumpOut = document.body.classList.contains(\"forbid-jump-out\")\n if (element.hasAttribute(\"data-link-href\") && !noJumpOut) {\n const href = element.getAttribute(\"data-link-href\");\n const target = element.getAttribute(\"data-link-target\");\n if (href) {\n if (target === \"_blank\") {\n window.open(href, \"_blank\");\n } else {\n window.location.href = href;\n }\n }\n } else if(noJumpOut && element.tagName === \"A\") {\n e.preventDefault();\n }\n});\n</script>`;\n\n/**\n * 读取构建后的 bridge 脚本内容\n */\nfunction getBridgeScriptContent(): string {\n try {\n // 获取当前模块的目录\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n \n // 读取构建后的 bridge.bridge.js 文件\n const bridgePath = resolve(__dirname, \"../dist/bridge.bridge.js\");\n const bridgeContent = readFileSync(bridgePath, \"utf-8\");\n \n return `<script>\\n${bridgeContent}\\n</script>`;\n } catch (error) {\n console.warn(\"Failed to read bridge script:\", error);\n return \"\";\n }\n}\n\n/**\n * Vite plugin: Inject editor bridge script\n * Injects bridge.js in development mode by reading the built bridge script\n */\nexport function editorBridgePlugin(): Plugin {\n let isDev = false;\n let bridgeScript = \"\";\n\n return {\n name: \"vite-plugin-editor-bridge\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n \n // 在开发模式下读取 bridge 脚本内容\n if (isDev) {\n bridgeScript = getBridgeScriptContent();\n }\n },\n\n transformIndexHtml(html) {\n // 在开发模式下注入 bridge 脚本\n const devScript = isDev ? bridgeScript : \"\";\n\n const scriptsToInject = `${clickHandlerScript}${devScript}</body>`;\n\n return html.replace(\"</body>\", scriptsToInject);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Vite plugin: Expose routes to window.__APP_ROUTES__\n * Only enabled in development mode\n */\nexport function routesExposePlugin(options?: { routesFilePath?: string }): Plugin {\n let isDev = false;\n const routesPath = options?.routesFilePath || \"src/routes.tsx\";\n\n return {\n name: \"vite-plugin-routes-expose\",\n enforce: \"post\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!id.endsWith(routesPath)) {\n return null;\n }\n\n try {\n if (code.includes(\"window.__APP_ROUTES__\")) {\n return null;\n }\n\n const transformedCode = `${code}\n\n// Development mode: Expose routes to window.__APP_ROUTES__\nif (typeof window !== 'undefined') {\n window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];\n}\n`;\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\n/**\n * Browser logs collection plugin\n * Injects script into HTML head to collect console logs and network requests\n * Logs are written directly to browser.log file (same level as index.html)\n */\nexport function browserLogsPlugin(): Plugin {\n let logFilePath = \"\";\n\n // Script to inject into browser\n const injectedScript = `\n<script>\n(function() {\n 'use strict';\n \n // Log API path (provided by Vite dev server)\n var LOG_API_PATH = '/__browser__';\n \n // Write queue to ensure sequential writes\n var writeQueue = [];\n var isWriting = false;\n \n // Process write queue to ensure sequential writes\n function processWriteQueue() {\n if (isWriting || writeQueue.length === 0) return;\n \n isWriting = true;\n var entry = writeQueue.shift();\n var logText = JSON.stringify(entry);\n \n fetch(LOG_API_PATH, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: logText\n })\n .then(function(response) {\n isWriting = false;\n if (!response.ok) {\n console.warn('[BrowserLogs] Failed to write log:', response.status);\n }\n // Continue processing next item in queue\n processWriteQueue();\n })\n .catch(function(error) {\n console.warn('[BrowserLogs] Failed to write log:', error.message);\n // On failure, put log back to queue head for retry\n writeQueue.unshift(entry);\n isWriting = false;\n // Retry after delay\n setTimeout(processWriteQueue, 1000);\n });\n }\n \n // Limit headers object size\n function truncateHeaders(headers) {\n if (!headers) return headers;\n var jsonStr = JSON.stringify(headers);\n if (jsonStr.length <= MAX_HEADER_SIZE) return headers;\n return '[Headers truncated, size: ' + jsonStr.length + ']';\n }\n \n // Truncate oversized log entries\n function truncateLogEntry(entry) {\n var jsonStr = JSON.stringify(entry);\n if (jsonStr.length <= MAX_LOG_ENTRY_SIZE) {\n return entry;\n }\n \n // If oversized, progressively truncate non-critical fields\n var truncated = Object.assign({}, entry);\n \n // 1. Truncate response body first\n if (truncated.responseBody && typeof truncated.responseBody === 'string') {\n truncated.responseBody = truncated.responseBody.substring(0, 500) + '... [truncated]';\n }\n \n // 2. Truncate request body\n if (truncated.requestBody && typeof truncated.requestBody === 'string') {\n truncated.requestBody = truncated.requestBody.substring(0, 500) + '... [truncated]';\n }\n \n // 3. Truncate message\n if (truncated.message && typeof truncated.message === 'string' && truncated.message.length > 1000) {\n truncated.message = truncated.message.substring(0, 1000) + '... [truncated]';\n }\n \n // 4. Truncate stack\n if (truncated.stack && Array.isArray(truncated.stack) && truncated.stack.length > 3) {\n truncated.stack = truncated.stack.slice(0, 3);\n }\n \n // Add truncation marker\n truncated._truncated = true;\n truncated._originalSize = jsonStr.length;\n \n return truncated;\n }\n \n // Add log and send immediately (ensure order)\n function addLog(entry) {\n var truncatedEntry = truncateLogEntry(entry);\n writeQueue.push(truncatedEntry);\n processWriteQueue();\n }\n \n // ============================================\n // Console log collection\n // ============================================\n var originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n debug: console.debug\n };\n \n function getStackTrace() {\n var stack = new Error().stack || '';\n var lines = stack.split('\\\\n').slice(3);\n // Limit stack lines\n return lines.slice(0, MAX_STACK_LINES).map(function(line) { return line.trim(); });\n }\n \n function formatMessage(args) {\n return Array.from(args).map(function(arg) {\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n if (typeof arg === 'object') {\n try {\n return JSON.stringify(arg);\n } catch (e) {\n return String(arg);\n }\n }\n return String(arg);\n }).join(' ');\n }\n \n function createLogEntry(level, args) {\n return {\n type: 'console',\n timestamp: new Date().toISOString(),\n level: level,\n message: formatMessage(args),\n stack: getStackTrace()\n };\n }\n \n // Check if message should be filtered (contains [vite] text)\n function shouldFilterConsoleLog(args) {\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n if (typeof arg === 'string' && arg.indexOf('[vite]') !== -1) {\n return true;\n }\n }\n return false;\n }\n \n function wrapConsoleMethod(method, level) {\n return function() {\n var args = arguments;\n // Filter out logs containing [vite]\n if (shouldFilterConsoleLog(args)) {\n return originalConsole[method].apply(console, args);\n }\n var entry = createLogEntry(level, args);\n addLog(entry);\n return originalConsole[method].apply(console, args);\n };\n }\n \n console.log = wrapConsoleMethod('log', 'log');\n console.info = wrapConsoleMethod('info', 'info');\n console.warn = wrapConsoleMethod('warn', 'warn');\n console.error = wrapConsoleMethod('error', 'error');\n console.debug = wrapConsoleMethod('debug', 'debug');\n \n // ============================================\n // Network request collection (exclude SSE and log API requests)\n // ============================================\n \n var MAX_BODY_SIZE = 2000;\n var MAX_LOG_ENTRY_SIZE = 3000; // Max single log entry length\n var MAX_HEADER_SIZE = 500; // Max single header object length\n var MAX_STACK_LINES = 5; // Max stack lines to keep\n const FILTERED_URLS = ['/__browser__', '/builtin']; // Filter out log API and Vite built-in requests\n \n function isSSERequest(url, headers) {\n var sseUrlPatterns = ['/events', '/sse', '/stream', 'text/event-stream'];\n var urlStr = String(url).toLowerCase();\n for (var i = 0; i < sseUrlPatterns.length; i++) {\n if (urlStr.indexOf(sseUrlPatterns[i]) !== -1) {\n return true;\n }\n }\n \n if (headers) {\n if (typeof headers.get === 'function') {\n var accept = headers.get('Accept') || headers.get('accept');\n if (accept && accept.indexOf('text/event-stream') !== -1) {\n return true;\n }\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n if (key.toLowerCase() === 'accept' && headers[key].indexOf('text/event-stream') !== -1) {\n return true;\n }\n }\n }\n }\n \n return false;\n }\n \n function shouldFilterRequest(url) {\n return FILTERED_URLS.some(function(filteredUrl) {\n return String(url).indexOf(filteredUrl) !== -1;\n });\n }\n \n function formatRequestBody(body) {\n if (!body) return null;\n \n try {\n if (typeof body === 'string') {\n return body.substring(0, MAX_BODY_SIZE);\n }\n if (body instanceof FormData) {\n var formDataObj = {};\n body.forEach(function(value, key) {\n if (value instanceof File) {\n formDataObj[key] = '[File: ' + value.name + ', size: ' + value.size + ']';\n } else {\n formDataObj[key] = String(value).substring(0, 1000);\n }\n });\n return JSON.stringify(formDataObj);\n }\n if (body instanceof Blob) {\n return '[Blob: size=' + body.size + ', type=' + body.type + ']';\n }\n if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {\n return '[Binary: size=' + body.byteLength + ']';\n }\n if (body instanceof URLSearchParams) {\n return body.toString().substring(0, MAX_BODY_SIZE);\n }\n return String(body).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading body: ' + e.message + ']';\n }\n }\n \n function formatResponseBody(response, responseType) {\n if (!response) return null;\n \n try {\n if (responseType === '' || responseType === 'text') {\n return String(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'json') {\n return JSON.stringify(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'document') {\n return '[Document]';\n }\n if (responseType === 'blob') {\n return '[Blob: size=' + response.size + ']';\n }\n if (responseType === 'arraybuffer') {\n return '[ArrayBuffer: size=' + response.byteLength + ']';\n }\n return String(response).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading response: ' + e.message + ']';\n }\n }\n \n // Intercept XMLHttpRequest\n var originalXHROpen = XMLHttpRequest.prototype.open;\n var originalXHRSend = XMLHttpRequest.prototype.send;\n var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;\n \n XMLHttpRequest.prototype.open = function(method, url, async, user, password) {\n this.__requestInfo__ = {\n method: method,\n url: url,\n startTime: null,\n headers: {}\n };\n return originalXHROpen.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.setRequestHeader = function(name, value) {\n if (this.__requestInfo__ && this.__requestInfo__.headers) {\n this.__requestInfo__.headers[name] = value;\n }\n return originalXHRSetRequestHeader.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.send = function(body) {\n var xhr = this;\n var requestInfo = xhr.__requestInfo__;\n \n if (requestInfo) {\n // Skip SSE requests and filtered requests\n if (isSSERequest(requestInfo.url, requestInfo.headers) || shouldFilterRequest(requestInfo.url)) {\n return originalXHRSend.apply(this, arguments);\n }\n \n requestInfo.startTime = Date.now();\n requestInfo.requestBody = formatRequestBody(body);\n \n xhr.addEventListener('loadend', function() {\n var contentType = xhr.getResponseHeader('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return;\n }\n \n var responseHeaders = {};\n var allHeaders = xhr.getAllResponseHeaders();\n if (allHeaders) {\n allHeaders.split('\\\\r\\\\n').forEach(function(line) {\n var parts = line.split(': ');\n if (parts.length === 2) {\n responseHeaders[parts[0]] = parts[1];\n }\n });\n }\n \n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'xhr',\n method: requestInfo.method,\n url: requestInfo.url,\n status: xhr.status,\n statusText: xhr.statusText,\n duration: Date.now() - requestInfo.startTime,\n requestHeaders: truncateHeaders(requestInfo.headers),\n requestBody: requestInfo.requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseType: xhr.responseType,\n responseBody: formatResponseBody(xhr.response, xhr.responseType),\n responseSize: xhr.response ? (typeof xhr.response === 'string' ? xhr.response.length : (xhr.response.byteLength || xhr.response.size || null)) : null\n };\n \n addLog(entry);\n });\n }\n \n return originalXHRSend.apply(this, arguments);\n };\n \n // Intercept Fetch API\n var originalFetch = window.fetch;\n \n function headersToObject(headers) {\n var obj = {};\n if (!headers) return obj;\n \n if (typeof headers.forEach === 'function') {\n headers.forEach(function(value, key) {\n obj[key] = value;\n });\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n obj[key] = headers[key];\n }\n }\n return obj;\n }\n \n window.fetch = function(input, init) {\n var startTime = Date.now();\n var method = (init && init.method) || 'GET';\n var url = typeof input === 'string' ? input : input.url;\n var headers = init && init.headers;\n \n // Skip SSE requests and filtered requests\n if (isSSERequest(url, headers) || shouldFilterRequest(url)) {\n return originalFetch.apply(this, arguments);\n }\n \n var requestHeaders = headersToObject(headers);\n var requestBody = formatRequestBody(init && init.body);\n \n return originalFetch.apply(this, arguments)\n .then(function(response) {\n var contentType = response.headers.get('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return response;\n }\n \n var clonedResponse = response.clone();\n var responseHeaders = headersToObject(response.headers);\n \n clonedResponse.text().then(function(bodyText) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: bodyText ? bodyText.substring(0, MAX_BODY_SIZE) : null,\n responseSize: bodyText ? bodyText.length : null,\n ok: response.ok\n };\n \n addLog(entry);\n }).catch(function(e) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: '[Unable to read: ' + e.message + ']',\n responseSize: null,\n ok: response.ok\n };\n \n addLog(entry);\n });\n \n return response;\n })\n .catch(function(error) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: 0,\n statusText: 'Network Error',\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: null,\n responseBody: null,\n error: error.message\n };\n \n addLog(entry);\n throw error;\n });\n };\n \n // ============================================\n // Global error capture\n // ============================================\n window.addEventListener('error', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: event.message,\n stack: event.error ? event.error.stack : 'at ' + event.filename + ':' + event.lineno + ':' + event.colno\n };\n addLog(entry);\n });\n \n // ============================================\n // Vite deps 504 error capture using PerformanceObserver\n // Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)\n // ============================================\n if (typeof PerformanceObserver !== 'undefined') {\n var reportedUrls = {}; // Track reported URLs to avoid duplicates\n \n var perfObserver = new PerformanceObserver(function(list) {\n var entries = list.getEntries();\n for (var i = 0; i < entries.length; i++) {\n var perfEntry = entries[i];\n // Only check script resources\n if (perfEntry.initiatorType !== 'script') {\n continue;\n }\n \n var resourceUrl = perfEntry.name || '';\n // Only report errors for node_modules/.vite resources\n if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {\n continue;\n }\n \n // Check if response status is 504 (Gateway Timeout)\n // responseStatus is available in Resource Timing Level 2\n var status = perfEntry.responseStatus;\n if (status === 504) {\n // Avoid duplicate reports\n if (reportedUrls[resourceUrl]) {\n continue;\n }\n reportedUrls[resourceUrl] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: resourceUrl,\n status: 504,\n message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,\n duration: perfEntry.duration,\n transferSize: perfEntry.transferSize\n };\n addLog(entry);\n }\n }\n });\n \n try {\n perfObserver.observe({ type: 'resource', buffered: true });\n } catch (e) {\n // Fallback for browsers that don't support the options\n try {\n perfObserver.observe({ entryTypes: ['resource'] });\n } catch (e2) {\n originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);\n }\n }\n }\n \n window.addEventListener('unhandledrejection', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: 'Unhandled Promise Rejection: ' + (event.reason ? (event.reason.message || String(event.reason)) : 'Unknown'),\n stack: event.reason && event.reason.stack ? event.reason.stack : ''\n };\n addLog(entry);\n });\n \n // ============================================\n // Send remaining logs on page unload\n // ============================================\n window.addEventListener('beforeunload', function() {\n if (writeQueue.length > 0) {\n // Use sendBeacon to ensure logs are sent\n writeQueue.forEach(function(entry) {\n navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));\n });\n writeQueue = [];\n }\n });\n \n // ============================================\n // Provide manual flush method\n // ============================================\n window.__flushBrowserLogs__ = function() {\n return new Promise(function(resolve) {\n // Wait for queue to finish processing\n function checkQueue() {\n if (writeQueue.length === 0 && !isWriting) {\n resolve();\n } else {\n setTimeout(checkQueue, 100);\n }\n }\n checkQueue();\n });\n };\n \n // Provide method to get queue status\n window.__getBrowserLogsStatus__ = function() {\n return {\n queueLength: writeQueue.length,\n isWriting: isWriting\n };\n };\n \n originalConsole.log('[BrowserLogs] Log collection started');\n})();\n</script>`;\n\n return {\n name: \"vite-plugin-browser-logs\",\n\n configResolved(config) {\n // Determine log file path: same level as index.html\n const root = config.root || process.cwd();\n logFilePath = path.join(root, \"browser.log\");\n },\n\n configureServer(devServer) {\n // Add log write API\n devServer.middlewares.use((req, res, next) => {\n if (req.url === \"/__browser__\" && req.method === \"POST\") {\n // Get request origin, dynamically set CORS headers to avoid protocol mismatch\n const origin = req.headers.origin || \"*\";\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString();\n });\n req.on(\"end\", () => {\n try {\n // Ensure log directory exists\n const logDir = path.dirname(logFilePath);\n if (!fs.existsSync(logDir)) {\n fs.mkdirSync(logDir, { recursive: true });\n }\n // Append to log file\n fs.appendFileSync(logFilePath, `${body}\\n`, \"utf-8\");\n res.writeHead(200, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: true }));\n } catch (error) {\n console.error(\"[BrowserLogs] Write error:\", error);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: false, error: String(error) }));\n }\n });\n } else if (req.url === \"/__browser__\" && req.method === \"OPTIONS\") {\n // Handle CORS preflight request\n const origin = req.headers.origin || \"*\";\n res.writeHead(204, {\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Max-Age\": \"86400\",\n });\n res.end();\n } else if (req.url === \"/__browser__\") {\n const origin = req.headers.origin || \"*\";\n res.writeHead(405, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n });\n res.end(JSON.stringify({ error: \"Method not allowed\" }));\n } else {\n next();\n }\n });\n\n console.log(\"[BrowserLogs] Logs will be written to:\", logFilePath);\n },\n\n transformIndexHtml(html) {\n // Insert script after <head> tag to ensure earliest execution\n return html.replace(/<head([^>]*)>/i, `<head$1>${injectedScript}`);\n },\n };\n}\n","/**\n * Taro Environment Variables Injection Helper\n * \n * Automatically injects environment variables into Taro's defineConstants\n * so that they will be replaced at build time.\n * \n * @example\n * ```ts\n * // In Taro config/index.ts\n * import { injectTaroEnv } from '@amaster.ai/vite-plugins/taro-env-inject'\n * \n * export default defineConfig({\n * defineConstants: {\n * ...injectTaroEnv()\n * }\n * })\n * ```\n */\n\nexport interface TaroEnvInjectOptions {\n /**\n * Additional environment variable names to inject\n * @default []\n */\n additional?: string[];\n \n /**\n * Whether to inject all TARO_APP_* prefixed variables\n * @default true\n */\n autoInjectTaroApp?: boolean;\n \n /**\n * Whether to inject all VITE_* prefixed variables\n * @default true\n */\n autoInjectVite?: boolean;\n}\n\n/**\n * Inject environment variables into Taro's defineConstants\n * \n * This function reads environment variables and formats them for Taro's defineConstants.\n * Taro will replace these at build time, converting `process.env.XXX` to actual values.\n */\nexport function injectTaroEnv(options: TaroEnvInjectOptions = {}): Record<string, string> {\n const {\n additional = [],\n autoInjectTaroApp = true,\n autoInjectVite = true,\n } = options;\n\n const constants: Record<string, string> = {};\n\n // Collect variable names to inject\n const varsToInject = new Set<string>(additional);\n\n // Auto-detect TARO_APP_* variables\n if (autoInjectTaroApp) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('TARO_APP_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Auto-detect VITE_* variables\n if (autoInjectVite) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('VITE_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Inject variables into defineConstants format\n varsToInject.forEach(varName => {\n const value = process.env[varName] || '';\n constants[`process.env.${varName}`] = JSON.stringify(value);\n });\n\n return constants;\n}\n\n/**\n * Inject specific environment variables for amaster.ai mini-program builds\n * \n * This is a convenience function that injects the standard environment variables\n * used by @amaster.ai/http-client for API base URL configuration.\n */\nexport function injectAmasterEnv(): Record<string, string> {\n return {\n 'process.env.TARO_APP_API_BASE_URL': JSON.stringify(process.env.TARO_APP_API_BASE_URL || ''),\n 'process.env.VITE_API_BASE_URL': JSON.stringify(process.env.VITE_API_BASE_URL || ''),\n };\n}\n","import { componentIdPlugin } from \"./component-id\";\nimport { editorBridgePlugin } from \"./editor-bridge\";\nimport { routesExposePlugin } from \"./routes-expose\";\nimport { browserLogsPlugin } from \"./browser-logs\";\nimport process from \"node:process\";\nimport type { Plugin } from \"vite\";\n\n// 预留配置项目,目前没有可配置的\nexport interface DevToolsOptions {\n // 未来可添加配置项\n}\n\n/**\n * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可\n * @param _options 预留参数,用于未来扩展配置(例如可选择性启用某些插件)\n * @returns Plugin[] Vite 插件数组\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\nexport default function devTools(_options: DevToolsOptions = {}): Plugin[] {\n const plugins: Plugin[] = [\n componentIdPlugin(),\n editorBridgePlugin(),\n routesExposePlugin()\n ]\n\n // process.env.WORKSPACE_GIT_REPO 有这个表示是在 sandbox 里面运行,启用浏览器日志插件\n if (process.env.WORKSPACE_GIT_REPO) {\n plugins.push(browserLogsPlugin());\n }\n\n return plugins;\n}\n\nexport {\n componentIdPlugin,\n editorBridgePlugin,\n routesExposePlugin\n}\n\n// Export Taro environment injection helpers\nexport { injectTaroEnv, injectAmasterEnv } from \"./taro-env-inject\";"]}
package/dist/index.d.cts CHANGED
@@ -20,6 +20,56 @@ declare function routesExposePlugin(options?: {
20
20
  routesFilePath?: string;
21
21
  }): Plugin;
22
22
 
23
+ /**
24
+ * Taro Environment Variables Injection Helper
25
+ *
26
+ * Automatically injects environment variables into Taro's defineConstants
27
+ * so that they will be replaced at build time.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // In Taro config/index.ts
32
+ * import { injectTaroEnv } from '@amaster.ai/vite-plugins/taro-env-inject'
33
+ *
34
+ * export default defineConfig({
35
+ * defineConstants: {
36
+ * ...injectTaroEnv()
37
+ * }
38
+ * })
39
+ * ```
40
+ */
41
+ interface TaroEnvInjectOptions {
42
+ /**
43
+ * Additional environment variable names to inject
44
+ * @default []
45
+ */
46
+ additional?: string[];
47
+ /**
48
+ * Whether to inject all TARO_APP_* prefixed variables
49
+ * @default true
50
+ */
51
+ autoInjectTaroApp?: boolean;
52
+ /**
53
+ * Whether to inject all VITE_* prefixed variables
54
+ * @default true
55
+ */
56
+ autoInjectVite?: boolean;
57
+ }
58
+ /**
59
+ * Inject environment variables into Taro's defineConstants
60
+ *
61
+ * This function reads environment variables and formats them for Taro's defineConstants.
62
+ * Taro will replace these at build time, converting `process.env.XXX` to actual values.
63
+ */
64
+ declare function injectTaroEnv(options?: TaroEnvInjectOptions): Record<string, string>;
65
+ /**
66
+ * Inject specific environment variables for amaster.ai mini-program builds
67
+ *
68
+ * This is a convenience function that injects the standard environment variables
69
+ * used by @amaster.ai/http-client for API base URL configuration.
70
+ */
71
+ declare function injectAmasterEnv(): Record<string, string>;
72
+
23
73
  interface DevToolsOptions {
24
74
  }
25
75
  /**
@@ -29,4 +79,4 @@ interface DevToolsOptions {
29
79
  */
30
80
  declare function devTools(_options?: DevToolsOptions): Plugin[];
31
81
 
32
- export { type DevToolsOptions, componentIdPlugin, devTools as default, editorBridgePlugin, routesExposePlugin };
82
+ export { type DevToolsOptions, componentIdPlugin, devTools as default, editorBridgePlugin, injectAmasterEnv, injectTaroEnv, routesExposePlugin };
package/dist/index.d.ts CHANGED
@@ -20,6 +20,56 @@ declare function routesExposePlugin(options?: {
20
20
  routesFilePath?: string;
21
21
  }): Plugin;
22
22
 
23
+ /**
24
+ * Taro Environment Variables Injection Helper
25
+ *
26
+ * Automatically injects environment variables into Taro's defineConstants
27
+ * so that they will be replaced at build time.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // In Taro config/index.ts
32
+ * import { injectTaroEnv } from '@amaster.ai/vite-plugins/taro-env-inject'
33
+ *
34
+ * export default defineConfig({
35
+ * defineConstants: {
36
+ * ...injectTaroEnv()
37
+ * }
38
+ * })
39
+ * ```
40
+ */
41
+ interface TaroEnvInjectOptions {
42
+ /**
43
+ * Additional environment variable names to inject
44
+ * @default []
45
+ */
46
+ additional?: string[];
47
+ /**
48
+ * Whether to inject all TARO_APP_* prefixed variables
49
+ * @default true
50
+ */
51
+ autoInjectTaroApp?: boolean;
52
+ /**
53
+ * Whether to inject all VITE_* prefixed variables
54
+ * @default true
55
+ */
56
+ autoInjectVite?: boolean;
57
+ }
58
+ /**
59
+ * Inject environment variables into Taro's defineConstants
60
+ *
61
+ * This function reads environment variables and formats them for Taro's defineConstants.
62
+ * Taro will replace these at build time, converting `process.env.XXX` to actual values.
63
+ */
64
+ declare function injectTaroEnv(options?: TaroEnvInjectOptions): Record<string, string>;
65
+ /**
66
+ * Inject specific environment variables for amaster.ai mini-program builds
67
+ *
68
+ * This is a convenience function that injects the standard environment variables
69
+ * used by @amaster.ai/http-client for API base URL configuration.
70
+ */
71
+ declare function injectAmasterEnv(): Record<string, string>;
72
+
23
73
  interface DevToolsOptions {
24
74
  }
25
75
  /**
@@ -29,4 +79,4 @@ interface DevToolsOptions {
29
79
  */
30
80
  declare function devTools(_options?: DevToolsOptions): Plugin[];
31
81
 
32
- export { type DevToolsOptions, componentIdPlugin, devTools as default, editorBridgePlugin, routesExposePlugin };
82
+ export { type DevToolsOptions, componentIdPlugin, devTools as default, editorBridgePlugin, injectAmasterEnv, injectTaroEnv, routesExposePlugin };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {createHash}from'crypto';import g,{readFileSync}from'fs';import b,{dirname,resolve}from'path';import {fileURLToPath}from'url';import H from'process';function _(t,e){let n=`${t}:${e}`;return createHash("md5").update(n).digest("hex").substring(0,12)}var T=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function m(){let t=false;return {name:"vite-plugin-component-id",enforce:"pre",configResolved(e){t=e.command==="serve";},transform(e,n){if(!t||!/\.(tsx|jsx)$/.test(n)||n.includes("node_modules")||!/<[a-z]/.test(e))return null;try{let r=e,o=/<([a-z][\da-z]*)(?=[\s/>])/g,a,i=[];for(;(a=o.exec(e))!==null;){let s=a[1];if(!s)continue;let d=a.index,c=a.index+a[0].length;if(!T.has(s))continue;let u=c,p=!1,f=!1;for(;u<e.length&&!p;)e[u]===">"&&(p=!0,e.substring(d,u).includes("data-node-component-id")&&(f=!0)),u++;f||i.push({index:d,tag:s,tagEndIndex:c});}let l=e;for(let s=i.length-1;s>=0;s--){let d=i[s];if(!d)continue;let{index:c,tagEndIndex:u}=d,p=_(n,c),f=l.substring(0,u),y=l.substring(u);r=`${f} data-node-component-id="${p}"${y}`,l=r;}return {code:r,map:null}}catch{return null}}}}var E=`<script>
1
+ import {createHash}from'crypto';import g,{readFileSync}from'fs';import b,{dirname,resolve}from'path';import {fileURLToPath}from'url';import P from'process';function w(r,e){let n=`${r}:${e}`;return createHash("md5").update(n).digest("hex").substring(0,12)}var T=new Set(["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"]);function m(){let r=false;return {name:"vite-plugin-component-id",enforce:"pre",configResolved(e){r=e.command==="serve";},transform(e,n){if(!r||!/\.(tsx|jsx)$/.test(n)||n.includes("node_modules")||!/<[a-z]/.test(e))return null;try{let t=e,o=/<([a-z][\da-z]*)(?=[\s/>])/g,a,s=[];for(;(a=o.exec(e))!==null;){let i=a[1];if(!i)continue;let d=a.index,c=a.index+a[0].length;if(!T.has(i))continue;let l=c,p=!1,f=!1;for(;l<e.length&&!p;)e[l]===">"&&(p=!0,e.substring(d,l).includes("data-node-component-id")&&(f=!0)),l++;f||s.push({index:d,tag:i,tagEndIndex:c});}let u=e;for(let i=s.length-1;i>=0;i--){let d=s[i];if(!d)continue;let{index:c,tagEndIndex:l}=d,p=w(n,c),f=u.substring(0,l),y=u.substring(l);t=`${f} data-node-component-id="${p}"${y}`,u=t;}return {code:t,map:null}}catch{return null}}}}var I=`<script>
2
2
  document.addEventListener("click", (e) => {
3
3
  const element = e.target;
4
4
  const noJumpOut = document.body.classList.contains("forbid-jump-out")
@@ -16,15 +16,15 @@ document.addEventListener("click", (e) => {
16
16
  e.preventDefault();
17
17
  }
18
18
  });
19
- </script>`;function I(){try{let t=fileURLToPath(import.meta.url),e=dirname(t),n=resolve(e,"../dist/bridge.bridge.js");return `<script>
19
+ </script>`;function q(){try{let r=fileURLToPath(import.meta.url),e=dirname(r),n=resolve(e,"../dist/bridge.bridge.js");return `<script>
20
20
  ${readFileSync(n,"utf-8")}
21
- </script>`}catch(t){return console.warn("Failed to read bridge script:",t),""}}function h(){let t=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){t=n.command==="serve",t&&(e=I());},transformIndexHtml(n){let o=`${E}${t?e:""}</body>`;return n.replace("</body>",o)}}}function v(t){let e=false,n=t?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(r){e=r.command==="serve";},transform(r,o){if(!e||!o.endsWith(n))return null;try{return r.includes("window.__APP_ROUTES__")?null:{code:`${r}
21
+ </script>`}catch(r){return console.warn("Failed to read bridge script:",r),""}}function h(){let r=false,e="";return {name:"vite-plugin-editor-bridge",configResolved(n){r=n.command==="serve",r&&(e=q());},transformIndexHtml(n){let o=`${I}${r?e:""}</body>`;return n.replace("</body>",o)}}}function v(r){let e=false,n=r?.routesFilePath||"src/routes.tsx";return {name:"vite-plugin-routes-expose",enforce:"post",configResolved(t){e=t.command==="serve";},transform(t,o){if(!e||!o.endsWith(n))return null;try{return t.includes("window.__APP_ROUTES__")?null:{code:`${t}
22
22
 
23
23
  // Development mode: Expose routes to window.__APP_ROUTES__
24
24
  if (typeof window !== 'undefined') {
25
25
  window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];
26
26
  }
27
- `,map:null}}catch{return null}}}}function w(){let t="",e=`
27
+ `,map:null}}catch{return null}}}}function _(){let r="",e=`
28
28
  <script>
29
29
  (function() {
30
30
  'use strict';
@@ -600,6 +600,6 @@ if (typeof window !== 'undefined') {
600
600
 
601
601
  originalConsole.log('[BrowserLogs] Log collection started');
602
602
  })();
603
- </script>`;return {name:"vite-plugin-browser-logs",configResolved(n){let r=n.root||H.cwd();t=b.join(r,"browser.log");},configureServer(n){n.middlewares.use((r,o,a)=>{if(r.url==="/__browser__"&&r.method==="POST"){let i=r.headers.origin||"*",l="";r.on("data",s=>{l+=s.toString();}),r.on("end",()=>{try{let s=b.dirname(t);g.existsSync(s)||g.mkdirSync(s,{recursive:!0}),g.appendFileSync(t,`${l}
604
- `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(s){console.error("[BrowserLogs] Write error:",s),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(s)}));}});}else if(r.url==="/__browser__"&&r.method==="OPTIONS"){let i=r.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":i,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(r.url==="/__browser__"){let i=r.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":i}),o.end(JSON.stringify({error:"Method not allowed"}));}else a();}),console.log("[BrowserLogs] Logs will be written to:",t);},transformIndexHtml(n){return n.replace(/<head([^>]*)>/i,`<head$1>${e}`)}}}function L(t={}){let e=[m(),h(),v()];return H.env.WORKSPACE_GIT_REPO&&e.push(w()),e}export{m as componentIdPlugin,L as default,h as editorBridgePlugin,v as routesExposePlugin};//# sourceMappingURL=index.js.map
603
+ </script>`;return {name:"vite-plugin-browser-logs",configResolved(n){let t=n.root||P.cwd();r=b.join(t,"browser.log");},configureServer(n){n.middlewares.use((t,o,a)=>{if(t.url==="/__browser__"&&t.method==="POST"){let s=t.headers.origin||"*",u="";t.on("data",i=>{u+=i.toString();}),t.on("end",()=>{try{let i=b.dirname(r);g.existsSync(i)||g.mkdirSync(i,{recursive:!0}),g.appendFileSync(r,`${u}
604
+ `,"utf-8"),o.writeHead(200,{"Content-Type":"application/json","Access-Control-Allow-Origin":s,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:!0}));}catch(i){console.error("[BrowserLogs] Write error:",i),o.writeHead(500,{"Content-Type":"application/json","Access-Control-Allow-Origin":s,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type"}),o.end(JSON.stringify({success:false,error:String(i)}));}});}else if(t.url==="/__browser__"&&t.method==="OPTIONS"){let s=t.headers.origin||"*";o.writeHead(204,{"Access-Control-Allow-Origin":s,"Access-Control-Allow-Methods":"POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Max-Age":"86400"}),o.end();}else if(t.url==="/__browser__"){let s=t.headers.origin||"*";o.writeHead(405,{"Content-Type":"application/json","Access-Control-Allow-Origin":s}),o.end(JSON.stringify({error:"Method not allowed"}));}else a();}),console.log("[BrowserLogs] Logs will be written to:",r);},transformIndexHtml(n){return n.replace(/<head([^>]*)>/i,`<head$1>${e}`)}}}function L(r={}){let{additional:e=[],autoInjectTaroApp:n=true,autoInjectVite:t=true}=r,o={},a=new Set(e);return n&&Object.keys(process.env).forEach(s=>{s.startsWith("TARO_APP_")&&a.add(s);}),t&&Object.keys(process.env).forEach(s=>{s.startsWith("VITE_")&&a.add(s);}),a.forEach(s=>{let u=process.env[s]||"";o[`process.env.${s}`]=JSON.stringify(u);}),o}function R(){return {"process.env.TARO_APP_API_BASE_URL":JSON.stringify(process.env.TARO_APP_API_BASE_URL||""),"process.env.VITE_API_BASE_URL":JSON.stringify(process.env.VITE_API_BASE_URL||"")}}function k(r={}){let e=[m(),h(),v()];return P.env.WORKSPACE_GIT_REPO&&e.push(_()),e}export{m as componentIdPlugin,k as default,h as editorBridgePlugin,R as injectAmasterEnv,L as injectTaroEnv,v as routesExposePlugin};//# sourceMappingURL=index.js.map
605
605
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/component-id.ts","../src/editor-bridge.ts","../src/routes-expose.ts","../src/browser-logs.ts","../src/index.ts"],"names":["generateUniqueId","filePath","position","key","createHash","HTML_TAGS","componentIdPlugin","isDev","config","code","id","transformedCode","jsxOpenTagRegex","match","matches","tag","tagStartIndex","tagEndIndex","checkIndex","foundClosing","hasComponentId","currentCode","i","item","index","uniqueId","before","after","clickHandlerScript","getBridgeScriptContent","__filename","fileURLToPath","__dirname","dirname","bridgePath","resolve","readFileSync","error","editorBridgePlugin","bridgeScript","html","scriptsToInject","routesExposePlugin","options","routesPath","browserLogsPlugin","logFilePath","injectedScript","root","process","path","devServer","req","res","next","origin","body","chunk","logDir","fs","devTools","_options","plugins"],"mappings":"4JAGA,SAASA,CAAAA,CAAiBC,CAAAA,CAAkBC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ACZa,CAAAA,CAAQ,KAAKjB,CAAAA,EAAmB,EAG7BiB,CACX","file":"index.js","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Plugin } from \"vite\";\n\nfunction generateUniqueId(filePath: string, position: number): string {\n const key = `${filePath}:${position}`;\n return createHash(\"md5\").update(key).digest(\"hex\").substring(0, 12);\n}\n\nconst HTML_TAGS = new Set([\n \"a\", \"abbr\", \"address\", \"area\", \"article\", \"aside\", \"audio\", \"b\", \"base\", \"bdi\", \"bdo\",\n \"blockquote\", \"body\", \"br\", \"button\", \"canvas\", \"caption\", \"cite\", \"code\", \"col\",\n \"colgroup\", \"data\", \"datalist\", \"dd\", \"del\", \"details\", \"dfn\", \"dialog\", \"div\", \"dl\",\n \"dt\", \"em\", \"embed\", \"fieldset\", \"figcaption\", \"figure\", \"footer\", \"form\", \"h1\", \"h2\",\n \"h3\", \"h4\", \"h5\", \"h6\", \"head\", \"header\", \"hgroup\", \"hr\", \"html\", \"i\", \"iframe\", \"img\",\n \"input\", \"ins\", \"kbd\", \"label\", \"legend\", \"li\", \"link\", \"main\", \"map\", \"mark\", \"meta\",\n \"meter\", \"nav\", \"noscript\", \"object\", \"ol\", \"optgroup\", \"option\", \"output\", \"p\", \"param\",\n \"picture\", \"pre\", \"progress\", \"q\", \"rp\", \"rt\", \"ruby\", \"s\", \"samp\", \"script\", \"section\",\n \"select\", \"small\", \"source\", \"span\", \"strong\", \"style\", \"sub\", \"summary\", \"sup\", \"svg\",\n \"table\", \"tbody\", \"td\", \"template\", \"textarea\", \"tfoot\", \"th\", \"thead\", \"time\", \"title\",\n \"tr\", \"track\", \"u\", \"ul\", \"var\", \"video\", \"wbr\",\n]);\n\n/**\n * Vite plugin: Add data-node-component-id to React components\n * Only enabled in development mode\n */\nexport function componentIdPlugin(): Plugin {\n let isDev = false;\n\n return {\n name: \"vite-plugin-component-id\",\n enforce: \"pre\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!/\\.(tsx|jsx)$/.test(id)) {\n return null;\n }\n\n if (id.includes(\"node_modules\")) {\n return null;\n }\n\n if (!/<[a-z]/.test(code)) {\n return null;\n }\n\n try {\n let transformedCode = code;\n const jsxOpenTagRegex = /<([a-z][\\da-z]*)(?=[\\s/>])/g;\n\n let match: RegExpExecArray | null;\n const matches: Array<{ index: number; tag: string; tagEndIndex: number }> = [];\n\n while ((match = jsxOpenTagRegex.exec(code)) !== null) {\n const tag = match[1];\n if (!tag) continue;\n \n const tagStartIndex = match.index;\n const tagEndIndex = match.index + match[0].length;\n\n if (!HTML_TAGS.has(tag)) {\n continue;\n }\n\n let checkIndex = tagEndIndex;\n let foundClosing = false;\n let hasComponentId = false;\n\n while (checkIndex < code.length && !foundClosing) {\n const char = code[checkIndex];\n if (char === \">\") {\n foundClosing = true;\n const tagContent = code.substring(tagStartIndex, checkIndex);\n if (tagContent.includes(\"data-node-component-id\")) {\n hasComponentId = true;\n }\n }\n checkIndex++;\n }\n\n if (hasComponentId) {\n continue;\n }\n\n matches.push({\n index: tagStartIndex,\n tag,\n tagEndIndex,\n });\n }\n\n let currentCode = code;\n for (let i = matches.length - 1; i >= 0; i--) {\n const item = matches[i];\n if (!item) continue;\n \n const { index, tagEndIndex } = item;\n const uniqueId = generateUniqueId(id, index);\n\n const before = currentCode.substring(0, tagEndIndex);\n const after = currentCode.substring(tagEndIndex);\n\n transformedCode = `${before} data-node-component-id=\"${uniqueId}\"${after}`;\n currentCode = transformedCode;\n }\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { readFileSync } from \"fs\";\nimport { resolve, dirname } from \"path\";\nimport { fileURLToPath } from \"url\";\n\nconst clickHandlerScript = `<script>\ndocument.addEventListener(\"click\", (e) => {\n const element = e.target;\n const noJumpOut = document.body.classList.contains(\"forbid-jump-out\")\n if (element.hasAttribute(\"data-link-href\") && !noJumpOut) {\n const href = element.getAttribute(\"data-link-href\");\n const target = element.getAttribute(\"data-link-target\");\n if (href) {\n if (target === \"_blank\") {\n window.open(href, \"_blank\");\n } else {\n window.location.href = href;\n }\n }\n } else if(noJumpOut && element.tagName === \"A\") {\n e.preventDefault();\n }\n});\n</script>`;\n\n/**\n * 读取构建后的 bridge 脚本内容\n */\nfunction getBridgeScriptContent(): string {\n try {\n // 获取当前模块的目录\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n \n // 读取构建后的 bridge.bridge.js 文件\n const bridgePath = resolve(__dirname, \"../dist/bridge.bridge.js\");\n const bridgeContent = readFileSync(bridgePath, \"utf-8\");\n \n return `<script>\\n${bridgeContent}\\n</script>`;\n } catch (error) {\n console.warn(\"Failed to read bridge script:\", error);\n return \"\";\n }\n}\n\n/**\n * Vite plugin: Inject editor bridge script\n * Injects bridge.js in development mode by reading the built bridge script\n */\nexport function editorBridgePlugin(): Plugin {\n let isDev = false;\n let bridgeScript = \"\";\n\n return {\n name: \"vite-plugin-editor-bridge\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n \n // 在开发模式下读取 bridge 脚本内容\n if (isDev) {\n bridgeScript = getBridgeScriptContent();\n }\n },\n\n transformIndexHtml(html) {\n // 在开发模式下注入 bridge 脚本\n const devScript = isDev ? bridgeScript : \"\";\n\n const scriptsToInject = `${clickHandlerScript}${devScript}</body>`;\n\n return html.replace(\"</body>\", scriptsToInject);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Vite plugin: Expose routes to window.__APP_ROUTES__\n * Only enabled in development mode\n */\nexport function routesExposePlugin(options?: { routesFilePath?: string }): Plugin {\n let isDev = false;\n const routesPath = options?.routesFilePath || \"src/routes.tsx\";\n\n return {\n name: \"vite-plugin-routes-expose\",\n enforce: \"post\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!id.endsWith(routesPath)) {\n return null;\n }\n\n try {\n if (code.includes(\"window.__APP_ROUTES__\")) {\n return null;\n }\n\n const transformedCode = `${code}\n\n// Development mode: Expose routes to window.__APP_ROUTES__\nif (typeof window !== 'undefined') {\n window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];\n}\n`;\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\n/**\n * Browser logs collection plugin\n * Injects script into HTML head to collect console logs and network requests\n * Logs are written directly to browser.log file (same level as index.html)\n */\nexport function browserLogsPlugin(): Plugin {\n let logFilePath = \"\";\n\n // Script to inject into browser\n const injectedScript = `\n<script>\n(function() {\n 'use strict';\n \n // Log API path (provided by Vite dev server)\n var LOG_API_PATH = '/__browser__';\n \n // Write queue to ensure sequential writes\n var writeQueue = [];\n var isWriting = false;\n \n // Process write queue to ensure sequential writes\n function processWriteQueue() {\n if (isWriting || writeQueue.length === 0) return;\n \n isWriting = true;\n var entry = writeQueue.shift();\n var logText = JSON.stringify(entry);\n \n fetch(LOG_API_PATH, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: logText\n })\n .then(function(response) {\n isWriting = false;\n if (!response.ok) {\n console.warn('[BrowserLogs] Failed to write log:', response.status);\n }\n // Continue processing next item in queue\n processWriteQueue();\n })\n .catch(function(error) {\n console.warn('[BrowserLogs] Failed to write log:', error.message);\n // On failure, put log back to queue head for retry\n writeQueue.unshift(entry);\n isWriting = false;\n // Retry after delay\n setTimeout(processWriteQueue, 1000);\n });\n }\n \n // Limit headers object size\n function truncateHeaders(headers) {\n if (!headers) return headers;\n var jsonStr = JSON.stringify(headers);\n if (jsonStr.length <= MAX_HEADER_SIZE) return headers;\n return '[Headers truncated, size: ' + jsonStr.length + ']';\n }\n \n // Truncate oversized log entries\n function truncateLogEntry(entry) {\n var jsonStr = JSON.stringify(entry);\n if (jsonStr.length <= MAX_LOG_ENTRY_SIZE) {\n return entry;\n }\n \n // If oversized, progressively truncate non-critical fields\n var truncated = Object.assign({}, entry);\n \n // 1. Truncate response body first\n if (truncated.responseBody && typeof truncated.responseBody === 'string') {\n truncated.responseBody = truncated.responseBody.substring(0, 500) + '... [truncated]';\n }\n \n // 2. Truncate request body\n if (truncated.requestBody && typeof truncated.requestBody === 'string') {\n truncated.requestBody = truncated.requestBody.substring(0, 500) + '... [truncated]';\n }\n \n // 3. Truncate message\n if (truncated.message && typeof truncated.message === 'string' && truncated.message.length > 1000) {\n truncated.message = truncated.message.substring(0, 1000) + '... [truncated]';\n }\n \n // 4. Truncate stack\n if (truncated.stack && Array.isArray(truncated.stack) && truncated.stack.length > 3) {\n truncated.stack = truncated.stack.slice(0, 3);\n }\n \n // Add truncation marker\n truncated._truncated = true;\n truncated._originalSize = jsonStr.length;\n \n return truncated;\n }\n \n // Add log and send immediately (ensure order)\n function addLog(entry) {\n var truncatedEntry = truncateLogEntry(entry);\n writeQueue.push(truncatedEntry);\n processWriteQueue();\n }\n \n // ============================================\n // Console log collection\n // ============================================\n var originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n debug: console.debug\n };\n \n function getStackTrace() {\n var stack = new Error().stack || '';\n var lines = stack.split('\\\\n').slice(3);\n // Limit stack lines\n return lines.slice(0, MAX_STACK_LINES).map(function(line) { return line.trim(); });\n }\n \n function formatMessage(args) {\n return Array.from(args).map(function(arg) {\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n if (typeof arg === 'object') {\n try {\n return JSON.stringify(arg);\n } catch (e) {\n return String(arg);\n }\n }\n return String(arg);\n }).join(' ');\n }\n \n function createLogEntry(level, args) {\n return {\n type: 'console',\n timestamp: new Date().toISOString(),\n level: level,\n message: formatMessage(args),\n stack: getStackTrace()\n };\n }\n \n // Check if message should be filtered (contains [vite] text)\n function shouldFilterConsoleLog(args) {\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n if (typeof arg === 'string' && arg.indexOf('[vite]') !== -1) {\n return true;\n }\n }\n return false;\n }\n \n function wrapConsoleMethod(method, level) {\n return function() {\n var args = arguments;\n // Filter out logs containing [vite]\n if (shouldFilterConsoleLog(args)) {\n return originalConsole[method].apply(console, args);\n }\n var entry = createLogEntry(level, args);\n addLog(entry);\n return originalConsole[method].apply(console, args);\n };\n }\n \n console.log = wrapConsoleMethod('log', 'log');\n console.info = wrapConsoleMethod('info', 'info');\n console.warn = wrapConsoleMethod('warn', 'warn');\n console.error = wrapConsoleMethod('error', 'error');\n console.debug = wrapConsoleMethod('debug', 'debug');\n \n // ============================================\n // Network request collection (exclude SSE and log API requests)\n // ============================================\n \n var MAX_BODY_SIZE = 2000;\n var MAX_LOG_ENTRY_SIZE = 3000; // Max single log entry length\n var MAX_HEADER_SIZE = 500; // Max single header object length\n var MAX_STACK_LINES = 5; // Max stack lines to keep\n const FILTERED_URLS = ['/__browser__', '/builtin']; // Filter out log API and Vite built-in requests\n \n function isSSERequest(url, headers) {\n var sseUrlPatterns = ['/events', '/sse', '/stream', 'text/event-stream'];\n var urlStr = String(url).toLowerCase();\n for (var i = 0; i < sseUrlPatterns.length; i++) {\n if (urlStr.indexOf(sseUrlPatterns[i]) !== -1) {\n return true;\n }\n }\n \n if (headers) {\n if (typeof headers.get === 'function') {\n var accept = headers.get('Accept') || headers.get('accept');\n if (accept && accept.indexOf('text/event-stream') !== -1) {\n return true;\n }\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n if (key.toLowerCase() === 'accept' && headers[key].indexOf('text/event-stream') !== -1) {\n return true;\n }\n }\n }\n }\n \n return false;\n }\n \n function shouldFilterRequest(url) {\n return FILTERED_URLS.some(function(filteredUrl) {\n return String(url).indexOf(filteredUrl) !== -1;\n });\n }\n \n function formatRequestBody(body) {\n if (!body) return null;\n \n try {\n if (typeof body === 'string') {\n return body.substring(0, MAX_BODY_SIZE);\n }\n if (body instanceof FormData) {\n var formDataObj = {};\n body.forEach(function(value, key) {\n if (value instanceof File) {\n formDataObj[key] = '[File: ' + value.name + ', size: ' + value.size + ']';\n } else {\n formDataObj[key] = String(value).substring(0, 1000);\n }\n });\n return JSON.stringify(formDataObj);\n }\n if (body instanceof Blob) {\n return '[Blob: size=' + body.size + ', type=' + body.type + ']';\n }\n if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {\n return '[Binary: size=' + body.byteLength + ']';\n }\n if (body instanceof URLSearchParams) {\n return body.toString().substring(0, MAX_BODY_SIZE);\n }\n return String(body).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading body: ' + e.message + ']';\n }\n }\n \n function formatResponseBody(response, responseType) {\n if (!response) return null;\n \n try {\n if (responseType === '' || responseType === 'text') {\n return String(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'json') {\n return JSON.stringify(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'document') {\n return '[Document]';\n }\n if (responseType === 'blob') {\n return '[Blob: size=' + response.size + ']';\n }\n if (responseType === 'arraybuffer') {\n return '[ArrayBuffer: size=' + response.byteLength + ']';\n }\n return String(response).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading response: ' + e.message + ']';\n }\n }\n \n // Intercept XMLHttpRequest\n var originalXHROpen = XMLHttpRequest.prototype.open;\n var originalXHRSend = XMLHttpRequest.prototype.send;\n var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;\n \n XMLHttpRequest.prototype.open = function(method, url, async, user, password) {\n this.__requestInfo__ = {\n method: method,\n url: url,\n startTime: null,\n headers: {}\n };\n return originalXHROpen.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.setRequestHeader = function(name, value) {\n if (this.__requestInfo__ && this.__requestInfo__.headers) {\n this.__requestInfo__.headers[name] = value;\n }\n return originalXHRSetRequestHeader.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.send = function(body) {\n var xhr = this;\n var requestInfo = xhr.__requestInfo__;\n \n if (requestInfo) {\n // Skip SSE requests and filtered requests\n if (isSSERequest(requestInfo.url, requestInfo.headers) || shouldFilterRequest(requestInfo.url)) {\n return originalXHRSend.apply(this, arguments);\n }\n \n requestInfo.startTime = Date.now();\n requestInfo.requestBody = formatRequestBody(body);\n \n xhr.addEventListener('loadend', function() {\n var contentType = xhr.getResponseHeader('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return;\n }\n \n var responseHeaders = {};\n var allHeaders = xhr.getAllResponseHeaders();\n if (allHeaders) {\n allHeaders.split('\\\\r\\\\n').forEach(function(line) {\n var parts = line.split(': ');\n if (parts.length === 2) {\n responseHeaders[parts[0]] = parts[1];\n }\n });\n }\n \n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'xhr',\n method: requestInfo.method,\n url: requestInfo.url,\n status: xhr.status,\n statusText: xhr.statusText,\n duration: Date.now() - requestInfo.startTime,\n requestHeaders: truncateHeaders(requestInfo.headers),\n requestBody: requestInfo.requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseType: xhr.responseType,\n responseBody: formatResponseBody(xhr.response, xhr.responseType),\n responseSize: xhr.response ? (typeof xhr.response === 'string' ? xhr.response.length : (xhr.response.byteLength || xhr.response.size || null)) : null\n };\n \n addLog(entry);\n });\n }\n \n return originalXHRSend.apply(this, arguments);\n };\n \n // Intercept Fetch API\n var originalFetch = window.fetch;\n \n function headersToObject(headers) {\n var obj = {};\n if (!headers) return obj;\n \n if (typeof headers.forEach === 'function') {\n headers.forEach(function(value, key) {\n obj[key] = value;\n });\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n obj[key] = headers[key];\n }\n }\n return obj;\n }\n \n window.fetch = function(input, init) {\n var startTime = Date.now();\n var method = (init && init.method) || 'GET';\n var url = typeof input === 'string' ? input : input.url;\n var headers = init && init.headers;\n \n // Skip SSE requests and filtered requests\n if (isSSERequest(url, headers) || shouldFilterRequest(url)) {\n return originalFetch.apply(this, arguments);\n }\n \n var requestHeaders = headersToObject(headers);\n var requestBody = formatRequestBody(init && init.body);\n \n return originalFetch.apply(this, arguments)\n .then(function(response) {\n var contentType = response.headers.get('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return response;\n }\n \n var clonedResponse = response.clone();\n var responseHeaders = headersToObject(response.headers);\n \n clonedResponse.text().then(function(bodyText) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: bodyText ? bodyText.substring(0, MAX_BODY_SIZE) : null,\n responseSize: bodyText ? bodyText.length : null,\n ok: response.ok\n };\n \n addLog(entry);\n }).catch(function(e) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: '[Unable to read: ' + e.message + ']',\n responseSize: null,\n ok: response.ok\n };\n \n addLog(entry);\n });\n \n return response;\n })\n .catch(function(error) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: 0,\n statusText: 'Network Error',\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: null,\n responseBody: null,\n error: error.message\n };\n \n addLog(entry);\n throw error;\n });\n };\n \n // ============================================\n // Global error capture\n // ============================================\n window.addEventListener('error', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: event.message,\n stack: event.error ? event.error.stack : 'at ' + event.filename + ':' + event.lineno + ':' + event.colno\n };\n addLog(entry);\n });\n \n // ============================================\n // Vite deps 504 error capture using PerformanceObserver\n // Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)\n // ============================================\n if (typeof PerformanceObserver !== 'undefined') {\n var reportedUrls = {}; // Track reported URLs to avoid duplicates\n \n var perfObserver = new PerformanceObserver(function(list) {\n var entries = list.getEntries();\n for (var i = 0; i < entries.length; i++) {\n var perfEntry = entries[i];\n // Only check script resources\n if (perfEntry.initiatorType !== 'script') {\n continue;\n }\n \n var resourceUrl = perfEntry.name || '';\n // Only report errors for node_modules/.vite resources\n if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {\n continue;\n }\n \n // Check if response status is 504 (Gateway Timeout)\n // responseStatus is available in Resource Timing Level 2\n var status = perfEntry.responseStatus;\n if (status === 504) {\n // Avoid duplicate reports\n if (reportedUrls[resourceUrl]) {\n continue;\n }\n reportedUrls[resourceUrl] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: resourceUrl,\n status: 504,\n message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,\n duration: perfEntry.duration,\n transferSize: perfEntry.transferSize\n };\n addLog(entry);\n }\n }\n });\n \n try {\n perfObserver.observe({ type: 'resource', buffered: true });\n } catch (e) {\n // Fallback for browsers that don't support the options\n try {\n perfObserver.observe({ entryTypes: ['resource'] });\n } catch (e2) {\n originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);\n }\n }\n }\n \n window.addEventListener('unhandledrejection', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: 'Unhandled Promise Rejection: ' + (event.reason ? (event.reason.message || String(event.reason)) : 'Unknown'),\n stack: event.reason && event.reason.stack ? event.reason.stack : ''\n };\n addLog(entry);\n });\n \n // ============================================\n // Send remaining logs on page unload\n // ============================================\n window.addEventListener('beforeunload', function() {\n if (writeQueue.length > 0) {\n // Use sendBeacon to ensure logs are sent\n writeQueue.forEach(function(entry) {\n navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));\n });\n writeQueue = [];\n }\n });\n \n // ============================================\n // Provide manual flush method\n // ============================================\n window.__flushBrowserLogs__ = function() {\n return new Promise(function(resolve) {\n // Wait for queue to finish processing\n function checkQueue() {\n if (writeQueue.length === 0 && !isWriting) {\n resolve();\n } else {\n setTimeout(checkQueue, 100);\n }\n }\n checkQueue();\n });\n };\n \n // Provide method to get queue status\n window.__getBrowserLogsStatus__ = function() {\n return {\n queueLength: writeQueue.length,\n isWriting: isWriting\n };\n };\n \n originalConsole.log('[BrowserLogs] Log collection started');\n})();\n</script>`;\n\n return {\n name: \"vite-plugin-browser-logs\",\n\n configResolved(config) {\n // Determine log file path: same level as index.html\n const root = config.root || process.cwd();\n logFilePath = path.join(root, \"browser.log\");\n },\n\n configureServer(devServer) {\n // Add log write API\n devServer.middlewares.use((req, res, next) => {\n if (req.url === \"/__browser__\" && req.method === \"POST\") {\n // Get request origin, dynamically set CORS headers to avoid protocol mismatch\n const origin = req.headers.origin || \"*\";\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString();\n });\n req.on(\"end\", () => {\n try {\n // Ensure log directory exists\n const logDir = path.dirname(logFilePath);\n if (!fs.existsSync(logDir)) {\n fs.mkdirSync(logDir, { recursive: true });\n }\n // Append to log file\n fs.appendFileSync(logFilePath, `${body}\\n`, \"utf-8\");\n res.writeHead(200, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: true }));\n } catch (error) {\n console.error(\"[BrowserLogs] Write error:\", error);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: false, error: String(error) }));\n }\n });\n } else if (req.url === \"/__browser__\" && req.method === \"OPTIONS\") {\n // Handle CORS preflight request\n const origin = req.headers.origin || \"*\";\n res.writeHead(204, {\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Max-Age\": \"86400\",\n });\n res.end();\n } else if (req.url === \"/__browser__\") {\n const origin = req.headers.origin || \"*\";\n res.writeHead(405, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n });\n res.end(JSON.stringify({ error: \"Method not allowed\" }));\n } else {\n next();\n }\n });\n\n console.log(\"[BrowserLogs] Logs will be written to:\", logFilePath);\n },\n\n transformIndexHtml(html) {\n // Insert script after <head> tag to ensure earliest execution\n return html.replace(/<head([^>]*)>/i, `<head$1>${injectedScript}`);\n },\n };\n}\n","import { componentIdPlugin } from \"./component-id\";\nimport { editorBridgePlugin } from \"./editor-bridge\";\nimport { routesExposePlugin } from \"./routes-expose\";\nimport { browserLogsPlugin } from \"./browser-logs\";\nimport process from \"node:process\";\nimport type { Plugin } from \"vite\";\n\n// 预留配置项目,目前没有可配置的\nexport interface DevToolsOptions {\n // 未来可添加配置项\n}\n\n/**\n * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可\n * @param _options 预留参数,用于未来扩展配置(例如可选择性启用某些插件)\n * @returns Plugin[] Vite 插件数组\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\nexport default function devTools(_options: DevToolsOptions = {}): Plugin[] {\n const plugins: Plugin[] = [\n componentIdPlugin(),\n editorBridgePlugin(),\n routesExposePlugin()\n ]\n\n // process.env.WORKSPACE_GIT_REPO 有这个表示是在 sandbox 里面运行,启用浏览器日志插件\n if (process.env.WORKSPACE_GIT_REPO) {\n plugins.push(browserLogsPlugin());\n }\n\n return plugins;\n}\n\nexport {\n componentIdPlugin,\n editorBridgePlugin,\n routesExposePlugin\n}"]}
1
+ {"version":3,"sources":["../src/component-id.ts","../src/editor-bridge.ts","../src/routes-expose.ts","../src/browser-logs.ts","../src/taro-env-inject.ts","../src/index.ts"],"names":["generateUniqueId","filePath","position","key","createHash","HTML_TAGS","componentIdPlugin","isDev","config","code","id","transformedCode","jsxOpenTagRegex","match","matches","tag","tagStartIndex","tagEndIndex","checkIndex","foundClosing","hasComponentId","currentCode","item","index","uniqueId","before","after","clickHandlerScript","getBridgeScriptContent","__filename","fileURLToPath","__dirname","dirname","bridgePath","resolve","readFileSync","error","editorBridgePlugin","bridgeScript","html","scriptsToInject","routesExposePlugin","options","routesPath","browserLogsPlugin","logFilePath","injectedScript","root","process","path","devServer","req","res","next","origin","body","chunk","logDir","fs","injectTaroEnv","additional","autoInjectTaroApp","autoInjectVite","constants","varsToInject","varName","value","injectAmasterEnv","devTools","_options","plugins"],"mappings":"4JAGA,SAASA,CAAAA,CAAiBC,CAAAA,CAAkBC,EAA0B,CACpE,IAAMC,EAAM,CAAA,EAAGF,CAAQ,IAAIC,CAAQ,CAAA,CAAA,CACnC,OAAOE,UAAAA,CAAW,KAAK,EAAE,MAAA,CAAOD,CAAG,CAAA,CAAE,MAAA,CAAO,KAAK,CAAA,CAAE,SAAA,CAAU,EAAG,EAAE,CACpE,CAEA,IAAME,CAAAA,CAAY,IAAI,GAAA,CAAI,CACxB,IAAK,MAAA,CAAQ,SAAA,CAAW,OAAQ,SAAA,CAAW,OAAA,CAAS,QAAS,GAAA,CAAK,MAAA,CAAQ,KAAA,CAAO,KAAA,CACjF,aAAc,MAAA,CAAQ,IAAA,CAAM,SAAU,QAAA,CAAU,SAAA,CAAW,OAAQ,MAAA,CAAQ,KAAA,CAC3E,WAAY,MAAA,CAAQ,UAAA,CAAY,KAAM,KAAA,CAAO,SAAA,CAAW,MAAO,QAAA,CAAU,KAAA,CAAO,KAChF,IAAA,CAAM,IAAA,CAAM,OAAA,CAAS,UAAA,CAAY,aAAc,QAAA,CAAU,QAAA,CAAU,OAAQ,IAAA,CAAM,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IAAMC,EAAQ,OAAA,CAAQ,GAAA,CAAID,CAAO,CAAA,EAAK,EAAA,CACtCF,CAAAA,CAAU,CAAA,YAAA,EAAeE,CAAO,EAAE,CAAA,CAAI,IAAA,CAAK,SAAA,CAAUC,CAAK,EAC5D,CAAC,CAAA,CAEMH,CACT,CAQO,SAASI,CAAAA,EAA2C,CACzD,OAAO,CACL,mCAAA,CAAqC,IAAA,CAAK,SAAA,CAAU,OAAA,CAAQ,IAAI,qBAAA,EAAyB,EAAE,CAAA,CAC3F,+BAAA,CAAiC,IAAA,CAAK,SAAA,CAAU,OAAA,CAAQ,GAAA,CAAI,mBAAqB,EAAE,CACrF,CACF,CC7Ee,SAARC,CAAAA,CAA0BC,CAAAA,CAA4B,EAAC,CAAa,CACvE,IAAMC,CAAAA,CAAoB,CACtBhE,CAAAA,EAAkB,CAClB+B,CAAAA,EAAmB,CACnBI,CAAAA,EACJ,CAAA,CAGA,OAAIO,CAAAA,CAAQ,GAAA,CAAI,oBACZsB,CAAAA,CAAQ,IAAA,CAAK1B,CAAAA,EAAmB,EAG7B0B,CACX","file":"index.js","sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { Plugin } from \"vite\";\n\nfunction generateUniqueId(filePath: string, position: number): string {\n const key = `${filePath}:${position}`;\n return createHash(\"md5\").update(key).digest(\"hex\").substring(0, 12);\n}\n\nconst HTML_TAGS = new Set([\n \"a\", \"abbr\", \"address\", \"area\", \"article\", \"aside\", \"audio\", \"b\", \"base\", \"bdi\", \"bdo\",\n \"blockquote\", \"body\", \"br\", \"button\", \"canvas\", \"caption\", \"cite\", \"code\", \"col\",\n \"colgroup\", \"data\", \"datalist\", \"dd\", \"del\", \"details\", \"dfn\", \"dialog\", \"div\", \"dl\",\n \"dt\", \"em\", \"embed\", \"fieldset\", \"figcaption\", \"figure\", \"footer\", \"form\", \"h1\", \"h2\",\n \"h3\", \"h4\", \"h5\", \"h6\", \"head\", \"header\", \"hgroup\", \"hr\", \"html\", \"i\", \"iframe\", \"img\",\n \"input\", \"ins\", \"kbd\", \"label\", \"legend\", \"li\", \"link\", \"main\", \"map\", \"mark\", \"meta\",\n \"meter\", \"nav\", \"noscript\", \"object\", \"ol\", \"optgroup\", \"option\", \"output\", \"p\", \"param\",\n \"picture\", \"pre\", \"progress\", \"q\", \"rp\", \"rt\", \"ruby\", \"s\", \"samp\", \"script\", \"section\",\n \"select\", \"small\", \"source\", \"span\", \"strong\", \"style\", \"sub\", \"summary\", \"sup\", \"svg\",\n \"table\", \"tbody\", \"td\", \"template\", \"textarea\", \"tfoot\", \"th\", \"thead\", \"time\", \"title\",\n \"tr\", \"track\", \"u\", \"ul\", \"var\", \"video\", \"wbr\",\n]);\n\n/**\n * Vite plugin: Add data-node-component-id to React components\n * Only enabled in development mode\n */\nexport function componentIdPlugin(): Plugin {\n let isDev = false;\n\n return {\n name: \"vite-plugin-component-id\",\n enforce: \"pre\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!/\\.(tsx|jsx)$/.test(id)) {\n return null;\n }\n\n if (id.includes(\"node_modules\")) {\n return null;\n }\n\n if (!/<[a-z]/.test(code)) {\n return null;\n }\n\n try {\n let transformedCode = code;\n const jsxOpenTagRegex = /<([a-z][\\da-z]*)(?=[\\s/>])/g;\n\n let match: RegExpExecArray | null;\n const matches: Array<{ index: number; tag: string; tagEndIndex: number }> = [];\n\n while ((match = jsxOpenTagRegex.exec(code)) !== null) {\n const tag = match[1];\n if (!tag) continue;\n \n const tagStartIndex = match.index;\n const tagEndIndex = match.index + match[0].length;\n\n if (!HTML_TAGS.has(tag)) {\n continue;\n }\n\n let checkIndex = tagEndIndex;\n let foundClosing = false;\n let hasComponentId = false;\n\n while (checkIndex < code.length && !foundClosing) {\n const char = code[checkIndex];\n if (char === \">\") {\n foundClosing = true;\n const tagContent = code.substring(tagStartIndex, checkIndex);\n if (tagContent.includes(\"data-node-component-id\")) {\n hasComponentId = true;\n }\n }\n checkIndex++;\n }\n\n if (hasComponentId) {\n continue;\n }\n\n matches.push({\n index: tagStartIndex,\n tag,\n tagEndIndex,\n });\n }\n\n let currentCode = code;\n for (let i = matches.length - 1; i >= 0; i--) {\n const item = matches[i];\n if (!item) continue;\n \n const { index, tagEndIndex } = item;\n const uniqueId = generateUniqueId(id, index);\n\n const before = currentCode.substring(0, tagEndIndex);\n const after = currentCode.substring(tagEndIndex);\n\n transformedCode = `${before} data-node-component-id=\"${uniqueId}\"${after}`;\n currentCode = transformedCode;\n }\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { readFileSync } from \"fs\";\nimport { resolve, dirname } from \"path\";\nimport { fileURLToPath } from \"url\";\n\nconst clickHandlerScript = `<script>\ndocument.addEventListener(\"click\", (e) => {\n const element = e.target;\n const noJumpOut = document.body.classList.contains(\"forbid-jump-out\")\n if (element.hasAttribute(\"data-link-href\") && !noJumpOut) {\n const href = element.getAttribute(\"data-link-href\");\n const target = element.getAttribute(\"data-link-target\");\n if (href) {\n if (target === \"_blank\") {\n window.open(href, \"_blank\");\n } else {\n window.location.href = href;\n }\n }\n } else if(noJumpOut && element.tagName === \"A\") {\n e.preventDefault();\n }\n});\n</script>`;\n\n/**\n * 读取构建后的 bridge 脚本内容\n */\nfunction getBridgeScriptContent(): string {\n try {\n // 获取当前模块的目录\n const __filename = fileURLToPath(import.meta.url);\n const __dirname = dirname(__filename);\n \n // 读取构建后的 bridge.bridge.js 文件\n const bridgePath = resolve(__dirname, \"../dist/bridge.bridge.js\");\n const bridgeContent = readFileSync(bridgePath, \"utf-8\");\n \n return `<script>\\n${bridgeContent}\\n</script>`;\n } catch (error) {\n console.warn(\"Failed to read bridge script:\", error);\n return \"\";\n }\n}\n\n/**\n * Vite plugin: Inject editor bridge script\n * Injects bridge.js in development mode by reading the built bridge script\n */\nexport function editorBridgePlugin(): Plugin {\n let isDev = false;\n let bridgeScript = \"\";\n\n return {\n name: \"vite-plugin-editor-bridge\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n \n // 在开发模式下读取 bridge 脚本内容\n if (isDev) {\n bridgeScript = getBridgeScriptContent();\n }\n },\n\n transformIndexHtml(html) {\n // 在开发模式下注入 bridge 脚本\n const devScript = isDev ? bridgeScript : \"\";\n\n const scriptsToInject = `${clickHandlerScript}${devScript}</body>`;\n\n return html.replace(\"</body>\", scriptsToInject);\n },\n };\n}\n","import type { Plugin } from \"vite\";\n\n/**\n * Vite plugin: Expose routes to window.__APP_ROUTES__\n * Only enabled in development mode\n */\nexport function routesExposePlugin(options?: { routesFilePath?: string }): Plugin {\n let isDev = false;\n const routesPath = options?.routesFilePath || \"src/routes.tsx\";\n\n return {\n name: \"vite-plugin-routes-expose\",\n enforce: \"post\",\n\n configResolved(config) {\n isDev = config.command === \"serve\";\n },\n\n transform(code: string, id: string) {\n if (!isDev) {\n return null;\n }\n\n if (!id.endsWith(routesPath)) {\n return null;\n }\n\n try {\n if (code.includes(\"window.__APP_ROUTES__\")) {\n return null;\n }\n\n const transformedCode = `${code}\n\n// Development mode: Expose routes to window.__APP_ROUTES__\nif (typeof window !== 'undefined') {\n window.__APP_ROUTES__ = typeof routes !== 'undefined' && Array.isArray(routes) ? routes : [];\n}\n`;\n\n return {\n code: transformedCode,\n map: null,\n };\n } catch {\n return null;\n }\n },\n };\n}\n","import type { Plugin } from \"vite\";\nimport { Buffer } from \"node:buffer\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport process from \"node:process\";\n\n/**\n * Browser logs collection plugin\n * Injects script into HTML head to collect console logs and network requests\n * Logs are written directly to browser.log file (same level as index.html)\n */\nexport function browserLogsPlugin(): Plugin {\n let logFilePath = \"\";\n\n // Script to inject into browser\n const injectedScript = `\n<script>\n(function() {\n 'use strict';\n \n // Log API path (provided by Vite dev server)\n var LOG_API_PATH = '/__browser__';\n \n // Write queue to ensure sequential writes\n var writeQueue = [];\n var isWriting = false;\n \n // Process write queue to ensure sequential writes\n function processWriteQueue() {\n if (isWriting || writeQueue.length === 0) return;\n \n isWriting = true;\n var entry = writeQueue.shift();\n var logText = JSON.stringify(entry);\n \n fetch(LOG_API_PATH, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: logText\n })\n .then(function(response) {\n isWriting = false;\n if (!response.ok) {\n console.warn('[BrowserLogs] Failed to write log:', response.status);\n }\n // Continue processing next item in queue\n processWriteQueue();\n })\n .catch(function(error) {\n console.warn('[BrowserLogs] Failed to write log:', error.message);\n // On failure, put log back to queue head for retry\n writeQueue.unshift(entry);\n isWriting = false;\n // Retry after delay\n setTimeout(processWriteQueue, 1000);\n });\n }\n \n // Limit headers object size\n function truncateHeaders(headers) {\n if (!headers) return headers;\n var jsonStr = JSON.stringify(headers);\n if (jsonStr.length <= MAX_HEADER_SIZE) return headers;\n return '[Headers truncated, size: ' + jsonStr.length + ']';\n }\n \n // Truncate oversized log entries\n function truncateLogEntry(entry) {\n var jsonStr = JSON.stringify(entry);\n if (jsonStr.length <= MAX_LOG_ENTRY_SIZE) {\n return entry;\n }\n \n // If oversized, progressively truncate non-critical fields\n var truncated = Object.assign({}, entry);\n \n // 1. Truncate response body first\n if (truncated.responseBody && typeof truncated.responseBody === 'string') {\n truncated.responseBody = truncated.responseBody.substring(0, 500) + '... [truncated]';\n }\n \n // 2. Truncate request body\n if (truncated.requestBody && typeof truncated.requestBody === 'string') {\n truncated.requestBody = truncated.requestBody.substring(0, 500) + '... [truncated]';\n }\n \n // 3. Truncate message\n if (truncated.message && typeof truncated.message === 'string' && truncated.message.length > 1000) {\n truncated.message = truncated.message.substring(0, 1000) + '... [truncated]';\n }\n \n // 4. Truncate stack\n if (truncated.stack && Array.isArray(truncated.stack) && truncated.stack.length > 3) {\n truncated.stack = truncated.stack.slice(0, 3);\n }\n \n // Add truncation marker\n truncated._truncated = true;\n truncated._originalSize = jsonStr.length;\n \n return truncated;\n }\n \n // Add log and send immediately (ensure order)\n function addLog(entry) {\n var truncatedEntry = truncateLogEntry(entry);\n writeQueue.push(truncatedEntry);\n processWriteQueue();\n }\n \n // ============================================\n // Console log collection\n // ============================================\n var originalConsole = {\n log: console.log,\n info: console.info,\n warn: console.warn,\n error: console.error,\n debug: console.debug\n };\n \n function getStackTrace() {\n var stack = new Error().stack || '';\n var lines = stack.split('\\\\n').slice(3);\n // Limit stack lines\n return lines.slice(0, MAX_STACK_LINES).map(function(line) { return line.trim(); });\n }\n \n function formatMessage(args) {\n return Array.from(args).map(function(arg) {\n if (arg === null) return 'null';\n if (arg === undefined) return 'undefined';\n if (typeof arg === 'object') {\n try {\n return JSON.stringify(arg);\n } catch (e) {\n return String(arg);\n }\n }\n return String(arg);\n }).join(' ');\n }\n \n function createLogEntry(level, args) {\n return {\n type: 'console',\n timestamp: new Date().toISOString(),\n level: level,\n message: formatMessage(args),\n stack: getStackTrace()\n };\n }\n \n // Check if message should be filtered (contains [vite] text)\n function shouldFilterConsoleLog(args) {\n for (var i = 0; i < args.length; i++) {\n var arg = args[i];\n if (typeof arg === 'string' && arg.indexOf('[vite]') !== -1) {\n return true;\n }\n }\n return false;\n }\n \n function wrapConsoleMethod(method, level) {\n return function() {\n var args = arguments;\n // Filter out logs containing [vite]\n if (shouldFilterConsoleLog(args)) {\n return originalConsole[method].apply(console, args);\n }\n var entry = createLogEntry(level, args);\n addLog(entry);\n return originalConsole[method].apply(console, args);\n };\n }\n \n console.log = wrapConsoleMethod('log', 'log');\n console.info = wrapConsoleMethod('info', 'info');\n console.warn = wrapConsoleMethod('warn', 'warn');\n console.error = wrapConsoleMethod('error', 'error');\n console.debug = wrapConsoleMethod('debug', 'debug');\n \n // ============================================\n // Network request collection (exclude SSE and log API requests)\n // ============================================\n \n var MAX_BODY_SIZE = 2000;\n var MAX_LOG_ENTRY_SIZE = 3000; // Max single log entry length\n var MAX_HEADER_SIZE = 500; // Max single header object length\n var MAX_STACK_LINES = 5; // Max stack lines to keep\n const FILTERED_URLS = ['/__browser__', '/builtin']; // Filter out log API and Vite built-in requests\n \n function isSSERequest(url, headers) {\n var sseUrlPatterns = ['/events', '/sse', '/stream', 'text/event-stream'];\n var urlStr = String(url).toLowerCase();\n for (var i = 0; i < sseUrlPatterns.length; i++) {\n if (urlStr.indexOf(sseUrlPatterns[i]) !== -1) {\n return true;\n }\n }\n \n if (headers) {\n if (typeof headers.get === 'function') {\n var accept = headers.get('Accept') || headers.get('accept');\n if (accept && accept.indexOf('text/event-stream') !== -1) {\n return true;\n }\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n if (key.toLowerCase() === 'accept' && headers[key].indexOf('text/event-stream') !== -1) {\n return true;\n }\n }\n }\n }\n \n return false;\n }\n \n function shouldFilterRequest(url) {\n return FILTERED_URLS.some(function(filteredUrl) {\n return String(url).indexOf(filteredUrl) !== -1;\n });\n }\n \n function formatRequestBody(body) {\n if (!body) return null;\n \n try {\n if (typeof body === 'string') {\n return body.substring(0, MAX_BODY_SIZE);\n }\n if (body instanceof FormData) {\n var formDataObj = {};\n body.forEach(function(value, key) {\n if (value instanceof File) {\n formDataObj[key] = '[File: ' + value.name + ', size: ' + value.size + ']';\n } else {\n formDataObj[key] = String(value).substring(0, 1000);\n }\n });\n return JSON.stringify(formDataObj);\n }\n if (body instanceof Blob) {\n return '[Blob: size=' + body.size + ', type=' + body.type + ']';\n }\n if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) {\n return '[Binary: size=' + body.byteLength + ']';\n }\n if (body instanceof URLSearchParams) {\n return body.toString().substring(0, MAX_BODY_SIZE);\n }\n return String(body).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading body: ' + e.message + ']';\n }\n }\n \n function formatResponseBody(response, responseType) {\n if (!response) return null;\n \n try {\n if (responseType === '' || responseType === 'text') {\n return String(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'json') {\n return JSON.stringify(response).substring(0, MAX_BODY_SIZE);\n }\n if (responseType === 'document') {\n return '[Document]';\n }\n if (responseType === 'blob') {\n return '[Blob: size=' + response.size + ']';\n }\n if (responseType === 'arraybuffer') {\n return '[ArrayBuffer: size=' + response.byteLength + ']';\n }\n return String(response).substring(0, MAX_BODY_SIZE);\n } catch (e) {\n return '[Error reading response: ' + e.message + ']';\n }\n }\n \n // Intercept XMLHttpRequest\n var originalXHROpen = XMLHttpRequest.prototype.open;\n var originalXHRSend = XMLHttpRequest.prototype.send;\n var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader;\n \n XMLHttpRequest.prototype.open = function(method, url, async, user, password) {\n this.__requestInfo__ = {\n method: method,\n url: url,\n startTime: null,\n headers: {}\n };\n return originalXHROpen.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.setRequestHeader = function(name, value) {\n if (this.__requestInfo__ && this.__requestInfo__.headers) {\n this.__requestInfo__.headers[name] = value;\n }\n return originalXHRSetRequestHeader.apply(this, arguments);\n };\n \n XMLHttpRequest.prototype.send = function(body) {\n var xhr = this;\n var requestInfo = xhr.__requestInfo__;\n \n if (requestInfo) {\n // Skip SSE requests and filtered requests\n if (isSSERequest(requestInfo.url, requestInfo.headers) || shouldFilterRequest(requestInfo.url)) {\n return originalXHRSend.apply(this, arguments);\n }\n \n requestInfo.startTime = Date.now();\n requestInfo.requestBody = formatRequestBody(body);\n \n xhr.addEventListener('loadend', function() {\n var contentType = xhr.getResponseHeader('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return;\n }\n \n var responseHeaders = {};\n var allHeaders = xhr.getAllResponseHeaders();\n if (allHeaders) {\n allHeaders.split('\\\\r\\\\n').forEach(function(line) {\n var parts = line.split(': ');\n if (parts.length === 2) {\n responseHeaders[parts[0]] = parts[1];\n }\n });\n }\n \n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'xhr',\n method: requestInfo.method,\n url: requestInfo.url,\n status: xhr.status,\n statusText: xhr.statusText,\n duration: Date.now() - requestInfo.startTime,\n requestHeaders: truncateHeaders(requestInfo.headers),\n requestBody: requestInfo.requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseType: xhr.responseType,\n responseBody: formatResponseBody(xhr.response, xhr.responseType),\n responseSize: xhr.response ? (typeof xhr.response === 'string' ? xhr.response.length : (xhr.response.byteLength || xhr.response.size || null)) : null\n };\n \n addLog(entry);\n });\n }\n \n return originalXHRSend.apply(this, arguments);\n };\n \n // Intercept Fetch API\n var originalFetch = window.fetch;\n \n function headersToObject(headers) {\n var obj = {};\n if (!headers) return obj;\n \n if (typeof headers.forEach === 'function') {\n headers.forEach(function(value, key) {\n obj[key] = value;\n });\n } else if (typeof headers === 'object') {\n for (var key in headers) {\n obj[key] = headers[key];\n }\n }\n return obj;\n }\n \n window.fetch = function(input, init) {\n var startTime = Date.now();\n var method = (init && init.method) || 'GET';\n var url = typeof input === 'string' ? input : input.url;\n var headers = init && init.headers;\n \n // Skip SSE requests and filtered requests\n if (isSSERequest(url, headers) || shouldFilterRequest(url)) {\n return originalFetch.apply(this, arguments);\n }\n \n var requestHeaders = headersToObject(headers);\n var requestBody = formatRequestBody(init && init.body);\n \n return originalFetch.apply(this, arguments)\n .then(function(response) {\n var contentType = response.headers.get('Content-Type') || '';\n if (contentType.indexOf('text/event-stream') !== -1) {\n return response;\n }\n \n var clonedResponse = response.clone();\n var responseHeaders = headersToObject(response.headers);\n \n clonedResponse.text().then(function(bodyText) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: bodyText ? bodyText.substring(0, MAX_BODY_SIZE) : null,\n responseSize: bodyText ? bodyText.length : null,\n ok: response.ok\n };\n \n addLog(entry);\n }).catch(function(e) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: response.status,\n statusText: response.statusText,\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: truncateHeaders(responseHeaders),\n responseBody: '[Unable to read: ' + e.message + ']',\n responseSize: null,\n ok: response.ok\n };\n \n addLog(entry);\n });\n \n return response;\n })\n .catch(function(error) {\n var entry = {\n type: 'request',\n timestamp: new Date().toISOString(),\n requestType: 'fetch',\n method: method,\n url: url,\n status: 0,\n statusText: 'Network Error',\n duration: Date.now() - startTime,\n requestHeaders: truncateHeaders(requestHeaders),\n requestBody: requestBody,\n responseHeaders: null,\n responseBody: null,\n error: error.message\n };\n \n addLog(entry);\n throw error;\n });\n };\n \n // ============================================\n // Global error capture\n // ============================================\n window.addEventListener('error', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: event.message,\n stack: event.error ? event.error.stack : 'at ' + event.filename + ':' + event.lineno + ':' + event.colno\n };\n addLog(entry);\n });\n \n // ============================================\n // Vite deps 504 error capture using PerformanceObserver\n // Only captures 504 errors for node_modules/.vite resources (pre-bundled dependencies)\n // ============================================\n if (typeof PerformanceObserver !== 'undefined') {\n var reportedUrls = {}; // Track reported URLs to avoid duplicates\n \n var perfObserver = new PerformanceObserver(function(list) {\n var entries = list.getEntries();\n for (var i = 0; i < entries.length; i++) {\n var perfEntry = entries[i];\n // Only check script resources\n if (perfEntry.initiatorType !== 'script') {\n continue;\n }\n \n var resourceUrl = perfEntry.name || '';\n // Only report errors for node_modules/.vite resources\n if (resourceUrl.indexOf('node_modules/.vite') === -1 && resourceUrl.indexOf('/node_modules/.vite') === -1) {\n continue;\n }\n \n // Check if response status is 504 (Gateway Timeout)\n // responseStatus is available in Resource Timing Level 2\n var status = perfEntry.responseStatus;\n if (status === 504) {\n // Avoid duplicate reports\n if (reportedUrls[resourceUrl]) {\n continue;\n }\n reportedUrls[resourceUrl] = true;\n \n var entry = {\n type: 'vite-deps-error',\n timestamp: new Date().toISOString(),\n level: 'error',\n url: resourceUrl,\n status: 504,\n message: 'Vite pre-bundled dependency returned 504 Gateway Timeout: ' + resourceUrl,\n duration: perfEntry.duration,\n transferSize: perfEntry.transferSize\n };\n addLog(entry);\n }\n }\n });\n \n try {\n perfObserver.observe({ type: 'resource', buffered: true });\n } catch (e) {\n // Fallback for browsers that don't support the options\n try {\n perfObserver.observe({ entryTypes: ['resource'] });\n } catch (e2) {\n originalConsole.warn('[BrowserLogs] PerformanceObserver not supported:', e2.message);\n }\n }\n }\n \n window.addEventListener('unhandledrejection', function(event) {\n var entry = {\n type: 'error',\n timestamp: new Date().toISOString(),\n level: 'error',\n message: 'Unhandled Promise Rejection: ' + (event.reason ? (event.reason.message || String(event.reason)) : 'Unknown'),\n stack: event.reason && event.reason.stack ? event.reason.stack : ''\n };\n addLog(entry);\n });\n \n // ============================================\n // Send remaining logs on page unload\n // ============================================\n window.addEventListener('beforeunload', function() {\n if (writeQueue.length > 0) {\n // Use sendBeacon to ensure logs are sent\n writeQueue.forEach(function(entry) {\n navigator.sendBeacon(LOG_API_PATH, JSON.stringify(entry));\n });\n writeQueue = [];\n }\n });\n \n // ============================================\n // Provide manual flush method\n // ============================================\n window.__flushBrowserLogs__ = function() {\n return new Promise(function(resolve) {\n // Wait for queue to finish processing\n function checkQueue() {\n if (writeQueue.length === 0 && !isWriting) {\n resolve();\n } else {\n setTimeout(checkQueue, 100);\n }\n }\n checkQueue();\n });\n };\n \n // Provide method to get queue status\n window.__getBrowserLogsStatus__ = function() {\n return {\n queueLength: writeQueue.length,\n isWriting: isWriting\n };\n };\n \n originalConsole.log('[BrowserLogs] Log collection started');\n})();\n</script>`;\n\n return {\n name: \"vite-plugin-browser-logs\",\n\n configResolved(config) {\n // Determine log file path: same level as index.html\n const root = config.root || process.cwd();\n logFilePath = path.join(root, \"browser.log\");\n },\n\n configureServer(devServer) {\n // Add log write API\n devServer.middlewares.use((req, res, next) => {\n if (req.url === \"/__browser__\" && req.method === \"POST\") {\n // Get request origin, dynamically set CORS headers to avoid protocol mismatch\n const origin = req.headers.origin || \"*\";\n\n let body = \"\";\n req.on(\"data\", (chunk: Buffer) => {\n body += chunk.toString();\n });\n req.on(\"end\", () => {\n try {\n // Ensure log directory exists\n const logDir = path.dirname(logFilePath);\n if (!fs.existsSync(logDir)) {\n fs.mkdirSync(logDir, { recursive: true });\n }\n // Append to log file\n fs.appendFileSync(logFilePath, `${body}\\n`, \"utf-8\");\n res.writeHead(200, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: true }));\n } catch (error) {\n console.error(\"[BrowserLogs] Write error:\", error);\n res.writeHead(500, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n });\n res.end(JSON.stringify({ success: false, error: String(error) }));\n }\n });\n } else if (req.url === \"/__browser__\" && req.method === \"OPTIONS\") {\n // Handle CORS preflight request\n const origin = req.headers.origin || \"*\";\n res.writeHead(204, {\n \"Access-Control-Allow-Origin\": origin,\n \"Access-Control-Allow-Methods\": \"POST, OPTIONS\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Max-Age\": \"86400\",\n });\n res.end();\n } else if (req.url === \"/__browser__\") {\n const origin = req.headers.origin || \"*\";\n res.writeHead(405, {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": origin,\n });\n res.end(JSON.stringify({ error: \"Method not allowed\" }));\n } else {\n next();\n }\n });\n\n console.log(\"[BrowserLogs] Logs will be written to:\", logFilePath);\n },\n\n transformIndexHtml(html) {\n // Insert script after <head> tag to ensure earliest execution\n return html.replace(/<head([^>]*)>/i, `<head$1>${injectedScript}`);\n },\n };\n}\n","/**\n * Taro Environment Variables Injection Helper\n * \n * Automatically injects environment variables into Taro's defineConstants\n * so that they will be replaced at build time.\n * \n * @example\n * ```ts\n * // In Taro config/index.ts\n * import { injectTaroEnv } from '@amaster.ai/vite-plugins/taro-env-inject'\n * \n * export default defineConfig({\n * defineConstants: {\n * ...injectTaroEnv()\n * }\n * })\n * ```\n */\n\nexport interface TaroEnvInjectOptions {\n /**\n * Additional environment variable names to inject\n * @default []\n */\n additional?: string[];\n \n /**\n * Whether to inject all TARO_APP_* prefixed variables\n * @default true\n */\n autoInjectTaroApp?: boolean;\n \n /**\n * Whether to inject all VITE_* prefixed variables\n * @default true\n */\n autoInjectVite?: boolean;\n}\n\n/**\n * Inject environment variables into Taro's defineConstants\n * \n * This function reads environment variables and formats them for Taro's defineConstants.\n * Taro will replace these at build time, converting `process.env.XXX` to actual values.\n */\nexport function injectTaroEnv(options: TaroEnvInjectOptions = {}): Record<string, string> {\n const {\n additional = [],\n autoInjectTaroApp = true,\n autoInjectVite = true,\n } = options;\n\n const constants: Record<string, string> = {};\n\n // Collect variable names to inject\n const varsToInject = new Set<string>(additional);\n\n // Auto-detect TARO_APP_* variables\n if (autoInjectTaroApp) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('TARO_APP_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Auto-detect VITE_* variables\n if (autoInjectVite) {\n Object.keys(process.env).forEach(key => {\n if (key.startsWith('VITE_')) {\n varsToInject.add(key);\n }\n });\n }\n\n // Inject variables into defineConstants format\n varsToInject.forEach(varName => {\n const value = process.env[varName] || '';\n constants[`process.env.${varName}`] = JSON.stringify(value);\n });\n\n return constants;\n}\n\n/**\n * Inject specific environment variables for amaster.ai mini-program builds\n * \n * This is a convenience function that injects the standard environment variables\n * used by @amaster.ai/http-client for API base URL configuration.\n */\nexport function injectAmasterEnv(): Record<string, string> {\n return {\n 'process.env.TARO_APP_API_BASE_URL': JSON.stringify(process.env.TARO_APP_API_BASE_URL || ''),\n 'process.env.VITE_API_BASE_URL': JSON.stringify(process.env.VITE_API_BASE_URL || ''),\n };\n}\n","import { componentIdPlugin } from \"./component-id\";\nimport { editorBridgePlugin } from \"./editor-bridge\";\nimport { routesExposePlugin } from \"./routes-expose\";\nimport { browserLogsPlugin } from \"./browser-logs\";\nimport process from \"node:process\";\nimport type { Plugin } from \"vite\";\n\n// 预留配置项目,目前没有可配置的\nexport interface DevToolsOptions {\n // 未来可添加配置项\n}\n\n/**\n * 开发工具插件集合,简化调用,vite.config.ts 直接 devTools() 即可\n * @param _options 预留参数,用于未来扩展配置(例如可选择性启用某些插件)\n * @returns Plugin[] Vite 插件数组\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars\nexport default function devTools(_options: DevToolsOptions = {}): Plugin[] {\n const plugins: Plugin[] = [\n componentIdPlugin(),\n editorBridgePlugin(),\n routesExposePlugin()\n ]\n\n // process.env.WORKSPACE_GIT_REPO 有这个表示是在 sandbox 里面运行,启用浏览器日志插件\n if (process.env.WORKSPACE_GIT_REPO) {\n plugins.push(browserLogsPlugin());\n }\n\n return plugins;\n}\n\nexport {\n componentIdPlugin,\n editorBridgePlugin,\n routesExposePlugin\n}\n\n// Export Taro environment injection helpers\nexport { injectTaroEnv, injectAmasterEnv } from \"./taro-env-inject\";"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amaster.ai/vite-plugins",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.13",
4
4
  "description": "Collection of Vite plugins for React applications",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",