@weapp-tailwindcss/hbuilderx-runner 0.1.4 → 0.1.6
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 +26 -15
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +26 -15
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -132,7 +132,7 @@ async function findRunningHBuilderXCliCandidates(platform = node_process.default
|
|
|
132
132
|
`$PSModuleAutoLoadingPreference = 'None'`,
|
|
133
133
|
`[Console]::Error.WriteLine('process-discovery: querying')`,
|
|
134
134
|
`$paths = [System.Collections.Generic.List[string]]::new()`,
|
|
135
|
-
`foreach ($p in [System.Diagnostics.Process]::GetProcessesByName('HBuilderX')) { try { $paths.Add([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($p.MainModule.FileName))) } finally { $p.Dispose() } }`,
|
|
135
|
+
`foreach ($p in [System.Diagnostics.Process]::GetProcessesByName('HBuilderX')) { try { $paths.Add([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($p.MainModule.FileName))) } catch {} finally { $p.Dispose() } }`,
|
|
136
136
|
`[Console]::Error.WriteLine('process-discovery: complete')`,
|
|
137
137
|
`[Console]::WriteLine('WT-HBUILDERX-PROCESSES/1')`,
|
|
138
138
|
`[Console]::WriteLine([string]::Join([Environment]::NewLine, $paths))`,
|
|
@@ -143,18 +143,25 @@ async function findRunningHBuilderXCliCandidates(platform = node_process.default
|
|
|
143
143
|
"-o",
|
|
144
144
|
"command="
|
|
145
145
|
];
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
146
|
+
const timeout = 15e3;
|
|
147
|
+
const maxAttempts = platform === "win32" ? 3 : 1;
|
|
148
|
+
let result;
|
|
149
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
150
|
+
result = (0, node_child_process.spawnSync)(command, args, {
|
|
151
|
+
encoding: "utf8",
|
|
152
|
+
stdio: [
|
|
153
|
+
"ignore",
|
|
154
|
+
"pipe",
|
|
155
|
+
"pipe"
|
|
156
|
+
],
|
|
157
|
+
windowsHide: true,
|
|
158
|
+
timeout,
|
|
159
|
+
maxBuffer: 1048576
|
|
160
|
+
});
|
|
161
|
+
if (!result.error && result.status === 0) break;
|
|
162
|
+
if (!(result.signal === "SIGTERM" || result.error?.code === "ETIMEDOUT") || attempt === maxAttempts - 1) break;
|
|
163
|
+
}
|
|
164
|
+
if (!result || result.error || result.status !== 0) throw new Error(`HBuilderX 进程探测失败:${command}, exit=${result?.status}, signal=${result?.signal}, cwd=${node_process.default.cwd()}\n${result?.error?.message ?? ""}\n${result?.stderr ?? ""}\n${result?.stdout ?? ""}`);
|
|
158
165
|
let executables;
|
|
159
166
|
if (platform === "win32") {
|
|
160
167
|
const lines = result.stdout.replace(/^\uFEFF/, "").trim().split(/\r?\n/);
|
|
@@ -500,8 +507,12 @@ const ansiRE = new RegExp(`${String.fromCharCode(27)}\\[[\\d;]*m`, "g");
|
|
|
500
507
|
function stripAnsi(value) {
|
|
501
508
|
return value.replace(ansiRE, "");
|
|
502
509
|
}
|
|
510
|
+
/** CLI 的未启动协议响应因界面语言不同而变化,不能作为 host 名称解析。 */
|
|
511
|
+
function isStoppedHostDiagnostic(line) {
|
|
512
|
+
return /^(?:HBuilderX is not detected running\. Please execute cli open.*|没有可用的命令[,,]尝试使用\s*cli open|未检测到已打开的\s*HBuilderX[,,]请先执行\s*cli open.*)$/i.test(line.trim());
|
|
513
|
+
}
|
|
503
514
|
function parseHBuilderXHosts(output) {
|
|
504
|
-
return [...new Set(stripAnsi(output).split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !/^-?\d+:cli:|命令.+(?:不存在|错误)|not detected running/i.test(line)))];
|
|
515
|
+
return [...new Set(stripAnsi(output).split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !isStoppedHostDiagnostic(line) && !/^-?\d+:cli:|命令.+(?:不存在|错误)|not detected running/i.test(line)))];
|
|
505
516
|
}
|
|
506
517
|
function parseHBuilderXVersion(output) {
|
|
507
518
|
return stripAnsi(output).match(/\b(\d+\.\d+(?:\.\d+)+(?:-[0-9a-z.-]+)?)\b/i)?.[1];
|
|
@@ -571,7 +582,7 @@ async function connectHBuilderXHost(options) {
|
|
|
571
582
|
};
|
|
572
583
|
const probe = async () => {
|
|
573
584
|
const listed = await command(["listhost"]);
|
|
574
|
-
if (!(listed.issue.kind !== "timeout" &&
|
|
585
|
+
if (!(listed.issue.kind !== "timeout" && stripAnsi(listed.output).split(/\r?\n/).some(isStoppedHostDiagnostic))) assertCommand(listed);
|
|
575
586
|
const hosts = parseHBuilderXHosts(listed.output);
|
|
576
587
|
const compatible = [];
|
|
577
588
|
for (const host of explicitHost ? [explicitHost] : hosts) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ChildProcess } from "node:child_process";
|
|
2
1
|
import { Buffer } from "node:buffer";
|
|
2
|
+
import { ChildProcess } from "node:child_process";
|
|
3
3
|
//#region src/fs.d.ts
|
|
4
4
|
export declare function fileExists(file: string): Promise<boolean>;
|
|
5
5
|
export declare function readUtf8(file: string): Promise<string>;
|
package/dist/index.mjs
CHANGED
|
@@ -105,7 +105,7 @@ async function findRunningHBuilderXCliCandidates(platform = process.platform) {
|
|
|
105
105
|
`$PSModuleAutoLoadingPreference = 'None'`,
|
|
106
106
|
`[Console]::Error.WriteLine('process-discovery: querying')`,
|
|
107
107
|
`$paths = [System.Collections.Generic.List[string]]::new()`,
|
|
108
|
-
`foreach ($p in [System.Diagnostics.Process]::GetProcessesByName('HBuilderX')) { try { $paths.Add([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($p.MainModule.FileName))) } finally { $p.Dispose() } }`,
|
|
108
|
+
`foreach ($p in [System.Diagnostics.Process]::GetProcessesByName('HBuilderX')) { try { $paths.Add([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($p.MainModule.FileName))) } catch {} finally { $p.Dispose() } }`,
|
|
109
109
|
`[Console]::Error.WriteLine('process-discovery: complete')`,
|
|
110
110
|
`[Console]::WriteLine('WT-HBUILDERX-PROCESSES/1')`,
|
|
111
111
|
`[Console]::WriteLine([string]::Join([Environment]::NewLine, $paths))`,
|
|
@@ -116,18 +116,25 @@ async function findRunningHBuilderXCliCandidates(platform = process.platform) {
|
|
|
116
116
|
"-o",
|
|
117
117
|
"command="
|
|
118
118
|
];
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
const timeout = 15e3;
|
|
120
|
+
const maxAttempts = platform === "win32" ? 3 : 1;
|
|
121
|
+
let result;
|
|
122
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
123
|
+
result = spawnSync(command, args, {
|
|
124
|
+
encoding: "utf8",
|
|
125
|
+
stdio: [
|
|
126
|
+
"ignore",
|
|
127
|
+
"pipe",
|
|
128
|
+
"pipe"
|
|
129
|
+
],
|
|
130
|
+
windowsHide: true,
|
|
131
|
+
timeout,
|
|
132
|
+
maxBuffer: 1048576
|
|
133
|
+
});
|
|
134
|
+
if (!result.error && result.status === 0) break;
|
|
135
|
+
if (!(result.signal === "SIGTERM" || result.error?.code === "ETIMEDOUT") || attempt === maxAttempts - 1) break;
|
|
136
|
+
}
|
|
137
|
+
if (!result || result.error || result.status !== 0) throw new Error(`HBuilderX 进程探测失败:${command}, exit=${result?.status}, signal=${result?.signal}, cwd=${process.cwd()}\n${result?.error?.message ?? ""}\n${result?.stderr ?? ""}\n${result?.stdout ?? ""}`);
|
|
131
138
|
let executables;
|
|
132
139
|
if (platform === "win32") {
|
|
133
140
|
const lines = result.stdout.replace(/^\uFEFF/, "").trim().split(/\r?\n/);
|
|
@@ -473,8 +480,12 @@ const ansiRE = new RegExp(`${String.fromCharCode(27)}\\[[\\d;]*m`, "g");
|
|
|
473
480
|
function stripAnsi(value) {
|
|
474
481
|
return value.replace(ansiRE, "");
|
|
475
482
|
}
|
|
483
|
+
/** CLI 的未启动协议响应因界面语言不同而变化,不能作为 host 名称解析。 */
|
|
484
|
+
function isStoppedHostDiagnostic(line) {
|
|
485
|
+
return /^(?:HBuilderX is not detected running\. Please execute cli open.*|没有可用的命令[,,]尝试使用\s*cli open|未检测到已打开的\s*HBuilderX[,,]请先执行\s*cli open.*)$/i.test(line.trim());
|
|
486
|
+
}
|
|
476
487
|
function parseHBuilderXHosts(output) {
|
|
477
|
-
return [...new Set(stripAnsi(output).split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !/^-?\d+:cli:|命令.+(?:不存在|错误)|not detected running/i.test(line)))];
|
|
488
|
+
return [...new Set(stripAnsi(output).split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0 && !isStoppedHostDiagnostic(line) && !/^-?\d+:cli:|命令.+(?:不存在|错误)|not detected running/i.test(line)))];
|
|
478
489
|
}
|
|
479
490
|
function parseHBuilderXVersion(output) {
|
|
480
491
|
return stripAnsi(output).match(/\b(\d+\.\d+(?:\.\d+)+(?:-[0-9a-z.-]+)?)\b/i)?.[1];
|
|
@@ -544,7 +555,7 @@ async function connectHBuilderXHost(options) {
|
|
|
544
555
|
};
|
|
545
556
|
const probe = async () => {
|
|
546
557
|
const listed = await command(["listhost"]);
|
|
547
|
-
if (!(listed.issue.kind !== "timeout" &&
|
|
558
|
+
if (!(listed.issue.kind !== "timeout" && stripAnsi(listed.output).split(/\r?\n/).some(isStoppedHostDiagnostic))) assertCommand(listed);
|
|
548
559
|
const hosts = parseHBuilderXHosts(listed.output);
|
|
549
560
|
const compatible = [];
|
|
550
561
|
for (const host of explicitHost ? [explicitHost] : hosts) {
|
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.6",
|
|
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",
|