cfpilot 0.12.1 → 0.12.3

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/cli.js CHANGED
@@ -87,7 +87,7 @@ var VERSION, NAME;
87
87
  var init_version = __esm({
88
88
  "src/shared/version.ts"() {
89
89
  "use strict";
90
- VERSION = "0.12.1";
90
+ VERSION = "0.12.3";
91
91
  NAME = "cfpilot";
92
92
  }
93
93
  });
@@ -877,6 +877,31 @@ var init_cf_api = __esm({
877
877
  `/accounts/${encodeURIComponent(accountId)}/workers/domains/${encodeURIComponent(domainId)}`
878
878
  );
879
879
  }
880
+ /**
881
+ * 列出账号下全部 Worker 自定义域名绑定。
882
+ *
883
+ * 换部署形态(Pages ↔ Workers)时靠它找出旧数据面占用的域名,
884
+ * 否则迁移时只能依赖清单里的 `dataCustomDomain`(清单缺失就会漏)。
885
+ */
886
+ async listWorkerDomains(accountId) {
887
+ const result = await this.request(
888
+ "GET",
889
+ `/accounts/${encodeURIComponent(accountId)}/workers/domains`
890
+ );
891
+ return Array.isArray(result) ? result : [];
892
+ }
893
+ /**
894
+ * 删除 Worker 脚本。
895
+ *
896
+ * 换形态到 Pages 之后用它清理旧数据面 —— 只删**自己**创建的那个脚本名,
897
+ * 绝不按前缀批量删。
898
+ */
899
+ async deleteScript(accountId, scriptName) {
900
+ await this.request(
901
+ "DELETE",
902
+ `/accounts/${encodeURIComponent(accountId)}/workers/scripts/${encodeURIComponent(scriptName)}`
903
+ );
904
+ }
880
905
  /** 解除 Worker 自定义域名绑定(降级到 Route + CNAME 前清理用) */
881
906
  async deleteWorkerDomain(accountId, domainId) {
882
907
  await this.request(
@@ -1461,6 +1486,113 @@ var init_token_check = __esm({
1461
1486
  }
1462
1487
  });
1463
1488
 
1489
+ // src/deploy/workers-deploy.ts
1490
+ async function resolveZoneForHost(client, hostname) {
1491
+ const zones = await client.listZones();
1492
+ const host = hostname.trim().toLowerCase();
1493
+ if (!host) return null;
1494
+ const matches = zones.filter((zone2) => host === zone2.name || host.endsWith(`.${zone2.name}`)).sort((a, b) => b.name.length - a.name.length);
1495
+ const zone = matches[0];
1496
+ return zone ? { id: zone.id, name: zone.name } : null;
1497
+ }
1498
+ async function findWorkerDomain(client, accountId, scriptName) {
1499
+ const domains = await client.listWorkerDomains(accountId);
1500
+ return domains.find((d) => d.service === scriptName) ?? null;
1501
+ }
1502
+ async function uploadWorkerScript(options) {
1503
+ await options.client.uploadScript(options.accountId, options.name, {
1504
+ mainModule: "worker.js",
1505
+ code: options.code,
1506
+ compatibilityDate: WORKERS_COMPAT_DATE,
1507
+ bindings: options.bindings
1508
+ });
1509
+ }
1510
+ async function attachWorkerHostname(client, accountId, hostname, scriptName) {
1511
+ const zone = await resolveZoneForHost(client, hostname);
1512
+ if (!zone) {
1513
+ throw new Error(
1514
+ `\u57DF\u540D ${hostname} \u4E0D\u5728\u672C\u8D26\u53F7\u7684\u4EFB\u4F55 zone \u4E0B\uFF0C\u65E0\u6CD5\u7ED1\u5B9A\u4E3A Worker \u81EA\u5B9A\u4E49\u57DF\u540D\u3002
1515
+ \u2192 \u8BF7\u786E\u8BA4\u8BE5\u57DF\u540D\u7684 DNS \u6258\u7BA1\u5728\u8FD9\u4E2A Cloudflare \u8D26\u53F7\u91CC\uFF08Workers \u81EA\u5B9A\u4E49\u57DF\u540D\u4E0D\u652F\u6301\u5916\u90E8 CNAME\uFF09\u3002`
1516
+ );
1517
+ }
1518
+ return await client.attachCustomDomain(accountId, {
1519
+ hostname,
1520
+ service: scriptName,
1521
+ zoneId: zone.id
1522
+ });
1523
+ }
1524
+ async function detachWorkerHostname(client, accountId, scriptName) {
1525
+ const domain = await findWorkerDomain(client, accountId, scriptName);
1526
+ if (!domain) return "";
1527
+ try {
1528
+ await client.deleteWorkerDomain(accountId, domain.id);
1529
+ return domain.hostname;
1530
+ } catch {
1531
+ return "";
1532
+ }
1533
+ }
1534
+ async function probeHost(host, options = {}) {
1535
+ const deadline = Date.now() + (options.timeoutMs ?? 9e4);
1536
+ const interval = options.intervalMs ?? 5e3;
1537
+ for (; ; ) {
1538
+ try {
1539
+ await fetch(`https://${host}/`, {
1540
+ method: "GET",
1541
+ redirect: "manual",
1542
+ signal: AbortSignal.timeout(1e4)
1543
+ });
1544
+ return true;
1545
+ } catch {
1546
+ }
1547
+ if (Date.now() > deadline) return false;
1548
+ await new Promise((r) => setTimeout(r, interval));
1549
+ }
1550
+ }
1551
+ async function deployWorkersDataPlane(options) {
1552
+ const { client, accountId, name, hostname, log, warnings } = options;
1553
+ log(`\xB7 \u4E0A\u4F20 Workers \u6570\u636E\u9762\u811A\u672C ${name}`);
1554
+ await uploadWorkerScript(options);
1555
+ let host = "";
1556
+ let customDomain = "";
1557
+ if (hostname) {
1558
+ const domain = await attachWorkerHostname(client, accountId, hostname, name);
1559
+ customDomain = domain.hostname;
1560
+ host = domain.hostname;
1561
+ log(`\u2705 \u5DF2\u7ED1\u5B9A\u81EA\u5B9A\u4E49\u57DF\u540D ${host}`);
1562
+ const reachable = await probeHost(host);
1563
+ if (!reachable) {
1564
+ warnings.push(
1565
+ `\u81EA\u5B9A\u4E49\u57DF\u540D ${host} \u5728 90 \u79D2\u5185\u4ECD\u672A\u8FD4\u56DE\u54CD\u5E94\uFF08\u8BC1\u4E66\u7B7E\u53D1\u901A\u5E38\u9700\u8981 1~3 \u5206\u949F\uFF09\u3002
1566
+ \u2192 \u7A0D\u7B49\u7247\u523B\u7528\u6D4F\u89C8\u5668\u6253\u5F00\u8BE5\u57DF\u540D\u786E\u8BA4\uFF1B\u82E5\u957F\u65F6\u95F4\u4E0D\u53EF\u7528\uFF0C\u8BF7\u5230 Cloudflare \u63A7\u5236\u53F0\u68C0\u67E5
1567
+ Workers \u2192 \u4F60\u7684\u811A\u672C \u2192 \u8BBE\u7F6E \u2192 \u57DF\u548C\u8DEF\u7531 \u91CC\u7684\u81EA\u5B9A\u4E49\u57DF\u540D\u72B6\u6001\u3002`
1568
+ );
1569
+ }
1570
+ } else {
1571
+ await client.putScriptSubdomain(accountId, name, true);
1572
+ const subdomain = await client.getWorkersSubdomain(accountId);
1573
+ host = subdomain ? `${name}.${subdomain}.workers.dev` : `${name}.workers.dev`;
1574
+ warnings.push(
1575
+ `\u672A\u914D\u7F6E\u81EA\u5B9A\u4E49\u57DF\u540D\uFF0C\u6570\u636E\u9762\u4F7F\u7528 ${host}\u3002
1576
+ \u2192 *.workers.dev \u57DF\u540D\u76F4\u8FDE\u65E0\u6CD5\u8BBF\u95EE\uFF0C\u8BF7\u767B\u5F55 cloudflare \u63A7\u5236\u53F0\u914D\u7F6E\u81EA\u5B9A\u4E49\u57DF\u540D\uFF0C
1577
+ \u5426\u5219\u5BA2\u6237\u7AEF\u8282\u70B9\u4F1A\u5168\u90E8\u8FDE\u4E0D\u4E0A\u3002`
1578
+ );
1579
+ }
1580
+ return { name, host, customDomain };
1581
+ }
1582
+ async function deleteWorkersDataPlane(client, accountId, name, log) {
1583
+ const host = await detachWorkerHostname(client, accountId, name);
1584
+ if (host) log(`\xB7 \u5DF2\u89E3\u7ED1\u65E7\u6570\u636E\u9762\u57DF\u540D ${host}`);
1585
+ await client.deleteScript(accountId, name);
1586
+ log(`\u2705 \u5DF2\u5220\u9664\u65E7 Workers \u6570\u636E\u9762\uFF1A${name}`);
1587
+ }
1588
+ var WORKERS_COMPAT_DATE;
1589
+ var init_workers_deploy = __esm({
1590
+ "src/deploy/workers-deploy.ts"() {
1591
+ "use strict";
1592
+ WORKERS_COMPAT_DATE = "2026-10-01";
1593
+ }
1594
+ });
1595
+
1464
1596
  // src/shared/version-util.ts
1465
1597
  function parseVersion(input) {
1466
1598
  const text = input.trim();
@@ -2337,10 +2469,18 @@ async function deployPagesSplit(options) {
2337
2469
  result.uuid = effective.uuid;
2338
2470
  result.wsPath = effective.wsPath;
2339
2471
  result.panelPassword = effective.panelPassword;
2340
- for (const [label, name] of [
2341
- ["\u63A7\u5236\u9762", controlName],
2342
- ["\u6570\u636E\u9762", dataName]
2343
- ]) {
2472
+ const prevDataMode = manifest?.dataPlaneMode === "workers" ? "workers" : "pages";
2473
+ const dataMode = options.dataPlaneMode ?? prevDataMode;
2474
+ const modeSwitched = !!manifest && dataMode !== prevDataMode;
2475
+ const oldDataName = manifest?.dataProject ?? "";
2476
+ const targetHost = (options.dataHost ?? "").trim() || (manifest?.dataCustomDomain ?? "").trim();
2477
+ if (modeSwitched) {
2478
+ log(
2479
+ `\u26A0 \u6570\u636E\u9762\u90E8\u7F72\u5F62\u6001\u53D8\u66F4\uFF1A${prevDataMode === "pages" ? "Pages" : "Workers"} \u2192 ${dataMode === "pages" ? "Pages" : "Workers"}`
2480
+ );
2481
+ log(" \u2192 \u65B0\u6570\u636E\u9762\u90E8\u7F72\u6210\u529F\u540E\uFF0C\u4F1A\u81EA\u52A8\u5220\u9664\u65E7\u7684\u6570\u636E\u9762\u5E76\u8FC1\u79FB\u57DF\u540D");
2482
+ }
2483
+ const ensurePagesProject = async (label, name) => {
2344
2484
  try {
2345
2485
  const project = await client.createPagesProject(options.accountId, {
2346
2486
  name,
@@ -2367,11 +2507,17 @@ async function deployPagesSplit(options) {
2367
2507
  );
2368
2508
  }
2369
2509
  }
2510
+ };
2511
+ await ensurePagesProject("\u63A7\u5236\u9762", controlName);
2512
+ if (dataMode === "pages") {
2513
+ await ensurePagesProject("\u6570\u636E\u9762", dataName);
2514
+ } else {
2515
+ log("\xB7 \u6570\u636E\u9762\u90E8\u7F72\u5F62\u6001\uFF1AWorkers\uFF08\u4E0D\u521B\u5EFA Pages \u6570\u636E\u9762\u9879\u76EE\uFF09");
2370
2516
  }
2371
2517
  if (result.control.subdomain) {
2372
2518
  await configureProject(client, options.accountId, controlName, "\u63A7\u5236\u9762", result, options, log, warnings, effective);
2373
2519
  }
2374
- if (result.data.subdomain) {
2520
+ if (dataMode === "pages" && result.data.subdomain) {
2375
2521
  await configureProject(client, options.accountId, dataName, "\u6570\u636E\u9762", result, options, log, warnings, effective);
2376
2522
  }
2377
2523
  await writeEffectiveConfig(
@@ -2386,7 +2532,7 @@ async function deployPagesSplit(options) {
2386
2532
  const dataCode = kernel.data;
2387
2533
  const controlCode = kernel.control;
2388
2534
  let dataCustomDomain = "";
2389
- if (previousDataProject) {
2535
+ if (dataMode === "pages" && previousDataProject) {
2390
2536
  const isCustom = (d) => typeof d === "string" && !d.endsWith(".pages.dev");
2391
2537
  try {
2392
2538
  const all = await client.listPagesDomains(options.accountId, previousDataProject);
@@ -2400,31 +2546,149 @@ async function deployPagesSplit(options) {
2400
2546
  } catch {
2401
2547
  }
2402
2548
  }
2403
- const dataAttempt = await deployWithBlockRetry({
2404
- client,
2405
- accountId: options.accountId,
2406
- preferredName: dataName,
2407
- code: dataCode,
2408
- label: "\u6570\u636E\u9762",
2409
- result,
2410
- options,
2411
- effective,
2412
- wait,
2413
- log,
2414
- warnings,
2415
- oldProject: previousDataProject,
2416
- customDomain: dataCustomDomain
2417
- });
2418
- if (dataAttempt) {
2419
- result.data.name = dataAttempt.project ?? options.dataProject;
2420
- result.data.subdomain = dataAttempt.subdomain;
2549
+ if (dataMode === "pages" && prevDataMode === "workers" && !dataCustomDomain) {
2550
+ dataCustomDomain = targetHost;
2551
+ }
2552
+ if (dataMode === "workers") {
2553
+ const workersBindings = [
2554
+ { type: "kv_namespace", name: "KV", namespace_id: options.kvNamespaceId },
2555
+ { type: "plain_text", name: "UUID", text: effective.uuid },
2556
+ { type: "plain_text", name: "TROJAN_PASSWORD", text: effective.trojanPassword },
2557
+ { type: "plain_text", name: "WS_PATH", text: effective.wsPath },
2558
+ { type: "plain_text", name: "PATH", text: effective.wsPath },
2559
+ { type: "plain_text", name: "ENABLE_TROJAN", text: options.enableTrojan ? "true" : "false" },
2560
+ { type: "plain_text", name: "ENABLE_XHTTP", text: options.enableXhttp ? "true" : "false" },
2561
+ ...options.resolvePreferred === void 0 ? [] : [
2562
+ {
2563
+ type: "plain_text",
2564
+ name: "RESOLVE_PREFERRED",
2565
+ text: options.resolvePreferred ? "true" : "false"
2566
+ }
2567
+ ]
2568
+ ];
2569
+ const switchingFromPages = modeSwitched && prevDataMode === "pages";
2570
+ if (switchingFromPages && targetHost && oldDataName) {
2571
+ try {
2572
+ await client.removePagesDomain(options.accountId, oldDataName, targetHost);
2573
+ log(`\xB7 \u5DF2\u4ECE\u65E7 Pages \u6570\u636E\u9762 ${oldDataName} \u89E3\u7ED1\u57DF\u540D ${targetHost}\uFF08\u51C6\u5907\u8FC1\u5230 Workers\uFF09`);
2574
+ } catch {
2575
+ }
2576
+ }
2577
+ try {
2578
+ const deployed = await deployWorkersDataPlane({
2579
+ client,
2580
+ accountId: options.accountId,
2581
+ name: dataName,
2582
+ code: dataCode,
2583
+ hostname: targetHost || void 0,
2584
+ bindings: workersBindings,
2585
+ log,
2586
+ warnings
2587
+ });
2588
+ result.data.name = deployed.name;
2589
+ result.data.subdomain = deployed.host;
2590
+ dataCustomDomain = deployed.customDomain;
2591
+ } catch (err) {
2592
+ if (switchingFromPages && targetHost && oldDataName) {
2593
+ try {
2594
+ await client.addPagesDomain(options.accountId, oldDataName, targetHost);
2595
+ log("\xB7 \u5DF2\u628A\u57DF\u540D\u56DE\u6EDA\u5230\u65E7 Pages \u6570\u636E\u9762");
2596
+ } catch {
2597
+ warnings.push(
2598
+ `\u57DF\u540D ${targetHost} \u56DE\u6EDA\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u5230 Cloudflare \u63A7\u5236\u53F0\u628A\u5B83\u7ED1\u56DE ${oldDataName}\u3002`
2599
+ );
2600
+ }
2601
+ }
2602
+ throw new Error(
2603
+ `Workers \u6570\u636E\u9762\u90E8\u7F72\u5931\u8D25\uFF1A${err instanceof Error ? err.message : String(err)}`
2604
+ );
2605
+ }
2606
+ if (switchingFromPages && oldDataName) {
2607
+ try {
2608
+ await client.deletePagesProject(options.accountId, oldDataName);
2609
+ log(`\u2705 \u5DF2\u5220\u9664\u88AB\u66FF\u6362\u7684\u65E7 Pages \u6570\u636E\u9762\u9879\u76EE\uFF1A${oldDataName}`);
2610
+ } catch (err) {
2611
+ warnings.push(
2612
+ `\u5220\u9664\u65E7 Pages \u6570\u636E\u9762\u5931\u8D25\uFF08${oldDataName}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}
2613
+ \u2192 \u5B83\u5DF2\u7ECF\u4E0D\u518D\u63A5\u6536\u6D41\u91CF\uFF0C\u53EF\u5230\u63A7\u5236\u53F0\u624B\u52A8\u5220\u9664\u3002`
2614
+ );
2615
+ }
2616
+ }
2617
+ } else {
2618
+ if (modeSwitched && prevDataMode === "workers") {
2619
+ await ensurePagesProject("\u6570\u636E\u9762", dataName);
2620
+ if (result.data.subdomain) {
2621
+ await configureProject(client, options.accountId, dataName, "\u6570\u636E\u9762", result, options, log, warnings, effective);
2622
+ }
2623
+ }
2624
+ const dataAttempt = await deployWithBlockRetry({
2625
+ client,
2626
+ accountId: options.accountId,
2627
+ preferredName: dataName,
2628
+ code: dataCode,
2629
+ label: "\u6570\u636E\u9762",
2630
+ result,
2631
+ options,
2632
+ effective,
2633
+ wait,
2634
+ log,
2635
+ warnings,
2636
+ oldProject: previousDataProject,
2637
+ customDomain: dataCustomDomain
2638
+ });
2639
+ if (dataAttempt) {
2640
+ result.data.name = dataAttempt.project ?? options.dataProject;
2641
+ result.data.subdomain = dataAttempt.subdomain;
2642
+ if (modeSwitched && prevDataMode === "workers" && oldDataName) {
2643
+ let detachedHost = "";
2644
+ try {
2645
+ detachedHost = await detachWorkerHostname(client, options.accountId, oldDataName);
2646
+ if (detachedHost) log(`\xB7 \u5DF2\u4ECE\u65E7 Workers \u6570\u636E\u9762\u89E3\u7ED1\u57DF\u540D ${detachedHost}`);
2647
+ } catch {
2648
+ }
2649
+ const host = dataCustomDomain || detachedHost;
2650
+ let moved = true;
2651
+ if (host) {
2652
+ try {
2653
+ await client.addPagesDomain(options.accountId, result.data.name, host);
2654
+ log(`\u2705 \u81EA\u5B9A\u4E49\u57DF\u540D\u5DF2\u8FC1\u79FB\u5230 Pages \u6570\u636E\u9762\uFF1A${host}`);
2655
+ dataCustomDomain = host;
2656
+ } catch (err) {
2657
+ moved = false;
2658
+ warnings.push(
2659
+ `\u81EA\u5B9A\u4E49\u57DF\u540D\u8FC1\u79FB\u5931\u8D25\uFF08${host} \u2192 ${result.data.name}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}
2660
+ \u2192 \u8BF7\u624B\u52A8\u5230 Cloudflare \u63A7\u5236\u53F0\u628A\u8BE5\u57DF\u540D\u7ED1\u5230 ${result.data.name}\uFF0C\u5426\u5219\u8BA2\u9605\u5730\u5740\u4F1A\u5931\u6548\u3002`
2661
+ );
2662
+ try {
2663
+ await client.attachCustomDomain(options.accountId, {
2664
+ hostname: host,
2665
+ service: oldDataName,
2666
+ zoneId: (await client.listWorkerDomains(options.accountId)).find((d) => d.hostname === host)?.zone_id ?? ""
2667
+ });
2668
+ log("\xB7 \u5DF2\u628A\u57DF\u540D\u56DE\u6EDA\u5230\u65E7 Workers \u6570\u636E\u9762");
2669
+ } catch {
2670
+ }
2671
+ }
2672
+ }
2673
+ if (moved) {
2674
+ try {
2675
+ await deleteWorkersDataPlane(client, options.accountId, oldDataName, log);
2676
+ } catch (err) {
2677
+ warnings.push(
2678
+ `\u5220\u9664\u65E7 Workers \u6570\u636E\u9762\u5931\u8D25\uFF08${oldDataName}\uFF09\uFF1A${err instanceof Error ? err.message : String(err)}
2679
+ \u2192 \u5B83\u5DF2\u7ECF\u4E0D\u518D\u63A5\u6536\u6D41\u91CF\uFF0C\u53EF\u5230\u63A7\u5236\u53F0\u624B\u52A8\u5220\u9664\u3002`
2680
+ );
2681
+ }
2682
+ }
2683
+ }
2684
+ }
2421
2685
  }
2422
2686
  if (result.data.subdomain && result.control.name) {
2423
2687
  const expected = result.data.subdomain;
2424
2688
  try {
2425
2689
  const controlProject = await client.getPagesProject(options.accountId, result.control.name);
2426
2690
  const currentHost = controlProject.deployment_configs?.production?.env_vars?.DATA_HOST?.value ?? "";
2427
- if (currentHost && currentHost !== expected) {
2691
+ if (currentHost !== expected) {
2428
2692
  log(`\u26A0 \u63A7\u5236\u9762 DATA_HOST \u4ECD\u6307\u5411\u65E7\u57DF\u540D ${currentHost}\uFF0C\u6B63\u5728\u540C\u6B65\u4E3A ${expected}`);
2429
2693
  await configureProject(
2430
2694
  client,
@@ -2472,6 +2736,8 @@ async function deployPagesSplit(options) {
2472
2736
  dataSubdomain: result.data.subdomain,
2473
2737
  // 自定义域名:本次迁过来的,或旧项目上原有的(下次更新还要靠它迁移)
2474
2738
  dataCustomDomain: dataCustomDomain || manifest?.dataCustomDomain || "",
2739
+ // 部署形态:更新时靠它识别「用户是否改过数据面形态」
2740
+ dataPlaneMode: dataMode,
2475
2741
  build,
2476
2742
  kernelVersion,
2477
2743
  at: (/* @__PURE__ */ new Date()).toISOString(),
@@ -2622,6 +2888,7 @@ var init_pages_deploy = __esm({
2622
2888
  "src/deploy/pages-deploy.ts"() {
2623
2889
  "use strict";
2624
2890
  init_cf_api();
2891
+ init_workers_deploy();
2625
2892
  init_utils();
2626
2893
  init_kernel_remote();
2627
2894
  init_version_util();
@@ -2637,9 +2904,10 @@ var init_help = __esm({
2637
2904
  "use strict";
2638
2905
  init_version();
2639
2906
  DEPLOY_HELP = `
2640
- ${NAME} deploy \u2014\u2014 Pages \u53CC\u9879\u76EE\u90E8\u7F72\uFF08\u63A7\u5236\u9762 + \u6570\u636E\u9762\uFF09
2907
+ ${NAME} deploy \u2014\u2014 \u53CC\u9762\u90E8\u7F72\uFF08\u63A7\u5236\u9762 Pages + \u6570\u636E\u9762 Pages/Workers\uFF09
2641
2908
 
2642
- \u26A0\uFE0F \u8FD9\u662F\u552F\u4E00\u53D7\u652F\u6301\u7684\u90E8\u7F72\u5F62\u6001\u3002\u5408\u5E76\u6210\u5355\u9879\u76EE\u4F1A\u89E6\u53D1 8000119 \u98CE\u63A7\u3002
2909
+ \u26A0\uFE0F \u63A7\u5236\u9762\u5FC5\u987B\u7559\u5728 Pages\uFF1B\u6570\u636E\u9762\u53EF\u9009 Pages \u6216 Workers\u3002
2910
+ \u5408\u5E76\u6210\u5355\u9879\u76EE\u4F1A\u89E6\u53D1 8000119 \u98CE\u63A7\u3002
2643
2911
 
2644
2912
  \u7528\u6CD5:
2645
2913
  ${NAME} deploy [\u9009\u9879]
@@ -2647,12 +2915,17 @@ ${NAME} deploy \u2014\u2014 Pages \u53CC\u9879\u76EE\u90E8\u7F72\uFF08\u63A7\u52
2647
2915
  \u9009\u9879:
2648
2916
  --token <token> Cloudflare API Token\uFF08\u4E5F\u53EF\u7528\u73AF\u5883\u53D8\u91CF CLOUDFLARE_API_TOKEN\uFF09
2649
2917
  --account <id> \u76EE\u6807\u8D26\u53F7 ID
2650
- --kv <id> KV \u547D\u540D\u7A7A\u95F4 ID\uFF08\u4E24\u4E2A\u9879\u76EE\u5171\u7528\uFF09
2918
+ --kv <id> KV \u547D\u540D\u7A7A\u95F4 ID\uFF08\u4E24\u4E2A\u9762\u5171\u7528\uFF09
2651
2919
  --kv-title <title> \u65B0\u5EFA KV \u65F6\u4F7F\u7528\u7684\u6807\u9898
2652
2920
  --new-kv \u5F3A\u5236\u65B0\u5EFA\u4E00\u4E2A KV \u547D\u540D\u7A7A\u95F4\uFF08\u7528\u4E8E\u90E8\u7F72\u7B2C 2\u30013\u2026 \u4E2A\u5B9E\u4F8B\uFF09
2653
2921
  --list-kv \u5217\u51FA\u8BE5\u8D26\u53F7\u4E0B\u7684 KV \u4E0E\u5176\u4E2D\u7684 CFPilot \u5B9E\u4F8B\uFF0C\u4E0D\u6267\u884C\u90E8\u7F72
2654
2922
  --control <name> \u63A7\u5236\u9762 Pages \u9879\u76EE\u540D\uFF08\u9ED8\u8BA4\u968F\u673A\uFF09
2655
- --data <name> \u6570\u636E\u9762 Pages \u9879\u76EE\u540D\uFF08\u9ED8\u8BA4\u968F\u673A\uFF09
2923
+ --data <name> \u6570\u636E\u9762\u540D\u79F0\uFF08Pages \u9879\u76EE\u540D / Worker \u811A\u672C\u540D\uFF0C\u9ED8\u8BA4\u968F\u673A\uFF09
2924
+ --data-plane <mode> \u6570\u636E\u9762\u90E8\u7F72\u5F62\u6001\uFF1Apages\uFF08\u9ED8\u8BA4\uFF09/ workers
2925
+ \u4E0D\u4F20 = \u6CBF\u7528\u90E8\u7F72\u6E05\u5355\u91CC\u8BB0\u5F55\u7684\u5F62\u6001\uFF1B
2926
+ \u663E\u5F0F\u4F20\u4E14\u4E0E\u6E05\u5355\u4E0D\u540C = \u5207\u6362\u5F62\u6001\uFF08\u65B0\u6570\u636E\u9762\u4E0A\u7EBF\u540E\u81EA\u52A8\u5220\u9664\u65E7\u7684\u5E76\u8FC1\u79FB\u57DF\u540D\uFF09
2927
+ --data-host <host> Workers \u6570\u636E\u9762\u7684\u81EA\u5B9A\u4E49\u57DF\u540D\uFF08\u5982 w1a2b3c4.example.com\uFF09
2928
+ \u26A0\uFE0F *.workers.dev \u76F4\u8FDE\u4E0D\u53EF\u8BBF\u95EE\uFF0C\u4E0D\u7ED9\u57DF\u540D\u4F1A\u544A\u8B66
2656
2929
  --panel-path <path> \u9762\u677F\u8BBF\u95EE\u8DEF\u5F84\uFF08\u9ED8\u8BA4\u968F\u673A\uFF09
2657
2930
  --mode <mode> \u90E8\u7F72\u6A21\u5F0F\uFF1Aauto\uFF08\u9ED8\u8BA4\uFF0C\u81EA\u52A8\u5224\u65AD\uFF09/ fresh\uFF08\u5F3A\u5236\u9996\u6B21\uFF09/ update\uFF08\u5F3A\u5236\u66F4\u65B0\uFF09
2658
2931
  --force \u5FFD\u7565\u7248\u672C\u68C0\u67E5\uFF0C\u5F3A\u5236\u91CD\u65B0\u90E8\u7F72
@@ -2692,13 +2965,16 @@ ${NAME} deploy \u2014\u2014 Pages \u53CC\u9879\u76EE\u90E8\u7F72\uFF08\u63A7\u52
2692
2965
  packages/worker-core/dist/dataplane.js \u6570\u636E\u9762\uFF08VLESS/Trojan-WS/XHTTP\uFF0C\u81EA\u7814\u5B9E\u73B0\uFF09
2693
2966
 
2694
2967
  \u90E8\u7F72\u987A\u5E8F\uFF08\u4E0D\u53EF\u8C03\u6362\uFF09:
2695
- 1. \u521B\u5EFA\u4E24\u4E2A Pages \u9879\u76EE
2968
+ 1. \u521B\u5EFA\u63A7\u5236\u9762 Pages \u9879\u76EE\uFF08\u6570\u636E\u9762\u6309\u5F62\u6001\u521B\u5EFA Pages \u9879\u76EE\u6216 Worker\uFF09
2696
2969
  2. \u914D\u7F6E KV \u7ED1\u5B9A\u4E0E\u73AF\u5883\u53D8\u91CF\uFF08Pages \u7684\u7ED1\u5B9A\u53EA\u5BF9\u4E4B\u540E\u7684\u90E8\u7F72\u751F\u6548\uFF09
2697
2970
  3. \u5148\u90E8\u7F72\u6570\u636E\u9762\uFF0C\u518D\u90E8\u7F72\u63A7\u5236\u9762\uFF08\u63A7\u5236\u9762\u9700\u8981\u6570\u636E\u9762\u57DF\u540D\u751F\u6210\u8BA2\u9605\uFF09
2698
2971
 
2699
2972
  Token \u6240\u9700\u6743\u9650:
2700
2973
  Account / Pages / Edit \u521B\u5EFA\u9879\u76EE\u3001\u914D\u7F6E\u53D8\u91CF\u3001\u89E6\u53D1\u90E8\u7F72
2974
+ Account / Workers Scripts / Edit \u90E8\u7F72 Workers \u6570\u636E\u9762\uFF08--data-plane workers\uFF09
2701
2975
  Account / Workers KV Storage / Edit \u521B\u5EFA KV\uFF08\u82E5\u672A\u63D0\u4F9B --kv\uFF09
2976
+ Zone / Workers Routes / Edit \u7ED1\u5B9A Workers \u81EA\u5B9A\u4E49\u57DF\u540D\uFF08--data-host\uFF09
2977
+ Zone / DNS / Edit \u81EA\u5B9A\u4E49\u57DF\u540D\u9700\u8981\u81EA\u52A8\u5EFA DNS \u8BB0\u5F55
2702
2978
  `;
2703
2979
  }
2704
2980
  });
@@ -2910,6 +3186,18 @@ async function runDeployCommand(args) {
2910
3186
  process.exitCode = 1;
2911
3187
  return;
2912
3188
  }
3189
+ const dataPlaneRaw = (flagString(args, "data-plane") || "").toLowerCase();
3190
+ if (dataPlaneRaw && dataPlaneRaw !== "pages" && dataPlaneRaw !== "workers") {
3191
+ process.stderr.write(`\u2717 --data-plane \u53EA\u63A5\u53D7 pages / workers\uFF0C\u6536\u5230\uFF1A${dataPlaneRaw}
3192
+ `);
3193
+ process.exitCode = 1;
3194
+ return;
3195
+ }
3196
+ const dataPlaneMode = dataPlaneRaw ? dataPlaneRaw : void 0;
3197
+ const dataHost = flagString(args, "data-host") || "";
3198
+ if (dataHost && dataPlaneMode !== "workers") {
3199
+ process.stderr.write("\xB7 --data-host \u53EA\u5BF9 --data-plane workers \u751F\u6548\uFF0C\u5DF2\u5FFD\u7565\n");
3200
+ }
2913
3201
  const keepCredentials = !flagBool(args, "new-credentials");
2914
3202
  const skipSameVersion = !flagBool(args, "force");
2915
3203
  const panelPath = flagString(args, "panel-path") || "";
@@ -2937,6 +3225,9 @@ async function runDeployCommand(args) {
2937
3225
  // 想关在面板「入站配置 → 启用服务端 XHTTP 入站监听」关即可
2938
3226
  //(KV 配置优先级高于环境变量,面板开关会覆盖这里的默认值)。
2939
3227
  enableXhttp: true,
3228
+ // 数据面形态:不传 = 沿用清单;显式传且与清单不一致 = 切换形态
3229
+ dataPlaneMode,
3230
+ dataHost: dataPlaneMode === "workers" ? dataHost : void 0,
2940
3231
  mode,
2941
3232
  keepCredentials,
2942
3233
  skipSameVersion,
@@ -4686,8 +4977,14 @@ async function runScan(options) {
4686
4977
  function formatHost(ip) {
4687
4978
  return ip.includes(":") ? `[${ip}]` : ip;
4688
4979
  }
4980
+ function copyTag(colo) {
4981
+ const code = (colo || "").toUpperCase().trim();
4982
+ if (!code) return "CF";
4983
+ const city = coloCity(code);
4984
+ return city ? code + city : code;
4985
+ }
4689
4986
  function formatCopyable(entries) {
4690
- return entries.map((e) => `${formatHost(e.ip)}:${e.port}#${e.colo}`).join("\n");
4987
+ return entries.map((e) => `${formatHost(e.ip)}:${e.port}#${copyTag(e.colo)}`).join("\n");
4691
4988
  }
4692
4989
  function formatEntries(entries) {
4693
4990
  return entries.map(
@@ -5288,14 +5585,14 @@ async function detectProxyInterference(host) {
5288
5585
  advice: "\u5728\u300C\u8BBE\u7F6E \u2192 \u7F51\u7EDC\u548C Internet \u2192 \u4EE3\u7406\u300D\u4E2D\u5173\u95ED\u7CFB\u7EDF\u4EE3\u7406"
5289
5586
  });
5290
5587
  }
5291
- const probeHost = host?.trim() || "www.cloudflare.com";
5588
+ const probeHost2 = host?.trim() || "www.cloudflare.com";
5292
5589
  try {
5293
5590
  const { resolve4 } = await import("node:dns/promises");
5294
- const ips = await resolve4(probeHost).catch(() => []);
5591
+ const ips = await resolve4(probeHost2).catch(() => []);
5295
5592
  const fake = ips.find((ip) => isFakeIp(ip));
5296
5593
  if (fake) {
5297
5594
  findings.push({
5298
- message: `DNS \u628A ${probeHost} \u89E3\u6790\u5230 ${fake}\uFF08198.18/15 \u4FDD\u7559\u6BB5\uFF09\uFF0CTUN / fake-ip \u6B63\u5728\u751F\u6548`,
5595
+ message: `DNS \u628A ${probeHost2} \u89E3\u6790\u5230 ${fake}\uFF08198.18/15 \u4FDD\u7559\u6BB5\uFF09\uFF0CTUN / fake-ip \u6B63\u5728\u751F\u6548`,
5299
5596
  advice: "\u5173\u95ED\u4EE3\u7406\u5DE5\u5177\u7684 TUN \u6A21\u5F0F\u4E0E fake-ip DNS"
5300
5597
  });
5301
5598
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cfpilot",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "description": "CFPilot —— Cloudflare Pages 代理部署与优选工具(交互菜单 + 子命令)",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",