@adep/cli 0.1.13 → 0.1.15

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/README.md CHANGED
@@ -235,8 +235,8 @@ adep serve --db sqlite --db-file var/local.sqlite # 指定库文件
235
235
  - 绑定非回环地址时给出对外暴露警告(它不带生产级加固)。
236
236
 
237
237
  - 数据库两档模式(`--db`):
238
- - `sim`(缺省):内置模拟引擎,库是 JSON 文件 `.adep/sim/db.json`。`--schema` 只支持 DDL 子集,其余语句跳过并告警;
239
- - `sqlite`:**真实 SQLite 库文件**,驱动按运行时分派(Bun → `bun:sqlite`,Node ≥ 22.5 → `node:sqlite`)。`--schema` 的每条语句都真实执行,**失败即停**(视图 / 唯一索引 / 触发器等 sim 做不到的能力全可用)。运行时两者都没有时拒绝启动并提示回退 `--db sim`。
238
+ - `sqlite`(缺省):**真实 SQLite 库文件**,驱动按运行时分派(Bun → `bun:sqlite`,Node ≥ 22.5 → `node:sqlite`)。`--schema` 的每条语句都真实执行,**失败即停**(视图 / 唯一索引 / 触发器等 sim 做不到的能力全可用)。运行时不支持(Bun / Node < 22.5)或打开库文件失败时**自动降级 `sim` 并告警**,不拒绝启动;
239
+ - `sim`:内置模拟引擎,库是 JSON 文件 `.adep/sim/db.json`。`--schema` 只支持 DDL 子集,其余语句跳过并告警。
240
240
  - 模式名写错(旗标或环境变量)一律拒绝启动,不静默换库;启动横幅与根路径 `/` 会回显 `db.mode` / `db.file` / `db.driver`。
241
241
 
242
242
  ### `adep publish`
package/dist/index.js CHANGED
@@ -577,11 +577,23 @@ var init_http_envelope = __esm({
577
577
  });
578
578
 
579
579
  // packages/runtime/src/functions/domain.ts
580
- var MAX_TOTAL_SOURCE_BYTES, FnError;
580
+ function flatEntryCandidates(name) {
581
+ return ENTRY_SOURCE_EXTS.map((ext) => `${name}${ext}`);
582
+ }
583
+ function resolveDraftEntry(name, files) {
584
+ if (files[ENTRY_FILE] !== void 0) return ENTRY_FILE;
585
+ for (const candidate of flatEntryCandidates(name)) {
586
+ if (files[candidate] !== void 0) return candidate;
587
+ }
588
+ return null;
589
+ }
590
+ var MAX_TOTAL_SOURCE_BYTES, ENTRY_FILE, ENTRY_SOURCE_EXTS, FnError;
581
591
  var init_domain = __esm({
582
592
  "packages/runtime/src/functions/domain.ts"() {
583
593
  "use strict";
584
594
  MAX_TOTAL_SOURCE_BYTES = 256 * 1024;
595
+ ENTRY_FILE = "index.ts";
596
+ ENTRY_SOURCE_EXTS = [".ts", ".js", ".mjs", ".cjs"];
585
597
  FnError = class extends Error {
586
598
  status;
587
599
  code;
@@ -759,6 +771,7 @@ var init_worker_executor = __esm({
759
771
  "use strict";
760
772
  init_executor();
761
773
  init_resolve();
774
+ init_domain();
762
775
  WorkerFunctionExecutor = class {
763
776
  depsConfig;
764
777
  fetchConfig;
@@ -769,7 +782,7 @@ var init_worker_executor = __esm({
769
782
  async execute(input) {
770
783
  const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
771
784
  const memoryLimitMb = input.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
772
- const entry = input.entry ?? "index.ts";
785
+ const entry = input.entry ?? resolveDraftEntry(input.fn.name, input.files) ?? "index.ts";
773
786
  const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
774
787
  const logs = [];
775
788
  return new Promise((resolve15, reject) => {
@@ -5505,7 +5518,7 @@ var init_db_mode = __esm({
5505
5518
  "packages/cli/src/serve/db-mode.ts"() {
5506
5519
  "use strict";
5507
5520
  SERVE_DB_MODES = ["sim", "sqlite"];
5508
- DEFAULT_SERVE_DB_MODE = "sim";
5521
+ DEFAULT_SERVE_DB_MODE = "sqlite";
5509
5522
  DEFAULT_SQLITE_DB_FILE = ".adep/data/project.sqlite";
5510
5523
  }
5511
5524
  });
@@ -5531,9 +5544,12 @@ function detectSqliteRuntime(versions = process.versions) {
5531
5544
  function sqliteModuleName(runtime) {
5532
5545
  return runtime === "bun" ? "bun:sqlite" : "node:sqlite";
5533
5546
  }
5534
- function sqliteRuntimeRequirementMessage(versions = process.versions) {
5547
+ function sqliteUnavailableReason(versions = process.versions) {
5535
5548
  const current = isBun(versions) ? `Bun ${versions["bun"] ?? ""}`.trim() : `Node ${versions["node"] ?? "\u672A\u77E5"}`;
5536
- return `--db sqlite \u9700\u8981 Bun\uFF08\u5185\u7F6E bun:sqlite\uFF09\u6216 Node \u2265 ${NODE_SQLITE_MIN.major}.${NODE_SQLITE_MIN.minor}\uFF08\u5185\u7F6E node:sqlite\uFF09\uFF1B\u5F53\u524D\u8FD0\u884C\u65F6 ${current} \u4E0D\u63D0\u4F9B SQLite \u5185\u5EFA\u6A21\u5757\u3002\u8BF7\u6539\u7528 \`--db sim\`\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u65E0\u9700\u989D\u5916\u8FD0\u884C\u65F6\uFF09\uFF0C\u6216\u5347\u7EA7 Node / \u7528 Bun \u8FD0\u884C\u3002`;
5549
+ return `\u5F53\u524D\u8FD0\u884C\u65F6 ${current} \u4E0D\u63D0\u4F9B SQLite \u5185\u5EFA\u6A21\u5757\uFF08\u9700\u8981 Bun \u6216 Node \u2265 ${NODE_SQLITE_MIN.major}.${NODE_SQLITE_MIN.minor}\uFF09`;
5550
+ }
5551
+ function sqliteRuntimeRequirementMessage(versions = process.versions) {
5552
+ return `--db sqlite \u9700\u8981 Bun\uFF08\u5185\u7F6E bun:sqlite\uFF09\u6216 Node \u2265 ${NODE_SQLITE_MIN.major}.${NODE_SQLITE_MIN.minor}\uFF08\u5185\u7F6E node:sqlite\uFF09\uFF1B${sqliteUnavailableReason(versions)}\u3002\u8BF7\u6539\u7528 \`--db sim\`\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u65E0\u9700\u989D\u5916\u8FD0\u884C\u65F6\uFF09\uFF0C\u6216\u5347\u7EA7 Node / \u7528 Bun \u8FD0\u884C\u3002`;
5537
5553
  }
5538
5554
  async function openSqliteProjectDriver(file, options = {}) {
5539
5555
  const runtime = options.runtime ?? detectSqliteRuntime();
@@ -5639,8 +5655,8 @@ async function startServeServer(options) {
5639
5655
  cwd,
5640
5656
  options.staticDir ?? envString("ADEP_SERVE_STATIC_DIR") ?? "public"
5641
5657
  );
5642
- const dbMode = resolveServeDbMode(options.db);
5643
- const sqliteFile = dbMode === "sqlite" ? resolveServeDbFile(cwd, options.dbFile) : null;
5658
+ let dbMode = resolveServeDbMode(options.db);
5659
+ let sqliteFile = dbMode === "sqlite" ? resolveServeDbFile(cwd, options.dbFile) : null;
5644
5660
  const config = await loadConfig(cwd);
5645
5661
  const functionsDir = join14(cwd, config.functionsDir);
5646
5662
  const bearerUser = bearerUserResolverFromEnv();
@@ -5661,9 +5677,27 @@ async function startServeServer(options) {
5661
5677
  let sqliteDriver = null;
5662
5678
  if (sqliteFile !== null) {
5663
5679
  const runtimeName = detectSqliteRuntime();
5664
- if (runtimeName === null) throw new Error(sqliteRuntimeRequirementMessage());
5665
- sqliteModule = sqliteModuleName(runtimeName);
5666
- sqliteDriver = await openSqliteProjectDriver(sqliteFile, { runtime: runtimeName });
5680
+ if (runtimeName === null) {
5681
+ log(
5682
+ `[serve] \u8B66\u544A\uFF1A${sqliteUnavailableReason()}\uFF0C\u5DF2\u81EA\u52A8\u964D\u7EA7\u4E3A sim \u6A21\u5F0F\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u5E93 ${displayPath(cwd, join14(simDir(cwd), "db.json"))}\uFF09\u3002\u5982\u9700\u771F\u5B9E SQLite\uFF0C\u8BF7\u7528 Bun \u6216\u5347\u7EA7 Node \u540E\u91CD\u8BD5\u3002`
5683
+ );
5684
+ dbMode = "sim";
5685
+ sqliteFile = null;
5686
+ } else {
5687
+ sqliteModule = sqliteModuleName(runtimeName);
5688
+ try {
5689
+ sqliteDriver = await openSqliteProjectDriver(sqliteFile, { runtime: runtimeName });
5690
+ } catch (error) {
5691
+ const detail = error instanceof Error ? error.message : String(error);
5692
+ log(
5693
+ `[serve] \u8B66\u544A\uFF1A\u6253\u5F00 SQLite \u5E93\u5931\u8D25\uFF08${detail}\uFF09\uFF0C\u5DF2\u81EA\u52A8\u964D\u7EA7\u4E3A sim \u6A21\u5F0F\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u5E93 ${displayPath(cwd, join14(simDir(cwd), "db.json"))}\uFF09\u3002`
5694
+ );
5695
+ sqliteModule = null;
5696
+ sqliteDriver = null;
5697
+ sqliteFile = null;
5698
+ dbMode = "sim";
5699
+ }
5700
+ }
5667
5701
  }
5668
5702
  const runtime = await createSimRuntime({
5669
5703
  cwd,
@@ -6030,7 +6064,7 @@ async function collectFunctionFiles(functionsDir) {
6030
6064
  if (conflicting.length > 0) throw new AmbiguousFunctionError(functionsDir, conflicting);
6031
6065
  const out = {};
6032
6066
  for (const name of flatNames) {
6033
- out[name] = { "index.ts": await readFile12(join15(functionsDir, `${name}.ts`), "utf8") };
6067
+ out[name] = { [`${name}.ts`]: await readFile12(join15(functionsDir, `${name}.ts`), "utf8") };
6034
6068
  }
6035
6069
  for (const name of dirNames) {
6036
6070
  const files = await collectFunctionDir(join15(functionsDir, name));
@@ -12265,7 +12299,7 @@ function registerDevServers(program2, ctx) {
12265
12299
  "\u6570\u636E\u5E93\u7ED3\u6784\u6587\u4EF6\uFF1A\u542F\u52A8\u65F6\u5BF9\u672C\u5730\u5E93\u9010\u6761\u5E94\u7528\uFF08\u5EFA\u8868\u8BED\u53E5\u5EFA\u8BAE IF NOT EXISTS\uFF0C\u5E42\u7B49\u53EF\u91CD\u590D\u542F\u52A8\uFF09"
12266
12300
  ).option(
12267
12301
  "--db <mode>",
12268
- "\u6570\u636E\u5E93\u6A21\u5F0F\uFF1Asim\uFF08\u7F3A\u7701\uFF0C\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE + .adep/sim/db.json\uFF09| sqlite\uFF08\u771F\u5B9E SQLite \u5E93\u6587\u4EF6\uFF0C\u9700 Bun \u6216 Node \u2265 22.5\uFF09"
12302
+ "\u6570\u636E\u5E93\u6A21\u5F0F\uFF1Asqlite\uFF08\u7F3A\u7701\uFF0C\u771F\u5B9E SQLite \u5E93\u6587\u4EF6\uFF0C\u9700 Bun \u6216 Node \u2265 22.5\uFF1B\u8FD0\u884C\u65F6\u4E0D\u652F\u6301\u6216\u6253\u5F00\u5931\u8D25\u65F6\u81EA\u52A8\u964D\u7EA7 sim\uFF09| sim\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE + .adep/sim/db.json\uFF09"
12269
12303
  ).option(
12270
12304
  "--db-file <path>",
12271
12305
  "sqlite \u6A21\u5F0F\u7684\u5E93\u6587\u4EF6\uFF08\u7F3A\u7701\u53D6 ADEP_SERVE_DB_FILE\uFF0C\u518D\u7F3A\u7701 .adep/data/project.sqlite\uFF09"
package/dist/vite.js CHANGED
@@ -94,6 +94,18 @@ import { createHash } from "node:crypto";
94
94
 
95
95
  // packages/runtime/src/functions/domain.ts
96
96
  var MAX_TOTAL_SOURCE_BYTES = 256 * 1024;
97
+ var ENTRY_FILE = "index.ts";
98
+ var ENTRY_SOURCE_EXTS = [".ts", ".js", ".mjs", ".cjs"];
99
+ function flatEntryCandidates(name) {
100
+ return ENTRY_SOURCE_EXTS.map((ext) => `${name}${ext}`);
101
+ }
102
+ function resolveDraftEntry(name, files) {
103
+ if (files[ENTRY_FILE] !== void 0) return ENTRY_FILE;
104
+ for (const candidate of flatEntryCandidates(name)) {
105
+ if (files[candidate] !== void 0) return candidate;
106
+ }
107
+ return null;
108
+ }
97
109
  var FnError = class extends Error {
98
110
  status;
99
111
  code;
@@ -254,7 +266,7 @@ var WorkerFunctionExecutor = class {
254
266
  async execute(input) {
255
267
  const timeoutMs = input.timeoutMs ?? DEFAULT_TIMEOUT_MS;
256
268
  const memoryLimitMb = input.memoryLimitMb ?? DEFAULT_MEMORY_LIMIT_MB;
257
- const entry = input.entry ?? "index.ts";
269
+ const entry = input.entry ?? resolveDraftEntry(input.fn.name, input.files) ?? "index.ts";
258
270
  const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
259
271
  const logs = [];
260
272
  return new Promise((resolve3, reject) => {
@@ -4443,12 +4455,15 @@ async function startDevServer(options) {
4443
4455
 
4444
4456
  // packages/cli/src/vite.ts
4445
4457
  import {
4458
+ createAdepAutomationScriptMiddleware,
4446
4459
  createAdepFnProxyScriptMiddleware,
4447
4460
  createAdepProxyMiddleware,
4448
4461
  FN_FETCH_INTERCEPTOR_SCRIPT,
4462
+ injectAutomationScriptTag,
4449
4463
  injectFnProxyScriptTag,
4450
4464
  isAddrInUse,
4451
- normalizeFunctionPrefix
4465
+ normalizeFunctionPrefix,
4466
+ PREVIEW_AUTOMATION_SCRIPT
4452
4467
  } from "@adep/vite-plugin";
4453
4468
  var createDevServer = (opts) => startDevServer({ cwd: opts.cwd, port: opts.port, prefix: opts.prefix, log: opts.log });
4454
4469
  var loadConfig2 = (cwd) => loadAdepConfigModule(cwd);
@@ -4458,10 +4473,13 @@ function adepVitePlugin(options = {}) {
4458
4473
  var vite_default = adepVitePlugin;
4459
4474
  export {
4460
4475
  FN_FETCH_INTERCEPTOR_SCRIPT,
4476
+ PREVIEW_AUTOMATION_SCRIPT,
4461
4477
  adepVitePlugin,
4478
+ createAdepAutomationScriptMiddleware,
4462
4479
  createAdepFnProxyScriptMiddleware,
4463
4480
  createAdepProxyMiddleware,
4464
4481
  vite_default as default,
4482
+ injectAutomationScriptTag,
4465
4483
  injectFnProxyScriptTag,
4466
4484
  isAddrInUse,
4467
4485
  normalizeFunctionPrefix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adep/cli",
3
- "version": "0.1.13",
3
+ "version": "0.1.15",
4
4
  "type": "module",
5
5
  "description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
6
6
  "bin": {
@@ -21,7 +21,7 @@
21
21
  "commander": "14.0.2",
22
22
  "esbuild": "0.25.12",
23
23
  "@adep/cf-compat": "0.1.1",
24
- "@adep/vite-plugin": "0.1.5"
24
+ "@adep/vite-plugin": "0.1.6"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@adep/runtime": "0.2.6",