xshell 1.0.53 → 1.0.54

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
@@ -116,12 +116,16 @@ export declare function fcopy(fp_src: string, fp_dst: string, { print, overwrite
116
116
  print?: boolean;
117
117
  overwrite?: boolean;
118
118
  }): Promise<void>;
119
- /** 移动文件或文件夹 move file or direcotry
120
- - src: 源 文件/文件夹 完整路径 src file/directory absolute path
121
- - dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path
119
+ /** 移动文件或文件夹
120
+ - src: 源 文件/文件夹 完整路径
121
+ - dst: 目标 文件/文件夹 完整路径
122
+ - options?:
123
+ - print?: `true`
124
+ - overwrite?: `false`
125
+
122
126
  @example
123
127
  fmove('D:/temp/camera/', 'D:/camera/') */
124
- export declare function fmove(src: string, dst: string, { overwrite, print }?: {
128
+ export declare function fmove(fp_src: string, fp_dst: string, { overwrite, print }?: {
125
129
  overwrite?: boolean;
126
130
  print?: boolean;
127
131
  }): Promise<void>;
package/file.js CHANGED
@@ -220,27 +220,56 @@ export async function fdelete(fp, { print = true } = {}) {
220
220
  @example
221
221
  fcopy('D:/temp/camera/', 'D:/camera/') */
222
222
  export async function fcopy(fp_src, fp_dst, { print = true, overwrite = true, } = {}) {
223
- assert(fp_src.isdir === fp_dst.isdir, t('fp_src fp_dst 必须同为文件路径或文件夹路径'));
223
+ const { isdir } = fp_src;
224
+ assert(isdir === fp_dst.isdir, t('fp_src 和 fp_dst 必须同为文件路径或文件夹路径'));
224
225
  assert(path.isAbsolute(fp_src) && path.isAbsolute(fp_dst), t('fp_src 和 fp_dst 必须为完整路径'));
225
226
  if (print)
226
227
  console.log(t('复制'), fp_src, '->', fp_dst);
227
- const { copy } = await import('fs-extra');
228
- await copy(fp_src, fp_dst, { overwrite, errorOnExist: true });
228
+ if (isdir)
229
+ await fsp.cp(fp_src, fp_dst, {
230
+ recursive: true,
231
+ force: overwrite,
232
+ errorOnExist: !overwrite,
233
+ mode: overwrite ? 0 : fs.constants.COPYFILE_EXCL,
234
+ });
235
+ else {
236
+ await fmkdir(fp_dst.fdir, { print: false });
237
+ await fsp.copyFile(fp_src, fp_dst, overwrite ? 0 : fs.constants.COPYFILE_EXCL);
238
+ }
229
239
  }
230
- /** 移动文件或文件夹 move file or direcotry
231
- - src: 源 文件/文件夹 完整路径 src file/directory absolute path
232
- - dst: 目标 文件/文件夹 完整路径 dst file/directory absolute path
240
+ /** 移动文件或文件夹
241
+ - src: 源 文件/文件夹 完整路径
242
+ - dst: 目标 文件/文件夹 完整路径
243
+ - options?:
244
+ - print?: `true`
245
+ - overwrite?: `false`
246
+
233
247
  @example
234
248
  fmove('D:/temp/camera/', 'D:/camera/') */
235
- export async function fmove(src, dst, { overwrite = false, print = true } = {}) {
236
- if (src.isdir !== dst.isdir)
237
- throw new Error(t('srcdst 必须同为文件路径或文件夹路径'));
238
- if (!path.isAbsolute(src) || !path.isAbsolute(dst))
239
- throw new Error(t('src 和 dst 必须为完整路径'));
249
+ export async function fmove(fp_src, fp_dst, { overwrite = false, print = true } = {}) {
250
+ assert(fp_src.isdir === fp_dst.isdir, t('fp_src 和 fp_dst 必须同为文件路径或文件夹路径'));
251
+ assert(path.isAbsolute(fp_src) && path.isAbsolute(fp_dst), t('fp_srcfp_dst 必须为完整路径'));
240
252
  if (print)
241
- console.log(t('移动'), src, '->', dst);
242
- const { move } = await import('fs-extra');
243
- await move(src, dst, { overwrite });
253
+ console.log(t('移动'), fp_src, '->', fp_dst);
254
+ if (!overwrite && fexists(fp_dst))
255
+ throw new Error(`${t('已存在')} ${fp_dst}`);
256
+ await fmkdir(fp_dst.fdir, { print: false });
257
+ async function copy_and_delete() {
258
+ await fcopy(fp_src, fp_dst, { overwrite, print });
259
+ await fdelete(fp_src, { print });
260
+ }
261
+ if (fp_src[0] !== fp_dst[0])
262
+ await copy_and_delete();
263
+ else
264
+ try {
265
+ await fsp.rename(fp_src, fp_dst);
266
+ }
267
+ catch (error) {
268
+ if (error.code === 'EXDEV')
269
+ await copy_and_delete();
270
+ else
271
+ throw error;
272
+ }
244
273
  }
245
274
  /** 重命名文件 rename file
246
275
  - fp: 当前文件名/路径 current filename/path
@@ -259,7 +288,7 @@ export async function frename(fp, fp_, { fpd, print = true, overwrite = true } =
259
288
  if (print)
260
289
  console.log(t('重命名'), fp, '->', fp_);
261
290
  if (!overwrite && fexists(fp_))
262
- throw new Error(t('文件已存在:') + fp_);
291
+ throw new Error(`${t('已存在')} ${fp}`);
263
292
  await fsp.rename(fp, fp_);
264
293
  }
265
294
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -59,10 +59,9 @@
59
59
  "commander": "^11.0.0",
60
60
  "emoji-regex": "^10.2.1",
61
61
  "fetch-cookie": "^2.1.0",
62
- "fs-extra": "^11.1.1",
63
62
  "gulp-sort": "^2.0.0",
64
63
  "hash-string": "^1.0.0",
65
- "i18next": "^23.4.4",
64
+ "i18next": "^23.4.5",
66
65
  "i18next-scanner": "^4.3.0",
67
66
  "js-cookie": "^3.0.5",
68
67
  "koa": "^2.14.2",
@@ -72,7 +71,7 @@
72
71
  "mime-types": "^2.1.35",
73
72
  "ora": "^7.0.1",
74
73
  "react": "^18.2.0",
75
- "react-i18next": "^13.1.2",
74
+ "react-i18next": "^13.2.0",
76
75
  "resolve-path": "^1.4.0",
77
76
  "strip-ansi": "^7.1.0",
78
77
  "through2": "^4.0.2",
@@ -90,22 +89,21 @@
90
89
  "@types/babel__traverse": "^7.20.1",
91
90
  "@types/byte-size": "^8.1.0",
92
91
  "@types/chardet": "^0.8.1",
93
- "@types/fs-extra": "^11.0.1",
94
92
  "@types/gulp-sort": "2.0.1",
95
93
  "@types/js-cookie": "^3.0.3",
96
94
  "@types/koa": "^2.13.8",
97
95
  "@types/koa-compress": "^4.0.3",
98
96
  "@types/lodash": "^4.14.197",
99
97
  "@types/mime-types": "^2.1.1",
100
- "@types/node": "^20.5.1",
101
- "@types/react": "^18.2.20",
98
+ "@types/node": "^20.5.3",
99
+ "@types/react": "^18.2.21",
102
100
  "@types/through2": "^2.0.38",
103
101
  "@types/tough-cookie": "^4.0.2",
104
102
  "@types/ua-parser-js": "^0.7.36",
105
103
  "@types/vinyl-fs": "^3.0.2",
106
104
  "@types/vscode": "^1.81.0",
107
- "@typescript-eslint/eslint-plugin": "^6.4.0",
108
- "@typescript-eslint/parser": "^6.4.0",
105
+ "@typescript-eslint/eslint-plugin": "^6.4.1",
106
+ "@typescript-eslint/parser": "^6.4.1",
109
107
  "eslint": "^8.47.0",
110
108
  "eslint-plugin-react": "^7.33.2",
111
109
  "eslint-plugin-xlint": "^1.0.7"
package/process.d.ts CHANGED
@@ -40,7 +40,7 @@ interface StartOptions {
40
40
  - exe: .exe 路径或文件名 (建议使用完整路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)
41
41
  - args: `[]` 参数列表 arguments list
42
42
  - options
43
- - cwd?: `fp_root`
43
+ - cwd?: `继承当前工作目录 process.cwd()` 子进程的工作目录 `inherit the cwd` cwd of the child process.
44
44
  - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env
45
45
  - encoding?: `'utf-8'` 子进程输出编码 child output encoding
46
46
  - print?: `true` print 选项,支持设置细项 print option (with details)
package/process.js CHANGED
@@ -8,7 +8,7 @@ export const exe_nodejs = process.execPath.fp;
8
8
  - exe: .exe 路径或文件名 (建议使用完整路径,跳过 path 搜索,性能更高) path or filename (full path is recommanded to skip path searching for better perf)
9
9
  - args: `[]` 参数列表 arguments list
10
10
  - options
11
- - cwd?: `fp_root`
11
+ - cwd?: `继承当前工作目录 process.cwd()` 子进程的工作目录 `inherit the cwd` cwd of the child process.
12
12
  - env?: `process.env` 覆盖/添加到 process.env 的环境变量 overwrite/add to process.env
13
13
  - encoding?: `'utf-8'` 子进程输出编码 child output encoding
14
14
  - print?: `true` print 选项,支持设置细项 print option (with details)
@@ -184,7 +184,7 @@ export const exe_winterm = `C:/Users/${userInfo().username}/AppData/Local/Micros
184
184
  - args: 调用参数 call parameter
185
185
  - options?: WinTermOptions
186
186
  */
187
- export async function term(exe, args = [], { cwd = process.cwd().fp, print = true, title,
187
+ export async function term(exe, args = [], { cwd = process.cwd().fpd, print = true, title,
188
188
  // env
189
189
  } = {}) {
190
190
  return start(exe_winterm, [
package/server.js CHANGED
@@ -263,7 +263,7 @@ export class Server {
263
263
  return s;
264
264
  }
265
265
  async proxy(ctx, url, headers_ = {}) {
266
- const { request: { method, headers, query, body } } = ctx;
266
+ const { request: { method, headers, query, body, ip } } = ctx;
267
267
  let { response } = ctx;
268
268
  try {
269
269
  const response_ = await _request(url, {
@@ -272,6 +272,7 @@ export class Server {
272
272
  body,
273
273
  headers: {
274
274
  ...headers,
275
+ 'x-forwarded-for': headers['x-forwarded-for'] ? `${headers['x-forwarded-for']}, ${ip}` : ip,
275
276
  ...headers_
276
277
  },
277
278
  raw: true,