@weapp-tailwindcss/hbuilderx-runner 0.1.7 → 0.1.9

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
20
20
  value: mod,
21
21
  enumerable: true
22
22
  }) : target, mod));
23
- //#endregion
24
23
  let node_fs_promises = require("node:fs/promises");
25
24
  node_fs_promises = __toESM(node_fs_promises, 1);
26
25
  let node_path = require("node:path");
@@ -31,7 +30,7 @@ let node_buffer = require("node:buffer");
31
30
  let node_child_process = require("node:child_process");
32
31
  let cross_spawn = require("cross-spawn");
33
32
  cross_spawn = __toESM(cross_spawn, 1);
34
- //#region src/fs.ts
33
+ // src/fs.ts
35
34
  async function fileExists(file) {
36
35
  try {
37
36
  await node_fs_promises.default.access(file);
@@ -46,8 +45,7 @@ async function readUtf8(file) {
46
45
  function wait(ms) {
47
46
  return new Promise((resolve) => setTimeout(resolve, ms));
48
47
  }
49
- //#endregion
50
- //#region src/hbuilderx/configured-cli.ts
48
+ // src/hbuilderx/configured-cli.ts
51
49
  const macOSStableCli = "/Applications/HBuilderX.app/Contents/MacOS/cli";
52
50
  const macOSAlphaCli = "/Applications/HBuilderX-Alpha.app/Contents/MacOS/cli";
53
51
  function resolveCandidateSource(candidate, env) {
@@ -73,8 +71,7 @@ async function resolveConfiguredCli(options) {
73
71
  source: "env"
74
72
  };
75
73
  }
76
- //#endregion
77
- //#region src/hbuilderx/discovery.ts
74
+ // src/hbuilderx/discovery.ts
78
75
  function unique(items) {
79
76
  return [...new Set(items)];
80
77
  }
@@ -226,8 +223,7 @@ async function resolveHBuilderXCliInfoFromOptions(options = {}) {
226
223
  };
227
224
  throw new Error([`未找到 HBuilderX ${channel === "auto" ? "" : `${channel} `}CLI。`, "请安装 HBuilderX,或设置 HBUILDERX_CLI_PATH=/path/to/cli。"].join(""));
228
225
  }
229
- //#endregion
230
- //#region src/logs.ts
226
+ // src/logs.ts
231
227
  const PROJECT_NOT_UNI_APP_RE = /不是\s*uni-app\s*项目|not\s+a\s+uni-app\s+project/i;
232
228
  const PROJECT_TYPE_UNSUPPORTED_RE = /项目类型为([^,]+),暂不支持|是\s+([^,\s][^,]*)项目,暂不支持|project\s+type.+unsupported/i;
233
229
  const PROJECT_TARGET_UNSUPPORTED_RE = /不支持运行到\s*(鸿蒙|Harmony)|(?:Harmony|OpenHarmony).+(?:target|platform).+unsupported/i;
@@ -356,8 +352,7 @@ function formatRecentLogs(logs, maxLength = 6e3) {
356
352
  const important = (importantLogsByBuffer.get(logs) ?? []).filter((line) => !recent.includes(line));
357
353
  return important.length > 0 ? `关键错误:\n${important.join("\n")}\n\n最近日志:\n${recent}` : recent;
358
354
  }
359
- //#endregion
360
- //#region src/process/termination.ts
355
+ // src/process/termination.ts
361
356
  const ownedGroups = /* @__PURE__ */ new WeakMap();
362
357
  const closedChildren = /* @__PURE__ */ new WeakSet();
363
358
  const shutdownWaitMs = 1e3;
@@ -441,6 +436,7 @@ function waitForCleanup(closed, isGroupGone) {
441
436
  async function stopProcessTree(child, closed, signal) {
442
437
  let group = ownedGroups.get(child);
443
438
  const errors = [];
439
+ const exitRaces = [];
444
440
  const isGroupGone = () => {
445
441
  if (!group) return true;
446
442
  try {
@@ -458,7 +454,8 @@ async function stopProcessTree(child, closed, signal) {
458
454
  try {
459
455
  signalOwnedTree(child, nextSignal, group);
460
456
  } catch (error) {
461
- errors.push(error);
457
+ if (node_process.default.platform === "darwin" && group && (child.exitCode !== null || child.signalCode !== null) && error.code === "EPERM") exitRaces.push(error);
458
+ else errors.push(error);
462
459
  }
463
460
  try {
464
461
  if (await waitForCleanup(closed, isGroupGone)) {
@@ -469,11 +466,11 @@ async function stopProcessTree(child, closed, signal) {
469
466
  errors.push(error);
470
467
  }
471
468
  }
472
- const details = errors.map((error) => error instanceof Error ? error.message : String(error)).join("\n");
473
- throw new AggregateError(errors, `子进程 pid=${child.pid ?? "unknown"} 的有界清理未成功:需确认 close 和本轮进程组结束\n${details}`.trim());
469
+ const failures = [...errors, ...exitRaces];
470
+ const details = failures.map((error) => error instanceof Error ? error.message : String(error)).join("\n");
471
+ throw new AggregateError(failures, `子进程 pid=${child.pid ?? "unknown"} 的有界清理未成功:需确认 close 和本轮进程组结束\n${details}`.trim());
474
472
  }
475
- //#endregion
476
- //#region src/process.ts
473
+ // src/process.ts
477
474
  var HBuilderXCommandError = class extends Error {
478
475
  result;
479
476
  cleanupError;
@@ -624,8 +621,7 @@ function createProcessExitTracker(child) {
624
621
  }
625
622
  };
626
623
  }
627
- //#endregion
628
- //#region src/hbuilderx/hosts.ts
624
+ // src/hbuilderx/hosts.ts
629
625
  const ansiRE = new RegExp(`${String.fromCharCode(27)}\\[[\\d;]*m`, "g");
630
626
  function stripAnsi(value) {
631
627
  return value.replace(ansiRE, "");
@@ -738,8 +734,7 @@ async function connectHBuilderXHost(options) {
738
734
  } while (Date.now() < deadline);
739
735
  throw timeoutError(["listhost"]);
740
736
  }
741
- //#endregion
742
- //#region src/hbuilderx/runner.ts
737
+ // src/hbuilderx/runner.ts
743
738
  const defaultStartupTimeoutMs = 6e4;
744
739
  function createHBuilderXNativeLaunchArgs(options) {
745
740
  const args = [
@@ -873,8 +868,7 @@ async function createHBuilderXRunner(options = {}) {
873
868
  };
874
869
  return runner;
875
870
  }
876
- //#endregion
877
- //#region src/hbuilderx.ts
871
+ // src/hbuilderx.ts
878
872
  async function resolveHBuilderXCliInfo(candidatesOrOptions, env = node_process.default.env) {
879
873
  return await resolveHBuilderXCliInfoFromOptions(Array.isArray(candidatesOrOptions) ? {
880
874
  candidates: candidatesOrOptions,
@@ -951,8 +945,7 @@ function startLaunch(options) {
951
945
  args: createLaunchArgs(options)
952
946
  });
953
947
  }
954
- //#endregion
955
- //#region src/toolchains.ts
948
+ // src/toolchains.ts
956
949
  function runTool(command, args) {
957
950
  const result = (0, node_child_process.spawnSync)(command, args, { encoding: "utf8" });
958
951
  return {
@@ -1122,7 +1115,6 @@ function assertHarmonyToolchain(env = node_process.default.env, deviceId) {
1122
1115
  }
1123
1116
  return hdc;
1124
1117
  }
1125
- //#endregion
1126
1118
  exports.HBuilderXCommandError = HBuilderXCommandError;
1127
1119
  exports.assertAndroidToolchain = assertAndroidToolchain;
1128
1120
  exports.assertHarmonyToolchain = assertHarmonyToolchain;
@@ -0,0 +1,202 @@
1
+ import { ChildProcess } from "node:child_process";
2
+ import { Buffer } from "node:buffer";
3
+ export declare function fileExists(file: string): Promise<boolean>;
4
+ export declare function readUtf8(file: string): Promise<string>;
5
+ export declare function wait(ms: number): Promise<unknown>;
6
+ export type HBuilderXMiniProgramPlatform = 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-toutiao';
7
+ export type HBuilderXAppPlatform = 'app-android' | 'app-ios' | 'app-harmony';
8
+ export type HBuilderXPlatform = HBuilderXMiniProgramPlatform | HBuilderXAppPlatform;
9
+ export type HBuilderXChannel = 'auto' | 'stable' | 'alpha';
10
+ export type HBuilderXResolvedChannel = Exclude<HBuilderXChannel, 'auto'> | 'unknown';
11
+ export 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';
12
+ export interface HBuilderXIssue {
13
+ kind: HBuilderXIssueKind;
14
+ message: string;
15
+ hint?: string;
16
+ }
17
+ export interface CommandExit {
18
+ code: number | null;
19
+ signal: NodeJS.Signals | null;
20
+ }
21
+ export interface HBuilderXCommandOptions {
22
+ command: string;
23
+ args: string[];
24
+ cwd: string;
25
+ /** 业务截止时间;超时后另有有界进程清理预算。 */
26
+ timeoutMs?: number;
27
+ env?: Record<string, string | undefined>;
28
+ allowFailure?: boolean;
29
+ detached?: boolean;
30
+ stdio?: 'pipe' | 'inherit';
31
+ }
32
+ export interface HBuilderXCommandResult {
33
+ command: string;
34
+ args: string[];
35
+ cwd: string;
36
+ exit: CommandExit;
37
+ logs: string[];
38
+ output: string;
39
+ issue: HBuilderXIssue;
40
+ }
41
+ export interface SpawnedHBuilderXCommand {
42
+ child: ChildProcess;
43
+ logs: string[];
44
+ command: string;
45
+ args: string[];
46
+ cwd: string;
47
+ /** 在 close 前启动有界清理并确认本轮进程树结束;失败抛出诊断,多次调用复用同一结果。 */
48
+ stop: (signal?: NodeJS.Signals) => Promise<void>;
49
+ closed: Promise<CommandExit>;
50
+ ensureRunning: () => void;
51
+ }
52
+ export interface HBuilderXProjectOptions {
53
+ cwd: string;
54
+ hbuilderxCliPath?: string;
55
+ channel?: HBuilderXChannel;
56
+ host?: string;
57
+ env?: Record<string, string | undefined>;
58
+ timeoutMs?: number;
59
+ allowFailure?: boolean;
60
+ }
61
+ export interface HBuilderXLaunchOptions extends HBuilderXProjectOptions {
62
+ platform: HBuilderXPlatform;
63
+ args?: string[];
64
+ compile?: boolean;
65
+ runtimeLog?: boolean;
66
+ }
67
+ export interface ToolResult {
68
+ ok: boolean;
69
+ output: string;
70
+ status: number | null;
71
+ signal: NodeJS.Signals | null;
72
+ }
73
+ export interface AndroidToolchain {
74
+ command: string;
75
+ output: string;
76
+ env: Record<string, string> | undefined;
77
+ }
78
+ export type HBuilderXCliResolutionSource = 'running-process' | 'env' | 'default-path' | 'candidate';
79
+ export interface HBuilderXCliResolveOptions {
80
+ candidates?: string[];
81
+ channel?: HBuilderXChannel;
82
+ env?: NodeJS.ProcessEnv;
83
+ host?: string;
84
+ }
85
+ export interface HBuilderXCliResolution {
86
+ path: string;
87
+ isRunning: boolean;
88
+ source: HBuilderXCliResolutionSource;
89
+ channel: HBuilderXResolvedChannel;
90
+ host?: string;
91
+ version?: string;
92
+ }
93
+ export interface HBuilderXNativeCommandOptions {
94
+ args: string[];
95
+ cwd?: string;
96
+ timeoutMs?: number;
97
+ env?: Record<string, string | undefined>;
98
+ allowFailure?: boolean;
99
+ detached?: boolean;
100
+ stdio?: 'pipe' | 'inherit';
101
+ }
102
+ export interface HBuilderXRunnerOptions extends HBuilderXCliResolveOptions {
103
+ cwd?: string;
104
+ hbuilderxCliPath?: string;
105
+ timeoutMs?: number;
106
+ }
107
+ export interface HBuilderXRunner {
108
+ resolution: HBuilderXCliResolution;
109
+ run: (options: HBuilderXNativeCommandOptions) => Promise<HBuilderXCommandResult>;
110
+ spawn: (options: HBuilderXNativeCommandOptions) => SpawnedHBuilderXCommand;
111
+ closeProject: (options: HBuilderXProjectOptions) => Promise<HBuilderXCommandResult>;
112
+ openProject: (options: HBuilderXProjectOptions) => Promise<HBuilderXCommandResult>;
113
+ prepareProject: (options: HBuilderXProjectOptions) => Promise<HBuilderXCommandResult>;
114
+ launchProject: (options: HBuilderXLaunchOptions) => Promise<HBuilderXCommandResult>;
115
+ startLaunch: (options: HBuilderXLaunchOptions) => SpawnedHBuilderXCommand;
116
+ }
117
+ export declare const macOSStableCli = "/Applications/HBuilderX.app/Contents/MacOS/cli";
118
+ export declare const macOSAlphaCli = "/Applications/HBuilderX-Alpha.app/Contents/MacOS/cli";
119
+ export declare function resolveHBuilderXChannel(channel?: string): HBuilderXChannel;
120
+ export declare function inferHBuilderXChannel(file: string): HBuilderXResolvedChannel;
121
+ export declare function getDefaultHBuilderXCliCandidates(env?: NodeJS.ProcessEnv, channel?: HBuilderXChannel, platform?: NodeJS.Platform): string[];
122
+ export declare function extractHBuilderXMacOSExecutables(output: string): string[];
123
+ export declare function extractHBuilderXWindowsExecutables(output: string): string[];
124
+ export declare function extractHBuilderXExecutablesFromProcessOutput(output: string, platform?: NodeJS.Platform): string[];
125
+ export declare function extractHBuilderXMacOSExecutable(line: string): string | undefined;
126
+ export declare function extractHBuilderXWindowsExecutable(line: string): string | undefined;
127
+ export declare function extractHBuilderXExecutableFromProcessOutput(output: string, platform?: NodeJS.Platform): string | undefined;
128
+ export declare function findRunningHBuilderXCliCandidates(platform?: NodeJS.Platform): Promise<string[]>;
129
+ export declare function findRunningHBuilderXCli(platform?: NodeJS.Platform): Promise<string | undefined>;
130
+ export declare function selectHBuilderXCliCandidatesForChannel(items: string[], channel: HBuilderXChannel): string[];
131
+ export declare function resolveHBuilderXCliInfoFromOptions(options?: HBuilderXCliResolveOptions): Promise<HBuilderXCliResolution>;
132
+ export declare class HBuilderXCommandError extends Error {
133
+ readonly result: HBuilderXCommandResult;
134
+ readonly cleanupError?: Error;
135
+ constructor(message: string, result: HBuilderXCommandResult, cleanupError?: Error);
136
+ }
137
+ /** 保留同步请求终止的兼容入口;需要确认关闭时必须等待 spawned.stop()。 */
138
+ export declare function killProcessTree(child: ChildProcess, signal?: NodeJS.Signals): void;
139
+ export declare function spawnCommand(options: HBuilderXCommandOptions): SpawnedHBuilderXCommand;
140
+ export declare function runCommand(options: HBuilderXCommandOptions): Promise<HBuilderXCommandResult>;
141
+ export declare function createProcessExitTracker(child: ChildProcess): {
142
+ closed: Promise<CommandExit>;
143
+ ensureRunning(logs: string[]): void;
144
+ };
145
+ export declare function stripAnsi(value: string): string;
146
+ export declare function parseHBuilderXHosts(output: string): string[];
147
+ export declare function parseHBuilderXVersion(output: string): string | undefined;
148
+ export declare function inferHBuilderXChannelFromVersion(version: string): HBuilderXResolvedChannel;
149
+ export declare function createHBuilderXNativeLaunchArgs(options: HBuilderXLaunchOptions): string[];
150
+ export declare function createHBuilderXRunner(options?: HBuilderXRunnerOptions): Promise<HBuilderXRunner>;
151
+ export declare function resolveHBuilderXCliInfo(options?: HBuilderXCliResolveOptions): ReturnType<typeof resolveHBuilderXCliInfoFromOptions>;
152
+ export declare function resolveHBuilderXCliInfo(candidates?: string[], env?: NodeJS.ProcessEnv): ReturnType<typeof resolveHBuilderXCliInfoFromOptions>;
153
+ export declare function resolveHBuilderXCli(options?: HBuilderXCliResolveOptions): Promise<string>;
154
+ export declare function resolveHBuilderXCli(candidates?: string[]): Promise<string>;
155
+ export declare function createHBuilderXEnv(options?: {
156
+ hbuilderxCliPath?: string;
157
+ env?: Record<string, string | undefined>;
158
+ }): {
159
+ HBUILDERX_CLI_PATH: string | undefined;
160
+ NODE_OPTIONS: string;
161
+ };
162
+ export declare function hbuilderxPnpmArgs(args: string[]): string[];
163
+ export declare function runPnpmCommand(options: HBuilderXProjectOptions & {
164
+ args: string[];
165
+ }): Promise<HBuilderXCommandResult>;
166
+ export declare function spawnPnpmCommand(options: HBuilderXProjectOptions & {
167
+ args: string[];
168
+ }): SpawnedHBuilderXCommand;
169
+ export declare function closeProject(options: HBuilderXProjectOptions): Promise<HBuilderXCommandResult>;
170
+ export declare function openProject(options: HBuilderXProjectOptions): Promise<HBuilderXCommandResult>;
171
+ export declare function prepareProject(options: HBuilderXProjectOptions): Promise<HBuilderXCommandResult>;
172
+ export declare function createLaunchArgs(options: HBuilderXLaunchOptions): string[];
173
+ export declare function launchProject(options: HBuilderXLaunchOptions): Promise<HBuilderXCommandResult>;
174
+ /**
175
+ * @deprecated 需要固定 stable/alpha 与 host 时,请使用 `createHBuilderXRunner().startLaunch()`。
176
+ */
177
+ export declare function startLaunch(options: HBuilderXLaunchOptions): SpawnedHBuilderXCommand;
178
+ export declare function createLogBuffer(maxChunks?: number): {
179
+ logs: string[];
180
+ push(chunk: Buffer | string): void;
181
+ text(): string;
182
+ };
183
+ export declare function collectProcessOutput(child: ChildProcess, maxChunks?: number): string[];
184
+ export declare function classifyHBuilderXOutput(output: string): HBuilderXIssue;
185
+ export declare function createTimeoutIssue(): HBuilderXIssue;
186
+ export declare function formatRecentLogs(logs: string[], maxLength?: number): string;
187
+ export declare function runTool(command: string, args: string[]): ToolResult;
188
+ export declare function resolveAdbCommand(env?: NodeJS.ProcessEnv): AndroidToolchain;
189
+ export declare function assertAndroidToolchain(env?: NodeJS.ProcessEnv): Record<string, string> | undefined;
190
+ export declare function assertIosSimulatorToolchain(env?: NodeJS.ProcessEnv): void;
191
+ export interface IosSimulatorDevice {
192
+ lastBootedAt?: string;
193
+ name: string;
194
+ state: string;
195
+ udid: string;
196
+ }
197
+ export declare function parseIosSimulatorDevices(output: string): IosSimulatorDevice[];
198
+ export declare function selectPreferredIosSimulatorDevice(devices: IosSimulatorDevice[]): IosSimulatorDevice | undefined;
199
+ export declare function resolveIosSimulatorDeviceId(env?: NodeJS.ProcessEnv): string;
200
+ export declare function resolveHdcCommand(env?: NodeJS.ProcessEnv): string;
201
+ export declare function parseHdcTargets(output: string): string[];
202
+ export declare function assertHarmonyToolchain(env?: NodeJS.ProcessEnv, deviceId?: string): string;
package/dist/index.d.ts CHANGED
@@ -1,11 +1,8 @@
1
- import { ChildProcess } from "node:child_process";
2
1
  import { Buffer } from "node:buffer";
3
- //#region src/fs.d.ts
2
+ import { ChildProcess } from "node:child_process";
4
3
  export declare function fileExists(file: string): Promise<boolean>;
5
4
  export declare function readUtf8(file: string): Promise<string>;
6
5
  export declare function wait(ms: number): Promise<unknown>;
7
- //#endregion
8
- //#region src/types.d.ts
9
6
  export type HBuilderXMiniProgramPlatform = 'mp-weixin' | 'mp-alipay' | 'mp-baidu' | 'mp-toutiao';
10
7
  export type HBuilderXAppPlatform = 'app-android' | 'app-ios' | 'app-harmony';
11
8
  export type HBuilderXPlatform = HBuilderXMiniProgramPlatform | HBuilderXAppPlatform;
@@ -117,12 +114,8 @@ export interface HBuilderXRunner {
117
114
  launchProject: (options: HBuilderXLaunchOptions) => Promise<HBuilderXCommandResult>;
118
115
  startLaunch: (options: HBuilderXLaunchOptions) => SpawnedHBuilderXCommand;
119
116
  }
120
- //#endregion
121
- //#region src/hbuilderx/configured-cli.d.ts
122
117
  export declare const macOSStableCli = "/Applications/HBuilderX.app/Contents/MacOS/cli";
123
118
  export declare const macOSAlphaCli = "/Applications/HBuilderX-Alpha.app/Contents/MacOS/cli";
124
- //#endregion
125
- //#region src/hbuilderx/discovery.d.ts
126
119
  export declare function resolveHBuilderXChannel(channel?: string): HBuilderXChannel;
127
120
  export declare function inferHBuilderXChannel(file: string): HBuilderXResolvedChannel;
128
121
  export declare function getDefaultHBuilderXCliCandidates(env?: NodeJS.ProcessEnv, channel?: HBuilderXChannel, platform?: NodeJS.Platform): string[];
@@ -136,8 +129,6 @@ export declare function findRunningHBuilderXCliCandidates(platform?: NodeJS.Plat
136
129
  export declare function findRunningHBuilderXCli(platform?: NodeJS.Platform): Promise<string | undefined>;
137
130
  export declare function selectHBuilderXCliCandidatesForChannel(items: string[], channel: HBuilderXChannel): string[];
138
131
  export declare function resolveHBuilderXCliInfoFromOptions(options?: HBuilderXCliResolveOptions): Promise<HBuilderXCliResolution>;
139
- //#endregion
140
- //#region src/process.d.ts
141
132
  export declare class HBuilderXCommandError extends Error {
142
133
  readonly result: HBuilderXCommandResult;
143
134
  readonly cleanupError?: Error;
@@ -151,18 +142,12 @@ export declare function createProcessExitTracker(child: ChildProcess): {
151
142
  closed: Promise<CommandExit>;
152
143
  ensureRunning(logs: string[]): void;
153
144
  };
154
- //#endregion
155
- //#region src/hbuilderx/hosts.d.ts
156
145
  export declare function stripAnsi(value: string): string;
157
146
  export declare function parseHBuilderXHosts(output: string): string[];
158
147
  export declare function parseHBuilderXVersion(output: string): string | undefined;
159
148
  export declare function inferHBuilderXChannelFromVersion(version: string): HBuilderXResolvedChannel;
160
- //#endregion
161
- //#region src/hbuilderx/runner.d.ts
162
149
  export declare function createHBuilderXNativeLaunchArgs(options: HBuilderXLaunchOptions): string[];
163
150
  export declare function createHBuilderXRunner(options?: HBuilderXRunnerOptions): Promise<HBuilderXRunner>;
164
- //#endregion
165
- //#region src/hbuilderx.d.ts
166
151
  export declare function resolveHBuilderXCliInfo(options?: HBuilderXCliResolveOptions): ReturnType<typeof resolveHBuilderXCliInfoFromOptions>;
167
152
  export declare function resolveHBuilderXCliInfo(candidates?: string[], env?: NodeJS.ProcessEnv): ReturnType<typeof resolveHBuilderXCliInfoFromOptions>;
168
153
  export declare function resolveHBuilderXCli(options?: HBuilderXCliResolveOptions): Promise<string>;
@@ -190,8 +175,6 @@ export declare function launchProject(options: HBuilderXLaunchOptions): Promise<
190
175
  * @deprecated 需要固定 stable/alpha 与 host 时,请使用 `createHBuilderXRunner().startLaunch()`。
191
176
  */
192
177
  export declare function startLaunch(options: HBuilderXLaunchOptions): SpawnedHBuilderXCommand;
193
- //#endregion
194
- //#region src/logs.d.ts
195
178
  export declare function createLogBuffer(maxChunks?: number): {
196
179
  logs: string[];
197
180
  push(chunk: Buffer | string): void;
@@ -201,8 +184,6 @@ export declare function collectProcessOutput(child: ChildProcess, maxChunks?: nu
201
184
  export declare function classifyHBuilderXOutput(output: string): HBuilderXIssue;
202
185
  export declare function createTimeoutIssue(): HBuilderXIssue;
203
186
  export declare function formatRecentLogs(logs: string[], maxLength?: number): string;
204
- //#endregion
205
- //#region src/toolchains.d.ts
206
187
  export declare function runTool(command: string, args: string[]): ToolResult;
207
188
  export declare function resolveAdbCommand(env?: NodeJS.ProcessEnv): AndroidToolchain;
208
189
  export declare function assertAndroidToolchain(env?: NodeJS.ProcessEnv): Record<string, string> | undefined;
@@ -218,5 +199,4 @@ export declare function selectPreferredIosSimulatorDevice(devices: IosSimulatorD
218
199
  export declare function resolveIosSimulatorDeviceId(env?: NodeJS.ProcessEnv): string;
219
200
  export declare function resolveHdcCommand(env?: NodeJS.ProcessEnv): string;
220
201
  export declare function parseHdcTargets(output: string): string[];
221
- export declare function assertHarmonyToolchain(env?: NodeJS.ProcessEnv, deviceId?: string): string;
222
- //#endregion
202
+ export declare function assertHarmonyToolchain(env?: NodeJS.ProcessEnv, deviceId?: string): string;
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import process from "node:process";
4
4
  import { Buffer } from "node:buffer";
5
5
  import { spawnSync } from "node:child_process";
6
6
  import spawn from "cross-spawn";
7
- //#region src/fs.ts
7
+ // src/fs.ts
8
8
  async function fileExists(file) {
9
9
  try {
10
10
  await fs.access(file);
@@ -19,8 +19,7 @@ async function readUtf8(file) {
19
19
  function wait(ms) {
20
20
  return new Promise((resolve) => setTimeout(resolve, ms));
21
21
  }
22
- //#endregion
23
- //#region src/hbuilderx/configured-cli.ts
22
+ // src/hbuilderx/configured-cli.ts
24
23
  const macOSStableCli = "/Applications/HBuilderX.app/Contents/MacOS/cli";
25
24
  const macOSAlphaCli = "/Applications/HBuilderX-Alpha.app/Contents/MacOS/cli";
26
25
  function resolveCandidateSource(candidate, env) {
@@ -46,8 +45,7 @@ async function resolveConfiguredCli(options) {
46
45
  source: "env"
47
46
  };
48
47
  }
49
- //#endregion
50
- //#region src/hbuilderx/discovery.ts
48
+ // src/hbuilderx/discovery.ts
51
49
  function unique(items) {
52
50
  return [...new Set(items)];
53
51
  }
@@ -199,8 +197,7 @@ async function resolveHBuilderXCliInfoFromOptions(options = {}) {
199
197
  };
200
198
  throw new Error([`未找到 HBuilderX ${channel === "auto" ? "" : `${channel} `}CLI。`, "请安装 HBuilderX,或设置 HBUILDERX_CLI_PATH=/path/to/cli。"].join(""));
201
199
  }
202
- //#endregion
203
- //#region src/logs.ts
200
+ // src/logs.ts
204
201
  const PROJECT_NOT_UNI_APP_RE = /不是\s*uni-app\s*项目|not\s+a\s+uni-app\s+project/i;
205
202
  const PROJECT_TYPE_UNSUPPORTED_RE = /项目类型为([^,]+),暂不支持|是\s+([^,\s][^,]*)项目,暂不支持|project\s+type.+unsupported/i;
206
203
  const PROJECT_TARGET_UNSUPPORTED_RE = /不支持运行到\s*(鸿蒙|Harmony)|(?:Harmony|OpenHarmony).+(?:target|platform).+unsupported/i;
@@ -329,8 +326,7 @@ function formatRecentLogs(logs, maxLength = 6e3) {
329
326
  const important = (importantLogsByBuffer.get(logs) ?? []).filter((line) => !recent.includes(line));
330
327
  return important.length > 0 ? `关键错误:\n${important.join("\n")}\n\n最近日志:\n${recent}` : recent;
331
328
  }
332
- //#endregion
333
- //#region src/process/termination.ts
329
+ // src/process/termination.ts
334
330
  const ownedGroups = /* @__PURE__ */ new WeakMap();
335
331
  const closedChildren = /* @__PURE__ */ new WeakSet();
336
332
  const shutdownWaitMs = 1e3;
@@ -414,6 +410,7 @@ function waitForCleanup(closed, isGroupGone) {
414
410
  async function stopProcessTree(child, closed, signal) {
415
411
  let group = ownedGroups.get(child);
416
412
  const errors = [];
413
+ const exitRaces = [];
417
414
  const isGroupGone = () => {
418
415
  if (!group) return true;
419
416
  try {
@@ -431,7 +428,8 @@ async function stopProcessTree(child, closed, signal) {
431
428
  try {
432
429
  signalOwnedTree(child, nextSignal, group);
433
430
  } catch (error) {
434
- errors.push(error);
431
+ if (process.platform === "darwin" && group && (child.exitCode !== null || child.signalCode !== null) && error.code === "EPERM") exitRaces.push(error);
432
+ else errors.push(error);
435
433
  }
436
434
  try {
437
435
  if (await waitForCleanup(closed, isGroupGone)) {
@@ -442,11 +440,11 @@ async function stopProcessTree(child, closed, signal) {
442
440
  errors.push(error);
443
441
  }
444
442
  }
445
- const details = errors.map((error) => error instanceof Error ? error.message : String(error)).join("\n");
446
- throw new AggregateError(errors, `子进程 pid=${child.pid ?? "unknown"} 的有界清理未成功:需确认 close 和本轮进程组结束\n${details}`.trim());
443
+ const failures = [...errors, ...exitRaces];
444
+ const details = failures.map((error) => error instanceof Error ? error.message : String(error)).join("\n");
445
+ throw new AggregateError(failures, `子进程 pid=${child.pid ?? "unknown"} 的有界清理未成功:需确认 close 和本轮进程组结束\n${details}`.trim());
447
446
  }
448
- //#endregion
449
- //#region src/process.ts
447
+ // src/process.ts
450
448
  var HBuilderXCommandError = class extends Error {
451
449
  result;
452
450
  cleanupError;
@@ -597,8 +595,7 @@ function createProcessExitTracker(child) {
597
595
  }
598
596
  };
599
597
  }
600
- //#endregion
601
- //#region src/hbuilderx/hosts.ts
598
+ // src/hbuilderx/hosts.ts
602
599
  const ansiRE = new RegExp(`${String.fromCharCode(27)}\\[[\\d;]*m`, "g");
603
600
  function stripAnsi(value) {
604
601
  return value.replace(ansiRE, "");
@@ -711,8 +708,7 @@ async function connectHBuilderXHost(options) {
711
708
  } while (Date.now() < deadline);
712
709
  throw timeoutError(["listhost"]);
713
710
  }
714
- //#endregion
715
- //#region src/hbuilderx/runner.ts
711
+ // src/hbuilderx/runner.ts
716
712
  const defaultStartupTimeoutMs = 6e4;
717
713
  function createHBuilderXNativeLaunchArgs(options) {
718
714
  const args = [
@@ -846,8 +842,7 @@ async function createHBuilderXRunner(options = {}) {
846
842
  };
847
843
  return runner;
848
844
  }
849
- //#endregion
850
- //#region src/hbuilderx.ts
845
+ // src/hbuilderx.ts
851
846
  async function resolveHBuilderXCliInfo(candidatesOrOptions, env = process.env) {
852
847
  return await resolveHBuilderXCliInfoFromOptions(Array.isArray(candidatesOrOptions) ? {
853
848
  candidates: candidatesOrOptions,
@@ -924,8 +919,7 @@ function startLaunch(options) {
924
919
  args: createLaunchArgs(options)
925
920
  });
926
921
  }
927
- //#endregion
928
- //#region src/toolchains.ts
922
+ // src/toolchains.ts
929
923
  function runTool(command, args) {
930
924
  const result = spawnSync(command, args, { encoding: "utf8" });
931
925
  return {
@@ -1095,5 +1089,4 @@ function assertHarmonyToolchain(env = process.env, deviceId) {
1095
1089
  }
1096
1090
  return hdc;
1097
1091
  }
1098
- //#endregion
1099
1092
  export { HBuilderXCommandError, assertAndroidToolchain, assertHarmonyToolchain, assertIosSimulatorToolchain, classifyHBuilderXOutput, closeProject, collectProcessOutput, createHBuilderXEnv, createHBuilderXNativeLaunchArgs, createHBuilderXRunner, createLaunchArgs, createLogBuffer, createProcessExitTracker, createTimeoutIssue, extractHBuilderXExecutableFromProcessOutput, extractHBuilderXExecutablesFromProcessOutput, extractHBuilderXMacOSExecutable, extractHBuilderXMacOSExecutables, extractHBuilderXWindowsExecutable, extractHBuilderXWindowsExecutables, fileExists, findRunningHBuilderXCli, findRunningHBuilderXCliCandidates, formatRecentLogs, getDefaultHBuilderXCliCandidates, hbuilderxPnpmArgs, inferHBuilderXChannel, inferHBuilderXChannelFromVersion, killProcessTree, launchProject, macOSAlphaCli, macOSStableCli, openProject, parseHBuilderXHosts, parseHBuilderXVersion, parseHdcTargets, parseIosSimulatorDevices, prepareProject, readUtf8, resolveAdbCommand, resolveHBuilderXChannel, resolveHBuilderXCli, resolveHBuilderXCliInfo, resolveHBuilderXCliInfoFromOptions, resolveHdcCommand, resolveIosSimulatorDeviceId, runCommand, runPnpmCommand, runTool, selectHBuilderXCliCandidatesForChannel, selectPreferredIosSimulatorDevice, spawnCommand, spawnPnpmCommand, startLaunch, stripAnsi, wait };
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.7",
4
+ "version": "0.1.9",
5
5
  "description": "HBuilderX runner utilities for cross-platform uni-app Tailwind CSS workflows. 跨端 uni-app Tailwind CSS 工作流的 HBuilderX 运行器工具。",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -25,9 +25,14 @@
25
25
  "sideEffects": false,
26
26
  "exports": {
27
27
  ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.mjs",
30
- "require": "./dist/index.cjs"
28
+ "import": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.mjs"
31
+ },
32
+ "require": {
33
+ "types": "./dist/index.d.cts",
34
+ "default": "./dist/index.cjs"
35
+ }
31
36
  }
32
37
  },
33
38
  "main": "./dist/index.cjs",