@zwa73/utils 1.0.204 → 1.0.206
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/dist/UtilCom.js +2 -2
- package/dist/UtilFunctions.d.ts +3 -0
- package/dist/UtilFunctions.js +8 -6
- package/package.json +1 -1
package/dist/UtilCom.js
CHANGED
|
@@ -259,7 +259,7 @@ class UtilCom {
|
|
|
259
259
|
let { option, retries, verify } = opt;
|
|
260
260
|
retries ??= {};
|
|
261
261
|
retries.tryDelay = retries.tryDelay ?? 1000;
|
|
262
|
-
const procFn = () => this.once(option, ...datas);
|
|
262
|
+
const procFn = async () => this.once(option, ...datas);
|
|
263
263
|
return UtilFunctions_1.UtilFunc.retryPromise(procFn, verify, retries);
|
|
264
264
|
}
|
|
265
265
|
/**发送网络请求
|
|
@@ -338,7 +338,7 @@ class UtilCom {
|
|
|
338
338
|
}
|
|
339
339
|
exports.UtilCom = UtilCom;
|
|
340
340
|
if (false)
|
|
341
|
-
((async () => {
|
|
341
|
+
void ((async () => {
|
|
342
342
|
const t = await UtilCom.https().postJson()
|
|
343
343
|
.once({
|
|
344
344
|
hostname: 'httpbin.org',
|
package/dist/UtilFunctions.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ type ExecOpt = Partial<{
|
|
|
9
9
|
errlvl: LogLevel;
|
|
10
10
|
/**node_modules文件夹目录, 用于设定环境变量 */
|
|
11
11
|
nodeModules: string;
|
|
12
|
+
/**工作路径 */
|
|
13
|
+
cwd: string;
|
|
12
14
|
}>;
|
|
13
15
|
/**序列化选项 */
|
|
14
16
|
type StringifyOpt = Partial<{
|
|
@@ -103,6 +105,7 @@ export declare class UtilFunc {
|
|
|
103
105
|
* @param opt.outlvl - 普通输出的日志等级
|
|
104
106
|
* @param opt.errlvl - 错误的日志等级
|
|
105
107
|
* @param opt.nodeModules - nodeModules文件夹路径
|
|
108
|
+
* @param opt.cwd - 执行目录
|
|
106
109
|
*/
|
|
107
110
|
static exec(command: string, opt?: ExecOpt): Promise<{
|
|
108
111
|
stdout: string;
|
package/dist/UtilFunctions.js
CHANGED
|
@@ -120,8 +120,9 @@ class UtilFunc {
|
|
|
120
120
|
* @param opt.outlvl - 普通输出的日志等级
|
|
121
121
|
* @param opt.errlvl - 错误的日志等级
|
|
122
122
|
* @param opt.nodeModules - nodeModules文件夹路径
|
|
123
|
+
* @param opt.cwd - 执行目录
|
|
123
124
|
*/
|
|
124
|
-
static exec(command, opt) {
|
|
125
|
+
static async exec(command, opt) {
|
|
125
126
|
return new Promise(async (resolve, reject) => {
|
|
126
127
|
// 创建一个新的环境变量对象,并将项目的 node_modules/.bin 目录添加到 PATH 环境变量中
|
|
127
128
|
const env = Object.create(process.env);
|
|
@@ -137,7 +138,8 @@ class UtilFunc {
|
|
|
137
138
|
UtilFunc.originalExecTitle = UtilFunc.originalExecTitle == UtilSymbol_1.None
|
|
138
139
|
? process.title
|
|
139
140
|
: UtilFunc.originalExecTitle;
|
|
140
|
-
const
|
|
141
|
+
const cwd = opt?.cwd ?? process.cwd();
|
|
142
|
+
const child = cp.spawn(command, { shell: true, env, cwd });
|
|
141
143
|
let stdout = '';
|
|
142
144
|
let stderr = '';
|
|
143
145
|
child.stdout.on('data', (data) => {
|
|
@@ -163,7 +165,7 @@ class UtilFunc {
|
|
|
163
165
|
});
|
|
164
166
|
}
|
|
165
167
|
/**获得一个永不完成的Promise单例 */
|
|
166
|
-
static getNeverResolvedPromise() {
|
|
168
|
+
static async getNeverResolvedPromise() {
|
|
167
169
|
return NeverResolvedPromise;
|
|
168
170
|
}
|
|
169
171
|
/**重复尝试promise
|
|
@@ -299,7 +301,7 @@ class UtilFunc {
|
|
|
299
301
|
* @param timeLimit - 毫秒限时
|
|
300
302
|
* @returns 超时则返回 处理函数委托 完成则返回结果
|
|
301
303
|
*/
|
|
302
|
-
static timelimitPromise(func, timeLimit) {
|
|
304
|
+
static async timelimitPromise(func, timeLimit) {
|
|
303
305
|
return new Promise((reslove) => {
|
|
304
306
|
let clearTimer = null;
|
|
305
307
|
const procer = (async () => await func())();
|
|
@@ -545,7 +547,7 @@ class UtilFunc {
|
|
|
545
547
|
* @param task - 任务逻辑
|
|
546
548
|
* @returns 处理结果
|
|
547
549
|
*/
|
|
548
|
-
static queueProc(flag, task) {
|
|
550
|
+
static async queueProc(flag, task) {
|
|
549
551
|
// 如果当前标签的队列不存在,则创建一个新的队列
|
|
550
552
|
if (!UtilFunc.pendingMap[flag])
|
|
551
553
|
UtilFunc.pendingMap[flag] = [];
|
|
@@ -587,7 +589,7 @@ class UtilFunc {
|
|
|
587
589
|
UtilFunc.pendingMap[flag].push(processTask);
|
|
588
590
|
// 如果队列中只有当前任务,立即执行
|
|
589
591
|
if (UtilFunc.pendingMap[flag].length === 1)
|
|
590
|
-
processTask();
|
|
592
|
+
void processTask();
|
|
591
593
|
// 返回Promise,以便调用者可以等待任务完成
|
|
592
594
|
return promise;
|
|
593
595
|
}
|