@adep/cli 0.0.4 → 0.0.5
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/index.js +34 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2915,6 +2915,25 @@ var init_env = __esm({
|
|
|
2915
2915
|
});
|
|
2916
2916
|
|
|
2917
2917
|
// packages/cli/src/sim/invoke.ts
|
|
2918
|
+
function resolveFunctionEntry(files, fnName) {
|
|
2919
|
+
const flat = `${fnName}.ts`;
|
|
2920
|
+
if (files[flat] !== void 0) return flat;
|
|
2921
|
+
const directory = `${fnName}/index.ts`;
|
|
2922
|
+
if (files[directory] !== void 0) return directory;
|
|
2923
|
+
return void 0;
|
|
2924
|
+
}
|
|
2925
|
+
function listFunctionNames(files) {
|
|
2926
|
+
const names = /* @__PURE__ */ new Set();
|
|
2927
|
+
for (const key of Object.keys(files)) {
|
|
2928
|
+
const parts = key.split("/");
|
|
2929
|
+
if (parts.length === 1 && parts[0]?.endsWith(".ts")) {
|
|
2930
|
+
names.add(parts[0].slice(0, -3));
|
|
2931
|
+
} else if (parts.length === 2 && parts[1] === "index.ts") {
|
|
2932
|
+
names.add(parts[0]);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
return [...names];
|
|
2936
|
+
}
|
|
2918
2937
|
function createSimInvokeHandler(options) {
|
|
2919
2938
|
return async (method, args) => {
|
|
2920
2939
|
if (method !== "invoke") {
|
|
@@ -2924,7 +2943,10 @@ function createSimInvokeHandler(options) {
|
|
|
2924
2943
|
if (typeof input?.name !== "string" || input.name.length === 0) {
|
|
2925
2944
|
throw new Error("cloud.invoke \u9700\u8981\u76EE\u6807\u51FD\u6570\u540D\uFF08InvokeInput.name\uFF09");
|
|
2926
2945
|
}
|
|
2927
|
-
const targetEntry =
|
|
2946
|
+
const targetEntry = resolveFunctionEntry(options.files, input.name);
|
|
2947
|
+
if (targetEntry === void 0) {
|
|
2948
|
+
throw new Error(`\u76EE\u6807\u51FD\u6570 "${input.name}" \u4E0D\u5B58\u5728`);
|
|
2949
|
+
}
|
|
2928
2950
|
const executeInput = {
|
|
2929
2951
|
project: { id: "local", slug: "local" },
|
|
2930
2952
|
fn: { id: input.name, name: input.name },
|
|
@@ -3130,7 +3152,7 @@ async function startDevServer(options) {
|
|
|
3130
3152
|
} catch {
|
|
3131
3153
|
watcher = void 0;
|
|
3132
3154
|
}
|
|
3133
|
-
const buildInput = async (fnName, url, req) => {
|
|
3155
|
+
const buildInput = async (fnName, entry, url, req) => {
|
|
3134
3156
|
const query = {};
|
|
3135
3157
|
for (const key of new Set(url.searchParams.keys())) {
|
|
3136
3158
|
const values = url.searchParams.getAll(key);
|
|
@@ -3146,7 +3168,7 @@ async function startDevServer(options) {
|
|
|
3146
3168
|
project: { id: "local", slug: config.name },
|
|
3147
3169
|
fn: { id: fnName, name: fnName },
|
|
3148
3170
|
files,
|
|
3149
|
-
entry
|
|
3171
|
+
entry,
|
|
3150
3172
|
request: {
|
|
3151
3173
|
method: req.method ?? "GET",
|
|
3152
3174
|
path: url.pathname,
|
|
@@ -3173,14 +3195,13 @@ async function startDevServer(options) {
|
|
|
3173
3195
|
});
|
|
3174
3196
|
return;
|
|
3175
3197
|
}
|
|
3176
|
-
const entry =
|
|
3177
|
-
|
|
3178
|
-
if (source === void 0) {
|
|
3198
|
+
const entry = resolveFunctionEntry(files, fnName);
|
|
3199
|
+
if (entry === void 0) {
|
|
3179
3200
|
log(`[adep] ${req.method ?? "GET"} /${fnName} -> 404\uFF08\u51FD\u6570\u4E0D\u5B58\u5728\uFF09`);
|
|
3180
3201
|
writeJson(res, 404, { error: { code: "FN_NOT_FOUND", message: `\u51FD\u6570 "${fnName}" \u4E0D\u5B58\u5728` } });
|
|
3181
3202
|
return;
|
|
3182
3203
|
}
|
|
3183
|
-
const input = await buildInput(fnName, url, req);
|
|
3204
|
+
const input = await buildInput(fnName, entry, url, req);
|
|
3184
3205
|
const startedAt = performance.now();
|
|
3185
3206
|
try {
|
|
3186
3207
|
const result = await executor.execute(input);
|
|
@@ -3655,7 +3676,7 @@ async function startServeServer(options) {
|
|
|
3655
3676
|
hasStatic = false;
|
|
3656
3677
|
}
|
|
3657
3678
|
const files = await collectFunctions2(functionsDir);
|
|
3658
|
-
const functionNames =
|
|
3679
|
+
const functionNames = listFunctionNames(files);
|
|
3659
3680
|
const envText = await readFile7(join11(cwd, ".env.local"), "utf8").catch(() => "");
|
|
3660
3681
|
const env = parseEnvFile(envText);
|
|
3661
3682
|
const simEnv = await loadSimEnv(cwd).catch(() => ({}));
|
|
@@ -3668,7 +3689,7 @@ async function startServeServer(options) {
|
|
|
3668
3689
|
const executor = new WorkerFunctionExecutor();
|
|
3669
3690
|
const dbBundle = runtime.bundle;
|
|
3670
3691
|
const invokeHandler = createSimInvokeHandler({ executor, files });
|
|
3671
|
-
const buildInput = async (fnName, url, req) => {
|
|
3692
|
+
const buildInput = async (fnName, entry, url, req) => {
|
|
3672
3693
|
const query = {};
|
|
3673
3694
|
for (const key of new Set(url.searchParams.keys())) {
|
|
3674
3695
|
const values = url.searchParams.getAll(key);
|
|
@@ -3685,7 +3706,7 @@ async function startServeServer(options) {
|
|
|
3685
3706
|
project: { id: "local", slug: config.name },
|
|
3686
3707
|
fn: { id: fnName, name: fnName },
|
|
3687
3708
|
files,
|
|
3688
|
-
entry
|
|
3709
|
+
entry,
|
|
3689
3710
|
request: {
|
|
3690
3711
|
method: req.method ?? "GET",
|
|
3691
3712
|
path: url.pathname,
|
|
@@ -3742,14 +3763,13 @@ async function startServeServer(options) {
|
|
|
3742
3763
|
});
|
|
3743
3764
|
return;
|
|
3744
3765
|
}
|
|
3745
|
-
const entry =
|
|
3746
|
-
|
|
3747
|
-
if (source === void 0) {
|
|
3766
|
+
const entry = resolveFunctionEntry(files, fnName);
|
|
3767
|
+
if (entry === void 0) {
|
|
3748
3768
|
log(`[serve] ${req.method ?? "GET"} ${pathname} -> 404\uFF08\u51FD\u6570\u4E0D\u5B58\u5728\uFF09`);
|
|
3749
3769
|
writeJson2(res, 404, { error: { code: "FN_NOT_FOUND", message: `\u51FD\u6570 "${fnName}" \u4E0D\u5B58\u5728` } });
|
|
3750
3770
|
return;
|
|
3751
3771
|
}
|
|
3752
|
-
const input = await buildInput(fnName, url, req);
|
|
3772
|
+
const input = await buildInput(fnName, entry, url, req);
|
|
3753
3773
|
const startedAt = performance.now();
|
|
3754
3774
|
try {
|
|
3755
3775
|
const result = await executor.execute(input);
|