@adep/cli 0.5.2 → 0.5.4

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.
Files changed (4) hide show
  1. package/README.md +44 -20
  2. package/dist/index.js +2065 -735
  3. package/dist/vite.js +312 -35
  4. package/package.json +16 -5
package/dist/vite.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // packages/cli/src/vite.ts
2
+ import { existsSync } from "node:fs";
3
+ import { resolve as resolve5 } from "node:path";
2
4
  import { adepPlugin } from "@adep/vite-plugin";
3
5
 
4
6
  // packages/cli/src/dev.ts
@@ -361,7 +363,7 @@ var WorkerFunctionExecutor = class {
361
363
  `[adep] timeoutMs \u58F0\u660E ${budget.declaredMs}ms \u8D85\u8FC7\u6267\u884C\u9884\u7B97\u4E0A\u9650 ${this.timeoutMaxMs}ms\uFF0C\u5DF2\u6309\u4E0A\u9650\u94B3\u5236\uFF08FN_EXEC_TIMEOUT_CLAMPED\uFF09`
362
364
  );
363
365
  }
364
- return new Promise((resolve5, reject) => {
366
+ return new Promise((resolve6, reject) => {
365
367
  let worker;
366
368
  try {
367
369
  worker = new Worker(resolveWorkerEntry(), {
@@ -424,7 +426,7 @@ var WorkerFunctionExecutor = class {
424
426
  if (message.type === "result") {
425
427
  clearTimeout(timer);
426
428
  void worker.terminate();
427
- resolve5({ body: message.body, logs });
429
+ resolve6({ body: message.body, logs });
428
430
  return;
429
431
  }
430
432
  if (message.type === "error") {
@@ -2135,9 +2137,20 @@ var StorageError = class extends Error {
2135
2137
  var STORAGE_CODES = {
2136
2138
  invalidPath: "STORAGE_INVALID_PATH",
2137
2139
  invalidData: "STORAGE_INVALID_DATA",
2140
+ invalidVisibility: "STORAGE_INVALID_VISIBILITY",
2141
+ invalidSignedUrlTtl: "STORAGE_SIGNED_URL_TTL_INVALID",
2142
+ signedUrlTtlExceeded: "STORAGE_SIGNED_URL_TTL_EXCEEDED",
2138
2143
  notFound: "STORAGE_NOT_FOUND",
2139
2144
  quotaExceeded: "STORAGE_QUOTA_EXCEEDED"
2140
2145
  };
2146
+ function assertFileVisibility(value) {
2147
+ if (value === "public" || value === "private") return value;
2148
+ throw new StorageError(
2149
+ 400,
2150
+ STORAGE_CODES.invalidVisibility,
2151
+ `\u975E\u6CD5\u7684\u6587\u4EF6\u53EF\u89C1\u6027 ${JSON.stringify(value)}\uFF08\u53EA\u652F\u6301 'public' / 'private'\uFF09`
2152
+ );
2153
+ }
2141
2154
  function assertSafeStoragePath(path) {
2142
2155
  if (typeof path !== "string" || path.length === 0) {
2143
2156
  throw new StorageError(400, STORAGE_CODES.invalidPath, "\u5B58\u50A8\u8DEF\u5F84\u4E0D\u80FD\u4E3A\u7A7A");
@@ -2345,17 +2358,46 @@ function hmacSha256Hex(key, message) {
2345
2358
 
2346
2359
  // packages/runtime/src/storage/signature.ts
2347
2360
  var DEFAULT_SIGN_TTL_SECONDS = 15 * 60;
2361
+ var MAX_SIGNED_URL_TTL_SECONDS = 7 * 24 * 60 * 60;
2348
2362
  var SIGN_EXPIRES_KEY = "x-expires";
2349
2363
  var SIGN_SIGNATURE_KEY = "x-signature";
2364
+ function resolveSignedUrlTtl(ttlSeconds, options) {
2365
+ if (ttlSeconds === void 0) return DEFAULT_SIGN_TTL_SECONDS;
2366
+ if (!Number.isInteger(ttlSeconds) || ttlSeconds <= 0) {
2367
+ throw new StorageError(
2368
+ 400,
2369
+ STORAGE_CODES.invalidSignedUrlTtl,
2370
+ `\u7B7E\u540D\u6709\u6548\u671F\u5FC5\u987B\u662F\u6B63\u6574\u6570\u79D2\uFF08\u6536\u5230 ${ttlSeconds}\uFF09`
2371
+ );
2372
+ }
2373
+ if (ttlSeconds > MAX_SIGNED_URL_TTL_SECONDS && options?.force !== true) {
2374
+ throw new StorageError(
2375
+ 400,
2376
+ STORAGE_CODES.signedUrlTtlExceeded,
2377
+ `\u7B7E\u540D URL \u6709\u6548\u671F\u6700\u957F ${MAX_SIGNED_URL_TTL_SECONDS / 86400} \u5929\uFF08\u6536\u5230 ${ttlSeconds} \u79D2\uFF09\u3002\u9700\u8981\u957F\u671F\u7A33\u5B9A\u7684\u94FE\u63A5\u8BF7\u628A\u6587\u4EF6\u4E0A\u4F20\u4E3A visibility: 'public' \u5E76\u7528 getUrl() \u53D6\u76F4\u94FE\uFF1B\u786E\u9700\u8D85\u957F\u79C1\u6709\u94FE\u63A5\u8BF7\u663E\u5F0F\u4F20 { force: true }\uFF08\u8FC7\u671F\u524D\u94FE\u63A5\u6CC4\u6F0F\u5373\u957F\u671F\u53EF\u8BFB\uFF09\u3002`
2378
+ );
2379
+ }
2380
+ return ttlSeconds;
2381
+ }
2350
2382
  function sign(secret, projectId, path, expires) {
2351
2383
  const payload = `${projectId}|${path}|${expires}`;
2352
2384
  return hmacSha256Hex(secret, payload);
2353
2385
  }
2354
- function signDownloadUrl(config, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_SECONDS) {
2355
- const expires = Math.floor(Date.now() / 1e3) + ttlSeconds;
2356
- const base = `${config.baseUrl}/api/v1/projects/${encodeURIComponent(projectId)}/files/${encodeURIComponent(path)}`;
2386
+ function publicDownloadUrl(config, projectId, path) {
2387
+ return `${config.baseUrl}/api/v1/projects/${encodeURIComponent(projectId)}/files/${encodeURIComponent(path)}`;
2388
+ }
2389
+ function signDownloadUrlWithExpiry(config, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_SECONDS, options) {
2390
+ const ttl = resolveSignedUrlTtl(ttlSeconds, options);
2391
+ const expires = Math.floor(Date.now() / 1e3) + ttl;
2392
+ const base = publicDownloadUrl(config, projectId, path);
2357
2393
  const signature = sign(config.secret, projectId, path, expires);
2358
- return `${base}?${SIGN_EXPIRES_KEY}=${expires}&${SIGN_SIGNATURE_KEY}=${signature}`;
2394
+ return {
2395
+ url: `${base}?${SIGN_EXPIRES_KEY}=${expires}&${SIGN_SIGNATURE_KEY}=${signature}`,
2396
+ expires
2397
+ };
2398
+ }
2399
+ function signDownloadUrl(config, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_SECONDS, options) {
2400
+ return signDownloadUrlWithExpiry(config, projectId, path, ttlSeconds, options).url;
2359
2401
  }
2360
2402
 
2361
2403
  // packages/runtime/src/storage/cloud.ts
@@ -2404,9 +2446,10 @@ function createStorageCapability(driver, signer, projectId) {
2404
2446
  switch (method) {
2405
2447
  case "upload": {
2406
2448
  const [path, data, options] = args;
2449
+ const visibility = assertFileVisibility(options?.visibility ?? DEFAULT_VISIBILITY);
2407
2450
  return toStoredFile(
2408
2451
  await driver.put(projectId, path, asBytes(data), {
2409
- visibility: DEFAULT_VISIBILITY,
2452
+ visibility,
2410
2453
  ...options?.contentType === void 0 ? {} : { contentType: options.contentType }
2411
2454
  })
2412
2455
  );
@@ -2424,9 +2467,26 @@ function createStorageCapability(driver, signer, projectId) {
2424
2467
  const [prefix] = args;
2425
2468
  return (await driver.list(projectId, prefix)).map(toStoredFile);
2426
2469
  }
2470
+ case "getUrl": {
2471
+ const [path] = args;
2472
+ const meta = await driver.getMeta(projectId, path);
2473
+ if (meta.visibility === "public") {
2474
+ const result2 = {
2475
+ url: publicDownloadUrl(signer, projectId, path),
2476
+ expiresAt: null
2477
+ };
2478
+ return result2;
2479
+ }
2480
+ const signed = signDownloadUrlWithExpiry(signer, projectId, path);
2481
+ const result = {
2482
+ url: signed.url,
2483
+ expiresAt: new Date(signed.expires * 1e3).toISOString()
2484
+ };
2485
+ return result;
2486
+ }
2427
2487
  case "getSignedUrl": {
2428
- const [path, ttlSeconds] = args;
2429
- return signDownloadUrl(signer, projectId, path, ttlSeconds);
2488
+ const [path, ttlSeconds, options] = args;
2489
+ return signDownloadUrl(signer, projectId, path, ttlSeconds, options);
2430
2490
  }
2431
2491
  default:
2432
2492
  throw new StorageError(
@@ -2915,6 +2975,16 @@ function unquoteIdent(raw) {
2915
2975
  }
2916
2976
  return text;
2917
2977
  }
2978
+ function parsePlainIdent(raw) {
2979
+ const text = raw.trim();
2980
+ if (text.length === 0) return null;
2981
+ const first = text[0];
2982
+ if (first === '"' || first === "`" || first === "[" || first === "'") {
2983
+ const unquoted = unquoteIdent(text);
2984
+ return unquoted === text.trim() ? null : unquoted;
2985
+ }
2986
+ return /^[A-Za-z_][A-Za-z0-9_$]*$/.test(text) ? text : null;
2987
+ }
2918
2988
  function splitTopLevel2(body) {
2919
2989
  const parts = [];
2920
2990
  let depth = 0;
@@ -3008,19 +3078,47 @@ function parseColumn(part) {
3008
3078
  }
3009
3079
  const type = rest.slice(0, typeEnd).trim();
3010
3080
  rest = rest.slice(typeEnd).trim();
3011
- const notNull = /\bNOT\s+NULL\b/i.test(rest);
3012
- const primaryKey = /\bPRIMARY\s+KEY\b/i.test(rest);
3013
3081
  const defaultMatch = /\bDEFAULT\s+(.+?)(?=\s+(?:NOT|PRIMARY|UNIQUE|CHECK|REFERENCES|COLLATE|GENERATED|AS|AUTOINCREMENT|CONSTRAINT)\b|$)/i.exec(
3014
3082
  rest
3015
3083
  );
3084
+ const constraintText = defaultMatch === null ? rest : rest.replace(defaultMatch[0], " ");
3085
+ const declarationText = stripNonNullabilityClauses(constraintText);
3086
+ const notNull = /\bNOT\s+NULL\b/i.test(declarationText);
3087
+ const explicitNullable = !notNull && /\bNULL\b/i.test(declarationText);
3088
+ const primaryKey = /\bPRIMARY\s+KEY\b/i.test(declarationText);
3089
+ const unique = /\bUNIQUE\b/i.test(declarationText);
3016
3090
  return {
3017
3091
  name,
3018
3092
  type,
3019
3093
  notNull,
3094
+ explicitNullable,
3020
3095
  primaryKey,
3096
+ unique,
3021
3097
  defaultValue: defaultMatch === null ? null : defaultMatch[1].trim()
3022
3098
  };
3023
3099
  }
3100
+ function stripNonNullabilityClauses(text) {
3101
+ return text.replace(
3102
+ /\bREFERENCES\s+\S+(?:\s*\([^)]*\))?(?:\s+ON\s+(?:DELETE|UPDATE)\s+(?:CASCADE|RESTRICT|SET\s+NULL|SET\s+DEFAULT|NO\s+ACTION))*/gi,
3103
+ " "
3104
+ ).replace(/\bCHECK\s*\([^)]*\)/gi, " ").replace(/\bGENERATED\s+ALWAYS\s+AS\s*\([^)]*\)(?:\s+STORED|\s+VIRTUAL)?/gi, " ");
3105
+ }
3106
+ function parseTableUnique(part) {
3107
+ const trimmed = part.trim();
3108
+ const match = /^(?:CONSTRAINT\s+(?:"(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|[A-Za-z_][A-Za-z0-9_$]*)\s+)?UNIQUE\s*\(/i.exec(
3109
+ trimmed
3110
+ );
3111
+ if (match === null) return null;
3112
+ const body = findTableBody(trimmed, match[0].lastIndexOf("("));
3113
+ if (body === null) return null;
3114
+ const columns = [];
3115
+ for (const entry of splitTopLevel2(body)) {
3116
+ const column = parsePlainIdent(entry);
3117
+ if (column === null) return null;
3118
+ columns.push(column);
3119
+ }
3120
+ return columns.length === 0 ? null : columns;
3121
+ }
3024
3122
  function parseSchemaTables(sql) {
3025
3123
  const tables = [];
3026
3124
  const pattern = /CREATE\s+(?:TEMP|TEMPORARY\s+)?TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?("(?:[^"]|"")*"|`(?:[^`]|``)*`|\[[^\]]*\]|'[^']*'|[A-Za-z_][A-Za-z0-9_$.]*)\s*\(/gi;
@@ -3034,11 +3132,14 @@ function parseSchemaTables(sql) {
3034
3132
  const rawName = match[1];
3035
3133
  const name = unquoteIdent(rawName.split(".").pop() ?? rawName);
3036
3134
  const columns = [];
3135
+ const uniqueConstraints = [];
3037
3136
  for (const part of splitTopLevel2(body)) {
3137
+ const unique = parseTableUnique(part);
3138
+ if (unique !== null) uniqueConstraints.push(unique);
3038
3139
  const column = parseColumn(part);
3039
3140
  if (column !== null) columns.push(column);
3040
3141
  }
3041
- tables.push({ name, columns, statement: statement.trim() });
3142
+ tables.push({ name, columns, uniqueConstraints, statement: statement.trim() });
3042
3143
  }
3043
3144
  return tables;
3044
3145
  }
@@ -3061,6 +3162,18 @@ function planMissingColumn(table, column) {
3061
3162
  };
3062
3163
  }
3063
3164
 
3165
+ // packages/cli/src/auth.ts
3166
+ var CliError = class extends Error {
3167
+ constructor(code, message, exitCode = 1) {
3168
+ super(message);
3169
+ this.code = code;
3170
+ this.exitCode = exitCode;
3171
+ this.name = "CliError";
3172
+ }
3173
+ code;
3174
+ exitCode;
3175
+ };
3176
+
3064
3177
  // packages/cli/src/serve/sqlite-driver.ts
3065
3178
  import { mkdir as mkdir3 } from "node:fs/promises";
3066
3179
  import { dirname as dirname4, resolve as resolve2 } from "node:path";
@@ -3401,8 +3514,15 @@ function isFetchBlockedPort(port) {
3401
3514
 
3402
3515
  // packages/cli/src/serve/fetch-safe-port.ts
3403
3516
  var MAX_FETCH_SAFE_LISTEN_ATTEMPTS = 8;
3517
+ var DEFAULT_PORT_FALLBACK_SPAN = 12;
3518
+ var PortFallbackExhaustedError = class extends Error {
3519
+ constructor(message) {
3520
+ super(message);
3521
+ this.name = "PortFallbackExhaustedError";
3522
+ }
3523
+ };
3404
3524
  function listenOnce(server, port, host) {
3405
- return new Promise((resolve5, reject) => {
3525
+ return new Promise((resolve6, reject) => {
3406
3526
  const onError = (error) => {
3407
3527
  server.off("error", onError);
3408
3528
  reject(error);
@@ -3410,13 +3530,13 @@ function listenOnce(server, port, host) {
3410
3530
  server.once("error", onError);
3411
3531
  server.listen(port, host, () => {
3412
3532
  server.off("error", onError);
3413
- resolve5();
3533
+ resolve6();
3414
3534
  });
3415
3535
  });
3416
3536
  }
3417
3537
  function closeServer(server) {
3418
- return new Promise((resolve5, reject) => {
3419
- server.close((error) => error === void 0 ? resolve5() : reject(error));
3538
+ return new Promise((resolve6, reject) => {
3539
+ server.close((error) => error === void 0 ? resolve6() : reject(error));
3420
3540
  });
3421
3541
  }
3422
3542
  async function closeQuietly(server) {
@@ -3442,6 +3562,21 @@ function buildExhaustedMessage(input) {
3442
3562
  "\u53EF\u80FD\u539F\u56E0\uFF1A\u7CFB\u7EDF\u4E34\u65F6\u7AEF\u53E3\u8D77\u59CB\u503C\u88AB\u8C03\u4F4E\uFF08Windows \u7528 netsh int ipv4 show dynamicport tcp \u6838\u5BF9\uFF0CHyper-V / \u5BB9\u5668\u7F51\u7EDC\u4F1A\u6539\u5B83\uFF09\u3002\u53EF\u7528 --port \u6307\u5B9A\u4E00\u4E2A\u672A\u5360\u7528\u7684\u7AEF\u53E3\u7ED5\u8FC7\u3002"
3443
3563
  ].join("\n");
3444
3564
  }
3565
+ function isAddrInUseCode(error) {
3566
+ return error?.code === "EADDRINUSE";
3567
+ }
3568
+ function formatFallbackNotice(info) {
3569
+ return `[adep] \u7AEF\u53E3 ${info.requested} \u5DF2\u88AB\u5360\u7528\uFF0C\u5DF2\u6539\u7528 ${info.actual}\uFF08\u7F3A\u7701\u7AEF\u53E3\u81EA\u52A8\u987A\u5EF6\uFF1B\u663E\u5F0F\u6307\u5B9A\u7684\u7AEF\u53E3\u4E0D\u6362\u53F7\uFF09`;
3570
+ }
3571
+ function buildFallbackExhaustedMessage(input) {
3572
+ const first = input.requested + 1;
3573
+ const last = input.requested + input.span;
3574
+ return [
3575
+ `[adep] \u7AEF\u53E3 ${input.requested} \u5DF2\u88AB\u5360\u7528\uFF0C\u5176\u540E ${input.span} \u4E2A\u5019\u9009\u7AEF\u53E3\uFF08${first}~${last}\uFF09\u4E5F\u4E0D\u53EF\u7528\uFF0C\u5DF2\u653E\u5F03\u542F\u52A8\u3002`,
3576
+ "\u7F3A\u7701\u7AEF\u53E3\u81EA\u52A8\u987A\u5EF6\u53EA\u8986\u76D6\u8FD9\u4E00\u5C0F\u6BB5\uFF1B\u8BF7\u7528 --port \u6307\u5B9A\u4E00\u4E2A\u7A7A\u95F2\u7AEF\u53E3\uFF08\u663E\u5F0F\u7AEF\u53E3\u4E0D\u4F1A\u81EA\u52A8\u6362\u53F7\uFF09\u3002",
3577
+ `\u5360\u7528\u8005\u6392\u67E5\uFF1Alsof -nP -iTCP:${input.requested} -sTCP:LISTEN\uFF08Windows\uFF1Anetstat -ano | findstr :${input.requested}\uFF09`
3578
+ ].join("\n");
3579
+ }
3445
3580
  async function listenOnFetchSafePort(server, options) {
3446
3581
  const isBlocked = options.isBlocked ?? isFetchBlockedPort;
3447
3582
  const warn = options.warn ?? (() => {
@@ -3452,12 +3587,46 @@ async function listenOnFetchSafePort(server, options) {
3452
3587
  } catch {
3453
3588
  }
3454
3589
  };
3455
- if (options.port !== 0) {
3590
+ const requestedPort = options.port;
3591
+ if (requestedPort !== 0) {
3456
3592
  try {
3457
- await listenOnce(server, options.port, options.host);
3593
+ await listenOnce(server, requestedPort, options.host);
3458
3594
  } catch (error) {
3459
- await notifyListenError(error);
3460
- throw error;
3595
+ const fallback = options.fallbackOnInUse;
3596
+ if (fallback === void 0 || !isAddrInUseCode(error)) {
3597
+ await notifyListenError(error);
3598
+ throw error;
3599
+ }
3600
+ const span = fallback.span ?? DEFAULT_PORT_FALLBACK_SPAN;
3601
+ if (!Number.isInteger(span) || span < 1) {
3602
+ await notifyListenError(error);
3603
+ throw new Error(`[adep] fallbackOnInUse.span \u5FC5\u987B\u662F\u6B63\u6574\u6570\uFF08\u6536\u5230 ${String(span)}\uFF09\u3002`, {
3604
+ cause: error
3605
+ });
3606
+ }
3607
+ let lastError = error;
3608
+ for (let offset = 1; offset <= span; offset += 1) {
3609
+ const candidate = requestedPort + offset;
3610
+ if (candidate > 65535) break;
3611
+ if (isBlocked(candidate)) continue;
3612
+ try {
3613
+ await listenOnce(server, candidate, options.host);
3614
+ } catch (candidateError) {
3615
+ if (isAddrInUseCode(candidateError)) {
3616
+ lastError = candidateError;
3617
+ continue;
3618
+ }
3619
+ await notifyListenError(candidateError);
3620
+ throw candidateError;
3621
+ }
3622
+ const report = options.onFallback ?? ((info) => warn(formatFallbackNotice(info)));
3623
+ report({ requested: requestedPort, actual: candidate });
3624
+ return candidate;
3625
+ }
3626
+ await notifyListenError(lastError);
3627
+ throw new PortFallbackExhaustedError(
3628
+ buildFallbackExhaustedMessage({ requested: requestedPort, span })
3629
+ );
3461
3630
  }
3462
3631
  const actual = readTcpPort(server, options.host);
3463
3632
  if (isBlocked(actual)) {
@@ -3490,6 +3659,79 @@ async function listenOnFetchSafePort(server, options) {
3490
3659
  throw new Error(buildExhaustedMessage({ host: options.host, hits, maxAttempts }));
3491
3660
  }
3492
3661
 
3662
+ // packages/cli/src/serve/port-in-use.ts
3663
+ import { execFile } from "node:child_process";
3664
+ function parsePortOccupier(stdout) {
3665
+ for (const line of stdout.split(/\r?\n/)) {
3666
+ const trimmed = line.trim();
3667
+ if (trimmed.length === 0 || trimmed.startsWith("COMMAND")) continue;
3668
+ const [command, pid] = trimmed.split(/\s+/);
3669
+ if (command === void 0 || pid === void 0 || !/^\d+$/u.test(pid)) return null;
3670
+ return `${command} ${pid}`;
3671
+ }
3672
+ return null;
3673
+ }
3674
+ function runLsof(port) {
3675
+ return new Promise((resolve6, reject) => {
3676
+ execFile(
3677
+ "lsof",
3678
+ ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN"],
3679
+ { timeout: 2e3, windowsHide: true },
3680
+ (error, stdout) => {
3681
+ if (error !== null) {
3682
+ reject(error);
3683
+ return;
3684
+ }
3685
+ resolve6(stdout);
3686
+ }
3687
+ );
3688
+ });
3689
+ }
3690
+ async function lookupPortOccupier(port, options = {}) {
3691
+ if (process.platform === "win32") return null;
3692
+ const execute = options.execute ?? runLsof;
3693
+ try {
3694
+ return parsePortOccupier(await execute(port));
3695
+ } catch {
3696
+ return null;
3697
+ }
3698
+ }
3699
+ async function describePortInUse(options) {
3700
+ const occupier = await (options.lookup ?? lookupPortOccupier)(options.port);
3701
+ const nextPort = options.port < 65535 ? options.port + 1 : options.port - 1;
3702
+ const command = `adep ${options.scope}`;
3703
+ return [
3704
+ `[adep] \u7AEF\u53E3 ${options.port} \u5DF2\u88AB\u5360\u7528\uFF08EADDRINUSE\uFF09\uFF1B\u8BE5\u7AEF\u53E3\u662F\u663E\u5F0F\u6307\u5B9A\u7684\uFF08--port / PORT\uFF09\uFF0C\u4E0D\u4F1A\u81EA\u52A8\u6539\u7528\u5176\u5B83\u7AEF\u53E3\u3002`,
3705
+ occupier === null ? `\u5360\u7528\u8005\uFF1A\u65E0\u6CD5\u5B9A\u4F4D\u3002\u624B\u52A8\u68C0\u67E5\uFF1Alsof -nP -iTCP:${options.port} -sTCP:LISTEN\uFF08Windows\uFF1Anetstat -ano | findstr :${options.port}\uFF09` : `\u5360\u7528\u8005\uFF1A${occupier}\uFF08\u590D\u6838\u547D\u4EE4\uFF1Alsof -nP -iTCP:${options.port} -sTCP:LISTEN\uFF09`,
3706
+ `\u5904\u7F6E\uFF1A\u6539\u7528\u5176\u5B83\u7AEF\u53E3\uFF08${command} --port ${nextPort}\uFF09\uFF0C\u6216\u5148\u505C\u6B62\u5360\u7528\u8BE5\u7AEF\u53E3\u7684\u8FDB\u7A0B\u3002`
3707
+ ].join("\n");
3708
+ }
3709
+ function isAddrInUse(error) {
3710
+ return error?.code === "EADDRINUSE";
3711
+ }
3712
+ async function toPortCliError(error, context) {
3713
+ if (isAddrInUse(error)) {
3714
+ return new CliError(
3715
+ "PORT_IN_USE",
3716
+ await describePortInUse({ port: context.port, scope: context.scope })
3717
+ );
3718
+ }
3719
+ if (error instanceof PortFallbackExhaustedError) {
3720
+ return new CliError("PORT_FALLBACK_EXHAUSTED", error.message);
3721
+ }
3722
+ return null;
3723
+ }
3724
+ function isPortConflictError(error) {
3725
+ if (isAddrInUse(error)) return true;
3726
+ return error instanceof CliError && error.code === "PORT_IN_USE";
3727
+ }
3728
+ function toAddrInUseError(error) {
3729
+ const message = error instanceof Error ? error.message : String(error);
3730
+ const wrapped = new Error(message, { cause: error });
3731
+ wrapped.code = "EADDRINUSE";
3732
+ return wrapped;
3733
+ }
3734
+
3493
3735
  // packages/cli/src/sim/env.ts
3494
3736
  import { readFile as readFile4 } from "node:fs/promises";
3495
3737
  import { join as join6 } from "node:path";
@@ -5053,8 +5295,8 @@ function isRpcCapability(value) {
5053
5295
  function createRpcClient(capability, port, pending, nextId) {
5054
5296
  return createFlatRpcProxy((method, args) => {
5055
5297
  const id = nextId();
5056
- return new Promise((resolve5, reject) => {
5057
- pending.set(id, { resolve: resolve5, reject });
5298
+ return new Promise((resolve6, reject) => {
5299
+ pending.set(id, { resolve: resolve6, reject });
5058
5300
  port.postMessage({ type: "rpc", id, capability, method, args });
5059
5301
  });
5060
5302
  });
@@ -5164,9 +5406,9 @@ function isChainCapability(value) {
5164
5406
  return typeof spec === "object" && spec !== null && Array.isArray(spec.stepMethods) && Array.isArray(spec.terminalMethods);
5165
5407
  }
5166
5408
  function createChainClient(capability, port, pending, nextId, spec) {
5167
- const call = (method, args) => new Promise((resolve5, reject) => {
5409
+ const call = (method, args) => new Promise((resolve6, reject) => {
5168
5410
  const id = nextId();
5169
- pending.set(id, { resolve: resolve5, reject });
5411
+ pending.set(id, { resolve: resolve6, reject });
5170
5412
  port.postMessage({ type: "rpc", id, capability, method, args });
5171
5413
  });
5172
5414
  const makeChainable = (rootArgs, steps, txId) => new Proxy(
@@ -6033,13 +6275,22 @@ async function startDevServer(options) {
6033
6275
  } catch {
6034
6276
  }
6035
6277
  };
6036
- const actualPort = await listenOnFetchSafePort(server, {
6037
- port,
6038
- host: "127.0.0.1",
6039
- warn: log,
6040
- onListenError: disposeAfterListenError
6041
- });
6278
+ let actualPort;
6279
+ try {
6280
+ actualPort = await listenOnFetchSafePort(server, {
6281
+ port,
6282
+ host: "127.0.0.1",
6283
+ warn: log,
6284
+ ...options.port === void 0 ? { fallbackOnInUse: {} } : {},
6285
+ onListenError: disposeAfterListenError
6286
+ });
6287
+ } catch (error) {
6288
+ const portError = await toPortCliError(error, { port, scope: "dev" });
6289
+ if (portError !== null) throw portError;
6290
+ throw error;
6291
+ }
6042
6292
  const baseUrl = `http://127.0.0.1:${actualPort}`;
6293
+ runtime.storage.signer.baseUrl = baseUrl;
6043
6294
  const coldStartMs = Date.now() - coldStartAt;
6044
6295
  const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
6045
6296
  const dbLabel = db.mode === "sqlite" ? `SQLite \u771F\u5B9E\u5E93${db.module === null ? "" : `\uFF08${db.module}\uFF09`}` : "sim \u5F15\u64CE\uFF08\u5185\u7F6E\u6A21\u62DF\uFF09";
@@ -6078,14 +6329,39 @@ import {
6078
6329
  FN_FETCH_INTERCEPTOR_SCRIPT,
6079
6330
  injectAutomationScriptTag,
6080
6331
  injectFnProxyScriptTag,
6081
- isAddrInUse,
6332
+ isAddrInUse as isAddrInUse2,
6082
6333
  normalizeFunctionPrefix,
6083
6334
  PREVIEW_AUTOMATION_SCRIPT
6084
6335
  } from "@adep/vite-plugin";
6085
- var createDevServer = (opts) => startDevServer({ cwd: opts.cwd, port: opts.port, prefix: opts.prefix, log: opts.log });
6336
+ var createDevServer = async (opts) => {
6337
+ try {
6338
+ return await startDevServer({
6339
+ cwd: opts.cwd,
6340
+ port: opts.port,
6341
+ prefix: opts.prefix,
6342
+ log: opts.log,
6343
+ ...opts.schemaFile === void 0 ? {} : { schemaFile: opts.schemaFile }
6344
+ });
6345
+ } catch (error) {
6346
+ if (isPortConflictError(error)) throw toAddrInUseError(error);
6347
+ throw error;
6348
+ }
6349
+ };
6086
6350
  var loadConfig2 = (cwd) => loadAdepConfigModule(cwd);
6351
+ function resolveLocalSchemaFile(cwd, configured) {
6352
+ if (configured === false) return void 0;
6353
+ if (typeof configured === "string") return configured;
6354
+ return existsSync(resolve5(cwd, "database/schema.sql")) ? "database/schema.sql" : void 0;
6355
+ }
6087
6356
  function adepVitePlugin(options = {}) {
6088
- return adepPlugin({ ...options, createDevServer, loadConfig: loadConfig2 });
6357
+ const cwd = options.cwd ?? process.cwd();
6358
+ const schemaFile = resolveLocalSchemaFile(cwd, options.schemaFile);
6359
+ return adepPlugin({
6360
+ ...options,
6361
+ ...schemaFile === void 0 ? {} : { schemaFile },
6362
+ createDevServer,
6363
+ loadConfig: loadConfig2
6364
+ });
6089
6365
  }
6090
6366
  var vite_default = adepVitePlugin;
6091
6367
  export {
@@ -6098,6 +6374,7 @@ export {
6098
6374
  vite_default as default,
6099
6375
  injectAutomationScriptTag,
6100
6376
  injectFnProxyScriptTag,
6101
- isAddrInUse,
6102
- normalizeFunctionPrefix
6377
+ isAddrInUse2 as isAddrInUse,
6378
+ normalizeFunctionPrefix,
6379
+ resolveLocalSchemaFile
6103
6380
  };
package/package.json CHANGED
@@ -7,7 +7,18 @@
7
7
  },
8
8
  "homepage": "https://adep.top",
9
9
  "bugs": "https://gitcode.com/yunqiang_wu/ai-yunke/issues",
10
- "version": "0.5.2",
10
+ "version": "0.5.4",
11
+ "adep": {
12
+ "releaseTasks": [
13
+ "CLI-057",
14
+ "DB-025",
15
+ "CLI-100",
16
+ "CLI-101",
17
+ "CLI-102",
18
+ "CLI-103",
19
+ "CLI-104"
20
+ ]
21
+ },
11
22
  "type": "module",
12
23
  "description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
13
24
  "bin": {
@@ -30,14 +41,14 @@
30
41
  "esbuild": "0.25.12",
31
42
  "yaml": "2.9.1",
32
43
  "zod": "^4.6.6",
33
- "@adep/cf-compat": "0.1.4",
34
44
  "@adep/app-runtime": "0.1.1",
35
- "@adep/vite-plugin": "0.1.11",
45
+ "@adep/cf-compat": "0.1.4",
36
46
  "@adep/crypto": "0.1.1",
37
- "@adep/runtime": "0.3.9"
47
+ "@adep/vite-plugin": "0.1.13",
48
+ "@adep/runtime": "0.3.10"
38
49
  },
39
50
  "devDependencies": {
40
- "@adep/types": "0.4.2"
51
+ "@adep/types": "0.4.3"
41
52
  },
42
53
  "scripts": {
43
54
  "test": "vitest run",