@adep/cli 0.1.0 → 0.1.1
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 +219 -257
- package/dist/vite.js +57 -156
- package/dist/worker-entry.js +10 -10
- package/package.json +14 -29
- package/src/index.ts +0 -8
package/dist/vite.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
// src/vite.ts
|
|
2
|
-
import {
|
|
3
|
-
import { resolve as resolve3 } from "node:path";
|
|
1
|
+
// packages/cli/src/vite.ts
|
|
2
|
+
import { adepPlugin } from "@adep/vite-plugin";
|
|
4
3
|
|
|
5
|
-
// src/dev.ts
|
|
4
|
+
// packages/cli/src/dev.ts
|
|
6
5
|
import { createServer } from "node:http";
|
|
7
6
|
import { watch } from "node:fs";
|
|
8
7
|
import { mkdir as mkdir3, readdir as readdir2, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
|
|
9
8
|
import { basename, join as join7, resolve as resolve2 } from "node:path";
|
|
10
9
|
|
|
11
|
-
//
|
|
10
|
+
// packages/runtime/src/shared/capability-keys.ts
|
|
12
11
|
var RPC_CAPABILITY_KEY = "__adepRpc";
|
|
13
12
|
var CHAIN_CAPABILITY_KEY = "__adepChain";
|
|
14
13
|
var DB_RPC = {
|
|
@@ -40,7 +39,7 @@ var REALTIME_CAPABILITY_METHODS = [
|
|
|
40
39
|
"unsubscribe"
|
|
41
40
|
];
|
|
42
41
|
|
|
43
|
-
//
|
|
42
|
+
// packages/runtime/src/shared/executor-runtime.ts
|
|
44
43
|
var ExecutorError = class extends Error {
|
|
45
44
|
constructor(status, code, message) {
|
|
46
45
|
super(message);
|
|
@@ -60,19 +59,19 @@ function normalizeHttpStatus(status) {
|
|
|
60
59
|
return isHttpStatus(status) ? status : 500;
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
//
|
|
62
|
+
// packages/runtime/src/functions/runtime/worker-executor.ts
|
|
64
63
|
import { readFileSync } from "node:fs";
|
|
65
64
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
66
65
|
import { dirname, join } from "node:path";
|
|
67
66
|
import { Worker } from "node:worker_threads";
|
|
68
67
|
|
|
69
|
-
//
|
|
68
|
+
// packages/runtime/src/functions/deps/resolve.ts
|
|
70
69
|
import { resolve } from "node:path";
|
|
71
70
|
|
|
72
|
-
//
|
|
71
|
+
// packages/runtime/src/functions/deps/manifest.ts
|
|
73
72
|
import { createHash } from "node:crypto";
|
|
74
73
|
|
|
75
|
-
//
|
|
74
|
+
// packages/runtime/src/functions/domain.ts
|
|
76
75
|
var MAX_TOTAL_SOURCE_BYTES = 256 * 1024;
|
|
77
76
|
var FnError = class extends Error {
|
|
78
77
|
status;
|
|
@@ -85,7 +84,7 @@ var FnError = class extends Error {
|
|
|
85
84
|
}
|
|
86
85
|
};
|
|
87
86
|
|
|
88
|
-
//
|
|
87
|
+
// packages/runtime/src/functions/deps/manifest.ts
|
|
89
88
|
var PACKAGE_NAME_PATTERN = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-._~]+$/;
|
|
90
89
|
var COMPARATOR_PATTERN = /^(?:\^|~|>=|<=|>|<|=)?\d+(?:\.(?:\d+|x|X|\*)){0,2}(?:-[\w.-]+)?(?:\+[\w.-]+)?$/;
|
|
91
90
|
var MANIFEST_MAX_DEPS = 100;
|
|
@@ -167,7 +166,7 @@ function depsKeyOf(dependencies) {
|
|
|
167
166
|
return createHash("sha256").update(canonical).digest("hex").slice(0, 16);
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
//
|
|
169
|
+
// packages/runtime/src/functions/deps/resolve.ts
|
|
171
170
|
function resolveExecutionDeps(config, projectId, manifestContent) {
|
|
172
171
|
const manifest = tryParseManifestDependencies(manifestContent);
|
|
173
172
|
const { customDeps } = classifyDependencies(manifest, config.builtin);
|
|
@@ -180,7 +179,7 @@ function resolveExecutionDeps(config, projectId, manifestContent) {
|
|
|
180
179
|
};
|
|
181
180
|
}
|
|
182
181
|
|
|
183
|
-
//
|
|
182
|
+
// packages/runtime/src/functions/runtime/worker-executor.ts
|
|
184
183
|
function resolveWorkerEntry(baseDir = fileURLToPath(new URL(".", import.meta.url))) {
|
|
185
184
|
const candidates = [
|
|
186
185
|
join(baseDir, "worker-entry.js"),
|
|
@@ -230,7 +229,7 @@ var WorkerFunctionExecutor = class {
|
|
|
230
229
|
const entry = input.entry ?? "index.ts";
|
|
231
230
|
const deps = this.depsConfig === void 0 ? void 0 : resolveExecutionDeps(this.depsConfig, input.project.id, input.files["package.json"]);
|
|
232
231
|
const logs = [];
|
|
233
|
-
return new Promise((
|
|
232
|
+
return new Promise((resolve3, reject) => {
|
|
234
233
|
let worker;
|
|
235
234
|
try {
|
|
236
235
|
worker = new Worker(resolveWorkerEntry(), {
|
|
@@ -292,7 +291,7 @@ var WorkerFunctionExecutor = class {
|
|
|
292
291
|
if (message.type === "result") {
|
|
293
292
|
clearTimeout(timer);
|
|
294
293
|
void worker.terminate();
|
|
295
|
-
|
|
294
|
+
resolve3({ body: message.body, logs });
|
|
296
295
|
return;
|
|
297
296
|
}
|
|
298
297
|
if (message.type === "error") {
|
|
@@ -325,11 +324,11 @@ var WorkerFunctionExecutor = class {
|
|
|
325
324
|
}
|
|
326
325
|
};
|
|
327
326
|
|
|
328
|
-
// src/sim/runtime.ts
|
|
327
|
+
// packages/cli/src/sim/runtime.ts
|
|
329
328
|
import { mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "node:fs/promises";
|
|
330
329
|
import { dirname as dirname3, join as join4 } from "node:path";
|
|
331
330
|
|
|
332
|
-
//
|
|
331
|
+
// packages/runtime/src/database/builder/dialect.ts
|
|
333
332
|
var sqliteDialect = {
|
|
334
333
|
name: "sqlite",
|
|
335
334
|
placeholder: () => "?",
|
|
@@ -348,7 +347,7 @@ function dialectFor(driver) {
|
|
|
348
347
|
return driver.engine === "pg" ? postgresDialect : sqliteDialect;
|
|
349
348
|
}
|
|
350
349
|
|
|
351
|
-
//
|
|
350
|
+
// packages/runtime/src/database/provision/identifier.ts
|
|
352
351
|
var DbError = class extends Error {
|
|
353
352
|
constructor(status, code, message) {
|
|
354
353
|
super(message);
|
|
@@ -372,7 +371,7 @@ function quoteIdentifier(name) {
|
|
|
372
371
|
return `"${name.replace(/"/g, '""')}"`;
|
|
373
372
|
}
|
|
374
373
|
|
|
375
|
-
//
|
|
374
|
+
// packages/runtime/src/database/builder/guards.ts
|
|
376
375
|
function unsafeOperation(message) {
|
|
377
376
|
return new DbError(400, "DB_UNSAFE_OP", message);
|
|
378
377
|
}
|
|
@@ -396,7 +395,7 @@ function assertReadOnlyQuery(sql) {
|
|
|
396
395
|
}
|
|
397
396
|
}
|
|
398
397
|
|
|
399
|
-
//
|
|
398
|
+
// packages/runtime/src/database/builder/owned.ts
|
|
400
399
|
var OWNED_PK = "id";
|
|
401
400
|
var OWNED_OWNER_KEY = "__owner_key";
|
|
402
401
|
var CHANGE_LOG_PREFIX = "_adep_changes_";
|
|
@@ -509,7 +508,7 @@ async function readChanges(driver, table, query = {}) {
|
|
|
509
508
|
return rows.map(parseChange);
|
|
510
509
|
}
|
|
511
510
|
|
|
512
|
-
//
|
|
511
|
+
// packages/runtime/src/database/builder/ulid.ts
|
|
513
512
|
var ENCODING = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
|
|
514
513
|
var TIME_LEN = 10;
|
|
515
514
|
var RANDOM_LEN = 16;
|
|
@@ -575,7 +574,7 @@ function ulid(now = Date.now()) {
|
|
|
575
574
|
return time + random;
|
|
576
575
|
}
|
|
577
576
|
|
|
578
|
-
//
|
|
577
|
+
// packages/runtime/src/database/builder/table.ts
|
|
579
578
|
var OPERATORS = /* @__PURE__ */ new Set([
|
|
580
579
|
"=",
|
|
581
580
|
"!=",
|
|
@@ -894,7 +893,7 @@ function createTableBuilder(table, driver, dialect, options = {}) {
|
|
|
894
893
|
return build(initialState);
|
|
895
894
|
}
|
|
896
895
|
|
|
897
|
-
//
|
|
896
|
+
// packages/runtime/src/database/builder/index.ts
|
|
898
897
|
var TX_STATES = /* @__PURE__ */ new WeakMap();
|
|
899
898
|
function createCloudDb(driver, options = {}) {
|
|
900
899
|
const dialect = options.dialect ?? dialectFor(driver);
|
|
@@ -948,7 +947,7 @@ function createCloudDb(driver, options = {}) {
|
|
|
948
947
|
return makeHandle({ allowWriteDuringTx: false });
|
|
949
948
|
}
|
|
950
949
|
|
|
951
|
-
//
|
|
950
|
+
// packages/runtime/src/database/sdk/cloud.ts
|
|
952
951
|
var CLOUD_DB_SPEC = {
|
|
953
952
|
kind: "cloud-db",
|
|
954
953
|
rootMethod: "table",
|
|
@@ -1052,7 +1051,7 @@ function createDbCapability(driver, options = {}) {
|
|
|
1052
1051
|
};
|
|
1053
1052
|
}
|
|
1054
1053
|
|
|
1055
|
-
// src/sim/sql-engine.ts
|
|
1054
|
+
// packages/cli/src/sim/sql-engine.ts
|
|
1056
1055
|
var SimDbError = class extends Error {
|
|
1057
1056
|
constructor(code, message) {
|
|
1058
1057
|
super(message);
|
|
@@ -1470,7 +1469,7 @@ function project(rows, selectRaw) {
|
|
|
1470
1469
|
});
|
|
1471
1470
|
}
|
|
1472
1471
|
|
|
1473
|
-
// src/sim/db.ts
|
|
1472
|
+
// packages/cli/src/sim/db.ts
|
|
1474
1473
|
function toProjectDriver(engine) {
|
|
1475
1474
|
return {
|
|
1476
1475
|
engine: "sqlite",
|
|
@@ -1490,10 +1489,10 @@ function createSimDbCapability(options = {}) {
|
|
|
1490
1489
|
return { bundle, engine, driver };
|
|
1491
1490
|
}
|
|
1492
1491
|
|
|
1493
|
-
// src/sim/storage.ts
|
|
1492
|
+
// packages/cli/src/sim/storage.ts
|
|
1494
1493
|
import { join as join3 } from "node:path";
|
|
1495
1494
|
|
|
1496
|
-
//
|
|
1495
|
+
// packages/runtime/src/storage/driver.ts
|
|
1497
1496
|
var PROJECT_QUOTA_BYTES = 1024 * 1024 * 1024;
|
|
1498
1497
|
var StorageError = class extends Error {
|
|
1499
1498
|
constructor(status, code, message) {
|
|
@@ -1534,7 +1533,7 @@ function assertSafeStoragePath(path) {
|
|
|
1534
1533
|
return path;
|
|
1535
1534
|
}
|
|
1536
1535
|
|
|
1537
|
-
//
|
|
1536
|
+
// packages/runtime/src/storage/hmac-sha256.ts
|
|
1538
1537
|
var K = new Uint32Array([
|
|
1539
1538
|
1116352408,
|
|
1540
1539
|
1899447441,
|
|
@@ -1695,7 +1694,7 @@ function hmacSha256Hex(key, message) {
|
|
|
1695
1694
|
return [...hmacSha256(key, message)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1696
1695
|
}
|
|
1697
1696
|
|
|
1698
|
-
//
|
|
1697
|
+
// packages/runtime/src/storage/signature.ts
|
|
1699
1698
|
var DEFAULT_SIGN_TTL_SECONDS = 15 * 60;
|
|
1700
1699
|
var SIGN_EXPIRES_KEY = "x-expires";
|
|
1701
1700
|
var SIGN_SIGNATURE_KEY = "x-signature";
|
|
@@ -1710,7 +1709,7 @@ function signDownloadUrl(config, projectId, path, ttlSeconds = DEFAULT_SIGN_TTL_
|
|
|
1710
1709
|
return `${base}?${SIGN_EXPIRES_KEY}=${expires}&${SIGN_SIGNATURE_KEY}=${signature}`;
|
|
1711
1710
|
}
|
|
1712
1711
|
|
|
1713
|
-
//
|
|
1712
|
+
// packages/runtime/src/storage/cloud.ts
|
|
1714
1713
|
var DEFAULT_VISIBILITY = "private";
|
|
1715
1714
|
function asBytes(data) {
|
|
1716
1715
|
if (typeof data === "string") return new TextEncoder().encode(data);
|
|
@@ -1769,7 +1768,7 @@ function createStorageCapability(driver, signer, projectId) {
|
|
|
1769
1768
|
};
|
|
1770
1769
|
}
|
|
1771
1770
|
|
|
1772
|
-
//
|
|
1771
|
+
// packages/runtime/src/storage/driver/local.ts
|
|
1773
1772
|
import { mkdir, readFile, readdir, rm, stat, unlink, writeFile } from "node:fs/promises";
|
|
1774
1773
|
import { dirname as dirname2, join as join2 } from "node:path";
|
|
1775
1774
|
var META_SUFFIX = ".adep-meta.json";
|
|
@@ -1976,7 +1975,7 @@ function createLocalStorageDriver(options) {
|
|
|
1976
1975
|
};
|
|
1977
1976
|
}
|
|
1978
1977
|
|
|
1979
|
-
// src/sim/storage.ts
|
|
1978
|
+
// packages/cli/src/sim/storage.ts
|
|
1980
1979
|
function createSimStorageCapability(options) {
|
|
1981
1980
|
const dir = join3(options.cwd, ".adep", "sim", "storage");
|
|
1982
1981
|
const driver = createLocalStorageDriver({ dir });
|
|
@@ -1988,7 +1987,7 @@ function createSimStorageCapability(options) {
|
|
|
1988
1987
|
return { bundle, driver };
|
|
1989
1988
|
}
|
|
1990
1989
|
|
|
1991
|
-
// src/sim/realtime.ts
|
|
1990
|
+
// packages/cli/src/sim/realtime.ts
|
|
1992
1991
|
var SimRealtime = class {
|
|
1993
1992
|
seq = 0;
|
|
1994
1993
|
subscribers = /* @__PURE__ */ new Map();
|
|
@@ -2110,7 +2109,7 @@ function createSimRealtimeCapability() {
|
|
|
2110
2109
|
};
|
|
2111
2110
|
}
|
|
2112
2111
|
|
|
2113
|
-
// src/sim/runtime.ts
|
|
2112
|
+
// packages/cli/src/sim/runtime.ts
|
|
2114
2113
|
function simDir(cwd) {
|
|
2115
2114
|
return join4(cwd, ".adep", "sim");
|
|
2116
2115
|
}
|
|
@@ -2173,7 +2172,7 @@ async function createSimRuntime(options) {
|
|
|
2173
2172
|
};
|
|
2174
2173
|
}
|
|
2175
2174
|
|
|
2176
|
-
// src/sim/env.ts
|
|
2175
|
+
// packages/cli/src/sim/env.ts
|
|
2177
2176
|
import { readFile as readFile3 } from "node:fs/promises";
|
|
2178
2177
|
import { join as join5 } from "node:path";
|
|
2179
2178
|
function parseEnv(content) {
|
|
@@ -2206,7 +2205,7 @@ async function loadSimEnv(cwd, config = {}) {
|
|
|
2206
2205
|
return merged;
|
|
2207
2206
|
}
|
|
2208
2207
|
|
|
2209
|
-
// src/sim/invoke.ts
|
|
2208
|
+
// packages/cli/src/sim/invoke.ts
|
|
2210
2209
|
function resolveFunctionEntry(files, fnName) {
|
|
2211
2210
|
const flat = `${fnName}.ts`;
|
|
2212
2211
|
if (files[flat] !== void 0) return flat;
|
|
@@ -2247,7 +2246,7 @@ function createSimInvokeHandler(options) {
|
|
|
2247
2246
|
};
|
|
2248
2247
|
}
|
|
2249
2248
|
|
|
2250
|
-
// src/sim/boundary.ts
|
|
2249
|
+
// packages/cli/src/sim/boundary.ts
|
|
2251
2250
|
var SIM_BOUNDARIES = [
|
|
2252
2251
|
{
|
|
2253
2252
|
kind: "capability",
|
|
@@ -2276,11 +2275,11 @@ var SIM_BOUNDARIES = [
|
|
|
2276
2275
|
}
|
|
2277
2276
|
];
|
|
2278
2277
|
|
|
2279
|
-
// src/ts-config.ts
|
|
2278
|
+
// packages/cli/src/ts-config.ts
|
|
2280
2279
|
import { stat as stat2, readFile as readFile4 } from "node:fs/promises";
|
|
2281
2280
|
import { join as join6 } from "node:path";
|
|
2282
2281
|
|
|
2283
|
-
//
|
|
2282
|
+
// shared/sdk/adep-config.ts
|
|
2284
2283
|
var DEFAULT_ADEP_CONFIG = {
|
|
2285
2284
|
functionsDir: "functions",
|
|
2286
2285
|
functions_prefix: "/api"
|
|
@@ -2366,7 +2365,7 @@ function parseAdepConfig(raw) {
|
|
|
2366
2365
|
return { ok: true, data };
|
|
2367
2366
|
}
|
|
2368
2367
|
|
|
2369
|
-
// src/ts-config.ts
|
|
2368
|
+
// packages/cli/src/ts-config.ts
|
|
2370
2369
|
async function loadAdepConfigModule(cwd) {
|
|
2371
2370
|
const configPath = join6(cwd, "adep.config.ts");
|
|
2372
2371
|
try {
|
|
@@ -2410,7 +2409,7 @@ ${result.errors.map((e) => ` - ${e}`).join("\n")}`;
|
|
|
2410
2409
|
return result.data;
|
|
2411
2410
|
}
|
|
2412
2411
|
|
|
2413
|
-
// src/dev.ts
|
|
2412
|
+
// packages/cli/src/dev.ts
|
|
2414
2413
|
async function loadConfig(cwd) {
|
|
2415
2414
|
const name = basename(resolve2(cwd));
|
|
2416
2415
|
const config = await loadAdepConfigModule(cwd);
|
|
@@ -2693,126 +2692,28 @@ async function startDevServer(options) {
|
|
|
2693
2692
|
};
|
|
2694
2693
|
}
|
|
2695
2694
|
|
|
2696
|
-
// src/vite.ts
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
}
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
const prefixPath = normalized === "" ? "" : `/${normalized}`;
|
|
2708
|
-
return (req, res, next) => {
|
|
2709
|
-
if (prefixPath === "") return next();
|
|
2710
|
-
const url = new URL(req.url ?? "/", "http://127.0.0.1");
|
|
2711
|
-
if (url.pathname !== prefixPath && !url.pathname.startsWith(`${prefixPath}/`)) {
|
|
2712
|
-
return next();
|
|
2713
|
-
}
|
|
2714
|
-
const target = new URL(url.pathname + url.search, targetBase);
|
|
2715
|
-
const proxyReq = httpRequest(
|
|
2716
|
-
target,
|
|
2717
|
-
{ method: req.method, headers: { ...req.headers, host: target.host } },
|
|
2718
|
-
(proxyRes) => {
|
|
2719
|
-
res.writeHead(proxyRes.statusCode ?? 502, proxyRes.headers);
|
|
2720
|
-
proxyRes.pipe(res);
|
|
2721
|
-
}
|
|
2722
|
-
);
|
|
2723
|
-
proxyReq.on("error", (error) => {
|
|
2724
|
-
if (!res.headersSent) {
|
|
2725
|
-
res.writeHead(502, { "content-type": "application/json" });
|
|
2726
|
-
}
|
|
2727
|
-
res.end(
|
|
2728
|
-
JSON.stringify({
|
|
2729
|
-
error: {
|
|
2730
|
-
code: "ADEP_DEV_UNAVAILABLE",
|
|
2731
|
-
message: `\u4E91\u51FD\u6570\u4EE3\u7406\u5931\u8D25\uFF08adep dev server \u4E0D\u53EF\u8FBE\uFF09\uFF1A${error.message}`
|
|
2732
|
-
}
|
|
2733
|
-
})
|
|
2734
|
-
);
|
|
2735
|
-
});
|
|
2736
|
-
req.pipe(proxyReq);
|
|
2737
|
-
};
|
|
2738
|
-
}
|
|
2695
|
+
// packages/cli/src/vite.ts
|
|
2696
|
+
import {
|
|
2697
|
+
createAdepFnProxyScriptMiddleware,
|
|
2698
|
+
createAdepProxyMiddleware,
|
|
2699
|
+
FN_FETCH_INTERCEPTOR_SCRIPT,
|
|
2700
|
+
injectFnProxyScriptTag,
|
|
2701
|
+
isAddrInUse,
|
|
2702
|
+
normalizeFunctionPrefix
|
|
2703
|
+
} from "@adep/vite-plugin";
|
|
2704
|
+
var createDevServer = (opts) => startDevServer({ cwd: opts.cwd, port: opts.port, prefix: opts.prefix, log: opts.log });
|
|
2705
|
+
var loadConfig2 = (cwd) => loadAdepConfigModule(cwd);
|
|
2739
2706
|
function adepVitePlugin(options = {}) {
|
|
2740
|
-
|
|
2741
|
-
let dev;
|
|
2742
|
-
let prefix = normalizeFunctionPrefix(options.prefix);
|
|
2743
|
-
let prefixPath = "";
|
|
2744
|
-
let startPromise;
|
|
2745
|
-
const startAdepDev = async (log) => {
|
|
2746
|
-
if (startPromise !== void 0) return startPromise;
|
|
2747
|
-
startPromise = (async () => {
|
|
2748
|
-
if (prefix === "") {
|
|
2749
|
-
const config = await loadAdepConfigModule(cwd);
|
|
2750
|
-
prefix = normalizeFunctionPrefix(config?.functions_prefix);
|
|
2751
|
-
if (prefix === "") {
|
|
2752
|
-
log("[adep] adep.config.ts \u672A\u914D\u7F6E functions_prefix\uFF0C\u4E91\u51FD\u6570\u4EE3\u7406\u524D\u7F00\u9ED8\u8BA4 /api");
|
|
2753
|
-
prefix = "api";
|
|
2754
|
-
}
|
|
2755
|
-
}
|
|
2756
|
-
prefixPath = `/${prefix}`;
|
|
2757
|
-
const targetPort = options.port ?? 8787;
|
|
2758
|
-
try {
|
|
2759
|
-
dev = await startDevServer({ cwd, port: targetPort, prefix, log });
|
|
2760
|
-
} catch (error) {
|
|
2761
|
-
if (isAddrInUse(error)) {
|
|
2762
|
-
log(`[adep] \u7AEF\u53E3 ${targetPort} \u88AB\u5360\u7528\uFF0C\u6539\u7528\u968F\u673A\u7AEF\u53E3`);
|
|
2763
|
-
dev = await startDevServer({ cwd, port: 0, prefix, log });
|
|
2764
|
-
} else {
|
|
2765
|
-
log(
|
|
2766
|
-
`[adep] \u4E91\u51FD\u6570 dev server \u542F\u52A8\u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}\uFF08vite \u524D\u7AEF\u7167\u5E38\uFF0C\u51FD\u6570\u4EE3\u7406\u4E0D\u53EF\u7528\uFF09`
|
|
2767
|
-
);
|
|
2768
|
-
}
|
|
2769
|
-
}
|
|
2770
|
-
if (dev !== void 0) {
|
|
2771
|
-
log(
|
|
2772
|
-
`[adep] \u4E91\u51FD\u6570\u5DF2\u5C31\u7EEA\uFF1A${dev.baseUrl}${prefixPath}/<fn>\uFF08vite \u4EE3\u7406 ${prefixPath}/* \u2192 \u4E91\u51FD\u6570\uFF09`
|
|
2773
|
-
);
|
|
2774
|
-
}
|
|
2775
|
-
})();
|
|
2776
|
-
try {
|
|
2777
|
-
await startPromise;
|
|
2778
|
-
} finally {
|
|
2779
|
-
startPromise = void 0;
|
|
2780
|
-
}
|
|
2781
|
-
};
|
|
2782
|
-
const disposeAdepDev = async () => {
|
|
2783
|
-
if (dev === void 0) return;
|
|
2784
|
-
const target = dev;
|
|
2785
|
-
dev = void 0;
|
|
2786
|
-
await target.close();
|
|
2787
|
-
};
|
|
2788
|
-
const attachProxy = (server) => {
|
|
2789
|
-
if (dev === void 0 || prefixPath === "") return;
|
|
2790
|
-
server.middlewares.use(createAdepProxyMiddleware(prefixPath, dev.baseUrl));
|
|
2791
|
-
};
|
|
2792
|
-
return {
|
|
2793
|
-
name: "adep-cloud-functions",
|
|
2794
|
-
async configureServer(server) {
|
|
2795
|
-
const log = (line) => server.config.logger.info(line);
|
|
2796
|
-
await startAdepDev(log);
|
|
2797
|
-
attachProxy(server);
|
|
2798
|
-
server.httpServer?.on("close", () => {
|
|
2799
|
-
void disposeAdepDev();
|
|
2800
|
-
});
|
|
2801
|
-
},
|
|
2802
|
-
async configurePreviewServer(server) {
|
|
2803
|
-
const log = (line) => server.config.logger.info(line);
|
|
2804
|
-
await startAdepDev(log);
|
|
2805
|
-
attachProxy(server);
|
|
2806
|
-
},
|
|
2807
|
-
async closeBundle() {
|
|
2808
|
-
await disposeAdepDev();
|
|
2809
|
-
}
|
|
2810
|
-
};
|
|
2707
|
+
return adepPlugin({ ...options, createDevServer, loadConfig: loadConfig2 });
|
|
2811
2708
|
}
|
|
2812
2709
|
var vite_default = adepVitePlugin;
|
|
2813
2710
|
export {
|
|
2711
|
+
FN_FETCH_INTERCEPTOR_SCRIPT,
|
|
2814
2712
|
adepVitePlugin,
|
|
2713
|
+
createAdepFnProxyScriptMiddleware,
|
|
2815
2714
|
createAdepProxyMiddleware,
|
|
2816
2715
|
vite_default as default,
|
|
2716
|
+
injectFnProxyScriptTag,
|
|
2717
|
+
isAddrInUse,
|
|
2817
2718
|
normalizeFunctionPrefix
|
|
2818
2719
|
};
|
package/dist/worker-entry.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
//
|
|
1
|
+
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
2
2
|
import { parentPort, workerData } from "node:worker_threads";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// packages/runtime/src/functions/runtime/cloud-container.ts
|
|
7
7
|
var KNOWN_CAPABILITY_HINTS = {
|
|
8
8
|
db: {
|
|
9
9
|
code: "DB_NOT_PROVISIONED",
|
|
@@ -79,11 +79,11 @@ function createCloudContainer() {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
//
|
|
82
|
+
// packages/runtime/src/functions/runtime/sandbox.ts
|
|
83
83
|
import vm from "node:vm";
|
|
84
84
|
import * as nodeModule from "node:module";
|
|
85
85
|
|
|
86
|
-
//
|
|
86
|
+
// packages/runtime/src/functions/runtime/exports.ts
|
|
87
87
|
function transformModule(code) {
|
|
88
88
|
let out = code;
|
|
89
89
|
const named = [];
|
|
@@ -125,7 +125,7 @@ function transformModule(code) {
|
|
|
125
125
|
return out;
|
|
126
126
|
}
|
|
127
127
|
|
|
128
|
-
//
|
|
128
|
+
// packages/runtime/src/functions/runtime/sandbox.ts
|
|
129
129
|
var bunTranspiler;
|
|
130
130
|
function transpile(code) {
|
|
131
131
|
const bun = globalThis["Bun"];
|
|
@@ -231,7 +231,7 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare) {
|
|
|
231
231
|
return { handler };
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
//
|
|
234
|
+
// packages/runtime/src/functions/runtime/sandbox-fetch.ts
|
|
235
235
|
var SandboxFetchError = class extends Error {
|
|
236
236
|
code;
|
|
237
237
|
constructor(code, message) {
|
|
@@ -410,7 +410,7 @@ function createSandboxFetch(options) {
|
|
|
410
410
|
};
|
|
411
411
|
}
|
|
412
412
|
|
|
413
|
-
//
|
|
413
|
+
// packages/runtime/src/shared/capability-keys.ts
|
|
414
414
|
var RPC_CAPABILITY_KEY = "__adepRpc";
|
|
415
415
|
var CHAIN_CAPABILITY_KEY = "__adepChain";
|
|
416
416
|
var DB_RPC = {
|
|
@@ -428,7 +428,7 @@ var DB_RPC = {
|
|
|
428
428
|
chain: "chain"
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
-
//
|
|
431
|
+
// packages/runtime/src/functions/runtime/chain.ts
|
|
432
432
|
function isChainCapability(value) {
|
|
433
433
|
if (typeof value !== "object" || value === null) return false;
|
|
434
434
|
const spec = value[CHAIN_CAPABILITY_KEY];
|
|
@@ -499,7 +499,7 @@ function createChainClient(capability, port, pending, nextId, spec) {
|
|
|
499
499
|
return makeRoot(void 0);
|
|
500
500
|
}
|
|
501
501
|
|
|
502
|
-
//
|
|
502
|
+
// packages/runtime/src/functions/deps/manifest.ts
|
|
503
503
|
function splitBareSpecifier(request) {
|
|
504
504
|
if (request.startsWith("@")) {
|
|
505
505
|
const segments = request.split("/");
|
|
@@ -508,7 +508,7 @@ function splitBareSpecifier(request) {
|
|
|
508
508
|
return request.split("/")[0];
|
|
509
509
|
}
|
|
510
510
|
|
|
511
|
-
//
|
|
511
|
+
// packages/runtime/src/functions/runtime/worker-entry.ts
|
|
512
512
|
function isRpcCapability(value) {
|
|
513
513
|
return typeof value === "object" && value !== null && value[RPC_CAPABILITY_KEY] === true;
|
|
514
514
|
}
|
package/package.json
CHANGED
|
@@ -1,49 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adep/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "`adep` 命令行工具包位:登录 / 初始化 / 本地调试 / 部署 / 数据库维护 / 云存储 / 静态托管 / 微前端组件(widget),实现见任务单 CLI-001 ~ CLI-003 与 FE-002;子路径 `@adep/cli/vite` 提供云函数 vite 插件(CLI-014)",
|
|
6
6
|
"bin": {
|
|
7
|
-
"adep": "./
|
|
7
|
+
"adep": "./dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"
|
|
12
|
-
"default": "./src/index.ts"
|
|
11
|
+
"default": "./dist/index.js"
|
|
13
12
|
},
|
|
14
13
|
"./vite": {
|
|
15
|
-
"
|
|
16
|
-
"default": "./src/vite.ts"
|
|
14
|
+
"default": "./dist/vite.js"
|
|
17
15
|
}
|
|
18
16
|
},
|
|
19
17
|
"files": [
|
|
20
18
|
"dist"
|
|
21
19
|
],
|
|
22
|
-
"scripts": {
|
|
23
|
-
"test": "vitest run",
|
|
24
|
-
"init": "bun run src/index.ts init --template fullstack example1",
|
|
25
|
-
"build": "bun run ../../scripts/build-package.ts cli"
|
|
26
|
-
},
|
|
27
20
|
"dependencies": {
|
|
28
21
|
"commander": "14.0.2",
|
|
29
|
-
"esbuild": "0.25.12"
|
|
22
|
+
"esbuild": "0.25.12",
|
|
23
|
+
"@adep/vite-plugin": "0.1.1"
|
|
30
24
|
},
|
|
31
25
|
"devDependencies": {
|
|
32
|
-
"@adep/runtime": "0.2.
|
|
33
|
-
"@adep/types": "0.2.
|
|
34
|
-
},
|
|
35
|
-
"publishConfig": {
|
|
36
|
-
"bin": {
|
|
37
|
-
"adep": "./dist/index.js"
|
|
38
|
-
},
|
|
39
|
-
"exports": {
|
|
40
|
-
".": {
|
|
41
|
-
"default": "./dist/index.js"
|
|
42
|
-
},
|
|
43
|
-
"./vite": {
|
|
44
|
-
"default": "./dist/vite.js"
|
|
45
|
-
}
|
|
46
|
-
}
|
|
26
|
+
"@adep/runtime": "0.2.1",
|
|
27
|
+
"@adep/types": "0.2.1"
|
|
47
28
|
},
|
|
48
|
-
"
|
|
49
|
-
|
|
29
|
+
"scripts": {
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"init": "bun run src/index.ts init --template fullstack example1",
|
|
32
|
+
"build": "bun run ../../scripts/build-package.ts cli"
|
|
33
|
+
}
|
|
34
|
+
}
|