xshell 0.0.29 → 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.
- package/file.d.ts +5 -7
- package/file.js +25 -19
- package/file.js.map +1 -1
- package/i18n/README.md +4 -1
- package/i18n/dict.d.ts +1 -1
- package/i18n/dict.js.map +1 -1
- package/i18n/i18n-scan.js +17 -15
- package/i18n/i18n-scan.js.map +1 -1
- package/i18n/index.d.ts +2 -2
- package/i18n/index.js +8 -8
- package/i18n/index.js.map +1 -1
- package/i18n/rwdict.d.ts +2 -3
- package/i18n/rwdict.js +2 -3
- package/i18n/rwdict.js.map +1 -1
- package/i18n/scanner/checker.d.ts +3 -4
- package/i18n/scanner/checker.js +11 -15
- package/i18n/scanner/checker.js.map +1 -1
- package/i18n/scanner/index.d.ts +1 -1
- package/i18n/scanner/index.js +184 -175
- package/i18n/scanner/index.js.map +1 -1
- package/i18n/scanner/parser.js +19 -17
- package/i18n/scanner/parser.js.map +1 -1
- package/i18n/utils.d.ts +1 -1
- package/i18n/utils.js +5 -4
- package/i18n/utils.js.map +1 -1
- package/index.d.ts +5 -5
- package/index.js +5 -5
- package/index.js.map +1 -1
- package/net.js +9 -12
- package/net.js.map +1 -1
- package/package.json +20 -19
- package/process.d.ts +3 -2
- package/process.js +4 -2
- package/process.js.map +1 -1
- package/prototype.browser.js +6 -1
- package/prototype.browser.js.map +1 -1
- package/prototype.js +11 -12
- package/prototype.js.map +1 -1
- package/repl.js +12 -32
- package/repl.js.map +1 -1
- package/server.d.ts +1 -0
- package/server.js +15 -14
- package/server.js.map +1 -1
- package/ufs.js +3 -3
- package/ufs.js.map +1 -1
- package/utils.d.ts +18 -3
- package/utils.js +151 -20
- package/utils.js.map +1 -1
package/i18n/scanner/parser.js
CHANGED
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mix_parse_trans_from_string_by_babel = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const castArray_js_1 = tslib_1.__importDefault(require("lodash/castArray.js"));
|
|
6
|
+
const trim_js_1 = tslib_1.__importDefault(require("lodash/trim.js"));
|
|
7
|
+
const get_js_1 = tslib_1.__importDefault(require("lodash/get.js"));
|
|
8
|
+
const traverse_1 = tslib_1.__importDefault(require("@babel/traverse"));
|
|
7
9
|
const parser_1 = require("@babel/parser");
|
|
8
|
-
const t =
|
|
10
|
+
const t = tslib_1.__importStar(require("@babel/types"));
|
|
9
11
|
require("../../prototype.js");
|
|
10
12
|
// import { Checker } from './checker'
|
|
11
13
|
/** file:///D:/0/i18next-scanner/src/parser.js */
|
|
12
14
|
function mix_parse_trans_from_string_by_babel(parser) {
|
|
13
|
-
parser.parseTransFromStringByBabel = function (code, options = {},
|
|
14
|
-
if (
|
|
15
|
-
|
|
15
|
+
parser.parseTransFromStringByBabel = function parse_trans_from_string_by_babel(code, options = {}, custom_handler = null, on_error = () => { }) {
|
|
16
|
+
if (typeof options === 'function') {
|
|
17
|
+
custom_handler = options;
|
|
16
18
|
options = {};
|
|
17
19
|
}
|
|
18
20
|
const { transformOptions = {}, // object
|
|
@@ -32,7 +34,7 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
32
34
|
return literal.quasis.map(element => element.value.cooked).join("");
|
|
33
35
|
return literal.value;
|
|
34
36
|
};
|
|
35
|
-
const attr = (0,
|
|
37
|
+
const attr = (0, castArray_js_1.default)(node.openingElement.attributes).reduce((acc, attribute) => {
|
|
36
38
|
if (!t.isJSXAttribute(attribute) ||
|
|
37
39
|
!t.isJSXIdentifier(attribute.name))
|
|
38
40
|
return acc;
|
|
@@ -47,7 +49,7 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
47
49
|
else if (t.isLiteral(expression))
|
|
48
50
|
acc[name] = getLiteralValue(expression);
|
|
49
51
|
else if (t.isObjectExpression(expression)) {
|
|
50
|
-
const properties = (0,
|
|
52
|
+
const properties = (0, castArray_js_1.default)(expression.properties);
|
|
51
53
|
acc[name] = properties.reduce((obj, property) => {
|
|
52
54
|
if (!t.isObjectProperty(property))
|
|
53
55
|
return obj;
|
|
@@ -71,7 +73,7 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
71
73
|
}
|
|
72
74
|
return acc;
|
|
73
75
|
}, {});
|
|
74
|
-
const transKey = (0,
|
|
76
|
+
const transKey = (0, trim_js_1.default)(attr[i18nKey]);
|
|
75
77
|
const defaultsString = attr[defaultsKey] || "";
|
|
76
78
|
if (typeof defaultsString !== "string")
|
|
77
79
|
this.log(`defaults value must be a static string, saw ${defaultsString.yellow}`);
|
|
@@ -79,7 +81,7 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
79
81
|
const tOptions = attr.tOptions;
|
|
80
82
|
const options = {
|
|
81
83
|
...tOptions,
|
|
82
|
-
defaultValue: defaultsString || nodes_to_string(node.children, filepath,
|
|
84
|
+
defaultValue: defaultsString || nodes_to_string(node.children, filepath, on_error),
|
|
83
85
|
fallbackKey,
|
|
84
86
|
};
|
|
85
87
|
if (Object.prototype.hasOwnProperty.call(attr, "count"))
|
|
@@ -89,8 +91,8 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
89
91
|
this.log(`The ns attribute must be a string, saw ${attr.ns?.yellow}`);
|
|
90
92
|
options.ns = attr.ns;
|
|
91
93
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
+
if (custom_handler) {
|
|
95
|
+
custom_handler(transKey, options);
|
|
94
96
|
return;
|
|
95
97
|
}
|
|
96
98
|
this.set(transKey, options);
|
|
@@ -101,7 +103,7 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
101
103
|
// traverse(ast, Checker({ filepath }))
|
|
102
104
|
}
|
|
103
105
|
catch (err) {
|
|
104
|
-
|
|
106
|
+
on_error(() => {
|
|
105
107
|
console.error('');
|
|
106
108
|
const { line, column } = (err && err.loc) || { line: 1, column: 1 };
|
|
107
109
|
console.error([filepath, line, column].join(":").yellow);
|
|
@@ -117,7 +119,7 @@ function mix_parse_trans_from_string_by_babel(parser) {
|
|
|
117
119
|
exports.mix_parse_trans_from_string_by_babel = mix_parse_trans_from_string_by_babel;
|
|
118
120
|
function nodes_to_string(nodes, filepath, onError) {
|
|
119
121
|
let memo = '';
|
|
120
|
-
let
|
|
122
|
+
let node_index = 0;
|
|
121
123
|
nodes.forEach((node, i) => {
|
|
122
124
|
if (t.isJSXText(node) || t.isStringLiteral(node)) {
|
|
123
125
|
const value = node.value
|
|
@@ -135,7 +137,7 @@ function nodes_to_string(nodes, filepath, onError) {
|
|
|
135
137
|
if (t.isStringLiteral(expression))
|
|
136
138
|
memo += expression.value;
|
|
137
139
|
else if (t.isObjectExpression(expression) &&
|
|
138
|
-
t.isObjectProperty((0,
|
|
140
|
+
t.isObjectProperty((0, get_js_1.default)(expression, 'properties[0]')))
|
|
139
141
|
memo += '{{' + expression.properties[0].key.name + '}}';
|
|
140
142
|
else
|
|
141
143
|
onError(() => {
|
|
@@ -146,8 +148,8 @@ function nodes_to_string(nodes, filepath, onError) {
|
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
else if (node.children)
|
|
149
|
-
memo += `<${
|
|
150
|
-
|
|
151
|
+
memo += `<${node_index}>${nodes_to_string(node.children, filepath, onError)}</${node_index}>`;
|
|
152
|
+
node_index++;
|
|
151
153
|
});
|
|
152
154
|
return memo;
|
|
153
155
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["parser.ts"],"names":[],"mappings":";;;;AAAA,mCAAiE;AACjE,4EAAsC;AACtC,0CAAqC;AACrC,6DAAiC;AAEjC,8BAA2B;AAE3B,sCAAsC;AAEtC,iDAAiD;AACjD,SAAgB,oCAAoC,CAAE,MAAM;IACxD,MAAM,CAAC,2BAA2B,GAAG,UAAS,IAAY,EAAE,OAAO,GAAG,EAAG,EAAE,aAAa,GAAG,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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,SAAS,IAAI,eAAe,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,KAAK,SAAS,GAAG,CAAA;QAG/F,SAAS,EAAE,CAAA;IACf,CAAC,CAAC,CAAA;IAEF,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["import { isFunction, castArray, trim, get as _get } from 'lodash'\nimport traverse from '@babel/traverse'\nimport { parse } from '@babel/parser'\nimport * as t from '@babel/types'\n\nimport '../../prototype.js'\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(code: string, options = { }, customHandler = null, onError: (callback: Function) => void = () => { } ) {\n if (isFunction(options)) {\n customHandler = 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, onError),\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 (customHandler) {\n customHandler(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 onError(() => {\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 nodeIndex = 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 += `<${nodeIndex}>${nodes_to_string(node.children, filepath, onError)}</${nodeIndex}>`\n \n \n nodeIndex++\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,CAC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AU,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
|
|
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.
|
|
4
|
-
|
|
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
|
|
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.
|
|
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,
|
|
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.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './prototype';
|
|
2
|
-
export * from './utils';
|
|
3
|
-
export * from './file';
|
|
4
|
-
export * from './process';
|
|
5
|
-
export * from './net';
|
|
1
|
+
export * from './prototype.js';
|
|
2
|
+
export * from './utils.js';
|
|
3
|
+
export * from './file.js';
|
|
4
|
+
export * from './process.js';
|
|
5
|
+
export * from './net.js';
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,
|
|
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 =
|
|
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 =
|
|
8
|
-
const iconv_lite_1 =
|
|
9
|
-
const cheerio_1 =
|
|
10
|
-
const qs_1 =
|
|
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");
|
|
@@ -38,8 +38,7 @@ exports.cookies = {
|
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
40
|
exports._request = request_promise_native_1.default.defaults({
|
|
41
|
-
rejectUnauthorized: false,
|
|
42
|
-
gzip: true,
|
|
41
|
+
// rejectUnauthorized: false,
|
|
43
42
|
/** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */
|
|
44
43
|
simple: false,
|
|
45
44
|
jar: exports.cookies.jar
|
|
@@ -66,8 +65,6 @@ async function request_retry(retries, request_options) {
|
|
|
66
65
|
exports.request_retry = request_retry;
|
|
67
66
|
async function request(url, { queries, body, type = 'application/json', proxy, method, headers, encoding, raw = false, retries, timeout = 20 * 1000, auth, gzip, cookies, } = {}) {
|
|
68
67
|
url = url.toString();
|
|
69
|
-
if (!url.startsWith('http'))
|
|
70
|
-
url = 'http://' + url;
|
|
71
68
|
const _body = body; // for error log
|
|
72
69
|
if (body && !method)
|
|
73
70
|
method = 'post';
|
|
@@ -92,7 +89,7 @@ async function request(url, { queries, body, type = 'application/json', proxy, m
|
|
|
92
89
|
resolveWithFullResponse: true,
|
|
93
90
|
headers: {
|
|
94
91
|
'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',
|
|
95
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
92
|
+
'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',
|
|
96
93
|
...body ? { 'content-type': type } : {},
|
|
97
94
|
...cookies ? {
|
|
98
95
|
cookie: Object.entries(cookies)
|
|
@@ -136,7 +133,7 @@ async function request(url, { queries, body, type = 'application/json', proxy, m
|
|
|
136
133
|
(0, utils_js_1.inspect)(qs) + '\n';
|
|
137
134
|
if (_body)
|
|
138
135
|
s += `\n${'request.body:'.blue}\n` +
|
|
139
|
-
(0, utils_js_1.inspect)(
|
|
136
|
+
(0, utils_js_1.inspect)(_body) + '\n';
|
|
140
137
|
if (name === 'StatusCodeError')
|
|
141
138
|
s += `\n${'response.status:'.yellow} ${String(error.statusCode).red}\n`;
|
|
142
139
|
else if (error instanceof errors_js_1.RequestError)
|
|
@@ -230,7 +227,7 @@ function to_curl(url, { queries, headers, method, body, proxy, exe = true } = {}
|
|
|
230
227
|
// ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())
|
|
231
228
|
// ) +
|
|
232
229
|
(proxy ? ` --proxy ${proxy.quote()}` : '') +
|
|
233
|
-
(method && method !== 'get' ? ` -X ${method}` : '') +
|
|
230
|
+
(method && method !== 'get' ? ` -X ${method.toUpperCase()}` : '') +
|
|
234
231
|
(headers ? Object.entries(headers).map(([key, value]) => ' -H ' + `${key}: ${value}`.quote()).join('') : '') +
|
|
235
232
|
(body ? ' -H ' + 'content-type: application/json'.quote() : '') +
|
|
236
233
|
(body ? ' --data ' + JSON.stringify(body).quote() : '');
|
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,yDAA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AG;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 gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAMA,4FAG+B;AAC/B,gEAAgF;AAEhF,0EAAyC;AAEzC,oEAA8B;AAC9B,8DAA6B;AAC7B,oDAAmB;AACnB,+CAAwD;AA2C/C,uFA3CA,qBAAM,OA2CA;AAlCf,0BAAuB;AAEvB,yCAAkD;AAElD,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,4CAAkC,CAAA;IAClC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,gCAAiB,EAAE,CAAA;AAE/B,QAAA,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAAG,EAAE,gCAAe,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtC,GAAG,CAAE,aAAqB,EAAE,GAAG,GAAG,KAAK;QACnC,IAAI,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC;YAChC,IAAI,GAAG;gBACH,OAAO,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;;gBAE9C,OAAO,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,aAAa,CAAC,CAAA;QAEjD,IAAI,OAAiB,CAAA;QACrB,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE;YAClE,IAAI,KAAK;gBAAE,MAAM,KAAK,CAAA;YACtB,OAAO,GAAG,QAA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AC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAE,CAAC,CAAE,EAAE,CAAC,CAAA;AACpE,CAAC;AArBD,0BAqBC;AAKD,kDAAkD;AAClD;;;;;;EAME;AACK,KAAK,UAAU,GAAG,CACrB,IAAY,EACZ,IAAY,EACZ,EAAE,GAAG,GAAG,+BAA+B,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,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.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"bin": {
|
|
6
6
|
"xshell": "./xshell.js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
],
|
|
17
17
|
"type": "commonjs",
|
|
18
18
|
"engines": {
|
|
19
|
-
"node": ">=17.
|
|
20
|
-
"vscode": "
|
|
19
|
+
"node": ">=17.4.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"
|
|
@@ -65,25 +65,25 @@
|
|
|
65
65
|
]
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@babel/core": "^7.
|
|
69
|
-
"@babel/parser": "^7.
|
|
70
|
-
"@babel/traverse": "^7.
|
|
68
|
+
"@babel/core": "^7.17.5",
|
|
69
|
+
"@babel/parser": "^7.17.3",
|
|
70
|
+
"@babel/traverse": "^7.17.3",
|
|
71
71
|
"@koa/cors": "^3.1.0",
|
|
72
72
|
"byte-size": "^8.1.0",
|
|
73
73
|
"chalk": "^4.1.2",
|
|
74
74
|
"chardet": "^1.4.0",
|
|
75
75
|
"cheerio": "^1.0.0-rc.10",
|
|
76
|
-
"cli-table3": "^0.6.
|
|
76
|
+
"cli-table3": "^0.6.1",
|
|
77
77
|
"cli-truncate": "=2.1.0",
|
|
78
78
|
"colors": "^1.4.0",
|
|
79
79
|
"commander": "^8.3.0",
|
|
80
80
|
"ejs": "^3.1.6",
|
|
81
81
|
"emoji-regex": "^10.0.0",
|
|
82
|
-
"fs-extra": "^10.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.
|
|
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",
|
|
@@ -95,9 +95,9 @@
|
|
|
95
95
|
"memfs": "^3.4.1",
|
|
96
96
|
"ora": "=5.4.1",
|
|
97
97
|
"promise-retry": "^2.0.1",
|
|
98
|
-
"qs": "^6.10.
|
|
98
|
+
"qs": "^6.10.3",
|
|
99
99
|
"react": "^17.0.2",
|
|
100
|
-
"react-i18next": "^11.15.
|
|
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,16 +107,17 @@
|
|
|
107
107
|
"strip-ansi": "=6.0.0",
|
|
108
108
|
"tough-cookie": "^4.0.0",
|
|
109
109
|
"tslib": "^2.3.1",
|
|
110
|
-
"typescript": "^4.
|
|
110
|
+
"typescript": "^4.6.2",
|
|
111
111
|
"upath": "^2.0.1",
|
|
112
112
|
"vinyl": "^2.2.1",
|
|
113
113
|
"vinyl-fs": "^3.0.3"
|
|
114
114
|
},
|
|
115
115
|
"devDependencies": {
|
|
116
|
-
"@babel/types": "^7.
|
|
116
|
+
"@babel/types": "^7.17.0",
|
|
117
117
|
"@types/babel__traverse": "^7.14.2",
|
|
118
|
+
"@types/byte-size": "^8.1.0",
|
|
118
119
|
"@types/chardet": "^0.8.1",
|
|
119
|
-
"@types/cheerio": "^0.22.
|
|
120
|
+
"@types/cheerio": "^0.22.31",
|
|
120
121
|
"@types/ejs": "^3.1.0",
|
|
121
122
|
"@types/express": "^4.17.13",
|
|
122
123
|
"@types/fs-extra": "^9.0.13",
|
|
@@ -124,18 +125,18 @@
|
|
|
124
125
|
"@types/js-cookie": "^3.0.1",
|
|
125
126
|
"@types/koa": "^2.13.4",
|
|
126
127
|
"@types/koa-compress": "^4.0.3",
|
|
127
|
-
"@types/lodash": "^4.14.
|
|
128
|
-
"@types/node": "^17.0.
|
|
128
|
+
"@types/lodash": "^4.14.179",
|
|
129
|
+
"@types/node": "^17.0.21",
|
|
129
130
|
"@types/promise-retry": "^1.1.3",
|
|
130
131
|
"@types/qs": "^6.9.7",
|
|
131
|
-
"@types/react": "^17.0.
|
|
132
|
+
"@types/react": "^17.0.39",
|
|
132
133
|
"@types/request": "^2.48.8",
|
|
133
134
|
"@types/request-promise-native": "^1.0.18",
|
|
134
135
|
"@types/rimraf": "^3.0.2",
|
|
135
136
|
"@types/stream-buffers": "^3.0.4",
|
|
136
137
|
"@types/tampermonkey": "^4.0.5",
|
|
137
138
|
"@types/vinyl-fs": "^2.4.12",
|
|
138
|
-
"@types/vscode": "^1.
|
|
139
|
+
"@types/vscode": "^1.64.0",
|
|
139
140
|
"source-map-loader": "^3.0.1",
|
|
140
141
|
"ts-loader": "^9.2.6"
|
|
141
142
|
}
|
package/process.d.ts
CHANGED
|
@@ -38,8 +38,8 @@ interface StartOptions {
|
|
|
38
38
|
*/
|
|
39
39
|
export declare function start(exe: string, args?: string[], { cwd, encoding, print, stdio, detached, env, }?: StartOptions): ChildProcess;
|
|
40
40
|
export interface CallOptions extends StartOptions {
|
|
41
|
-
/** `true` whether to throw Error when code is not 0 */
|
|
42
41
|
throw_code?: boolean;
|
|
42
|
+
input?: string;
|
|
43
43
|
}
|
|
44
44
|
export interface CallResult<T = string> {
|
|
45
45
|
pid: number;
|
|
@@ -53,12 +53,13 @@ export interface CallResult<T = string> {
|
|
|
53
53
|
/** call process for result
|
|
54
54
|
- exe: .exe path or filename (full path is recommanded to skip path searching for better perf)
|
|
55
55
|
- args: `[]` arguments list
|
|
56
|
-
- options
|
|
56
|
+
- options?:
|
|
57
57
|
- cwd?: `'d:/'`
|
|
58
58
|
- env?: `process.env` overwrite/add to process.env
|
|
59
59
|
- encoding?: `'utf-8'` child output encoding
|
|
60
60
|
- print?: `true` print option (with details)
|
|
61
61
|
- stdio?: `'pipe'` when 'ignore' then ignore stdio processing
|
|
62
|
+
- input?: string
|
|
62
63
|
- detached?: `false` whether to break the connection with child (ignore stdio, unref)
|
|
63
64
|
- throw_code?: `true` whether to throw Error when code is not 0
|
|
64
65
|
*/
|
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 =
|
|
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();
|
|
@@ -67,7 +67,7 @@ function start(exe, args = [], { cwd = exports.fp_root, encoding = 'utf-8', prin
|
|
|
67
67
|
}
|
|
68
68
|
exports.start = start;
|
|
69
69
|
async function call(exe, args = [], options = {}) {
|
|
70
|
-
const { encoding = 'utf-8', print = true, throw_code = true, } = options;
|
|
70
|
+
const { encoding = 'utf-8', print = true, throw_code = true, input } = options;
|
|
71
71
|
const print_options = typeof print === 'boolean' ?
|
|
72
72
|
{
|
|
73
73
|
command: print,
|
|
@@ -83,6 +83,8 @@ async function call(exe, args = [], options = {}) {
|
|
|
83
83
|
console.log(cmd.blue);
|
|
84
84
|
options.print = false;
|
|
85
85
|
let child = start(exe, args, options);
|
|
86
|
+
if (input)
|
|
87
|
+
child.stdin.write(input);
|
|
86
88
|
// --- collect output
|
|
87
89
|
let stdouts = [];
|
|
88
90
|
let stderrs = [];
|