@heybox/hb-sdk 0.4.0 → 0.4.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.
@@ -5,7 +5,7 @@ var fs = require('node:fs/promises');
5
5
  var path = require('node:path');
6
6
  var require$$0 = require('fs');
7
7
  var require$$1 = require('path');
8
- var index = require('./index-io4h3kr-.cjs');
8
+ var index = require('./index-p5XZBWaZ.cjs');
9
9
  require('node:module');
10
10
  require('os');
11
11
  require('readline');
@@ -5,8 +5,8 @@ var fs = require('node:fs');
5
5
  var fs$1 = require('node:fs/promises');
6
6
  var path = require('node:path');
7
7
  var promises = require('node:readline/promises');
8
- var session = require('./session-CMBN3o9z.cjs');
9
- var index = require('./index-io4h3kr-.cjs');
8
+ var session = require('./session-DNG8Q6Ni.cjs');
9
+ var index = require('./index-p5XZBWaZ.cjs');
10
10
  var node_crypto = require('node:crypto');
11
11
 
12
12
  var re = {exports: {}};
@@ -3328,7 +3328,7 @@ async function createDefaultCosClient(uploadToken) {
3328
3328
  };
3329
3329
  }
3330
3330
  async function loadCosConstructor() {
3331
- const cosModule = await Promise.resolve().then(function () { return require('./index-yjJgBEBF.cjs'); }).then(function (n) { return n.index; });
3331
+ const cosModule = await Promise.resolve().then(function () { return require('./index-X-XUt2Ei.cjs'); }).then(function (n) { return n.index; });
3332
3332
  return cosModule.default;
3333
3333
  }
3334
3334
  function formatSize(bytes) {
@@ -9,7 +9,7 @@ var node_url = require('node:url');
9
9
  var net = require('node:net');
10
10
  var node_http = require('node:http');
11
11
  var browser = require('./browser-RAy8e8cV.cjs');
12
- var index = require('./index-io4h3kr-.cjs');
12
+ var index = require('./index-p5XZBWaZ.cjs');
13
13
  require('node:process');
14
14
  require('node:buffer');
15
15
  require('node:util');
@@ -186,6 +186,21 @@ async function getPorts(options) {
186
186
  throw new Error('No available ports found');
187
187
  }
188
188
 
189
+ async function selectAvailablePort(options) {
190
+ const maxAttempts = options.maxAttempts ?? 20;
191
+ const port = await options.getPort({
192
+ host: options.host,
193
+ port: createPortCandidates(options.startPort, maxAttempts),
194
+ });
195
+ if (port < options.startPort || port >= options.startPort + maxAttempts) {
196
+ throw new Error(`无法找到可用 ${options.label} 端口,起始端口: ${options.startPort}`);
197
+ }
198
+ return port;
199
+ }
200
+ function createPortCandidates(startPort, count) {
201
+ return Array.from({ length: count }, (_, index) => startPort + index);
202
+ }
203
+
189
204
  const MINI_PROGRAM_URL_QUERY_PARAM$1 = 'mini_url';
190
205
  const LAN_ADDRESSES_PATH = '/__hb_sdk_lan_addresses__';
191
206
  const MOCK_NETWORK_PROXY_PATH = '/__hb_sdk_mock_network__';
@@ -536,14 +551,12 @@ function readContentType(filePath) {
536
551
  return 'application/octet-stream';
537
552
  }
538
553
  async function listenHttpServer(server, options, getPortImpl) {
539
- const maxAttempts = 20;
540
- const port = await getPortImpl({
554
+ const port = await selectAvailablePort({
555
+ getPort: getPortImpl,
541
556
  host: DEV_LISTEN_HOST$1,
542
- port: createPortCandidates(options.port, maxAttempts),
557
+ label: 'mock host',
558
+ startPort: options.port,
543
559
  });
544
- if (port < options.port || port >= options.port + maxAttempts) {
545
- throw new Error(`无法找到可用 mock host 端口,起始端口: ${options.port}`);
546
- }
547
560
  await new Promise((resolve, reject) => {
548
561
  const onError = (error) => {
549
562
  server.off('listening', onListening);
@@ -560,9 +573,6 @@ async function listenHttpServer(server, options, getPortImpl) {
560
573
  const address = server.address();
561
574
  return address.port;
562
575
  }
563
- function createPortCandidates(startPort, count) {
564
- return Array.from({ length: count }, (_, index) => startPort + index);
565
- }
566
576
  function readErrorMessage(error) {
567
577
  return error instanceof Error ? error.message : String(error);
568
578
  }
@@ -628,18 +638,30 @@ async function runDevCommand(options, runtime = {}) {
628
638
  const logger = runtime.logger ?? index.createCliLogger();
629
639
  const fetchImpl = runtime.fetchImpl ?? fetch;
630
640
  const openUrl = runtime.openExternalUrl ?? browser.openExternalUrl;
641
+ const networkInterfaceSnapshot = (runtime.networkInterfaces ?? os.networkInterfaces)();
642
+ const getPortImpl = runtime.getPort ?? getPorts;
643
+ const appPort = await selectAvailablePort({
644
+ getPort: getPortImpl,
645
+ host: DEV_LISTEN_HOST,
646
+ label: 'Vite dev server',
647
+ startPort: options.port ?? DEFAULT_APP_PORT,
648
+ });
649
+ const resolvedOptions = {
650
+ ...options,
651
+ port: appPort,
652
+ };
631
653
  const projectRoot = findProjectRoot(runtime.cwd ?? process.cwd());
632
654
  const vite = await logger.task('正在加载项目 Vite', () => loadProjectVite(projectRoot), { successText: '已加载项目 Vite' });
633
- const appServer = await logger.task('正在创建 Vite dev server', () => withManagedDevOutputEnv(() => vite.createServer(createViteServerOptions(projectRoot, options)), runtime.env), { successText: '已创建 Vite dev server' });
634
- await logger.task('正在启动 Vite dev server', () => appServer.listen(options.port ?? DEFAULT_APP_PORT), {
655
+ const appServer = await logger.task('正在创建 Vite dev server', () => withManagedDevOutputEnv(() => vite.createServer(createViteServerOptions(projectRoot, resolvedOptions)), runtime.env), { successText: '已创建 Vite dev server' });
656
+ await logger.task('正在启动 Vite dev server', () => appServer.listen(appPort), {
635
657
  successText: 'Vite dev server 已启动',
636
658
  });
637
- const appUrl = await logger.task('正在探测小程序入口', () => resolveViteAppUrl(appServer, options, fetchImpl), {
659
+ const appUrl = await logger.task('正在探测小程序入口', () => resolveViteAppUrl(appServer, resolvedOptions, fetchImpl), {
638
660
  successText: '已确定小程序入口',
639
661
  });
640
662
  const lanAddresses = createLanAddressCandidates({
641
663
  appUrl,
642
- interfaces: (runtime.networkInterfaces ?? os.networkInterfaces)(),
664
+ interfaces: networkInterfaceSnapshot,
643
665
  runtimeUrl: options.runtimeUrl,
644
666
  viteNetworkUrls: appServer.resolvedUrls?.network ?? [],
645
667
  });
@@ -649,7 +671,7 @@ async function runDevCommand(options, runtime = {}) {
649
671
  mockHost = await logger.task('正在启动 Mock runtime host', () => startMiniProgramMockHostServer({
650
672
  appUrl,
651
673
  fetchImpl,
652
- getPort: runtime.getPort ?? getPorts,
674
+ getPort: getPortImpl,
653
675
  defaultLanAddressId: lanAddresses[0]?.id,
654
676
  lanAddresses,
655
677
  macAppProtocol: createMacAppProtocol(appUrl, { runtimeUrl: options.runtimeUrl }),
@@ -711,9 +733,12 @@ function createViteServerOptions(projectRoot, options) {
711
733
  const configFile = resolveProjectViteConfig(projectRoot);
712
734
  const server = {
713
735
  cors: true,
736
+ hmr: {
737
+ clientPort: options.port ?? DEFAULT_APP_PORT,
738
+ },
714
739
  host: DEV_LISTEN_HOST,
715
740
  port: options.port ?? DEFAULT_APP_PORT,
716
- strictPort: false,
741
+ strictPort: true,
717
742
  };
718
743
  if (configFile) {
719
744
  return {
@@ -856,24 +881,19 @@ function createLanAddressCandidates(options) {
856
881
  const viteNetworkUrlByHost = new Map(options.viteNetworkUrls
857
882
  .map((url) => [readUrlHost(url), url])
858
883
  .filter((entry) => Boolean(entry[0])));
859
- const candidates = Object.entries(options.interfaces)
860
- .flatMap(([name, infos]) => (infos ?? []).map((info) => ({
861
- info,
862
- name,
863
- })))
864
- .filter(({ info }) => info.family === 'IPv4' && !info.internal && isPrivateIPv4(info.address))
865
- .map(({ info, name }) => {
866
- const appUrl = viteNetworkUrlByHost.get(info.address) ?? replaceUrlHost(options.appUrl, info.address);
884
+ const candidates = createLanInterfaceCandidates(options.interfaces)
885
+ .map(({ address, id, name }) => {
886
+ const appUrl = viteNetworkUrlByHost.get(address) ?? replaceUrlHost(options.appUrl, address);
867
887
  if (!appUrl) {
868
888
  return undefined;
869
889
  }
870
890
  const candidate = {
871
- address: info.address,
891
+ address,
872
892
  appUrl,
873
- id: `${name}-${info.address}`,
893
+ id,
874
894
  name,
875
895
  };
876
- const runtimeUrl = rewriteLoopbackUrlHost(options.runtimeUrl, info.address);
896
+ const runtimeUrl = rewriteLoopbackUrlHost(options.runtimeUrl, address);
877
897
  if (runtimeUrl !== undefined) {
878
898
  candidate.mobileAppQrPayload = createMobileAppQrPayload(appUrl, { runtimeUrl });
879
899
  }
@@ -892,6 +912,22 @@ function createLanAddressCandidates(options) {
892
912
  return readInterfacePriority(left.name) - readInterfacePriority(right.name) || left.name.localeCompare(right.name);
893
913
  });
894
914
  }
915
+ function createLanInterfaceCandidates(interfaces) {
916
+ return Object.entries(interfaces)
917
+ .flatMap(([name, infos]) => (infos ?? []).map((info) => ({
918
+ info,
919
+ name,
920
+ })))
921
+ .filter(({ info }) => info.family === 'IPv4' && !info.internal && isPrivateIPv4(info.address))
922
+ .map(({ info, name }) => ({
923
+ address: info.address,
924
+ id: `${name}-${info.address}`,
925
+ name,
926
+ }))
927
+ .sort((left, right) => {
928
+ return readInterfacePriority(left.name) - readInterfacePriority(right.name) || left.name.localeCompare(right.name);
929
+ });
930
+ }
895
931
  function rewriteLoopbackUrlHost(input, host) {
896
932
  if (input === undefined || input === '') {
897
933
  return undefined;
@@ -4,7 +4,7 @@ var fs$1 = require('node:fs');
4
4
  var fs = require('node:fs/promises');
5
5
  var os = require('node:os');
6
6
  var path = require('node:path');
7
- var index = require('./index-io4h3kr-.cjs');
7
+ var index = require('./index-p5XZBWaZ.cjs');
8
8
  require('node:module');
9
9
  require('path');
10
10
  require('os');
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var index$2 = require('./index-io4h3kr-.cjs');
3
+ var index$2 = require('./index-p5XZBWaZ.cjs');
4
4
  var require$$0$2 = require('fs');
5
5
  var require$$2$1 = require('crypto');
6
6
  var require$$1$2 = require('path');
7
7
  var require$$0$3 = require('assert');
8
8
  var require$$4$2 = require('events');
9
9
  var require$$1$1 = require('util');
10
- var deploy = require('./deploy-CknDDoS_.cjs');
10
+ var deploy = require('./deploy-71Eb_W7K.cjs');
11
11
  var require$$0$5 = require('net');
12
12
  var require$$0$4 = require('url');
13
13
  var require$$2$2 = require('http');
@@ -234,19 +234,19 @@ function requireArgument () {
234
234
 
235
235
  var command = {};
236
236
 
237
- const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-io4h3kr-.cjs', document.baseURI).href)));
237
+ const require$5 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-p5XZBWaZ.cjs', document.baseURI).href)));
238
238
  function __require$4() { return require$5("node:events"); }
239
239
 
240
- const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-io4h3kr-.cjs', document.baseURI).href)));
240
+ const require$4 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-p5XZBWaZ.cjs', document.baseURI).href)));
241
241
  function __require$3() { return require$4("node:child_process"); }
242
242
 
243
- const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-io4h3kr-.cjs', document.baseURI).href)));
243
+ const require$3 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-p5XZBWaZ.cjs', document.baseURI).href)));
244
244
  function __require$2() { return require$3("node:path"); }
245
245
 
246
- const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-io4h3kr-.cjs', document.baseURI).href)));
246
+ const require$2 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-p5XZBWaZ.cjs', document.baseURI).href)));
247
247
  function __require$1() { return require$2("node:fs"); }
248
248
 
249
- const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-io4h3kr-.cjs', document.baseURI).href)));
249
+ const require$1 = node_module.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('cli-chunks/index-p5XZBWaZ.cjs', document.baseURI).href)));
250
250
  function __require() { return require$1("node:process"); }
251
251
 
252
252
  var help = {};
@@ -13092,7 +13092,7 @@ function readErrorMessage(error, options = {}) {
13092
13092
  }
13093
13093
 
13094
13094
  const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
13095
- const BUILT_CLI_VERSION = '0.4.0';
13095
+ const BUILT_CLI_VERSION = '0.4.2';
13096
13096
  const PACKAGE_JSON_CANDIDATES = [
13097
13097
  path.resolve(__dirname, '..', '..', 'package.json'),
13098
13098
  path.resolve(__dirname, '..', 'package.json'),
@@ -13249,31 +13249,31 @@ function createCommandLoggerResolver(options) {
13249
13249
  };
13250
13250
  }
13251
13251
  const defaultClearLoginStatus = async (...args) => {
13252
- const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-B-A53Sta.cjs'); });
13252
+ const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-COcBbeEc.cjs'); });
13253
13253
  return clearLoginStatus(...args);
13254
13254
  };
13255
13255
  const defaultLoginToHeybox = async (...args) => {
13256
- const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-B-A53Sta.cjs'); });
13256
+ const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-COcBbeEc.cjs'); });
13257
13257
  return loginToHeybox(...args);
13258
13258
  };
13259
13259
  const defaultPrintLoginStatus = async (...args) => {
13260
- const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-B-A53Sta.cjs'); });
13260
+ const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-COcBbeEc.cjs'); });
13261
13261
  return printLoginStatus(...args);
13262
13262
  };
13263
13263
  const defaultRunCreateCommand = async (...args) => {
13264
- const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-D1j9UnM7.cjs'); });
13264
+ const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-CPI9SgG3.cjs'); });
13265
13265
  return runCreateCommand(...args);
13266
13266
  };
13267
13267
  const defaultRunDeployCommand = async (...args) => {
13268
- const { runDeployCommand } = await Promise.resolve().then(function () { return require('./deploy-CknDDoS_.cjs'); }).then(function (n) { return n.deploy; });
13268
+ const { runDeployCommand } = await Promise.resolve().then(function () { return require('./deploy-71Eb_W7K.cjs'); }).then(function (n) { return n.deploy; });
13269
13269
  return runDeployCommand(...args);
13270
13270
  };
13271
13271
  const defaultRunDevCommand = async (...args) => {
13272
- const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-BS9h09yG.cjs'); });
13272
+ const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-B_HCfuH4.cjs'); });
13273
13273
  return runDevCommand(...args);
13274
13274
  };
13275
13275
  const defaultRunDoctorCommand = async (...args) => {
13276
- const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-WTl1HCW0.cjs'); });
13276
+ const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-B_UT0kAa.cjs'); });
13277
13277
  return runDoctorCommand(...args);
13278
13278
  };
13279
13279
  function resolveStandaloneLogger(options, verbose) {
@@ -2,9 +2,9 @@
2
2
 
3
3
  var node_crypto = require('node:crypto');
4
4
  var node_http = require('node:http');
5
- var session = require('./session-CMBN3o9z.cjs');
5
+ var session = require('./session-DNG8Q6Ni.cjs');
6
6
  var browser = require('./browser-RAy8e8cV.cjs');
7
- var index = require('./index-io4h3kr-.cjs');
7
+ var index = require('./index-p5XZBWaZ.cjs');
8
8
  require('node:path');
9
9
  require('fs');
10
10
  require('constants');
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var path = require('node:path');
4
- var index = require('./index-io4h3kr-.cjs');
4
+ var index = require('./index-p5XZBWaZ.cjs');
5
5
  var require$$0$2 = require('fs');
6
6
  var require$$0 = require('constants');
7
7
  var require$$0$1 = require('stream');
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./cli-chunks/index-io4h3kr-.cjs');
3
+ var index = require('./cli-chunks/index-p5XZBWaZ.cjs');
4
4
  require('node:module');
5
5
  require('node:fs');
6
6
  require('node:fs/promises');
@@ -13,6 +13,10 @@ npm run build
13
13
  npm run deploy
14
14
  ```
15
15
 
16
+ ## 依赖说明
17
+
18
+ `@heybox/hb-sdk` 是小程序页面运行时会 import 的 SDK,因此模板把它放在 `dependencies`。Vite、TypeScript、Vitest 等只参与本地开发、测试或构建的工具放在 `devDependencies`。
19
+
16
20
  ## 开发模式
17
21
 
18
22
  - `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面,也可以选择局域网网卡后用手机小黑盒 APP 扫码调试。手机需要与电脑处在同一局域网,并使用支持小程序调试壳的新版小黑盒 APP。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heybox/hb-sdk",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -19,7 +19,7 @@
19
19
  ## Package metadata
20
20
 
21
21
  - Package: `@heybox/hb-sdk`
22
- - Version at generation time: `0.4.0`
22
+ - Version at generation time: `0.4.2`
23
23
  - Public root export: `@heybox/hb-sdk`
24
24
  - Protocol export: `@heybox/hb-sdk/protocol`
25
25
  - Vite plugin export: `@heybox/hb-sdk/vite`
@@ -577,6 +577,10 @@ npm run build
577
577
  npm run deploy
578
578
  ```
579
579
 
580
+ ## 依赖说明
581
+
582
+ `@heybox/hb-sdk` 是小程序页面运行时会 import 的 SDK,因此模板把它放在 `dependencies`。Vite、TypeScript、Vitest 等只参与本地开发、测试或构建的工具放在 `devDependencies`。
583
+
580
584
  ## 开发模式
581
585
 
582
586
  - `npm run dev`:启动本地 Vite 服务和 `hb-sdk` 内置 mock runtime host,适合本地调试 SDK 能力;调试页内可点击按钮在 Mac 版 APP 中启动同一页面,也可以选择局域网网卡后用手机小黑盒 APP 扫码调试。手机需要与电脑处在同一局域网,并使用支持小程序调试壳的新版小黑盒 APP。Codex、VSCode 等内嵌浏览器可能无法唤起系统 APP,需要时请在系统浏览器中打开同一个调试页后重试。
package/skill/skill.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "hb-sdk",
3
- "skillVersion": "0.4.0+skill.6e13c65735d8",
3
+ "skillVersion": "0.4.2+skill.fc5802b13fbb",
4
4
  "sdk": {
5
5
  "package": "@heybox/hb-sdk",
6
- "version": "0.4.0",
7
- "compatibility": "0.4.0"
6
+ "version": "0.4.2",
7
+ "compatibility": "0.4.2"
8
8
  },
9
9
  "source": "https://open.xiaoheihe.cn/agent-skills/hb-sdk",
10
- "integrity": "sha256-6e13c65735d8de3ac9c9dd48b16412b93e3497038d0582b5eed05355dc3397bd"
10
+ "integrity": "sha256-fc5802b13fbbfc70964dc56c9cc5d5888e2bed739ed38fbe17555a418e8a744d"
11
11
  }