xshell 1.0.183 → 1.0.185

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/file.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { promises as fsp, default as fs } from 'fs';
2
- type FileHandle = fsp.FileHandle & {
3
- fp: string;
4
- };
5
2
  export { fsp };
6
3
  export type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'utf-16le';
4
+ export type FileHandle = fsp.FileHandle & {
5
+ fp: string;
6
+ };
7
7
  export declare const encodings: readonly ["utf-8", "gb18030", "shift-jis", "utf-16le"];
8
8
  export declare const ramdisk: boolean;
9
9
  /** fp 所指向的 文件/ 文件夹 是否存在
@@ -17,7 +17,7 @@ export declare function fexists(fp: string, { print }?: {
17
17
  by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
18
18
  a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
19
19
 
20
- - flags: `'r'`
20
+ - flags: `'r'` https://nodejs.org/docs/latest/api/fs.html#file-system-flags
21
21
  - options?:
22
22
  - mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created. */
23
23
  export declare function fopen(fp: string, flags?: string | number, { mode, print }?: {
package/file.js CHANGED
@@ -21,7 +21,7 @@ export function fexists(fp, { print = true } = {}) {
21
21
  by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains
22
22
  a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams).
23
23
 
24
- - flags: `'r'`
24
+ - flags: `'r'` https://nodejs.org/docs/latest/api/fs.html#file-system-flags
25
25
  - options?:
26
26
  - mode?: `'0o666'` Sets the file mode (permission and sticky bits) if the file is created. */
27
27
  export async function fopen(fp, flags = 'r', { mode, print } = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.183",
3
+ "version": "1.0.185",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -94,7 +94,7 @@
94
94
  "react-i18next": "^15.0.3",
95
95
  "react-object-model": "^1.2.13",
96
96
  "resolve-path": "^1.4.0",
97
- "sass": "^1.79.5",
97
+ "sass": "^1.80.1",
98
98
  "sass-loader": "^16.0.2",
99
99
  "source-map-loader": "^5.0.0",
100
100
  "strip-ansi": "^7.1.0",
@@ -102,7 +102,7 @@
102
102
  "through2": "^4.0.2",
103
103
  "tough-cookie": "^5.0.0-rc.4",
104
104
  "ts-loader": "^9.5.1",
105
- "tslib": "^2.7.0",
105
+ "tslib": "^2.8.0",
106
106
  "typescript": "^5.6.3",
107
107
  "ua-parser-js": "^2.0.0-beta.3",
108
108
  "undici": "^6.20.1",
@@ -126,7 +126,7 @@
126
126
  "@types/koa-compress": "^4.0.6",
127
127
  "@types/lodash": "^4.17.10",
128
128
  "@types/mime-types": "^2.1.4",
129
- "@types/node": "^22.7.5",
129
+ "@types/node": "^22.7.6",
130
130
  "@types/react": "^18.3.11",
131
131
  "@types/through2": "^2.0.41",
132
132
  "@types/tough-cookie": "^4.0.5",
package/process.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type ChildProcess } from 'child_process';
2
2
  import './prototype.js';
3
- import { Encoding } from './file.js';
3
+ import type { Encoding } from './file.js';
4
4
  import type { MyProxy } from './net.js';
5
5
  import { inspect } from './utils.js';
6
6
  export declare const exe_nodejs: string;
@@ -17,6 +17,7 @@ export declare const print_no_command: {
17
17
  readonly stderr: true;
18
18
  };
19
19
  };
20
+ type StdioType = 'pipe' | 'ignore' | 'inherit' | number;
20
21
  interface StartOptions {
21
22
  /** `继承当前工作目录 process.cwd()` 子进程的工作目录 `inherit the cwd` cwd of the child process. */
22
23
  cwd?: string;
@@ -34,8 +35,16 @@ interface StartOptions {
34
35
  /** 进程执行成功的消息 */
35
36
  code: boolean;
36
37
  };
37
- /** `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing */
38
- stdio?: 'pipe' | 'ignore' | ['pipe' | 'ignore' | 'inherit', 'pipe' | 'ignore' | 'inherit', 'pipe' | 'ignore' | 'inherit'];
38
+ /** `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 */
39
+ stdio?: 'pipe' | 'ignore' | [StdioType, StdioType, StdioType];
40
+ /** 启动子进程之后写入到子进程 stdin 中的内容,写完后关闭子进程 stdin (pty 不关闭) */
41
+ input?: string;
42
+ /** 使用文件作为标准输入 */
43
+ fp_stdin?: string;
44
+ /** 使用文件作为标准输出 */
45
+ fp_stdout?: string;
46
+ /** 使用文件作为标准错误 */
47
+ fp_stderr?: string;
39
48
  /** `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref) */
40
49
  detached?: boolean;
41
50
  /** 为 true 时会设置 UV_PROCESS_WINDOWS_HIDE
@@ -59,8 +68,12 @@ interface StartOptions {
59
68
  - encoding?: `'utf-8'` 子进程输出编码 child output encoding
60
69
  - print?: `true` print 选项,支持设置细项 print option (with details)
61
70
  - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing
71
+ - input?: string, 启动子进程之后写入到子进程 stdin 中的内容,写完后关闭子进程 stdin (pty 不关闭)
72
+ - fp_stdin?: 使用文件作为标准输入,设置 stdio 中选项为对应的值
73
+ - fp_stdout?: 使用文件作为标准输出,设置 stdio 中选项为对应的值
74
+ - fp_stderr?: 使用文件作为标准错误,设置 stdio 中选项为对应的值
62
75
  - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref) */
63
- export declare function start(exe: string, args?: string[], { cwd, encoding, print, stdio, detached, envs, window: _window, proxy, }?: StartOptions): Promise<ChildProcess>;
76
+ export declare function start(exe: string, args?: string[], options?: StartOptions): Promise<ChildProcess>;
64
77
  export declare function start_nodejs(js: string, args?: string[], options?: StartOptions): Promise<ChildProcess>;
65
78
  export interface CallOptions extends StartOptions {
66
79
  throw_code?: boolean;
package/process.js CHANGED
@@ -2,7 +2,7 @@ import { spawn } from 'child_process';
2
2
  import os from 'os';
3
3
  import { t } from './i18n/instance.js';
4
4
  import './prototype.js';
5
- import { inspect, DecoderStream, filter_values } from './utils.js';
5
+ import { inspect, DecoderStream, filter_values, assert } from './utils.js';
6
6
  export const exe_nodejs = process.execPath.fp;
7
7
  export const platform = os.platform();
8
8
  export const username = os.userInfo().username;
@@ -17,16 +17,38 @@ export const print_no_command = { print: { command: false, code: false, stdout:
17
17
  - encoding?: `'utf-8'` 子进程输出编码 child output encoding
18
18
  - print?: `true` print 选项,支持设置细项 print option (with details)
19
19
  - stdio?: `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 when 'ignore' then ignore stdio processing
20
+ - input?: string, 启动子进程之后写入到子进程 stdin 中的内容,写完后关闭子进程 stdin (pty 不关闭)
21
+ - fp_stdin?: 使用文件作为标准输入,设置 stdio 中选项为对应的值
22
+ - fp_stdout?: 使用文件作为标准输出,设置 stdio 中选项为对应的值
23
+ - fp_stderr?: 使用文件作为标准错误,设置 stdio 中选项为对应的值
20
24
  - detached?: `false` 是否断开和 child 的关系 (ignore stdio, unref) whether to break the connection with child (ignore stdio, unref) */
21
- export async function start(exe, args = [], { cwd, encoding = 'utf-8', print = true, stdio = 'pipe', detached = false, envs, window: _window = true, proxy, } = {}) {
25
+ export async function start(exe, args = [], options = {}) {
26
+ const { cwd, encoding = 'utf-8', detached = false, window: _window = true, envs, input, fp_stdin, fp_stdout, fp_stderr } = options;
27
+ let { print = true, stdio = detached ? 'ignore' : 'pipe', proxy } = options;
22
28
  if (proxy === true) {
23
29
  const { MyProxy } = await import('./net.js');
24
30
  proxy = MyProxy.socks5;
25
31
  }
26
- const options = {
32
+ if (typeof stdio === 'string')
33
+ stdio = [stdio, stdio, stdio];
34
+ if (input)
35
+ assert(!fp_stdin, 'input 和 fp_stdin 不能同时设置');
36
+ if (fp_stdin || fp_stdout || fp_stderr) {
37
+ const { fopen } = await import('./file.js');
38
+ if (fp_stdin)
39
+ stdio[0] = (await fopen(fp_stdin, 'r')).fd;
40
+ if (fp_stdout)
41
+ stdio[1] = (await fopen(fp_stdout, 'w')).fd;
42
+ if (fp_stderr)
43
+ stdio[2] = fp_stderr === fp_stdout
44
+ ? stdio[1]
45
+ : (await fopen(fp_stderr, 'w')).fd;
46
+ }
47
+ const options_ = {
27
48
  cwd,
28
49
  shell: false,
29
50
  windowsHide: !_window,
51
+ detached,
30
52
  stdio,
31
53
  ...envs || proxy ? {
32
54
  env: filter_values({
@@ -47,8 +69,6 @@ export async function start(exe, args = [], { cwd, encoding = 'utf-8', print = t
47
69
  command: print,
48
70
  code: print,
49
71
  };
50
- if (typeof stdio === 'string')
51
- stdio = [stdio, stdio, stdio];
52
72
  if (print.command)
53
73
  console.log(((short_exe_names[exe] || exe.quote_if_space()) +
54
74
  (args.length ?
@@ -58,23 +78,18 @@ export async function start(exe, args = [], { cwd, encoding = 'utf-8', print = t
58
78
  :
59
79
  '')).blue);
60
80
  if (detached) {
61
- let child = spawn(exe, args, {
62
- ...options,
63
- stdio: 'ignore',
64
- detached: true,
65
- });
81
+ assert(stdio.every(x => x === 'ignore' || typeof x === 'number'), '调用 start({ detached: true }) 时 stdio 只能是 fd 或者 ignore');
82
+ let child = spawn(exe, args, options_);
66
83
  child.unref();
67
84
  return child;
68
85
  }
69
- let child = spawn(exe, args, options);
86
+ let child = spawn(exe, args, options_);
70
87
  // 防止 child spawn 失败时 crash nodejs 进程
71
88
  child.on('error', error => {
72
89
  console.error(error);
73
90
  });
74
91
  if (stdio[0] === 'pipe')
75
92
  child.stdin.setDefaultEncoding('utf8');
76
- if (stdio.every(s => s === 'ignore'))
77
- return child;
78
93
  if (encoding !== 'binary') {
79
94
  if (stdio[1] === 'pipe') {
80
95
  if (encoding === 'utf-8')
@@ -93,13 +108,15 @@ export async function start(exe, args = [], { cwd, encoding = 'utf-8', print = t
93
108
  child.stderr.pipe(process.stderr, { end: false });
94
109
  }
95
110
  }
111
+ if (input)
112
+ child.stdin.end(input);
96
113
  return child;
97
114
  }
98
115
  export async function start_nodejs(js, args = [], options) {
99
116
  return start(exe_nodejs, [js, ...args], options);
100
117
  }
101
118
  export async function call(exe, args = [], options = {}) {
102
- const { encoding = 'utf-8', throw_code = true, input, printers } = options;
119
+ const { encoding = 'utf-8', throw_code = true, printers } = options;
103
120
  let { stdio = 'pipe', print = true } = options;
104
121
  if (typeof print === 'boolean')
105
122
  print = {
@@ -121,8 +138,6 @@ export async function call(exe, args = [], options = {}) {
121
138
  ...options,
122
139
  print: false,
123
140
  });
124
- if (input)
125
- child.stdin.end(input);
126
141
  // --- collect output
127
142
  let stdouts = [];
128
143
  let stderrs = [];
@@ -88,11 +88,15 @@ declare global {
88
88
  /** 返回去掉 suffix 结尾的字符串,如果没有以 suffix 结尾则返回原字符串 */
89
89
  strip_if_end(this: string, suffix: string): string;
90
90
  /** 从 search 字符串出现的位置开始截取到最后
91
- - include?: `false` 传 true 时包括 search 部分 */
92
- slice_from(this: string, search: string, include?: boolean): string;
93
- /** search 字符串出现的位置开始截断,去掉尾部
94
- - include?: `false` true 时包括 search 部分 */
95
- slice_to(this: string, search: string, include?: boolean): string;
91
+ - options?:
92
+ - include?: `false` true 时包括 search 部分
93
+ - last?: `false` true 时从最后一次出现的地方开始截取,否则默认从第一次出现的地方开始截取 */
94
+ slice_from(this: string, search: string, options?: SliceOptions): string;
95
+ /** search 字符串最后出现的位置开始截断,去掉尾部
96
+ - options?:
97
+ - include?: `false` 传 true 时包括 search 部分
98
+ - last?: `false` true 时截取到最后一次出现的地方,否则默认截取到第一次出现的地方 */
99
+ slice_to(this: string, search: string, options?: SliceOptions): string;
96
100
  /** 等价于 .endsWith('/') */
97
101
  isdir: boolean;
98
102
  /** 以 `/` 分割的路径,可能以 / 结尾 */
@@ -161,6 +165,10 @@ declare global {
161
165
  map<TResult>(mapfn: (value: T, index: number) => TResult): TResult[];
162
166
  }
163
167
  }
168
+ interface SliceOptions {
169
+ include?: boolean;
170
+ last?: boolean;
171
+ }
164
172
  export declare const emoji_regex: RegExp;
165
173
  export declare function to_method_property_descriptors(methods: {
166
174
  [name: string]: Function;
@@ -185,3 +193,4 @@ export declare const brackets: {
185
193
  };
186
194
  export declare function to_json(obj: any, replacer?: any): string;
187
195
  export declare function is_codepoint_fullwidth(codepoint: number): boolean;
196
+ export {};
@@ -275,15 +275,15 @@ Object.defineProperties(String.prototype, {
275
275
  strip_if_end(suffix) {
276
276
  return this.endsWith(suffix) ? this.slice(0, -suffix.length) : this;
277
277
  },
278
- slice_from(search, include = false) {
279
- const i = this.indexOf(search);
278
+ slice_from(search, { include = false, last = false } = {}) {
279
+ const i = last ? this.lastIndexOf(search) : this.indexOf(search);
280
280
  if (i === -1)
281
281
  throw new Error(`slice_from 在字符串 ${this} 中找不到 search: ${search}`);
282
282
  else
283
283
  return this.slice(include ? i : i + search.length);
284
284
  },
285
- slice_to(search, include) {
286
- const i = this.lastIndexOf(search);
285
+ slice_to(search, { include = false, last = false } = {}) {
286
+ const i = last ? this.lastIndexOf(search) : this.indexOf(search);
287
287
  if (i === -1)
288
288
  throw new Error(`slice_to 在字符串 ${this} 中找不到 search: ${search}`);
289
289
  else
package/prototype.d.ts CHANGED
@@ -110,11 +110,15 @@ declare global {
110
110
  /** 返回去掉 suffix 结尾的字符串,如果没有以 suffix 结尾则返回原字符串 */
111
111
  strip_if_end(this: string, suffix: string): string;
112
112
  /** 从 search 字符串出现的位置开始截取到最后
113
- - include?: `false` 传 true 时包括 search 部分 */
114
- slice_from(this: string, search: string, include?: boolean): string;
115
- /** search 字符串出现的位置开始截断,去掉尾部
116
- - include?: `false` true 时包括 search 部分 */
117
- slice_to(this: string, search: string, include?: boolean): string;
113
+ - options?:
114
+ - include?: `false` true 时包括 search 部分
115
+ - last?: `false` true 时从最后一次出现的地方开始截取,否则默认从第一次出现的地方开始截取 */
116
+ slice_from(this: string, search: string, options?: SliceOptions): string;
117
+ /** search 字符串最后出现的位置开始截断,去掉尾部
118
+ - options?:
119
+ - include?: `false` 传 true 时包括 search 部分
120
+ - last?: `false` true 时截取到最后一次出现的地方,否则默认截取到第一次出现的地方 */
121
+ slice_to(this: string, search: string, options?: SliceOptions): string;
118
122
  /** 等价于 .endsWith('/') */
119
123
  isdir: boolean;
120
124
  /** 以 `/` 分割的路径,可能以 / 结尾 */
@@ -191,6 +195,10 @@ declare global {
191
195
  map<TResult>(mapfn: (value: T, index: number) => TResult): TResult[];
192
196
  }
193
197
  }
198
+ interface SliceOptions {
199
+ include?: boolean;
200
+ last?: boolean;
201
+ }
194
202
  import chalk from 'chalk';
195
203
  export declare const emoji_regex: RegExp;
196
204
  export { chalk };
package/prototype.js CHANGED
@@ -294,15 +294,15 @@ if (!globalThis.my_prototype_defined) {
294
294
  strip_if_end(suffix) {
295
295
  return this.endsWith(suffix) ? this.slice(0, -suffix.length) : this;
296
296
  },
297
- slice_from(search, include = false) {
298
- const i = this.indexOf(search);
297
+ slice_from(search, { include = false, last = false } = {}) {
298
+ const i = last ? this.lastIndexOf(search) : this.indexOf(search);
299
299
  if (i === -1)
300
300
  throw new Error(`slice_from 在字符串 ${this} 中找不到 search: ${search}`);
301
301
  else
302
302
  return this.slice(include ? i : i + search.length);
303
303
  },
304
- slice_to(search, include) {
305
- const i = this.lastIndexOf(search);
304
+ slice_to(search, { include = false, last = false } = {}) {
305
+ const i = last ? this.lastIndexOf(search) : this.indexOf(search);
306
306
  if (i === -1)
307
307
  throw new Error(`slice_to 在字符串 ${this} 中找不到 search: ${search}`);
308
308
  else
@@ -75,7 +75,7 @@ export declare function encode(str: string): Uint8Array;
75
75
  在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
76
76
  export declare function decode(buffer: Uint8Array): string;
77
77
  /** 字符串字典序比较 */
78
- export declare function strcmp(l: string, r: string): 0 | 1 | -1;
78
+ export declare function strcmp(l: string, r: string): 1 | 0 | -1;
79
79
  /** 比较 1.10.02 这种版本号
80
80
  - l, r: 两个版本号字符串
81
81
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
package/utils.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare function filter_values<TObj extends Record<string, any>>(obj: TOb
42
42
  /** 忽略对象中的 keys, 返回新对象 */
43
43
  export declare function omit<TObj>(obj: TObj, omit_keys: string[]): TObj;
44
44
  /** 字符串字典序比较 */
45
- export declare function strcmp(l: string, r: string): 0 | 1 | -1;
45
+ export declare function strcmp(l: string, r: string): 1 | 0 | -1;
46
46
  /** 比较 1.10.02 这种版本号
47
47
  - l, r: 两个版本号字符串
48
48
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */