@adep/cli 0.1.0 → 0.1.2

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.
@@ -1,9 +1,9 @@
1
- // ../runtime/src/functions/runtime/worker-entry.ts
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
- // ../runtime/src/functions/runtime/cloud-container.ts
6
+ // packages/runtime/src/functions/runtime/cloud-container.ts
7
7
  var KNOWN_CAPABILITY_HINTS = {
8
8
  db: {
9
9
  code: "DB_NOT_PROVISIONED",
@@ -20,6 +20,10 @@ var KNOWN_CAPABILITY_HINTS = {
20
20
  realtime: {
21
21
  code: "REALTIME_NOT_AVAILABLE",
22
22
  message: "\u5B9E\u65F6\u901A\u9053\u672A\u88C5\u914D\uFF1Arealtime \u57DF\u672A\u88C5\u8F7D\uFF08\u68C0\u67E5\u90E8\u7F72\u5F62\u6001\u4E0E Redis \u914D\u7F6E\uFF09\uFF08REALTIME_NOT_AVAILABLE\uFF09"
23
+ },
24
+ kv: {
25
+ code: "KV_NOT_PROVISIONED",
26
+ message: "\u9879\u76EE KV \u5B58\u50A8\u672A\u53EF\u7528\uFF1Akv \u968F\u9879\u76EE\u6570\u636E\u5E93\u63D0\u4F9B\uFF0C\u8BF7\u5148\u542F\u52A8\u6570\u636E\u5E93\uFF08KV_NOT_PROVISIONED\uFF09"
23
27
  }
24
28
  };
25
29
  var CapabilityNotRegisteredError = class extends Error {
@@ -79,11 +83,11 @@ function createCloudContainer() {
79
83
  };
80
84
  }
81
85
 
82
- // ../runtime/src/functions/runtime/sandbox.ts
86
+ // packages/runtime/src/functions/runtime/sandbox.ts
83
87
  import vm from "node:vm";
84
88
  import * as nodeModule from "node:module";
85
89
 
86
- // ../runtime/src/functions/runtime/exports.ts
90
+ // packages/runtime/src/functions/runtime/exports.ts
87
91
  function transformModule(code) {
88
92
  let out = code;
89
93
  const named = [];
@@ -125,7 +129,7 @@ function transformModule(code) {
125
129
  return out;
126
130
  }
127
131
 
128
- // ../runtime/src/functions/runtime/sandbox.ts
132
+ // packages/runtime/src/functions/runtime/sandbox.ts
129
133
  var bunTranspiler;
130
134
  function transpile(code) {
131
135
  const bun = globalThis["Bun"];
@@ -231,7 +235,7 @@ function loadFunctionModule(files, entry, sandboxGlobals, resolveBare) {
231
235
  return { handler };
232
236
  }
233
237
 
234
- // ../runtime/src/functions/runtime/sandbox-fetch.ts
238
+ // packages/runtime/src/functions/runtime/sandbox-fetch.ts
235
239
  var SandboxFetchError = class extends Error {
236
240
  code;
237
241
  constructor(code, message) {
@@ -410,12 +414,14 @@ function createSandboxFetch(options) {
410
414
  };
411
415
  }
412
416
 
413
- // ../runtime/src/shared/capability-keys.ts
417
+ // packages/runtime/src/shared/capability-keys.ts
414
418
  var RPC_CAPABILITY_KEY = "__adepRpc";
415
419
  var CHAIN_CAPABILITY_KEY = "__adepChain";
416
420
  var DB_RPC = {
417
421
  /** 直通方法(如 query):`(method=query, args=[sql, params])`。 */
418
422
  query: "query",
423
+ /** 写路径(CF-013):`(method=writeQuery, args=[sql, params])` → `{ changes }`。 */
424
+ writeQuery: "writeQuery",
419
425
  /** 读取 owned 表变更流(DB-006):`(method=changes, args=[table, query])`。 */
420
426
  changes: "changes",
421
427
  /** 开启事务:`begin → txId`。 */
@@ -428,7 +434,7 @@ var DB_RPC = {
428
434
  chain: "chain"
429
435
  };
430
436
 
431
- // ../runtime/src/functions/runtime/chain.ts
437
+ // packages/runtime/src/functions/runtime/chain.ts
432
438
  function isChainCapability(value) {
433
439
  if (typeof value !== "object" || value === null) return false;
434
440
  const spec = value[CHAIN_CAPABILITY_KEY];
@@ -499,7 +505,7 @@ function createChainClient(capability, port, pending, nextId, spec) {
499
505
  return makeRoot(void 0);
500
506
  }
501
507
 
502
- // ../runtime/src/functions/deps/manifest.ts
508
+ // packages/runtime/src/functions/deps/manifest.ts
503
509
  function splitBareSpecifier(request) {
504
510
  if (request.startsWith("@")) {
505
511
  const segments = request.split("/");
@@ -508,7 +514,7 @@ function splitBareSpecifier(request) {
508
514
  return request.split("/")[0];
509
515
  }
510
516
 
511
- // ../runtime/src/functions/runtime/worker-entry.ts
517
+ // packages/runtime/src/functions/runtime/worker-entry.ts
512
518
  function isRpcCapability(value) {
513
519
  return typeof value === "object" && value !== null && value[RPC_CAPABILITY_KEY] === true;
514
520
  }
@@ -562,6 +568,7 @@ function createBareResolver(deps) {
562
568
  const platformRequire = createRequire(import.meta.url);
563
569
  const depsRequire = deps.dir === null ? null : createRequire(join(deps.dir, "__deps__.js"));
564
570
  return (request) => {
571
+ if (deps.builtin.includes(request)) return platformRequire(request);
565
572
  const root = splitBareSpecifier(request);
566
573
  if (deps.builtin.includes(root)) return platformRequire(request);
567
574
  if (deps.custom.includes(root)) {
@@ -619,7 +626,29 @@ function runWorker(input, port) {
619
626
  );
620
627
  }
621
628
  const sandboxGlobals = {
622
- console: forwardedConsole
629
+ console: forwardedConsole,
630
+ // CF-015:Cloudflare Workers 代码重度依赖 Web 标准 API(URL / Request / Response /
631
+ // Headers / 流 / 编码 / crypto 等)。Node 18+ 全局内置,直接注入 vm 上下文;
632
+ // 与 @adep/cf-compat 的 Workers 适配(ctxToRequest / responseToEnvelopeBody)配套。
633
+ URL,
634
+ URLSearchParams,
635
+ Request,
636
+ Response,
637
+ Headers,
638
+ TextEncoder,
639
+ TextDecoder,
640
+ AbortController,
641
+ AbortSignal,
642
+ ReadableStream,
643
+ WritableStream,
644
+ TransformStream,
645
+ Blob,
646
+ FormData,
647
+ crypto,
648
+ performance,
649
+ atob,
650
+ btoa,
651
+ structuredClone
623
652
  };
624
653
  if (input.env !== void 0) {
625
654
  sandboxGlobals["process"] = { env: input.env };
@@ -641,7 +670,8 @@ function runWorker(input, port) {
641
670
  ...input.request.body === void 0 ? {} : { body: input.request.body },
642
671
  files: input.request.files ?? [],
643
672
  cloud: container.cloud,
644
- user: input.request.user ?? null
673
+ user: input.request.user ?? null,
674
+ ...input.env === void 0 ? {} : { env: input.env }
645
675
  };
646
676
  try {
647
677
  const { handler } = loadFunctionModule(
@@ -688,5 +718,6 @@ if (workerPort !== null && workerData !== void 0) {
688
718
  runWorker(workerData, port);
689
719
  }
690
720
  export {
721
+ createBareResolver,
691
722
  runWorker
692
723
  };
package/package.json CHANGED
@@ -1,49 +1,35 @@
1
1
  {
2
2
  "name": "@adep/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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": "./src/index.ts"
7
+ "adep": "./dist/index.js"
8
8
  },
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./src/index.ts",
12
- "default": "./src/index.ts"
11
+ "default": "./dist/index.js"
13
12
  },
14
13
  "./vite": {
15
- "types": "./src/vite.ts",
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/cf-compat": "0.1.1",
24
+ "@adep/vite-plugin": "0.1.2"
30
25
  },
31
26
  "devDependencies": {
32
- "@adep/runtime": "0.2.0",
33
- "@adep/types": "0.2.0"
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
- }
27
+ "@adep/runtime": "0.2.2",
28
+ "@adep/types": "0.2.2"
47
29
  },
48
- "gitHead": "9c29cbb2a942afe4d4c7ae2987bcc229f6b99f9b"
49
- }
30
+ "scripts": {
31
+ "test": "vitest run",
32
+ "init": "bun run src/index.ts init --template fullstack example1",
33
+ "build": "bun run ../../scripts/build-package.ts cli"
34
+ }
35
+ }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bun
2
- /**
3
- * adep bin 入口(CLI-001)。Bun 直接运行 TS;npm 发布与独立二进制打包归 CLI-003 / 后续任务。
4
- */
5
- import { buildProgram } from './cli'
6
-
7
- const program = buildProgram()
8
- await program.parseAsync(process.argv)