xshell 1.3.21 → 1.3.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.3.21",
3
+ "version": "1.3.23",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/process.js CHANGED
@@ -3,7 +3,7 @@ import os from 'node:os';
3
3
  import node_sea from 'node:sea';
4
4
  import "./prototype.js";
5
5
  import { fopen } from "./file.js";
6
- import { inspect, DecoderStream, filter_values, check, colored, timeout } from "./utils.js";
6
+ import { inspect, DecoderStream, filter_values, check, colored, timeout, defer } from "./utils.js";
7
7
  export const sea = node_sea.isSea();
8
8
  export const exe_nodejs = process.execPath.fp;
9
9
  export const platform = os.platform();
@@ -155,15 +155,25 @@ function to_subprocess(child, { title, exe, args, command, }) {
155
155
  - title?: 由创建进程的调用者设置的,用于区分、识别、记忆的可选名称 */
156
156
  export async function start(exe, args = [], options = {}) {
157
157
  const { spawn_options, close_all_handles, command } = await prepare_spawn(true, exe, args, options);
158
+ let pspawn = defer();
159
+ let child;
158
160
  try {
159
- let child = to_subprocess(spawn(exe, args, spawn_options), { exe, command, args, title: options.title });
160
- child.unref();
161
- return child;
161
+ child = to_subprocess(spawn(exe, args, spawn_options), { exe, args, command, title: options.title });
162
+ child.once('spawn', () => {
163
+ child.unref();
164
+ pspawn.resolve();
165
+ });
166
+ // 监听 error 事件,处理启动失败的情况(如文件不存在),防止 node.js 进程退出
167
+ child.once('error', error => {
168
+ pspawn.reject(error);
169
+ });
162
170
  }
163
171
  finally {
164
172
  if (close_all_handles)
165
173
  await close_all_handles();
166
174
  }
175
+ await pspawn;
176
+ return child;
167
177
  }
168
178
  export class CallError extends Error {
169
179
  name = 'CallError';