@weapp-tailwindcss/hbuilderx-runner 0.0.2 → 0.0.4
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 +81 -6
- package/dist/index.d.ts +12 -3
- package/dist/index.mjs +75 -4
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -22,12 +22,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
}) : target, mod));
|
|
23
23
|
//#endregion
|
|
24
24
|
let node_fs_promises = require("node:fs/promises");
|
|
25
|
-
node_fs_promises = __toESM(node_fs_promises);
|
|
25
|
+
node_fs_promises = __toESM(node_fs_promises, 1);
|
|
26
26
|
let node_child_process = require("node:child_process");
|
|
27
27
|
let node_path = require("node:path");
|
|
28
|
-
node_path = __toESM(node_path);
|
|
28
|
+
node_path = __toESM(node_path, 1);
|
|
29
29
|
let node_process = require("node:process");
|
|
30
|
-
node_process = __toESM(node_process);
|
|
30
|
+
node_process = __toESM(node_process, 1);
|
|
31
31
|
//#region src/fs.ts
|
|
32
32
|
async function fileExists(file) {
|
|
33
33
|
try {
|
|
@@ -492,6 +492,71 @@ function assertIosSimulatorToolchain(env = node_process.default.env) {
|
|
|
492
492
|
"如果 firstLaunchStatus 不是 ready,请先打开 Xcode 完成首次组件安装,或执行 sudo xcodebuild -runFirstLaunch。"
|
|
493
493
|
].join("\n"));
|
|
494
494
|
}
|
|
495
|
+
function parseIosSimulatorDevices(output) {
|
|
496
|
+
const jsonStart = output.indexOf("{");
|
|
497
|
+
const jsonEnd = output.lastIndexOf("}");
|
|
498
|
+
if (jsonStart < 0 || jsonEnd < jsonStart) return [];
|
|
499
|
+
let value;
|
|
500
|
+
try {
|
|
501
|
+
value = JSON.parse(output.slice(jsonStart, jsonEnd + 1));
|
|
502
|
+
} catch {
|
|
503
|
+
return [];
|
|
504
|
+
}
|
|
505
|
+
if (!value || typeof value !== "object" || !("devices" in value)) return [];
|
|
506
|
+
const devices = value.devices;
|
|
507
|
+
if (!devices || typeof devices !== "object") return [];
|
|
508
|
+
return Object.values(devices).flatMap((runtimeDevices) => {
|
|
509
|
+
if (!Array.isArray(runtimeDevices)) return [];
|
|
510
|
+
return runtimeDevices.flatMap((device) => {
|
|
511
|
+
if (!device || typeof device !== "object" || !("udid" in device) || typeof device.udid !== "string" || "isAvailable" in device && device.isAvailable === false) return [];
|
|
512
|
+
return [{
|
|
513
|
+
..."lastBootedAt" in device && typeof device.lastBootedAt === "string" ? { lastBootedAt: device.lastBootedAt } : {},
|
|
514
|
+
name: "name" in device && typeof device.name === "string" ? device.name : device.udid,
|
|
515
|
+
state: "state" in device && typeof device.state === "string" ? device.state : "Unknown",
|
|
516
|
+
udid: device.udid
|
|
517
|
+
}];
|
|
518
|
+
});
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
function selectPreferredIosSimulatorDevice(devices) {
|
|
522
|
+
return [...devices].sort((left, right) => {
|
|
523
|
+
const stateDifference = Number(right.state === "Booted") - Number(left.state === "Booted");
|
|
524
|
+
if (stateDifference !== 0) return stateDifference;
|
|
525
|
+
const leftLastBootedAt = Date.parse(left.lastBootedAt ?? "");
|
|
526
|
+
const rightLastBootedAt = Date.parse(right.lastBootedAt ?? "");
|
|
527
|
+
const lastBootedDifference = (Number.isNaN(rightLastBootedAt) ? 0 : rightLastBootedAt) - (Number.isNaN(leftLastBootedAt) ? 0 : leftLastBootedAt);
|
|
528
|
+
if (lastBootedDifference !== 0) return lastBootedDifference;
|
|
529
|
+
return Number(/^iPhone\b/.test(right.name)) - Number(/^iPhone\b/.test(left.name));
|
|
530
|
+
})[0];
|
|
531
|
+
}
|
|
532
|
+
function resolveIosSimulatorDeviceId(env = node_process.default.env) {
|
|
533
|
+
const explicitDeviceId = env.E2E_HBUILDERX_IOS_DEVICE_ID;
|
|
534
|
+
if (explicitDeviceId) return explicitDeviceId;
|
|
535
|
+
const booted = runTool("xcrun", [
|
|
536
|
+
"simctl",
|
|
537
|
+
"list",
|
|
538
|
+
"devices",
|
|
539
|
+
"booted",
|
|
540
|
+
"--json"
|
|
541
|
+
]);
|
|
542
|
+
const bootedDevice = selectPreferredIosSimulatorDevice(booted.ok ? parseIosSimulatorDevices(booted.output) : []);
|
|
543
|
+
if (bootedDevice) return bootedDevice.udid;
|
|
544
|
+
const available = runTool("xcrun", [
|
|
545
|
+
"simctl",
|
|
546
|
+
"list",
|
|
547
|
+
"devices",
|
|
548
|
+
"available",
|
|
549
|
+
"--json"
|
|
550
|
+
]);
|
|
551
|
+
const availableDevice = selectPreferredIosSimulatorDevice(available.ok ? parseIosSimulatorDevices(available.output) : []);
|
|
552
|
+
if (availableDevice) return availableDevice.udid;
|
|
553
|
+
throw new Error([
|
|
554
|
+
"未找到可用于 HBuilderX app-ios E2E 的 iOS 模拟器。",
|
|
555
|
+
`booted: ${booted.output || "empty"}`,
|
|
556
|
+
`available: ${available.output || "empty"}`,
|
|
557
|
+
"请先在 Xcode 中安装并启动一个模拟器,或设置 E2E_HBUILDERX_IOS_DEVICE_ID。"
|
|
558
|
+
].join("\n"));
|
|
559
|
+
}
|
|
495
560
|
function resolveHdcCommand(env = node_process.default.env) {
|
|
496
561
|
const candidates = [
|
|
497
562
|
env.DEMO_VISUAL_HARMONY_HDC_PATH,
|
|
@@ -507,14 +572,20 @@ function resolveHdcCommand(env = node_process.default.env) {
|
|
|
507
572
|
"如需指定设备,请设置 E2E_HBUILDERX_HARMONY_DEVICE_ID 或 DEMO_VISUAL_HARMONY_DEVICE_ID。"
|
|
508
573
|
].join("\n"));
|
|
509
574
|
}
|
|
510
|
-
function
|
|
575
|
+
function parseHdcTargets(output) {
|
|
576
|
+
return output.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !/^\[empty\]$/i.test(line));
|
|
577
|
+
}
|
|
578
|
+
function assertHarmonyToolchain(env = node_process.default.env, deviceId) {
|
|
511
579
|
const hdc = resolveHdcCommand(env);
|
|
512
580
|
const result = runTool(hdc, ["list", "targets"]);
|
|
513
|
-
|
|
581
|
+
const targets = result.ok ? parseHdcTargets(result.output) : [];
|
|
582
|
+
if (!result.ok || targets.length === 0 || deviceId && !targets.includes(deviceId)) {
|
|
514
583
|
const issue = classifyHBuilderXOutput(result.output);
|
|
515
584
|
throw new Error([
|
|
516
585
|
"当前 Harmony hdc 无法列出设备,无法运行 HBuilderX app-harmony E2E。",
|
|
517
|
-
result.output || `exit=${result.status} signal=${result.signal ?? "none"}`,
|
|
586
|
+
result.output || `targets=empty exit=${result.status} signal=${result.signal ?? "none"}`,
|
|
587
|
+
`requestedDevice=${deviceId ?? "任意已连接设备"}`,
|
|
588
|
+
`detectedTargets=${targets.join(", ") || "empty"}`,
|
|
518
589
|
`issue=${issue.kind}: ${issue.message}`,
|
|
519
590
|
"请确认 Harmony 模拟器或真机已连接。"
|
|
520
591
|
].join("\n"));
|
|
@@ -545,15 +616,19 @@ exports.hbuilderxPnpmArgs = hbuilderxPnpmArgs;
|
|
|
545
616
|
exports.killProcessTree = killProcessTree;
|
|
546
617
|
exports.launchProject = launchProject;
|
|
547
618
|
exports.openProject = openProject;
|
|
619
|
+
exports.parseHdcTargets = parseHdcTargets;
|
|
620
|
+
exports.parseIosSimulatorDevices = parseIosSimulatorDevices;
|
|
548
621
|
exports.prepareProject = prepareProject;
|
|
549
622
|
exports.readUtf8 = readUtf8;
|
|
550
623
|
exports.resolveAdbCommand = resolveAdbCommand;
|
|
551
624
|
exports.resolveHBuilderXCli = resolveHBuilderXCli;
|
|
552
625
|
exports.resolveHBuilderXCliInfo = resolveHBuilderXCliInfo;
|
|
553
626
|
exports.resolveHdcCommand = resolveHdcCommand;
|
|
627
|
+
exports.resolveIosSimulatorDeviceId = resolveIosSimulatorDeviceId;
|
|
554
628
|
exports.runCommand = runCommand;
|
|
555
629
|
exports.runPnpmCommand = runPnpmCommand;
|
|
556
630
|
exports.runTool = runTool;
|
|
631
|
+
exports.selectPreferredIosSimulatorDevice = selectPreferredIosSimulatorDevice;
|
|
557
632
|
exports.spawnCommand = spawnCommand;
|
|
558
633
|
exports.spawnPnpmCommand = spawnPnpmCommand;
|
|
559
634
|
exports.startLaunch = startLaunch;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ChildProcess } from "node:child_process";
|
|
2
2
|
import { Buffer } from "node:buffer";
|
|
3
|
-
|
|
4
3
|
//#region src/fs.d.ts
|
|
5
4
|
declare function fileExists(file: string): Promise<boolean>;
|
|
6
5
|
declare function readUtf8(file: string): Promise<string>;
|
|
@@ -138,7 +137,17 @@ declare function runTool(command: string, args: string[]): ToolResult;
|
|
|
138
137
|
declare function resolveAdbCommand(env?: NodeJS.ProcessEnv): AndroidToolchain;
|
|
139
138
|
declare function assertAndroidToolchain(env?: NodeJS.ProcessEnv): Record<string, string> | undefined;
|
|
140
139
|
declare function assertIosSimulatorToolchain(env?: NodeJS.ProcessEnv): void;
|
|
140
|
+
interface IosSimulatorDevice {
|
|
141
|
+
lastBootedAt?: string;
|
|
142
|
+
name: string;
|
|
143
|
+
state: string;
|
|
144
|
+
udid: string;
|
|
145
|
+
}
|
|
146
|
+
declare function parseIosSimulatorDevices(output: string): IosSimulatorDevice[];
|
|
147
|
+
declare function selectPreferredIosSimulatorDevice(devices: IosSimulatorDevice[]): IosSimulatorDevice | undefined;
|
|
148
|
+
declare function resolveIosSimulatorDeviceId(env?: NodeJS.ProcessEnv): string;
|
|
141
149
|
declare function resolveHdcCommand(env?: NodeJS.ProcessEnv): string;
|
|
142
|
-
declare function
|
|
150
|
+
declare function parseHdcTargets(output: string): string[];
|
|
151
|
+
declare function assertHarmonyToolchain(env?: NodeJS.ProcessEnv, deviceId?: string): string;
|
|
143
152
|
//#endregion
|
|
144
|
-
export { AndroidToolchain, CommandExit, HBuilderXAppPlatform, HBuilderXCliResolution, HBuilderXCliResolutionSource, HBuilderXCommandError, HBuilderXCommandOptions, HBuilderXCommandResult, HBuilderXIssue, HBuilderXIssueKind, HBuilderXLaunchOptions, HBuilderXMiniProgramPlatform, HBuilderXPlatform, HBuilderXProjectOptions, SpawnedHBuilderXCommand, ToolResult, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, runCommand, runPnpmCommand, runTool, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
|
153
|
+
export { AndroidToolchain, CommandExit, HBuilderXAppPlatform, HBuilderXCliResolution, HBuilderXCliResolutionSource, HBuilderXCommandError, HBuilderXCommandOptions, HBuilderXCommandResult, HBuilderXIssue, HBuilderXIssueKind, HBuilderXLaunchOptions, HBuilderXMiniProgramPlatform, HBuilderXPlatform, HBuilderXProjectOptions, IosSimulatorDevice, SpawnedHBuilderXCommand, ToolResult, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, parseHdcTargets, parseIosSimulatorDevices, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, resolveIosSimulatorDeviceId, runCommand, runPnpmCommand, runTool, selectPreferredIosSimulatorDevice, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
package/dist/index.mjs
CHANGED
|
@@ -466,6 +466,71 @@ function assertIosSimulatorToolchain(env = process.env) {
|
|
|
466
466
|
"如果 firstLaunchStatus 不是 ready,请先打开 Xcode 完成首次组件安装,或执行 sudo xcodebuild -runFirstLaunch。"
|
|
467
467
|
].join("\n"));
|
|
468
468
|
}
|
|
469
|
+
function parseIosSimulatorDevices(output) {
|
|
470
|
+
const jsonStart = output.indexOf("{");
|
|
471
|
+
const jsonEnd = output.lastIndexOf("}");
|
|
472
|
+
if (jsonStart < 0 || jsonEnd < jsonStart) return [];
|
|
473
|
+
let value;
|
|
474
|
+
try {
|
|
475
|
+
value = JSON.parse(output.slice(jsonStart, jsonEnd + 1));
|
|
476
|
+
} catch {
|
|
477
|
+
return [];
|
|
478
|
+
}
|
|
479
|
+
if (!value || typeof value !== "object" || !("devices" in value)) return [];
|
|
480
|
+
const devices = value.devices;
|
|
481
|
+
if (!devices || typeof devices !== "object") return [];
|
|
482
|
+
return Object.values(devices).flatMap((runtimeDevices) => {
|
|
483
|
+
if (!Array.isArray(runtimeDevices)) return [];
|
|
484
|
+
return runtimeDevices.flatMap((device) => {
|
|
485
|
+
if (!device || typeof device !== "object" || !("udid" in device) || typeof device.udid !== "string" || "isAvailable" in device && device.isAvailable === false) return [];
|
|
486
|
+
return [{
|
|
487
|
+
..."lastBootedAt" in device && typeof device.lastBootedAt === "string" ? { lastBootedAt: device.lastBootedAt } : {},
|
|
488
|
+
name: "name" in device && typeof device.name === "string" ? device.name : device.udid,
|
|
489
|
+
state: "state" in device && typeof device.state === "string" ? device.state : "Unknown",
|
|
490
|
+
udid: device.udid
|
|
491
|
+
}];
|
|
492
|
+
});
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
function selectPreferredIosSimulatorDevice(devices) {
|
|
496
|
+
return [...devices].sort((left, right) => {
|
|
497
|
+
const stateDifference = Number(right.state === "Booted") - Number(left.state === "Booted");
|
|
498
|
+
if (stateDifference !== 0) return stateDifference;
|
|
499
|
+
const leftLastBootedAt = Date.parse(left.lastBootedAt ?? "");
|
|
500
|
+
const rightLastBootedAt = Date.parse(right.lastBootedAt ?? "");
|
|
501
|
+
const lastBootedDifference = (Number.isNaN(rightLastBootedAt) ? 0 : rightLastBootedAt) - (Number.isNaN(leftLastBootedAt) ? 0 : leftLastBootedAt);
|
|
502
|
+
if (lastBootedDifference !== 0) return lastBootedDifference;
|
|
503
|
+
return Number(/^iPhone\b/.test(right.name)) - Number(/^iPhone\b/.test(left.name));
|
|
504
|
+
})[0];
|
|
505
|
+
}
|
|
506
|
+
function resolveIosSimulatorDeviceId(env = process.env) {
|
|
507
|
+
const explicitDeviceId = env.E2E_HBUILDERX_IOS_DEVICE_ID;
|
|
508
|
+
if (explicitDeviceId) return explicitDeviceId;
|
|
509
|
+
const booted = runTool("xcrun", [
|
|
510
|
+
"simctl",
|
|
511
|
+
"list",
|
|
512
|
+
"devices",
|
|
513
|
+
"booted",
|
|
514
|
+
"--json"
|
|
515
|
+
]);
|
|
516
|
+
const bootedDevice = selectPreferredIosSimulatorDevice(booted.ok ? parseIosSimulatorDevices(booted.output) : []);
|
|
517
|
+
if (bootedDevice) return bootedDevice.udid;
|
|
518
|
+
const available = runTool("xcrun", [
|
|
519
|
+
"simctl",
|
|
520
|
+
"list",
|
|
521
|
+
"devices",
|
|
522
|
+
"available",
|
|
523
|
+
"--json"
|
|
524
|
+
]);
|
|
525
|
+
const availableDevice = selectPreferredIosSimulatorDevice(available.ok ? parseIosSimulatorDevices(available.output) : []);
|
|
526
|
+
if (availableDevice) return availableDevice.udid;
|
|
527
|
+
throw new Error([
|
|
528
|
+
"未找到可用于 HBuilderX app-ios E2E 的 iOS 模拟器。",
|
|
529
|
+
`booted: ${booted.output || "empty"}`,
|
|
530
|
+
`available: ${available.output || "empty"}`,
|
|
531
|
+
"请先在 Xcode 中安装并启动一个模拟器,或设置 E2E_HBUILDERX_IOS_DEVICE_ID。"
|
|
532
|
+
].join("\n"));
|
|
533
|
+
}
|
|
469
534
|
function resolveHdcCommand(env = process.env) {
|
|
470
535
|
const candidates = [
|
|
471
536
|
env.DEMO_VISUAL_HARMONY_HDC_PATH,
|
|
@@ -481,14 +546,20 @@ function resolveHdcCommand(env = process.env) {
|
|
|
481
546
|
"如需指定设备,请设置 E2E_HBUILDERX_HARMONY_DEVICE_ID 或 DEMO_VISUAL_HARMONY_DEVICE_ID。"
|
|
482
547
|
].join("\n"));
|
|
483
548
|
}
|
|
484
|
-
function
|
|
549
|
+
function parseHdcTargets(output) {
|
|
550
|
+
return output.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !/^\[empty\]$/i.test(line));
|
|
551
|
+
}
|
|
552
|
+
function assertHarmonyToolchain(env = process.env, deviceId) {
|
|
485
553
|
const hdc = resolveHdcCommand(env);
|
|
486
554
|
const result = runTool(hdc, ["list", "targets"]);
|
|
487
|
-
|
|
555
|
+
const targets = result.ok ? parseHdcTargets(result.output) : [];
|
|
556
|
+
if (!result.ok || targets.length === 0 || deviceId && !targets.includes(deviceId)) {
|
|
488
557
|
const issue = classifyHBuilderXOutput(result.output);
|
|
489
558
|
throw new Error([
|
|
490
559
|
"当前 Harmony hdc 无法列出设备,无法运行 HBuilderX app-harmony E2E。",
|
|
491
|
-
result.output || `exit=${result.status} signal=${result.signal ?? "none"}`,
|
|
560
|
+
result.output || `targets=empty exit=${result.status} signal=${result.signal ?? "none"}`,
|
|
561
|
+
`requestedDevice=${deviceId ?? "任意已连接设备"}`,
|
|
562
|
+
`detectedTargets=${targets.join(", ") || "empty"}`,
|
|
492
563
|
`issue=${issue.kind}: ${issue.message}`,
|
|
493
564
|
"请确认 Harmony 模拟器或真机已连接。"
|
|
494
565
|
].join("\n"));
|
|
@@ -496,4 +567,4 @@ function assertHarmonyToolchain(env = process.env) {
|
|
|
496
567
|
return hdc;
|
|
497
568
|
}
|
|
498
569
|
//#endregion
|
|
499
|
-
export { HBuilderXCommandError, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, runCommand, runPnpmCommand, runTool, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
|
570
|
+
export { HBuilderXCommandError, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXWindowsExecutable, fileExists, findRunningHBuilderXCli, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, killProcessTree, launchProject, openProject, parseHdcTargets, parseIosSimulatorDevices, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHdcCommand, resolveIosSimulatorDeviceId, runCommand, runPnpmCommand, runTool, selectPreferredIosSimulatorDevice, spawnCommand, spawnPnpmCommand, startLaunch, wait };
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-tailwindcss/hbuilderx-runner",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.4",
|
|
4
5
|
"description": "Stable HBuilderX CLI runner utilities for weapp-tailwindcss local e2e workflows.",
|
|
5
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
6
7
|
"license": "MIT",
|