xshell 0.0.12 → 0.0.16
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/chalk.browser.ts +41 -0
- package/file.d.ts +15 -0
- package/file.js +8 -1
- package/file.js.map +1 -1
- package/myfont.sass +11 -0
- package/net.browser.ts +141 -0
- package/package.json +6 -2
- package/prototype.browser.ts +728 -0
- package/repl.js +4 -0
- package/repl.js.map +1 -1
- package/scroll-bar.sass +35 -0
- package/server.d.ts +16 -3
- package/server.js +122 -2
- package/server.js.map +1 -1
- package/toaster.browser.ts +50 -0
- package/toaster.d.ts +9 -0
- package/toaster.sass +22 -0
- package/tsconfig.json +5 -0
- package/ufs.d.ts +21 -0
- package/ufs.js +153 -0
- package/ufs.js.map +1 -0
- package/utils.browser.ts +25 -0
- package/utils.d.ts +1 -1
package/ufs.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type fs from 'fs';
|
|
3
|
+
import './prototype.js';
|
|
4
|
+
declare 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 declare let ufs: UFS;
|
|
20
|
+
export declare function set_ufs(_ufs: UFS): void;
|
|
21
|
+
export default UFS;
|
package/ufs.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.set_ufs = exports.ufs = exports.UFS = void 0;
|
|
4
|
+
const lists_js_1 = require("fs-monkey/lib/util/lists.js");
|
|
5
|
+
require("./prototype.js");
|
|
6
|
+
class UFS {
|
|
7
|
+
constructor(fss) {
|
|
8
|
+
this.fss = fss || [];
|
|
9
|
+
const overriden_methods = Object.getOwnPropertyNames(UFS.prototype);
|
|
10
|
+
const filter_out_overriden_methods = (method) => !overriden_methods.includes(method);
|
|
11
|
+
lists_js_1.fsSyncMethods.filter(filter_out_overriden_methods).forEach(method => {
|
|
12
|
+
this[method] = UFS.sync_method_wrapper.bind(this, method);
|
|
13
|
+
}, this);
|
|
14
|
+
lists_js_1.fsAsyncMethods.filter(filter_out_overriden_methods).forEach(method => {
|
|
15
|
+
this[method] = UFS.async_method_wrapper.bind(this, method);
|
|
16
|
+
}, this);
|
|
17
|
+
}
|
|
18
|
+
use(fs) {
|
|
19
|
+
this.fss = [fs, ...this.fss];
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
existsSync(path) {
|
|
23
|
+
for (let fs of this.fss)
|
|
24
|
+
if (fs.existsSync(path))
|
|
25
|
+
return true;
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
readdir(...args) {
|
|
29
|
+
const method = 'readdir';
|
|
30
|
+
let callback = args.last;
|
|
31
|
+
if (typeof callback !== 'function')
|
|
32
|
+
callback = null;
|
|
33
|
+
else
|
|
34
|
+
args.pop();
|
|
35
|
+
let files = new Set();
|
|
36
|
+
const iterate = (i, error) => {
|
|
37
|
+
if (i >= this.fss.length)
|
|
38
|
+
return callback === null || callback === void 0 ? void 0 : callback(error, [...files].sort());
|
|
39
|
+
const fs = this.fss[i];
|
|
40
|
+
if (!fs[method])
|
|
41
|
+
return iterate(i + 1, new Error(`fs no method: ${method}, args: ${args}`));
|
|
42
|
+
fs[method](...args, (fsError, _files) => {
|
|
43
|
+
if (!fsError) {
|
|
44
|
+
files = new Set([...files, ..._files]);
|
|
45
|
+
return iterate(i + 1, null);
|
|
46
|
+
}
|
|
47
|
+
fsError.prev = error;
|
|
48
|
+
return iterate(i + 1, fsError);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
return iterate(0, null);
|
|
52
|
+
}
|
|
53
|
+
readdirSync(...args) {
|
|
54
|
+
const method = 'readdirSync';
|
|
55
|
+
let last_error = null;
|
|
56
|
+
let files = new Set();
|
|
57
|
+
this.fss.forEach(fs => {
|
|
58
|
+
try {
|
|
59
|
+
if (!fs[method])
|
|
60
|
+
throw new Error(`fs no method: ${method}, args: ${args}`);
|
|
61
|
+
files = new Set([...files, ...fs[method].apply(fs, args)]);
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
error.prev = last_error;
|
|
65
|
+
last_error = error;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (last_error)
|
|
69
|
+
throw last_error;
|
|
70
|
+
return [...files].sort();
|
|
71
|
+
}
|
|
72
|
+
createReadStream(path, options) {
|
|
73
|
+
let last_error = null;
|
|
74
|
+
for (let fs of this.fss)
|
|
75
|
+
try {
|
|
76
|
+
if (!fs.createReadStream)
|
|
77
|
+
throw new Error('method not supported: "createReadStream"');
|
|
78
|
+
if (!fs.existsSync)
|
|
79
|
+
throw new Error('method not supported: "existsSync"');
|
|
80
|
+
if (!fs.existsSync(path))
|
|
81
|
+
throw new Error(`文件不存在:${path}`);
|
|
82
|
+
const read_stream = fs.createReadStream.apply(fs, arguments);
|
|
83
|
+
if (!read_stream)
|
|
84
|
+
throw new Error('no valid read stream');
|
|
85
|
+
return read_stream;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
error.prev = last_error;
|
|
89
|
+
last_error = error;
|
|
90
|
+
}
|
|
91
|
+
throw last_error;
|
|
92
|
+
}
|
|
93
|
+
createWriteStream(path, options) {
|
|
94
|
+
let last_error = null;
|
|
95
|
+
for (let fs of this.fss)
|
|
96
|
+
try {
|
|
97
|
+
if (!fs.createWriteStream)
|
|
98
|
+
throw new Error('Method not supported: "createWriteStream"');
|
|
99
|
+
fs.statSync(path);
|
|
100
|
+
const write_stream = fs.createWriteStream.apply(fs, arguments);
|
|
101
|
+
if (!write_stream)
|
|
102
|
+
throw new Error('no valid write stream');
|
|
103
|
+
return write_stream;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
error.prev = last_error;
|
|
107
|
+
last_error = error;
|
|
108
|
+
}
|
|
109
|
+
throw last_error;
|
|
110
|
+
}
|
|
111
|
+
static sync_method_wrapper(method, ...args) {
|
|
112
|
+
let last_error = null;
|
|
113
|
+
for (let fs of this.fss)
|
|
114
|
+
try {
|
|
115
|
+
if (!fs[method])
|
|
116
|
+
throw new Error(`fs no method: ${method}, args: ${args}`);
|
|
117
|
+
return fs[method].apply(fs, args);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
error.prev = last_error;
|
|
121
|
+
last_error = error;
|
|
122
|
+
}
|
|
123
|
+
throw last_error;
|
|
124
|
+
}
|
|
125
|
+
static async_method_wrapper(method, ...args) {
|
|
126
|
+
let callback = args.last;
|
|
127
|
+
if (typeof callback !== 'function')
|
|
128
|
+
callback = null;
|
|
129
|
+
else
|
|
130
|
+
args.pop();
|
|
131
|
+
const iterate = (i, error) => {
|
|
132
|
+
if (i >= this.fss.length)
|
|
133
|
+
return callback === null || callback === void 0 ? void 0 : callback(error);
|
|
134
|
+
const fs = this.fss[i];
|
|
135
|
+
if (!fs[method])
|
|
136
|
+
return iterate(i + 1, new Error(`fs no method: ${method}, args: ${args}`));
|
|
137
|
+
return fs[method](...args, (fs_error, ...results) => {
|
|
138
|
+
if (!fs_error)
|
|
139
|
+
return callback === null || callback === void 0 ? void 0 : callback.call(fs, null, ...results);
|
|
140
|
+
fs_error.prev = error;
|
|
141
|
+
return iterate(i + 1, fs_error);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
return iterate(0, null);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.UFS = UFS;
|
|
148
|
+
function set_ufs(_ufs) {
|
|
149
|
+
exports.ufs = _ufs;
|
|
150
|
+
}
|
|
151
|
+
exports.set_ufs = set_ufs;
|
|
152
|
+
exports.default = UFS;
|
|
153
|
+
//# sourceMappingURL=ufs.js.map
|
package/ufs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ufs.js","sourceRoot":"","sources":["ufs.ts"],"names":[],"mappings":";;;AAAA,0DAAkH;AAKlH,0BAAuB;AAQvB,MAAa,GAAG;IAGZ,YAAa,GAAU;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,IAAI,EAAE,CAAA;QAEpB,MAAM,iBAAiB,GAAG,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;QAEnE,MAAM,4BAA4B,GAAG,CAAC,MAAc,EAAE,EAAE,CACpD,CAAC,iBAAiB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;QAEvC,wBAAe,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,OAAO,CAAE,MAAM,CAAC,EAAE;YACnE,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC7D,CAAC,EAAE,IAAI,CAAC,CAAA;QAER,yBAAgB,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC,OAAO,CAAE,MAAM,CAAC,EAAE;YACpE,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,oBAAoB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAC9D,CAAC,EAAE,IAAI,CAAC,CAAA;IACZ,CAAC;IAGD,GAAG,CAAE,EAAO;QACR,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QAC5B,OA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EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,CAAA;gBAC1D,QAAQ,CAAC,IAAI,GAAG,KAAK,CAAA;gBACrB,OAAO,OAAO,CAAC,CAAC,GAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;YACjC,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;IAC3B,CAAC;CACJ;AAxKD,kBAwKC;AAID,SAAgB,OAAO,CAAE,IAAS;IAC9B,WAAG,GAAG,IAAI,CAAA;AACd,CAAC;AAFD,0BAEC;AAED,kBAAe,GAAG,CAAA","sourcesContent":["import { fsAsyncMethods as fs_async_methods, fsSyncMethods 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 (let fs of this.fss)\n if (fs.existsSync(path)) 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 (let 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 (let 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 \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) return callback?.(error)\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 return fs[method](...args, (fs_error: Error & { prev: Error }, ...results: any[]) => {\n if (!fs_error) 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\nexport let ufs: UFS\n\nexport function set_ufs (_ufs: UFS) {\n ufs = _ufs\n}\n\nexport default UFS\n"]}
|
package/utils.browser.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export async function delay (milliseconds: number) {
|
|
2
|
+
return new Promise<void>( resolve => {
|
|
3
|
+
setTimeout(() => {
|
|
4
|
+
resolve()
|
|
5
|
+
}, milliseconds)
|
|
6
|
+
})
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
11
|
+
export function concat (arrays: ArrayBufferView[]) {
|
|
12
|
+
let length = 0
|
|
13
|
+
for (const a of arrays)
|
|
14
|
+
length += a.byteLength
|
|
15
|
+
|
|
16
|
+
let buf = new Uint8Array(length)
|
|
17
|
+
let offset = 0
|
|
18
|
+
for (const a of arrays) {
|
|
19
|
+
const uint8view = new Uint8Array(a.buffer, a.byteOffset, a.byteLength)
|
|
20
|
+
buf.set(uint8view, offset)
|
|
21
|
+
offset += uint8view.byteLength
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return buf
|
|
25
|
+
}
|
package/utils.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function unique<T>(iterable: T[] | Iterable<T>, selector?: string
|
|
|
11
11
|
/** sort keys in object and returns new object */
|
|
12
12
|
export declare function sort_keys<T>(obj: T): T;
|
|
13
13
|
/** string compare in lexicographic order */
|
|
14
|
-
export declare function strcmp(l: string, r: string):
|
|
14
|
+
export declare function strcmp(l: string, r: string): 0 | 1 | -1;
|
|
15
15
|
/** 拼接 TypedArrays 生成一个完整的 Uint8Array */
|
|
16
16
|
export declare function concat(views: ArrayBufferView[]): Uint8Array;
|
|
17
17
|
export declare function typed_array_to_buffer(view: ArrayBufferView): Buffer;
|