jsir 2.6.9 → 2.6.11
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 +82 -25
- package/deps/room.js +3 -1
- package/deps/util.js +11 -1
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -13,7 +13,7 @@ const {
|
|
|
13
13
|
getFullPath, parseUniqueName, toUniqueName, isJsirFileName, toJsirFileName,
|
|
14
14
|
getAlias, wrapperJsirText, eia, getKeyTips, getValTips, getJsirTypeKey,
|
|
15
15
|
createDetachedProcess, interceptStdStreams,
|
|
16
|
-
draftModify, isRunningInBackground, fileJson, fileLock, processLock
|
|
16
|
+
draftModify, isRunningInBackground, fileJson, fileLock, processLock, cleanFileLocks, getMd5Key
|
|
17
17
|
} = $lib;
|
|
18
18
|
const _args = process.argv.slice(2).map(trim);
|
|
19
19
|
const evalCode = require('../deps/evalCode')
|
|
@@ -184,6 +184,8 @@ function checkWorkspaces() {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
async function start() {
|
|
187
|
+
cleanFileLocks();
|
|
188
|
+
|
|
187
189
|
setting.wrapperInput = wrapperInput;
|
|
188
190
|
interceptStdStreams()
|
|
189
191
|
checkWorkspaces()
|
|
@@ -825,17 +827,28 @@ function dealStarGlobal(items, text) {
|
|
|
825
827
|
}
|
|
826
828
|
|
|
827
829
|
function wrapperClassLine(className, classLines) {
|
|
828
|
-
let
|
|
830
|
+
let firstNoEmptyLine = classLines.find(i => i.trim()) || '';
|
|
831
|
+
if (!firstNoEmptyLine || firstNoEmptyLine.startsWith(firstNoEmptyLine.trim().substring(0, 1))) {
|
|
832
|
+
return classLines;
|
|
833
|
+
}
|
|
834
|
+
let spaceLen = firstNoEmptyLine.indexOf(firstNoEmptyLine.trim());
|
|
835
|
+
classLines = classLines.map(i => {
|
|
836
|
+
let prefix = i.substring(0, spaceLen);
|
|
837
|
+
if (prefix.trim()) {
|
|
838
|
+
return ''
|
|
839
|
+
} else {
|
|
840
|
+
return i.substring(spaceLen);
|
|
841
|
+
}
|
|
842
|
+
});
|
|
829
843
|
let results = []
|
|
830
|
-
for (let line of
|
|
844
|
+
for (let line of classLines) {
|
|
831
845
|
let asyncMethod = false;
|
|
832
846
|
if (line.startsWith("async ")) {
|
|
833
847
|
// 检查是否为异步方法
|
|
834
848
|
asyncMethod = true;
|
|
835
849
|
line = line.replace("async ", "").trim(); // 去除 'async ' 前缀
|
|
836
850
|
}
|
|
837
|
-
|
|
838
|
-
if (methodMatch) {
|
|
851
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/.test(line)) {
|
|
839
852
|
let prefix = `function ${className}.`;
|
|
840
853
|
if (asyncMethod) {
|
|
841
854
|
prefix = "async " + prefix;
|
|
@@ -848,7 +861,7 @@ function wrapperClassLine(className, classLines) {
|
|
|
848
861
|
return results;
|
|
849
862
|
}
|
|
850
863
|
|
|
851
|
-
function wrapperClass(lines) {
|
|
864
|
+
function wrapperClass(lines, wrapperFn, trimClass = true) {
|
|
852
865
|
let results = [];
|
|
853
866
|
let className = null;
|
|
854
867
|
let inClass = false;
|
|
@@ -856,12 +869,19 @@ function wrapperClass(lines) {
|
|
|
856
869
|
let classLines = []
|
|
857
870
|
for (let line of lines) {
|
|
858
871
|
if (line.startsWith("class ")) {
|
|
872
|
+
if (!trimClass) {
|
|
873
|
+
results.push(line);
|
|
874
|
+
}
|
|
859
875
|
inClass = true;
|
|
860
|
-
className = reget(line, /^class\s+(
|
|
876
|
+
className = reget(line, /^class\s+([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
861
877
|
continue
|
|
862
878
|
} else if (inClass && line.startsWith("}")) {
|
|
863
879
|
inClass = false
|
|
864
|
-
results.push(...
|
|
880
|
+
results.push(...wrapperFn(className, classLines));
|
|
881
|
+
|
|
882
|
+
if (!trimClass) {
|
|
883
|
+
results.push(line);
|
|
884
|
+
}
|
|
865
885
|
classLines = []
|
|
866
886
|
continue;
|
|
867
887
|
}
|
|
@@ -877,7 +897,7 @@ function wrapperClass(lines) {
|
|
|
877
897
|
|
|
878
898
|
function dealStarCmd(rows, cmd, filterStr) {
|
|
879
899
|
let content = String(fs.readFileSync(getFullPath(cmd)));
|
|
880
|
-
let lines = wrapperClass(content.split('\n'));
|
|
900
|
+
let lines = wrapperClass(content.split('\n'), wrapperClassLine);
|
|
881
901
|
let capturingFunction = false;
|
|
882
902
|
let inMultiLineComment = false;
|
|
883
903
|
let potentialComments = [];
|
|
@@ -916,7 +936,7 @@ function dealStarCmd(rows, cmd, filterStr) {
|
|
|
916
936
|
|
|
917
937
|
// Check for function start
|
|
918
938
|
if ((line.startsWith('function ') || line.startsWith('async function '))) {
|
|
919
|
-
let _fnName = reget(line, /function\s+(
|
|
939
|
+
let _fnName = reget(line, /function\s+(\S+)\s*\(/);
|
|
920
940
|
let matchKey = _fnName + "(" + getFnArgsStr(lines.slice(index, index + 9).join("\n")) + ")"
|
|
921
941
|
if (isMatch(matchKey, filterStr)) {
|
|
922
942
|
fnName = _fnName;
|
|
@@ -939,7 +959,7 @@ function dealStarCmd(rows, cmd, filterStr) {
|
|
|
939
959
|
let row = getInfo(functionContent, fnName, fnType);
|
|
940
960
|
let pair = parseUniqueName(cmd);
|
|
941
961
|
row.value = [
|
|
942
|
-
infoStr(pair[0] + '/' + trimJsirFileName(pair[1])) + ' ' +
|
|
962
|
+
infoStr(pair[0] + '/' + trimJsirFileName(pair[1])) + ' ' + getMd5Key(parseUniqueName(cmd)[1]),
|
|
943
963
|
[commentContent, row.value].filter(i => trim(i)).join("\n")
|
|
944
964
|
].filter(i => trim(i)).join("\n");
|
|
945
965
|
rows.push(row);
|
|
@@ -1859,7 +1879,7 @@ function getScriptRequires(uniqueName) {
|
|
|
1859
1879
|
}
|
|
1860
1880
|
|
|
1861
1881
|
function getComments(i, cmdName, text, cols = [], col) {
|
|
1862
|
-
let docLines = [
|
|
1882
|
+
let docLines = [getMd5Key(parseUniqueName(cmdName)[1]) + " - " + i]
|
|
1863
1883
|
text = trim(text)
|
|
1864
1884
|
docLines.push(...getTextComments(text))
|
|
1865
1885
|
let argDef = getArgDef(text, cmdName)
|
|
@@ -2257,14 +2277,6 @@ function getArgDef(text, uniqueName) {
|
|
|
2257
2277
|
return Object.assign(temp, tempOpt)
|
|
2258
2278
|
}
|
|
2259
2279
|
|
|
2260
|
-
function getCmdMd5Key(str) {
|
|
2261
|
-
return '0x' + md5(str).substr(0, 8);
|
|
2262
|
-
}
|
|
2263
|
-
|
|
2264
|
-
function isMd5Key(str) {
|
|
2265
|
-
return /^0x[a-z\d]{8}$/.test(str);
|
|
2266
|
-
}
|
|
2267
|
-
|
|
2268
2280
|
function filterRequire(currSpace, cmdMatchStr) {
|
|
2269
2281
|
if (typeof cmdMatchStr === 'number') {
|
|
2270
2282
|
cmdMatchStr = '0x' + pad(8, BigNumber(cmdMatchStr).toString(16), '0');
|
|
@@ -2335,17 +2347,60 @@ async function _requireSource(currSpace, cmdMatchStr, force = false) {
|
|
|
2335
2347
|
return result
|
|
2336
2348
|
}
|
|
2337
2349
|
|
|
2350
|
+
function _wrapperClassErrorTag(className, lines) {
|
|
2351
|
+
let firstNoEmptyLine = lines.find(i => i.trim()) || '';
|
|
2352
|
+
if (!firstNoEmptyLine || firstNoEmptyLine.startsWith(firstNoEmptyLine.trim().substring(0, 1))) {
|
|
2353
|
+
return lines;
|
|
2354
|
+
}
|
|
2355
|
+
let spaceLen = firstNoEmptyLine.indexOf(firstNoEmptyLine.trim());
|
|
2356
|
+
let prefixMap = {}
|
|
2357
|
+
let ignoreMap = {}
|
|
2358
|
+
lines = lines.map((i, index) => {
|
|
2359
|
+
let prefix = i.substring(0, spaceLen);
|
|
2360
|
+
if (prefix.trim()) {
|
|
2361
|
+
ignoreMap[index] = i;
|
|
2362
|
+
i = ''
|
|
2363
|
+
return i;
|
|
2364
|
+
} else {
|
|
2365
|
+
prefixMap[index] = prefix;
|
|
2366
|
+
i = i.substring(spaceLen);
|
|
2367
|
+
}
|
|
2368
|
+
if (/^[a-zA-Z_$][a-zA-Z0-9_$]*\s*\(/.test(i)) {
|
|
2369
|
+
i = `function ${className}.` + i;
|
|
2370
|
+
} else if (i.startsWith('async ')) {
|
|
2371
|
+
i = `async function ${className}.` + i.replace(/^async /, '');
|
|
2372
|
+
}
|
|
2373
|
+
return i;
|
|
2374
|
+
})
|
|
2375
|
+
lines = _addErrorTag(lines);
|
|
2376
|
+
return lines.map((i, index) => {
|
|
2377
|
+
if (i.startsWith('function ')) {
|
|
2378
|
+
i = i.replace(/^function [^.]+\./, '');
|
|
2379
|
+
} else if (i.startsWith('async function ')) {
|
|
2380
|
+
i = 'async ' + i.replace(/^async function [^.]+\./, '');
|
|
2381
|
+
}
|
|
2382
|
+
return (ignoreMap[index] || prefixMap[index]) + i;
|
|
2383
|
+
})
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2338
2386
|
function addErrorTag(text) {
|
|
2339
|
-
let result = [];
|
|
2340
2387
|
let lines = text.split(/\n/);
|
|
2388
|
+
lines = wrapperClass(lines, _wrapperClassErrorTag, false)
|
|
2389
|
+
let result= _addErrorTag(lines);
|
|
2390
|
+
return result.join('\n');
|
|
2391
|
+
}
|
|
2392
|
+
|
|
2393
|
+
function _addErrorTag(lines) {
|
|
2394
|
+
let result = [];
|
|
2341
2395
|
let functionEnd = true;
|
|
2342
2396
|
let fnName = '';
|
|
2397
|
+
let fnIsAsync = false;
|
|
2343
2398
|
let wrapperFn = [];
|
|
2344
2399
|
for (let i = 0; i < lines.length; i++) {
|
|
2345
2400
|
let line = lines[i];
|
|
2346
2401
|
if (line.startsWith("@")) {
|
|
2347
2402
|
wrapperFn.push(line.substring(1).trim())
|
|
2348
|
-
result.push(
|
|
2403
|
+
result.push('');
|
|
2349
2404
|
} else {
|
|
2350
2405
|
result.push(line);
|
|
2351
2406
|
}
|
|
@@ -2353,15 +2408,16 @@ function addErrorTag(text) {
|
|
|
2353
2408
|
let isSyncFn = line.startsWith('function');
|
|
2354
2409
|
if (isAsyncFn || isSyncFn) {
|
|
2355
2410
|
fnName = reget(line, /function\s+([\s\S]+)\s*\(/)
|
|
2411
|
+
fnIsAsync = isAsyncFn;
|
|
2356
2412
|
}
|
|
2357
2413
|
if (functionEnd && fnName && (/\)\s*\{$/.test(trim(line)) || (line.startsWith("{") && trim(line) === '{'))) {
|
|
2358
2414
|
result[i] += 'try{';
|
|
2359
2415
|
if (wrapperFn.length > 0) {
|
|
2360
2416
|
let defaultArgsList = '("'+ fnName +'")';
|
|
2361
2417
|
let runner = `([${wrapperFn.map(i => 'new ' + i + (i.endsWith(")") ? '':defaultArgsList)).join(",")}],`
|
|
2362
|
-
if (
|
|
2418
|
+
if (fnIsAsync) {
|
|
2363
2419
|
result[i] += `return await $aopAsync${runner}async ()=>{`;
|
|
2364
|
-
} else
|
|
2420
|
+
} else {
|
|
2365
2421
|
result[i] += `return $aop${runner}()=>{`;
|
|
2366
2422
|
}
|
|
2367
2423
|
}
|
|
@@ -2371,10 +2427,11 @@ function addErrorTag(text) {
|
|
|
2371
2427
|
result[i] = `${wrapperFn.length > 0 ? '},arguments)':''}}catch(e){throw($errorTag(e,$cmdName+'[${fnName}]'))}` + line;
|
|
2372
2428
|
functionEnd = true;
|
|
2373
2429
|
fnName = '';
|
|
2430
|
+
fnIsAsync = false;
|
|
2374
2431
|
wrapperFn = []
|
|
2375
2432
|
}
|
|
2376
2433
|
}
|
|
2377
|
-
return result
|
|
2434
|
+
return result;
|
|
2378
2435
|
}
|
|
2379
2436
|
|
|
2380
2437
|
async function evalText($text = '', $cmdName = '', $args = {}) {
|
package/deps/room.js
CHANGED
|
@@ -307,6 +307,9 @@ async function processTasks() {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
async function initRoom() {
|
|
310
|
+
if (process.pid === setting.defaultPort) {
|
|
311
|
+
cleanFileLocks();
|
|
312
|
+
}
|
|
310
313
|
setting.roomTime = Date.now();
|
|
311
314
|
setting.nodeMap = await fileJson(jsirNodesFile);
|
|
312
315
|
let roomUpdateTouchTime = false;
|
|
@@ -320,7 +323,6 @@ async function initRoom() {
|
|
|
320
323
|
if (roomUpdateTouchTime) {
|
|
321
324
|
fileLock(updateRoomInfoLockKey, async () => {
|
|
322
325
|
let pros = []
|
|
323
|
-
pros.push(cleanFileLocks())
|
|
324
326
|
pros.push(syncRooms())
|
|
325
327
|
if (setting.serviceFns[setting.configMainFnKey] && !getConfig("configMain")) {
|
|
326
328
|
pros.push(syncConfigs())
|
package/deps/util.js
CHANGED
|
@@ -2259,6 +2259,14 @@ async function aopAsync(items, fn, args) {
|
|
|
2259
2259
|
return await runners[i](args)
|
|
2260
2260
|
}
|
|
2261
2261
|
|
|
2262
|
+
function getMd5Key(str) {
|
|
2263
|
+
return '0x' + md5(str).substr(0, 8);
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
function isMd5Key(str) {
|
|
2267
|
+
return /^0x[a-z\d]{8}$/.test(str);
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2262
2270
|
module.exports = {
|
|
2263
2271
|
formatUptime,
|
|
2264
2272
|
wrapperJsirText,
|
|
@@ -2377,5 +2385,7 @@ module.exports = {
|
|
|
2377
2385
|
hasTips,
|
|
2378
2386
|
tipKeys,
|
|
2379
2387
|
isPidAlive,
|
|
2380
|
-
cleanFileLocks
|
|
2388
|
+
cleanFileLocks,
|
|
2389
|
+
getMd5Key,
|
|
2390
|
+
isMd5Key
|
|
2381
2391
|
}
|