@weapp-tailwindcss/hbuilderx-runner 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +47 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +47 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -179,24 +179,45 @@ async function resolveHBuilderXCliInfoFromOptions(options = {}) {
|
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region src/logs.ts
|
|
181
181
|
const PROJECT_NOT_UNI_APP_RE = /不是\s*uni-app\s*项目|not\s+a\s+uni-app\s+project/i;
|
|
182
|
-
const PROJECT_TYPE_UNSUPPORTED_RE = /项目类型为(
|
|
182
|
+
const PROJECT_TYPE_UNSUPPORTED_RE = /项目类型为([^,]+),暂不支持|是\s+([^,\s][^,]*)项目,暂不支持|project\s+type.+unsupported/i;
|
|
183
|
+
const PROJECT_TARGET_UNSUPPORTED_RE = /不支持运行到\s*(鸿蒙|Harmony)|(?:Harmony|OpenHarmony).+(?:target|platform).+unsupported/i;
|
|
183
184
|
const CONFIG_LOAD_FAILED_RE = /failed to load config|error when starting dev server|Failed to resolve entry for package/i;
|
|
184
185
|
const CLI_NOT_FOUND_RE = /未找到\s*HBuilderX\s*CLI|HBUILDERX_CLI_PATH|command not found|ENOENT/i;
|
|
185
186
|
const CLI_INSTANCE_MISMATCH_RE = /当前运行的cli与正在运行的HBuilderX不匹配|cli.+(?:does not match|mismatch).+HBuilderX|try.+HBuilderX.+(?:cli|MacOS)/i;
|
|
186
187
|
const CLI_HOST_AMBIGUOUS_RE = /multiple running hbuilderx|多个.+HBuilderX.+运行|listhost.+--\s*host|--host.+listhost/i;
|
|
187
188
|
const ANDROID_TOOLCHAIN_MISSING_RE = /adb(?:\.exe)?(?:\s*[::].*)?(?:not found|ENOENT|不是内部或外部命令)|Android SDK|platform-tools/i;
|
|
188
189
|
const IOS_TOOLCHAIN_MISSING_RE = /xcrun|xcode-select|xcodebuild|simctl|DEVELOPER_DIR|iOS 模拟器|Xcode/i;
|
|
189
|
-
const
|
|
190
|
+
const HARMONY_TOOLCHAIN_MISSING_RES = [
|
|
191
|
+
/hdc(?:\.exe)?(?:\s+(?:list\s+targets|target\s+list))?\s*(?:[::]\s*)?(?:failed|not found|ENOENT|command not found)/i,
|
|
192
|
+
/未找到\s*(?:DevEco|鸿蒙)[^\r\n]*(?:SDK|工具链)/i,
|
|
193
|
+
/DevEco Studio[^\r\n]*(?:not found|未安装)/i,
|
|
194
|
+
/HDC_PATH/i
|
|
195
|
+
];
|
|
196
|
+
const HARMONY_BUILD_FAILED_RE = /Failed to resolve OhmUrl|ArkTS Compiler Error|运行包制作失败|hvigor ERROR/i;
|
|
197
|
+
const IMPORTANT_LOG_RE = /\b(?:fatal|error)\b|失败|已停止运行/i;
|
|
198
|
+
const importantLogsByBuffer = /* @__PURE__ */ new WeakMap();
|
|
190
199
|
function createLogBuffer(maxChunks = 160) {
|
|
191
200
|
const logs = [];
|
|
201
|
+
const importantLogs = [];
|
|
202
|
+
const importantLogSet = /* @__PURE__ */ new Set();
|
|
203
|
+
importantLogsByBuffer.set(logs, importantLogs);
|
|
192
204
|
return {
|
|
193
205
|
logs,
|
|
194
206
|
push(chunk) {
|
|
195
|
-
|
|
207
|
+
const text = chunk.toString();
|
|
208
|
+
logs.push(text);
|
|
196
209
|
if (logs.length > maxChunks) logs.splice(0, logs.length - maxChunks);
|
|
210
|
+
for (const item of text.split(/\r?\n/)) {
|
|
211
|
+
if (!IMPORTANT_LOG_RE.test(item)) continue;
|
|
212
|
+
const line = item.trim();
|
|
213
|
+
if (!line || importantLogSet.has(line)) continue;
|
|
214
|
+
importantLogSet.add(line);
|
|
215
|
+
importantLogs.push(line);
|
|
216
|
+
if (importantLogs.length > 24) importantLogSet.delete(importantLogs.pop());
|
|
217
|
+
}
|
|
197
218
|
},
|
|
198
219
|
text() {
|
|
199
|
-
return logs
|
|
220
|
+
return formatRecentLogs(logs);
|
|
200
221
|
}
|
|
201
222
|
};
|
|
202
223
|
}
|
|
@@ -227,11 +248,16 @@ function classifyHBuilderXOutput(output) {
|
|
|
227
248
|
message: "当前环境缺少 iOS 模拟器或 Xcode 工具链。",
|
|
228
249
|
hint: "请安装完整 Xcode,确认 xcrun simctl/xcodebuild 可用,并完成 Xcode 首次启动组件安装。"
|
|
229
250
|
};
|
|
230
|
-
if (
|
|
251
|
+
if (HARMONY_TOOLCHAIN_MISSING_RES.some((pattern) => pattern.test(output))) return {
|
|
231
252
|
kind: "harmony-toolchain-missing",
|
|
232
253
|
message: "当前环境缺少 Harmony 运行所需工具链。",
|
|
233
254
|
hint: "请安装 DevEco Studio,或设置 HDC_PATH/E2E_HBUILDERX_HARMONY_HDC_PATH 指向 hdc。"
|
|
234
255
|
};
|
|
256
|
+
if (HARMONY_BUILD_FAILED_RE.test(output)) return {
|
|
257
|
+
kind: "harmony-build-failed",
|
|
258
|
+
message: "HBuilderX 的 Harmony 工程构建失败。",
|
|
259
|
+
hint: "请查看保留的首个 ArkTS/hvigor 错误;这类错误发生在 HBuilderX 已生成 Harmony 工程之后。"
|
|
260
|
+
};
|
|
235
261
|
if (CLI_NOT_FOUND_RE.test(output)) return {
|
|
236
262
|
kind: "cli-not-found",
|
|
237
263
|
message: "未找到 HBuilderX CLI。",
|
|
@@ -242,12 +268,21 @@ function classifyHBuilderXOutput(output) {
|
|
|
242
268
|
message: "HBuilderX 将当前目录识别为非 uni-app 项目。",
|
|
243
269
|
hint: "请确认传入的是 HBuilderX 可识别的项目根目录,并检查 manifest.json、pages.json 与导入状态。"
|
|
244
270
|
};
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
271
|
+
const unsupportedTarget = output.match(PROJECT_TARGET_UNSUPPORTED_RE);
|
|
272
|
+
if (unsupportedTarget) return {
|
|
247
273
|
kind: "project-type-unsupported",
|
|
248
|
-
message: `HBuilderX
|
|
249
|
-
hint: "
|
|
274
|
+
message: `HBuilderX 不支持当前运行目标${unsupportedTarget[1] ? `:${unsupportedTarget[1]}` : ""}。`,
|
|
275
|
+
hint: "请升级到支持该项目目标的 HBuilderX channel,并确认项目路径与导入记录一致。"
|
|
250
276
|
};
|
|
277
|
+
const unsupported = output.match(PROJECT_TYPE_UNSUPPORTED_RE);
|
|
278
|
+
if (unsupported) {
|
|
279
|
+
const projectType = unsupported[1] ?? unsupported[2];
|
|
280
|
+
return {
|
|
281
|
+
kind: "project-type-unsupported",
|
|
282
|
+
message: `HBuilderX 不支持当前项目类型${projectType ? `:${projectType.trim()}` : ""}。`,
|
|
283
|
+
hint: "请确认项目已按目标平台导入,必要时先 close/open 项目后再 launch。"
|
|
284
|
+
};
|
|
285
|
+
}
|
|
251
286
|
if (CONFIG_LOAD_FAILED_RE.test(output)) return {
|
|
252
287
|
kind: "config-load-failed",
|
|
253
288
|
message: "HBuilderX/Vite 配置加载失败。",
|
|
@@ -267,7 +302,9 @@ function createTimeoutIssue() {
|
|
|
267
302
|
}
|
|
268
303
|
function formatRecentLogs(logs, maxLength = 6e3) {
|
|
269
304
|
const output = logs.join("");
|
|
270
|
-
|
|
305
|
+
const recent = output.length > maxLength ? output.slice(-maxLength) : output;
|
|
306
|
+
const important = (importantLogsByBuffer.get(logs) ?? []).filter((line) => !recent.includes(line));
|
|
307
|
+
return important.length > 0 ? `关键错误:\n${important.join("\n")}\n\n最近日志:\n${recent}` : recent;
|
|
271
308
|
}
|
|
272
309
|
//#endregion
|
|
273
310
|
//#region src/process.ts
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ type HBuilderXAppPlatform = 'app-android' | 'app-ios' | 'app-harmony';
|
|
|
11
11
|
type HBuilderXPlatform = HBuilderXMiniProgramPlatform | HBuilderXAppPlatform;
|
|
12
12
|
type HBuilderXChannel = 'auto' | 'stable' | 'alpha';
|
|
13
13
|
type HBuilderXResolvedChannel = Exclude<HBuilderXChannel, 'auto'> | 'unknown';
|
|
14
|
-
type HBuilderXIssueKind = 'cli-not-found' | 'cli-instance-mismatch' | 'cli-host-ambiguous' | 'project-not-uni-app' | 'project-type-unsupported' | 'config-load-failed' | 'android-toolchain-missing' | 'ios-toolchain-missing' | 'harmony-toolchain-missing' | 'timeout' | 'process-exit' | 'unknown';
|
|
14
|
+
type HBuilderXIssueKind = 'cli-not-found' | 'cli-instance-mismatch' | 'cli-host-ambiguous' | 'project-not-uni-app' | 'project-type-unsupported' | 'config-load-failed' | 'android-toolchain-missing' | 'ios-toolchain-missing' | 'harmony-toolchain-missing' | 'harmony-build-failed' | 'timeout' | 'process-exit' | 'unknown';
|
|
15
15
|
interface HBuilderXIssue {
|
|
16
16
|
kind: HBuilderXIssueKind;
|
|
17
17
|
message: string;
|
package/dist/index.mjs
CHANGED
|
@@ -153,24 +153,45 @@ async function resolveHBuilderXCliInfoFromOptions(options = {}) {
|
|
|
153
153
|
//#endregion
|
|
154
154
|
//#region src/logs.ts
|
|
155
155
|
const PROJECT_NOT_UNI_APP_RE = /不是\s*uni-app\s*项目|not\s+a\s+uni-app\s+project/i;
|
|
156
|
-
const PROJECT_TYPE_UNSUPPORTED_RE = /项目类型为(
|
|
156
|
+
const PROJECT_TYPE_UNSUPPORTED_RE = /项目类型为([^,]+),暂不支持|是\s+([^,\s][^,]*)项目,暂不支持|project\s+type.+unsupported/i;
|
|
157
|
+
const PROJECT_TARGET_UNSUPPORTED_RE = /不支持运行到\s*(鸿蒙|Harmony)|(?:Harmony|OpenHarmony).+(?:target|platform).+unsupported/i;
|
|
157
158
|
const CONFIG_LOAD_FAILED_RE = /failed to load config|error when starting dev server|Failed to resolve entry for package/i;
|
|
158
159
|
const CLI_NOT_FOUND_RE = /未找到\s*HBuilderX\s*CLI|HBUILDERX_CLI_PATH|command not found|ENOENT/i;
|
|
159
160
|
const CLI_INSTANCE_MISMATCH_RE = /当前运行的cli与正在运行的HBuilderX不匹配|cli.+(?:does not match|mismatch).+HBuilderX|try.+HBuilderX.+(?:cli|MacOS)/i;
|
|
160
161
|
const CLI_HOST_AMBIGUOUS_RE = /multiple running hbuilderx|多个.+HBuilderX.+运行|listhost.+--\s*host|--host.+listhost/i;
|
|
161
162
|
const ANDROID_TOOLCHAIN_MISSING_RE = /adb(?:\.exe)?(?:\s*[::].*)?(?:not found|ENOENT|不是内部或外部命令)|Android SDK|platform-tools/i;
|
|
162
163
|
const IOS_TOOLCHAIN_MISSING_RE = /xcrun|xcode-select|xcodebuild|simctl|DEVELOPER_DIR|iOS 模拟器|Xcode/i;
|
|
163
|
-
const
|
|
164
|
+
const HARMONY_TOOLCHAIN_MISSING_RES = [
|
|
165
|
+
/hdc(?:\.exe)?(?:\s+(?:list\s+targets|target\s+list))?\s*(?:[::]\s*)?(?:failed|not found|ENOENT|command not found)/i,
|
|
166
|
+
/未找到\s*(?:DevEco|鸿蒙)[^\r\n]*(?:SDK|工具链)/i,
|
|
167
|
+
/DevEco Studio[^\r\n]*(?:not found|未安装)/i,
|
|
168
|
+
/HDC_PATH/i
|
|
169
|
+
];
|
|
170
|
+
const HARMONY_BUILD_FAILED_RE = /Failed to resolve OhmUrl|ArkTS Compiler Error|运行包制作失败|hvigor ERROR/i;
|
|
171
|
+
const IMPORTANT_LOG_RE = /\b(?:fatal|error)\b|失败|已停止运行/i;
|
|
172
|
+
const importantLogsByBuffer = /* @__PURE__ */ new WeakMap();
|
|
164
173
|
function createLogBuffer(maxChunks = 160) {
|
|
165
174
|
const logs = [];
|
|
175
|
+
const importantLogs = [];
|
|
176
|
+
const importantLogSet = /* @__PURE__ */ new Set();
|
|
177
|
+
importantLogsByBuffer.set(logs, importantLogs);
|
|
166
178
|
return {
|
|
167
179
|
logs,
|
|
168
180
|
push(chunk) {
|
|
169
|
-
|
|
181
|
+
const text = chunk.toString();
|
|
182
|
+
logs.push(text);
|
|
170
183
|
if (logs.length > maxChunks) logs.splice(0, logs.length - maxChunks);
|
|
184
|
+
for (const item of text.split(/\r?\n/)) {
|
|
185
|
+
if (!IMPORTANT_LOG_RE.test(item)) continue;
|
|
186
|
+
const line = item.trim();
|
|
187
|
+
if (!line || importantLogSet.has(line)) continue;
|
|
188
|
+
importantLogSet.add(line);
|
|
189
|
+
importantLogs.push(line);
|
|
190
|
+
if (importantLogs.length > 24) importantLogSet.delete(importantLogs.pop());
|
|
191
|
+
}
|
|
171
192
|
},
|
|
172
193
|
text() {
|
|
173
|
-
return logs
|
|
194
|
+
return formatRecentLogs(logs);
|
|
174
195
|
}
|
|
175
196
|
};
|
|
176
197
|
}
|
|
@@ -201,11 +222,16 @@ function classifyHBuilderXOutput(output) {
|
|
|
201
222
|
message: "当前环境缺少 iOS 模拟器或 Xcode 工具链。",
|
|
202
223
|
hint: "请安装完整 Xcode,确认 xcrun simctl/xcodebuild 可用,并完成 Xcode 首次启动组件安装。"
|
|
203
224
|
};
|
|
204
|
-
if (
|
|
225
|
+
if (HARMONY_TOOLCHAIN_MISSING_RES.some((pattern) => pattern.test(output))) return {
|
|
205
226
|
kind: "harmony-toolchain-missing",
|
|
206
227
|
message: "当前环境缺少 Harmony 运行所需工具链。",
|
|
207
228
|
hint: "请安装 DevEco Studio,或设置 HDC_PATH/E2E_HBUILDERX_HARMONY_HDC_PATH 指向 hdc。"
|
|
208
229
|
};
|
|
230
|
+
if (HARMONY_BUILD_FAILED_RE.test(output)) return {
|
|
231
|
+
kind: "harmony-build-failed",
|
|
232
|
+
message: "HBuilderX 的 Harmony 工程构建失败。",
|
|
233
|
+
hint: "请查看保留的首个 ArkTS/hvigor 错误;这类错误发生在 HBuilderX 已生成 Harmony 工程之后。"
|
|
234
|
+
};
|
|
209
235
|
if (CLI_NOT_FOUND_RE.test(output)) return {
|
|
210
236
|
kind: "cli-not-found",
|
|
211
237
|
message: "未找到 HBuilderX CLI。",
|
|
@@ -216,12 +242,21 @@ function classifyHBuilderXOutput(output) {
|
|
|
216
242
|
message: "HBuilderX 将当前目录识别为非 uni-app 项目。",
|
|
217
243
|
hint: "请确认传入的是 HBuilderX 可识别的项目根目录,并检查 manifest.json、pages.json 与导入状态。"
|
|
218
244
|
};
|
|
219
|
-
const
|
|
220
|
-
if (
|
|
245
|
+
const unsupportedTarget = output.match(PROJECT_TARGET_UNSUPPORTED_RE);
|
|
246
|
+
if (unsupportedTarget) return {
|
|
221
247
|
kind: "project-type-unsupported",
|
|
222
|
-
message: `HBuilderX
|
|
223
|
-
hint: "
|
|
248
|
+
message: `HBuilderX 不支持当前运行目标${unsupportedTarget[1] ? `:${unsupportedTarget[1]}` : ""}。`,
|
|
249
|
+
hint: "请升级到支持该项目目标的 HBuilderX channel,并确认项目路径与导入记录一致。"
|
|
224
250
|
};
|
|
251
|
+
const unsupported = output.match(PROJECT_TYPE_UNSUPPORTED_RE);
|
|
252
|
+
if (unsupported) {
|
|
253
|
+
const projectType = unsupported[1] ?? unsupported[2];
|
|
254
|
+
return {
|
|
255
|
+
kind: "project-type-unsupported",
|
|
256
|
+
message: `HBuilderX 不支持当前项目类型${projectType ? `:${projectType.trim()}` : ""}。`,
|
|
257
|
+
hint: "请确认项目已按目标平台导入,必要时先 close/open 项目后再 launch。"
|
|
258
|
+
};
|
|
259
|
+
}
|
|
225
260
|
if (CONFIG_LOAD_FAILED_RE.test(output)) return {
|
|
226
261
|
kind: "config-load-failed",
|
|
227
262
|
message: "HBuilderX/Vite 配置加载失败。",
|
|
@@ -241,7 +276,9 @@ function createTimeoutIssue() {
|
|
|
241
276
|
}
|
|
242
277
|
function formatRecentLogs(logs, maxLength = 6e3) {
|
|
243
278
|
const output = logs.join("");
|
|
244
|
-
|
|
279
|
+
const recent = output.length > maxLength ? output.slice(-maxLength) : output;
|
|
280
|
+
const important = (importantLogsByBuffer.get(logs) ?? []).filter((line) => !recent.includes(line));
|
|
281
|
+
return important.length > 0 ? `关键错误:\n${important.join("\n")}\n\n最近日志:\n${recent}` : recent;
|
|
245
282
|
}
|
|
246
283
|
//#endregion
|
|
247
284
|
//#region src/process.ts
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/hbuilderx-runner",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"description": "Stable HBuilderX CLI runner utilities for weapp-tailwindcss local e2e workflows.",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|