xshell 1.0.21 → 1.0.22
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 +1 -11
- package/file.js +0 -9
- package/file.js.map +1 -1
- package/i18n/dict.json +9 -0
- package/net.browser.js +22 -25
- package/net.browser.js.map +1 -1
- package/net.js +23 -27
- package/net.js.map +1 -1
- package/package.json +10 -19
- package/repl.js +11 -11
- package/repl.js.map +1 -1
- package/server.d.ts +2 -8
- package/server.js +17 -15
- package/server.js.map +1 -1
- package/tsconfig.json +1 -1
- package/utils.browser.d.ts +3 -0
- package/utils.browser.js +4 -3
- package/utils.browser.js.map +1 -1
- package/utils.d.ts +6 -6
- package/utils.js +13 -22
- package/utils.js.map +1 -1
- package/ufs.d.ts +0 -19
- package/ufs.js +0 -145
- package/ufs.js.map +0 -1
package/ufs.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
import type fs from 'fs';
|
|
3
|
-
import './prototype.js';
|
|
4
|
-
type FS = typeof fs;
|
|
5
|
-
export interface UFS extends FS {
|
|
6
|
-
}
|
|
7
|
-
export declare class UFS {
|
|
8
|
-
fss: FS[];
|
|
9
|
-
constructor(fss: any[]);
|
|
10
|
-
use(fs: any): this;
|
|
11
|
-
existsSync(path: string): boolean;
|
|
12
|
-
readdir(...args: any[]): any;
|
|
13
|
-
readdirSync(...args: any[]): unknown[];
|
|
14
|
-
createReadStream(path: string, options?: any): any;
|
|
15
|
-
createWriteStream(path: string, options?: any): any;
|
|
16
|
-
static sync_method_wrapper(this: UFS, method: string, ...args: any[]): any;
|
|
17
|
-
static async_method_wrapper(this: UFS, method: string, ...args: any[]): any;
|
|
18
|
-
}
|
|
19
|
-
export {};
|
package/ufs.js
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { fsAsyncMethods as fs_async_methods, fsSyncMethods as fs_sync_methods } from 'fs-monkey/lib/util/lists.js';
|
|
2
|
-
import './prototype.js';
|
|
3
|
-
export class UFS {
|
|
4
|
-
fss;
|
|
5
|
-
constructor(fss) {
|
|
6
|
-
this.fss = fss || [];
|
|
7
|
-
const overriden_methods = Object.getOwnPropertyNames(UFS.prototype);
|
|
8
|
-
const filter_out_overriden_methods = (method) => !overriden_methods.includes(method);
|
|
9
|
-
fs_sync_methods.filter(filter_out_overriden_methods).forEach(method => {
|
|
10
|
-
this[method] = UFS.sync_method_wrapper.bind(this, method);
|
|
11
|
-
}, this);
|
|
12
|
-
fs_async_methods.filter(filter_out_overriden_methods).forEach(method => {
|
|
13
|
-
this[method] = UFS.async_method_wrapper.bind(this, method);
|
|
14
|
-
}, this);
|
|
15
|
-
}
|
|
16
|
-
use(fs) {
|
|
17
|
-
this.fss = [fs, ...this.fss];
|
|
18
|
-
return this;
|
|
19
|
-
}
|
|
20
|
-
existsSync(path) {
|
|
21
|
-
for (const fs of this.fss)
|
|
22
|
-
if (fs.existsSync(path))
|
|
23
|
-
return true;
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
readdir(...args) {
|
|
27
|
-
const method = 'readdir';
|
|
28
|
-
let callback = args.last;
|
|
29
|
-
if (typeof callback !== 'function')
|
|
30
|
-
callback = null;
|
|
31
|
-
else
|
|
32
|
-
args.pop();
|
|
33
|
-
let files = new Set();
|
|
34
|
-
const iterate = (i, error) => {
|
|
35
|
-
if (i >= this.fss.length)
|
|
36
|
-
return callback?.(error, [...files].sort());
|
|
37
|
-
const fs = this.fss[i];
|
|
38
|
-
if (!fs[method])
|
|
39
|
-
return iterate(i + 1, new Error(`fs no method: ${method}, args: ${args}`));
|
|
40
|
-
fs[method](...args, (fsError, _files) => {
|
|
41
|
-
if (!fsError) {
|
|
42
|
-
files = new Set([...files, ..._files]);
|
|
43
|
-
return iterate(i + 1, null);
|
|
44
|
-
}
|
|
45
|
-
fsError.prev = error;
|
|
46
|
-
return iterate(i + 1, fsError);
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
return iterate(0, null);
|
|
50
|
-
}
|
|
51
|
-
readdirSync(...args) {
|
|
52
|
-
const method = 'readdirSync';
|
|
53
|
-
let last_error = null;
|
|
54
|
-
let files = new Set();
|
|
55
|
-
this.fss.forEach(fs => {
|
|
56
|
-
try {
|
|
57
|
-
if (!fs[method])
|
|
58
|
-
throw new Error(`fs no method: ${method}, args: ${args}`);
|
|
59
|
-
files = new Set([...files, ...fs[method].apply(fs, args)]);
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
error.prev = last_error;
|
|
63
|
-
last_error = error;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
if (last_error)
|
|
67
|
-
throw last_error;
|
|
68
|
-
return [...files].sort();
|
|
69
|
-
}
|
|
70
|
-
createReadStream(path, options) {
|
|
71
|
-
let last_error = null;
|
|
72
|
-
for (const fs of this.fss)
|
|
73
|
-
try {
|
|
74
|
-
if (!fs.createReadStream)
|
|
75
|
-
throw new Error('method not supported: "createReadStream"');
|
|
76
|
-
if (!fs.existsSync)
|
|
77
|
-
throw new Error('method not supported: "existsSync"');
|
|
78
|
-
if (!fs.existsSync(path))
|
|
79
|
-
throw new Error(`文件不存在:${path}`);
|
|
80
|
-
const read_stream = fs.createReadStream.apply(fs, arguments);
|
|
81
|
-
if (!read_stream)
|
|
82
|
-
throw new Error('no valid read stream');
|
|
83
|
-
return read_stream;
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
error.prev = last_error;
|
|
87
|
-
last_error = error;
|
|
88
|
-
}
|
|
89
|
-
throw last_error;
|
|
90
|
-
}
|
|
91
|
-
createWriteStream(path, options) {
|
|
92
|
-
let last_error = null;
|
|
93
|
-
for (const fs of this.fss)
|
|
94
|
-
try {
|
|
95
|
-
if (!fs.createWriteStream)
|
|
96
|
-
throw new Error('Method not supported: "createWriteStream"');
|
|
97
|
-
fs.statSync(path);
|
|
98
|
-
const write_stream = fs.createWriteStream.apply(fs, arguments);
|
|
99
|
-
if (!write_stream)
|
|
100
|
-
throw new Error('no valid write stream');
|
|
101
|
-
return write_stream;
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
error.prev = last_error;
|
|
105
|
-
last_error = error;
|
|
106
|
-
}
|
|
107
|
-
throw last_error;
|
|
108
|
-
}
|
|
109
|
-
static sync_method_wrapper(method, ...args) {
|
|
110
|
-
let last_error = null;
|
|
111
|
-
for (let fs of this.fss)
|
|
112
|
-
try {
|
|
113
|
-
if (!fs[method])
|
|
114
|
-
throw new Error(`fs no method: ${method}, args: ${args}`);
|
|
115
|
-
return fs[method].apply(fs, args);
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
error.prev = last_error;
|
|
119
|
-
last_error = error;
|
|
120
|
-
}
|
|
121
|
-
throw last_error;
|
|
122
|
-
}
|
|
123
|
-
static async_method_wrapper(method, ...args) {
|
|
124
|
-
let callback = args.last;
|
|
125
|
-
if (typeof callback !== 'function')
|
|
126
|
-
callback = null;
|
|
127
|
-
else
|
|
128
|
-
args.pop();
|
|
129
|
-
const iterate = (i, error) => {
|
|
130
|
-
if (i >= this.fss.length)
|
|
131
|
-
return callback?.(error);
|
|
132
|
-
const fs = this.fss[i];
|
|
133
|
-
if (!fs[method])
|
|
134
|
-
return iterate(i + 1, new Error(`fs no method: ${method}, args: ${args}`));
|
|
135
|
-
return fs[method](...args, (fs_error, ...results) => {
|
|
136
|
-
if (!fs_error)
|
|
137
|
-
return callback?.call(fs, null, ...results);
|
|
138
|
-
fs_error.prev = error;
|
|
139
|
-
return iterate(i + 1, fs_error);
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
return iterate(0, null);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
//# sourceMappingURL=ufs.js.map
|
package/ufs.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ufs.js","sourceRoot":"","sources":["ufs.ts"],"names":[],"mappings":"AAAA,O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ethods as fs_sync_methods } from 'fs-monkey/lib/util/lists.js'\n\nimport type fs from 'fs'\n\n\nimport './prototype.js'\n\n\ntype FS = typeof fs\n\n// @ts-ignore\nexport interface UFS extends FS { }\n\nexport class UFS {\n fss: FS[]\n \n constructor (fss: any[]) {\n this.fss = fss || []\n \n const overriden_methods = Object.getOwnPropertyNames(UFS.prototype)\n \n const filter_out_overriden_methods = (method: string) => \n !overriden_methods.includes(method)\n \n fs_sync_methods.filter(filter_out_overriden_methods).forEach( method => {\n this[method] = UFS.sync_method_wrapper.bind(this, method)\n }, this)\n \n fs_async_methods.filter(filter_out_overriden_methods).forEach( method => {\n this[method] = UFS.async_method_wrapper.bind(this, method)\n }, this)\n }\n \n \n use (fs: any) {\n this.fss = [fs, ...this.fss]\n return this\n }\n \n \n existsSync (path: string) {\n for (const fs of this.fss)\n if (fs.existsSync(path))\n return true\n return false\n }\n \n \n readdir (...args) {\n const method = 'readdir'\n \n let callback = args.last\n \n if (typeof callback !== 'function')\n callback = null\n else\n args.pop()\n \n let files = new Set()\n \n const iterate = (i: number, error: Error) => {\n if (i >= this.fss.length) return callback?.(error, [...files].sort())\n \n const fs = this.fss[i]\n \n if (!fs[method]) return iterate(i+1, new Error(`fs no method: ${method}, args: ${args}`))\n \n fs[method as string](...args, (fsError: Error & { prev: Error }, _files: string[]) => {\n if (!fsError) {\n files = new Set([...files, ..._files])\n return iterate(i+1, null)\n }\n fsError.prev = error\n return iterate(i+1, fsError)\n })\n }\n \n return iterate(0, null)\n }\n \n \n readdirSync (...args) {\n const method = 'readdirSync'\n \n let last_error = null\n let files = new Set()\n \n this.fss.forEach( fs => {\n try {\n if (!fs[method]) throw new Error(`fs no method: ${method}, args: ${args}`)\n \n files = new Set([...files, ...fs[method].apply(fs, args)])\n } catch (error) {\n error.prev = last_error\n last_error = error\n }\n })\n \n if (last_error) throw last_error\n \n return [...files].sort()\n }\n \n \n createReadStream (path: string, options?: any) {\n let last_error = null\n \n for (const fs of this.fss)\n try {\n if (!fs.createReadStream) throw new Error('method not supported: \"createReadStream\"')\n if (!fs.existsSync) throw new Error('method not supported: \"existsSync\"')\n if (!fs.existsSync(path)) throw new Error(`文件不存在:${path}`)\n const read_stream = fs.createReadStream.apply(fs, arguments)\n if (!read_stream) throw new Error('no valid read stream')\n return read_stream\n } catch (error) {\n error.prev = last_error\n last_error = error\n }\n \n throw last_error\n }\n \n \n createWriteStream (path: string, options?: any) {\n let last_error = null\n \n for (const fs of this.fss)\n try {\n if (!fs.createWriteStream) throw new Error('Method not supported: \"createWriteStream\"')\n fs.statSync(path)\n const write_stream = fs.createWriteStream.apply(fs, arguments)\n if (!write_stream) throw new Error('no valid write stream')\n return write_stream\n } catch (error) {\n error.prev = last_error\n last_error = error\n }\n \n throw last_error\n }\n \n \n static sync_method_wrapper (this: UFS, method: string, ...args: any[]) {\n let last_error: Error = null\n for (let fs of this.fss)\n try {\n if (!fs[method]) throw new Error(`fs no method: ${method}, args: ${args}`)\n return fs[method].apply(fs, args)\n } catch (error) {\n error.prev = last_error\n last_error = error\n }\n throw last_error\n }\n \n \n static async_method_wrapper (this: UFS, method: string, ...args: any[]) {\n let callback = args.last\n \n if (typeof callback !== 'function')\n callback = null\n else\n args.pop()\n \n const iterate = (i: number, error: Error) => {\n if (i >= this.fss.length)\n return callback?.(error)\n \n const fs = this.fss[i]\n \n if (!fs[method])\n return iterate(i + 1, new Error(`fs no method: ${method}, args: ${args}`))\n \n return fs[method](...args, (fs_error: Error & { prev: Error }, ...results: any[]) => {\n if (!fs_error)\n return callback?.call(fs, null, ...results)\n fs_error.prev = error\n return iterate(i + 1, fs_error)\n })\n }\n \n return iterate(0, null)\n }\n}\n"]}
|