xshell 1.0.189 → 1.0.191

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.js CHANGED
@@ -384,7 +384,8 @@ export async function flink(fp_real, fp_link, { junction = false, print = true,
384
384
  if (!skip_existing)
385
385
  throw new Error(`存在同名${is_fpd_link ? '文件夹' : '文件'}: ${fp_link},无法创建链接`);
386
386
  else {
387
- console.log('跳过已存在: ', fp_link);
387
+ if (print)
388
+ console.log('跳过已存在:', fp_link);
388
389
  return;
389
390
  }
390
391
  if (print)
package/git.d.ts CHANGED
@@ -5,10 +5,11 @@ export declare class Git {
5
5
  constructor(cwd: string);
6
6
  static init(cwd: string, print?: boolean): Promise<Git>;
7
7
  static clone(repo: string, fpd: string, shallow?: boolean | string): Promise<void>;
8
- call(args?: any[], { color, print, printers }?: {
8
+ call(args?: any[], { color, print, printers, throw_code, }?: {
9
9
  color?: boolean;
10
10
  print?: CallOptions['print'];
11
11
  printers?: CallOptions['printers'];
12
+ throw_code?: CallOptions['throw_code'];
12
13
  }): Promise<import("./process.ts").CallResult<string>>;
13
14
  get_branch(): Promise<string>;
14
15
  /** - print: `true` */
package/git.js CHANGED
@@ -22,7 +22,7 @@ export class Git {
22
22
  '.'
23
23
  ]);
24
24
  }
25
- async call(args = [], { color = true, print, printers } = {}) {
25
+ async call(args = [], { color = true, print, printers, throw_code, } = {}) {
26
26
  return call(Git.exe, [
27
27
  ...color ? [] : [
28
28
  '-c', 'color.status=false',
@@ -34,7 +34,8 @@ export class Git {
34
34
  ], {
35
35
  cwd: this.cwd,
36
36
  print,
37
- printers
37
+ printers,
38
+ throw_code
38
39
  });
39
40
  }
40
41
  async get_branch() {
@@ -89,7 +90,7 @@ export class Git {
89
90
  'fetch',
90
91
  remote || '--all',
91
92
  '--prune'
92
- ], { print: { code: false, command: false, stdout: true, stderr: true } });
93
+ ], print_stdout);
93
94
  if (print)
94
95
  console.log('更新远程分支成功');
95
96
  }
@@ -129,4 +130,5 @@ export class Git {
129
130
  };
130
131
  }
131
132
  }
133
+ const print_stdout = { print: { code: false, command: false, stdout: true, stderr: true } };
132
134
  //# sourceMappingURL=git.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.189",
3
+ "version": "1.0.191",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -49,8 +49,8 @@
49
49
  ]
50
50
  },
51
51
  "dependencies": {
52
- "@babel/core": "^7.25.9",
53
- "@babel/parser": "^7.25.9",
52
+ "@babel/core": "^7.26.0",
53
+ "@babel/parser": "^7.26.1",
54
54
  "@babel/traverse": "^7.25.9",
55
55
  "@koa/cors": "^5.0.0",
56
56
  "@stylistic/eslint-plugin": "^2.9.0",
@@ -81,7 +81,7 @@
81
81
  "gulp-sort": "^2.0.0",
82
82
  "hash-string": "^1.0.0",
83
83
  "https-proxy-agent": "^7.0.5",
84
- "i18next": "^23.16.2",
84
+ "i18next": "^23.16.4",
85
85
  "i18next-scanner": "^4.6.0",
86
86
  "koa": "^2.15.3",
87
87
  "koa-compress": "^5.1.1",
@@ -92,9 +92,9 @@
92
92
  "ora": "^8.1.0",
93
93
  "react": "^18.3.1",
94
94
  "react-i18next": "^15.1.0",
95
- "react-object-model": "^1.2.14",
95
+ "react-object-model": "^1.2.15",
96
96
  "resolve-path": "^1.4.0",
97
- "sass": "^1.80.3",
97
+ "sass": "^1.80.4",
98
98
  "sass-loader": "^16.0.2",
99
99
  "source-map-loader": "^5.0.0",
100
100
  "strip-ansi": "^7.1.0",
@@ -113,9 +113,9 @@
113
113
  "ws": "^8.18.0"
114
114
  },
115
115
  "devDependencies": {
116
- "@babel/types": "^7.25.9",
116
+ "@babel/types": "^7.26.0",
117
117
  "@types/ali-oss": "^6.16.11",
118
- "@types/archiver": "^6.0.2",
118
+ "@types/archiver": "^6.0.3",
119
119
  "@types/babel__traverse": "^7.20.6",
120
120
  "@types/byte-size": "^8.1.2",
121
121
  "@types/chardet": "^0.8.3",
@@ -126,8 +126,8 @@
126
126
  "@types/koa-compress": "^4.0.6",
127
127
  "@types/lodash": "^4.17.12",
128
128
  "@types/mime-types": "^2.1.4",
129
- "@types/node": "^22.7.8",
130
- "@types/react": "^18.3.11",
129
+ "@types/node": "^22.8.1",
130
+ "@types/react": "^18.3.12",
131
131
  "@types/through2": "^2.0.41",
132
132
  "@types/tough-cookie": "^4.0.5",
133
133
  "@types/ua-parser-js": "^0.7.39",
@@ -92,7 +92,7 @@ declare global {
92
92
  - include?: `false` 传 true 时包括 search 部分
93
93
  - last?: `false` true 时从最后一次出现的地方开始截取,否则默认从第一次出现的地方开始截取 */
94
94
  slice_from(this: string, search: string, options?: SliceOptions): string;
95
- /** 从 search 字符串最后出现的位置开始截断,去掉尾部
95
+ /** 从 search 字符串出现的位置开始截断,去掉尾部
96
96
  - options?:
97
97
  - include?: `false` 传 true 时包括 search 部分
98
98
  - last?: `false` true 时截取到最后一次出现的地方,否则默认截取到第一次出现的地方 */
package/prototype.d.ts CHANGED
@@ -114,7 +114,7 @@ declare global {
114
114
  - include?: `false` 传 true 时包括 search 部分
115
115
  - last?: `false` true 时从最后一次出现的地方开始截取,否则默认从第一次出现的地方开始截取 */
116
116
  slice_from(this: string, search: string, options?: SliceOptions): string;
117
- /** 从 search 字符串最后出现的位置开始截断,去掉尾部
117
+ /** 从 search 字符串出现的位置开始截断,去掉尾部
118
118
  - options?:
119
119
  - include?: `false` 传 true 时包括 search 部分
120
120
  - last?: `false` true 时截取到最后一次出现的地方,否则默认截取到第一次出现的地方 */
package/server.js CHANGED
@@ -303,8 +303,8 @@ export class Server {
303
303
  if (error.status !== 404)
304
304
  console.error(error);
305
305
  response.status = error.status || 500;
306
+ response.set('content-type', 'text/plain; charset=utf-8');
306
307
  response.body = inspect(error, { colors: false });
307
- response.type = 'text/plain';
308
308
  }
309
309
  }
310
310
  /** 解析 req.body to request.body
@@ -24,7 +24,10 @@ export declare function delay(milliseconds: number, { signal }?: {
24
24
  export declare class TimeoutError extends Error {
25
25
  constructor(message?: string, options?: ErrorOptions);
26
26
  }
27
- export declare function timeout<TReturn>(milliseconds: number, action: () => Promise<TReturn>): Promise<TReturn>;
27
+ /** 在指定的时间 (milliseconds) 内运行某个任务,超时之后
28
+ - 如果传入了 on_timeout 参数: 调用 on_timeout,返回 null
29
+ - 如果没传入 on_timeout 参数: 抛出 TimeoutError */
30
+ export declare function timeout<TReturn>(milliseconds: number, action: () => Promise<TReturn>, on_timeout?: () => void | Promise<void>): Promise<TReturn>;
28
31
  /** https://stackoverflow.com/questions/63297164/how-to-only-accept-arraybuffer-as-parameter */
29
32
  export type StrictArrayBuffer = ArrayBuffer & {
30
33
  buffer?: undefined;
@@ -75,7 +78,7 @@ export declare function encode(str: string): Uint8Array;
75
78
  在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
76
79
  export declare function decode(buffer: Uint8Array): string;
77
80
  /** 字符串字典序比较 */
78
- export declare function strcmp(l: string, r: string): 0 | 1 | -1;
81
+ export declare function strcmp(l: string, r: string): 1 | 0 | -1;
79
82
  /** 比较 1.10.02 这种版本号
80
83
  - l, r: 两个版本号字符串
81
84
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
package/utils.browser.js CHANGED
@@ -71,11 +71,51 @@ export class TimeoutError extends Error {
71
71
  this.name = this.constructor.name;
72
72
  }
73
73
  }
74
- export async function timeout(milliseconds, action) {
74
+ /** 在指定的时间 (milliseconds) 内运行某个任务,超时之后
75
+ - 如果传入了 on_timeout 参数: 调用 on_timeout,返回 null
76
+ - 如果没传入 on_timeout 参数: 抛出 TimeoutError */
77
+ export async function timeout(milliseconds, action, on_timeout) {
75
78
  const error = new TimeoutError();
76
79
  return new Promise((resolve, reject) => {
77
- delay(milliseconds).then(() => { reject(error); });
78
- action().then(resolve, reject);
80
+ let done = false;
81
+ let rejected = false;
82
+ (async () => {
83
+ await delay(milliseconds);
84
+ if (!done)
85
+ if (on_timeout)
86
+ try {
87
+ await on_timeout();
88
+ resolve(null);
89
+ }
90
+ catch (error) {
91
+ if (rejected)
92
+ throw error; // 会成为 unhandled rejection
93
+ else {
94
+ rejected = true;
95
+ reject(error);
96
+ }
97
+ }
98
+ else {
99
+ rejected = true;
100
+ reject(error);
101
+ }
102
+ })();
103
+ (async () => {
104
+ try {
105
+ resolve(await action());
106
+ }
107
+ catch (error) {
108
+ if (rejected)
109
+ console.log(`已超时任务的错误: ${error.message}`);
110
+ else {
111
+ rejected = true;
112
+ reject(error);
113
+ }
114
+ }
115
+ finally {
116
+ done = true;
117
+ }
118
+ })();
79
119
  });
80
120
  }
81
121
  /** 创建一个 promise,后续可调用 promise.resolve, promise.reject 方法设置其状态和值
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?: 宽松模式,允许两个版本号格式(位数)不一致 */
@@ -85,7 +85,10 @@ export declare function delay(milliseconds: number, options?: TimerOptions): Pro
85
85
  export declare class TimeoutError extends Error {
86
86
  constructor(message?: string, options?: ErrorOptions);
87
87
  }
88
- export declare function timeout<TReturn>(milliseconds: number, action: () => Promise<TReturn>): Promise<TReturn>;
88
+ /** 在指定的时间 (milliseconds) 内运行某个任务,超时之后
89
+ - 如果传入了 on_timeout 参数: 调用 on_timeout,返回 null
90
+ - 如果没传入 on_timeout 参数: 抛出 TimeoutError */
91
+ export declare function timeout<TReturn>(milliseconds: number, action: () => Promise<TReturn>, on_timeout?: () => void | Promise<void>): Promise<TReturn>;
89
92
  /** https://stackoverflow.com/questions/63297164/how-to-only-accept-arraybuffer-as-parameter */
90
93
  export type StrictArrayBuffer = ArrayBuffer & {
91
94
  buffer?: undefined;
package/utils.js CHANGED
@@ -242,11 +242,51 @@ export class TimeoutError extends Error {
242
242
  this.name = this.constructor.name;
243
243
  }
244
244
  }
245
- export async function timeout(milliseconds, action) {
245
+ /** 在指定的时间 (milliseconds) 内运行某个任务,超时之后
246
+ - 如果传入了 on_timeout 参数: 调用 on_timeout,返回 null
247
+ - 如果没传入 on_timeout 参数: 抛出 TimeoutError */
248
+ export async function timeout(milliseconds, action, on_timeout) {
246
249
  const error = new TimeoutError();
247
250
  return new Promise((resolve, reject) => {
248
- delay(milliseconds).then(() => { reject(error); });
249
- action().then(resolve, reject);
251
+ let done = false;
252
+ let rejected = false;
253
+ (async () => {
254
+ await delay(milliseconds);
255
+ if (!done)
256
+ if (on_timeout)
257
+ try {
258
+ await on_timeout();
259
+ resolve(null);
260
+ }
261
+ catch (error) {
262
+ if (rejected)
263
+ throw error; // 会成为 unhandled rejection
264
+ else {
265
+ rejected = true;
266
+ reject(error);
267
+ }
268
+ }
269
+ else {
270
+ rejected = true;
271
+ reject(error);
272
+ }
273
+ })();
274
+ (async () => {
275
+ try {
276
+ resolve(await action());
277
+ }
278
+ catch (error) {
279
+ if (rejected)
280
+ console.log(`已超时任务的错误: ${error.message}`);
281
+ else {
282
+ rejected = true;
283
+ reject(error);
284
+ }
285
+ }
286
+ finally {
287
+ done = true;
288
+ }
289
+ })();
250
290
  });
251
291
  }
252
292
  /** 创建一个 promise,后续可调用 promise.resolve, promise.reject 方法设置其状态和值
package/xlint.js CHANGED
@@ -587,7 +587,9 @@ export const xlint_plugin = {
587
587
  },
588
588
  FunctionExpression(node) {
589
589
  stack.push(false);
590
- if (node.parent.type === 'VariableDeclarator')
590
+ if (node.parent.type === 'VariableDeclarator' &&
591
+ // 忽略 let a = 1, b = function () { } 这样的情况
592
+ node.parent.parent.declarations.length === 1)
591
593
  context.report({
592
594
  node: node.parent.parent,
593
595
  message: '函数应该使用 function foo { } 这样来声明而不是 const foo = function () { }',
@@ -607,9 +609,11 @@ export const xlint_plugin = {
607
609
  },
608
610
  'ArrowFunctionExpression:exit'(node) {
609
611
  if (!stack.pop() && // not has this expr
610
- node.parent.type === 'VariableDeclarator' &&
611
- node.body.type === 'BlockStatement' && node.body.body.length // 多条语句才转换
612
- )
612
+ (node.parent.type === 'VariableDeclarator' &&
613
+ // 忽略 let a = 1, b = () => { } 这样的情况
614
+ node.parent.parent.declarations.length === 1) &&
615
+ // 多条语句才转换
616
+ node.body.type === 'BlockStatement' && node.body.body.length)
613
617
  context.report({
614
618
  node: node.parent.parent,
615
619
  message: '多条语句的函数应该使用 function foo { } 这样来声明而不是 const foo = () => { }',