xshell 0.0.10 → 0.0.14
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/extension.js +11 -11
- package/extension.js.map +1 -1
- package/file.d.ts +34 -13
- package/file.js +28 -19
- package/file.js.map +1 -1
- package/net.d.ts +28 -19
- package/net.js +66 -56
- package/net.js.map +1 -1
- package/package.json +15 -19
- package/process.d.ts +14 -14
- package/process.js +56 -62
- package/process.js.map +1 -1
- package/prototype.d.ts +31 -20
- package/prototype.js +115 -96
- package/prototype.js.map +1 -1
- package/repl.d.ts +2 -5
- package/repl.js +72 -58
- package/repl.js.map +1 -1
- package/server.d.ts +26 -9
- package/server.js +224 -100
- package/server.js.map +1 -1
- package/tsconfig.json +6 -6
- package/ufs.d.ts +21 -0
- package/ufs.js +153 -0
- package/ufs.js.map +1 -0
- package/utils.d.ts +17 -10
- package/utils.js +84 -41
- package/utils.js.map +1 -1
package/net.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rpc_curl = exports.rpc = exports.to_curl = exports.request_page = exports.parse_html = exports.request_json = exports.request = exports.request_retry = exports._request = exports.Cookie = exports.
|
|
3
|
+
exports.rpc_curl = exports.rpc = exports.to_curl = exports.request_page = exports.parse_html = exports.request_json = exports.request = exports.request_retry = exports._request = exports.Cookie = exports.cookies = exports.MyProxy = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const request_promise_native_1 = (0, tslib_1.__importDefault)(require("request-promise-native"));
|
|
6
6
|
const errors_1 = require("request-promise-native/errors");
|
|
@@ -14,13 +14,12 @@ require("./prototype");
|
|
|
14
14
|
const utils_1 = require("./utils");
|
|
15
15
|
var MyProxy;
|
|
16
16
|
(function (MyProxy) {
|
|
17
|
-
MyProxy["
|
|
18
|
-
MyProxy["whistle"] = "http://
|
|
17
|
+
MyProxy["socks5"] = "http://localhost:10080";
|
|
18
|
+
MyProxy["whistle"] = "http://localhost:8899";
|
|
19
19
|
})(MyProxy = exports.MyProxy || (exports.MyProxy = {}));
|
|
20
20
|
// ------------------------------------ Fetch, Request
|
|
21
|
-
const DEFAULT_RETRIES = 3;
|
|
22
21
|
const cookie_store = new tough_cookie_1.MemoryCookieStore();
|
|
23
|
-
exports.
|
|
22
|
+
exports.cookies = {
|
|
24
23
|
store: cookie_store,
|
|
25
24
|
jar: request_promise_native_1.default.jar(cookie_store),
|
|
26
25
|
get(domain_or_url, str = false) {
|
|
@@ -43,7 +42,7 @@ exports._request = request_promise_native_1.default.defaults({
|
|
|
43
42
|
gzip: true,
|
|
44
43
|
/** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */
|
|
45
44
|
simple: false,
|
|
46
|
-
jar: exports.
|
|
45
|
+
jar: exports.cookies.jar
|
|
47
46
|
});
|
|
48
47
|
async function request_retry(retries, request_options) {
|
|
49
48
|
return (0, promise_retry_1.default)({
|
|
@@ -66,20 +65,16 @@ async function request_retry(retries, request_options) {
|
|
|
66
65
|
});
|
|
67
66
|
}
|
|
68
67
|
exports.request_retry = request_retry;
|
|
69
|
-
async function request(url, { queries, body, json,
|
|
68
|
+
async function request(url, { queries, body, type = 'application/json', proxy, method, headers, encoding, raw = false, retries, timeout = 20 * 1000, auth, gzip, cookies, } = {}) {
|
|
70
69
|
var _a;
|
|
71
70
|
url = url.toString();
|
|
72
71
|
if (!url.startsWith('http'))
|
|
73
72
|
url = 'http://' + url;
|
|
73
|
+
const _body = body; // for error log
|
|
74
74
|
if (body && !method)
|
|
75
|
-
method = '
|
|
76
|
-
if (
|
|
77
|
-
// pass
|
|
78
|
-
}
|
|
79
|
-
else if (typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body))) {
|
|
80
|
-
json = true;
|
|
75
|
+
method = 'post';
|
|
76
|
+
if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))
|
|
81
77
|
body = JSON.stringify(body);
|
|
82
|
-
}
|
|
83
78
|
// --- proxy
|
|
84
79
|
if (proxy) {
|
|
85
80
|
if (proxy === true)
|
|
@@ -92,22 +87,32 @@ async function request(url, { queries, body, json, form, proxy, method, headers,
|
|
|
92
87
|
gzip = !raw;
|
|
93
88
|
const options = {
|
|
94
89
|
url,
|
|
95
|
-
method,
|
|
90
|
+
...method ? { method: method.toUpperCase() } : {},
|
|
96
91
|
proxy,
|
|
97
92
|
gzip,
|
|
98
93
|
encoding: null,
|
|
99
94
|
resolveWithFullResponse: true,
|
|
100
95
|
headers: {
|
|
101
96
|
'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',
|
|
102
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
103
|
-
...
|
|
104
|
-
...cookies ? {
|
|
97
|
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',
|
|
98
|
+
...body ? { 'content-type': type } : {},
|
|
99
|
+
...cookies ? {
|
|
100
|
+
cookie: Object.entries(cookies)
|
|
101
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('; ')
|
|
102
|
+
} : {},
|
|
105
103
|
...headers
|
|
106
104
|
},
|
|
107
105
|
...queries ? { qs: queries } : {},
|
|
108
|
-
|
|
109
|
-
...(
|
|
110
|
-
|
|
106
|
+
// --- body
|
|
107
|
+
...(() => {
|
|
108
|
+
if (!body)
|
|
109
|
+
return {};
|
|
110
|
+
if (type === 'application/x-www-form-urlencoded')
|
|
111
|
+
return { form: body };
|
|
112
|
+
if (type === 'multipart/form-data')
|
|
113
|
+
return { formData: body };
|
|
114
|
+
return { body };
|
|
115
|
+
})(),
|
|
111
116
|
...timeout ? { timeout } : {},
|
|
112
117
|
...auth ? { auth } : {},
|
|
113
118
|
};
|
|
@@ -115,7 +120,7 @@ async function request(url, { queries, body, json, form, proxy, method, headers,
|
|
|
115
120
|
try {
|
|
116
121
|
if (retries) {
|
|
117
122
|
if (retries === true)
|
|
118
|
-
retries =
|
|
123
|
+
retries = 3;
|
|
119
124
|
resp = await request_retry(retries, options);
|
|
120
125
|
}
|
|
121
126
|
else
|
|
@@ -124,52 +129,53 @@ async function request(url, { queries, body, json, form, proxy, method, headers,
|
|
|
124
129
|
throw new errors_1.StatusCodeError(resp.statusCode, resp.body, options, resp);
|
|
125
130
|
}
|
|
126
131
|
catch (error) {
|
|
127
|
-
const { name, options: { method, url, uri, qs
|
|
132
|
+
const { name, options: { method, url, uri, qs }, response, } = error;
|
|
128
133
|
error[utils_1.inspect.custom] = () => {
|
|
129
|
-
let s = '─'.repeat(
|
|
130
|
-
`${
|
|
134
|
+
let s = '─'.repeat(utils_1.output_width / 2) + '\n' +
|
|
135
|
+
`${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\n`;
|
|
131
136
|
if (qs)
|
|
132
|
-
s += `\n${'
|
|
137
|
+
s += `\n${'request.query:'.blue}\n` +
|
|
133
138
|
(0, utils_1.inspect)(qs) + '\n';
|
|
134
|
-
if (
|
|
135
|
-
s += `\n${'
|
|
139
|
+
if (_body)
|
|
140
|
+
s += `\n${'request.body:'.blue}\n` +
|
|
136
141
|
(0, utils_1.inspect)(body) + '\n';
|
|
137
142
|
if (name === 'StatusCodeError')
|
|
138
|
-
s += `\n${'
|
|
143
|
+
s += `\n${'response.status:'.yellow} ${String(error.statusCode).red}\n`;
|
|
139
144
|
else if (error instanceof errors_1.RequestError)
|
|
140
|
-
s += `\n${'
|
|
145
|
+
s += `\n${'response.cause:'.yellow}\n` +
|
|
141
146
|
`${(0, utils_1.inspect)(error.cause)}\n`;
|
|
142
147
|
else
|
|
143
148
|
s += `\n${(0, utils_1.inspect)(error)}\n`;
|
|
144
149
|
if (response) {
|
|
145
|
-
s += `\n${'
|
|
150
|
+
s += `\n${'response.headers:'.yellow}\n` +
|
|
146
151
|
`${(0, utils_1.inspect)(response.headers)}\n`;
|
|
147
152
|
if (response.body)
|
|
148
|
-
s += `\n${'
|
|
153
|
+
s += `\n${'response.body:'.yellow}\n` +
|
|
149
154
|
`${(0, utils_1.inspect)(response.body.toString())}\n`;
|
|
150
155
|
}
|
|
151
|
-
s += `\n${'
|
|
156
|
+
s += `\n${'stack:'.yellow}\n` +
|
|
152
157
|
`${new Error().stack}\n` +
|
|
153
|
-
'─'.repeat(
|
|
158
|
+
'─'.repeat(utils_1.output_width / 2);
|
|
154
159
|
return s;
|
|
155
160
|
};
|
|
156
161
|
throw error;
|
|
157
162
|
}
|
|
158
|
-
if (encoding === 'BINARY')
|
|
159
|
-
return resp.body;
|
|
160
|
-
encoding = (encoding || ((_a = /charset=(.*)/.exec(resp.headers['content-type'])) === null || _a === void 0 ? void 0 : _a[1]) || 'UTF-8');
|
|
161
163
|
if (raw)
|
|
162
164
|
return resp;
|
|
163
165
|
if (!resp.body)
|
|
164
166
|
return resp.body;
|
|
167
|
+
// --- decode body
|
|
168
|
+
if (encoding === 'binary')
|
|
169
|
+
return resp.body;
|
|
170
|
+
encoding || (encoding = ((_a = /charset=(.*)/.exec(resp.headers['content-type'])) === null || _a === void 0 ? void 0 : _a[1]) || 'utf-8');
|
|
171
|
+
if (/utf-?8/i.test(encoding))
|
|
172
|
+
return resp.body.toString('utf-8');
|
|
165
173
|
return iconv_lite_1.default.decode(resp.body, encoding);
|
|
166
174
|
}
|
|
167
175
|
exports.request = request;
|
|
176
|
+
/** make http request and parse body as json */
|
|
168
177
|
async function request_json(url, options) {
|
|
169
|
-
const resp = await request(url,
|
|
170
|
-
json: true,
|
|
171
|
-
...options
|
|
172
|
-
});
|
|
178
|
+
const resp = await request(url, options);
|
|
173
179
|
if (!resp)
|
|
174
180
|
return;
|
|
175
181
|
try {
|
|
@@ -212,7 +218,7 @@ async function request_page(url, options) {
|
|
|
212
218
|
return parse_html(await request(url, options));
|
|
213
219
|
}
|
|
214
220
|
exports.request_page = request_page;
|
|
215
|
-
function to_curl(url, { queries, headers, method, body,
|
|
221
|
+
function to_curl(url, { queries, headers, method, body, proxy, exe = true } = {}) {
|
|
216
222
|
if (proxy === true)
|
|
217
223
|
proxy = process.env.http_proxy;
|
|
218
224
|
url = url.toString();
|
|
@@ -226,34 +232,38 @@ function to_curl(url, { queries, headers, method, body, json, proxy, exe = true
|
|
|
226
232
|
// ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())
|
|
227
233
|
// ) +
|
|
228
234
|
(proxy ? ` --proxy ${proxy.quote()}` : '') +
|
|
229
|
-
(method && method !== '
|
|
235
|
+
(method && method !== 'get' ? ` -X ${method}` : '') +
|
|
230
236
|
(headers ? Object.entries(headers).map(([key, value]) => ' -H ' + `${key}: ${value}`.quote()).join('') : '') +
|
|
231
|
-
(
|
|
237
|
+
(body ? ' -H ' + 'content-type: application/json'.quote() : '') +
|
|
232
238
|
(body ? ' --data ' + JSON.stringify(body).quote() : '');
|
|
233
239
|
}
|
|
234
240
|
exports.to_curl = to_curl;
|
|
235
|
-
// ------------------------------------
|
|
236
|
-
/**
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
241
|
+
// ------------------------------------ rpc client
|
|
242
|
+
/** post json to http://localhost:8421/api/rpc
|
|
243
|
+
- func: function name
|
|
244
|
+
- args?: argument array
|
|
245
|
+
- options?:
|
|
246
|
+
- ignore?: `false` wait for execution but do not serialize result to response
|
|
247
|
+
- async?: `false` do not wait for exec
|
|
248
|
+
*/
|
|
249
|
+
async function rpc(func, args, { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false } = {}) {
|
|
250
|
+
if (!func)
|
|
251
|
+
throw new Error('rpc argument error: no func');
|
|
242
252
|
return request_json(url, {
|
|
243
253
|
body: {
|
|
244
254
|
func,
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
255
|
+
args,
|
|
256
|
+
async: _async,
|
|
257
|
+
ignore,
|
|
248
258
|
}
|
|
249
259
|
});
|
|
250
260
|
}
|
|
251
261
|
exports.rpc = rpc;
|
|
252
262
|
function rpc_curl(func, args) {
|
|
253
263
|
const cmd = args.find(arg => typeof arg === 'object') ?
|
|
254
|
-
to_curl('http://
|
|
264
|
+
to_curl('http://localhost:8421/api/rpc', { body: { func, args } })
|
|
255
265
|
:
|
|
256
|
-
to_curl('http://
|
|
266
|
+
to_curl('http://localhost:8421/api/rpc', { queries: { func, args } });
|
|
257
267
|
return cmd;
|
|
258
268
|
}
|
|
259
269
|
exports.rpc_curl = rpc_curl;
|
package/net.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAGA,iGAAoD;AAEpD,0DAA6E;AAE7E,+EAAyC;AAEzC,yEAA8B;AAC9B,mEAA6B;AAC7B,yDAAmB;AACnB,+CAAwD;AA6C/C,uFA7CA,qBAAM,OA6CA;AApCf,uBAAoB;AAEpB,mCAAiC;AAEjC,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,6CAAkC,CAAA;IAClC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,eAAe,GAAG,CAAC,CAAA;AAEzB,MAAM,YAAY,GAAG,IAAI,gCAAiB,EAAE,CAAA;AAE/B,QAAA,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAAG,EAAE,gCAAe,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtC,GAAG,CAAE,aAAqB,EAAE,GAAG,GAAG,KAAK;QACnC,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC;YAChC,IAAI,GAAG;gBACH,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;;gB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AI,CAAC,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,+BAA+B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACtE,CAAC;YACG,OAAO,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC7E,OAAO,GAAG,CAAA;AACd,CAAC;AAND,4BAMC","sourcesContent":["import request_lib from 'request'\nimport type { OptionsWithUri, OptionsWithUrl } from 'request'\n\nimport request_promise from 'request-promise-native'\nimport type { FullResponse } from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype'\nimport type { Encoding } from './file'\nimport { inspect } from './utils'\n\nexport enum MyProxy {\n HTTP1080 = 'http://127.0.0.1:1080',\n whistle = 'http://127.0.0.1:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst DEFAULT_RETRIES = 3\n\nconst cookie_store = new MemoryCookieStore()\n\nexport const Cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n rejectUnauthorized: false,\n gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: Cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n queries?: Record<string, any>\n \n /** HTTP request body data */\n body?: string | Record<string, any>\n \n /** is JSON format */\n json?: boolean\n \n /** form (x-www-form-urlencoded or multipart) format */\n form?: boolean | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n /** `false` when proxy is true then use MyProxy.whistle */\n proxy?: boolean | MyProxy | string\n \n method?: 'GET' | 'POST' | 'PUT' | 'HEAD' | 'DELETE' | 'PATCH'\n \n headers?: Record<string, string>\n \n /** `(webpage content-type: charset=gb18030) || 'UTF-8'` */\n encoding?: Encoding\n \n /** `false` */\n retries?: boolean | number\n \n /** `20 * 1000` */\n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n /** `raw -> false; else -> true` */\n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'BINARY' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n json,\n \n form,\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries = false,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n if (body && !method)\n method = 'POST'\n \n if (form) {\n // pass\n } else if (typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body))) {\n json = true\n body = JSON.stringify(body)\n }\n \n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n method,\n proxy,\n gzip,\n encoding: null,\n resolveWithFullResponse: true,\n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36',\n ... json && !form ? { 'content-type': 'application/json' } : { }, \n ... cookies ? { cookie: Object.entries(cookies).map( ([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('; ') } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n ... (!form && body) ? { body } : { },\n ... (form === true || form === 'application/x-www-form-urlencoded') ? { form: body } : { },\n ... (form === 'multipart/form-data') ? { formData: body as Record<string, any> } : { },\n ... timeout ? { timeout } : { },\n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = DEFAULT_RETRIES\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs, body }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(global.WIDTH / 2) + '\\n' +\n `${name.red} ${(method || 'GET').blue} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'Request Query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (body)\n s += `\\n${'Request Body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'Status Code:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'Cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'Response Headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'Response Body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'Stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(global.WIDTH / 2)\n \n return s\n }\n \n throw error\n }\n \n if (encoding === 'BINARY')\n return resp.body\n \n encoding = (encoding || /charset=(.*)/.exec(resp.headers['content-type'])?.[1] || 'UTF-8') as Encoding\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, {\n json: true,\n ... options\n })\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html( await request(url, options) )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, json, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'GET' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( json ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ RPC Client\n/** POST JSON to http://127.0.0.1:8421/api/rpc */\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://127.0.0.1:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) {\n console.error('RPC Client Error: NO FUNC')\n throw new Error('RPC Client Error: NO FUNC')\n }\n return request_json(url, {\n body: {\n func,\n ... args?.length ? { args } : { },\n ... _async ? { async: _async } : { },\n ... ignore ? { ignore } : { },\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://127.0.0.1:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://127.0.0.1:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAGA,iGAAoD;AAEpD,0DAA6E;AAE7E,+EAAyC;AAEzC,yEAA8B;AAC9B,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MAAM,GAAG,KAAK,KAA0D,EAAG;IAE3I,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAA;IAEzD,OAAO,YAAY,CAAC,GAAG,EAAE;QACrB,IAAI,EAAE;YACF,IAAI;YACJ,IAAI;YACJ,KAAK,EAAE,MAAM;YACb,MAAM;SACT;KACJ,CAAC,CAAA;AACN,CAAC;AAfD,kBAeC;AAGD,SAAgB,QAAQ,CAAE,IAAY,EAAE,IAAW;IAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,+BAA+B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACtE,CAAC;YACG,OAAO,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC7E,OAAO,GAAG,CAAA;AACd,CAAC;AAND,4BAMC","sourcesContent":["import request_lib from 'request'\nimport type { OptionsWithUri, OptionsWithUrl } from 'request'\n\nimport request_promise from 'request-promise-native'\nimport type { FullResponse } from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype'\nimport type { Encoding } from './file'\nimport { inspect, output_width } from './utils'\n\nexport enum MyProxy {\n socks5 = 'http://localhost:10080',\n whistle = 'http://localhost:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst cookie_store = new MemoryCookieStore()\n\nexport const cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n rejectUnauthorized: false,\n gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"xshell": "./xshell.js"
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"type": "commonjs",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=16.0.0",
|
|
18
|
-
"vscode": ">=1.
|
|
18
|
+
"vscode": ">=1.62.0"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"start": "node --title=xshell --inspect=0.0.0.0:8420 ./xshell.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"author": {
|
|
29
29
|
"name": "ShenHongFei",
|
|
30
|
-
"email": "
|
|
30
|
+
"email": "shen.hongfei@outlook.com",
|
|
31
31
|
"url": "https://github.com/ShenHongFei"
|
|
32
32
|
},
|
|
33
33
|
"publisher": "ShenHongFei",
|
|
@@ -65,50 +65,46 @@
|
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@koa/cors": "^3.1.0",
|
|
67
67
|
"byte-size": "^8.1.0",
|
|
68
|
-
"
|
|
68
|
+
"chalk": "^4.1.2",
|
|
69
|
+
"chardet": "^1.4.0",
|
|
69
70
|
"cheerio": "^1.0.0-rc.10",
|
|
70
|
-
"
|
|
71
|
-
"emoji-regex": "^9.2.2",
|
|
71
|
+
"emoji-regex": "^10.0.0",
|
|
72
72
|
"fs-extra": "^10.0.0",
|
|
73
73
|
"fs-monkey": "^1.0.3",
|
|
74
74
|
"iconv-lite": "^0.6.3",
|
|
75
|
-
"koa": "^2.13.
|
|
75
|
+
"koa": "^2.13.4",
|
|
76
76
|
"koa-compress": "^5.1.0",
|
|
77
77
|
"koa-useragent": "^4.0.0",
|
|
78
78
|
"lodash": "^4.17.21",
|
|
79
|
-
"memfs": "^3.
|
|
80
|
-
"parse-multipart-data": "^1.2.0",
|
|
79
|
+
"memfs": "^3.4.0",
|
|
81
80
|
"promise-retry": "^2.0.1",
|
|
82
|
-
"puppeteer-core": "^10.2.0",
|
|
83
81
|
"qs": "^6.10.1",
|
|
84
82
|
"readdir-enhanced": "^6.0.4",
|
|
85
83
|
"request": "^2.88.2",
|
|
86
84
|
"request-promise-native": "^1.0.9",
|
|
85
|
+
"resolve-path": "^1.4.0",
|
|
87
86
|
"rimraf": "^3.0.2",
|
|
88
87
|
"stream-buffers": "^3.0.2",
|
|
89
88
|
"strip-ansi": "=6.0.0",
|
|
90
89
|
"tough-cookie": "^4.0.0",
|
|
91
90
|
"tslib": "^2.3.1",
|
|
92
|
-
"typescript": "^4.
|
|
93
|
-
"upath": "^2.0.1"
|
|
94
|
-
"utf-8-validate": "^5.0.5"
|
|
91
|
+
"typescript": "^4.5.2",
|
|
92
|
+
"upath": "^2.0.1"
|
|
95
93
|
},
|
|
96
94
|
"devDependencies": {
|
|
97
95
|
"@types/chardet": "^0.8.1",
|
|
98
96
|
"@types/cheerio": "^0.22.30",
|
|
99
|
-
"@types/fs-extra": "^9.0.
|
|
97
|
+
"@types/fs-extra": "^9.0.13",
|
|
100
98
|
"@types/koa": "^2.13.4",
|
|
101
99
|
"@types/koa-compress": "^4.0.3",
|
|
102
|
-
"@types/lodash": "^4.14.
|
|
103
|
-
"@types/node": "^16.
|
|
104
|
-
"@types/node-schedule": "^1.3.2",
|
|
100
|
+
"@types/lodash": "^4.14.177",
|
|
101
|
+
"@types/node": "^16.11.10",
|
|
105
102
|
"@types/promise-retry": "^1.1.3",
|
|
106
103
|
"@types/qs": "^6.9.7",
|
|
107
104
|
"@types/request": "^2.48.7",
|
|
108
105
|
"@types/request-promise-native": "^1.0.18",
|
|
109
106
|
"@types/rimraf": "^3.0.2",
|
|
110
|
-
"@types/shortid": "^0.0.29",
|
|
111
107
|
"@types/stream-buffers": "^3.0.4",
|
|
112
|
-
"@types/vscode": "^1.
|
|
108
|
+
"@types/vscode": "^1.62.0"
|
|
113
109
|
}
|
|
114
110
|
}
|
package/process.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import type { ChildProcess } from 'child_process';
|
|
|
3
3
|
import './prototype';
|
|
4
4
|
import { Encoding } from './file';
|
|
5
5
|
import { inspect } from './utils';
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const fp_root: string;
|
|
7
|
+
export declare const exe_node: string;
|
|
7
8
|
interface StartOptions {
|
|
8
9
|
/** `'d:/'` */
|
|
9
10
|
cwd?: string;
|
|
10
11
|
/** `process.env` overwrite/add to process.env */
|
|
11
12
|
env?: Record<string, string>;
|
|
12
|
-
/** `'
|
|
13
|
+
/** `'utf-8'` child output encoding */
|
|
13
14
|
encoding?: Encoding;
|
|
14
15
|
/** `true` print option (with details) */
|
|
15
16
|
print?: boolean | {
|
|
@@ -25,12 +26,12 @@ interface StartOptions {
|
|
|
25
26
|
detached?: boolean;
|
|
26
27
|
}
|
|
27
28
|
/** start process
|
|
28
|
-
- exe: .exe path or filename (full path is recommanded to skip
|
|
29
|
+
- exe: .exe path or filename (full path is recommanded to skip path searching for better perf)
|
|
29
30
|
- args: `[]` arguments list
|
|
30
31
|
- options
|
|
31
|
-
- cwd?: `
|
|
32
|
+
- cwd?: `fp_root`
|
|
32
33
|
- env?: `process.env` overwrite/add to process.env
|
|
33
|
-
- encoding?: `'
|
|
34
|
+
- encoding?: `'utf-8'` child output encoding
|
|
34
35
|
- print?: `true` print option (with details)
|
|
35
36
|
- stdio?: `'pipe'` when 'ignore' then ignore stdio processing
|
|
36
37
|
- detached?: `false` whether to break the connection with child (ignore stdio, unref)
|
|
@@ -50,12 +51,12 @@ export interface CallResult<T = string> {
|
|
|
50
51
|
[inspect.custom](): string;
|
|
51
52
|
}
|
|
52
53
|
/** call process for result
|
|
53
|
-
- exe: .exe path or filename (full path is recommanded to skip
|
|
54
|
+
- exe: .exe path or filename (full path is recommanded to skip path searching for better perf)
|
|
54
55
|
- args: `[]` arguments list
|
|
55
56
|
- options
|
|
56
57
|
- cwd?: `'d:/'`
|
|
57
58
|
- env?: `process.env` overwrite/add to process.env
|
|
58
|
-
- encoding?: `'
|
|
59
|
+
- encoding?: `'utf-8'` child output encoding
|
|
59
60
|
- print?: `true` print option (with details)
|
|
60
61
|
- stdio?: `'pipe'` when 'ignore' then ignore stdio processing
|
|
61
62
|
- detached?: `false` whether to break the connection with child (ignore stdio, unref)
|
|
@@ -63,25 +64,24 @@ export interface CallResult<T = string> {
|
|
|
63
64
|
*/
|
|
64
65
|
export declare function call(exe: string, args?: string[]): Promise<CallResult<string>>;
|
|
65
66
|
export declare function call(exe: string, args?: string[], options?: CallOptions & {
|
|
66
|
-
encoding
|
|
67
|
-
init_buffer_size?: number;
|
|
68
|
-
}): Promise<CallResult<Buffer>>;
|
|
69
|
-
export declare function call(exe: string, args?: string[], options?: CallOptions & {
|
|
70
|
-
encoding?: 'UTF-8' | 'GB18030';
|
|
67
|
+
encoding?: 'utf-8' | 'gb18030';
|
|
71
68
|
}): Promise<CallResult<string>>;
|
|
69
|
+
export declare function call(exe: string, args?: string[], options?: CallOptions & {
|
|
70
|
+
encoding: 'binary';
|
|
71
|
+
}): Promise<CallResult<Buffer>>;
|
|
72
72
|
/** call node <js> for result
|
|
73
73
|
- js: .js path (relative path will resolve based on cwd)
|
|
74
74
|
- args: `[]` arguments list
|
|
75
75
|
- options
|
|
76
76
|
- cwd?: `'d:/'`
|
|
77
77
|
- env?: `process.env` overwrite/add to process.env
|
|
78
|
-
- encoding?: `'
|
|
78
|
+
- encoding?: `'utf-8'` child process output encoding
|
|
79
79
|
- print?: `true` print option (with details)
|
|
80
80
|
- stdio?: `'pipe'` when 'ignore' then ignore stdio processing
|
|
81
81
|
- detached?: `false` whether to break the connection with child (ignore stdio, unref)
|
|
82
82
|
- throw_code?: `true` whether to throw Error when code is not 0
|
|
83
83
|
*/
|
|
84
84
|
export declare function call_node(js: string, args?: string[], options?: CallOptions & {
|
|
85
|
-
encoding?: '
|
|
85
|
+
encoding?: 'utf-8' | 'gb18030';
|
|
86
86
|
}): Promise<CallResult<string>>;
|
|
87
87
|
export {};
|