xshell 1.1.16 → 1.1.17

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.1.16",
3
+ "version": "1.1.17",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/path.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare function extname(path: string): string;
54
54
  /** `/` */
55
55
  export declare const sep = "/";
56
56
  /** The platform-specific file delimiter. ';' or ':'. */
57
- export declare const delimiter: ";" | ":";
57
+ export declare const delimiter: ":" | ";";
58
58
  /** Returns an object from a path string - the opposite of format().
59
59
  @param path path to evaluate.
60
60
  @throws {TypeError} if `path` is not a string. */
@@ -81,7 +81,7 @@ export declare let path: {
81
81
  basename: typeof basename;
82
82
  extname: typeof extname;
83
83
  sep: string;
84
- delimiter: ";" | ":";
84
+ delimiter: ":" | ";";
85
85
  parse: typeof parse;
86
86
  format: typeof format;
87
87
  toNamespacedPath: typeof toNamespacedPath;
package/process.d.ts CHANGED
@@ -100,8 +100,11 @@ export interface CallOptions extends BaseOptions {
100
100
  throw_code?: boolean;
101
101
  /** `'utf-8'` 子进程输出编码 */
102
102
  encoding?: 'binary' | Encoding;
103
- /** `'pipe'` 设置为 'ignore' 时忽略 stdio 处理 */
103
+ /** `[stdin ? 'pipe' : 'ignore', 'pipe', 'pipe']` 设置为 'ignore' 时忽略 stdio 处理 */
104
104
  stdio?: 'pipe' | 'ignore' | [StdioType, StdioType, StdioType];
105
+ /** `false` 子进程是否可能会读取 stdin
106
+ 设置为 true 时会设置子进程 stdin 为 'pipe', 否则为 'ignore' */
107
+ stdin?: boolean;
105
108
  /** 启动子进程之后写入到子进程 stdin 中的内容,写完后关闭子进程 stdin */
106
109
  input?: string;
107
110
  /** 实时处理 stdout 和 stderr 的每个 chunk,启用后子进程输出不会自动 print */
package/process.js CHANGED
@@ -17,7 +17,9 @@ export function get_command(exe, args) {
17
17
  }
18
18
  async function prepare_spawn(detached, exe, args, { cwd, window: _window, envs,
19
19
  // @ts-ignore
20
- input, fp_stdin, fp_stdout, fp_stderr, print = true, proxy,
20
+ input,
21
+ // @ts-ignore
22
+ stdin, fp_stdin, fp_stdout, fp_stderr, print = true, proxy,
21
23
  // @ts-ignore
22
24
  stdio }) {
23
25
  // --- 处理 proxy, envs
@@ -52,7 +54,12 @@ stdio }) {
52
54
  else if (detached)
53
55
  stdio = ['ignore', 'ignore', 'ignore'];
54
56
  else
55
- stdio = [input ? 'pipe' : 'ignore', 'pipe', 'pipe'];
57
+ stdio = [
58
+ // 当子进程 stdin 为 'ignore' 时,python 会报错 [WinError 6] 句柄无效,cmd / powershell 都会立即结束退出
59
+ (stdin || input) ? 'pipe' : 'ignore',
60
+ 'pipe',
61
+ 'pipe'
62
+ ];
56
63
  if (fp_stdin || fp_stdout || fp_stderr) {
57
64
  const { fopen } = await import("./file.js");
58
65
  async function open(fp, flags) {
@@ -77,6 +84,7 @@ stdio }) {
77
84
  }
78
85
  if (detached)
79
86
  check(stdio.every((x) => x === 'ignore' || typeof x === 'number'), '调用 start 时 stdio 只能是 fd 或者 ignore');
87
+ // --- 处理 stdio 结束
80
88
  if (typeof print === 'boolean')
81
89
  print = {
82
90
  command: print,
@@ -108,6 +116,18 @@ function to_subprocess(child, { title, exe, args, command, }) {
108
116
  child.exe = exe;
109
117
  child.args = args || [];
110
118
  child.command = command;
119
+ child[inspect.custom] = () => {
120
+ const { title, command, running, exitCode, presult } = child;
121
+ return {
122
+ ...title ? { title } : {},
123
+ command,
124
+ running,
125
+ ...running ? {} : {
126
+ code: exitCode,
127
+ presult
128
+ }
129
+ };
130
+ };
111
131
  Object.defineProperties(child, {
112
132
  finished: {
113
133
  get() {
@@ -274,7 +294,7 @@ export async function call(exe, args = [], options = {}) {
274
294
  });
275
295
  }
276
296
  };
277
- if (throw_code && signal)
297
+ if (throw_code && code)
278
298
  throw new CallError(result);
279
299
  return result;
280
300
  }
@@ -81,7 +81,7 @@ export declare function encode(str: string): Uint8Array<ArrayBufferLike>;
81
81
  在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
82
82
  export declare function decode(buffer: Uint8Array): string;
83
83
  /** 字符串字典序比较 */
84
- export declare function strcmp(l: string, r: string): 1 | 0 | -1;
84
+ export declare function strcmp(l: string, r: string): 0 | 1 | -1;
85
85
  /** 比较 1.10.02 这种版本号
86
86
  - l, r: 两个版本号字符串
87
87
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
package/utils.d.ts CHANGED
@@ -40,7 +40,7 @@ export declare function filter_values<TObj extends Record<string, any>>(obj: TOb
40
40
  /** 忽略对象中的 keys, 返回新对象 */
41
41
  export declare function omit<TObj>(obj: TObj, omit_keys: string[]): TObj;
42
42
  /** 字符串字典序比较 */
43
- export declare function strcmp(l: string, r: string): 1 | 0 | -1;
43
+ export declare function strcmp(l: string, r: string): 0 | 1 | -1;
44
44
  /** 比较 1.10.02 这种版本号
45
45
  - l, r: 两个版本号字符串
46
46
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
package/stdin.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /** 监听终端按键 (输入),并调用 key_processor 处理
2
- - on_key: 按键处理函数
3
- - on_exit?: ctrl + c 会退出进程,可加入退出前自定义处理逻辑 */
4
- export declare function process_stdin(on_key: (key: string) => void | Promise<void>, on_exit?: () => void | Promise<void>): void;
package/stdin.js DELETED
@@ -1,25 +0,0 @@
1
- import process from 'process';
2
- /** 监听终端按键 (输入),并调用 key_processor 处理
3
- - on_key: 按键处理函数
4
- - on_exit?: ctrl + c 会退出进程,可加入退出前自定义处理逻辑 */
5
- export function process_stdin(on_key, on_exit) {
6
- // https://stackoverflow.com/a/12506613/7609214
7
- let { stdin } = process;
8
- if (stdin.isTTY) {
9
- stdin.setRawMode(true);
10
- stdin.resume();
11
- }
12
- stdin.setEncoding('utf-8');
13
- // on any data into stdin
14
- stdin.on('data', async (key) => {
15
- // ctrl-c ( end of text )
16
- if (key === '\u0003') {
17
- await on_exit?.();
18
- process.exit();
19
- }
20
- // write the key to stdout all normal like
21
- console.log(key);
22
- await on_key(key);
23
- });
24
- }
25
- //# sourceMappingURL=stdin.js.map