@heybox/hb-sdk 0.9.4-alpha.0 → 0.9.4-alpha.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.
Files changed (31) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +2 -0
  3. package/dist/cli-chunks/{runtime-gate-alLUP4_C.cjs → artifact-BTi9i7N4.cjs} +136 -65
  4. package/dist/cli-chunks/{build-BHfbvke-.cjs → build-CScc5bgz.cjs} +34 -83
  5. package/dist/cli-chunks/{create-B-KOcThY.cjs → create-BybyVKxB.cjs} +1 -1
  6. package/dist/cli-chunks/{deploy-lock-DY7E8TFw.cjs → deploy-lock-CtJXBtKK.cjs} +1 -1
  7. package/dist/cli-chunks/{dev-BC_oKKzT.cjs → dev-BVZ9yV84.cjs} +15469 -15357
  8. package/dist/cli-chunks/{context-DZldyzoT.cjs → dev-context-BjwOy-fF.cjs} +299 -299
  9. package/dist/cli-chunks/{doctor-l9Gd1Rhf.cjs → doctor-CTEun30u.cjs} +1 -1
  10. package/dist/cli-chunks/{games-DDoaQ_KF.cjs → games-Bp6gkkgb.cjs} +2 -2
  11. package/dist/cli-chunks/{index-Czupnh5A.cjs → index-CxelQqdy.cjs} +17 -17
  12. package/dist/cli-chunks/{index-COzyQErL.cjs → index-DF8KQKoa.cjs} +1 -1
  13. package/dist/cli-chunks/{index.esm-BX-KdUxn.cjs → index.esm-vr3yuZ2Q.cjs} +6 -6
  14. package/dist/cli-chunks/{login-Dy-um6Ka.cjs → login-BPyX2p9v.cjs} +1 -1
  15. package/dist/cli-chunks/{project-vite-CTWRejM4.cjs → project-vite-DBId94T0.cjs} +1 -1
  16. package/dist/cli-chunks/{remote-BKIgszJS.cjs → remote-C1n11VWk.cjs} +66 -144
  17. package/dist/cli-chunks/{runtime-permission-env-DFFgIfoX.cjs → runtime-permission-env-Beurz19O.cjs} +127 -128
  18. package/dist/cli-chunks/{skill-WQPin-5N.cjs → skill-C33zgdJF.cjs} +2 -2
  19. package/dist/cli-chunks/{version-BQVBVZPA.cjs → version-BKjLEHsb.cjs} +1 -1
  20. package/dist/cli.cjs +1 -1
  21. package/dist/devtools/browser-dev-host/assets/{browser-dev-host-j00ZN_C-.js → browser-dev-host-DedSMBMn.js} +15 -15
  22. package/dist/devtools/browser-dev-host/assets/{desktop-app-launch-BTmNqUZA.js → desktop-app-launch-BBIYbjgT.js} +1 -1
  23. package/dist/devtools/browser-dev-host/assets/{index-D3cBjlwQ.js → index-CnC7wDP_.js} +3 -3
  24. package/dist/devtools/browser-dev-host/index.html +2 -2
  25. package/dist/index.cjs.js +1 -1
  26. package/dist/index.esm.js +1 -1
  27. package/dist/vite.cjs.js +79 -13
  28. package/dist/vite.esm.js +79 -13
  29. package/package.json +6 -6
  30. package/skill/skill.json +4 -4
  31. package/types/vite/index.d.ts +35 -7
@@ -238,19 +238,19 @@ function requireArgument () {
238
238
 
239
239
  var command = {};
240
240
 
241
- 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-Czupnh5A.cjs', document.baseURI).href)));
241
+ 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-CxelQqdy.cjs', document.baseURI).href)));
242
242
  function __require$4() { return require$5("node:events"); }
243
243
 
244
- 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-Czupnh5A.cjs', document.baseURI).href)));
244
+ 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-CxelQqdy.cjs', document.baseURI).href)));
245
245
  function __require$3() { return require$4("node:child_process"); }
246
246
 
247
- 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-Czupnh5A.cjs', document.baseURI).href)));
247
+ 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-CxelQqdy.cjs', document.baseURI).href)));
248
248
  function __require$2() { return require$3("node:path"); }
249
249
 
250
- 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-Czupnh5A.cjs', document.baseURI).href)));
250
+ 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-CxelQqdy.cjs', document.baseURI).href)));
251
251
  function __require$1() { return require$2("node:fs"); }
252
252
 
253
- 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-Czupnh5A.cjs', document.baseURI).href)));
253
+ 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-CxelQqdy.cjs', document.baseURI).href)));
254
254
  function __require() { return require$1("node:process"); }
255
255
 
256
256
  var help = {};
@@ -17249,7 +17249,7 @@ async function inspectFeedbackLog(file, size) {
17249
17249
  return { mimeType: 'text/plain', width: 0, height: 0 };
17250
17250
  }
17251
17251
  async function createFeedbackCosClient(getToken) {
17252
- const { default: COS } = await Promise.resolve().then(function () { return require('./index-COzyQErL.cjs'); }).then(function (n) { return n.index; });
17252
+ const { default: COS } = await Promise.resolve().then(function () { return require('./index-DF8KQKoa.cjs'); }).then(function (n) { return n.index; });
17253
17253
  const cos = new COS({
17254
17254
  getAuthorization(_options, callback) {
17255
17255
  void getToken().then((token) => callback({
@@ -20900,7 +20900,7 @@ function readEnvNameArgFromArgv(argv) {
20900
20900
  }
20901
20901
 
20902
20902
  const CLI_VERSION_PLACEHOLDER = ['__HB', 'SDK', 'CLI', 'VERSION__'].join('_');
20903
- const BUILT_CLI_VERSION = '0.9.4-alpha.0';
20903
+ const BUILT_CLI_VERSION = '0.9.4-alpha.2';
20904
20904
  const PACKAGE_JSON_CANDIDATES = [
20905
20905
  path.resolve(__dirname, '..', '..', 'package.json'),
20906
20906
  path.resolve(__dirname, '..', 'package.json'),
@@ -21284,39 +21284,39 @@ function createCommandLoggerResolver(options) {
21284
21284
  };
21285
21285
  }
21286
21286
  const defaultClearLoginStatus = async (...args) => {
21287
- const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-Dy-um6Ka.cjs'); });
21287
+ const { clearLoginStatus } = await Promise.resolve().then(function () { return require('./login-BPyX2p9v.cjs'); });
21288
21288
  return clearLoginStatus(...args);
21289
21289
  };
21290
21290
  const defaultLoginToHeybox = async (...args) => {
21291
- const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-Dy-um6Ka.cjs'); });
21291
+ const { loginToHeybox } = await Promise.resolve().then(function () { return require('./login-BPyX2p9v.cjs'); });
21292
21292
  return loginToHeybox(...args);
21293
21293
  };
21294
21294
  const defaultPrintLoginStatus = async (...args) => {
21295
- const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-Dy-um6Ka.cjs'); });
21295
+ const { printLoginStatus } = await Promise.resolve().then(function () { return require('./login-BPyX2p9v.cjs'); });
21296
21296
  return printLoginStatus(...args);
21297
21297
  };
21298
21298
  const defaultRunBuildCommand = async (...args) => {
21299
- const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-BHfbvke-.cjs'); });
21299
+ const { runBuildCommand } = await Promise.resolve().then(function () { return require('./build-CScc5bgz.cjs'); });
21300
21300
  return runBuildCommand(...args);
21301
21301
  };
21302
21302
  const defaultRunCreateCommand = async (...args) => {
21303
- const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-B-KOcThY.cjs'); });
21303
+ const { runCreateCommand } = await Promise.resolve().then(function () { return require('./create-BybyVKxB.cjs'); });
21304
21304
  return runCreateCommand(...args);
21305
21305
  };
21306
21306
  const defaultRunDevCommand = async (...args) => {
21307
- const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-BC_oKKzT.cjs'); }).then(function (n) { return n.dev; });
21307
+ const { runDevCommand } = await Promise.resolve().then(function () { return require('./dev-BVZ9yV84.cjs'); }).then(function (n) { return n.dev; });
21308
21308
  return runDevCommand(...args);
21309
21309
  };
21310
21310
  const defaultRunDoctorCommand = async (...args) => {
21311
- const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-l9Gd1Rhf.cjs'); });
21311
+ const { runDoctorCommand } = await Promise.resolve().then(function () { return require('./doctor-CTEun30u.cjs'); });
21312
21312
  return runDoctorCommand(...args);
21313
21313
  };
21314
21314
  const defaultRunSkillInstallCommand = async (...args) => {
21315
- const { runSkillInstallCommand } = await Promise.resolve().then(function () { return require('./skill-WQPin-5N.cjs'); });
21315
+ const { runSkillInstallCommand } = await Promise.resolve().then(function () { return require('./skill-C33zgdJF.cjs'); });
21316
21316
  return runSkillInstallCommand(...args);
21317
21317
  };
21318
21318
  const defaultRunRemoteCommand = async (...args) => {
21319
- const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-BKIgszJS.cjs'); });
21319
+ const { runRemoteCommand } = await Promise.resolve().then(function () { return require('./remote-C1n11VWk.cjs'); });
21320
21320
  return runRemoteCommand(...args);
21321
21321
  };
21322
21322
  function resolveStandaloneLogger(options, verbose) {
@@ -21408,7 +21408,7 @@ function parseNonNegativeInteger(value) {
21408
21408
  return parsed;
21409
21409
  }
21410
21410
  const defaultRunGameSearchCommand = async (...args) => {
21411
- const { runGameSearchCommand } = await Promise.resolve().then(function () { return require('./games-DDoaQ_KF.cjs'); });
21411
+ const { runGameSearchCommand } = await Promise.resolve().then(function () { return require('./games-Bp6gkkgb.cjs'); });
21412
21412
  return runGameSearchCommand(...args);
21413
21413
  };
21414
21414
 
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index$2 = require('./index-Czupnh5A.cjs');
3
+ var index$2 = require('./index-CxelQqdy.cjs');
4
4
  var require$$0$3 = require('fs');
5
5
  var require$$0$2 = require('crypto');
6
6
  var require$$1$2 = require('path');
@@ -11,8 +11,8 @@ var require$$0$3 = require('url');
11
11
  var require$$5 = require('zlib');
12
12
  var require$$0 = require('buffer');
13
13
  var require$$1 = require('util');
14
- var index = require('./index-Czupnh5A.cjs');
15
- var dev = require('./dev-BC_oKKzT.cjs');
14
+ var index = require('./index-CxelQqdy.cjs');
15
+ var dev = require('./dev-BVZ9yV84.cjs');
16
16
  require('node:module');
17
17
  require('readline');
18
18
  require('os');
@@ -26,10 +26,10 @@ require('constants');
26
26
  require('node:fs');
27
27
  require('node:fs/promises');
28
28
  require('node:zlib');
29
- require('./context-DZldyzoT.cjs');
30
- require('./runtime-permission-env-DFFgIfoX.cjs');
31
- require('./version-BQVBVZPA.cjs');
29
+ require('./runtime-permission-env-Beurz19O.cjs');
30
+ require('./version-BKjLEHsb.cjs');
32
31
  require('node:async_hooks');
32
+ require('./dev-context-BjwOy-fF.cjs');
33
33
  require('sharp');
34
34
  require('node:os');
35
35
  require('node:net');
@@ -42,7 +42,7 @@ require('node:buffer');
42
42
  require('node:url');
43
43
  require('node:util');
44
44
  require('node:child_process');
45
- require('./project-vite-CTWRejM4.cjs');
45
+ require('./project-vite-DBId94T0.cjs');
46
46
 
47
47
  var bufferUtil = {exports: {}};
48
48
 
@@ -3,7 +3,7 @@
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 index = require('./index-Czupnh5A.cjs');
6
+ var index = require('./index-CxelQqdy.cjs');
7
7
  var browser = require('./browser-RAy8e8cV.cjs');
8
8
  require('node:module');
9
9
  require('readline');
@@ -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-Czupnh5A.cjs');
8
+ var index = require('./index-CxelQqdy.cjs');
9
9
 
10
10
  function findProjectRoot(startDir) {
11
11
  let current = path.resolve(startDir);
@@ -1,18 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var runtimePermissionEnv = require('./runtime-permission-env-DFFgIfoX.cjs');
4
- var context = require('./context-DZldyzoT.cjs');
3
+ var runtimePermissionEnv = require('./runtime-permission-env-Beurz19O.cjs');
4
+ var devContext = require('./dev-context-BjwOy-fF.cjs');
5
5
  var promises = require('node:readline/promises');
6
- var index = require('./index-Czupnh5A.cjs');
7
- var runtimeGate = require('./runtime-gate-alLUP4_C.cjs');
6
+ var index = require('./index-CxelQqdy.cjs');
8
7
  var childProcess = require('node:child_process');
9
8
  var fs = require('node:fs');
10
9
  var fs$1 = require('node:fs/promises');
11
10
  var path = require('node:path');
12
11
  var node_crypto = require('node:crypto');
13
12
  require('node:zlib');
14
- var deployLock = require('./deploy-lock-DY7E8TFw.cjs');
15
- require('./version-BQVBVZPA.cjs');
13
+ var artifact = require('./artifact-BTi9i7N4.cjs');
14
+ var deployLock = require('./deploy-lock-CtJXBtKK.cjs');
15
+ require('./version-BKjLEHsb.cjs');
16
16
  require('node:async_hooks');
17
17
  require('sharp');
18
18
  require('node:module');
@@ -308,7 +308,7 @@ function createDefaultCosClient(uploadToken, COS) {
308
308
  };
309
309
  }
310
310
  async function loadCosConstructor() {
311
- const cosModule = await Promise.resolve().then(function () { return require('./index-COzyQErL.cjs'); }).then(function (n) { return n.index; });
311
+ const cosModule = await Promise.resolve().then(function () { return require('./index-DF8KQKoa.cjs'); }).then(function (n) { return n.index; });
312
312
  return cosModule.default;
313
313
  }
314
314
  function formatSize(bytes) {
@@ -444,7 +444,7 @@ async function runDeployCommand(options, runtime = {}) {
444
444
  {
445
445
  const configuredProfile = runtimePermissionEnv.parseMiniappBasicInfo(packageJson.heybox ?? {}, '0.8.1');
446
446
  if (!configuredProfile) {
447
- const bound = await (runtime.getBoundMiniProgram ?? context.getBoundMiniProgram)({
447
+ const bound = await (runtime.getBoundMiniProgram ?? devContext.getBoundMiniProgram)({
448
448
  allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
449
449
  apiBaseUrl,
450
450
  cwd: projectRoot,
@@ -453,7 +453,7 @@ async function runDeployCommand(options, runtime = {}) {
453
453
  loginBaseUrl,
454
454
  session,
455
455
  });
456
- await context.migrateBasicInfo(projectRoot, bound.detail, miniProgramId, runtime.fetchImpl);
456
+ await devContext.migrateBasicInfo(projectRoot, bound.detail, miniProgramId, runtime.fetchImpl);
457
457
  }
458
458
  const localPermissions = runtimePermissionEnv.readMiniappPermissionsFromPackageJson(projectRoot, runtimePermissionEnv.resolveMiniappSdkVersion());
459
459
  if (typeof packageJson.scripts?.build !== 'string') {
@@ -469,7 +469,7 @@ async function runDeployCommand(options, runtime = {}) {
469
469
  }, runtime, apiBaseUrl, projectRoot, logger);
470
470
  let skipPlatformCsp = false;
471
471
  try {
472
- const { detail } = await logger.task('正在读取远端小程序权限', () => (runtime.getBoundMiniProgram ?? context.getBoundMiniProgram)({
472
+ const { detail } = await logger.task('正在读取远端小程序权限', () => (runtime.getBoundMiniProgram ?? devContext.getBoundMiniProgram)({
473
473
  allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
474
474
  apiBaseUrl,
475
475
  cwd: projectRoot,
@@ -479,7 +479,7 @@ async function runDeployCommand(options, runtime = {}) {
479
479
  session,
480
480
  }), { successText: '已读取远端小程序权限' });
481
481
  const effectivePermissions = runtimePermissionEnv.composeMiniappRuntimePermissions(localPermissions, detail.runtime_permissions, detail.party_type).runtimePermissions;
482
- skipPlatformCsp = context.shouldSkipMiniappPlatformCsp(effectivePermissions);
482
+ skipPlatformCsp = devContext.shouldSkipMiniappPlatformCsp(effectivePermissions);
483
483
  const permissionWarning = getUnapprovedPermissionWarning(localPermissions, detail.runtime_permissions, detail.party_type);
484
484
  if (permissionWarning)
485
485
  logger.warn(permissionWarning);
@@ -509,26 +509,25 @@ async function runDeployCommand(options, runtime = {}) {
509
509
  let preflightToken = '';
510
510
  {
511
511
  const distDir = path.join(projectRoot, 'dist');
512
- const parsedManifest = await readDeployManifest(projectRoot, logger);
513
- ({ manifest, version } = parsedManifest);
512
+ const artifact$1 = await artifact.inspectVersionArtifact({
513
+ projectRoot,
514
+ declarations: {
515
+ platforms: declaredPlatforms,
516
+ window: declaredWindow,
517
+ bindAppIds: declaredBindAppIds,
518
+ category: declaredCategory,
519
+ },
520
+ });
521
+ if (artifact$1.hadBom)
522
+ logger.warn('dist/manifest.json 包含 BOM,已自动剥离');
523
+ manifest = artifact$1.manifest;
524
+ version = artifact$1.summary.version;
514
525
  for (const warning of getMiniappMetadataWarnings(manifest)) {
515
526
  logger.warn(`[${warning.code}] ${warning.message}`, { stream: 'stderr' });
516
527
  }
517
- if (manifest.category !== declaredCategory) {
518
- throw new Error('dist/manifest.json.category 与 package.json#heybox.category 不一致,请重新 build 后再 deploy');
519
- }
520
- if (!declaredPlatforms || !runtimePermissionEnv.areMiniappPlatformsEqual(parsedManifest.platforms, declaredPlatforms)) {
521
- throw new Error('dist/manifest.json.platforms 与 package.json#heybox.platforms 不一致,请重新 build 后再 deploy');
522
- }
523
- if (!runtimePermissionEnv.areMiniappWindowsEqual(parsedManifest.window, declaredWindow)) {
524
- throw new Error('dist/manifest.json.window 与 package.json#heybox.window 不一致,请重新 build 后再 deploy');
525
- }
526
528
  if (version !== precheckVersion) {
527
529
  throw new Error(`dist/manifest.json.version (${version}) 与预检版本 (${precheckVersion}) 不一致,请重新 build 后再 deploy`);
528
530
  }
529
- if (declaredBindAppIds && !areStringArraysEqual(parsedManifest.bindAppIds, declaredBindAppIds)) {
530
- throw new Error('dist/manifest.json.bindAppIds 与 package.json#heybox.bindAppIds 不一致,请重新 build 后再 deploy');
531
- }
532
531
  await runVersionPrecheck({
533
532
  session,
534
533
  miniProgramId,
@@ -538,20 +537,12 @@ async function runDeployCommand(options, runtime = {}) {
538
537
  autoPublish,
539
538
  }, runtime, apiBaseUrl, projectRoot, logger);
540
539
  const uploadFiles = await logger.task('正在校验 dist 上传文件', async () => {
541
- const allFiles = await walkDistFiles(distDir);
542
- const blocked = allFiles.find((entry) => runtimePermissionEnv.relativePathContainsNodeModulesSegment(entry.relativePath));
543
- if (blocked) {
544
- throw new Error(`dist 目录含 node_modules:${blocked.relativePath}`);
545
- }
546
- const files = runtimePermissionEnv.prepareMiniappArtifactFiles(allFiles.filter((entry) => runtimePermissionEnv.shouldUploadDistFile(entry.relativePath)));
540
+ const inventory = await artifact.inspectVersionArtifactFiles(distDir);
541
+ const files = inventory.files.map((file) => ({ ...file, mimeType: inferMimeType(file.relativePath) }));
547
542
  const pathError = runtimePermissionEnv.validateMiniappUploadPathLengths(files, { miniProgramId });
548
543
  if (pathError) {
549
544
  throw new Error(pathError);
550
545
  }
551
- const sizeError = runtimePermissionEnv.validateMiniappUploadSizeBudgets(files);
552
- if (sizeError) {
553
- throw new Error(sizeError);
554
- }
555
546
  logger.debug(`待上传文件数: ${files.length}`);
556
547
  return files;
557
548
  }, { successText: 'dist 上传文件校验完成' });
@@ -567,8 +558,8 @@ async function runDeployCommand(options, runtime = {}) {
567
558
  const sources = [localProfile.icon, ...localProfile.coverImages];
568
559
  const refs = [{ path: profile.icon, kind: 'icon' }, ...profile.coverImages.map((path) => ({ path, kind: 'cover' }))];
569
560
  for (const [index, ref] of refs.entries()) {
570
- const image = await context.readBasicInfoSource(distDir, ref.path, ref.kind);
571
- const source = await context.readBasicInfoSource(projectRoot, sources[index], ref.kind);
561
+ const image = await devContext.readBasicInfoSource(distDir, ref.path, ref.kind);
562
+ const source = await devContext.readBasicInfoSource(projectRoot, sources[index], ref.kind);
572
563
  if (source.sha256 !== image.sha256)
573
564
  throw new Error('构建图片与项目声明不一致,请重新构建');
574
565
  if (image.sha256 === BASIC_INFO_PLACEHOLDER_SHA256)
@@ -622,12 +613,16 @@ async function runDeployCommand(options, runtime = {}) {
622
613
  const uploadBytes = createdUploadSession.missingFiles.reduce((sum, { file }) => sum + file.size, 0);
623
614
  logger.info(`Companion Blob 复用: ${createdUploadSession.reusedCompanionFiles.length} 个,免上传 ${formatDeployBytes(reusedBytes)};实际待上传 ${formatDeployBytes(uploadBytes)}`);
624
615
  try {
625
- const missingKeys = new Set(createdUploadSession.missingFiles.map(item => item.key));
626
- const uploadedCompanions = createdUploadSession.files.filter(item => item.file.relativePath.startsWith('companions/') && !missingKeys.has(item.key));
616
+ const missingKeys = new Set(createdUploadSession.missingFiles.map((item) => item.key));
617
+ const uploadedCompanions = createdUploadSession.files.filter((item) => item.file.relativePath.startsWith('companions/') && !missingKeys.has(item.key));
627
618
  for (let index = 0; index < uploadedCompanions.length; index += runtimePermissionEnv.MINIAPP_UPLOAD_BATCH_SIZE) {
628
619
  await (runtime.recordUserMiniprogramUploadResult ?? recordUserMiniprogramUploadResult)({
629
- session, miniProgramId, version, sessionId: uploadSessionId,
630
- files: uploadedCompanions.slice(index, index + runtimePermissionEnv.MINIAPP_UPLOAD_BATCH_SIZE)
620
+ session,
621
+ miniProgramId,
622
+ version,
623
+ sessionId: uploadSessionId,
624
+ files: uploadedCompanions
625
+ .slice(index, index + runtimePermissionEnv.MINIAPP_UPLOAD_BATCH_SIZE)
631
626
  .map(({ file }) => ({ path: file.relativePath, size: file.size, sha256: file.sha256 })),
632
627
  }, { baseUrl: apiBaseUrl, fetchImpl: runtime.fetchImpl });
633
628
  }
@@ -715,46 +710,6 @@ function findProjectRoot(startDir) {
715
710
  async function readPackageJson(projectRoot) {
716
711
  return JSON.parse(await fs$1.readFile(path.join(projectRoot, 'package.json'), 'utf8'));
717
712
  }
718
- function areStringArraysEqual(left, right) {
719
- return left.length === right.length && left.every((value, index) => value === right[index]);
720
- }
721
- async function readDeployManifest(projectRoot, logger) {
722
- const distDir = path.join(projectRoot, 'dist');
723
- const manifestPath = path.join(distDir, 'manifest.json');
724
- const entryHtmlPath = path.join(distDir, 'index.html');
725
- if (!fs.existsSync(manifestPath)) {
726
- throw new Error('未找到 dist/manifest.json,可能需要先跑 build 或检查 vite miniappManifest 插件');
727
- }
728
- if (!fs.existsSync(entryHtmlPath)) {
729
- throw new Error('未找到 dist/index.html,dist 目录残缺,请重新 build');
730
- }
731
- const entryHtml = await fs$1.readFile(entryHtmlPath, 'utf8');
732
- if (!runtimeGate.hasMiniappRuntimeGate(entryHtml)) {
733
- throw new Error('dist/index.html 缺少平台 Runtime 启动门禁,请在 Vite 配置中启用 miniappManifest() 后重新 build');
734
- }
735
- const { manifest, hadBom } = runtimePermissionEnv.parseMiniappManifestJson(await fs$1.readFile(manifestPath, 'utf8'), 'dist/manifest.json');
736
- if (hadBom) {
737
- logger.warn('dist/manifest.json 包含 BOM,已自动剥离');
738
- }
739
- const validated = runtimePermissionEnv.validateMiniappManifestForDeploy(manifest);
740
- if (validated.workspaceCards) {
741
- runtimeGate.verifyWorkspaceCardsSnapshot({ ...validated, bindAppIds: validated.bindAppIds ?? [], workspaceCards: validated.workspaceCards });
742
- runtimeGate.verifyWorkspaceCardArtifacts(distDir, validated.workspaceCards);
743
- }
744
- const bindAppIds = validated.bindAppIds ?? [];
745
- return {
746
- manifest: {
747
- ...manifest,
748
- platforms: validated.platforms,
749
- ...(bindAppIds.length === 0 ? {} : { bindAppIds }),
750
- },
751
- bindAppIds,
752
- sdkVersion: validated.sdkVersion,
753
- version: validated.version,
754
- platforms: validated.platforms,
755
- ...(validated.window === undefined ? {} : { window: validated.window }),
756
- };
757
- }
758
713
  function validateVersionForDeploy(version, sourceLabel) {
759
714
  if (typeof version !== 'string' || !runtimePermissionEnv.isValidMiniappManifestVersion(version)) {
760
715
  throw new Error(`${sourceLabel} 必须是合法 SemVer,允许 prerelease,不允许 build metadata 和 0.0.0:${String(version)}`);
@@ -868,41 +823,12 @@ function createBuildArgs(pm, mode, buildScript) {
868
823
  const modeOption = /\bhb-sdk\s+build\b/.test(buildScript) ? '--env' : '--mode';
869
824
  return ['run', 'build', ...(mode ? [...(pm === 'npm' ? ['--'] : []), modeOption, mode] : [])];
870
825
  }
871
- async function walkDistFiles(distDir) {
872
- const results = [];
873
- await walk(distDir, '');
874
- return results;
875
- async function walk(absDir, relDir) {
876
- const entries = await fs$1.readdir(absDir, { withFileTypes: true });
877
- for (const entry of entries) {
878
- const absPath = path.join(absDir, entry.name);
879
- const relPath = relDir ? `${relDir}/${entry.name}` : entry.name;
880
- const link = await fs$1.lstat(absPath);
881
- if (link.isSymbolicLink()) {
882
- throw new Error(`dist 目录包含 symlink,拒绝处理:${relPath}`);
883
- }
884
- if (entry.isDirectory()) {
885
- await walk(absPath, relPath);
886
- continue;
887
- }
888
- if (!entry.isFile()) {
889
- continue;
890
- }
891
- const fileStat = await fs$1.stat(absPath);
892
- results.push({
893
- relativePath: relPath,
894
- absolutePath: absPath,
895
- size: fileStat.size,
896
- mimeType: inferMimeType(entry.name),
897
- });
898
- }
899
- }
900
- }
901
826
  function inferMimeType(fileName) {
902
827
  return MIME_BY_EXT[path.extname(fileName).toLowerCase()] || 'application/octet-stream';
903
828
  }
904
829
  async function assertDeployUploadFilesStillMatchSignature(options) {
905
- const currentFiles = runtimePermissionEnv.prepareMiniappArtifactFiles((await walkDistFiles(options.distDir)).filter((entry) => runtimePermissionEnv.shouldUploadDistFile(entry.relativePath)));
830
+ const inventory = await artifact.inspectVersionArtifactFiles(options.distDir);
831
+ const currentFiles = inventory.files.map((file) => ({ ...file, mimeType: inferMimeType(file.relativePath) }));
906
832
  const currentByPath = new Map(currentFiles.map((file) => [file.relativePath, file]));
907
833
  if (currentFiles.length !== options.expectedFiles.length) {
908
834
  throw new Error('dist 构建产物在签名后发生变化,请重新执行 deploy');
@@ -917,10 +843,6 @@ async function assertDeployUploadFilesStillMatchSignature(options) {
917
843
  if (pathError) {
918
844
  throw new Error(pathError);
919
845
  }
920
- const sizeError = runtimePermissionEnv.validateMiniappUploadSizeBudgets(currentFiles);
921
- if (sizeError) {
922
- throw new Error(sizeError);
923
- }
924
846
  const currentReceipt = await options.computeMiniappArtifactReceipt(currentFiles);
925
847
  if (currentReceipt.artifactSignature !== options.expectedSignature) {
926
848
  throw new Error('dist 构建产物在签名后发生变化,请重新 build 后再 deploy');
@@ -1062,7 +984,7 @@ async function runRemoteDeployCommand(options, runtime) {
1062
984
  async function createRemoteCommandContext(options, runtime) {
1063
985
  index.applyMiniProgramServiceTagIfNeeded(options.serviceTag);
1064
986
  const logger = resolveRemoteLogger(options, runtime);
1065
- const environment = await context.resolveRemoteEnvironment({
987
+ const environment = await devContext.resolveRemoteEnvironment({
1066
988
  allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
1067
989
  apiBaseUrl: options.apiBaseUrl,
1068
990
  env: options.env,
@@ -1072,10 +994,10 @@ async function createRemoteCommandContext(options, runtime) {
1072
994
  fetchImpl: runtime.fetchImpl,
1073
995
  requireAuthSession: runtime.requireAuthSession,
1074
996
  });
1075
- const packageJson = await context.readMiniProgramProjectPackage(runtime.cwd ?? process.cwd());
1076
- const binding = context.readBoundMiniProgramIdFromPackageJson(packageJson.packageJson);
997
+ const packageJson = await devContext.readMiniProgramProjectPackage(runtime.cwd ?? process.cwd());
998
+ const binding = devContext.readBoundMiniProgramIdFromPackageJson(packageJson.packageJson);
1077
999
  const api = {
1078
- ...adaptRemoteApiClient(context.createRemoteApiClientForEnvironment(environment)),
1000
+ ...adaptRemoteApiClient(devContext.createRemoteApiClientForEnvironment(environment)),
1079
1001
  ...runtime.api,
1080
1002
  };
1081
1003
  logger.debug(`Heybox API: ${environment.apiBaseUrl}`);
@@ -1221,48 +1143,48 @@ async function remoteList(options, context, runtime) {
1221
1143
  }
1222
1144
  return finishRemoteCommand(options, runtime, output);
1223
1145
  }
1224
- async function remoteCreate(options, context$1, runtime) {
1225
- if (context$1.binding && !options.forceBind) {
1226
- throw new Error(`当前项目已绑定 ${context$1.binding};如需覆盖,请使用 --force-bind`);
1146
+ async function remoteCreate(options, context, runtime) {
1147
+ if (context.binding && !options.forceBind) {
1148
+ throw new Error(`当前项目已绑定 ${context.binding};如需覆盖,请使用 --force-bind`);
1227
1149
  }
1228
- const access = await context$1.api.accessStatus();
1150
+ const access = await context.api.accessStatus();
1229
1151
  if (access.status !== 'approved') {
1230
1152
  throw new Error(`当前 CLI 用户没有创建工坊小程序权限:${String(access.status ?? 'unknown')}`);
1231
1153
  }
1232
- await confirmCreateWithCurrentEntity(options, context$1, runtime);
1233
- runtimePermissionEnv.parseMiniappBasicInfo(context$1.packageJson.packageJson.heybox ?? {});
1234
- const result = await context$1.api.createMiniProgram();
1154
+ await confirmCreateWithCurrentEntity(options, context, runtime);
1155
+ runtimePermissionEnv.parseMiniappBasicInfo(context.packageJson.packageJson.heybox ?? {});
1156
+ const result = await context.api.createMiniProgram();
1235
1157
  const miniProgramId = requireMiniProgramId(result);
1236
- await context.writeBoundMiniProgramId(context$1.packageJson.projectRoot, miniProgramId, { force: options.forceBind });
1158
+ await devContext.writeBoundMiniProgramId(context.packageJson.projectRoot, miniProgramId, { force: options.forceBind });
1237
1159
  const output = { changed: true, miniProgramId, remote: toCamelCaseDeep(result) };
1238
1160
  if (!options.json) {
1239
- context$1.logger.success(`创建并绑定成功:${miniProgramId}`);
1161
+ context.logger.success(`创建并绑定成功:${miniProgramId}`);
1240
1162
  }
1241
1163
  return finishRemoteCommand(options, runtime, output);
1242
1164
  }
1243
- async function remoteBind(options, context$1, runtime) {
1165
+ async function remoteBind(options, context, runtime) {
1244
1166
  const miniProgramId = requireNonEmpty(options.miniProgramId, 'remote bind 必须传 <mini-program-id>');
1245
- if (context$1.binding && context$1.binding !== miniProgramId && !options.force) {
1246
- throw new Error(`当前项目已绑定 ${context$1.binding};如需覆盖本地绑定,请使用 --force`);
1167
+ if (context.binding && context.binding !== miniProgramId && !options.force) {
1168
+ throw new Error(`当前项目已绑定 ${context.binding};如需覆盖本地绑定,请使用 --force`);
1247
1169
  }
1248
- const detail = await context$1.api.getMiniProgramDetail(miniProgramId);
1170
+ const detail = await context.api.getMiniProgramDetail(miniProgramId);
1249
1171
  const verifiedId = requireMiniProgramId(detail);
1250
1172
  if (verifiedId !== miniProgramId)
1251
1173
  throw new Error('远端返回的小程序 ID 与绑定目标不一致');
1252
- await assertMiniProgramEntityMatchesCurrent(context$1, detail);
1253
- const { changed } = await context.migrateBasicInfo(context$1.packageJson.projectRoot, detail, verifiedId, runtime.fetchImpl, options.force);
1174
+ await assertMiniProgramEntityMatchesCurrent(context, detail);
1175
+ const { changed } = await devContext.migrateBasicInfo(context.packageJson.projectRoot, detail, verifiedId, runtime.fetchImpl, options.force);
1254
1176
  const output = { changed, miniProgramId: verifiedId, remote: toCamelCaseDeep(detail) };
1255
1177
  if (!options.json) {
1256
- context$1.logger.success(changed ? `绑定成功:${verifiedId}` : `已绑定:${verifiedId}`);
1178
+ context.logger.success(changed ? `绑定成功:${verifiedId}` : `已绑定:${verifiedId}`);
1257
1179
  }
1258
1180
  return finishRemoteCommand(options, runtime, output);
1259
1181
  }
1260
- async function remoteInfo(options, context$1, runtime) {
1261
- const miniProgramId = requireBinding(context$1);
1262
- const detail = await context$1.api.getMiniProgramDetail(miniProgramId);
1263
- const localPermissions = runtimePermissionEnv.readMiniappPermissionsFromPackageJson(context$1.packageJson.projectRoot, runtimePermissionEnv.resolveMiniappSdkVersion());
1182
+ async function remoteInfo(options, context, runtime) {
1183
+ const miniProgramId = requireBinding(context);
1184
+ const detail = await context.api.getMiniProgramDetail(miniProgramId);
1185
+ const localPermissions = runtimePermissionEnv.readMiniappPermissionsFromPackageJson(context.packageJson.projectRoot, runtimePermissionEnv.resolveMiniappSdkVersion());
1264
1186
  const permissionViews = runtimePermissionEnv.composeMiniappRuntimePermissions(localPermissions, detail.runtime_permissions, detail.party_type).views;
1265
- const localBindAppIds = runtimePermissionEnv.readMiniappBindAppIdsFromPackageJson(context$1.packageJson.projectRoot);
1187
+ const localBindAppIds = runtimePermissionEnv.readMiniappBindAppIdsFromPackageJson(context.packageJson.projectRoot);
1266
1188
  const currentBindApps = normalizeRemoteBoundApps(detail.bind_apps);
1267
1189
  const currentByID = new Map(currentBindApps.map((item) => [item.appid, item]));
1268
1190
  const local = localBindAppIds.map((appid) => currentByID.get(appid) ?? { appid });
@@ -1271,12 +1193,12 @@ async function remoteInfo(options, context$1, runtime) {
1271
1193
  const localIDs = new Set(localBindAppIds);
1272
1194
  const removed = currentBindApps.filter((item) => !localIDs.has(item.appid));
1273
1195
  const bindings = { local, current: currentBindApps, added, removed };
1274
- const basicInfo = await context.compareBasicInfo(context$1.packageJson.projectRoot, detail, runtime.fetchImpl);
1196
+ const basicInfo = await devContext.compareBasicInfo(context.packageJson.projectRoot, detail, runtime.fetchImpl);
1275
1197
  const output = { changed: false, miniProgramId, detail: toCamelCaseDeep(detail), permissions: permissionViews, permissionSources: { localDeclaration: localPermissions.permissions ?? null, onlineManifest: detail.manifest ?? null, onlineRuntimeSnapshot: detail.effective_runtime_permissions ?? null, platformApprovals: detail.runtime_permissions ?? null }, bindings, basicInfo };
1276
1198
  if (!options.json)
1277
- context$1.logger.info(`版本资料:${basicInfo.status}`);
1199
+ context.logger.info(`版本资料:${basicInfo.status}`);
1278
1200
  if (!options.json) {
1279
- printMiniProgramDetail(context$1.logger, detail, permissionViews, bindings);
1201
+ printMiniProgramDetail(context.logger, detail, permissionViews, bindings);
1280
1202
  }
1281
1203
  return finishRemoteCommand(options, runtime, output);
1282
1204
  }