@adep/vite-plugin 0.1.6 → 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.
@@ -78,12 +78,24 @@ export interface AdepViteServer {
78
78
  on(event: 'close', listener: () => void): void;
79
79
  };
80
80
  }
81
+ /** ResolvedConfig 结构子集(本包不 import vite,只消费 command 字段)。 */
82
+ export interface AdepResolvedConfig {
83
+ /** `serve` = dev server(`vite` / `vite dev`);`build` = `vite build`。 */
84
+ command: 'serve' | 'build';
85
+ }
81
86
  export interface AdepVitePlugin {
82
87
  name: string;
83
88
  /** 插件始终实现以下钩子(结构类型对齐 Vite Plugin 的子集,本包不依赖 vite 包)。 */
84
89
  configureServer: (server: AdepViteServer) => void | Promise<void>;
85
90
  configurePreviewServer: (server: AdepViteServer) => void | Promise<void>;
86
- /** 注入 fetch 拦截器 script 标签(幂等)。 */
91
+ /**
92
+ * 记录当前是 serve(dev)还是 build。**只有 serve 才注入 `/@adep/*.js` script 标签**——
93
+ * 这两段脚本由 dev server 中间件提供,build 产物里没有;build 时注入会让部署后的页面
94
+ * 请求不存在的 `/@adep/fn-proxy.js` → 静态托管 SPA 回退到 index.html(HTML)→
95
+ * 浏览器报 `Uncaught SyntaxError: Unexpected token '<'`。
96
+ */
97
+ configResolved: (config: AdepResolvedConfig) => void;
98
+ /** 注入 fetch 拦截器 script 标签(幂等;仅 serve 时生效,见 configResolved)。 */
87
99
  transformIndexHtml: (html: string) => string;
88
100
  closeBundle: () => void | Promise<void>;
89
101
  }
@@ -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
@@ -711,6 +711,7 @@ function adepPlugin(options = {}) {
711
711
  let prefix = normalizeFunctionPrefix(options.prefix);
712
712
  let prefixPath = "";
713
713
  let startPromise;
714
+ let isServe = false;
714
715
  const startAdepDev = async (log) => {
715
716
  if (startPromise !== void 0) return startPromise;
716
717
  const create = options.createDevServer;
@@ -765,6 +766,9 @@ function adepPlugin(options = {}) {
765
766
  };
766
767
  return {
767
768
  name: "adep-cloud-functions",
769
+ configResolved(config) {
770
+ isServe = config.command === "serve";
771
+ },
768
772
  async configureServer(server) {
769
773
  const log = (line) => server.config.logger.info(line);
770
774
  await startAdepDev(log);
@@ -779,6 +783,7 @@ function adepPlugin(options = {}) {
779
783
  attachMiddlewares(server);
780
784
  },
781
785
  transformIndexHtml(html) {
786
+ if (!isServe) return html;
782
787
  return injectAutomationScriptTag(injectFnProxyScriptTag(html));
783
788
  },
784
789
  async closeBundle() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adep/vite-plugin",
3
- "version": "0.1.6",
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 用户独立使用。",