@adep/vite-plugin 0.1.11 → 0.1.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/dev-server.d.ts +13 -0
- package/dist/index.js +22 -6
- package/package.json +6 -1
package/dist/dev-server.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export interface AdepDevServerHandle {
|
|
|
33
33
|
/**
|
|
34
34
|
* 本地 adep dev server 工厂(CLI 注入 `startDevServer`)。`port=0` 表示让系统分配
|
|
35
35
|
* 随机端口(插件端口占用重试时用)。
|
|
36
|
+
*
|
|
37
|
+
* **端口占用的错误形状属于契约**:工厂在目标端口被占用时必须抛 `code === 'EADDRINUSE'`
|
|
38
|
+
* 的错误——插件据此改用随机端口重试(CLI 侧由适配层把库函数的人读向 CliError 翻译成这个
|
|
39
|
+
* 形状,见 `packages/cli/src/vite.ts`)。抛成别的形状 ⇒ 插件认不出 ⇒ 不挂函数代理 ⇒
|
|
40
|
+
* `/api/*` 落到 vite 的 SPA 回退(HTML 而不是函数 JSON)。
|
|
36
41
|
*/
|
|
37
42
|
export interface AdepDevServerFactory {
|
|
38
43
|
(opts: {
|
|
@@ -40,6 +45,8 @@ export interface AdepDevServerFactory {
|
|
|
40
45
|
port: number;
|
|
41
46
|
prefix: string;
|
|
42
47
|
log: (line: string) => void;
|
|
48
|
+
/** 启动时应用的 schema 文件(相对 cwd;CLI 侧约定发现 database/schema.sql)。 */
|
|
49
|
+
schemaFile?: string;
|
|
43
50
|
}): Promise<AdepDevServerHandle>;
|
|
44
51
|
}
|
|
45
52
|
/** 读 `adep.config.ts` 的 `functions_prefix`(CLI 注入 `loadAdepConfigModule`)。 */
|
|
@@ -55,6 +62,12 @@ export interface AdepVitePluginOptions {
|
|
|
55
62
|
prefix?: string;
|
|
56
63
|
/** 项目根目录(缺省 process.cwd(),即 vite 工程根)。 */
|
|
57
64
|
cwd?: string;
|
|
65
|
+
/**
|
|
66
|
+
* 启动时应用到本地库的 schema 文件(相对 cwd)。字符串 = 显式指定;`false` = 关闭
|
|
67
|
+
* 自动发现;缺省时由 CLI 包装层按约定发现 `<cwd>/database/schema.sql`。
|
|
68
|
+
* 仅在注入了 createDevServer 时生效(裸插件不启动本地 dev server)。
|
|
69
|
+
*/
|
|
70
|
+
schemaFile?: string | false;
|
|
58
71
|
/**
|
|
59
72
|
* 启动本地 adep dev server 的工厂(CLI 注入);未提供时不启动 dev server、不挂函数
|
|
60
73
|
* 代理(仍 serve `/@adep/fn-proxy.js`——纯 IDE 预览场景)。
|
package/dist/index.js
CHANGED
|
@@ -708,6 +708,9 @@ function injectAutomationScriptTag(html) {
|
|
|
708
708
|
}
|
|
709
709
|
|
|
710
710
|
// packages/vite-plugin/src/dev-server.ts
|
|
711
|
+
function describeError(error) {
|
|
712
|
+
return error instanceof Error ? error.message : String(error);
|
|
713
|
+
}
|
|
711
714
|
function adepPlugin(options = {}) {
|
|
712
715
|
const cwd = resolve(options.cwd ?? process.cwd());
|
|
713
716
|
let dev;
|
|
@@ -730,16 +733,29 @@ function adepPlugin(options = {}) {
|
|
|
730
733
|
}
|
|
731
734
|
prefixPath = `/${prefix}`;
|
|
732
735
|
const targetPort = options.port ?? 8787;
|
|
736
|
+
const schemaFile = typeof options.schemaFile === "string" ? options.schemaFile : void 0;
|
|
737
|
+
const factoryOptions = {
|
|
738
|
+
cwd,
|
|
739
|
+
prefix,
|
|
740
|
+
log,
|
|
741
|
+
...schemaFile === void 0 ? {} : { schemaFile }
|
|
742
|
+
};
|
|
733
743
|
try {
|
|
734
|
-
dev = await create({
|
|
744
|
+
dev = await create({ ...factoryOptions, port: targetPort });
|
|
735
745
|
} catch (error) {
|
|
736
|
-
if (isAddrInUse(error)) {
|
|
737
|
-
log(`[adep] \u7AEF\u53E3 ${targetPort} \u88AB\u5360\u7528\uFF0C\u6539\u7528\u968F\u673A\u7AEF\u53E3`);
|
|
738
|
-
dev = await create({ cwd, port: 0, prefix, log });
|
|
739
|
-
} else {
|
|
746
|
+
if (!isAddrInUse(error)) {
|
|
740
747
|
log(
|
|
741
|
-
`[adep] \u4E91\u51FD\u6570 dev server \u542F\u52A8\u5931\u8D25\uFF1A${
|
|
748
|
+
`[adep] \u4E91\u51FD\u6570 dev server \u542F\u52A8\u5931\u8D25\uFF1A${describeError(error)}\uFF08vite \u524D\u7AEF\u7167\u5E38\uFF0C\u51FD\u6570\u4EE3\u7406\u4E0D\u53EF\u7528\uFF09`
|
|
742
749
|
);
|
|
750
|
+
} else {
|
|
751
|
+
log(`[adep] \u7AEF\u53E3 ${targetPort} \u88AB\u5360\u7528\uFF0C\u6539\u7528\u968F\u673A\u7AEF\u53E3`);
|
|
752
|
+
try {
|
|
753
|
+
dev = await create({ ...factoryOptions, port: 0 });
|
|
754
|
+
} catch (retryError) {
|
|
755
|
+
log(
|
|
756
|
+
`[adep] \u4E91\u51FD\u6570 dev server \u542F\u52A8\u5931\u8D25\uFF08\u968F\u673A\u7AEF\u53E3\uFF09\uFF1A${describeError(retryError)}\uFF08vite \u524D\u7AEF\u7167\u5E38\uFF0C\u51FD\u6570\u4EE3\u7406\u4E0D\u53EF\u7528\uFF09`
|
|
757
|
+
);
|
|
758
|
+
}
|
|
743
759
|
}
|
|
744
760
|
}
|
|
745
761
|
if (dev !== void 0) {
|
package/package.json
CHANGED
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
},
|
|
8
8
|
"homepage": "https://adep.top",
|
|
9
9
|
"bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
|
|
10
|
-
"version": "0.1.
|
|
10
|
+
"version": "0.1.13",
|
|
11
|
+
"adep": {
|
|
12
|
+
"releaseTasks": [
|
|
13
|
+
"CLI-051"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
11
16
|
"private": false,
|
|
12
17
|
"type": "module",
|
|
13
18
|
"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 用户独立使用。",
|