@heybox/hb-sdk 0.9.8-alpha.3 → 0.9.8-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -2
- package/dist/cli-chunks/{build-wK5IcYmp.cjs → build-DU2VspYv.cjs} +16 -17
- package/dist/cli-chunks/{create-D1DAg4er.cjs → create-BhlbyaKS.cjs} +1 -1
- package/dist/cli-chunks/{dev-zh_Wb9WZ.cjs → dev-Cqp-4QEC.cjs} +378 -187
- package/dist/cli-chunks/{doctor-Br31MP94.cjs → doctor-CKGquwH_.cjs} +1 -1
- package/dist/cli-chunks/{games-B5bUkOCp.cjs → games-DjgM539u.cjs} +1 -1
- package/dist/cli-chunks/{index-CkPh8IQn.cjs → index-DoIKelYn.cjs} +1 -1
- package/dist/cli-chunks/{index-B8tKOZ1w.cjs → index-J_BdY_ve.cjs} +17 -17
- package/dist/cli-chunks/{index.esm-DOvuMPDE.cjs → index.esm-Hlcp1Yj-.cjs} +13 -11
- package/dist/cli-chunks/{login-BGxsC07i.cjs → login-BCv_ddZa.cjs} +1 -1
- package/dist/cli-chunks/{project-vite-DU7Wp4o5.cjs → project-vite-zaoVjKWe.cjs} +1 -1
- package/dist/cli-chunks/{remote-HX0wMZ6W.cjs → remote-Dr-fODD4.cjs} +733 -66
- package/dist/cli-chunks/{artifact-C4JTa7D5.cjs → runtime-permission-env-BES2h0Jz.cjs} +9878 -12
- package/dist/cli-chunks/{skill-B6KtNum4.cjs → skill-BjDyiR9s.cjs} +2 -2
- package/dist/cli-chunks/{version-DIhLu9jy.cjs → version-_QrqDwtA.cjs} +1 -1
- package/dist/cli.cjs +1 -1
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-BV3_FaGx.js +221 -0
- package/dist/devtools/browser-dev-host/assets/desktop-app-launch-Dil_RZ3q.js +13 -0
- package/dist/devtools/browser-dev-host/assets/index-Bk5RxHO3.css +1 -0
- package/dist/devtools/browser-dev-host/assets/index-GgAcIKHe.js +567 -0
- package/dist/devtools/browser-dev-host/index.html +3 -3
- package/dist/index.cjs.js +3 -3
- package/dist/index.esm.js +3 -3
- package/dist/vite.cjs.js +46 -38
- package/dist/vite.esm.js +46 -38
- package/package.json +4 -4
- package/skill/skill.json +4 -4
- package/types/index.d.ts +2 -2
- package/types/vite/index.d.ts +2 -2
- package/dist/cli-chunks/dev-context-4ZGqANND.cjs +0 -669
- package/dist/cli-chunks/runtime-permission-env-CAnNV2Lw.cjs +0 -9884
- package/dist/devtools/browser-dev-host/assets/browser-dev-host-5lgAW5KL.js +0 -228
- package/dist/devtools/browser-dev-host/assets/desktop-app-launch-B4cpTP3G.js +0 -6
- package/dist/devtools/browser-dev-host/assets/index-DxL85blk.js +0 -567
- package/dist/devtools/browser-dev-host/assets/index-ophYZqpX.css +0 -1
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var index_esm = require('./index.esm-CvMA_ppV.cjs');
|
|
4
|
-
var runtimePermissionEnv = require('./runtime-permission-env-
|
|
5
|
-
var
|
|
4
|
+
var runtimePermissionEnv = require('./runtime-permission-env-BES2h0Jz.cjs');
|
|
5
|
+
var node_crypto = require('node:crypto');
|
|
6
|
+
var fs = require('node:fs/promises');
|
|
7
|
+
var path = require('node:path');
|
|
8
|
+
var fs$1 = require('node:fs');
|
|
9
|
+
var sharp = require('sharp');
|
|
6
10
|
var promises = require('node:readline/promises');
|
|
7
|
-
var index = require('./index-
|
|
11
|
+
var index = require('./index-J_BdY_ve.cjs');
|
|
8
12
|
var childProcess = require('node:child_process');
|
|
9
|
-
var fs = require('node:fs');
|
|
10
|
-
var fs$1 = require('node:fs/promises');
|
|
11
|
-
var path = require('node:path');
|
|
12
|
-
var node_crypto = require('node:crypto');
|
|
13
13
|
require('node:zlib');
|
|
14
|
-
var artifact = require('./artifact-C4JTa7D5.cjs');
|
|
15
|
-
require('./version-DIhLu9jy.cjs');
|
|
16
|
-
require('node:async_hooks');
|
|
17
|
-
require('sharp');
|
|
18
|
-
require('node:module');
|
|
19
|
-
require('readline');
|
|
20
|
-
require('os');
|
|
21
|
-
require('tty');
|
|
22
|
-
require('assert');
|
|
23
|
-
require('events');
|
|
24
|
-
require('stream');
|
|
25
|
-
require('buffer');
|
|
26
|
-
require('util');
|
|
27
|
-
require('path');
|
|
28
|
-
require('fs');
|
|
29
|
-
require('constants');
|
|
30
|
-
require('node:util');
|
|
31
|
-
require('node:timers/promises');
|
|
32
|
-
require('node:url');
|
|
33
|
-
require('./_commonjs-dynamic-modules-DUamuDzp.cjs');
|
|
34
|
-
require('inspector');
|
|
35
14
|
|
|
36
15
|
// 脚手架开发占位图;构建可用,提审前必须替换。
|
|
37
16
|
const BASIC_INFO_PLACEHOLDER_SHA256 = 'd14e54b30f5e6d1bcbf51267bc82b06a0af7c333f2945bcc16b4e1adc3b123dd';
|
|
@@ -57,6 +36,321 @@ function getMiniappMetadataWarnings(metadata) {
|
|
|
57
36
|
return warnings;
|
|
58
37
|
}
|
|
59
38
|
|
|
39
|
+
async function inspectBasicInfoImage(bytes, sourcePath, kind) {
|
|
40
|
+
const inspected = await inspectDecodedBasicInfoImage(bytes, kind);
|
|
41
|
+
const extensions = { jpg: ['jpg', 'jpeg'], png: ['png'], gif: ['gif'], webp: ['webp'] };
|
|
42
|
+
const ext = sourcePath.split('.').pop().toLowerCase();
|
|
43
|
+
if (!extensions[inspected.extension]?.includes(ext))
|
|
44
|
+
throw new Error('资料图片格式与扩展名不一致');
|
|
45
|
+
return inspected;
|
|
46
|
+
}
|
|
47
|
+
async function inspectRemoteBasicInfoImage(bytes, kind) {
|
|
48
|
+
return inspectDecodedBasicInfoImage(bytes, kind);
|
|
49
|
+
}
|
|
50
|
+
async function inspectDecodedBasicInfoImage(bytes, kind) {
|
|
51
|
+
if (!bytes.length || bytes.length > runtimePermissionEnv.BASIC_INFO_MAX_BYTES)
|
|
52
|
+
throw new Error('资料图片不得为空或超过 10 MiB');
|
|
53
|
+
const decoder = sharp(bytes, { limitInputPixels: runtimePermissionEnv.BASIC_INFO_MAX_PIXELS, failOn: 'warning' });
|
|
54
|
+
const metadata = await decoder.metadata();
|
|
55
|
+
const extensions = { jpeg: 'jpg', png: 'png', gif: 'gif', webp: 'webp' };
|
|
56
|
+
if (!metadata.format || !extensions[metadata.format])
|
|
57
|
+
throw new Error('资料图片格式不支持');
|
|
58
|
+
const width = metadata.width ?? 0;
|
|
59
|
+
const height = metadata.pageHeight ?? metadata.height ?? 0;
|
|
60
|
+
if (!width || !height || width * height > runtimePermissionEnv.BASIC_INFO_MAX_PIXELS)
|
|
61
|
+
throw new Error('资料图片不得超过 4000 万像素');
|
|
62
|
+
if (kind === 'icon' && (width !== 200 || height !== 200))
|
|
63
|
+
throw new Error('icon 必须是 200×200');
|
|
64
|
+
// 强制解码而非只信任图片头;不将解码结果写回图片。
|
|
65
|
+
await decoder.stats();
|
|
66
|
+
return { sha256: node_crypto.createHash('sha256').update(bytes).digest('hex'), extension: extensions[metadata.format] };
|
|
67
|
+
}
|
|
68
|
+
async function readBasicInfoSource(projectRoot, relative, kind) {
|
|
69
|
+
runtimePermissionEnv.validateBasicInfoPath(relative);
|
|
70
|
+
const root = await fs.realpath(projectRoot);
|
|
71
|
+
const target = await fs.realpath(path.join(root, relative));
|
|
72
|
+
const resolvedRelative = path.relative(root, target).split(path.sep).join('/');
|
|
73
|
+
runtimePermissionEnv.validateBasicInfoPath(resolvedRelative);
|
|
74
|
+
if (resolvedRelative.startsWith('../') || path.isAbsolute(resolvedRelative))
|
|
75
|
+
throw new Error('资料图片不能逃逸项目目录');
|
|
76
|
+
const info = await fs.stat(target);
|
|
77
|
+
if (!info.isFile() || info.size > runtimePermissionEnv.BASIC_INFO_MAX_BYTES)
|
|
78
|
+
throw new Error('资料图片必须为不超过 10 MiB 的普通文件');
|
|
79
|
+
const file = await fs.open(target, fs$1.constants.O_RDONLY | fs$1.constants.O_NOFOLLOW);
|
|
80
|
+
try {
|
|
81
|
+
const actual = await file.stat();
|
|
82
|
+
if (!actual.isFile() || actual.size > runtimePermissionEnv.BASIC_INFO_MAX_BYTES)
|
|
83
|
+
throw new Error('资料图片文件已变化');
|
|
84
|
+
const bytes = await file.readFile();
|
|
85
|
+
return { bytes, ...(await inspectBasicInfoImage(bytes, relative, kind)) };
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
await file.close();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** 逐级校验真实目录,避免保留目录或迁移目录中的符号链接将写入带到项目外。 */
|
|
92
|
+
async function ensureBasicInfoDirectory(rootPath, relative) {
|
|
93
|
+
const root = await fs.realpath(rootPath);
|
|
94
|
+
let current = root;
|
|
95
|
+
for (const part of relative.split('/')) {
|
|
96
|
+
if (!part || part === '.' || part === '..')
|
|
97
|
+
throw new Error('资料目录不合法');
|
|
98
|
+
current = path.join(current, part);
|
|
99
|
+
await fs.mkdir(current).catch((error) => {
|
|
100
|
+
if (error.code !== 'EEXIST')
|
|
101
|
+
throw error;
|
|
102
|
+
});
|
|
103
|
+
const resolved = await fs.realpath(current);
|
|
104
|
+
const within = path.relative(root, resolved);
|
|
105
|
+
if (within.startsWith('..') || path.isAbsolute(within))
|
|
106
|
+
throw new Error('资料目录不能逃逸项目');
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
class MiniProgramProjectBindingError extends Error {
|
|
111
|
+
code;
|
|
112
|
+
constructor(message, code) {
|
|
113
|
+
super(message);
|
|
114
|
+
this.code = code;
|
|
115
|
+
this.name = 'MiniProgramProjectBindingError';
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function findMiniProgramProjectRoot(startDir) {
|
|
119
|
+
let current = path.resolve(startDir);
|
|
120
|
+
while (true) {
|
|
121
|
+
if (fs$1.existsSync(path.join(current, 'package.json'))) {
|
|
122
|
+
return current;
|
|
123
|
+
}
|
|
124
|
+
const parent = path.dirname(current);
|
|
125
|
+
if (parent === current) {
|
|
126
|
+
throw new MiniProgramProjectBindingError('当前目录或父目录未找到 package.json', 'PACKAGE_JSON_NOT_FOUND');
|
|
127
|
+
}
|
|
128
|
+
current = parent;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function readMiniProgramProjectPackage(startDir) {
|
|
132
|
+
const projectRoot = findMiniProgramProjectRoot(startDir);
|
|
133
|
+
const packageJsonPath = path.join(projectRoot, 'package.json');
|
|
134
|
+
const raw = await fs.readFile(packageJsonPath, 'utf8');
|
|
135
|
+
let packageJson;
|
|
136
|
+
try {
|
|
137
|
+
packageJson = JSON.parse(raw);
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
141
|
+
throw new MiniProgramProjectBindingError(`package.json 不是合法 JSON:${packageJsonPath}\n${message}`, 'PACKAGE_JSON_INVALID');
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
projectRoot,
|
|
145
|
+
packageJsonPath,
|
|
146
|
+
packageJson,
|
|
147
|
+
raw,
|
|
148
|
+
indent: detectJsonIndent(raw),
|
|
149
|
+
trailingNewline: raw.endsWith('\r\n') ? '\r\n' : raw.endsWith('\n') ? '\n' : '',
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function readBoundMiniProgramIdFromPackageJson(packageJson) {
|
|
153
|
+
const value = packageJson.heybox?.miniProgramId;
|
|
154
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
155
|
+
}
|
|
156
|
+
async function readBoundMiniProgramId(startDir) {
|
|
157
|
+
return readBoundMiniProgramIdFromPackageJson((await readMiniProgramProjectPackage(startDir)).packageJson);
|
|
158
|
+
}
|
|
159
|
+
async function requireBoundMiniProgramId(startDir) {
|
|
160
|
+
const context = await readMiniProgramProjectPackage(startDir);
|
|
161
|
+
const miniProgramId = readBoundMiniProgramIdFromPackageJson(context.packageJson);
|
|
162
|
+
if (!miniProgramId) {
|
|
163
|
+
throw new MiniProgramProjectBindingError(`当前项目未绑定小程序。请先运行 hb-sdk remote create 或 hb-sdk remote bind <mini-program-id>。\n配置位置:${context.packageJsonPath}#heybox.miniProgramId`, 'MINI_PROGRAM_UNBOUND');
|
|
164
|
+
}
|
|
165
|
+
return { ...context, miniProgramId };
|
|
166
|
+
}
|
|
167
|
+
async function writeBoundMiniProgramId(startDir, miniProgramId, options = {}) {
|
|
168
|
+
const context = await readMiniProgramProjectPackage(startDir);
|
|
169
|
+
const normalizedMiniProgramId = String(miniProgramId).trim();
|
|
170
|
+
if (!normalizedMiniProgramId) {
|
|
171
|
+
throw new MiniProgramProjectBindingError('miniProgramId 不能为空', 'PACKAGE_JSON_INVALID');
|
|
172
|
+
}
|
|
173
|
+
const currentMiniProgramId = readBoundMiniProgramIdFromPackageJson(context.packageJson);
|
|
174
|
+
if (currentMiniProgramId && currentMiniProgramId !== normalizedMiniProgramId && !options.force) {
|
|
175
|
+
throw new MiniProgramProjectBindingError(`当前项目已绑定小程序 ${currentMiniProgramId}。如需覆盖本地绑定,请使用 --force。`, 'MINI_PROGRAM_BINDING_EXISTS');
|
|
176
|
+
}
|
|
177
|
+
if (currentMiniProgramId === normalizedMiniProgramId) {
|
|
178
|
+
return {
|
|
179
|
+
...context,
|
|
180
|
+
changed: false,
|
|
181
|
+
miniProgramId: normalizedMiniProgramId,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
if (context.packageJson.heybox !== undefined && !isPlainObject(context.packageJson.heybox)) {
|
|
185
|
+
throw new MiniProgramProjectBindingError('package.json heybox 字段必须是对象,不能写入 miniProgramId', 'PACKAGE_JSON_HEYBOX_INVALID');
|
|
186
|
+
}
|
|
187
|
+
context.packageJson.heybox = {
|
|
188
|
+
...(context.packageJson.heybox ?? {}),
|
|
189
|
+
miniProgramId: normalizedMiniProgramId,
|
|
190
|
+
};
|
|
191
|
+
await fs.writeFile(context.packageJsonPath, `${JSON.stringify(context.packageJson, null, context.indent)}${context.trailingNewline || '\n'}`, 'utf8');
|
|
192
|
+
return {
|
|
193
|
+
...context,
|
|
194
|
+
changed: true,
|
|
195
|
+
miniProgramId: normalizedMiniProgramId,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function detectJsonIndent(raw) {
|
|
199
|
+
const match = raw.match(/\n(\s+)"[^"]+":/);
|
|
200
|
+
return match?.[1] ?? 2;
|
|
201
|
+
}
|
|
202
|
+
function isPlainObject(value) {
|
|
203
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function trustedProfileUrl(raw) {
|
|
207
|
+
const url = new URL(raw);
|
|
208
|
+
const trusted = ['max-c.com', 'xiaoheihe.cn', 'heybox.com'];
|
|
209
|
+
if (url.protocol !== 'https:' ||
|
|
210
|
+
url.username ||
|
|
211
|
+
url.password ||
|
|
212
|
+
(url.port && url.port !== '443') ||
|
|
213
|
+
!trusted.some((host) => url.hostname === host || url.hostname.endsWith(`.${host}`)))
|
|
214
|
+
throw new Error('线上资料图片 URL 不受信任');
|
|
215
|
+
return url;
|
|
216
|
+
}
|
|
217
|
+
async function downloadImage(raw, fetchImpl) {
|
|
218
|
+
const response = await fetchImpl(trustedProfileUrl(raw), { redirect: 'error', signal: AbortSignal.timeout(15_000) });
|
|
219
|
+
if (!response.ok || !response.body)
|
|
220
|
+
throw new Error('下载线上资料图片失败');
|
|
221
|
+
if (Number(response.headers.get('content-length')) > runtimePermissionEnv.BASIC_INFO_MAX_BYTES)
|
|
222
|
+
throw new Error('图片超过 10 MiB');
|
|
223
|
+
const chunks = [];
|
|
224
|
+
let size = 0;
|
|
225
|
+
const reader = response.body.getReader();
|
|
226
|
+
try {
|
|
227
|
+
for (;;) {
|
|
228
|
+
const part = await reader.read();
|
|
229
|
+
if (part.done)
|
|
230
|
+
break;
|
|
231
|
+
size += part.value.length;
|
|
232
|
+
if (size > runtimePermissionEnv.BASIC_INFO_MAX_BYTES)
|
|
233
|
+
throw new Error('图片超过 10 MiB');
|
|
234
|
+
chunks.push(part.value);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
await reader.cancel();
|
|
239
|
+
}
|
|
240
|
+
return Buffer.concat(chunks);
|
|
241
|
+
}
|
|
242
|
+
/** package-last 提交:失败只清理本次新增素材,原配置始终保留。 */
|
|
243
|
+
async function migrateBasicInfo(cwd, detail, miniProgramId, fetchImpl = fetch, force = false) {
|
|
244
|
+
const context = await readMiniProgramProjectPackage(cwd);
|
|
245
|
+
const heybox = context.packageJson.heybox ?? {};
|
|
246
|
+
const existing = heybox.miniProgramId;
|
|
247
|
+
if (existing && existing !== miniProgramId && !force)
|
|
248
|
+
throw new Error('当前项目已绑定其他小程序,请使用 --force');
|
|
249
|
+
const fields = ['name', 'icon', 'coverImages'];
|
|
250
|
+
const present = fields.filter((key) => Object.prototype.hasOwnProperty.call(heybox, key));
|
|
251
|
+
if (present.length && present.length !== 3)
|
|
252
|
+
throw new Error(`资料配置不完整,请补齐 ${fields.filter((key) => !present.includes(key)).join('、')}`);
|
|
253
|
+
const created = [];
|
|
254
|
+
const temp = `${context.packageJsonPath}.${node_crypto.randomUUID()}.tmp`;
|
|
255
|
+
try {
|
|
256
|
+
let profile = present.length ? runtimePermissionEnv.parseMiniappBasicInfo(heybox) : undefined;
|
|
257
|
+
if (profile) {
|
|
258
|
+
await readBasicInfoSource(context.projectRoot, profile.icon, 'icon');
|
|
259
|
+
for (const cover of profile.coverImages)
|
|
260
|
+
await readBasicInfoSource(context.projectRoot, cover, 'cover');
|
|
261
|
+
if (existing === miniProgramId)
|
|
262
|
+
return { changed: false, miniProgramId };
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
if (detail.mini_program_id !== miniProgramId)
|
|
266
|
+
throw new Error('远端小程序身份不一致');
|
|
267
|
+
const snapshot = detail.published_basic_info;
|
|
268
|
+
if (!snapshot?.version ||
|
|
269
|
+
!snapshot.icon_url ||
|
|
270
|
+
!Array.isArray(snapshot.cover_image_urls) ||
|
|
271
|
+
snapshot.cover_image_urls.length < 1 ||
|
|
272
|
+
snapshot.cover_image_urls.length > 5)
|
|
273
|
+
throw new Error('没有当前正式发布快照,请手工配置 heybox.name/icon/coverImages');
|
|
274
|
+
profile = { name: runtimePermissionEnv.normalizeBasicInfoName(snapshot.name), icon: '', coverImages: [] };
|
|
275
|
+
const entries = [
|
|
276
|
+
{ url: snapshot.icon_url, kind: 'icon', label: 'icon' },
|
|
277
|
+
...snapshot.cover_image_urls.map((url, i) => ({ url, kind: 'cover', label: `cover-${String(i + 1).padStart(2, '0')}` })),
|
|
278
|
+
];
|
|
279
|
+
for (const entry of entries) {
|
|
280
|
+
const bytes = await downloadImage(entry.url, fetchImpl);
|
|
281
|
+
const image = await inspectRemoteBasicInfoImage(bytes, entry.kind);
|
|
282
|
+
const relative = `assets/heybox/${entry.label}.${image.sha256.slice(0, 12)}.${image.extension}`;
|
|
283
|
+
const target = path.join(context.projectRoot, relative);
|
|
284
|
+
await ensureBasicInfoDirectory(context.projectRoot, 'assets/heybox');
|
|
285
|
+
try {
|
|
286
|
+
await fs.writeFile(target, bytes, { flag: 'wx' });
|
|
287
|
+
created.push(target);
|
|
288
|
+
}
|
|
289
|
+
catch (error) {
|
|
290
|
+
if (error.code !== 'EEXIST' ||
|
|
291
|
+
!(await readBasicInfoSource(context.projectRoot, relative, entry.kind).then((existing) => existing.bytes.equals(bytes), () => false)))
|
|
292
|
+
throw new Error('迁移素材名称冲突,未覆盖已有文件');
|
|
293
|
+
}
|
|
294
|
+
if (entry.kind === 'icon')
|
|
295
|
+
profile.icon = relative;
|
|
296
|
+
else
|
|
297
|
+
profile.coverImages.push(relative);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// 避免覆盖用户在下载期间修改的配置。
|
|
301
|
+
if ((await fs.readFile(context.packageJsonPath, 'utf8')) !== context.raw)
|
|
302
|
+
throw new Error('package.json 已变化,请重试迁移');
|
|
303
|
+
context.packageJson.heybox = { ...heybox, miniProgramId, ...profile };
|
|
304
|
+
await fs.writeFile(temp, JSON.stringify(context.packageJson, null, context.indent) + context.trailingNewline, { flag: 'wx' });
|
|
305
|
+
await fs.rename(temp, context.packageJsonPath);
|
|
306
|
+
return { changed: true, miniProgramId };
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
// 若用户同时修改了 package,保留可能已被引用的素材供重试复用。
|
|
310
|
+
if ((await fs.readFile(context.packageJsonPath, 'utf8').catch(() => '')) === context.raw) {
|
|
311
|
+
await Promise.all(created.map((file) => fs.unlink(file).catch(() => { })));
|
|
312
|
+
}
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
finally {
|
|
316
|
+
await fs.unlink(temp).catch(() => { });
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
async function compareBasicInfo(cwd, detail, fetchImpl = fetch) {
|
|
320
|
+
const context = await readMiniProgramProjectPackage(cwd);
|
|
321
|
+
const published = detail.published_basic_info;
|
|
322
|
+
let local;
|
|
323
|
+
try {
|
|
324
|
+
local = runtimePermissionEnv.parseMiniappBasicInfo(context.packageJson.heybox ?? {});
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
return { status: 'unavailable' };
|
|
328
|
+
}
|
|
329
|
+
if (!local || !published?.version)
|
|
330
|
+
return { status: 'unavailable', local, published };
|
|
331
|
+
try {
|
|
332
|
+
const pairs = [
|
|
333
|
+
{ local: local.icon, remote: published.icon_url, kind: 'icon' },
|
|
334
|
+
...local.coverImages.map((p, i) => ({ local: p, remote: published.cover_image_urls[i], kind: 'cover' })),
|
|
335
|
+
];
|
|
336
|
+
let changed = local.name !== runtimePermissionEnv.normalizeBasicInfoName(published.name) || local.coverImages.length !== published.cover_image_urls.length;
|
|
337
|
+
for (const pair of pairs) {
|
|
338
|
+
if (!pair.remote) {
|
|
339
|
+
changed = true;
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
const source = await readBasicInfoSource(context.projectRoot, pair.local, pair.kind);
|
|
343
|
+
const bytes = await downloadImage(pair.remote, fetchImpl);
|
|
344
|
+
const remote = await inspectRemoteBasicInfoImage(bytes, pair.kind);
|
|
345
|
+
changed ||= source.sha256 !== remote.sha256;
|
|
346
|
+
}
|
|
347
|
+
return { status: changed ? 'changed' : 'unchanged', local, published };
|
|
348
|
+
}
|
|
349
|
+
catch {
|
|
350
|
+
return { status: 'unavailable', local, published };
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
60
354
|
const CREATE_USER_MINIPROGRAM_UPLOAD_SESSION_API_PATH = '/mall/developer/user_miniprogram/version/upload_session/create';
|
|
61
355
|
const RECORD_USER_MINIPROGRAM_UPLOAD_RESULT_API_PATH = '/mall/developer/user_miniprogram/version/upload_session/record';
|
|
62
356
|
const COMPANION_FINALIZATION_TIMEOUT_MS = 30 * 60_000;
|
|
@@ -67,7 +361,7 @@ async function authorizeCompanionUpload(options, runtime = {}) {
|
|
|
67
361
|
}
|
|
68
362
|
return result;
|
|
69
363
|
}
|
|
70
|
-
async function precheckUserMiniprogramVersion(options, runtime = {}) {
|
|
364
|
+
async function precheckUserMiniprogramVersion$1(options, runtime = {}) {
|
|
71
365
|
return postUserMiniprogramVersionForm(runtimePermissionEnv.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH, options, {
|
|
72
366
|
// 构建前轻预检不携带独立资料;权威准入读取构建 Manifest。
|
|
73
367
|
...(options.version ? { version: options.version } : {}),
|
|
@@ -76,7 +370,7 @@ async function precheckUserMiniprogramVersion(options, runtime = {}) {
|
|
|
76
370
|
auto_publish: String(options.autoPublish),
|
|
77
371
|
}, runtime);
|
|
78
372
|
}
|
|
79
|
-
async function submitUserMiniprogramAudit(options, runtime = {}) {
|
|
373
|
+
async function submitUserMiniprogramAudit$1(options, runtime = {}) {
|
|
80
374
|
return postUserMiniprogramVersionForm(runtimePermissionEnv.SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH, options, { session_id: options.sessionId, preflight_token: options.preflightToken, artifact_protocol_version: '2' }, runtime);
|
|
81
375
|
}
|
|
82
376
|
async function createUserMiniprogramUploadSession(options, runtime = {}) {
|
|
@@ -143,7 +437,7 @@ async function runUpload(options, runtime = {}) {
|
|
|
143
437
|
const getCDNUploadToken = runtime.getCDNUploadToken ?? index.getCDNUploadToken;
|
|
144
438
|
const postCDNUploadCallback = runtime.postCDNUploadCallback ?? index.postCDNUploadCallback;
|
|
145
439
|
const recordUserMiniprogramUploadResult$1 = runtime.recordUserMiniprogramUploadResult ?? recordUserMiniprogramUploadResult;
|
|
146
|
-
const createReadStream = runtime.createReadStream ?? fs.createReadStream;
|
|
440
|
+
const createReadStream = runtime.createReadStream ?? fs$1.createReadStream;
|
|
147
441
|
const cdnBaseUrl = runtime.cdnBaseUrl ?? runtime.baseUrl;
|
|
148
442
|
let createCosClient = runtime.createCosClient;
|
|
149
443
|
if (!createCosClient) {
|
|
@@ -310,7 +604,7 @@ function createDefaultCosClient(uploadToken, COS) {
|
|
|
310
604
|
};
|
|
311
605
|
}
|
|
312
606
|
async function loadCosConstructor() {
|
|
313
|
-
const cosModule = await Promise.resolve().then(function () { return require('./index-
|
|
607
|
+
const cosModule = await Promise.resolve().then(function () { return require('./index-DoIKelYn.cjs'); }).then(function (n) { return n.index; });
|
|
314
608
|
return cosModule.default;
|
|
315
609
|
}
|
|
316
610
|
function formatSize(bytes) {
|
|
@@ -357,7 +651,7 @@ function isRecord(value) {
|
|
|
357
651
|
async function computeMiniappArtifactReceipt(files, runtime = {}) {
|
|
358
652
|
const preparedFiles = runtimePermissionEnv.prepareMiniappArtifactFiles(files);
|
|
359
653
|
const hash = node_crypto.createHash('sha256');
|
|
360
|
-
const createReadStream = runtime.createReadStream ?? fs.createReadStream;
|
|
654
|
+
const createReadStream = runtime.createReadStream ?? fs$1.createReadStream;
|
|
361
655
|
hash.update(runtimePermissionEnv.createMiniappArtifactSignatureHeader(preparedFiles.length));
|
|
362
656
|
for (const file of preparedFiles) {
|
|
363
657
|
hash.update(runtimePermissionEnv.createMiniappArtifactFileHeader(file));
|
|
@@ -377,6 +671,333 @@ async function computeMiniappArtifactReceipt(files, runtime = {}) {
|
|
|
377
671
|
return { artifactSignature: hash.digest('hex'), files: preparedFiles };
|
|
378
672
|
}
|
|
379
673
|
|
|
674
|
+
function createRemoteApiClient(options) {
|
|
675
|
+
return {
|
|
676
|
+
listPermissionApplications: (request) => remoteGet(runtimePermissionEnv.LIST_USER_MINIPROGRAM_PERMISSION_APPLICATION_API_PATH, request, options),
|
|
677
|
+
submitPermissionApplication: (request) => remotePostForm(runtimePermissionEnv.SUBMIT_USER_MINIPROGRAM_PERMISSION_APPLICATION_API_PATH, request, options),
|
|
678
|
+
listDeveloperEntities: () => listDeveloperEntities(options),
|
|
679
|
+
switchDeveloperEntity: (requestOptions) => switchDeveloperEntity(requestOptions, options),
|
|
680
|
+
getDeveloperAccessStatus: () => getDeveloperAccessStatus(options),
|
|
681
|
+
listUserMiniprograms: (requestOptions = {}) => listUserMiniprograms(requestOptions, options),
|
|
682
|
+
createUserMiniprogram: () => createUserMiniprogram(options),
|
|
683
|
+
getUserMiniprogramDetail: (requestOptions) => getUserMiniprogramDetail(requestOptions, options),
|
|
684
|
+
createLocalDevLaunchToken: (requestOptions) => createLocalDevLaunchToken$1(requestOptions, options),
|
|
685
|
+
getPreviewAllowlist: (requestOptions) => getPreviewAllowlist(requestOptions, options),
|
|
686
|
+
updatePreviewAllowlist: (requestOptions) => updatePreviewAllowlist(requestOptions, options),
|
|
687
|
+
createUserMiniprogramLeaderboard: (requestOptions) => createUserMiniprogramLeaderboard(requestOptions, options),
|
|
688
|
+
getUserMiniprogramLeaderboard: (requestOptions) => getUserMiniprogramLeaderboard(requestOptions, options),
|
|
689
|
+
listUserMiniprogramLeaderboards: (requestOptions) => listUserMiniprogramLeaderboards(requestOptions, options),
|
|
690
|
+
deleteUserMiniprogramLeaderboard: (requestOptions) => deleteUserMiniprogramLeaderboard(requestOptions, options),
|
|
691
|
+
precheckUserMiniprogramVersion: (requestOptions) => precheckUserMiniprogramVersion(requestOptions, options),
|
|
692
|
+
submitUserMiniprogramAudit: (requestOptions) => submitUserMiniprogramAudit(requestOptions, options),
|
|
693
|
+
getVersionPreviewInfo: (requestOptions) => getVersionPreviewInfo(requestOptions, options),
|
|
694
|
+
withdrawUserMiniprogramVersion: (requestOptions) => withdrawUserMiniprogramVersion(requestOptions, options),
|
|
695
|
+
releaseUserMiniprogramVersion: (requestOptions) => releaseUserMiniprogramVersion(requestOptions, options),
|
|
696
|
+
takeDownUserMiniprogram: (requestOptions) => takeDownUserMiniprogram(requestOptions, options),
|
|
697
|
+
reopenUserMiniprogram: (requestOptions) => reopenUserMiniprogram(requestOptions, options),
|
|
698
|
+
updateSquareDisplay: (requestOptions) => updateSquareDisplay(requestOptions, options),
|
|
699
|
+
listUserMiniprogramVersions: (requestOptions) => listUserMiniprogramVersions(requestOptions, options),
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
async function listDeveloperEntities(runtime) {
|
|
703
|
+
return remoteGet(runtimePermissionEnv.DEVELOPER_ENTITY_LIST_API_PATH, {}, runtime);
|
|
704
|
+
}
|
|
705
|
+
async function switchDeveloperEntity(options, runtime) {
|
|
706
|
+
return (await remotePostForm(runtimePermissionEnv.DEVELOPER_ENTITY_SWITCH_API_PATH, options, runtime, { requireResult: false })) ?? {};
|
|
707
|
+
}
|
|
708
|
+
async function getDeveloperAccessStatus(runtime) {
|
|
709
|
+
return remoteGet(runtimePermissionEnv.USER_MINIPROGRAM_ACCESS_STATUS_API_PATH, {}, runtime);
|
|
710
|
+
}
|
|
711
|
+
async function listUserMiniprograms(options, runtime) {
|
|
712
|
+
return remoteGet(runtimePermissionEnv.LIST_USER_MINIPROGRAM_API_PATH, options, runtime);
|
|
713
|
+
}
|
|
714
|
+
async function createUserMiniprogram(runtime) {
|
|
715
|
+
return remotePostForm(runtimePermissionEnv.CREATE_USER_MINIPROGRAM_API_PATH, {}, runtime);
|
|
716
|
+
}
|
|
717
|
+
async function getUserMiniprogramDetail(options, runtime) {
|
|
718
|
+
return remoteGet(runtimePermissionEnv.DETAIL_USER_MINIPROGRAM_API_PATH, options, runtime);
|
|
719
|
+
}
|
|
720
|
+
async function createLocalDevLaunchToken$1(options, runtime) {
|
|
721
|
+
return remotePostForm(runtimePermissionEnv.CREATE_USER_MINIPROGRAM_LOCAL_DEV_LAUNCH_TOKEN_API_PATH, options, runtime);
|
|
722
|
+
}
|
|
723
|
+
async function getPreviewAllowlist(options, runtime) {
|
|
724
|
+
return remoteGet(runtimePermissionEnv.USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH, options, runtime);
|
|
725
|
+
}
|
|
726
|
+
async function updatePreviewAllowlist(options, runtime) {
|
|
727
|
+
return remotePostForm(runtimePermissionEnv.UPDATE_USER_MINIPROGRAM_PREVIEW_ALLOWLIST_API_PATH, options, runtime);
|
|
728
|
+
}
|
|
729
|
+
async function createUserMiniprogramLeaderboard(options, runtime) {
|
|
730
|
+
return remotePostForm(runtimePermissionEnv.CREATE_USER_MINIPROGRAM_LEADERBOARD_API_PATH, options, runtime);
|
|
731
|
+
}
|
|
732
|
+
async function getUserMiniprogramLeaderboard(options, runtime) {
|
|
733
|
+
return remoteGet(runtimePermissionEnv.DETAIL_USER_MINIPROGRAM_LEADERBOARD_API_PATH, options, runtime);
|
|
734
|
+
}
|
|
735
|
+
async function listUserMiniprogramLeaderboards(options, runtime) {
|
|
736
|
+
return remoteGet(runtimePermissionEnv.LIST_USER_MINIPROGRAM_LEADERBOARD_API_PATH, options, runtime);
|
|
737
|
+
}
|
|
738
|
+
async function deleteUserMiniprogramLeaderboard(options, runtime) {
|
|
739
|
+
return ((await remotePostForm(runtimePermissionEnv.DELETE_USER_MINIPROGRAM_LEADERBOARD_API_PATH, options, runtime, { requireResult: false })) ?? {});
|
|
740
|
+
}
|
|
741
|
+
async function precheckUserMiniprogramVersion(options, runtime) {
|
|
742
|
+
return remotePostForm(runtimePermissionEnv.PRECHECK_USER_MINIPROGRAM_VERSION_API_PATH, options, runtime);
|
|
743
|
+
}
|
|
744
|
+
async function submitUserMiniprogramAudit(options, runtime) {
|
|
745
|
+
return remotePostForm(runtimePermissionEnv.SUBMIT_USER_MINIPROGRAM_AUDIT_API_PATH, {
|
|
746
|
+
mini_program_id: options.mini_program_id, session_id: options.session_id, preflight_token: options.preflight_token,
|
|
747
|
+
}, runtime);
|
|
748
|
+
}
|
|
749
|
+
async function getVersionPreviewInfo(options, runtime) {
|
|
750
|
+
return remoteGet(runtimePermissionEnv.USER_MINIPROGRAM_VERSION_PREVIEW_INFO_API_PATH, {
|
|
751
|
+
mini_program_id: options.mini_program_id,
|
|
752
|
+
preview_version: options.version,
|
|
753
|
+
}, runtime);
|
|
754
|
+
}
|
|
755
|
+
async function withdrawUserMiniprogramVersion(options, runtime) {
|
|
756
|
+
return remotePostForm(runtimePermissionEnv.WITHDRAW_USER_MINIPROGRAM_VERSION_API_PATH, options, runtime);
|
|
757
|
+
}
|
|
758
|
+
async function releaseUserMiniprogramVersion(options, runtime) {
|
|
759
|
+
return remotePostForm(runtimePermissionEnv.RELEASE_USER_MINIPROGRAM_VERSION_API_PATH, options, runtime);
|
|
760
|
+
}
|
|
761
|
+
async function takeDownUserMiniprogram(options, runtime) {
|
|
762
|
+
return remotePostForm(runtimePermissionEnv.TAKE_DOWN_USER_MINIPROGRAM_API_PATH, options, runtime);
|
|
763
|
+
}
|
|
764
|
+
async function reopenUserMiniprogram(options, runtime) {
|
|
765
|
+
return remotePostForm(runtimePermissionEnv.REOPEN_USER_MINIPROGRAM_API_PATH, options, runtime);
|
|
766
|
+
}
|
|
767
|
+
async function updateSquareDisplay(options, runtime) {
|
|
768
|
+
return remotePostForm(runtimePermissionEnv.UPDATE_SQUARE_DISPLAY_API_PATH, options, runtime);
|
|
769
|
+
}
|
|
770
|
+
async function listUserMiniprogramVersions(options, runtime) {
|
|
771
|
+
return remoteGet(runtimePermissionEnv.LIST_USER_MINIPROGRAM_VERSION_API_PATH, options, runtime);
|
|
772
|
+
}
|
|
773
|
+
async function remoteGet(path, query, runtime) {
|
|
774
|
+
const pathWithQuery = createPathWithQuery(path, query);
|
|
775
|
+
const context = index.createHeyboxOpenPlatformRequestContext(runtime.session, pathWithQuery);
|
|
776
|
+
const fetchImpl = runtime.fetchImpl ?? fetch;
|
|
777
|
+
const response = await fetchImpl(index.createHeyboxApiUrl(runtime.baseUrl ?? context.baseUrl, pathWithQuery, context.platformParams), {
|
|
778
|
+
method: 'GET',
|
|
779
|
+
headers: context.headers,
|
|
780
|
+
});
|
|
781
|
+
return readRequiredResult(response, pathWithQuery);
|
|
782
|
+
}
|
|
783
|
+
async function remotePostForm(path, fields, runtime, options = {}) {
|
|
784
|
+
const context = index.createHeyboxOpenPlatformRequestContext(runtime.session, path, {
|
|
785
|
+
contentType: 'application/x-www-form-urlencoded',
|
|
786
|
+
});
|
|
787
|
+
const fetchImpl = runtime.fetchImpl ?? fetch;
|
|
788
|
+
const response = await fetchImpl(index.createHeyboxApiUrl(runtime.baseUrl ?? context.baseUrl, path, context.platformParams), {
|
|
789
|
+
method: 'POST',
|
|
790
|
+
headers: context.headers,
|
|
791
|
+
body: createFormBody(fields),
|
|
792
|
+
});
|
|
793
|
+
if (options.requireResult === false) {
|
|
794
|
+
return readOptionalResult(response, path);
|
|
795
|
+
}
|
|
796
|
+
return readRequiredResult(response, path);
|
|
797
|
+
}
|
|
798
|
+
async function readRequiredResult(response, pathWithQuery) {
|
|
799
|
+
const result = await index.readHeyboxApiEnvelope(response, { pathWithQuery, requireResult: true });
|
|
800
|
+
return result;
|
|
801
|
+
}
|
|
802
|
+
async function readOptionalResult(response, pathWithQuery) {
|
|
803
|
+
return index.readHeyboxApiEnvelope(response, { pathWithQuery, requireResult: false });
|
|
804
|
+
}
|
|
805
|
+
function createPathWithQuery(path, query) {
|
|
806
|
+
const params = new URLSearchParams();
|
|
807
|
+
for (const [key, value] of Object.entries(query)) {
|
|
808
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
809
|
+
params.set(key, String(value));
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
const queryString = params.toString();
|
|
813
|
+
return queryString ? `${path}?${queryString}` : path;
|
|
814
|
+
}
|
|
815
|
+
function createFormBody(fields) {
|
|
816
|
+
const body = new URLSearchParams();
|
|
817
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
818
|
+
if (value === undefined || value === null) {
|
|
819
|
+
continue;
|
|
820
|
+
}
|
|
821
|
+
if (Array.isArray(value)) {
|
|
822
|
+
body.set(key, value.join(','));
|
|
823
|
+
continue;
|
|
824
|
+
}
|
|
825
|
+
if (typeof value === 'object') {
|
|
826
|
+
body.set(key, JSON.stringify(value));
|
|
827
|
+
continue;
|
|
828
|
+
}
|
|
829
|
+
body.set(key, String(value));
|
|
830
|
+
}
|
|
831
|
+
return body.toString();
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
async function resolveRemoteEnvironment(options = {}, runtime = {}) {
|
|
835
|
+
const env = options.env ?? process.env;
|
|
836
|
+
const apiBaseUrl = index.resolveHeyboxApiBaseUrl({ ...options, env });
|
|
837
|
+
const loginBaseUrl = index.resolveHeyboxLoginBaseUrl({ ...options, env });
|
|
838
|
+
const session = options.session ?? (await (runtime.requireAuthSession ?? index.requireHeyboxAuthSession)({ loginBaseUrl }));
|
|
839
|
+
return {
|
|
840
|
+
apiBaseUrl,
|
|
841
|
+
loginBaseUrl,
|
|
842
|
+
allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl === true || isTruthyEnvFlag(env.HB_SDK_ALLOW_UNSAFE_API_BASE_URL),
|
|
843
|
+
env,
|
|
844
|
+
fetchImpl: runtime.fetchImpl ?? options.fetchImpl ?? fetch,
|
|
845
|
+
session,
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
function createRemoteApiClientForEnvironment(environment) {
|
|
849
|
+
return createRemoteApiClient({
|
|
850
|
+
baseUrl: environment.apiBaseUrl,
|
|
851
|
+
fetchImpl: environment.fetchImpl,
|
|
852
|
+
session: environment.session,
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
async function getBoundMiniProgram(options = {}, runtime = {}) {
|
|
856
|
+
const cwd = options.cwd ?? process.cwd();
|
|
857
|
+
const binding = await requireBoundMiniProgramId(cwd);
|
|
858
|
+
const api = await resolveRemoteApiClient(options, runtime);
|
|
859
|
+
const detail = await api.getUserMiniprogramDetail({ mini_program_id: binding.miniProgramId });
|
|
860
|
+
return {
|
|
861
|
+
...binding,
|
|
862
|
+
detail,
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
async function createLocalDevLaunchToken(options, runtime = {}) {
|
|
866
|
+
const miniProgramId = options.miniProgramId.trim();
|
|
867
|
+
if (!miniProgramId) {
|
|
868
|
+
throw new Error('mini-program-id 不能为空');
|
|
869
|
+
}
|
|
870
|
+
const api = await resolveRemoteApiClient(options, runtime);
|
|
871
|
+
return api.createLocalDevLaunchToken({
|
|
872
|
+
mini_program_id: miniProgramId,
|
|
873
|
+
...(options.developmentSnapshot ? { development_snapshot: options.developmentSnapshot } : {}),
|
|
874
|
+
...(options.companionManifestSha256
|
|
875
|
+
? { companion_manifest_sha256: options.companionManifestSha256 }
|
|
876
|
+
: {}),
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
async function resolveRemoteApiClient(options, runtime) {
|
|
880
|
+
if (runtime.apiClient) {
|
|
881
|
+
return runtime.apiClient;
|
|
882
|
+
}
|
|
883
|
+
return createRemoteApiClientForEnvironment(await resolveRemoteEnvironment(options, runtime));
|
|
884
|
+
}
|
|
885
|
+
function isTruthyEnvFlag(value) {
|
|
886
|
+
return ['1', 'true', 'yes', 'on'].includes(String(value ?? '')
|
|
887
|
+
.trim()
|
|
888
|
+
.toLowerCase());
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/** Browser Fake 与 channel 共用的本地 grant 有效性校验。 */
|
|
892
|
+
function resolveBrowserFakeContext(context, now = Date.now()) {
|
|
893
|
+
if (context.localDevGrant === undefined)
|
|
894
|
+
return context;
|
|
895
|
+
const parsed = index_esm.parseMiniProgramLocalDevGrant(context.localDevGrant);
|
|
896
|
+
if (!parsed.valid ||
|
|
897
|
+
!context.devSessionId?.trim() ||
|
|
898
|
+
!Number.isSafeInteger(context.contextRevision) ||
|
|
899
|
+
context.contextRevision !== parsed.grant.revision ||
|
|
900
|
+
!context.expiresAt ||
|
|
901
|
+
!Number.isFinite(context.expiresAt) ||
|
|
902
|
+
(context.source !== 'remote' && context.expiresAt <= now)) {
|
|
903
|
+
return { ...context, localDevGrant: undefined, warning: '本地临时授权无效或已过期,已降权' };
|
|
904
|
+
}
|
|
905
|
+
return {
|
|
906
|
+
...context,
|
|
907
|
+
...(context.expiresAt <= now ? { source: 'anonymous', localDevLaunchToken: undefined, expiresAt: now + 30_000 } : {}),
|
|
908
|
+
localDevGrant: index_esm.createMiniProgramLocalDevGrant({
|
|
909
|
+
declaredPermissions: context.declaredPermissions ?? {},
|
|
910
|
+
runtimePermissions: context.runtimePermissions,
|
|
911
|
+
revision: parsed.grant.revision,
|
|
912
|
+
eligiblePermissionKeys: context.platforms?.some((platform) => ['windows', 'macos', 'linux'].includes(platform))
|
|
913
|
+
? ['network', 'companion', 'appProtocol']
|
|
914
|
+
: ['network', 'appProtocol'],
|
|
915
|
+
}),
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
function shouldSkipMiniappPlatformCsp(_runtimePermissions) {
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
const DEFAULT_PERMISSION_STATE = {
|
|
922
|
+
networkRequest: {
|
|
923
|
+
status: 'disabled',
|
|
924
|
+
useOfficialDomain: false,
|
|
925
|
+
},
|
|
926
|
+
};
|
|
927
|
+
function createBrowserDevPermissionState(context) {
|
|
928
|
+
const parsed = index_esm.parseMiniProgramRuntimePermissions(context.localDevGrant
|
|
929
|
+
? index_esm.composeLocalDevRuntimePermissions({ declaredPermissions: context.declaredPermissions ?? {}, runtimePermissions: context.runtimePermissions,
|
|
930
|
+
localDevGrant: context.localDevGrant }).runtimePermissions
|
|
931
|
+
: context.runtimePermissions);
|
|
932
|
+
const networkRequest = parsed.permissions.network;
|
|
933
|
+
return parsed.valid && networkRequest
|
|
934
|
+
? {
|
|
935
|
+
networkRequest: {
|
|
936
|
+
status: networkRequest.status,
|
|
937
|
+
useOfficialDomain: networkRequest.config.useOfficialDomain === true,
|
|
938
|
+
},
|
|
939
|
+
}
|
|
940
|
+
: cloneDefaultPermissionState();
|
|
941
|
+
}
|
|
942
|
+
/** Mobile Dev Session 使用本地声明与平台基线,不读取 Browser 模拟权限状态。 */
|
|
943
|
+
function createMobileDevSessionRuntimePermissions(context) {
|
|
944
|
+
if (context.source !== 'remote') {
|
|
945
|
+
return { schema_version: 1, entries: [] };
|
|
946
|
+
}
|
|
947
|
+
// 历史内部调用没有本地声明,沿用旧快照适配;新 CLI 始终显式提供声明(可为空)。
|
|
948
|
+
if (context.declaredPermissions === undefined) {
|
|
949
|
+
const state = createBrowserDevPermissionState(context);
|
|
950
|
+
return createDevRuntimePermissions(context.runtimePermissions, state, state.networkRequest.useOfficialDomain);
|
|
951
|
+
}
|
|
952
|
+
return index_esm.composeLocalDevRuntimePermissions({ declaredPermissions: context.declaredPermissions, runtimePermissions: context.runtimePermissions }).runtimePermissions;
|
|
953
|
+
}
|
|
954
|
+
function cloneDefaultPermissionState() {
|
|
955
|
+
return {
|
|
956
|
+
networkRequest: { ...DEFAULT_PERMISSION_STATE.networkRequest },
|
|
957
|
+
};
|
|
958
|
+
}
|
|
959
|
+
function createDevRuntimePermissions(snapshot, state, useOfficialDomain) {
|
|
960
|
+
const parsed = index_esm.parseMiniProgramRuntimePermissions(snapshot);
|
|
961
|
+
if (!parsed.valid) {
|
|
962
|
+
return { schema_version: 1, entries: [] };
|
|
963
|
+
}
|
|
964
|
+
const entries = [];
|
|
965
|
+
for (const key of index_esm.MINI_PROGRAM_PERMISSION_KEYS) {
|
|
966
|
+
const entry = parsed.permissions[key];
|
|
967
|
+
if (!entry)
|
|
968
|
+
continue;
|
|
969
|
+
entries.push(key === 'network'
|
|
970
|
+
? {
|
|
971
|
+
key,
|
|
972
|
+
status: state.networkRequest.status,
|
|
973
|
+
config: { useOfficialDomain },
|
|
974
|
+
}
|
|
975
|
+
: key === 'user_game_data'
|
|
976
|
+
? {
|
|
977
|
+
key,
|
|
978
|
+
status: entry.status,
|
|
979
|
+
// 精确资源清单是 snapshot 的合法必需项:浏览器模拟只调整开关,不能丢掉 Manifest 声明。
|
|
980
|
+
config: { resources: entry.config.resources },
|
|
981
|
+
}
|
|
982
|
+
: {
|
|
983
|
+
key,
|
|
984
|
+
status: entry.status,
|
|
985
|
+
config: {},
|
|
986
|
+
});
|
|
987
|
+
}
|
|
988
|
+
const revision = isPlainRecord(snapshot) && typeof snapshot.revision === 'number' && Number.isInteger(snapshot.revision) && snapshot.revision >= 0
|
|
989
|
+
? snapshot.revision
|
|
990
|
+
: undefined;
|
|
991
|
+
return {
|
|
992
|
+
schema_version: 1,
|
|
993
|
+
...(revision === undefined ? {} : { revision }),
|
|
994
|
+
entries,
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
function isPlainRecord(value) {
|
|
998
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) && Object.getPrototypeOf(value) === Object.prototype;
|
|
999
|
+
}
|
|
1000
|
+
|
|
380
1001
|
/** 发布提示使用显式声明与远端主体批准策略,不消费本地调试授权。 */
|
|
381
1002
|
function getUnapprovedPermissionWarning(local, approvals, partyType) {
|
|
382
1003
|
if (!local.declared)
|
|
@@ -433,6 +1054,10 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
433
1054
|
if (typeof miniProgramId !== 'string' || !miniProgramId.trim()) {
|
|
434
1055
|
throw new Error('未在 package.json 中找到 heybox.miniProgramId,请先配置 mini program id');
|
|
435
1056
|
}
|
|
1057
|
+
if (runtime.expectedProject && (miniProgramId.trim() !== runtime.expectedProject.miniProgramId ||
|
|
1058
|
+
packageJson.version !== runtime.expectedProject.version)) {
|
|
1059
|
+
throw new index.CliError('项目 ID 或版本已变化,请刷新上传发布面板后重新核对');
|
|
1060
|
+
}
|
|
436
1061
|
const declaredPlatforms = runtimePermissionEnv.readMiniappPlatformsFromPackageJson(projectRoot);
|
|
437
1062
|
const declaredWindow = runtimePermissionEnv.readMiniappWindowFromPackageJson(projectRoot);
|
|
438
1063
|
const declaredBindAppIds = runtimePermissionEnv.readMiniappBindAppIdsFromPackageJson(projectRoot);
|
|
@@ -446,7 +1071,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
446
1071
|
{
|
|
447
1072
|
const configuredProfile = runtimePermissionEnv.parseMiniappBasicInfo(packageJson.heybox ?? {}, '0.8.1');
|
|
448
1073
|
if (!configuredProfile) {
|
|
449
|
-
const bound = await (runtime.getBoundMiniProgram ??
|
|
1074
|
+
const bound = await (runtime.getBoundMiniProgram ?? getBoundMiniProgram)({
|
|
450
1075
|
allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
|
|
451
1076
|
apiBaseUrl,
|
|
452
1077
|
cwd: projectRoot,
|
|
@@ -455,7 +1080,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
455
1080
|
loginBaseUrl,
|
|
456
1081
|
session,
|
|
457
1082
|
});
|
|
458
|
-
await
|
|
1083
|
+
await migrateBasicInfo(projectRoot, bound.detail, miniProgramId, runtime.fetchImpl);
|
|
459
1084
|
}
|
|
460
1085
|
const localPermissions = runtimePermissionEnv.readMiniappPermissionsFromPackageJson(projectRoot, runtimePermissionEnv.resolveMiniappSdkVersion());
|
|
461
1086
|
if (typeof packageJson.scripts?.build !== 'string') {
|
|
@@ -473,7 +1098,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
473
1098
|
let networkPolicy;
|
|
474
1099
|
let firstParty = false;
|
|
475
1100
|
try {
|
|
476
|
-
const { detail } = await logger.task('正在读取远端小程序权限', () => (runtime.getBoundMiniProgram ??
|
|
1101
|
+
const { detail } = await logger.task('正在读取远端小程序权限', () => (runtime.getBoundMiniProgram ?? getBoundMiniProgram)({
|
|
477
1102
|
allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
|
|
478
1103
|
apiBaseUrl,
|
|
479
1104
|
cwd: projectRoot,
|
|
@@ -484,7 +1109,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
484
1109
|
}), { successText: '已读取远端小程序权限' });
|
|
485
1110
|
const effectivePermissions = runtimePermissionEnv.composeMiniappRuntimePermissions(localPermissions, detail.runtime_permissions, detail.party_type).runtimePermissions;
|
|
486
1111
|
firstParty = detail.party_type === 'first_party';
|
|
487
|
-
skipPlatformCsp =
|
|
1112
|
+
skipPlatformCsp = shouldSkipMiniappPlatformCsp(effectivePermissions);
|
|
488
1113
|
networkPolicy = effectivePermissions.entries.some((entry) => entry.key === 'network' && entry.status === 'enabled')
|
|
489
1114
|
? detail.network_policy : undefined;
|
|
490
1115
|
const permissionWarning = getUnapprovedPermissionWarning(localPermissions, detail.runtime_permissions, detail.party_type);
|
|
@@ -499,6 +1124,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
499
1124
|
const platform = runtime.platform ?? process.platform;
|
|
500
1125
|
const buildMode = validateBuildMode(env.HB_SDK_ENV?.trim(), platform);
|
|
501
1126
|
const buildScript = await readProjectBuildScript(projectRoot);
|
|
1127
|
+
runtime.onBuildStart?.();
|
|
502
1128
|
logger.info(`开始构建: ${pm} ${createBuildArgs(pm, buildMode, buildScript).join(' ')}`);
|
|
503
1129
|
await runBuildScript(pm, projectRoot, runtime.spawn ?? childProcess.spawn, {
|
|
504
1130
|
env: { ...runtimePermissionEnv.createMiniappPlatformCspEnv(env, skipPlatformCsp, networkPolicy, firstParty), HB_SDK_DEFER_METADATA_WARNINGS: '1' },
|
|
@@ -516,7 +1142,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
516
1142
|
let preflightToken = '';
|
|
517
1143
|
{
|
|
518
1144
|
const distDir = path.join(projectRoot, 'dist');
|
|
519
|
-
const artifact
|
|
1145
|
+
const artifact = await runtimePermissionEnv.inspectVersionArtifact({
|
|
520
1146
|
projectRoot,
|
|
521
1147
|
declarations: {
|
|
522
1148
|
platforms: declaredPlatforms,
|
|
@@ -525,10 +1151,10 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
525
1151
|
category: declaredCategory,
|
|
526
1152
|
},
|
|
527
1153
|
});
|
|
528
|
-
if (artifact
|
|
1154
|
+
if (artifact.hadBom)
|
|
529
1155
|
logger.warn('dist/manifest.json 包含 BOM,已自动剥离');
|
|
530
|
-
manifest = artifact
|
|
531
|
-
version = artifact
|
|
1156
|
+
manifest = artifact.manifest;
|
|
1157
|
+
version = artifact.summary.version;
|
|
532
1158
|
for (const warning of getMiniappMetadataWarnings(manifest)) {
|
|
533
1159
|
logger.warn(`[${warning.code}] ${warning.message}`, { stream: 'stderr' });
|
|
534
1160
|
}
|
|
@@ -544,7 +1170,7 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
544
1170
|
autoPublish,
|
|
545
1171
|
}, runtime, apiBaseUrl, projectRoot, logger);
|
|
546
1172
|
const uploadFiles = await logger.task('正在校验 dist 上传文件', async () => {
|
|
547
|
-
const inventory = await
|
|
1173
|
+
const inventory = await runtimePermissionEnv.inspectVersionArtifactFiles(distDir);
|
|
548
1174
|
const files = inventory.files.map((file) => ({ ...file, mimeType: inferMimeType(file.relativePath) }));
|
|
549
1175
|
const pathError = runtimePermissionEnv.validateMiniappUploadPathLengths(files, { miniProgramId });
|
|
550
1176
|
if (pathError) {
|
|
@@ -565,8 +1191,8 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
565
1191
|
const sources = [localProfile.icon, ...localProfile.coverImages];
|
|
566
1192
|
const refs = [{ path: profile.icon, kind: 'icon' }, ...profile.coverImages.map((path) => ({ path, kind: 'cover' }))];
|
|
567
1193
|
for (const [index, ref] of refs.entries()) {
|
|
568
|
-
const image = await
|
|
569
|
-
const source = await
|
|
1194
|
+
const image = await readBasicInfoSource(distDir, ref.path, ref.kind);
|
|
1195
|
+
const source = await readBasicInfoSource(projectRoot, sources[index], ref.kind);
|
|
570
1196
|
if (source.sha256 !== image.sha256)
|
|
571
1197
|
throw new Error('构建图片与项目声明不一致,请重新构建');
|
|
572
1198
|
if (image.sha256 === BASIC_INFO_PLACEHOLDER_SHA256)
|
|
@@ -653,19 +1279,19 @@ async function runDeployCommand(options, runtime = {}) {
|
|
|
653
1279
|
}
|
|
654
1280
|
}
|
|
655
1281
|
catch (error) {
|
|
656
|
-
throw translateHeyboxDeployError(error, { projectRoot, stage: 'upload', version });
|
|
1282
|
+
throw translateHeyboxDeployError(error, { projectRoot, stage: 'upload', version, workbench: Boolean(runtime.expectedProject) });
|
|
657
1283
|
}
|
|
658
1284
|
}
|
|
659
1285
|
try {
|
|
660
1286
|
const submitOptions = { session, miniProgramId, sessionId: uploadSessionId, preflightToken };
|
|
661
|
-
submitAuditResult = await logger.task('正在提交审核', () => (runtime.submitUserMiniprogramAudit ?? submitUserMiniprogramAudit)(submitOptions, {
|
|
1287
|
+
submitAuditResult = await logger.task('正在提交审核', () => (runtime.submitUserMiniprogramAudit ?? submitUserMiniprogramAudit$1)(submitOptions, {
|
|
662
1288
|
baseUrl: apiBaseUrl,
|
|
663
1289
|
fetchImpl: runtime.fetchImpl,
|
|
664
1290
|
}), { successText: '审核提交完成' });
|
|
665
1291
|
}
|
|
666
1292
|
catch (error) {
|
|
667
1293
|
logger.warn('提交未完成;已上传文件会保留,再次部署相同产物时只补传缺失文件。');
|
|
668
|
-
throw translateHeyboxDeployError(error, { projectRoot, stage: 'submitAudit', version });
|
|
1294
|
+
throw translateHeyboxDeployError(error, { projectRoot, stage: 'submitAudit', version, workbench: Boolean(runtime.expectedProject) });
|
|
669
1295
|
}
|
|
670
1296
|
printDeploySuccess({
|
|
671
1297
|
autoPublish,
|
|
@@ -704,7 +1330,7 @@ function printDeploySuccess(options) {
|
|
|
704
1330
|
}
|
|
705
1331
|
}
|
|
706
1332
|
async function readPackageJson(projectRoot) {
|
|
707
|
-
return JSON.parse(await fs
|
|
1333
|
+
return JSON.parse(await fs.readFile(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
708
1334
|
}
|
|
709
1335
|
function validateVersionForDeploy(version, sourceLabel) {
|
|
710
1336
|
if (typeof version !== 'string' || !runtimePermissionEnv.isValidMiniappManifestVersion(version)) {
|
|
@@ -747,18 +1373,18 @@ async function maybePromptReleaseNote(runtime) {
|
|
|
747
1373
|
async function runVersionPrecheck(options, runtime, apiBaseUrl, projectRoot, logger) {
|
|
748
1374
|
try {
|
|
749
1375
|
const label = options.version ?? '';
|
|
750
|
-
return await logger.task(`正在预检版本 ${label}`, () => (runtime.precheckUserMiniprogramVersion ?? precheckUserMiniprogramVersion)(options, {
|
|
1376
|
+
return await logger.task(`正在预检版本 ${label}`, () => (runtime.precheckUserMiniprogramVersion ?? precheckUserMiniprogramVersion$1)(options, {
|
|
751
1377
|
baseUrl: apiBaseUrl,
|
|
752
1378
|
fetchImpl: runtime.fetchImpl,
|
|
753
1379
|
}), { successText: `版本 ${label} 预检通过` });
|
|
754
1380
|
}
|
|
755
1381
|
catch (error) {
|
|
756
|
-
throw translateHeyboxDeployError(error, { projectRoot, stage: 'precheck', version: options.version ?? '' });
|
|
1382
|
+
throw translateHeyboxDeployError(error, { projectRoot, stage: 'precheck', version: options.version ?? '', workbench: Boolean(runtime.expectedProject) });
|
|
757
1383
|
}
|
|
758
1384
|
}
|
|
759
1385
|
function detectPackageManager(projectRoot) {
|
|
760
1386
|
for (const candidate of SUPPORTED_PACKAGE_MANAGERS) {
|
|
761
|
-
if (fs.existsSync(path.join(projectRoot, candidate.lockfile))) {
|
|
1387
|
+
if (fs$1.existsSync(path.join(projectRoot, candidate.lockfile))) {
|
|
762
1388
|
return candidate.name;
|
|
763
1389
|
}
|
|
764
1390
|
}
|
|
@@ -808,7 +1434,7 @@ function escapeWindowsCommandArgument(argument) {
|
|
|
808
1434
|
}
|
|
809
1435
|
async function readProjectBuildScript(projectRoot) {
|
|
810
1436
|
try {
|
|
811
|
-
const packageJson = JSON.parse(await fs
|
|
1437
|
+
const packageJson = JSON.parse(await fs.readFile(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
812
1438
|
return typeof packageJson.scripts?.build === 'string' ? packageJson.scripts.build : '';
|
|
813
1439
|
}
|
|
814
1440
|
catch {
|
|
@@ -823,7 +1449,7 @@ function inferMimeType(fileName) {
|
|
|
823
1449
|
return MIME_BY_EXT[path.extname(fileName).toLowerCase()] || 'application/octet-stream';
|
|
824
1450
|
}
|
|
825
1451
|
async function assertDeployUploadFilesStillMatchSignature(options) {
|
|
826
|
-
const inventory = await
|
|
1452
|
+
const inventory = await runtimePermissionEnv.inspectVersionArtifactFiles(options.distDir);
|
|
827
1453
|
const currentFiles = inventory.files.map((file) => ({ ...file, mimeType: inferMimeType(file.relativePath) }));
|
|
828
1454
|
const currentByPath = new Map(currentFiles.map((file) => [file.relativePath, file]));
|
|
829
1455
|
if (currentFiles.length !== options.expectedFiles.length) {
|
|
@@ -849,10 +1475,12 @@ function translateHeyboxDeployError(error, options) {
|
|
|
849
1475
|
if (isVersionLifecycleConflictMessage(message) && options.stage !== 'upload') {
|
|
850
1476
|
const packageJsonPath = path.join(options.projectRoot, 'package.json');
|
|
851
1477
|
const nextVersion = suggestNextPatchVersion(options.version);
|
|
852
|
-
return new index.CliError(
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1478
|
+
return new index.CliError(options.workbench
|
|
1479
|
+
? `版本 ${options.version} 已进入审核或线上生命周期。请修改项目 package.json 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},再点击“构建上传并提审”。`
|
|
1480
|
+
: [
|
|
1481
|
+
`当前小程序版本 ${options.version} 已进入线上生命周期或正在审核,不能复用。`,
|
|
1482
|
+
`请升级 ${packageJsonPath} 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},重新 build 后再 deploy。`,
|
|
1483
|
+
].join('\n'), [
|
|
856
1484
|
`当前小程序版本 ${options.version} 已进入线上生命周期或正在审核,不能复用。`,
|
|
857
1485
|
`请升级 ${packageJsonPath} 中的 version${nextVersion ? `(例如 ${nextVersion})` : ''},重新 build 后再 deploy。`,
|
|
858
1486
|
`原始错误:${readVerboseDeployErrorMessage(error)}`,
|
|
@@ -951,10 +1579,15 @@ async function runRemoteCommand(options, runtime = {}) {
|
|
|
951
1579
|
}
|
|
952
1580
|
async function runRemoteDeployCommand(options, runtime) {
|
|
953
1581
|
const logger = resolveRemoteLogger(options, runtime);
|
|
954
|
-
const context = await createRemoteCommandContext(options, runtime);
|
|
1582
|
+
const context = await logger.task('正在校验登录态与开发者主体', () => createRemoteCommandContext(options, runtime));
|
|
955
1583
|
const miniProgramId = requireBinding(context);
|
|
956
|
-
|
|
1584
|
+
if (runtime.expectedProject && miniProgramId !== runtime.expectedProject.miniProgramId) {
|
|
1585
|
+
throw new index.CliError('项目绑定已变化,请刷新上传发布面板后重新核对');
|
|
1586
|
+
}
|
|
1587
|
+
await logger.task('正在校验小程序管理权限', () => assertBoundMiniProgramEntityMatchesCurrent(context, miniProgramId));
|
|
957
1588
|
const deployRuntime = {
|
|
1589
|
+
expectedProject: runtime.expectedProject,
|
|
1590
|
+
onBuildStart: runtime.onBuildStart,
|
|
958
1591
|
cwd: runtime.cwd,
|
|
959
1592
|
fetchImpl: runtime.fetchImpl,
|
|
960
1593
|
isTTY: runtime.isTTY,
|
|
@@ -980,7 +1613,7 @@ async function runRemoteDeployCommand(options, runtime) {
|
|
|
980
1613
|
async function createRemoteCommandContext(options, runtime) {
|
|
981
1614
|
index.applyMiniProgramServiceTagIfNeeded(options.serviceTag);
|
|
982
1615
|
const logger = resolveRemoteLogger(options, runtime);
|
|
983
|
-
const environment = await
|
|
1616
|
+
const environment = await resolveRemoteEnvironment({
|
|
984
1617
|
allowUnsafeApiBaseUrl: options.allowUnsafeApiBaseUrl,
|
|
985
1618
|
apiBaseUrl: options.apiBaseUrl,
|
|
986
1619
|
env: options.env,
|
|
@@ -990,10 +1623,10 @@ async function createRemoteCommandContext(options, runtime) {
|
|
|
990
1623
|
fetchImpl: runtime.fetchImpl,
|
|
991
1624
|
requireAuthSession: runtime.requireAuthSession,
|
|
992
1625
|
});
|
|
993
|
-
const packageJson = await
|
|
994
|
-
const binding =
|
|
1626
|
+
const packageJson = await readMiniProgramProjectPackage(runtime.cwd ?? process.cwd());
|
|
1627
|
+
const binding = readBoundMiniProgramIdFromPackageJson(packageJson.packageJson);
|
|
995
1628
|
const api = {
|
|
996
|
-
...adaptRemoteApiClient(
|
|
1629
|
+
...adaptRemoteApiClient(createRemoteApiClientForEnvironment(environment)),
|
|
997
1630
|
...runtime.api,
|
|
998
1631
|
};
|
|
999
1632
|
logger.debug(`Heybox API: ${environment.apiBaseUrl}`);
|
|
@@ -1151,7 +1784,7 @@ async function remoteCreate(options, context, runtime) {
|
|
|
1151
1784
|
runtimePermissionEnv.parseMiniappBasicInfo(context.packageJson.packageJson.heybox ?? {});
|
|
1152
1785
|
const result = await context.api.createMiniProgram();
|
|
1153
1786
|
const miniProgramId = requireMiniProgramId(result);
|
|
1154
|
-
await
|
|
1787
|
+
await writeBoundMiniProgramId(context.packageJson.projectRoot, miniProgramId, { force: options.forceBind });
|
|
1155
1788
|
const output = { changed: true, miniProgramId, remote: toCamelCaseDeep(result) };
|
|
1156
1789
|
if (!options.json) {
|
|
1157
1790
|
context.logger.success(`创建并绑定成功:${miniProgramId}`);
|
|
@@ -1168,13 +1801,28 @@ async function remoteBind(options, context, runtime) {
|
|
|
1168
1801
|
if (verifiedId !== miniProgramId)
|
|
1169
1802
|
throw new Error('远端返回的小程序 ID 与绑定目标不一致');
|
|
1170
1803
|
await assertMiniProgramEntityMatchesCurrent(context, detail);
|
|
1171
|
-
const { changed } = await
|
|
1804
|
+
const { changed } = await migrateBasicInfo(context.packageJson.projectRoot, detail, verifiedId, runtime.fetchImpl, options.force);
|
|
1172
1805
|
const output = { changed, miniProgramId: verifiedId, remote: toCamelCaseDeep(detail) };
|
|
1173
1806
|
if (!options.json) {
|
|
1174
1807
|
context.logger.success(changed ? `绑定成功:${verifiedId}` : `已绑定:${verifiedId}`);
|
|
1175
1808
|
}
|
|
1176
1809
|
return finishRemoteCommand(options, runtime, output);
|
|
1177
1810
|
}
|
|
1811
|
+
/** 工作台扫码只读取版本和协议,复用认证与项目绑定,避免图片比对和详情输出。 */
|
|
1812
|
+
async function readRemoteMiniProgramPreview(options, runtime = {}) {
|
|
1813
|
+
const context = await createRemoteCommandContext({ env: options.env }, runtime);
|
|
1814
|
+
const miniProgramId = requireBinding(context);
|
|
1815
|
+
const detail = await context.api.getMiniProgramDetail(miniProgramId);
|
|
1816
|
+
if (requireMiniProgramId(detail) !== miniProgramId)
|
|
1817
|
+
throw new index.CliError('远端返回的小程序 ID 与绑定目标不一致');
|
|
1818
|
+
const candidate = options.mode === 'review' ? detail.pending_version : detail.status === 'published' ? detail : undefined;
|
|
1819
|
+
let protocolString = detail.protocol_string;
|
|
1820
|
+
if (options.mode === 'review' && candidate?.version) {
|
|
1821
|
+
const preview = await context.api.getPreviewInfo({ miniProgramId, version: candidate.version });
|
|
1822
|
+
protocolString = typeof preview.protocol_string === 'string' ? preview.protocol_string : undefined;
|
|
1823
|
+
}
|
|
1824
|
+
return { miniProgramId, version: candidate?.version, status: candidate?.status, protocolString };
|
|
1825
|
+
}
|
|
1178
1826
|
async function remoteInfo(options, context, runtime) {
|
|
1179
1827
|
const miniProgramId = requireBinding(context);
|
|
1180
1828
|
const detail = await context.api.getMiniProgramDetail(miniProgramId);
|
|
@@ -1189,7 +1837,7 @@ async function remoteInfo(options, context, runtime) {
|
|
|
1189
1837
|
const localIDs = new Set(localBindAppIds);
|
|
1190
1838
|
const removed = currentBindApps.filter((item) => !localIDs.has(item.appid));
|
|
1191
1839
|
const bindings = { local, current: currentBindApps, added, removed };
|
|
1192
|
-
const basicInfo = await
|
|
1840
|
+
const basicInfo = await compareBasicInfo(context.packageJson.projectRoot, detail, runtime.fetchImpl);
|
|
1193
1841
|
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 };
|
|
1194
1842
|
if (!options.json)
|
|
1195
1843
|
context.logger.info(`版本资料:${basicInfo.status}`);
|
|
@@ -1874,4 +2522,23 @@ function toCamelKey(key) {
|
|
|
1874
2522
|
return key.replace(/_([a-z0-9])/g, (_, char) => char.toUpperCase());
|
|
1875
2523
|
}
|
|
1876
2524
|
|
|
2525
|
+
var remote = /*#__PURE__*/Object.freeze({
|
|
2526
|
+
__proto__: null,
|
|
2527
|
+
readRemoteMiniProgramPreview: readRemoteMiniProgramPreview,
|
|
2528
|
+
runRemoteCommand: runRemoteCommand
|
|
2529
|
+
});
|
|
2530
|
+
|
|
2531
|
+
exports.MiniProgramProjectBindingError = MiniProgramProjectBindingError;
|
|
2532
|
+
exports.createBrowserDevPermissionState = createBrowserDevPermissionState;
|
|
2533
|
+
exports.createLocalDevLaunchToken = createLocalDevLaunchToken;
|
|
2534
|
+
exports.createMobileDevSessionRuntimePermissions = createMobileDevSessionRuntimePermissions;
|
|
2535
|
+
exports.getBoundMiniProgram = getBoundMiniProgram;
|
|
2536
|
+
exports.migrateBasicInfo = migrateBasicInfo;
|
|
2537
|
+
exports.readBoundMiniProgramId = readBoundMiniProgramId;
|
|
2538
|
+
exports.readBoundMiniProgramIdFromPackageJson = readBoundMiniProgramIdFromPackageJson;
|
|
2539
|
+
exports.readRemoteMiniProgramPreview = readRemoteMiniProgramPreview;
|
|
2540
|
+
exports.remote = remote;
|
|
2541
|
+
exports.resolveBrowserFakeContext = resolveBrowserFakeContext;
|
|
1877
2542
|
exports.runRemoteCommand = runRemoteCommand;
|
|
2543
|
+
exports.shouldSkipMiniappPlatformCsp = shouldSkipMiniappPlatformCsp;
|
|
2544
|
+
exports.validateDeployReleaseNote = validateDeployReleaseNote;
|