jsir 2.6.6 → 2.6.7

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/cmd/oaa.js CHANGED
@@ -443,6 +443,7 @@ function _nextLine(callback, promptStr, hidden, resolve, end, isText) {
443
443
  _rl.removeAllListeners('line')
444
444
  _rl.on('line', lineHandler)
445
445
  _rl.prompt()
446
+ setting.lastOutput = null;
446
447
  }
447
448
 
448
449
  async function nextText(callback, end, hidden) {
package/deps/evalCode.js CHANGED
@@ -19,6 +19,12 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
19
19
 
20
20
  const $setTips = $lib.setTips;
21
21
  const $delTips = $lib.delTips;
22
+ const $tips = {
23
+ set: $lib.setTips,
24
+ del: $lib.delTips,
25
+ has: $lib.hasTips,
26
+ key: $lib.tipKeys
27
+ }
22
28
  const $errorTag = $lib.errorTag;
23
29
  const $aop = $lib.aop;
24
30
  const $aopAsync = $lib.aopAsync;
@@ -29,7 +35,7 @@ module.exports = async ($text = '', $cmdName = '', $args = [],
29
35
  $require, $requires, $import,
30
36
  $text, $cmdName, $args,
31
37
  $nextLine, $nextText,
32
- $setTips, $delTips,
38
+ $setTips, $delTips, $tips,
33
39
  $enter, $filterCmd,
34
40
  $currentSpace, $defaultSpace, $workspaceMap,
35
41
  $homeDir, $lib, $cmdMap
package/deps/room.js CHANGED
@@ -342,10 +342,10 @@ async function initRoom() {
342
342
  pros.push(syncConfigs())
343
343
  }
344
344
  await Promise.all(pros);
345
- }, false)
345
+ }, false).catch(debug)
346
346
  }
347
347
  if (defTasks && Object.keys(defTasks).length > 0) {
348
- processLock(roomTasksFile, processTasks, false)
348
+ processLock(roomTasksFile, processTasks, false).catch(debug)
349
349
  }
350
350
  await syncSetting();
351
351
  }
@@ -510,9 +510,12 @@ async function reqNode(node, method, url, port, body) {
510
510
  return await new Promise((resolve, reject) => {
511
511
  let timeout = null
512
512
 
513
- const req = http.request({...opt, headers: {
513
+ let options = {...opt,
514
+ headers: {
514
515
  'sign': createSign()
515
- }}, (res) => {
516
+ }};
517
+ options.path = encodeURI(opt.path);
518
+ const req = http.request(options, (res) => {
516
519
  let data = '';
517
520
  // 数据块接收
518
521
  res.on('data', (chunk) => {
@@ -587,7 +590,7 @@ async function reqFn(fnKey, args = []) {
587
590
  throw `service function ${fnKey} not found`;
588
591
  }
589
592
  let resp = await reqNode(target.node, 'post',
590
- `/${encodeURI(fnKey)}`, target.port, JSON.stringify(args || []))
593
+ `/${fnKey}`, target.port, JSON.stringify(args || []))
591
594
  return JSON.parse(resp).result;
592
595
  }
593
596
 
package/deps/setting.js CHANGED
@@ -35,7 +35,8 @@ module.exports = {
35
35
  enterOutputs: null,
36
36
  defaultPort: 52108,
37
37
  reqNodeTimeouts: {
38
- '/': 2000
38
+ '/': 2000,
39
+ '/config/main': 2000
39
40
  },
40
41
  roomTimer: 2000,
41
42
  roomTime: Date.now(),
package/deps/util.js CHANGED
@@ -285,7 +285,7 @@ function createConsole(uniqueName) {
285
285
  }
286
286
  let hasFlag = false;
287
287
  let sameFlag = false;
288
- if (args.length > 1 && typeof args[0] === 'string' && args[0].startsWith("*") && args[0].endsWith("*")) {
288
+ if (args.length > 1 && typeof args[0] === 'string' && args[0].length > 2 && args[0].startsWith("*") && args[0].endsWith("*")) {
289
289
  hasFlag = true;
290
290
  let flag = args[0]
291
291
  args = args.slice(1)
@@ -307,19 +307,22 @@ function createConsole(uniqueName) {
307
307
  }
308
308
  } else {
309
309
  let _args = _consoleFns[key].args(args);
310
-
311
- if (hasFlag && !isRunningInBackground() && setting.lastOutput && sameFlag) {
312
- let lines = (setting.lastOutput.match(/\n/g) || []).length + 1;
313
- for (let i = 0; i < lines; i++) {
314
- process.stdout.write('\x1b[A\r'+ ' '.repeat(process.stdout.columns))
310
+ let lastOutput = null;
311
+ if (hasFlag) {
312
+ lastOutput = _args.join(" ")
313
+ if (!isRunningInBackground() && setting.lastOutput && sameFlag) {
314
+ let lines = setting.lastOutput.split('\n').length;
315
+ for (let i = 0; i < lines; i++) {
316
+ process.stdout.write('\x1b[A\r'+ ' '.repeat(process.stdout.columns))
317
+ }
318
+ _args[0] = '\r' + _args[0]
315
319
  }
316
- _args[0] = '\r' + _args[0]
317
320
  }
318
321
 
319
322
  _consoleFns[key].fn(..._args);
320
323
 
321
324
  if (hasFlag) {
322
- setting.lastOutput = _args.join(" ");
325
+ setting.lastOutput = lastOutput;
323
326
  } else {
324
327
  setting.lastOutput = null;
325
328
  }
@@ -1229,26 +1232,20 @@ async function _fileLock(key, fn, expireMs = 49000) {
1229
1232
  if (!key || typeof fn !== 'function') {
1230
1233
  throw new Error('invalid arguments');
1231
1234
  }
1235
+ if (expireMs < 1000) {
1236
+ throw new Error("expireMs can not less than 1000")
1237
+ }
1232
1238
 
1233
1239
  let lockKeyDir = getLockKeyDir(key)
1234
1240
  const now = Date.now();
1235
- const expireAt = expireMs > 0 ? now + expireMs : 0;
1241
+ const expireAt = now + expireMs;
1236
1242
 
1237
1243
  // 1. 尝试判断锁目录是否已存在
1238
1244
  let lockExists = await fileExist(lockKeyDir);
1239
1245
 
1240
1246
  if (lockExists) {
1241
1247
  // 目录存在时,读取文件名中的过期时间戳
1242
- const storedExpireAt = await readExpireTimestamp(lockKeyDir);
1243
- if (storedExpireAt === null) {
1244
- // 理论上不会出现没有“expire-xxxx”文件的情况,除非中途被手动改动
1245
- // 可以选择强制删除目录,或者直接返回 false
1246
- return false;
1247
- }
1248
- if (storedExpireAt === 0) {
1249
- // 说明当时设置的是永不过期
1250
- return false;
1251
- }
1248
+ const storedExpireAt = await readExpireTimestamp(lockKeyDir) || 0;
1252
1249
  if (storedExpireAt > now) {
1253
1250
  // 说明锁尚未过期
1254
1251
  return false;
@@ -1289,10 +1286,12 @@ async function _fileLock(key, fn, expireMs = 49000) {
1289
1286
  await timeLimit([fn()], expireMs)
1290
1287
  return true;
1291
1288
  } finally {
1292
- // 5. 执行完毕后,手动释放锁目录(也可选择保留到过期自动失效,但一般都建议主动释放)
1293
- try {
1294
- await fp.rm(lockKeyDir, { recursive: true, force: true });
1295
- } catch (_) {}
1289
+ if (Date.now() <= expireAt - 9) {
1290
+ // 5. 执行完毕后,手动释放锁目录(也可选择保留到过期自动失效,但一般都建议主动释放)
1291
+ try {
1292
+ await fp.rm(lockKeyDir, { recursive: true, force: true });
1293
+ } catch (_) {}
1294
+ }
1296
1295
  }
1297
1296
  }
1298
1297
 
@@ -1397,6 +1396,14 @@ function delTips(...keys) {
1397
1396
  }
1398
1397
  }
1399
1398
 
1399
+ function hasTips(key) {
1400
+ return setting.tips.hasOwnProperty(key);
1401
+ }
1402
+
1403
+ function tipKeys() {
1404
+ return Object.keys(setting.tips);
1405
+ }
1406
+
1400
1407
  function tipsOnRmCallback(key) {
1401
1408
  let callbacks = _tipsOnRm[key]
1402
1409
  delete _tipsOnRm[key]
@@ -2147,6 +2154,14 @@ function getValTips() {
2147
2154
  let items = [];
2148
2155
  for (let key of Object.keys(setting.tips)) {
2149
2156
  let val = setting.tips[key].map(i => {
2157
+ if (typeof i === 'function') {
2158
+ try {
2159
+ i = i();
2160
+ } catch (e) {
2161
+ console.$error(`tips "${key}"`, e);
2162
+ return '';
2163
+ }
2164
+ }
2150
2165
  let item = trim(i)
2151
2166
  if (item.indexOf(',') !== -1) {
2152
2167
  item = `[${item}]`;
@@ -2356,5 +2371,7 @@ module.exports = {
2356
2371
  fileExist,
2357
2372
  aop,
2358
2373
  aopAsync,
2359
- processLock
2374
+ processLock,
2375
+ hasTips,
2376
+ tipKeys
2360
2377
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsir",
3
- "version": "2.6.6",
3
+ "version": "2.6.7",
4
4
  "description": "JavaScript Script Management Tool",
5
5
  "main": "index.js",
6
6
  "scripts": {