@adep/vite-plugin 0.1.7 → 0.1.8

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.
@@ -44,8 +44,10 @@ export declare const FN_FETCH_INTERCEPTOR_SCRIPT = "(function () {\n if (window
44
44
  *
45
45
  * 信封 `{ source: 'adep-ide-preview', kind: 'console', level, text }` 由 IDE 的
46
46
  * `FrontendPreview.onMessage` 消费;`window.parent === window`(直接打开 / 分享链接)不发。
47
+ * 另侦测 vite 构建错误浮层(`vite-error-overlay`),以 `{ kind: 'build-error', message,
48
+ * file?, line?, column? }` 回传——报错收件箱 `source: 'build'` 的生产端(VIBE-011)。
47
49
  */
48
- export declare const CONSOLE_RELAY_SCRIPT = "(function () {\n if (window.__adepErrorRelayInstalled) return;\n window.__adepErrorRelayInstalled = true;\n var LEVELS = { log: \"log\", info: \"info\", warn: \"warn\", error: \"error\", debug: \"log\" };\n function fmt(value) {\n try {\n if (typeof value === \"string\") return value;\n if (value === undefined) return \"undefined\";\n var seen = [];\n var json = JSON.stringify(value, function (key, val) {\n if (val instanceof Error) return val.stack || (val.name + \": \" + val.message);\n if (typeof val === \"function\") return \"[Function \" + (val.name || \"anonymous\") + \"]\";\n if (typeof val === \"bigint\") return String(val) + \"n\";\n if (val && typeof val === \"object\") {\n if (seen.indexOf(val) !== -1) return \"[Circular]\";\n seen.push(val);\n }\n return val;\n });\n return json === undefined ? String(value) : json;\n } catch {\n return String(value);\n }\n }\n function send(level, args) {\n try {\n if (window.parent === window) return;\n var text = Array.prototype.map.call(args, fmt).join(\" \");\n window.parent.postMessage({ source: \"adep-ide-preview\", kind: \"console\", level: level, text: text }, \"*\");\n } catch {\n }\n }\n Object.keys(LEVELS).forEach(function (name) {\n var native = console[name];\n console[name] = function () {\n send(LEVELS[name], arguments);\n native.apply(console, arguments);\n };\n });\n window.addEventListener('error', function (event) {\n var text = event.message || \"Script error\";\n if (event.filename) {\n text += \" (\" + event.filename + \":\" + event.lineno + \":\" + event.colno + \")\";\n }\n send(\"error\", [text]);\n });\n window.addEventListener('unhandledrejection', function (event) {\n var reason = event.reason;\n var text = reason && reason.stack ? String(reason.stack) : \"Unhandled rejection: \" + fmt(reason);\n send(\"error\", [text]);\n });\n})();\n";
50
+ export declare const CONSOLE_RELAY_SCRIPT = "(function () {\n if (window.__adepErrorRelayInstalled) return;\n window.__adepErrorRelayInstalled = true;\n var LEVELS = { log: \"log\", info: \"info\", warn: \"warn\", error: \"error\", debug: \"log\" };\n function fmt(value) {\n try {\n if (typeof value === \"string\") return value;\n if (value === undefined) return \"undefined\";\n var seen = [];\n var json = JSON.stringify(value, function (key, val) {\n if (val instanceof Error) return val.stack || (val.name + \": \" + val.message);\n if (typeof val === \"function\") return \"[Function \" + (val.name || \"anonymous\") + \"]\";\n if (typeof val === \"bigint\") return String(val) + \"n\";\n if (val && typeof val === \"object\") {\n if (seen.indexOf(val) !== -1) return \"[Circular]\";\n seen.push(val);\n }\n return val;\n });\n return json === undefined ? String(value) : json;\n } catch {\n return String(value);\n }\n }\n function send(level, args) {\n try {\n if (window.parent === window) return;\n var text = Array.prototype.map.call(args, fmt).join(\" \");\n window.parent.postMessage({ source: \"adep-ide-preview\", kind: \"console\", level: level, text: text }, \"*\");\n } catch {\n }\n }\n Object.keys(LEVELS).forEach(function (name) {\n var native = console[name];\n console[name] = function () {\n send(LEVELS[name], arguments);\n native.apply(console, arguments);\n };\n });\n window.addEventListener('error', function (event) {\n var text = event.message || \"Script error\";\n if (event.filename) {\n text += \" (\" + event.filename + \":\" + event.lineno + \":\" + event.colno + \")\";\n }\n send(\"error\", [text]);\n });\n window.addEventListener('unhandledrejection', function (event) {\n var reason = event.reason;\n var text = reason && reason.stack ? String(reason.stack) : \"Unhandled rejection: \" + fmt(reason);\n send(\"error\", [text]);\n });\n function reportBuildError(overlay) {\n try {\n if (window.parent === window) return;\n var root = overlay.shadowRoot;\n if (!root) return;\n var msgEl = root.querySelector(\".message\");\n var message = msgEl ? String(msgEl.textContent || \"\").trim() : \"\";\n if (!message) return;\n var payload = { source: \"adep-ide-preview\", kind: \"build-error\", message: message };\n var fileEl = root.querySelector(\".file\");\n if (fileEl) {\n var loc = /^(.*?):(\\d+):(\\d+)$/.exec(String(fileEl.textContent || \"\").trim());\n if (loc) {\n payload.file = loc[1];\n payload.line = Number(loc[2]);\n payload.column = Number(loc[3]);\n }\n }\n window.parent.postMessage(payload, \"*\");\n } catch {\n }\n }\n function watchOverlays(scope) {\n if (!scope || typeof MutationObserver === \"undefined\") return;\n new MutationObserver(function (records) {\n for (var i = 0; i < records.length; i++) {\n var added = records[i].addedNodes;\n for (var j = 0; j < added.length; j++) {\n var node = added[j];\n if (node.nodeType === 1 && /^vite-error-overlay$/i.test(node.tagName || \"\")) reportBuildError(node);\n }\n }\n }).observe(scope, { childList: true, subtree: true });\n }\n if (typeof document !== \"undefined\" && document.documentElement) watchOverlays(document.documentElement);\n})();\n";
49
51
  /**
50
52
  * 构造中间件:serve `/@adep/fn-proxy.js`(返回上面的拦截器脚本)。
51
53
  * vite dev / preview server 均挂;路径未命中则 next() 放行。
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
- // src/dev-server.ts
1
+ // packages/vite-plugin/src/dev-server.ts
2
2
  import { resolve } from "node:path";
3
3
 
4
- // src/prefix.ts
4
+ // packages/vite-plugin/src/prefix.ts
5
5
  function normalizeFunctionPrefix(raw) {
6
6
  const value = (raw ?? "").trim();
7
7
  if (value.length === 0 || value === "/") return "";
8
8
  return value.replace(/^\/+|\/+$/g, "");
9
9
  }
10
10
 
11
- // src/proxy.ts
11
+ // packages/vite-plugin/src/proxy.ts
12
12
  import { request as httpRequest } from "node:http";
13
13
  function isAddrInUse(error) {
14
14
  return typeof error === "object" && error !== null && "code" in error && error.code === "EADDRINUSE";
@@ -48,7 +48,7 @@ function createAdepProxyMiddleware(prefix, targetBase) {
48
48
  };
49
49
  }
50
50
 
51
- // src/preview-automation.ts
51
+ // packages/vite-plugin/src/preview-automation.ts
52
52
  var PREVIEW_AUTOMATION_SCRIPT = `(function () {
53
53
  if (window.__adepAutomationInstalled) return;
54
54
  window.__adepAutomationInstalled = true;
@@ -519,7 +519,7 @@ var PREVIEW_AUTOMATION_SCRIPT = `(function () {
519
519
  })();
520
520
  `;
521
521
 
522
- // src/ide-proxy.ts
522
+ // packages/vite-plugin/src/ide-proxy.ts
523
523
  var FN_FETCH_INTERCEPTOR_SCRIPT = `(function () {
524
524
  if (window.__adepFnProxyInstalled) return;
525
525
  window.__adepFnProxyInstalled = true;
@@ -704,7 +704,7 @@ function injectAutomationScriptTag(html) {
704
704
  return html.replace("</head>", '<script src="/@adep/automation.js"></script></head>');
705
705
  }
706
706
 
707
- // src/dev-server.ts
707
+ // packages/vite-plugin/src/dev-server.ts
708
708
  function adepPlugin(options = {}) {
709
709
  const cwd = resolve(options.cwd ?? process.cwd());
710
710
  let dev;
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@adep/vite-plugin",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "云函数 Vite 插件(IDE-030,自 CLI-014 @adep/cli/vite 抽出):vite dev 进程内启动本地 adep dev server 并代理 /{prefix}/* 到云函数;同时 serve /@adep/fn-proxy.js(Web IDE 预览 fetch 拦截器)。本地运行时与配置加载经 createDevServer / loadConfig 注入端口接入,供 CLI / Web IDE / 非 CLI 用户独立使用。",
7
- "main": "./src/index.ts",
8
- "types": "./src/index.ts",
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./src/index.ts",
11
+ "types": "./dist/index.d.ts",
12
12
  "default": "./dist/index.js"
13
13
  }
14
14
  },
@@ -18,15 +18,5 @@
18
18
  "scripts": {
19
19
  "test": "vitest run",
20
20
  "build": "bun run ../../scripts/build-package.ts vite-plugin"
21
- },
22
- "publishConfig": {
23
- "main": "./dist/index.js",
24
- "types": "./dist/index.d.ts",
25
- "exports": {
26
- ".": {
27
- "types": "./dist/index.d.ts",
28
- "default": "./dist/index.js"
29
- }
30
- }
31
21
  }
32
- }
22
+ }