xshell 1.0.204 → 1.0.206

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.
Files changed (3) hide show
  1. package/package.json +8 -8
  2. package/process.js +8 -8
  3. package/server.js +20 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.204",
3
+ "version": "1.0.206",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -57,9 +57,9 @@
57
57
  "@svgr/webpack": "^8.1.0",
58
58
  "@types/sass-loader": "^8.0.9",
59
59
  "@types/ws": "^8.5.13",
60
- "@typescript-eslint/eslint-plugin": "^8.16.0",
61
- "@typescript-eslint/parser": "^8.16.0",
62
- "@typescript-eslint/utils": "^8.16.0",
60
+ "@typescript-eslint/eslint-plugin": "^8.17.0",
61
+ "@typescript-eslint/parser": "^8.17.0",
62
+ "@typescript-eslint/utils": "^8.17.0",
63
63
  "@xterm/addon-fit": "^0.10.0",
64
64
  "@xterm/addon-web-links": "^0.11.0",
65
65
  "@xterm/addon-webgl": "^0.18.0",
@@ -75,13 +75,13 @@
75
75
  "commander": "^12.1.0",
76
76
  "css-loader": "^7.1.2",
77
77
  "emoji-regex": "^10.4.0",
78
- "eslint": "^9.15.0",
78
+ "eslint": "^9.16.0",
79
79
  "eslint-plugin-import": "^2.31.0",
80
80
  "eslint-plugin-react": "^7.37.2",
81
81
  "gulp-sort": "^2.0.0",
82
82
  "hash-string": "^1.0.0",
83
83
  "https-proxy-agent": "^7.0.5",
84
- "i18next": "^24.0.2",
84
+ "i18next": "^24.0.5",
85
85
  "i18next-scanner": "^4.6.0",
86
86
  "koa": "^2.15.3",
87
87
  "koa-compress": "^5.1.1",
@@ -91,10 +91,10 @@
91
91
  "mime-types": "^2.1.35",
92
92
  "ora": "^8.1.1",
93
93
  "react": "^18.3.1",
94
- "react-i18next": "^15.1.2",
94
+ "react-i18next": "^15.1.3",
95
95
  "react-object-model": "^1.2.18",
96
96
  "resolve-path": "^1.4.0",
97
- "sass": "^1.81.0",
97
+ "sass": "^1.81.1",
98
98
  "sass-loader": "^16.0.3",
99
99
  "source-map-loader": "^5.0.0",
100
100
  "strip-ansi": "^7.1.0",
package/process.js CHANGED
@@ -7,6 +7,12 @@ export const platform = os.platform();
7
7
  export const username = os.userInfo().username;
8
8
  export const noprint = { print: false };
9
9
  export const print_no_command = { print: { command: false, code: false, stdout: true, stderr: true } };
10
+ function get_command(exe, args) {
11
+ return (short_exe_names[exe] || exe.quote_if_space()) +
12
+ (args.length
13
+ ? ' ' + args.map(arg => arg.quote_if_space()).join(' ')
14
+ : '');
15
+ }
10
16
  async function prepare_spawn(detached, exe, args, { cwd, window: _window = true, envs,
11
17
  // @ts-ignore
12
18
  input, fp_stdin, fp_stdout, fp_stderr, print = true, proxy,
@@ -78,13 +84,7 @@ stdio }) {
78
84
  };
79
85
  let command;
80
86
  if (print.command)
81
- console.log((command =
82
- (short_exe_names[exe] || exe.quote_if_space()) +
83
- (args.length
84
- ? ' ' + args
85
- .map(arg => arg.quote_if_space())
86
- .join(' ')
87
- : '')).blue);
87
+ console.log((command = get_command(exe, args)).blue);
88
88
  return {
89
89
  print,
90
90
  command,
@@ -193,7 +193,7 @@ export async function call(exe, args = [], options = {}) {
193
193
  let message;
194
194
  const code_error = throw_code && (code || signal);
195
195
  if (print.code || code_error) {
196
- message = `进程 ${command} ` + (code
196
+ message = `进程 ${command || get_command(exe, args)} ` + (code
197
197
  ? `${throw_code ? '异常' : ''}结束,退出码: ${code}${signal ? `,信号: ${signal}` : ''}`
198
198
  : '正常结束');
199
199
  console.log(message[code_error ? 'red' : 'blue']);
package/server.js CHANGED
@@ -148,8 +148,16 @@ export class Server {
148
148
  maxPayload: 2 ** 30 // 1 GB
149
149
  });
150
150
  this.websocket_server.on('connection', (ws, request) => {
151
- ws.addEventListener('message', ({ data }) => {
152
- this.remote.handle(new Uint8Array(data), ws);
151
+ ws.addEventListener('message', async ({ data }) => {
152
+ // 处理 funcs 中已经注册的 handlers
153
+ try {
154
+ await this.remote.handle(new Uint8Array(data), ws);
155
+ }
156
+ catch (error) {
157
+ this.on_error(error);
158
+ // 这里再往上扔会成为 uncaughtException 使进程退出,
159
+ // 通过上面的处理应该足够了
160
+ }
153
161
  });
154
162
  });
155
163
  const on_upgrade = this.on_upgrade.bind(this);
@@ -248,11 +256,12 @@ export class Server {
248
256
  }
249
257
  /** 可被子类重写定义错误处理逻辑 */
250
258
  on_error(error, ctx) {
251
- if (error.code === 'EPIPE' || error.code === 'ECONNRESET')
259
+ const code = error?.code;
260
+ if (code === 'EPIPE' || code === 'ECONNRESET')
252
261
  console.log(`${error.code}:`, ctx?.request?.url);
253
262
  else {
254
263
  console.error(error);
255
- console.log(ctx);
264
+ console.log('ctx:', ctx);
256
265
  }
257
266
  }
258
267
  on_upgrade(request, socket, head) {
@@ -359,7 +368,7 @@ export class Server {
359
368
  logger(ctx) {
360
369
  const { colors } = this;
361
370
  const { request } = ctx;
362
- const { query, body, path, _path, protocol, host, req: { httpVersion: http_version }, ip, headers, } = request;
371
+ const { query: queries, body, path, _path, protocol, host, req: { httpVersion: http_version }, ip, headers, } = request;
363
372
  let { method } = request;
364
373
  let s = '';
365
374
  // 时间
@@ -396,9 +405,9 @@ export class Server {
396
405
  end = Number(end).to_fsize_str();
397
406
  s += ` (${start} - ${end || ''})`;
398
407
  }
399
- // query
400
- if (Object.keys(query).length) {
401
- let t = inspect(query, { compact: true })
408
+ // queries
409
+ if (Object.keys(queries).length) {
410
+ let t = inspect(queries, { compact: true })
402
411
  .replace('[Object: null prototype] ', '')
403
412
  .strip_if_end('\n');
404
413
  s += (s + t).width > output_width ? '\n' : ' ';
@@ -468,15 +477,15 @@ export class Server {
468
477
  - timeout?: `1000 * 5` 请求超时时间,可以传入 0 禁用超时
469
478
  - throw_error?: `false` 在遇到 request 请求错误时直接 throw 出来,而不是自动设置到 response */
470
479
  async request(ctx, path_url, { headers: headers_, redirect = 'manual', queries, timeout, throw_error } = {}) {
471
- const { request: { method, headers, query, body, ip } } = ctx;
480
+ const { request: { method, headers, query: _queries, body, ip } } = ctx;
472
481
  let { response } = ctx;
473
482
  const x_forwarded_for = headers['x-forwarded-for'] ? `${headers['x-forwarded-for']}, ${ip}` : ip;
474
483
  try {
475
484
  const response_ = await _request(path_url, {
476
485
  method: method,
477
486
  queries: queries
478
- ? filter_values({ ...query, ...queries })
479
- : query,
487
+ ? filter_values({ ..._queries, ...queries })
488
+ : _queries,
480
489
  body,
481
490
  headers: (headers_
482
491
  ? filter_values({