@adep/vite-plugin 0.1.6 → 0.1.7
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/dev-server.d.ts +13 -1
- package/dist/index.js +11 -6
- package/package.json +15 -5
package/dist/dev-server.d.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
//
|
|
1
|
+
// src/dev-server.ts
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// 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
|
-
//
|
|
11
|
+
// 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
|
-
//
|
|
51
|
+
// 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
|
-
//
|
|
522
|
+
// src/ide-proxy.ts
|
|
523
523
|
var FN_FETCH_INTERCEPTOR_SCRIPT = `(function () {
|
|
524
524
|
if (window.__adepFnProxyInstalled) return;
|
|
525
525
|
window.__adepFnProxyInstalled = true;
|
|
@@ -704,13 +704,14 @@ function injectAutomationScriptTag(html) {
|
|
|
704
704
|
return html.replace("</head>", '<script src="/@adep/automation.js"></script></head>');
|
|
705
705
|
}
|
|
706
706
|
|
|
707
|
-
//
|
|
707
|
+
// src/dev-server.ts
|
|
708
708
|
function adepPlugin(options = {}) {
|
|
709
709
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
710
710
|
let dev;
|
|
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,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adep/vite-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
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": "./
|
|
8
|
-
"types": "./
|
|
7
|
+
"main": "./src/index.ts",
|
|
8
|
+
"types": "./src/index.ts",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
@@ -18,5 +18,15 @@
|
|
|
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
|
+
}
|
|
21
31
|
}
|
|
22
|
-
}
|
|
32
|
+
}
|