xshell 0.0.55 → 0.0.58
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 +7 -6
- package/file.js +25 -21
- package/file.js.map +1 -1
- package/net.browser.d.ts +7 -1
- package/net.browser.js +6 -0
- package/net.browser.js.map +1 -1
- package/net.d.ts +7 -1
- package/net.js +11 -2
- package/net.js.map +1 -1
- package/package.json +22 -24
- package/extension.cjs +0 -55780
- package/extension.cjs.map +0 -1
package/net.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,OAAO,IAAI,eAAe,GAE7B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAEhF,OAAO,aAAa,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAE9B,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AASxD,OAAO,gBAAgB,CAAA;AAEvB,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAE1D,MAAM,CAAN,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,4CAAkC,CAAA;IAClC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,OAAO,KAAP,OAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,iBAAiB,EAAE,CAAA;AAE5C,MAAM,CAAC,MAAM,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtC,GAAG,CAAE,aAAqB,EAAE,GAAG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C,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,IAAI,CACL;oBACI,EAAE;oBACF,KAAK;oBACL,IAAI,EAAE,IAAI;iBACb,EACD,SAAS,CACZ,CAAA;gBAED,MAAM,KAAK,CAAA;aACd;aACA,EAAG,QAAQ;YACZ,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;YAE1B,IAAI,IAAI;gBACJ,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;SAC/B;IACL,CAAC;CACJ","sourcesContent":["import {\n default as request_lib,\n type OptionsWithUri,\n type OptionsWithUrl\n} from 'request'\n\nimport {\n default as request_promise,\n type FullResponse,\n} from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors.js'\n\nimport promise_retry from 'promise-retry'\n\nimport { WebSocket } from 'ws'\n\nimport iconv from 'iconv-lite'\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.js'\nimport type { Encoding } from './file.js'\nimport { inspect, output_width, concat } from './utils.js'\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 \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 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/101.0.4951.67 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.error(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function parse_html (html: string) {\n const { default: cheerio } = await import('cheerio')\n \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 // @ts-ignore\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.toUpperCase()}` : '' ) +\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)\n 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\n\nlet decoder = new TextDecoder()\n\nlet encoder = new TextEncoder()\n\n\nexport async function connect_websocket (\n url: string | URL,\n {\n protocols,\n max_payload = 2 ** 33, // 8 GB\n on_open,\n on_close,\n on_error,\n on_message\n }: {\n protocols?: string | string[]\n max_payload?: number\n on_open? (event: any, websocket: WebSocket): any\n on_close? (event: { code: number, reason: string }, websocket: WebSocket): any\n on_error? (event: any, websocket: WebSocket): any\n on_message (event: { data: ArrayBuffer }, websocket: WebSocket): any\n }\n) {\n let websocket = new WebSocket(url, protocols, { maxPayload: max_payload })\n \n // https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543\n websocket.binaryType = 'arraybuffer'\n \n return new Promise<WebSocket>((resolve, reject) => {\n websocket.addEventListener('open', async event => {\n console.log(`${websocket.url} opened`)\n \n await on_open?.(event, websocket)\n \n resolve(websocket)\n })\n \n websocket.addEventListener('close', event => {\n console.log(`${websocket.url} closed with code = ${event.code}, reason = '${event.reason}'`)\n on_close?.(event, websocket)\n })\n \n websocket.addEventListener('error', event => {\n const message = `${websocket.url} errored`\n on_error?.(event, websocket)\n reject(\n Object.assign(\n new Error(message),\n { event }\n )\n )\n })\n \n websocket.addEventListener('message', event => {\n on_message(event as any, websocket)\n })\n })\n}\n\n\n/** 二进制消息格式 \n - json.length (小端序): 4 字节\n - json 数据\n - binary 数据\n*/\nexport interface Message <T extends any[] = any[]> {\n /** 本次 rpc 的 id */\n id?: number\n \n /** rpc 发起方指定被调用的 function name, 多个相同 id, func 的 message 组成一个请求流 */\n func?: string\n \n /** 等待执行,但不要序列化返回 func 的执行结果 (message 中无 args) */\n ignore?: boolean\n \n /** 不等待 func 执行,remote 收到后直接确认返回 (message 中 done = true) */\n async?: boolean\n \n /** 这个数组里面要么是对应的 JS 参数,要么是 Uint8Array 参数对应的 binary length \n args 可以是: \n - rpc 发起方调用 func 的参数,或者请求流 message 携带的数据\n - 作为结果或者响应流的 message 数据,传给请求发起方\n */\n args?: T\n \n /** bins: 哪几个 arg 是 Uint8Array 类型的,如: [0, 3] */\n bins?: number[]\n \n /** 被调方执行 func 产生的错误 */\n error?: Error\n \n /** 如果请求或者响应是一个流,通过这个 flag 表明是最后一个 message, 并且可以销毁 handler 了 */\n done?: boolean\n}\n\n/** 通过创建 Remote 对象对 WebSocket RPC 进行抽象 \n 调用方使用 remote.call 进行调用 \n 被调方在创建 Remote 对象时传入 funcs 注册处理函数,并使用 Remote.handle 方法处理 WebSocket message \n*/\nexport class Remote {\n url: string\n \n websocket: WebSocket\n \n id = 0\n \n /** 被调方的 message 处理器 */\n funcs: Record<\n string, \n (message: Message, websocket?: WebSocket) => void | Promise<void>\n > = { }\n \n /** 调用方发起的 rpc 对应响应的 message 处理器 */\n handlers: ((message: Message) => any)[] = [ ]\n \n print = false\n \n /** 在未连接时或连接断开后,调用 call 是否自动连接到 remote */\n autoconnect = true\n \n pconnect: Promise<any>\n \n \n get connected () {\n return this.websocket?.readyState === WebSocket.OPEN\n }\n \n \n static parse <T extends any[] = any[]> (array_buffer: ArrayBuffer) {\n const buf = new Uint8Array(array_buffer as ArrayBuffer)\n const dv = new DataView(array_buffer)\n \n const len_json = dv.getUint32(0, true)\n \n let offset = 4 + len_json\n \n let message: Message<T> = JSON.parse(\n decoder.decode(\n buf.subarray(4, offset)\n )\n )\n \n if (message.bins) {\n const { bins } = message\n let { args } = message\n \n for (const ibin of bins) {\n const len_buf = args[ibin]\n args[ibin] = buf.subarray(offset, offset + len_buf)\n offset += len_buf\n }\n }\n \n return message\n }\n \n \n static pack ({\n id,\n func,\n ignore,\n async: _async,\n done,\n error,\n args: _args = [ ],\n }: Message) {\n let args = [..._args]\n \n let bins: number[] = [ ]\n let bufs: Uint8Array[] = [ ]\n \n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n if (arg instanceof Uint8Array) {\n bins.push(i)\n bufs.push(arg)\n args[i] = arg.length\n }\n }\n \n const data_json = {\n id,\n ... func ? { func } : { },\n ... ignore ? { ignore } : { },\n ... _async ? { async: _async } : { },\n ... done ? { done } : { },\n ... error ? { error } : { },\n ... args.length ? { args } : { },\n ... bins.length ? { bins } : { },\n }\n \n const str_json = encoder.encode(\n JSON.stringify(data_json)\n )\n \n let dv = new DataView(\n new ArrayBuffer(4)\n )\n \n dv.setUint32(0, str_json.length, true)\n \n return concat([\n dv,\n str_json,\n ... bufs\n ])\n }\n \n \n constructor ({\n url,\n funcs,\n websocket,\n autoconnect\n }: {\n url?: string\n funcs?: Remote['funcs']\n websocket?: WebSocket\n autoconnect?: boolean\n } = { }) {\n this.url = url\n \n if (funcs)\n this.funcs = funcs\n \n this.websocket = websocket\n \n if (typeof autoconnect !== 'undefined')\n this.autoconnect = autoconnect\n }\n \n \n async connect () {\n this.websocket = await connect_websocket(this.url, {\n on_message: this.handle.bind(this),\n on_close: () => {\n this.id = 0\n this.handlers = [ ]\n },\n })\n }\n \n \n disconnect () {\n this.websocket?.close()\n this.id = 0\n this.handlers = [ ]\n }\n \n \n send (message: Message, websocket = this.websocket) {\n if (websocket?.readyState !== WebSocket.OPEN)\n throw new Error(`${websocket?.url || 'websocket'} 已断开,无法调用 remote.send`)\n \n if (!('id' in message))\n message.id = this.id\n \n websocket.send(\n Remote.pack(message)\n )\n }\n \n \n /** 调用 remote 中的 func, 中间消息及返回结果可由 handler 处理,处理 done message 之后的返回值作为 call 函数的返回值 \n 如果为 unary rpc, 可以不传 handler, await call 之后可以得到响应 message 的 args\n */\n async call <T extends any[] = any[]> (\n message: Message,\n handler?: (message: Message<T>) => any\n ) {\n if (!this.connected)\n if (this.autoconnect) {\n // 临界区:保证多个 call 并发时只连接一次\n const ptail = this.pconnect\n \n let resolve: () => void\n this.pconnect = new Promise<void>((_resolve, _reject) => {\n resolve = _resolve\n })\n \n try {\n await ptail\n } catch { }\n // 临界区结束,只有一个 call 调用运行到这里,可以开始连接 WebSocket\n \n if (!this.connected) {\n if (this.websocket)\n console.log(`${this.url} 已断开,尝试自动重连`)\n else\n console.log(`${this.url} 未连接,尝试自动连接`)\n \n try {\n await this.connect()\n } finally {\n resolve()\n }\n }\n } else\n throw new Error(`${this.url} 未连接或已断开,无法调用 remote.call`)\n \n return new Promise<T>((resolve, reject) => {\n this.handlers[this.id] = async (message: Message<T>) => {\n const { error, done } = message\n \n if (error) {\n reject(\n Object.assign(\n new Error(),\n error\n )\n )\n return\n }\n \n const result = handler ?\n await handler(message)\n :\n message.args\n \n if (done)\n resolve(result)\n }\n \n this.send(message)\n \n this.id++\n })\n }\n \n \n /** 处理接收到的 WebSocket message\n 1. 被调用方接收 message 并开始处理\n 2. 调用方处理 message 响应\n */\n async handle (event: { data: ArrayBuffer }, websocket: WebSocket) {\n const message = Remote.parse(event.data)\n \n const { func, id, done } = message\n \n if (this.print)\n console.log(message)\n \n if (func) // 作为被调方\n try {\n const handler = this.funcs[func]\n \n if (!handler)\n throw new Error(`找不到 rpc handler for '${func}'`)\n \n await handler(message, websocket)\n } catch (error) {\n this.send(\n {\n id,\n error,\n done: true\n },\n websocket\n )\n \n throw error\n }\n else { // 作为发起方\n this.handlers[id](message)\n \n if (done)\n this.handlers[id] = null\n }\n }\n}\n\n\n"]}
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":"AAMA,OAAO,EACH,OAAO,IAAI,eAAe,GAE7B,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAA;AAEhF,OAAO,aAAa,MAAM,eAAe,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAE9B,OAAO,KAAK,MAAM,YAAY,CAAA;AAC9B,OAAO,EAAE,MAAM,IAAI,CAAA;AACnB,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AASxD,OAAO,gBAAgB,CAAA;AAEvB,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAE1D,MAAM,CAAN,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,4CAAkC,CAAA;IAClC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,OAAO,KAAP,OAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,iBAAiB,EAAE,CAAA;AAE5C,MA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AK,CAAC,IAAI,CAAC,CAAA;gBAEhC,IAAI,CAAC,OAAO;oBACR,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,GAAG,CAAC,CAAA;gBAEpD,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,CAAA;aACpC;YAAC,OAAO,KAAK,EAAE;gBACZ,IAAI,CAAC,IAAI,CACL;oBACI,EAAE;oBACF,KAAK;oBACL,IAAI,EAAE,IAAI;iBACb,EACD,SAAS,CACZ,CAAA;gBAED,MAAM,KAAK,CAAA;aACd;aACA,EAAG,QAAQ;YACZ,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;YAE1B,IAAI,IAAI;gBACJ,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;SAC/B;IACL,CAAC;CACJ","sourcesContent":["import {\n default as request_lib,\n type OptionsWithUri,\n type OptionsWithUrl\n} from 'request'\n\nimport {\n default as request_promise,\n type FullResponse,\n} from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors.js'\n\nimport promise_retry from 'promise-retry'\n\nimport { WebSocket } from 'ws'\n\nimport iconv from 'iconv-lite'\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.js'\nimport type { Encoding } from './file.js'\nimport { inspect, output_width, concat } from './utils.js'\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 \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 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/103.0.0.0 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.error(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function parse_html (html: string) {\n const { default: cheerio } = await import('cheerio')\n \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 // @ts-ignore\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.toUpperCase()}` : '' ) +\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)\n 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\n\nlet decoder = new TextDecoder()\n\nlet encoder = new TextEncoder()\n\n\n/** 连接 websocket url, 设置各种事件监听器 \n - url\n - options:\n - on_message: 根据 websocket frame 的 opcode 不同 (text frame 或 binary frame) event 中的 data 对应为 ArrayBuffer 或者 string\n https://datatracker.ietf.org/doc/html/rfc6455#section-5.2\n*/\nexport async function connect_websocket (\n url: string | URL,\n {\n protocols,\n max_payload = 2 ** 33, // 8 GB\n on_open,\n on_close,\n on_error,\n on_message\n }: {\n protocols?: string | string[]\n max_payload?: number\n on_open? (event: any, websocket: WebSocket): any\n on_close? (event: { code: number, reason: string }, websocket: WebSocket): any\n on_error? (event: any, websocket: WebSocket): any\n on_message (event: { data: ArrayBuffer | string }, websocket: WebSocket): any\n }\n) {\n let websocket = new WebSocket(\n url,\n protocols,\n {\n maxPayload: max_payload,\n skipUTF8Validation: true\n }\n )\n \n // https://stackoverflow.com/questions/11821096/what-is-the-difference-between-an-arraybuffer-and-a-blob/39951543\n websocket.binaryType = 'arraybuffer'\n \n return new Promise<WebSocket>((resolve, reject) => {\n websocket.addEventListener('open', async event => {\n console.log(`${websocket.url} opened`)\n \n await on_open?.(event, websocket)\n \n resolve(websocket)\n })\n \n websocket.addEventListener('close', event => {\n console.log(`${websocket.url} closed with code = ${event.code}, reason = '${event.reason}'`)\n on_close?.(event, websocket)\n })\n \n websocket.addEventListener('error', event => {\n const message = `${websocket.url} errored`\n on_error?.(event, websocket)\n reject(\n Object.assign(\n new Error(message),\n { event }\n )\n )\n })\n \n websocket.addEventListener('message', event => {\n on_message(event as any, websocket)\n })\n })\n}\n\n\n/** 二进制消息格式 \n - json.length (小端序): 4 字节\n - json 数据\n - binary 数据\n*/\nexport interface Message <T extends any[] = any[]> {\n /** 本次 rpc 的 id */\n id?: number\n \n /** rpc 发起方指定被调用的 function name, 多个相同 id, func 的 message 组成一个请求流 */\n func?: string\n \n /** 等待执行,但不要序列化返回 func 的执行结果 (message 中无 args) */\n ignore?: boolean\n \n /** 不等待 func 执行,remote 收到后直接确认返回 (message 中 done = true) */\n async?: boolean\n \n /** 这个数组里面要么是对应的 JS 参数,要么是 Uint8Array 参数对应的 binary length \n args 可以是: \n - rpc 发起方调用 func 的参数,或者请求流 message 携带的数据\n - 作为结果或者响应流的 message 数据,传给请求发起方\n */\n args?: T\n \n /** bins: 哪几个 arg 是 Uint8Array 类型的,如: [0, 3] */\n bins?: number[]\n \n /** 被调方执行 func 产生的错误 */\n error?: Error\n \n /** 如果请求或者响应是一个流,通过这个 flag 表明是最后一个 message, 并且可以销毁 handler 了 */\n done?: boolean\n}\n\n/** 通过创建 Remote 对象对 WebSocket RPC 进行抽象 \n 调用方使用 remote.call 进行调用 \n 被调方在创建 Remote 对象时传入 funcs 注册处理函数,并使用 Remote.handle 方法处理 WebSocket message \n*/\nexport class Remote {\n url: string\n \n websocket: WebSocket\n \n id = 0\n \n /** 被调方的 message 处理器 */\n funcs: Record<\n string, \n (message: Message, websocket?: WebSocket) => void | Promise<void>\n > = { }\n \n /** 调用方发起的 rpc 对应响应的 message 处理器 */\n handlers: ((message: Message) => any)[] = [ ]\n \n print = false\n \n /** 在未连接时或连接断开后,调用 call 是否自动连接到 remote */\n autoconnect = true\n \n pconnect: Promise<any>\n \n \n get connected () {\n return this.websocket?.readyState === WebSocket.OPEN\n }\n \n \n static parse <T extends any[] = any[]> (array_buffer: ArrayBuffer) {\n const buf = new Uint8Array(array_buffer as ArrayBuffer)\n const dv = new DataView(array_buffer)\n \n const len_json = dv.getUint32(0, true)\n \n let offset = 4 + len_json\n \n let message: Message<T> = JSON.parse(\n decoder.decode(\n buf.subarray(4, offset)\n )\n )\n \n if (message.bins) {\n const { bins } = message\n let { args } = message\n \n for (const ibin of bins) {\n const len_buf = args[ibin]\n args[ibin] = buf.subarray(offset, offset + len_buf)\n offset += len_buf\n }\n }\n \n return message\n }\n \n \n static pack ({\n id,\n func,\n ignore,\n async: _async,\n done,\n error,\n args: _args = [ ],\n }: Message) {\n let args = [..._args]\n \n let bins: number[] = [ ]\n let bufs: Uint8Array[] = [ ]\n \n for (let i = 0; i < args.length; i++) {\n const arg = args[i]\n if (arg instanceof Uint8Array) {\n bins.push(i)\n bufs.push(arg)\n args[i] = arg.length\n }\n }\n \n const data_json = {\n id,\n ... func ? { func } : { },\n ... ignore ? { ignore } : { },\n ... _async ? { async: _async } : { },\n ... done ? { done } : { },\n ... error ? { error } : { },\n ... args.length ? { args } : { },\n ... bins.length ? { bins } : { },\n }\n \n const str_json = encoder.encode(\n JSON.stringify(data_json)\n )\n \n let dv = new DataView(\n new ArrayBuffer(4)\n )\n \n dv.setUint32(0, str_json.length, true)\n \n return concat([\n dv,\n str_json,\n ... bufs\n ])\n }\n \n \n constructor ({\n url,\n funcs,\n websocket,\n autoconnect\n }: {\n url?: string\n funcs?: Remote['funcs']\n websocket?: WebSocket\n autoconnect?: boolean\n } = { }) {\n this.url = url\n \n if (funcs)\n this.funcs = funcs\n \n this.websocket = websocket\n \n if (typeof autoconnect !== 'undefined')\n this.autoconnect = autoconnect\n }\n \n \n async connect () {\n this.websocket = await connect_websocket(this.url, {\n on_message: this.handle.bind(this),\n on_close: () => {\n this.id = 0\n this.handlers = [ ]\n },\n })\n }\n \n \n disconnect () {\n this.websocket?.close()\n this.id = 0\n this.handlers = [ ]\n }\n \n \n send (message: Message, websocket = this.websocket) {\n if (websocket?.readyState !== WebSocket.OPEN)\n throw new Error(`${websocket?.url || 'websocket'} 已断开,无法调用 remote.send`)\n \n if (!('id' in message))\n message.id = this.id\n \n websocket.send(\n Remote.pack(message)\n )\n }\n \n \n /** 调用 remote 中的 func, 中间消息及返回结果可由 handler 处理,处理 done message 之后的返回值作为 call 函数的返回值 \n 如果为 unary rpc, 可以不传 handler, await call 之后可以得到响应 message 的 args\n */\n async call <T extends any[] = any[]> (\n message: Message,\n handler?: (message: Message<T>) => any\n ) {\n if (!this.connected)\n if (this.autoconnect) {\n // 临界区:保证多个 call 并发时只连接一次\n const ptail = this.pconnect\n \n let resolve: () => void\n this.pconnect = new Promise<void>((_resolve, _reject) => {\n resolve = _resolve\n })\n \n try {\n await ptail\n } catch { }\n // 临界区结束,只有一个 call 调用运行到这里,可以开始连接 WebSocket\n \n if (!this.connected) {\n if (this.websocket)\n console.log(`${this.url} 已断开,尝试自动重连`)\n else\n console.log(`${this.url} 未连接,尝试自动连接`)\n \n try {\n await this.connect()\n } finally {\n resolve()\n }\n }\n } else\n throw new Error(`${this.url} 未连接或已断开,无法调用 remote.call`)\n \n return new Promise<T>((resolve, reject) => {\n this.handlers[this.id] = async (message: Message<T>) => {\n const { error, done } = message\n \n if (error) {\n reject(\n Object.assign(\n new Error(),\n error\n )\n )\n return\n }\n \n const result = handler ?\n await handler(message)\n :\n message.args\n \n if (done)\n resolve(result)\n }\n \n this.send(message)\n \n this.id++\n })\n }\n \n \n /** 处理接收到的 WebSocket message\n 1. 被调用方接收 message 并开始处理\n 2. 调用方处理 message 响应\n */\n async handle (event: { data: ArrayBuffer }, websocket: WebSocket) {\n const message = Remote.parse(event.data)\n \n const { func, id, done } = message\n \n if (this.print)\n console.log(message)\n \n if (func) // 作为被调方\n try {\n const handler = this.funcs[func]\n \n if (!handler)\n throw new Error(`找不到 rpc handler for '${func}'`)\n \n await handler(message, websocket)\n } catch (error) {\n this.send(\n {\n id,\n error,\n done: true\n },\n websocket\n )\n \n throw error\n }\n else { // 作为发起方\n this.handlers[id](message)\n \n if (done)\n this.handlers[id] = null\n }\n }\n}\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.58",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"interactive programming"
|
|
17
17
|
],
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=18.
|
|
20
|
-
"vscode": ">=1.
|
|
19
|
+
"node": ">=18.4.0",
|
|
20
|
+
"vscode": ">=1.68.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"start": "node --title=xshell --inspect=0.0.0.0:8420 ./xshell.js",
|
|
@@ -65,14 +65,14 @@
|
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@babel/core": "^7.18.
|
|
69
|
-
"@babel/parser": "^7.18.
|
|
70
|
-
"@babel/traverse": "^7.18.
|
|
68
|
+
"@babel/core": "^7.18.6",
|
|
69
|
+
"@babel/parser": "^7.18.6",
|
|
70
|
+
"@babel/traverse": "^7.18.6",
|
|
71
71
|
"@koa/cors": "^3.3.0",
|
|
72
72
|
"byte-size": "^8.1.0",
|
|
73
73
|
"chalk": "^5.0.1",
|
|
74
74
|
"chardet": "^1.4.0",
|
|
75
|
-
"cheerio": "^1.0.0-rc.
|
|
75
|
+
"cheerio": "^1.0.0-rc.12",
|
|
76
76
|
"cli-table3": "^0.6.2",
|
|
77
77
|
"cli-truncate": "^3.1.0",
|
|
78
78
|
"colors": "^1.4.0",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"fs-monkey": "^1.0.3",
|
|
84
84
|
"gulp-sort": "^2.0.0",
|
|
85
85
|
"hash-string": "^1.0.0",
|
|
86
|
-
"i18next": "^21.8.
|
|
87
|
-
"i18next-scanner": "^3.
|
|
86
|
+
"i18next": "^21.8.11",
|
|
87
|
+
"i18next-scanner": "^3.3.0",
|
|
88
88
|
"iconv-lite": "^0.6.3",
|
|
89
89
|
"js-cookie": "^3.0.1",
|
|
90
90
|
"koa": "^2.13.4",
|
|
@@ -92,28 +92,27 @@
|
|
|
92
92
|
"koa-useragent": "^4.0.0",
|
|
93
93
|
"lodash": "^4.17.21",
|
|
94
94
|
"map-stream": "0.0.7",
|
|
95
|
-
"memfs": "^3.4.
|
|
96
|
-
"ora": "^6.1.
|
|
95
|
+
"memfs": "^3.4.7",
|
|
96
|
+
"ora": "^6.1.2",
|
|
97
97
|
"promise-retry": "^2.0.1",
|
|
98
|
-
"qs": "^6.
|
|
99
|
-
"react": "^18.
|
|
100
|
-
"react-i18next": "^11.17.
|
|
98
|
+
"qs": "^6.11.0",
|
|
99
|
+
"react": "^18.2.0",
|
|
100
|
+
"react-i18next": "^11.17.3",
|
|
101
101
|
"request": "^2.88.2",
|
|
102
102
|
"request-promise-native": "^1.0.9",
|
|
103
103
|
"resolve-path": "^1.4.0",
|
|
104
|
-
"rimraf": "^3.0.2",
|
|
105
104
|
"stream-buffers": "^3.0.2",
|
|
106
105
|
"strip-ansi": "^7.0.1",
|
|
107
106
|
"tough-cookie": "^4.0.0",
|
|
108
107
|
"tslib": "^2.4.0",
|
|
109
|
-
"typescript": "^4.7.
|
|
108
|
+
"typescript": "^4.7.4",
|
|
110
109
|
"upath": "^2.0.1",
|
|
111
110
|
"vinyl": "^2.2.1",
|
|
112
111
|
"vinyl-fs": "^3.0.3",
|
|
113
|
-
"ws": "^8.
|
|
112
|
+
"ws": "^8.8.0"
|
|
114
113
|
},
|
|
115
114
|
"devDependencies": {
|
|
116
|
-
"@babel/types": "^7.18.
|
|
115
|
+
"@babel/types": "^7.18.7",
|
|
117
116
|
"@types/babel__traverse": "^7.17.1",
|
|
118
117
|
"@types/byte-size": "^8.1.0",
|
|
119
118
|
"@types/chardet": "^0.8.1",
|
|
@@ -126,19 +125,18 @@
|
|
|
126
125
|
"@types/koa": "^2.13.4",
|
|
127
126
|
"@types/koa-compress": "^4.0.3",
|
|
128
127
|
"@types/lodash": "^4.14.182",
|
|
129
|
-
"@types/node": "^
|
|
128
|
+
"@types/node": "^18.0.0",
|
|
130
129
|
"@types/promise-retry": "^1.1.3",
|
|
131
130
|
"@types/qs": "^6.9.7",
|
|
132
|
-
"@types/react": "^18.0.
|
|
131
|
+
"@types/react": "^18.0.14",
|
|
133
132
|
"@types/request": "^2.48.8",
|
|
134
133
|
"@types/request-promise-native": "^1.0.18",
|
|
135
|
-
"@types/rimraf": "^3.0.2",
|
|
136
134
|
"@types/stream-buffers": "^3.0.4",
|
|
137
135
|
"@types/tampermonkey": "^4.0.5",
|
|
138
136
|
"@types/vinyl-fs": "^2.4.12",
|
|
139
|
-
"@types/vscode": "^1.
|
|
137
|
+
"@types/vscode": "^1.68.1",
|
|
140
138
|
"@types/ws": "^8.5.3",
|
|
141
|
-
"source-map-loader": "^
|
|
142
|
-
"ts-loader": "^9.3.
|
|
139
|
+
"source-map-loader": "^4.0.0",
|
|
140
|
+
"ts-loader": "^9.3.1"
|
|
143
141
|
}
|
|
144
142
|
}
|