@adep/cli 0.1.15 → 0.1.17
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 +5 -0
- package/dist/index.js +1118 -709
- package/dist/vite.js +312 -37
- package/package.json +4 -3
package/dist/vite.js
CHANGED
|
@@ -4,8 +4,8 @@ import { adepPlugin } from "@adep/vite-plugin";
|
|
|
4
4
|
// packages/cli/src/dev.ts
|
|
5
5
|
import { createServer } from "node:http";
|
|
6
6
|
import { watch } from "node:fs";
|
|
7
|
-
import { mkdir as
|
|
8
|
-
import { basename, join as
|
|
7
|
+
import { mkdir as mkdir4, readFile as readFile7, writeFile as writeFile3 } from "node:fs/promises";
|
|
8
|
+
import { basename, join as join10, resolve as resolve4 } from "node:path";
|
|
9
9
|
|
|
10
10
|
// packages/runtime/src/shared/capability-keys.ts
|
|
11
11
|
var RPC_CAPABILITY_KEY = "__adepRpc";
|
|
@@ -269,7 +269,7 @@ var WorkerFunctionExecutor = class {
|
|
|
269
269
|
const entry = input.entry ?? resolveDraftEntry(input.fn.name, input.files) ?? "index.ts";
|
|
270
270
|
const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
|
|
271
271
|
const logs = [];
|
|
272
|
-
return new Promise((
|
|
272
|
+
return new Promise((resolve5, reject) => {
|
|
273
273
|
let worker;
|
|
274
274
|
try {
|
|
275
275
|
worker = new Worker(resolveWorkerEntry(), {
|
|
@@ -331,7 +331,7 @@ var WorkerFunctionExecutor = class {
|
|
|
331
331
|
if (message.type === "result") {
|
|
332
332
|
clearTimeout(timer);
|
|
333
333
|
void worker.terminate();
|
|
334
|
-
|
|
334
|
+
resolve5({ body: message.body, logs });
|
|
335
335
|
return;
|
|
336
336
|
}
|
|
337
337
|
if (message.type === "error") {
|
|
@@ -2386,7 +2386,7 @@ function createLocalStorageDriver(options) {
|
|
|
2386
2386
|
assertStoragePrefix(prefix);
|
|
2387
2387
|
const root = bucketDir(projectId);
|
|
2388
2388
|
const metas = [];
|
|
2389
|
-
const walk = async (dir,
|
|
2389
|
+
const walk = async (dir, relative2) => {
|
|
2390
2390
|
let entries;
|
|
2391
2391
|
try {
|
|
2392
2392
|
entries = await readdir(dir, { withFileTypes: true });
|
|
@@ -2397,7 +2397,7 @@ function createLocalStorageDriver(options) {
|
|
|
2397
2397
|
for (const entry of entries) {
|
|
2398
2398
|
if (entry.name.endsWith(META_SUFFIX)) continue;
|
|
2399
2399
|
const full = join2(dir, entry.name);
|
|
2400
|
-
const rel =
|
|
2400
|
+
const rel = relative2 === "" ? entry.name : `${relative2}/${entry.name}`;
|
|
2401
2401
|
if (entry.isFile()) {
|
|
2402
2402
|
if (prefix !== void 0 && !rel.startsWith(prefix)) continue;
|
|
2403
2403
|
tasks.push(
|
|
@@ -2438,11 +2438,12 @@ function createLocalStorageDriver(options) {
|
|
|
2438
2438
|
}
|
|
2439
2439
|
|
|
2440
2440
|
// packages/cli/src/sim/storage.ts
|
|
2441
|
+
var SIM_SIGN_SECRET = "adep-sim-secret";
|
|
2441
2442
|
function createSimStorageCapability(options) {
|
|
2442
2443
|
const dir = join3(options.cwd, ".adep", "sim", "storage");
|
|
2443
2444
|
const driver = createLocalStorageDriver({ dir });
|
|
2444
2445
|
const signer = {
|
|
2445
|
-
secret: options.secret ??
|
|
2446
|
+
secret: options.secret ?? SIM_SIGN_SECRET,
|
|
2446
2447
|
baseUrl: options.baseUrl ?? "http://127.0.0.1:8787"
|
|
2447
2448
|
};
|
|
2448
2449
|
const bundle = createStorageCapability(driver, signer, options.projectId ?? "sim-project");
|
|
@@ -2631,15 +2632,261 @@ async function createSimRuntime(options) {
|
|
|
2631
2632
|
bundle,
|
|
2632
2633
|
realtime: simRealtime.realtime,
|
|
2633
2634
|
db,
|
|
2635
|
+
/** 存储句柄(serve 的签名文件下载路由用它读对象;bundle 里的 capability 是同一驱动的 RPC 面)。 */
|
|
2636
|
+
storage,
|
|
2634
2637
|
dispose: async () => {
|
|
2635
2638
|
await db.driver.close();
|
|
2636
2639
|
}
|
|
2637
2640
|
};
|
|
2638
2641
|
}
|
|
2639
2642
|
|
|
2640
|
-
// packages/cli/src/
|
|
2643
|
+
// packages/cli/src/serve/db-mode.ts
|
|
2641
2644
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
2642
|
-
import { join as join5 } from "node:path";
|
|
2645
|
+
import { join as join5, relative, resolve as resolve3 } from "node:path";
|
|
2646
|
+
|
|
2647
|
+
// packages/cli/src/db.ts
|
|
2648
|
+
function splitSqlStatements(source) {
|
|
2649
|
+
const statements = [];
|
|
2650
|
+
let buffer = "";
|
|
2651
|
+
let inQuote = false;
|
|
2652
|
+
const lines = source.split("\n");
|
|
2653
|
+
for (const rawLine of lines) {
|
|
2654
|
+
const trimmed = rawLine.trim();
|
|
2655
|
+
if (!inQuote && (trimmed.length === 0 || trimmed.startsWith("--"))) continue;
|
|
2656
|
+
for (let i = 0; i < rawLine.length; i++) {
|
|
2657
|
+
const ch = rawLine[i];
|
|
2658
|
+
if (inQuote) {
|
|
2659
|
+
if (ch === "'") {
|
|
2660
|
+
if (rawLine[i + 1] === "'") {
|
|
2661
|
+
buffer += ch + rawLine[i + 1];
|
|
2662
|
+
i++;
|
|
2663
|
+
continue;
|
|
2664
|
+
}
|
|
2665
|
+
inQuote = false;
|
|
2666
|
+
}
|
|
2667
|
+
buffer += ch;
|
|
2668
|
+
continue;
|
|
2669
|
+
}
|
|
2670
|
+
if (ch === "'") {
|
|
2671
|
+
inQuote = true;
|
|
2672
|
+
buffer += ch;
|
|
2673
|
+
continue;
|
|
2674
|
+
}
|
|
2675
|
+
if (ch === "-" && rawLine[i + 1] === "-") break;
|
|
2676
|
+
if (ch === ";") {
|
|
2677
|
+
const statement = buffer.trim();
|
|
2678
|
+
if (statement.length > 0) statements.push(statement);
|
|
2679
|
+
buffer = "";
|
|
2680
|
+
continue;
|
|
2681
|
+
}
|
|
2682
|
+
buffer += ch;
|
|
2683
|
+
}
|
|
2684
|
+
buffer += inQuote ? "\n" : " ";
|
|
2685
|
+
}
|
|
2686
|
+
if (inQuote) {
|
|
2687
|
+
throw new Error(`SQL \u8FC1\u79FB\u6587\u4EF6\u5F15\u53F7\u672A\u95ED\u5408\uFF1A${buffer.trim().slice(0, 80)}\u2026`);
|
|
2688
|
+
}
|
|
2689
|
+
const tail = buffer.trim();
|
|
2690
|
+
if (tail.length > 0) statements.push(tail);
|
|
2691
|
+
return statements;
|
|
2692
|
+
}
|
|
2693
|
+
|
|
2694
|
+
// packages/cli/src/serve/sqlite-driver.ts
|
|
2695
|
+
import { mkdir as mkdir3 } from "node:fs/promises";
|
|
2696
|
+
import { dirname as dirname4, resolve as resolve2 } from "node:path";
|
|
2697
|
+
var NODE_SQLITE_MIN = { major: 22, minor: 5 };
|
|
2698
|
+
function isBun(versions) {
|
|
2699
|
+
return versions["bun"] !== void 0 && versions["bun"] !== "";
|
|
2700
|
+
}
|
|
2701
|
+
function detectSqliteRuntime(versions = process.versions) {
|
|
2702
|
+
if (isBun(versions)) return "bun";
|
|
2703
|
+
const raw = versions["node"];
|
|
2704
|
+
if (raw === void 0) return null;
|
|
2705
|
+
const [majorText, minorText] = raw.split(".");
|
|
2706
|
+
const major = Number(majorText);
|
|
2707
|
+
const minor = Number(minorText ?? "0");
|
|
2708
|
+
if (!Number.isInteger(major) || !Number.isInteger(minor)) return null;
|
|
2709
|
+
if (major > NODE_SQLITE_MIN.major) return "node";
|
|
2710
|
+
if (major === NODE_SQLITE_MIN.major && minor >= NODE_SQLITE_MIN.minor) return "node";
|
|
2711
|
+
return null;
|
|
2712
|
+
}
|
|
2713
|
+
function sqliteModuleName(runtime) {
|
|
2714
|
+
return runtime === "bun" ? "bun:sqlite" : "node:sqlite";
|
|
2715
|
+
}
|
|
2716
|
+
function sqliteUnavailableReason(versions = process.versions) {
|
|
2717
|
+
const current = isBun(versions) ? `Bun ${versions["bun"] ?? ""}`.trim() : `Node ${versions["node"] ?? "\u672A\u77E5"}`;
|
|
2718
|
+
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`;
|
|
2719
|
+
}
|
|
2720
|
+
function sqliteRuntimeRequirementMessage(versions = process.versions) {
|
|
2721
|
+
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`;
|
|
2722
|
+
}
|
|
2723
|
+
async function openSqliteProjectDriver(file, options = {}) {
|
|
2724
|
+
const runtime = options.runtime ?? detectSqliteRuntime();
|
|
2725
|
+
if (runtime === null) throw new Error(sqliteRuntimeRequirementMessage());
|
|
2726
|
+
const moduleName = sqliteModuleName(runtime);
|
|
2727
|
+
const ctorName = runtime === "bun" ? "Database" : "DatabaseSync";
|
|
2728
|
+
let mod;
|
|
2729
|
+
try {
|
|
2730
|
+
const specifier = moduleName;
|
|
2731
|
+
mod = await import(
|
|
2732
|
+
/* @vite-ignore */
|
|
2733
|
+
specifier
|
|
2734
|
+
);
|
|
2735
|
+
} catch (error) {
|
|
2736
|
+
throw new Error(
|
|
2737
|
+
`${sqliteRuntimeRequirementMessage()}
|
|
2738
|
+
\uFF08\u8F7D\u5165 ${moduleName} \u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}\uFF09`,
|
|
2739
|
+
{ cause: error }
|
|
2740
|
+
);
|
|
2741
|
+
}
|
|
2742
|
+
const Ctor = mod[ctorName];
|
|
2743
|
+
if (Ctor === void 0) {
|
|
2744
|
+
throw new Error(`${moduleName} \u672A\u5BFC\u51FA ${ctorName}\uFF1A\u5F53\u524D\u8FD0\u884C\u65F6\u7684 SQLite \u5185\u5EFA\u6A21\u5757\u4E0D\u53EF\u7528`);
|
|
2745
|
+
}
|
|
2746
|
+
const target = file === ":memory:" ? file : resolve2(file);
|
|
2747
|
+
if (target !== ":memory:") await mkdir3(dirname4(target), { recursive: true });
|
|
2748
|
+
const database = new Ctor(target);
|
|
2749
|
+
database.exec("PRAGMA journal_mode = WAL; PRAGMA foreign_keys = ON;");
|
|
2750
|
+
return {
|
|
2751
|
+
engine: "sqlite",
|
|
2752
|
+
async run(sql, params = []) {
|
|
2753
|
+
if (params.length === 0) {
|
|
2754
|
+
database.exec(sql);
|
|
2755
|
+
return { changes: 0 };
|
|
2756
|
+
}
|
|
2757
|
+
const result = database.prepare(sql).run(...params);
|
|
2758
|
+
return { changes: Number(result.changes) };
|
|
2759
|
+
},
|
|
2760
|
+
async all(sql, params = []) {
|
|
2761
|
+
const statement = database.prepare(sql);
|
|
2762
|
+
statement.setReturnArrays?.(false);
|
|
2763
|
+
return statement.all(...params);
|
|
2764
|
+
},
|
|
2765
|
+
async get(sql, params = []) {
|
|
2766
|
+
const statement = database.prepare(sql);
|
|
2767
|
+
statement.setReturnArrays?.(false);
|
|
2768
|
+
const row = statement.get(...params);
|
|
2769
|
+
return row ?? null;
|
|
2770
|
+
},
|
|
2771
|
+
async close() {
|
|
2772
|
+
database.close();
|
|
2773
|
+
}
|
|
2774
|
+
};
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
// packages/cli/src/serve/db-mode.ts
|
|
2778
|
+
var SERVE_DB_MODES = ["sim", "sqlite"];
|
|
2779
|
+
var DEFAULT_SERVE_DB_MODE = "sqlite";
|
|
2780
|
+
var DEFAULT_SQLITE_DB_FILE = ".adep/data/project.sqlite";
|
|
2781
|
+
function isServeDbMode(value) {
|
|
2782
|
+
return SERVE_DB_MODES.includes(value.trim().toLowerCase());
|
|
2783
|
+
}
|
|
2784
|
+
function parseServeDbMode(raw, source) {
|
|
2785
|
+
const value = raw.trim().toLowerCase();
|
|
2786
|
+
if (!isServeDbMode(value)) {
|
|
2787
|
+
throw new Error(
|
|
2788
|
+
`${source} \u7684\u6570\u636E\u5E93\u6A21\u5F0F "${raw}" \u65E0\u6548\uFF1A\u53EA\u652F\u6301 ${SERVE_DB_MODES.join(" | ")}\uFF08sim = \u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\u4E0E .adep/sim/db.json\uFF1Bsqlite = \u771F\u5B9E SQLite \u5E93\u6587\u4EF6\uFF09`
|
|
2789
|
+
);
|
|
2790
|
+
}
|
|
2791
|
+
return value;
|
|
2792
|
+
}
|
|
2793
|
+
function resolveServeDbMode(explicit) {
|
|
2794
|
+
if (explicit !== void 0) return parseServeDbMode(explicit, "--db");
|
|
2795
|
+
const fromEnv = process.env["ADEP_SERVE_DB"];
|
|
2796
|
+
if (fromEnv !== void 0 && fromEnv.trim() !== "") {
|
|
2797
|
+
return parseServeDbMode(fromEnv, "ADEP_SERVE_DB");
|
|
2798
|
+
}
|
|
2799
|
+
return DEFAULT_SERVE_DB_MODE;
|
|
2800
|
+
}
|
|
2801
|
+
function resolveServeDbFile(cwd, explicit) {
|
|
2802
|
+
const raw = explicit ?? envDbFile() ?? DEFAULT_SQLITE_DB_FILE;
|
|
2803
|
+
return raw === ":memory:" ? raw : resolve3(cwd, raw);
|
|
2804
|
+
}
|
|
2805
|
+
function envDbFile() {
|
|
2806
|
+
const raw = process.env["ADEP_SERVE_DB_FILE"];
|
|
2807
|
+
return raw === void 0 || raw.trim() === "" ? void 0 : raw.trim();
|
|
2808
|
+
}
|
|
2809
|
+
function displayPath(cwd, target) {
|
|
2810
|
+
if (target === ":memory:") return target;
|
|
2811
|
+
const rel = relative(cwd, target);
|
|
2812
|
+
return rel.startsWith("..") ? target : rel;
|
|
2813
|
+
}
|
|
2814
|
+
function simDbTarget(cwd) {
|
|
2815
|
+
return displayPath(cwd, join5(simDir(cwd), "db.json"));
|
|
2816
|
+
}
|
|
2817
|
+
function resolveLocalDbTarget(cwd, options) {
|
|
2818
|
+
const mode = resolveServeDbMode(options.db);
|
|
2819
|
+
return {
|
|
2820
|
+
mode,
|
|
2821
|
+
file: mode === "sqlite" ? resolveServeDbFile(cwd, options.dbFile) : null
|
|
2822
|
+
};
|
|
2823
|
+
}
|
|
2824
|
+
async function openLocalDbDriver(target, options) {
|
|
2825
|
+
if (target.mode === "sim" || target.file === null) {
|
|
2826
|
+
return { mode: "sim", file: null, module: null, driver: null };
|
|
2827
|
+
}
|
|
2828
|
+
const simTarget = simDbTarget(options.cwd);
|
|
2829
|
+
const runtimeName = detectSqliteRuntime();
|
|
2830
|
+
if (runtimeName === null) {
|
|
2831
|
+
options.log(
|
|
2832
|
+
`[${options.tag}] \u8B66\u544A\uFF1A${sqliteUnavailableReason()}\uFF0C\u5DF2\u81EA\u52A8\u964D\u7EA7\u4E3A sim \u6A21\u5F0F\uFF08\u5185\u7F6E\u6A21\u62DF\u5F15\u64CE\uFF0C\u5E93 ${simTarget}\uFF09\u3002\u5982\u9700\u771F\u5B9E SQLite\uFF0C\u8BF7\u7528 Bun \u6216\u5347\u7EA7 Node \u540E\u91CD\u8BD5\u3002`
|
|
2833
|
+
);
|
|
2834
|
+
return { mode: "sim", file: null, module: null, driver: null };
|
|
2835
|
+
}
|
|
2836
|
+
try {
|
|
2837
|
+
const driver = await openSqliteProjectDriver(target.file, { runtime: runtimeName });
|
|
2838
|
+
return {
|
|
2839
|
+
mode: "sqlite",
|
|
2840
|
+
file: target.file,
|
|
2841
|
+
module: sqliteModuleName(runtimeName),
|
|
2842
|
+
driver
|
|
2843
|
+
};
|
|
2844
|
+
} catch (error) {
|
|
2845
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
2846
|
+
options.log(
|
|
2847
|
+
`[${options.tag}] \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 ${simTarget}\uFF09\u3002`
|
|
2848
|
+
);
|
|
2849
|
+
return { mode: "sim", file: null, module: null, driver: null };
|
|
2850
|
+
}
|
|
2851
|
+
}
|
|
2852
|
+
async function applyLocalSchema(driver, options) {
|
|
2853
|
+
const { schemaFile, mode, tag, cwd, log } = options;
|
|
2854
|
+
const schemaPath = resolve3(cwd, schemaFile);
|
|
2855
|
+
const schemaSource = await readFile3(schemaPath, "utf8").catch((error) => {
|
|
2856
|
+
if (error.code === "ENOENT") {
|
|
2857
|
+
throw new Error(`schema \u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A${schemaPath}`);
|
|
2858
|
+
}
|
|
2859
|
+
throw error;
|
|
2860
|
+
});
|
|
2861
|
+
const statements = splitSqlStatements(schemaSource);
|
|
2862
|
+
let applied = 0;
|
|
2863
|
+
let skipped = 0;
|
|
2864
|
+
for (const [index, statement] of statements.entries()) {
|
|
2865
|
+
try {
|
|
2866
|
+
await driver.run(statement);
|
|
2867
|
+
applied += 1;
|
|
2868
|
+
} catch (error) {
|
|
2869
|
+
const isUnsupported = error instanceof Error && "code" in error && error.code === "DB_UNSAFE_OP";
|
|
2870
|
+
if (mode === "sim" && isUnsupported) {
|
|
2871
|
+
skipped += 1;
|
|
2872
|
+
log(`[${tag}] \u8DF3\u8FC7 schema \u8BED\u53E5\uFF08sim \u5F15\u64CE\u4E0D\u652F\u6301\uFF09\uFF1A${statement.slice(0, 60)}\u2026`);
|
|
2873
|
+
continue;
|
|
2874
|
+
}
|
|
2875
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
2876
|
+
throw new Error(
|
|
2877
|
+
`schema \u8BED\u53E5\u6267\u884C\u5931\u8D25\uFF08--schema ${schemaFile}\uFF0C\u7B2C ${index + 1} \u6761\uFF0Cdb \u6A21\u5F0F ${mode}\uFF09\uFF1A${detail}
|
|
2878
|
+
\u8BED\u53E5\uFF1A${statement.slice(0, 200)}` + (mode === "sqlite" ? "\n\uFF08sqlite \u6A21\u5F0F\u4E0D\u505A\u8BED\u53E5\u8DF3\u8FC7\uFF1B\u5982\u9700\u8DF3\u8FC7\u8BED\u4E49\u8BF7\u6539\u7528 --db sim\uFF09" : ""),
|
|
2879
|
+
{ cause: error }
|
|
2880
|
+
);
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2883
|
+
const skipNote = skipped > 0 ? `\uFF0C\u8DF3\u8FC7 ${skipped} \u6761` : "";
|
|
2884
|
+
log(`[${tag}] \u5DF2\u5E94\u7528\u6570\u636E\u5E93\u7ED3\u6784\uFF08--schema ${schemaFile}\uFF09\uFF1A${applied} \u6761\u8BED\u53E5${skipNote}`);
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2887
|
+
// packages/cli/src/sim/env.ts
|
|
2888
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
2889
|
+
import { join as join6 } from "node:path";
|
|
2643
2890
|
function parseEnv(content) {
|
|
2644
2891
|
const env = {};
|
|
2645
2892
|
for (const raw of content.split(/\r?\n/)) {
|
|
@@ -2654,8 +2901,8 @@ function parseEnv(content) {
|
|
|
2654
2901
|
return env;
|
|
2655
2902
|
}
|
|
2656
2903
|
async function loadSimEnv(cwd, config = {}) {
|
|
2657
|
-
const envRoot = await
|
|
2658
|
-
const envLocal = await
|
|
2904
|
+
const envRoot = await readFile4(join6(cwd, ".env"), "utf8").catch(() => "");
|
|
2905
|
+
const envLocal = await readFile4(join6(cwd, ".env.local"), "utf8").catch(() => "");
|
|
2659
2906
|
const merged = { ...parseEnv(envRoot), ...parseEnv(envLocal) };
|
|
2660
2907
|
for (const secret of config.secrets ?? []) {
|
|
2661
2908
|
if (merged[secret] !== void 0) continue;
|
|
@@ -2726,9 +2973,13 @@ function createSimInvokeHandler(options) {
|
|
|
2726
2973
|
// shared/builtin-deps.ts
|
|
2727
2974
|
var CF_COMPAT_SPECIFIER = "@adep/cf-compat";
|
|
2728
2975
|
var STATE_OBJECTS_SPECIFIER = "@adep/runtime/state-objects";
|
|
2976
|
+
var CRYPTO_SPECIFIER = "@adep/crypto";
|
|
2977
|
+
var ROUTE_SPECIFIER = "@adep/runtime/route";
|
|
2729
2978
|
var BUILTIN_DEPS = [
|
|
2730
2979
|
CF_COMPAT_SPECIFIER,
|
|
2731
2980
|
STATE_OBJECTS_SPECIFIER,
|
|
2981
|
+
CRYPTO_SPECIFIER,
|
|
2982
|
+
ROUTE_SPECIFIER,
|
|
2732
2983
|
"axios",
|
|
2733
2984
|
"lodash",
|
|
2734
2985
|
"dayjs",
|
|
@@ -2737,7 +2988,12 @@ var BUILTIN_DEPS = [
|
|
|
2737
2988
|
var BUILTIN_DEPS_CSV = BUILTIN_DEPS.join(",");
|
|
2738
2989
|
|
|
2739
2990
|
// packages/cli/src/builtin-deps.ts
|
|
2740
|
-
var LOCAL_BUILTIN_DEPS = [
|
|
2991
|
+
var LOCAL_BUILTIN_DEPS = [
|
|
2992
|
+
CF_COMPAT_SPECIFIER,
|
|
2993
|
+
STATE_OBJECTS_SPECIFIER,
|
|
2994
|
+
CRYPTO_SPECIFIER,
|
|
2995
|
+
ROUTE_SPECIFIER
|
|
2996
|
+
];
|
|
2741
2997
|
|
|
2742
2998
|
// packages/cli/src/sim/boundary.ts
|
|
2743
2999
|
var SIM_BOUNDARIES = [
|
|
@@ -2769,8 +3025,8 @@ var SIM_BOUNDARIES = [
|
|
|
2769
3025
|
];
|
|
2770
3026
|
|
|
2771
3027
|
// packages/cli/src/ts-config.ts
|
|
2772
|
-
import { stat as stat2, readFile as
|
|
2773
|
-
import { join as
|
|
3028
|
+
import { stat as stat2, readFile as readFile5 } from "node:fs/promises";
|
|
3029
|
+
import { join as join7 } from "node:path";
|
|
2774
3030
|
|
|
2775
3031
|
// shared/sdk/adep-config.ts
|
|
2776
3032
|
var DEFAULT_ADEP_CONFIG = {
|
|
@@ -2909,7 +3165,7 @@ function parseAdepConfig(raw) {
|
|
|
2909
3165
|
|
|
2910
3166
|
// packages/cli/src/ts-config.ts
|
|
2911
3167
|
async function loadAdepConfigModule(cwd) {
|
|
2912
|
-
const configPath =
|
|
3168
|
+
const configPath = join7(cwd, "adep.config.ts");
|
|
2913
3169
|
try {
|
|
2914
3170
|
await stat2(configPath);
|
|
2915
3171
|
} catch {
|
|
@@ -2923,7 +3179,7 @@ async function loadAdepConfigModule(cwd) {
|
|
|
2923
3179
|
rawDefault = mod.default;
|
|
2924
3180
|
} else {
|
|
2925
3181
|
const { transform } = await import("esbuild");
|
|
2926
|
-
const source = await
|
|
3182
|
+
const source = await readFile5(configPath, "utf8");
|
|
2927
3183
|
const { code } = await transform(source, {
|
|
2928
3184
|
loader: "ts",
|
|
2929
3185
|
format: "esm",
|
|
@@ -3436,7 +3692,7 @@ function loadStateObjectClasses(files, entry = STATE_OBJECTS_ENTRY, options = {}
|
|
|
3436
3692
|
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
3437
3693
|
import { parentPort, workerData } from "node:worker_threads";
|
|
3438
3694
|
import { createRequire } from "node:module";
|
|
3439
|
-
import { join as
|
|
3695
|
+
import { join as join8 } from "node:path";
|
|
3440
3696
|
|
|
3441
3697
|
// packages/runtime/src/functions/runtime/cloud-container.ts
|
|
3442
3698
|
var KNOWN_CAPABILITY_HINTS = {
|
|
@@ -3717,9 +3973,9 @@ function isChainCapability(value) {
|
|
|
3717
3973
|
return typeof spec === "object" && spec !== null && Array.isArray(spec.stepMethods) && Array.isArray(spec.terminalMethods);
|
|
3718
3974
|
}
|
|
3719
3975
|
function createChainClient(capability, port, pending, nextId, spec) {
|
|
3720
|
-
const call = (method, args) => new Promise((
|
|
3976
|
+
const call = (method, args) => new Promise((resolve5, reject) => {
|
|
3721
3977
|
const id = nextId();
|
|
3722
|
-
pending.set(id, { resolve:
|
|
3978
|
+
pending.set(id, { resolve: resolve5, reject });
|
|
3723
3979
|
port.postMessage({ type: "rpc", id, capability, method, args });
|
|
3724
3980
|
});
|
|
3725
3981
|
const makeChainable = (rootArgs, steps, txId) => new Proxy(
|
|
@@ -3798,8 +4054,8 @@ function createRpcClient(capability, port, pending, nextId) {
|
|
|
3798
4054
|
if (typeof method !== "string") return void 0;
|
|
3799
4055
|
return (...args) => {
|
|
3800
4056
|
const id = nextId();
|
|
3801
|
-
return new Promise((
|
|
3802
|
-
pending.set(id, { resolve:
|
|
4057
|
+
return new Promise((resolve5, reject) => {
|
|
4058
|
+
pending.set(id, { resolve: resolve5, reject });
|
|
3803
4059
|
port.postMessage({ type: "rpc", id, capability, method, args });
|
|
3804
4060
|
});
|
|
3805
4061
|
};
|
|
@@ -3835,7 +4091,7 @@ function errorMessageWithLocation(error, files) {
|
|
|
3835
4091
|
}
|
|
3836
4092
|
function createBareResolver(deps) {
|
|
3837
4093
|
const platformRequire = createRequire(import.meta.url);
|
|
3838
|
-
const depsRequire = deps.dir === null ? null : createRequire(
|
|
4094
|
+
const depsRequire = deps.dir === null ? null : createRequire(join8(deps.dir, "__deps__.js"));
|
|
3839
4095
|
return (request) => {
|
|
3840
4096
|
if (deps.builtin.includes(request)) return platformRequire(request);
|
|
3841
4097
|
const root = splitBareSpecifier(request);
|
|
@@ -3980,8 +4236,8 @@ if (workerPort !== null && workerData !== void 0) {
|
|
|
3980
4236
|
}
|
|
3981
4237
|
|
|
3982
4238
|
// packages/cli/src/dev-shared.ts
|
|
3983
|
-
import { readdir as readdir2, readFile as
|
|
3984
|
-
import { join as
|
|
4239
|
+
import { readdir as readdir2, readFile as readFile6 } from "node:fs/promises";
|
|
4240
|
+
import { join as join9 } from "node:path";
|
|
3985
4241
|
|
|
3986
4242
|
// packages/runtime/src/shared/function-source.ts
|
|
3987
4243
|
var SHARED_SOURCE_ROOT = "functions/_shared/";
|
|
@@ -4044,11 +4300,11 @@ async function collectFunctions(dir) {
|
|
|
4044
4300
|
}
|
|
4045
4301
|
for (const entry of entries) {
|
|
4046
4302
|
const rel = prefix.length === 0 ? entry.name : `${prefix}/${entry.name}`;
|
|
4047
|
-
const full =
|
|
4303
|
+
const full = join9(sub, entry.name);
|
|
4048
4304
|
if (entry.isDirectory()) {
|
|
4049
4305
|
await walk(full, rel);
|
|
4050
4306
|
} else if (entry.isFile() && isRuntimeSource(entry.name)) {
|
|
4051
|
-
files[rel] = await
|
|
4307
|
+
files[rel] = await readFile6(full, "utf8");
|
|
4052
4308
|
}
|
|
4053
4309
|
}
|
|
4054
4310
|
};
|
|
@@ -4118,7 +4374,7 @@ async function requestInput(url, req, readBody) {
|
|
|
4118
4374
|
|
|
4119
4375
|
// packages/cli/src/dev.ts
|
|
4120
4376
|
async function loadConfig(cwd) {
|
|
4121
|
-
const name = basename(
|
|
4377
|
+
const name = basename(resolve4(cwd));
|
|
4122
4378
|
const config = await loadAdepConfigModule(cwd);
|
|
4123
4379
|
return {
|
|
4124
4380
|
name: config?.name ?? name,
|
|
@@ -4161,34 +4417,49 @@ function printBoundaries(log) {
|
|
|
4161
4417
|
}
|
|
4162
4418
|
}
|
|
4163
4419
|
async function ensureGitignore(cwd) {
|
|
4164
|
-
const gitignorePath =
|
|
4165
|
-
const existing = await
|
|
4420
|
+
const gitignorePath = join10(cwd, ".gitignore");
|
|
4421
|
+
const existing = await readFile7(gitignorePath, "utf8").catch(() => "");
|
|
4166
4422
|
if (existing.split(/\r?\n/).includes(".adep/")) return;
|
|
4167
4423
|
await writeFile3(gitignorePath, `${existing.replace(/\n+$/, "")}
|
|
4168
4424
|
.adep/
|
|
4169
4425
|
`, "utf8");
|
|
4170
4426
|
}
|
|
4171
4427
|
async function startDevServer(options) {
|
|
4172
|
-
const cwd =
|
|
4428
|
+
const cwd = resolve4(options.cwd);
|
|
4173
4429
|
const log = options.log ?? ((line) => process.stdout.write(`${line}
|
|
4174
4430
|
`));
|
|
4175
4431
|
const config = await loadConfig(cwd);
|
|
4176
4432
|
if (options.prefix !== void 0) {
|
|
4177
4433
|
config.functionsPrefix = options.prefix.replace(/^\/+|\/+$/g, "");
|
|
4178
4434
|
}
|
|
4179
|
-
const functionsDir =
|
|
4435
|
+
const functionsDir = join10(cwd, config.functionsDir);
|
|
4180
4436
|
const coldStartAt = Date.now();
|
|
4437
|
+
const dbTarget = resolveLocalDbTarget(cwd, {
|
|
4438
|
+
...options.db === void 0 ? {} : { db: options.db },
|
|
4439
|
+
...options.dbFile === void 0 ? {} : { dbFile: options.dbFile }
|
|
4440
|
+
});
|
|
4181
4441
|
const bearerUser = bearerUserResolverFromEnv();
|
|
4182
4442
|
const executor = new WorkerFunctionExecutor({
|
|
4183
4443
|
deps: { rootDir: cwd, builtin: LOCAL_BUILTIN_DEPS }
|
|
4184
4444
|
});
|
|
4185
|
-
await
|
|
4445
|
+
await mkdir4(functionsDir, { recursive: true });
|
|
4446
|
+
const db = await openLocalDbDriver(dbTarget, { cwd, tag: "adep", log });
|
|
4186
4447
|
const runtime = await createSimRuntime({
|
|
4187
4448
|
cwd,
|
|
4188
4449
|
projectId: "local",
|
|
4189
4450
|
baseUrl: `http://127.0.0.1:${options.port ?? 8787}`,
|
|
4190
|
-
log
|
|
4451
|
+
log,
|
|
4452
|
+
...db.driver === null ? {} : { driver: db.driver }
|
|
4191
4453
|
});
|
|
4454
|
+
if (options.schemaFile !== void 0) {
|
|
4455
|
+
await applyLocalSchema(runtime.db.driver, {
|
|
4456
|
+
cwd,
|
|
4457
|
+
schemaFile: options.schemaFile,
|
|
4458
|
+
mode: db.mode,
|
|
4459
|
+
tag: "adep",
|
|
4460
|
+
log
|
|
4461
|
+
});
|
|
4462
|
+
}
|
|
4192
4463
|
await ensureGitignore(cwd);
|
|
4193
4464
|
let files = mergeSharedIntoFunctions(await collectFunctions(functionsDir));
|
|
4194
4465
|
let env = {
|
|
@@ -4269,12 +4540,12 @@ async function startDevServer(options) {
|
|
|
4269
4540
|
const reload = async () => {
|
|
4270
4541
|
const [nextFiles, envText2] = await Promise.all([
|
|
4271
4542
|
collectFunctions(functionsDir).then(mergeSharedIntoFunctions),
|
|
4272
|
-
|
|
4543
|
+
readFile7(join10(cwd, ".env.local"), "utf8").catch(() => "")
|
|
4273
4544
|
]);
|
|
4274
4545
|
files = nextFiles;
|
|
4275
4546
|
env = { ...config.environment, ...parseEnvFile(envText2) };
|
|
4276
4547
|
};
|
|
4277
|
-
const envText = await
|
|
4548
|
+
const envText = await readFile7(join10(cwd, ".env.local"), "utf8").catch(() => "");
|
|
4278
4549
|
env = { ...config.environment, ...parseEnvFile(envText) };
|
|
4279
4550
|
let debounceTimer;
|
|
4280
4551
|
let watcher;
|
|
@@ -4431,13 +4702,17 @@ async function startDevServer(options) {
|
|
|
4431
4702
|
const baseUrl = `http://127.0.0.1:${actualPort}`;
|
|
4432
4703
|
const coldStartMs = Date.now() - coldStartAt;
|
|
4433
4704
|
const curlPath = config.functionsPrefix.length === 0 ? "/hello" : `/${config.functionsPrefix}/hello`;
|
|
4434
|
-
|
|
4705
|
+
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";
|
|
4706
|
+
const dbTargetText = db.file === null ? simDbTarget(cwd) : displayPath(cwd, db.file);
|
|
4707
|
+
log(
|
|
4708
|
+
`[adep] dev server listening on ${baseUrl}\uFF08\u672C\u5730\u8FD0\u884C\u65F6 / ${dbLabel}\uFF0C\u51B7\u542F\u52A8 ${coldStartMs}ms\uFF09`
|
|
4709
|
+
);
|
|
4435
4710
|
log(`[adep] curl \u793A\u4F8B\uFF1Acurl ${baseUrl}${curlPath}`);
|
|
4436
4711
|
printBoundaries(log);
|
|
4437
4712
|
if (bearerUser !== void 0) {
|
|
4438
4713
|
log(`[adep] \u767B\u5F55\u5373\u670D\u52A1\uFF1AADEP_AUTH_ISSUER \u5DF2\u914D\u7F6E\uFF0CBearer token \u5C06\u89E3\u6790\u4E3A\u7528\u6237\u8EAB\u4EFD\uFF08userinfo \u7AEF\u70B9\uFF09`);
|
|
4439
4714
|
}
|
|
4440
|
-
log(`[adep] \
|
|
4715
|
+
log(`[adep] \u6570\u636E\u5E93\uFF1A${dbLabel} \u2192 ${dbTargetText}`);
|
|
4441
4716
|
startStateAlarmScheduler();
|
|
4442
4717
|
return {
|
|
4443
4718
|
port: actualPort,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adep/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
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,10 +21,11 @@
|
|
|
21
21
|
"commander": "14.0.2",
|
|
22
22
|
"esbuild": "0.25.12",
|
|
23
23
|
"@adep/cf-compat": "0.1.1",
|
|
24
|
-
"@adep/
|
|
24
|
+
"@adep/crypto": "0.1.0",
|
|
25
|
+
"@adep/vite-plugin": "0.1.7",
|
|
26
|
+
"@adep/runtime": "0.2.7"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
|
-
"@adep/runtime": "0.2.6",
|
|
28
29
|
"@adep/types": "0.2.3"
|
|
29
30
|
},
|
|
30
31
|
"scripts": {
|