@heybox/hb-sdk 0.6.7-alpha.1 → 0.6.7

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.
Files changed (27) hide show
  1. package/README.md +3 -3
  2. package/dist/cli-chunks/{build-cBQK_qq-.cjs → build-DaHCCSLH.cjs} +25 -29
  3. package/dist/cli-chunks/{context-CfrdSQSg.cjs → context-cQXupHub.cjs} +23 -122
  4. package/dist/cli-chunks/{create-mp5nBLFJ.cjs → create-D2dSw7bl.cjs} +1 -1
  5. package/dist/cli-chunks/{dev-CSuSpwJC.cjs → dev-D6WhI3cC.cjs} +110 -21
  6. package/dist/cli-chunks/{doctor-nEv6ikeF.cjs → doctor-CtNS5Tt2.cjs} +21 -3
  7. package/dist/cli-chunks/{index-CZ1l6xci.cjs → index-B1w-Jpba.cjs} +14 -14
  8. package/dist/cli-chunks/{index-CgUdrl3g.cjs → index-C4y2G95g.cjs} +3 -3
  9. package/dist/cli-chunks/{runtime-permission-env-BSs4uCNa.cjs → index-v4-6fbXX.cjs} +29 -73
  10. package/dist/cli-chunks/{login-B2kXjmcM.cjs → login-D-ZK-n1E.cjs} +2 -2
  11. package/dist/cli-chunks/{project-vite-BGAleOVW.cjs → project-vite-J4lrUja0.cjs} +1 -1
  12. package/dist/cli-chunks/{remote-B5byhdC7.cjs → remote-BZNHAL5_.cjs} +44 -42
  13. package/dist/cli-chunks/{runtime-gate--rPXjiG6.cjs → runtime-gate-DfMJQGH9.cjs} +3 -3
  14. package/dist/cli-chunks/{session-BbDd1r6M.cjs → session-5ryBp2wZ.cjs} +1 -1
  15. package/dist/cli.cjs +1 -1
  16. package/dist/index.cjs.js +1 -1
  17. package/dist/index.esm.js +1 -1
  18. package/dist/miniapp-publish.cjs.js +29 -2
  19. package/dist/miniapp-publish.esm.js +29 -2
  20. package/dist/vite.cjs.js +50 -28
  21. package/dist/vite.esm.js +50 -28
  22. package/package.json +1 -1
  23. package/skill/references/api-root.md +7 -9
  24. package/skill/skill.json +4 -4
  25. package/types/vite/html-policy.d.ts +0 -1
  26. package/types/vite/index.d.ts +1 -0
  27. package/types/vite/runtime-permission-env.d.ts +0 -9
@@ -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-CZ1l6xci.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-B1w-Jpba.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-CZ1l6xci.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-B1w-Jpba.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-CZ1l6xci.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-B1w-Jpba.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-CZ1l6xci.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-B1w-Jpba.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-CZ1l6xci.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-B1w-Jpba.cjs', document.baseURI).href)));
250
250
  function __require() { return require$1("node:process"); }
251
251
 
252
252
  var help = {};
@@ -13347,7 +13347,7 @@ function getPathname(pathWithQuery) {
13347
13347
  }
13348
13348
 
13349
13349
  const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
13350
- const BUILT_CLI_VERSION = '0.6.7-alpha.1';
13350
+ const BUILT_CLI_VERSION = '0.6.7';
13351
13351
  const PACKAGE_JSON_CANDIDATES = [
13352
13352
  path.resolve(__dirname, '..', '..', 'package.json'),
13353
13353
  path.resolve(__dirname, '..', 'package.json'),
@@ -13680,35 +13680,35 @@ function createCommandLoggerResolver(options) {
13680
13680
  };
13681
13681
  }
13682
13682
  const defaultClearLoginStatus = async (...args) => {
13683
- const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-B2kXjmcM.cjs'); });
13683
+ const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-D-ZK-n1E.cjs'); });
13684
13684
  return clearLoginStatus(...args);
13685
13685
  };
13686
13686
  const defaultLoginToHeybox = async (...args) => {
13687
- const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-B2kXjmcM.cjs'); });
13687
+ const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-D-ZK-n1E.cjs'); });
13688
13688
  return loginToHeybox(...args);
13689
13689
  };
13690
13690
  const defaultPrintLoginStatus = async (...args) => {
13691
- const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-B2kXjmcM.cjs'); });
13691
+ const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-D-ZK-n1E.cjs'); });
13692
13692
  return printLoginStatus(...args);
13693
13693
  };
13694
13694
  const defaultRunBuildCommand = async (...args) => {
13695
- const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-cBQK_qq-.cjs'); });
13695
+ const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-DaHCCSLH.cjs'); });
13696
13696
  return runBuildCommand(...args);
13697
13697
  };
13698
13698
  const defaultRunCreateCommand = async (...args) => {
13699
- const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-mp5nBLFJ.cjs'); });
13699
+ const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-D2dSw7bl.cjs'); });
13700
13700
  return runCreateCommand(...args);
13701
13701
  };
13702
13702
  const defaultRunDevCommand = async (...args) => {
13703
- const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-CSuSpwJC.cjs'); });
13703
+ const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-D6WhI3cC.cjs'); });
13704
13704
  return runDevCommand(...args);
13705
13705
  };
13706
13706
  const defaultRunDoctorCommand = async (...args) => {
13707
- const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-nEv6ikeF.cjs'); });
13707
+ const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-CtNS5Tt2.cjs'); });
13708
13708
  return runDoctorCommand(...args);
13709
13709
  };
13710
13710
  const defaultRunRemoteCommand = async (...args) => {
13711
- const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-B5byhdC7.cjs'); });
13711
+ const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-BZNHAL5_.cjs'); });
13712
13712
  return runRemoteCommand(...args);
13713
13713
  };
13714
13714
  function resolveStandaloneLogger(options, verbose) {
@@ -1,13 +1,13 @@
1
1
  'use strict';
2
2
 
3
- var index$2 = require('./index-CZ1l6xci.cjs');
3
+ var index$2 = require('./index-B1w-Jpba.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 runtimePermissionEnv = require('./runtime-permission-env-BSs4uCNa.cjs');
10
+ var index$3 = require('./index-v4-6fbXX.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');
@@ -13707,7 +13707,7 @@ function requireSource () {
13707
13707
  const ajv_1 = requireAjv$1();
13708
13708
  const ajv_formats_1 = requireDist();
13709
13709
  const debounceFn = requireDebounceFn();
13710
- const semver = runtimePermissionEnv.requireSemver();
13710
+ const semver = index$3.requireSemver();
13711
13711
  const onetime = index$2.requireOnetime();
13712
13712
  const encryptionAlgorithm = 'aes-256-cbc';
13713
13713
  const createPlainObject = () => {
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var node_async_hooks = require('node:async_hooks');
4
-
5
3
  var re = {exports: {}};
6
4
 
7
5
  var constants;
@@ -2841,18 +2839,45 @@ function getMiniappUploadKey(input) {
2841
2839
  }
2842
2840
  function validateUploadPaths(items, options) {
2843
2841
  const limit = options.maxLength;
2842
+ const uploadKeys = new Set();
2844
2843
  for (const item of items) {
2844
+ const relativePath = String(item.relativePath ?? '');
2845
+ const normalizedRelativePath = normalizeRelativePath(relativePath);
2846
+ const invalidReason = getInvalidUploadPathReason(normalizedRelativePath);
2847
+ if (invalidReason) {
2848
+ return `构建产物文件路径不合法(${invalidReason}):${JSON.stringify(relativePath)}`;
2849
+ }
2845
2850
  const key = getMiniappUploadKey({
2846
2851
  miniProgramId: options.miniProgramId,
2847
2852
  version: options.version,
2848
- relativePath: item.relativePath,
2853
+ relativePath: normalizedRelativePath,
2849
2854
  });
2855
+ if (uploadKeys.has(key)) {
2856
+ return `构建产物文件路径重复,无法上传到同一位置:${JSON.stringify(relativePath)}`;
2857
+ }
2858
+ uploadKeys.add(key);
2850
2859
  if (key.length > limit) {
2851
- return `文件路径过长,请缩短构建产物文件名或目录层级:${item.relativePath}`;
2860
+ return `文件路径过长,请缩短构建产物文件名或目录层级:${relativePath}`;
2852
2861
  }
2853
2862
  }
2854
2863
  return undefined;
2855
2864
  }
2865
+ function getInvalidUploadPathReason(relativePath) {
2866
+ const segments = relativePath.replace(/\\/g, '/').split('/');
2867
+ if (segments.some((segment) => !segment)) {
2868
+ return '包含空路径段';
2869
+ }
2870
+ if (segments.some((segment) => segment === '.')) {
2871
+ return '包含当前目录';
2872
+ }
2873
+ if (segments.some((segment) => segment === '..')) {
2874
+ return '包含上级目录';
2875
+ }
2876
+ if (/[\u0000-\u001F\u007F]/.test(relativePath)) {
2877
+ return '包含控制字符';
2878
+ }
2879
+ return undefined;
2880
+ }
2856
2881
  function validateUploadTotalSize(items, options = {}) {
2857
2882
  const limit = options.limitBytes ?? MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES;
2858
2883
  const total = items.reduce((sum, item) => {
@@ -2881,72 +2906,6 @@ function shouldUploadDistFile(relativePath) {
2881
2906
  return true;
2882
2907
  }
2883
2908
 
2884
- const HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV = 'HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN';
2885
- const HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV = 'HB_SDK_RUNTIME_PERMISSION_CONTEXT';
2886
- const VERIFIED_RUNTIME_PERMISSION_CONTEXT = 'verified';
2887
- const environmentScopeStorage = new node_async_hooks.AsyncLocalStorage();
2888
- let environmentScopeTail = Promise.resolve();
2889
- function shouldSkipMiniappPlatformCspFromEnv(env = process.env) {
2890
- return env[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] === VERIFIED_RUNTIME_PERMISSION_CONTEXT && env[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] === '1';
2891
- }
2892
- function createMiniappPlatformCspEnv(env, skipPlatformCsp) {
2893
- return {
2894
- ...env,
2895
- [HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV]: VERIFIED_RUNTIME_PERMISSION_CONTEXT,
2896
- [HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV]: skipPlatformCsp ? '1' : '0',
2897
- };
2898
- }
2899
- async function withMiniappPlatformCspEnv(skipPlatformCsp, action, env = process.env) {
2900
- if (environmentScopeStorage.getStore()?.active) {
2901
- return runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env);
2902
- }
2903
- let releaseScope = () => undefined;
2904
- const previousScope = environmentScopeTail;
2905
- environmentScopeTail = new Promise((resolve) => {
2906
- releaseScope = resolve;
2907
- });
2908
- await previousScope;
2909
- const scope = { active: true };
2910
- try {
2911
- return await environmentScopeStorage.run(scope, () => runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env));
2912
- }
2913
- finally {
2914
- scope.active = false;
2915
- releaseScope();
2916
- }
2917
- }
2918
- async function runMiniappPlatformCspEnvScope(skipPlatformCsp, action, env) {
2919
- const targets = env === process.env ? [env] : [env, process.env];
2920
- const previousValues = targets.map((target) => ({
2921
- context: target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV],
2922
- officialDomain: target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV],
2923
- }));
2924
- for (const target of targets) {
2925
- target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] = VERIFIED_RUNTIME_PERMISSION_CONTEXT;
2926
- target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] = skipPlatformCsp ? '1' : '0';
2927
- }
2928
- try {
2929
- return await action();
2930
- }
2931
- finally {
2932
- targets.forEach((target, index) => {
2933
- const previousValue = previousValues[index];
2934
- if (previousValue?.context === undefined) {
2935
- delete target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV];
2936
- }
2937
- else {
2938
- target[HB_SDK_RUNTIME_PERMISSION_CONTEXT_ENV] = previousValue.context;
2939
- }
2940
- if (previousValue?.officialDomain === undefined) {
2941
- delete target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV];
2942
- }
2943
- else {
2944
- target[HB_SDK_RUNTIME_USE_OFFICIAL_DOMAIN_ENV] = previousValue.officialDomain;
2945
- }
2946
- });
2947
- }
2948
- }
2949
-
2950
2909
  exports.ACTIVITY_UPLOAD_KEY_MAX_LENGTH = ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
2951
2910
  exports.CREATE_USER_MINIPROGRAM_API_PATH = CREATE_USER_MINIPROGRAM_API_PATH;
2952
2911
  exports.CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH = CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH;
@@ -2971,14 +2930,11 @@ exports.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH = USER_MINIPROGRAM_ACCESS_STATUS
2971
2930
  exports.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH = USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH;
2972
2931
  exports.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH = USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH;
2973
2932
  exports.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH = WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH;
2974
- exports.createMiniappPlatformCspEnv = createMiniappPlatformCspEnv;
2975
2933
  exports.getMiniappUploadKey = getMiniappUploadKey;
2976
2934
  exports.normalizeRelativePath = normalizeRelativePath;
2977
2935
  exports.relativePathContainsNodeModulesSegment = relativePathContainsNodeModulesSegment;
2978
2936
  exports.requireSemver = requireSemver;
2979
2937
  exports.semverExports = semverExports;
2980
- exports.shouldSkipMiniappPlatformCspFromEnv = shouldSkipMiniappPlatformCspFromEnv;
2981
2938
  exports.shouldUploadDistFile = shouldUploadDistFile;
2982
2939
  exports.validateUploadPaths = validateUploadPaths;
2983
2940
  exports.validateUploadTotalSize = validateUploadTotalSize;
2984
- exports.withMiniappPlatformCspEnv = withMiniappPlatformCspEnv;
@@ -3,9 +3,9 @@
3
3
  var promises = require('node:readline/promises');
4
4
  var node_crypto = require('node:crypto');
5
5
  var node_http = require('node:http');
6
- var session = require('./session-BbDd1r6M.cjs');
6
+ var session = require('./session-5ryBp2wZ.cjs');
7
7
  var browser = require('./browser-RAy8e8cV.cjs');
8
- var index = require('./index-CZ1l6xci.cjs');
8
+ var index = require('./index-B1w-Jpba.cjs');
9
9
  require('node:path');
10
10
  require('fs');
11
11
  require('constants');
@@ -5,7 +5,7 @@ var fs$1 = require('node:fs/promises');
5
5
  var node_module = require('node:module');
6
6
  var path = require('node:path');
7
7
  var node_url = require('node:url');
8
- var index = require('./index-CZ1l6xci.cjs');
8
+ var index = require('./index-B1w-Jpba.cjs');
9
9
 
10
10
  function findProjectRoot(startDir) {
11
11
  let current = path.resolve(startDir);
@@ -1,15 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var promises = require('node:readline/promises');
4
- var index = require('./index-CZ1l6xci.cjs');
5
- var session = require('./session-BbDd1r6M.cjs');
4
+ var index = require('./index-B1w-Jpba.cjs');
5
+ var session = require('./session-5ryBp2wZ.cjs');
6
6
  var childProcess = require('node:child_process');
7
7
  var fs = require('node:fs');
8
8
  var fs$1 = require('node:fs/promises');
9
9
  var path = require('node:path');
10
- var runtimePermissionEnv = require('./runtime-permission-env-BSs4uCNa.cjs');
11
- var runtimeGate = require('./runtime-gate--rPXjiG6.cjs');
12
- var context = require('./context-CfrdSQSg.cjs');
10
+ var index$1 = require('./index-v4-6fbXX.cjs');
11
+ var runtimeGate = require('./runtime-gate-DfMJQGH9.cjs');
12
+ var context = require('./context-cQXupHub.cjs');
13
13
  require('node:module');
14
14
  require('path');
15
15
  require('os');
@@ -23,7 +23,6 @@ require('util');
23
23
  require('node:crypto');
24
24
  require('fs');
25
25
  require('constants');
26
- require('node:async_hooks');
27
26
 
28
27
  async function getCDNUploadInfo(options, runtime = {}) {
29
28
  const body = new URLSearchParams();
@@ -70,7 +69,7 @@ async function runUpload(options, runtime = {}) {
70
69
  const postCDNUploadCallback$1 = runtime.postCDNUploadCallback ?? postCDNUploadCallback;
71
70
  const createReadStream = runtime.createReadStream ?? fs.createReadStream;
72
71
  const orderedFiles = [...options.files].sort((a, b) => a.relativePath.localeCompare(b.relativePath));
73
- const batches = chunkUploadFiles(orderedFiles, runtimePermissionEnv.MINIAPP_UPLOAD_BATCH_SIZE);
72
+ const batches = chunkUploadFiles(orderedFiles, index$1.MINIAPP_UPLOAD_BATCH_SIZE);
74
73
  await logger.task(`正在上传 ${orderedFiles.length} 个文件`, async (taskContext) => {
75
74
  logger.debug(`上传并发数: ${concurrency}`);
76
75
  logger.debug(`上传批次数: ${batches.length}`);
@@ -80,7 +79,7 @@ async function runUpload(options, runtime = {}) {
80
79
  logger.debug(`正在处理上传批次 ${batchIndex + 1}/${batches.length},文件数: ${batch.length}`);
81
80
  logger.debug('正在获取 CDN 上传信息');
82
81
  const fileInfos = createUploadFileInfos(batch, options);
83
- const uploadInfo = await getCDNUploadInfo$1({ session: options.session, scope: runtimePermissionEnv.MINIAPP_UPLOAD_SCOPE, fileInfos, needCache: false }, { baseUrl: runtime.baseUrl, fetchImpl });
82
+ const uploadInfo = await getCDNUploadInfo$1({ session: options.session, scope: index$1.MINIAPP_UPLOAD_SCOPE, fileInfos, needCache: false }, { baseUrl: runtime.baseUrl, fetchImpl });
84
83
  logger.debug(`CDN bucket: ${uploadInfo.bucket}`);
85
84
  logger.debug(`CDN region: ${uploadInfo.region}`);
86
85
  validateUploadInfoKeys(batch, uploadInfo.keys, options);
@@ -141,7 +140,7 @@ function createUploadFileInfos(files, options) {
141
140
  name: file.relativePath.split('/').pop() ?? file.relativePath,
142
141
  mimetype: file.mimeType,
143
142
  fsize: file.size,
144
- path: runtimePermissionEnv.getMiniappUploadKey({
143
+ path: index$1.getMiniappUploadKey({
145
144
  miniProgramId: options.miniProgramId,
146
145
  version: options.version,
147
146
  relativePath: file.relativePath,
@@ -152,15 +151,15 @@ function validateUploadInfoKeys(files, keys, options) {
152
151
  if (keys.length !== files.length) {
153
152
  throw new index.CliError(`CDN 上传接口返回 key 数量异常:期望 ${files.length},实际 ${keys.length}`);
154
153
  }
155
- for (let index$1 = 0; index$1 < files.length; index$1 += 1) {
156
- const expectedKey = runtimePermissionEnv.getMiniappUploadKey({
154
+ for (let index$2 = 0; index$2 < files.length; index$2 += 1) {
155
+ const expectedKey = index$1.getMiniappUploadKey({
157
156
  miniProgramId: options.miniProgramId,
158
157
  version: options.version,
159
- relativePath: files[index$1].relativePath,
158
+ relativePath: files[index$2].relativePath,
160
159
  });
161
- const actualKey = keys[index$1];
160
+ const actualKey = keys[index$2];
162
161
  if (actualKey !== expectedKey) {
163
- throw new index.CliError(`CDN 上传接口返回 key 异常:${files[index$1].relativePath}`, [`CDN 上传接口返回 key 异常:${files[index$1].relativePath}`, `expected: ${expectedKey}`, `actual: ${actualKey}`].join('\n'));
162
+ throw new index.CliError(`CDN 上传接口返回 key 异常:${files[index$2].relativePath}`, [`CDN 上传接口返回 key 异常:${files[index$2].relativePath}`, `expected: ${expectedKey}`, `actual: ${actualKey}`].join('\n'));
164
163
  }
165
164
  }
166
165
  }
@@ -192,7 +191,7 @@ async function createDefaultCosClient(uploadToken) {
192
191
  };
193
192
  }
194
193
  async function loadCosConstructor() {
195
- const cosModule = await Promise.resolve().then(function () { return require('./index-CgUdrl3g.cjs'); }).then(function (n) { return n.index; });
194
+ const cosModule = await Promise.resolve().then(function () { return require('./index-C4y2G95g.cjs'); }).then(function (n) { return n.index; });
196
195
  return cosModule.default;
197
196
  }
198
197
  function formatSize(bytes) {
@@ -236,7 +235,7 @@ function isRecord(value) {
236
235
  }
237
236
 
238
237
  async function precheckUserMiniprogramVersion(options, runtime = {}) {
239
- return postUserMiniprogramVersionForm(runtimePermissionEnv.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH, options, {
238
+ return postUserMiniprogramVersionForm(index$1.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH, options, {
240
239
  // 展示资料由服务端沿用 last approved 或注入默认名/默认图;CLI 不传 name/icon/cover。
241
240
  ...(options.version ? { version: options.version } : {}),
242
241
  ...(options.source_version ? { source_version: options.source_version } : {}),
@@ -245,7 +244,7 @@ async function precheckUserMiniprogramVersion(options, runtime = {}) {
245
244
  }, runtime);
246
245
  }
247
246
  async function submitUserMiniprogramAudit(options, runtime = {}) {
248
- return postUserMiniprogramVersionForm(runtimePermissionEnv.SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH, options, {
247
+ return postUserMiniprogramVersionForm(index$1.SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH, options, {
249
248
  // 展示资料由服务端沿用 last approved 或注入默认名/默认图;CLI 不传 name/icon/cover。
250
249
  ...(options.manifest ? { manifest: JSON.stringify(options.manifest) } : {}),
251
250
  ...(options.source_version ? { source_version: options.source_version } : {}),
@@ -342,30 +341,15 @@ async function runDeployCommand(options, runtime = {}) {
342
341
  releaseNote,
343
342
  autoPublish,
344
343
  }, runtime, apiBaseUrl, projectRoot, logger);
345
- let skipPlatformCsp = false;
346
- try {
347
- const { detail } = await logger.task('正在读取远端小程序权限', () => (runtime.getBoundMiniProgram ?? context.getBoundMiniProgram)({
348
- allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
349
- apiBaseUrl,
350
- cwd: projectRoot,
351
- env,
352
- fetchImpl: runtime.fetchImpl,
353
- loginBaseUrl,
354
- session: session$1,
355
- }), { successText: '已读取远端小程序权限' });
356
- skipPlatformCsp = context.shouldSkipMiniappPlatformCsp(detail.runtime_permissions);
357
- }
358
- catch (error) {
359
- logger.warn('未读取到远端 Runtime 权限,构建将继续注入平台 CSP。');
360
- logger.debug(`远端 Runtime 权限读取失败详情:${index.readRedactedErrorMessage(error, { verbose: true })}`);
361
- }
362
344
  const pm = detectPackageManager(projectRoot);
363
- const buildMode = env.HB_SDK_ENV?.trim();
345
+ const platform = runtime.platform ?? process.platform;
346
+ const buildMode = validateBuildMode(env.HB_SDK_ENV?.trim(), platform);
364
347
  logger.info(`开始构建: ${pm} ${createBuildArgs(pm, buildMode).join(' ')}`);
365
348
  await runBuildScript(pm, projectRoot, runtime.spawn ?? childProcess.spawn, {
366
- env: runtimePermissionEnv.createMiniappPlatformCspEnv(env, skipPlatformCsp),
349
+ env,
367
350
  mode: buildMode,
368
351
  outputMode: options.buildOutputMode ?? 'inherit',
352
+ platform,
369
353
  stderr: runtime.stderr,
370
354
  });
371
355
  logger.success('构建完成');
@@ -382,16 +366,16 @@ async function runDeployCommand(options, runtime = {}) {
382
366
  }
383
367
  const uploadFiles = await logger.task('正在校验 dist 上传文件', async () => {
384
368
  const allFiles = await walkDistFiles(distDir);
385
- const blocked = allFiles.find((entry) => runtimePermissionEnv.relativePathContainsNodeModulesSegment(entry.relativePath));
369
+ const blocked = allFiles.find((entry) => index$1.relativePathContainsNodeModulesSegment(entry.relativePath));
386
370
  if (blocked) {
387
371
  throw new Error(`dist 目录含 node_modules:${blocked.relativePath}`);
388
372
  }
389
- const files = allFiles.filter((entry) => runtimePermissionEnv.shouldUploadDistFile(entry.relativePath));
390
- const pathError = runtimePermissionEnv.validateUploadPaths(files, { miniProgramId, version, maxLength: runtimePermissionEnv.ACTIVITY_UPLOAD_KEY_MAX_LENGTH });
373
+ const files = allFiles.filter((entry) => index$1.shouldUploadDistFile(entry.relativePath));
374
+ const pathError = index$1.validateUploadPaths(files, { miniProgramId, version, maxLength: index$1.ACTIVITY_UPLOAD_KEY_MAX_LENGTH });
391
375
  if (pathError) {
392
376
  throw new Error(pathError);
393
377
  }
394
- const sizeError = runtimePermissionEnv.validateUploadTotalSize(files);
378
+ const sizeError = index$1.validateUploadTotalSize(files);
395
379
  if (sizeError) {
396
380
  throw new Error(sizeError);
397
381
  }
@@ -554,9 +538,14 @@ async function runBuildScript(pm, cwd, spawnImpl, options) {
554
538
  await new Promise((resolve, reject) => {
555
539
  const pipeStdoutToStderr = options.outputMode === 'stderr';
556
540
  const buildArgs = createBuildArgs(pm, options.mode);
557
- const child = spawnImpl(pm, buildArgs, {
541
+ const isWindows = options.platform === 'win32';
542
+ const [executable, args] = isWindows
543
+ ? createWindowsBuildCommand(pm, buildArgs)
544
+ : [pm, buildArgs];
545
+ const child = spawnImpl(executable, args, {
558
546
  cwd,
559
547
  env: { ...process.env, ...options.env },
548
+ ...(isWindows ? { shell: false, windowsVerbatimArguments: true } : {}),
560
549
  stdio: pipeStdoutToStderr ? ['inherit', 'pipe', 'inherit'] : 'inherit',
561
550
  });
562
551
  if (pipeStdoutToStderr) {
@@ -575,6 +564,19 @@ async function runBuildScript(pm, cwd, spawnImpl, options) {
575
564
  });
576
565
  });
577
566
  }
567
+ function createWindowsBuildCommand(pm, buildArgs) {
568
+ const command = `${pm}.cmd ${buildArgs.map(escapeWindowsCommandArgument).join(' ')}`;
569
+ return ['cmd.exe', ['/d', '/s', '/c', `"${command}"`]];
570
+ }
571
+ function validateBuildMode(mode, platform) {
572
+ if (platform === 'win32' && mode && !/^[A-Za-z0-9._-]+$/.test(mode)) {
573
+ throw new Error('Windows 下 HB_SDK_ENV 仅支持字母、数字、点、下划线和连字符');
574
+ }
575
+ return mode;
576
+ }
577
+ function escapeWindowsCommandArgument(argument) {
578
+ return `"${argument}"`;
579
+ }
578
580
  function createBuildArgs(pm, mode) {
579
581
  return ['run', 'build', ...(mode ? [...(pm === 'npm' ? ['--'] : []), '--mode', mode] : [])];
580
582
  }
@@ -600,7 +602,7 @@ async function walkDistFiles(distDir) {
600
602
  }
601
603
  const fileStat = await fs$1.stat(absPath);
602
604
  results.push({
603
- relativePath: runtimePermissionEnv.normalizeRelativePath(relPath),
605
+ relativePath: index$1.normalizeRelativePath(relPath),
604
606
  absolutePath: absPath,
605
607
  size: fileStat.size,
606
608
  mimeType: inferMimeType(entry.name),
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var runtimePermissionEnv = require('./runtime-permission-env-BSs4uCNa.cjs');
3
+ var index = require('./index-v4-6fbXX.cjs');
4
4
 
5
5
  function isValidMiniappManifestVersion(version) {
6
6
  return getMiniappManifestVersionError(version) === undefined;
@@ -41,7 +41,7 @@ function validateSdkVersion(version, sourceLabel = 'sdkVersion') {
41
41
  throw new Error(`${sourceLabel} 必须是合法 SemVer:${String(version)}`);
42
42
  }
43
43
  const normalized = version.trim();
44
- const parsed = runtimePermissionEnv.semverExports.parse(normalized);
44
+ const parsed = index.semverExports.parse(normalized);
45
45
  if (!parsed || parsed.version !== normalized || parsed.build.length > 0) {
46
46
  throw new Error(`${sourceLabel} 必须是合法 SemVer:${normalized}`);
47
47
  }
@@ -55,7 +55,7 @@ function getMiniappManifestVersionError(version) {
55
55
  return `必须是合法 SemVer:${String(version)}`;
56
56
  }
57
57
  const normalized = version.trim();
58
- const parsed = runtimePermissionEnv.semverExports.parse(normalized);
58
+ const parsed = index.semverExports.parse(normalized);
59
59
  if (!parsed) {
60
60
  return `必须是合法 SemVer:${normalized}`;
61
61
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-CZ1l6xci.cjs');
3
+ var index = require('./index-B1w-Jpba.cjs');
4
4
  var node_crypto = require('node:crypto');
5
5
  var path = require('node:path');
6
6
  var require$$0$2 = require('fs');
package/dist/cli.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./cli-chunks/index-CZ1l6xci.cjs');
3
+ var index = require('./cli-chunks/index-B1w-Jpba.cjs');
4
4
  require('node:module');
5
5
  require('node:fs');
6
6
  require('node:fs/promises');
package/dist/index.cjs.js CHANGED
@@ -325,7 +325,7 @@ function createMessageId() {
325
325
  /** 构建时替换为当前发布包的实际版本。 */
326
326
  const HB_SDK_VERSION = typeof undefined === 'string'
327
327
  ? undefined
328
- : '0.6.7-alpha.1';
328
+ : '0.6.7';
329
329
 
330
330
  /**
331
331
  * 判断未知数据是否符合小程序 bridge 消息信封。
package/dist/index.esm.js CHANGED
@@ -321,7 +321,7 @@ function createMessageId() {
321
321
  /** 构建时替换为当前发布包的实际版本。 */
322
322
  const HB_SDK_VERSION = typeof undefined === 'string'
323
323
  ? undefined
324
- : '0.6.7-alpha.1';
324
+ : '0.6.7';
325
325
 
326
326
  /**
327
327
  * 判断未知数据是否符合小程序 bridge 消息信封。
@@ -2863,18 +2863,45 @@ function getMiniappUploadKey(input) {
2863
2863
  }
2864
2864
  function validateUploadPaths(items, options) {
2865
2865
  const limit = options.maxLength ?? ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
2866
+ const uploadKeys = new Set();
2866
2867
  for (const item of items) {
2868
+ const relativePath = String(item.relativePath ?? '');
2869
+ const normalizedRelativePath = normalizeRelativePath(relativePath);
2870
+ const invalidReason = getInvalidUploadPathReason(normalizedRelativePath);
2871
+ if (invalidReason) {
2872
+ return `构建产物文件路径不合法(${invalidReason}):${JSON.stringify(relativePath)}`;
2873
+ }
2867
2874
  const key = getMiniappUploadKey({
2868
2875
  miniProgramId: options.miniProgramId,
2869
2876
  version: options.version,
2870
- relativePath: item.relativePath,
2877
+ relativePath: normalizedRelativePath,
2871
2878
  });
2879
+ if (uploadKeys.has(key)) {
2880
+ return `构建产物文件路径重复,无法上传到同一位置:${JSON.stringify(relativePath)}`;
2881
+ }
2882
+ uploadKeys.add(key);
2872
2883
  if (key.length > limit) {
2873
- return `文件路径过长,请缩短构建产物文件名或目录层级:${item.relativePath}`;
2884
+ return `文件路径过长,请缩短构建产物文件名或目录层级:${relativePath}`;
2874
2885
  }
2875
2886
  }
2876
2887
  return undefined;
2877
2888
  }
2889
+ function getInvalidUploadPathReason(relativePath) {
2890
+ const segments = relativePath.replace(/\\/g, '/').split('/');
2891
+ if (segments.some((segment) => !segment)) {
2892
+ return '包含空路径段';
2893
+ }
2894
+ if (segments.some((segment) => segment === '.')) {
2895
+ return '包含当前目录';
2896
+ }
2897
+ if (segments.some((segment) => segment === '..')) {
2898
+ return '包含上级目录';
2899
+ }
2900
+ if (/[\u0000-\u001F\u007F]/.test(relativePath)) {
2901
+ return '包含控制字符';
2902
+ }
2903
+ return undefined;
2904
+ }
2878
2905
  function validateUploadTotalSize(items, options = {}) {
2879
2906
  const limit = options.limitBytes ?? MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES;
2880
2907
  const total = items.reduce((sum, item) => {
@@ -2861,18 +2861,45 @@ function getMiniappUploadKey(input) {
2861
2861
  }
2862
2862
  function validateUploadPaths(items, options) {
2863
2863
  const limit = options.maxLength ?? ACTIVITY_UPLOAD_KEY_MAX_LENGTH;
2864
+ const uploadKeys = new Set();
2864
2865
  for (const item of items) {
2866
+ const relativePath = String(item.relativePath ?? '');
2867
+ const normalizedRelativePath = normalizeRelativePath(relativePath);
2868
+ const invalidReason = getInvalidUploadPathReason(normalizedRelativePath);
2869
+ if (invalidReason) {
2870
+ return `构建产物文件路径不合法(${invalidReason}):${JSON.stringify(relativePath)}`;
2871
+ }
2865
2872
  const key = getMiniappUploadKey({
2866
2873
  miniProgramId: options.miniProgramId,
2867
2874
  version: options.version,
2868
- relativePath: item.relativePath,
2875
+ relativePath: normalizedRelativePath,
2869
2876
  });
2877
+ if (uploadKeys.has(key)) {
2878
+ return `构建产物文件路径重复,无法上传到同一位置:${JSON.stringify(relativePath)}`;
2879
+ }
2880
+ uploadKeys.add(key);
2870
2881
  if (key.length > limit) {
2871
- return `文件路径过长,请缩短构建产物文件名或目录层级:${item.relativePath}`;
2882
+ return `文件路径过长,请缩短构建产物文件名或目录层级:${relativePath}`;
2872
2883
  }
2873
2884
  }
2874
2885
  return undefined;
2875
2886
  }
2887
+ function getInvalidUploadPathReason(relativePath) {
2888
+ const segments = relativePath.replace(/\\/g, '/').split('/');
2889
+ if (segments.some((segment) => !segment)) {
2890
+ return '包含空路径段';
2891
+ }
2892
+ if (segments.some((segment) => segment === '.')) {
2893
+ return '包含当前目录';
2894
+ }
2895
+ if (segments.some((segment) => segment === '..')) {
2896
+ return '包含上级目录';
2897
+ }
2898
+ if (/[\u0000-\u001F\u007F]/.test(relativePath)) {
2899
+ return '包含控制字符';
2900
+ }
2901
+ return undefined;
2902
+ }
2876
2903
  function validateUploadTotalSize(items, options = {}) {
2877
2904
  const limit = options.limitBytes ?? MINIAPP_UPLOAD_TOTAL_SIZE_LIMIT_BYTES;
2878
2905
  const total = items.reduce((sum, item) => {