xshell 0.0.31 → 0.0.32

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.
@@ -1 +1 @@
1
- {"version":3,"file":"parser.js","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":";;;;AAAA,oFAA2C;AAC3C,0EAAiC;AACjC,wEAAgC;AAEhC,4EAAsC;AACtC,0CAAqC;AACrC,6DAAiC;AAEjC,8BAA2B;AAG3B,sCAAsC;AAEtC,iDAAiD;AACjD,SAAgB,oCAAoC,CAAE,MAAM;IACxD,MAAM,CAAC,2BAA2B,GAAG,SAAS,gCAAgC,CAC1E,IAAY,EACZ,OAAO,GAAG,EAAG,EACb,cAAc,GAAG,IAAI,EACrB,WACM,GAAG,EAAE,GAAG,CAAC;QAEf,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YAC/B,cAAc,GAAG,OAAO,CAAA;YACxB,OAAO,GAAG,EAAG,CAAA;SAChB;QAED,MAAM,EACF,gBAAgB,GAAG,EAAG,EAAE,SAAS;QACjC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS;QACnD,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS;QAC/C,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,SAAS;QACvD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,mBAAmB;QACjE,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS;QAChE,QAAQ,GACX,GAAG,OAAc,CAAA;QAElB,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACjC,IAAI,CAAC,IAAI;gBAAE,OAAM;YAEjB,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS;gBA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I,IAAI,UAAU,CAAC,KAAK,CAAA;iBACvB,IACD,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC;gBAChC,CAAC,CAAC,gBAAgB,CAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,eAAe,CAAC,CAAC;gBAErD,IAAI,IAAI,IAAI,GAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;;gBAEhE,OAAO,CAAC,GAAG,EAAE;oBACT,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;oBACjG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;oBACjB,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;oBACxD,OAAO,CAAC,KAAK,CAAC,2FAA2F,CAAC,GAAG,CAAC,CAAA;gBAClH,CAAC,CAAC,CAAA;SAET;aAAM,IAAI,IAAI,CAAC,QAAQ;YACpB,IAAI,IAAI,IAAI,UAAU,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,UAAU,GAAG,CAAA;QAGjG,UAAU,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["import castArray from 'lodash/castArray.js'\nimport trim from 'lodash/trim.js'\nimport _get from 'lodash/get.js'\n\nimport traverse from '@babel/traverse'\nimport { parse } from '@babel/parser'\nimport * as t from '@babel/types'\n\nimport '../../prototype.js'\n\n\n// import { Checker } from './checker'\n\n/** file:///D:/0/i18next-scanner/src/parser.js */\nexport function mix_parse_trans_from_string_by_babel (parser) {\n parser.parseTransFromStringByBabel = function parse_trans_from_string_by_babel (\n code: string, \n options = { }, \n custom_handler = null,\n on_error: (callback: Function) => void \n = () => { }\n ) {\n if (typeof options === 'function') {\n custom_handler = options\n options = { }\n }\n \n const {\n transformOptions = { }, // object\n component = this.options.trans.component, // string\n i18nKey = this.options.trans.i18nKey, // string\n defaultsKey = this.options.trans.defaultsKey, // string\n fallbackKey = this.options.trans.fallbackKey, // boolean|function\n babylon: babylon_options = this.options.trans.babylon, // object\n filepath,\n } = options as any\n \n const parseJSXElement = ({ node }) => {\n if (!node) return\n \n if (node.openingElement.name.name !== component) return\n \n \n const getLiteralValue = literal => {\n if (t.isTemplateLiteral(literal))\n return literal.quasis.map(element => element.value.cooked).join(\"\")\n \n return literal.value\n }\n \n const attr = castArray(node.openingElement.attributes).reduce(\n (acc, attribute) => {\n if (\n !t.isJSXAttribute(attribute) ||\n !t.isJSXIdentifier(attribute.name)\n ) return acc\n \n const { name } = attribute.name\n const value = attribute.value\n if (t.isLiteral(value))\n acc[name] = getLiteralValue(value)\n else if (t.isJSXExpressionContainer(value)) {\n const expression = value.expression\n if (t.isIdentifier(expression))\n acc[name] = expression.name\n else if (t.isLiteral(expression))\n acc[name] = getLiteralValue(expression)\n else if (t.isObjectExpression(expression)) {\n const properties = castArray(expression.properties)\n acc[name] = properties.reduce((obj, property) => {\n if (!t.isObjectProperty(property)) return obj\n if (t.isLiteral(property.value))\n obj[(property.key as any).name] = getLiteralValue(property.value)\n else // Unable to get value of the property\n obj[(property.key as any).name] = \"\"\n return obj\n }, { })\n /**\n * 防止 count 被忽略,如\n * ```jsx\n * <Trans count={arr.length}>\n * 一二三{{ count: arr.length }}\n * </Trans>\n * ```\n */\n } else if (name === \"count\")\n acc[name] = 0\n }\n return acc\n },\n { }\n )\n const transKey = trim(attr[i18nKey])\n \n const defaultsString = attr[defaultsKey] || \"\"\n if (typeof defaultsString !== \"string\")\n this.log(`defaults value must be a static string, saw ${defaultsString.yellow}`)\n \n \n // https://www.i18next.com/translation-function/essentials#overview-options\n const tOptions = attr.tOptions\n const options = {\n ...tOptions,\n defaultValue: defaultsString || nodes_to_string(node.children, filepath, on_error),\n fallbackKey,\n }\n \n if (Object.prototype.hasOwnProperty.call(attr, \"count\"))\n options.count = Number(attr.count) || 0\n \n \n if (Object.prototype.hasOwnProperty.call(attr, \"ns\")) {\n if (typeof options.ns !== \"string\")\n this.log(`The ns attribute must be a string, saw ${attr.ns?.yellow}`)\n \n options.ns = attr.ns\n }\n \n if (custom_handler) {\n custom_handler(transKey, options)\n return\n }\n \n this.set(transKey, options)\n }\n \n try {\n const ast = parse(code, { ...babylon_options })\n traverse(ast, { JSXElement: parseJSXElement, })\n // traverse(ast, Checker({ filepath }))\n } catch (err) {\n on_error(() => {\n console.error('')\n const { line, column } = (err && err.loc) || { line: 1, column: 1 }\n console.error([filepath, line, column].join(\":\").yellow)\n console.error(`Unable to parse ${component?.blue} component.\\n`.red)\n if (!filepath)\n console.error(String(code).red)\n console.error((\" \" + err.message).red)\n })\n }\n \n return this\n }\n}\n\n\nfunction nodes_to_string (nodes, filepath, onError) {\n let memo = ''\n let node_index = 0\n nodes.forEach((node, i) => {\n if (t.isJSXText(node) || t.isStringLiteral(node)) {\n const value = node.value\n .replace(/^[\\r\\n]+\\s*/g, \"\") // remove leading spaces containing a leading newline character\n .replace(/[\\r\\n]+\\s*$/g, \"\") // remove trailing spaces containing a leading newline character\n .replace(/[\\r\\n]+\\s*/g, \" \") // replace spaces containing a leading newline character with a single space character\n \n if (!value) return\n \n memo += value\n } else if (t.isJSXExpressionContainer(node)) {\n const { expression = { } } = node\n \n if (t.isNumericLiteral(expression)) // Numeric literal is ignored in react-i18next\n memo += ''\n if (t.isStringLiteral(expression))\n memo += expression.value\n else if (\n t.isObjectExpression(expression) &&\n t.isObjectProperty(_get(expression, 'properties[0]'))\n )\n memo += '{{' + (expression.properties[0] as any).key.name + '}}'\n else\n onError(() => {\n const { line, column } = (node.expression && node.expression.loc.start) || { line: 1, column: 1 }\n console.error('')\n console.error([filepath, line, column].join(\":\").yellow)\n console.error('Unsupported JSX expression. Only static values or {{interpolation}} blocks are supported.'.red)\n })\n \n } else if (node.children)\n memo += `<${node_index}>${nodes_to_string(node.children, filepath, onError)}</${node_index}>`\n \n \n node_index++\n })\n \n return memo\n}\n\n"]}
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":";;;;AAAA,+EAA2C;AAC3C,qEAAiC;AACjC,mEAAgC;AAEhC,uEAAsC;AACtC,0CAAqC;AACrC,wDAAiC;AAEjC,8BAA2B;AAG3B,sCAAsC;AAEtC,iDAAiD;AACjD,SAAgB,oCAAoC,CAAE,MAAM;IACxD,MAAM,CAAC,2BAA2B,GAAG,SAAS,gCAAgC,CAC1E,IAAY,EACZ,OAAO,GAAG,EAAG,EACb,cAAc,GAAG,IAAI,EACrB,WACM,GAAG,EAAE,GAAG,CAAC;QAEf,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YAC/B,cAAc,GAAG,OAAO,CAAA;YACxB,OAAO,GAAG,EAAG,CAAA;SAChB;QAED,MAAM,EACF,gBAAgB,GAAG,EAAG,EAAE,SAAS;QACjC,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,SAAS;QACnD,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS;QAC/C,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,SAAS;QACvD,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,EAAE,mBAAmB;QACjE,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,SAAS;QAChE,QAAQ,GACX,GAAG,OAAc,CAAA;QAElB,MAAM,eAAe,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;YACjC,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G,8CAA8C;gBAC/E,IAAI,IAAI,EAAE,CAAA;YACd,IAAI,CAAC,CAAC,eAAe,CAAC,UAAU,CAAC;gBAC7B,IAAI,IAAI,UAAU,CAAC,KAAK,CAAA;iBACvB,IACD,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC;gBAChC,CAAC,CAAC,gBAAgB,CAAC,IAAA,gBAAI,EAAC,UAAU,EAAE,eAAe,CAAC,CAAC;gBAErD,IAAI,IAAI,IAAI,GAAI,UAAU,CAAC,UAAU,CAAC,CAAC,CAAS,CAAC,GAAG,CAAC,IAAI,GAAG,IAAI,CAAA;;gBAEhE,OAAO,CAAC,GAAG,EAAE;oBACT,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;oBACjG,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;oBACjB,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAA;oBACxD,OAAO,CAAC,KAAK,CAAC,2FAA2F,CAAC,GAAG,CAAC,CAAA;gBAClH,CAAC,CAAC,CAAA;SAET;aAAM,IAAI,IAAI,CAAC,QAAQ;YACpB,IAAI,IAAI,IAAI,UAAU,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,UAAU,GAAG,CAAA;QAGjG,UAAU,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["import castArray from 'lodash/castArray.js'\nimport trim from 'lodash/trim.js'\nimport _get from 'lodash/get.js'\n\nimport traverse from '@babel/traverse'\nimport { parse } from '@babel/parser'\nimport * as t from '@babel/types'\n\nimport '../../prototype.js'\n\n\n// import { Checker } from './checker'\n\n/** file:///D:/0/i18next-scanner/src/parser.js */\nexport function mix_parse_trans_from_string_by_babel (parser) {\n parser.parseTransFromStringByBabel = function parse_trans_from_string_by_babel (\n code: string, \n options = { }, \n custom_handler = null,\n on_error: (callback: Function) => void \n = () => { }\n ) {\n if (typeof options === 'function') {\n custom_handler = options\n options = { }\n }\n \n const {\n transformOptions = { }, // object\n component = this.options.trans.component, // string\n i18nKey = this.options.trans.i18nKey, // string\n defaultsKey = this.options.trans.defaultsKey, // string\n fallbackKey = this.options.trans.fallbackKey, // boolean|function\n babylon: babylon_options = this.options.trans.babylon, // object\n filepath,\n } = options as any\n \n const parseJSXElement = ({ node }) => {\n if (!node) return\n \n if (node.openingElement.name.name !== component) return\n \n \n const getLiteralValue = literal => {\n if (t.isTemplateLiteral(literal))\n return literal.quasis.map(element => element.value.cooked).join(\"\")\n \n return literal.value\n }\n \n const attr = castArray(node.openingElement.attributes).reduce(\n (acc, attribute) => {\n if (\n !t.isJSXAttribute(attribute) ||\n !t.isJSXIdentifier(attribute.name)\n ) return acc\n \n const { name } = attribute.name\n const value = attribute.value\n if (t.isLiteral(value))\n acc[name] = getLiteralValue(value)\n else if (t.isJSXExpressionContainer(value)) {\n const expression = value.expression\n if (t.isIdentifier(expression))\n acc[name] = expression.name\n else if (t.isLiteral(expression))\n acc[name] = getLiteralValue(expression)\n else if (t.isObjectExpression(expression)) {\n const properties = castArray(expression.properties)\n acc[name] = properties.reduce((obj, property) => {\n if (!t.isObjectProperty(property)) return obj\n if (t.isLiteral(property.value))\n obj[(property.key as any).name] = getLiteralValue(property.value)\n else // Unable to get value of the property\n obj[(property.key as any).name] = \"\"\n return obj\n }, { })\n /**\n * 防止 count 被忽略,如\n * ```jsx\n * <Trans count={arr.length}>\n * 一二三{{ count: arr.length }}\n * </Trans>\n * ```\n */\n } else if (name === \"count\")\n acc[name] = 0\n }\n return acc\n },\n { }\n )\n const transKey = trim(attr[i18nKey])\n \n const defaultsString = attr[defaultsKey] || \"\"\n if (typeof defaultsString !== \"string\")\n this.log(`defaults value must be a static string, saw ${defaultsString.yellow}`)\n \n \n // https://www.i18next.com/translation-function/essentials#overview-options\n const tOptions = attr.tOptions\n const options = {\n ...tOptions,\n defaultValue: defaultsString || nodes_to_string(node.children, filepath, on_error),\n fallbackKey,\n }\n \n if (Object.prototype.hasOwnProperty.call(attr, \"count\"))\n options.count = Number(attr.count) || 0\n \n \n if (Object.prototype.hasOwnProperty.call(attr, \"ns\")) {\n if (typeof options.ns !== \"string\")\n this.log(`The ns attribute must be a string, saw ${attr.ns?.yellow}`)\n \n options.ns = attr.ns\n }\n \n if (custom_handler) {\n custom_handler(transKey, options)\n return\n }\n \n this.set(transKey, options)\n }\n \n try {\n const ast = parse(code, { ...babylon_options })\n traverse(ast, { JSXElement: parseJSXElement, })\n // traverse(ast, Checker({ filepath }))\n } catch (err) {\n on_error(() => {\n console.error('')\n const { line, column } = (err && err.loc) || { line: 1, column: 1 }\n console.error([filepath, line, column].join(\":\").yellow)\n console.error(`Unable to parse ${component?.blue} component.\\n`.red)\n if (!filepath)\n console.error(String(code).red)\n console.error((\" \" + err.message).red)\n })\n }\n \n return this\n }\n}\n\n\nfunction nodes_to_string (nodes, filepath, onError) {\n let memo = ''\n let node_index = 0\n nodes.forEach((node, i) => {\n if (t.isJSXText(node) || t.isStringLiteral(node)) {\n const value = node.value\n .replace(/^[\\r\\n]+\\s*/g, \"\") // remove leading spaces containing a leading newline character\n .replace(/[\\r\\n]+\\s*$/g, \"\") // remove trailing spaces containing a leading newline character\n .replace(/[\\r\\n]+\\s*/g, \" \") // replace spaces containing a leading newline character with a single space character\n \n if (!value) return\n \n memo += value\n } else if (t.isJSXExpressionContainer(node)) {\n const { expression = { } } = node\n \n if (t.isNumericLiteral(expression)) // Numeric literal is ignored in react-i18next\n memo += ''\n if (t.isStringLiteral(expression))\n memo += expression.value\n else if (\n t.isObjectExpression(expression) &&\n t.isObjectProperty(_get(expression, 'properties[0]'))\n )\n memo += '{{' + (expression.properties[0] as any).key.name + '}}'\n else\n onError(() => {\n const { line, column } = (node.expression && node.expression.loc.start) || { line: 1, column: 1 }\n console.error('')\n console.error([filepath, line, column].join(\":\").yellow)\n console.error('Unsupported JSX expression. Only static values or {{interpolation}} blocks are supported.'.red)\n })\n \n } else if (node.children)\n memo += `<${node_index}>${nodes_to_string(node.children, filepath, onError)}</${node_index}>`\n \n \n node_index++\n })\n \n return memo\n}\n\n"]}
package/i18n/utils.d.ts CHANGED
@@ -1 +1 @@
1
- export declare function try_require(modpath: string): any;
1
+ export declare function try_load_dict(fp_dict: string): Promise<any>;
package/i18n/utils.js CHANGED
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.try_require = void 0;
4
- function try_require(modpath) {
3
+ exports.try_load_dict = void 0;
4
+ const file_js_1 = require("../file.js");
5
+ async function try_load_dict(fp_dict) {
5
6
  try {
6
- return require(modpath);
7
+ return await (0, file_js_1.fread_json)(fp_dict, { print: false });
7
8
  }
8
9
  catch {
9
10
  // console.error('未找到或解析错误,跳过加载:' + modpath)
10
11
  return {};
11
12
  }
12
13
  }
13
- exports.try_require = try_require;
14
+ exports.try_load_dict = try_load_dict;
14
15
  //# sourceMappingURL=utils.js.map
package/i18n/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,WAAW,CAAE,OAAe;IACxC,IAAI;QACA,OAAO,OAAO,CAAC,OAAO,CAAC,CAAA;KAC1B;IAAC,MAAM;QACJ,4CAA4C;QAC5C,OAAO,EAAG,CAAA;KACb;AACL,CAAC;AAPD,kCAOC","sourcesContent":["export function try_require (modpath: string) {\n try {\n return require(modpath)\n } catch {\n // console.error('未找到或解析错误,跳过加载:' + modpath)\n return { }\n }\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAAA,wCAAuC;AAEhC,KAAK,UAAU,aAAa,CAAE,OAAe;IAChD,IAAI;QACA,OAAO,MAAM,IAAA,oBAAU,EAAC,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;KACrD;IAAC,MAAM;QACJ,4CAA4C;QAC5C,OAAO,EAAG,CAAA;KACb;AACL,CAAC;AAPD,sCAOC","sourcesContent":["import { fread_json } from '../file.js'\n\nexport async function try_load_dict (fp_dict: string) {\n try {\n return await fread_json(fp_dict, { print: false })\n } catch {\n // console.error('未找到或解析错误,跳过加载:' + modpath)\n return { }\n }\n}\n"]}
package/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- (0, tslib_1.__exportStar)(require("./prototype.js"), exports);
5
- (0, tslib_1.__exportStar)(require("./utils.js"), exports);
6
- (0, tslib_1.__exportStar)(require("./file.js"), exports);
7
- (0, tslib_1.__exportStar)(require("./process.js"), exports);
8
- (0, tslib_1.__exportStar)(require("./net.js"), exports);
4
+ tslib_1.__exportStar(require("./prototype.js"), exports);
5
+ tslib_1.__exportStar(require("./utils.js"), exports);
6
+ tslib_1.__exportStar(require("./file.js"), exports);
7
+ tslib_1.__exportStar(require("./process.js"), exports);
8
+ tslib_1.__exportStar(require("./net.js"), exports);
9
9
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,8DAA8B;AAC9B,0DAA0B;AAC1B,yDAAyB;AACzB,4DAA4B;AAC5B,wDAAwB","sourcesContent":["export * from './prototype.js'\nexport * from './utils.js'\nexport * from './file.js'\nexport * from './process.js'\nexport * from './net.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;AAAA,yDAA8B;AAC9B,qDAA0B;AAC1B,oDAAyB;AACzB,uDAA4B;AAC5B,mDAAwB","sourcesContent":["export * from './prototype.js'\nexport * from './utils.js'\nexport * from './file.js'\nexport * from './process.js'\nexport * from './net.js'\n"]}
package/net.js CHANGED
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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
- const request_promise_native_1 = (0, tslib_1.__importDefault)(require("request-promise-native"));
5
+ const request_promise_native_1 = tslib_1.__importDefault(require("request-promise-native"));
6
6
  const errors_js_1 = require("request-promise-native/errors.js");
7
- const promise_retry_1 = (0, tslib_1.__importDefault)(require("promise-retry"));
8
- const iconv_lite_1 = (0, tslib_1.__importDefault)(require("iconv-lite"));
9
- const cheerio_1 = (0, tslib_1.__importDefault)(require("cheerio"));
10
- const qs_1 = (0, tslib_1.__importDefault)(require("qs"));
7
+ const promise_retry_1 = tslib_1.__importDefault(require("promise-retry"));
8
+ const iconv_lite_1 = tslib_1.__importDefault(require("iconv-lite"));
9
+ const cheerio_1 = tslib_1.__importDefault(require("cheerio"));
10
+ const qs_1 = tslib_1.__importDefault(require("qs"));
11
11
  const tough_cookie_1 = require("tough-cookie");
12
12
  Object.defineProperty(exports, "Cookie", { enumerable: true, get: function () { return tough_cookie_1.Cookie; } });
13
13
  require("./prototype.js");
package/net.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAMA,iGAG+B;AAC/B,gEAAgF;AAEhF,+EAAyC;AAEzC,yEAA8B;AAC9B,mEAA6B;AAC7B,yDAAmB;AACnB,+CAAwD;AA2C/C,uFA3CA,qBAAM,OA2CA;AAlCf,0BAAuB;AAEvB,yCAAkD;AAElD,IAAY,OAGX;A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A;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 {\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 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.js'\nimport type { Encoding } from './file.js'\nimport { inspect, output_width } 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/98.0.4758.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.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) 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"]}
1
+ {"version":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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 {\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 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.js'\nimport type { Encoding } from './file.js'\nimport { inspect, output_width } 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/98.0.4758.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.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) 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.31",
3
+ "version": "0.0.32",
4
4
  "main": "./index.js",
5
5
  "bin": {
6
6
  "xshell": "./xshell.js",
@@ -17,7 +17,7 @@
17
17
  "type": "commonjs",
18
18
  "engines": {
19
19
  "node": ">=17.4.0",
20
- "vscode": "^1.64.0"
20
+ "vscode": ">=1.64.0"
21
21
  },
22
22
  "scripts": {
23
23
  "start": "node --title=xshell --inspect=0.0.0.0:8420 ./xshell.js",
@@ -37,7 +37,7 @@
37
37
  "homepage": "https://github.com/ShenHongFei/xshell",
38
38
  "repository": {
39
39
  "type": "git",
40
- "url": "https://github.com/ShenHongFei/xshell"
40
+ "url": "https://github.com/ShenHongFei/xshell.git"
41
41
  },
42
42
  "bugs": {
43
43
  "url": "https://github.com/ShenHongFei/xshell/issues"
@@ -79,11 +79,11 @@
79
79
  "commander": "^8.3.0",
80
80
  "ejs": "^3.1.6",
81
81
  "emoji-regex": "^10.0.0",
82
- "fs-extra": "^10.0.0",
82
+ "fs-extra": "^10.0.1",
83
83
  "fs-monkey": "^1.0.3",
84
84
  "gulp-sort": "^2.0.0",
85
85
  "hash-string": "^1.0.0",
86
- "i18next": "^21.6.11",
86
+ "i18next": "^21.6.12",
87
87
  "i18next-scanner": "^3.1.0",
88
88
  "iconv-lite": "^0.6.3",
89
89
  "js-cookie": "^3.0.1",
@@ -97,7 +97,7 @@
97
97
  "promise-retry": "^2.0.1",
98
98
  "qs": "^6.10.3",
99
99
  "react": "^17.0.2",
100
- "react-i18next": "^11.15.4",
100
+ "react-i18next": "^11.15.5",
101
101
  "readdir-enhanced": "^6.0.4",
102
102
  "request": "^2.88.2",
103
103
  "request-promise-native": "^1.0.9",
@@ -107,7 +107,7 @@
107
107
  "strip-ansi": "=6.0.0",
108
108
  "tough-cookie": "^4.0.0",
109
109
  "tslib": "^2.3.1",
110
- "typescript": "^4.5.5",
110
+ "typescript": "^4.6.2",
111
111
  "upath": "^2.0.1",
112
112
  "vinyl": "^2.2.1",
113
113
  "vinyl-fs": "^3.0.3"
@@ -125,8 +125,8 @@
125
125
  "@types/js-cookie": "^3.0.1",
126
126
  "@types/koa": "^2.13.4",
127
127
  "@types/koa-compress": "^4.0.3",
128
- "@types/lodash": "^4.14.178",
129
- "@types/node": "^17.0.19",
128
+ "@types/lodash": "^4.14.179",
129
+ "@types/node": "^17.0.21",
130
130
  "@types/promise-retry": "^1.1.3",
131
131
  "@types/qs": "^6.9.7",
132
132
  "@types/react": "^17.0.39",
package/process.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.call_node = exports.call = exports.start = exports.exe_node = exports.fp_root = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const child_process_1 = require("child_process");
6
- const iconv_lite_1 = (0, tslib_1.__importDefault)(require("iconv-lite"));
6
+ const iconv_lite_1 = tslib_1.__importDefault(require("iconv-lite"));
7
7
  require("./prototype.js");
8
8
  const utils_js_1 = require("./utils.js");
9
9
  exports.fp_root = `${__dirname}/`.to_slash();
package/process.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"process.js","sourceRoot":"","sources":["process.ts"],"names":[],"mappings":";;;;AAAA,iDAIsB;AAGtB,yEAA8B;AAE9B,0BAAuB;AAEvB,yCAAoC;AAEvB,QAAA,OAAO,GAAG,GAAG,SAAS,GAAG,CAAC,QAAQ,EAAE,CAAA;AAEpC,QAAA,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAA;AA8BnD;;;;;;;;;;EAUE;AACF,S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,CAAA;QAC7C,CAAC;KACJ,CAAA;IAED,IAAI,IAAI,IAAI,UAAU;QAClB,MAAM,MAAM,CAAC,MAAM,CACf,IAAI,KAAK,CAAC,OAAO,CAAC,EAClB,MAAM,CACT,CAAA;IAEL,OAAO,MAAM,CAAA;AACjB,CAAC;AAlGD,oBAkGC;AAGD;;;;;;;;;;;EAWE;AACK,KAAK,UAAU,SAAS,CAAE,EAAU,EAAE,OAAiB,EAAE,EAAE,OAA0D;IACxH,OAAO,IAAI,CAAC,gBAAQ,EAAE,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;AACjD,CAAC;AAFD,8BAEC","sourcesContent":["import {\n spawn,\n type SpawnOptions,\n type ChildProcess\n} from 'child_process'\nimport { Readable } from 'stream'\n\nimport iconv from 'iconv-lite'\n\nimport './prototype.js'\nimport { Encoding } from './file.js'\nimport { inspect } from './utils.js'\n\nexport const fp_root = `${__dirname}/`.to_slash()\n\nexport const exe_node = process.execPath.to_slash()\n\n\n// ------------------------------------ start & call\ninterface StartOptions {\n /** `'d:/'` */\n cwd?: string\n \n /** `process.env` overwrite/add to process.env */\n env?: Record<string, string>\n \n /** `'utf-8'` child output encoding */\n encoding?: Encoding\n \n /** `true` print option (with details) */\n print?: boolean | {\n command?: boolean\n stdout?: boolean\n stderr?: boolean\n code?: boolean\n error?: boolean\n }\n \n /** `'pipe'` when 'ignore' then ignore stdio processing */\n stdio?: 'pipe' | 'ignore'\n \n /** `false` whether to break the connection with child (ignore stdio, unref) */\n detached?: boolean\n}\n\n/** start process \n - exe: .exe path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` arguments list\n - options\n - cwd?: `fp_root`\n - env?: `process.env` overwrite/add to process.env\n - encoding?: `'utf-8'` child output encoding\n - print?: `true` print option (with details)\n - stdio?: `'pipe'` when 'ignore' then ignore stdio processing\n - detached?: `false` whether to break the connection with child (ignore stdio, unref)\n*/\nexport function start (exe: string, args: string[] = [], {\n cwd = fp_root,\n \n encoding = 'utf-8',\n \n print = true,\n \n stdio = 'pipe',\n \n detached = false,\n \n env,\n \n}: StartOptions = { }): ChildProcess {\n const options: SpawnOptions = {\n cwd,\n shell: false,\n windowsHide: !detached,\n stdio,\n ... env ? {\n env: { ...process.env, ...env }\n } : { },\n }\n \n if (print)\n console.log(`${exe} ${ args.map(arg => arg.includes(' ') ? arg.quote() : arg).join(' ') }`.blue)\n \n if (detached) {\n let child = spawn(exe, args, {\n ...options,\n stdio: 'ignore',\n detached: true,\n })\n \n child.unref()\n return child\n }\n \n let child = spawn(exe, args, options)\n \n if (stdio === 'pipe')\n child.stdin.setDefaultEncoding('utf8')\n \n // prevent child spawn error crashing nodejs process\n child.on('error', error => {\n console.error(error)\n })\n \n if (stdio === 'ignore')\n return child\n \n if (encoding !== 'binary') {\n if (encoding === 'utf-8') {\n child.stdout.setEncoding('utf-8')\n child.stderr.setEncoding('utf-8')\n } else {\n child.stdout = child.stdout.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n child.stderr = child.stderr.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n }\n \n if (print) {\n child.stdout.pipe(process.stdout, { end: false })\n child.stderr.pipe(process.stderr, { end: false })\n }\n }\n \n return child\n}\n\n\nexport interface CallOptions extends StartOptions {\n throw_code?: boolean\n input?: string\n}\n\nexport interface CallResult<T = string> {\n pid: number\n stdout: T\n stderr: T\n code: number | null\n signal: NodeJS.Signals | null\n child: ChildProcess\n [inspect.custom] (): string\n}\n\n\n/** call process for result\n - exe: .exe path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` arguments list\n - options?:\n - cwd?: `'d:/'`\n - env?: `process.env` overwrite/add to process.env\n - encoding?: `'utf-8'` child output encoding\n - print?: `true` print option (with details)\n - stdio?: `'pipe'` when 'ignore' then ignore stdio processing\n - input?: string\n - detached?: `false` whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` whether to throw Error when code is not 0\n*/\nexport async function call (exe: string, args?: string[]): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding?: 'utf-8' | 'gb18030' }): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding: 'binary' }): Promise<CallResult<Buffer>>\nexport async function call (exe: string, args: string[] = [], options: CallOptions = { }): Promise<CallResult<string | Buffer>> {\n const {\n encoding = 'utf-8', \n print = true,\n throw_code = true,\n input\n } = options\n \n const print_options = typeof print === 'boolean' ?\n {\n command: print,\n stdout: print,\n stderr: print,\n code: print,\n error: print\n }\n :\n print\n \n const cmd = `${exe} ${ args.map(arg => arg.includes(' ') ? arg.quote() : arg).join(' ') }`\n \n if (print_options.command)\n console.log(cmd.blue)\n \n options.print = false\n \n let child = start(exe, args, options)\n \n if (input)\n child.stdin.write(input)\n \n // --- collect output\n let stdouts: (string | Buffer)[] = [ ]\n let stderrs: (string | Buffer)[] = [ ]\n \n let code: number | null, \n signal: NodeJS.Signals\n \n await Promise.all([\n new Promise<void>(resolve => {\n child.on('exit', (_code, _signal) => {\n code = _code\n signal = _signal\n resolve()\n })\n }),\n (async () => {\n for await (const chunk of child.stdout as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print_options.stdout)\n process.stdout.write(chunk)\n stdouts.push(chunk)\n }\n })(),\n (async () => {\n for await (const chunk of child.stderr as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print_options.stderr)\n process.stderr.write(chunk)\n stderrs.push(chunk)\n }\n })()\n ])\n \n const message = `process(${ child.pid }) '${ cmd }' exited ${ code }${ signal ? `, by signal ${ signal }` : '' }.`\n \n if (print_options.code || code || signal)\n console.log(message[code || signal ? 'red' : 'blue'])\n \n const result = {\n pid: child.pid,\n \n stdout: encoding === 'binary' ?\n Buffer.concat(stdouts as Buffer[])\n :\n (stdouts as string[]).join(''),\n \n stderr: encoding === 'binary' ?\n Buffer.concat(stderrs as Buffer[])\n :\n (stderrs as string[]).join(''),\n \n code,\n \n signal,\n \n child,\n \n [inspect.custom] () {\n return inspect(this, { omit: ['child'] })\n }\n }\n \n if (code && throw_code)\n throw Object.assign(\n new Error(message), \n result\n )\n \n return result\n}\n\n\n/** call node <js> for result\n - js: .js path (relative path will resolve based on cwd)\n - args: `[]` arguments list\n - options\n - cwd?: `'d:/'`\n - env?: `process.env` overwrite/add to process.env\n - encoding?: `'utf-8'` child process output encoding\n - print?: `true` print option (with details)\n - stdio?: `'pipe'` when 'ignore' then ignore stdio processing\n - detached?: `false` whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` whether to throw Error when code is not 0\n*/\nexport async function call_node (js: string, args: string[] = [], options?: CallOptions & { encoding?: 'utf-8' | 'gb18030' }) {\n return call(exe_node, [js, ...args], options)\n}\n\n"]}
1
+ {"version":3,"file":"process.js","sourceRoot":"","sources":["process.ts"],"names":[],"mappings":";;;;AAAA,iDAIsB;AAGtB,oEAA8B;AAE9B,0BAAuB;AAEvB,yCAAoC;AAEvB,QAAA,OAAO,GAAG,GAAG,SAAS,GAAG,CAAC,QAAQ,EAAE,CAAA;AAEpC,QAAA,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAA;AA8BnD;;;;;;;;;;EAUE;AACF,SAAgB,KAAK,CAAE,GAAW,EAAE,OAAiB,EAAE,EAAE,EACrD,GAAG,GAAG,eAAO,EAEb,QAAQ,GAAG,OAAO,EAElB,KAAK,GAAG,IAAI,EAEZ,KAAK,GAAG,MAAM,EAEd,QAAQ,GAAG,KAAK,EAEhB,GAAG,MAEW,EAAG;IACjB,MAAM,OAAO,GAAiB;QAC1B,GAAG;QACH,KAAK,EAAE,KAAK;QACZ,WAAW,EAAE,CAAC,QAAQ;QACtB,KAAK;QACL,GAAI,GAAG,CAAC,CAAC,CAAC;YACN,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,EAAE;SAClC,CAAC,CAAC,CAAC,EAAG;KACV,CAAA;IAED,IAAI,KAAK;QACL,OAAO,CAAC,GAAG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'\n\nimport iconv from 'iconv-lite'\n\nimport './prototype.js'\nimport { Encoding } from './file.js'\nimport { inspect } from './utils.js'\n\nexport const fp_root = `${__dirname}/`.to_slash()\n\nexport const exe_node = process.execPath.to_slash()\n\n\n// ------------------------------------ start & call\ninterface StartOptions {\n /** `'d:/'` */\n cwd?: string\n \n /** `process.env` overwrite/add to process.env */\n env?: Record<string, string>\n \n /** `'utf-8'` child output encoding */\n encoding?: Encoding\n \n /** `true` print option (with details) */\n print?: boolean | {\n command?: boolean\n stdout?: boolean\n stderr?: boolean\n code?: boolean\n error?: boolean\n }\n \n /** `'pipe'` when 'ignore' then ignore stdio processing */\n stdio?: 'pipe' | 'ignore'\n \n /** `false` whether to break the connection with child (ignore stdio, unref) */\n detached?: boolean\n}\n\n/** start process \n - exe: .exe path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` arguments list\n - options\n - cwd?: `fp_root`\n - env?: `process.env` overwrite/add to process.env\n - encoding?: `'utf-8'` child output encoding\n - print?: `true` print option (with details)\n - stdio?: `'pipe'` when 'ignore' then ignore stdio processing\n - detached?: `false` whether to break the connection with child (ignore stdio, unref)\n*/\nexport function start (exe: string, args: string[] = [], {\n cwd = fp_root,\n \n encoding = 'utf-8',\n \n print = true,\n \n stdio = 'pipe',\n \n detached = false,\n \n env,\n \n}: StartOptions = { }): ChildProcess {\n const options: SpawnOptions = {\n cwd,\n shell: false,\n windowsHide: !detached,\n stdio,\n ... env ? {\n env: { ...process.env, ...env }\n } : { },\n }\n \n if (print)\n console.log(`${exe} ${ args.map(arg => arg.includes(' ') ? arg.quote() : arg).join(' ') }`.blue)\n \n if (detached) {\n let child = spawn(exe, args, {\n ...options,\n stdio: 'ignore',\n detached: true,\n })\n \n child.unref()\n return child\n }\n \n let child = spawn(exe, args, options)\n \n if (stdio === 'pipe')\n child.stdin.setDefaultEncoding('utf8')\n \n // prevent child spawn error crashing nodejs process\n child.on('error', error => {\n console.error(error)\n })\n \n if (stdio === 'ignore')\n return child\n \n if (encoding !== 'binary') {\n if (encoding === 'utf-8') {\n child.stdout.setEncoding('utf-8')\n child.stderr.setEncoding('utf-8')\n } else {\n child.stdout = child.stdout.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n child.stderr = child.stderr.pipe(\n iconv.decodeStream(encoding)\n ) as any as Readable\n }\n \n if (print) {\n child.stdout.pipe(process.stdout, { end: false })\n child.stderr.pipe(process.stderr, { end: false })\n }\n }\n \n return child\n}\n\n\nexport interface CallOptions extends StartOptions {\n throw_code?: boolean\n input?: string\n}\n\nexport interface CallResult<T = string> {\n pid: number\n stdout: T\n stderr: T\n code: number | null\n signal: NodeJS.Signals | null\n child: ChildProcess\n [inspect.custom] (): string\n}\n\n\n/** call process for result\n - exe: .exe path or filename (full path is recommanded to skip path searching for better perf)\n - args: `[]` arguments list\n - options?:\n - cwd?: `'d:/'`\n - env?: `process.env` overwrite/add to process.env\n - encoding?: `'utf-8'` child output encoding\n - print?: `true` print option (with details)\n - stdio?: `'pipe'` when 'ignore' then ignore stdio processing\n - input?: string\n - detached?: `false` whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` whether to throw Error when code is not 0\n*/\nexport async function call (exe: string, args?: string[]): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding?: 'utf-8' | 'gb18030' }): Promise<CallResult<string>>\nexport async function call (exe: string, args?: string[], options?: CallOptions & { encoding: 'binary' }): Promise<CallResult<Buffer>>\nexport async function call (exe: string, args: string[] = [], options: CallOptions = { }): Promise<CallResult<string | Buffer>> {\n const {\n encoding = 'utf-8', \n print = true,\n throw_code = true,\n input\n } = options\n \n const print_options = typeof print === 'boolean' ?\n {\n command: print,\n stdout: print,\n stderr: print,\n code: print,\n error: print\n }\n :\n print\n \n const cmd = `${exe} ${ args.map(arg => arg.includes(' ') ? arg.quote() : arg).join(' ') }`\n \n if (print_options.command)\n console.log(cmd.blue)\n \n options.print = false\n \n let child = start(exe, args, options)\n \n if (input)\n child.stdin.write(input)\n \n // --- collect output\n let stdouts: (string | Buffer)[] = [ ]\n let stderrs: (string | Buffer)[] = [ ]\n \n let code: number | null, \n signal: NodeJS.Signals\n \n await Promise.all([\n new Promise<void>(resolve => {\n child.on('exit', (_code, _signal) => {\n code = _code\n signal = _signal\n resolve()\n })\n }),\n (async () => {\n for await (const chunk of child.stdout as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print_options.stdout)\n process.stdout.write(chunk)\n stdouts.push(chunk)\n }\n })(),\n (async () => {\n for await (const chunk of child.stderr as AsyncIterable<string | Buffer>) {\n if (encoding !== 'binary' && print_options.stderr)\n process.stderr.write(chunk)\n stderrs.push(chunk)\n }\n })()\n ])\n \n const message = `process(${ child.pid }) '${ cmd }' exited ${ code }${ signal ? `, by signal ${ signal }` : '' }.`\n \n if (print_options.code || code || signal)\n console.log(message[code || signal ? 'red' : 'blue'])\n \n const result = {\n pid: child.pid,\n \n stdout: encoding === 'binary' ?\n Buffer.concat(stdouts as Buffer[])\n :\n (stdouts as string[]).join(''),\n \n stderr: encoding === 'binary' ?\n Buffer.concat(stderrs as Buffer[])\n :\n (stderrs as string[]).join(''),\n \n code,\n \n signal,\n \n child,\n \n [inspect.custom] () {\n return inspect(this, { omit: ['child'] })\n }\n }\n \n if (code && throw_code)\n throw Object.assign(\n new Error(message), \n result\n )\n \n return result\n}\n\n\n/** call node <js> for result\n - js: .js path (relative path will resolve based on cwd)\n - args: `[]` arguments list\n - options\n - cwd?: `'d:/'`\n - env?: `process.env` overwrite/add to process.env\n - encoding?: `'utf-8'` child process output encoding\n - print?: `true` print option (with details)\n - stdio?: `'pipe'` when 'ignore' then ignore stdio processing\n - detached?: `false` whether to break the connection with child (ignore stdio, unref)\n - throw_code?: `true` whether to throw Error when code is not 0\n*/\nexport async function call_node (js: string, args: string[] = [], options?: CallOptions & { encoding?: 'utf-8' | 'gb18030' }) {\n return call(exe_node, [js, ...args], options)\n}\n\n"]}
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.is_codepoint_fullwidth = exports.to_json = exports.brackets = exports.quotes = exports.cjk = exports.to_getter_property_descriptors = exports.to_method_property_descriptors = exports.emoji_regex = void 0;
5
5
  const tslib_1 = require("tslib");
6
- const byte_size_1 = (0, tslib_1.__importDefault)(require("byte-size"));
7
- const emoji_regex_1 = (0, tslib_1.__importDefault)(require("emoji-regex"));
6
+ const byte_size_1 = tslib_1.__importDefault(require("byte-size"));
7
+ const emoji_regex_1 = tslib_1.__importDefault(require("emoji-regex"));
8
8
  exports.emoji_regex = (0, emoji_regex_1.default)();
9
9
  function to_method_property_descriptors(methods) {
10
10
  return Object.fromEntries(Object.entries(methods)