jsir 3.0.6 → 3.0.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 +36 -14
- package/deps/room.js +22 -10
- package/deps/util.js +14 -3
- package/package.json +1 -1
package/cmd/oaa.js
CHANGED
|
@@ -192,7 +192,10 @@ function checkWorkspaces() {
|
|
|
192
192
|
continue
|
|
193
193
|
}
|
|
194
194
|
if (fs.existsSync(workspace)) {
|
|
195
|
-
|
|
195
|
+
let stat = fs.lstatSync(workspace)
|
|
196
|
+
if (stat.isDirectory()) {
|
|
197
|
+
setting.workspaceMap[space] = workspace;
|
|
198
|
+
}
|
|
196
199
|
}
|
|
197
200
|
}
|
|
198
201
|
arrayDataFile(_workspaceConfigFile, () => Object.values(setting.workspaceMap))
|
|
@@ -667,13 +670,21 @@ async function wrapperInput(str, packOutput = false) {
|
|
|
667
670
|
}
|
|
668
671
|
}
|
|
669
672
|
|
|
670
|
-
function wrapperAlias(
|
|
673
|
+
function wrapperAlias(items) {
|
|
671
674
|
let aliasMap = getConfig("alias");
|
|
672
675
|
if (!aliasMap || Object.keys(aliasMap).length <= 0) {
|
|
673
|
-
return
|
|
676
|
+
return items;
|
|
677
|
+
}
|
|
678
|
+
let result = []
|
|
679
|
+
for (let i = 0; i < items.length; i++) {
|
|
680
|
+
let item = items[i]
|
|
681
|
+
if (!item.endsWith(" ") && item.startsWith(".")) {
|
|
682
|
+
result.push(...enrichArgs(getAlias(aliasMap, item)))
|
|
683
|
+
} else {
|
|
684
|
+
result.push(item)
|
|
685
|
+
}
|
|
674
686
|
}
|
|
675
|
-
|
|
676
|
-
return [getAlias(aliasMap, fstr), str.substring(fstr.length)].map(trim).filter(i => i).join(' ')
|
|
687
|
+
return result;
|
|
677
688
|
}
|
|
678
689
|
|
|
679
690
|
async function _wrapperInput(str) {
|
|
@@ -683,7 +694,6 @@ async function _wrapperInput(str) {
|
|
|
683
694
|
return;
|
|
684
695
|
}
|
|
685
696
|
setting.newError = false;
|
|
686
|
-
str = wrapperAlias(str);
|
|
687
697
|
|
|
688
698
|
if (/^[`'"]/.test(str)) {
|
|
689
699
|
let fstr = str.substring(0, 1);
|
|
@@ -714,7 +724,7 @@ async function _wrapperInput(str) {
|
|
|
714
724
|
await evalText(text)
|
|
715
725
|
}
|
|
716
726
|
} else if (str.match(/^\./)) {
|
|
717
|
-
await dealKeyword(enrichArgs(str))
|
|
727
|
+
await dealKeyword(wrapperAlias(enrichArgs(str)))
|
|
718
728
|
} else if (!str.split(/\s+/)[0].match(/^\d+$/)) {
|
|
719
729
|
filterCmdAndList(str);
|
|
720
730
|
} else {
|
|
@@ -1535,6 +1545,13 @@ const keywordDef = {
|
|
|
1535
1545
|
let workspaces = Object.values(setting.workspaceMap)
|
|
1536
1546
|
workspaces.push(newWorkspace)
|
|
1537
1547
|
arrayDataFile(_workspaceConfigFile, () => workspaces)
|
|
1548
|
+
} else if (newWorkspace.startsWith("+")) {
|
|
1549
|
+
let name = newWorkspace.replace(/^\+\s*/, '');
|
|
1550
|
+
let path = setting.workspaceMap[name]
|
|
1551
|
+
if (path && name !== setting.defaultSpace) {
|
|
1552
|
+
let target = setting.workspaceMap[setting.defaultSpace] + '/' + name
|
|
1553
|
+
recreateSymlink(path, target)
|
|
1554
|
+
}
|
|
1538
1555
|
} else {
|
|
1539
1556
|
console.warn('invalid args')
|
|
1540
1557
|
}
|
|
@@ -1610,7 +1627,7 @@ const keywordDef = {
|
|
|
1610
1627
|
}
|
|
1611
1628
|
}
|
|
1612
1629
|
} else {
|
|
1613
|
-
console.warn(`require "${keyword}" not unique`)
|
|
1630
|
+
console.warn(`require "${keyword}" not exist&unique`)
|
|
1614
1631
|
}
|
|
1615
1632
|
},
|
|
1616
1633
|
args: {
|
|
@@ -1755,10 +1772,6 @@ const keywordDef = {
|
|
|
1755
1772
|
if (setting.selfRoom.selfNode === room.selfNode && String(process.pid) === pid) {
|
|
1756
1773
|
continue;
|
|
1757
1774
|
}
|
|
1758
|
-
if (setting.selfRoom.selfNode !== room.selfNode && targets.includes(room.selfNode) && !targets.includes(pid)
|
|
1759
|
-
&& room.jsirs[pid].port === setting.defaultPort) {
|
|
1760
|
-
continue;
|
|
1761
|
-
}
|
|
1762
1775
|
tasks.push(async (input) => {
|
|
1763
1776
|
let pidKey = `[${room.name} ${pid}]`
|
|
1764
1777
|
if (taskPids.includes(pid)) {
|
|
@@ -2027,6 +2040,15 @@ function initWorkspace(space) {
|
|
|
2027
2040
|
setting.defaultSpace = workspace;
|
|
2028
2041
|
}
|
|
2029
2042
|
|
|
2043
|
+
function recreateSymlink(src, dest) {
|
|
2044
|
+
// 如果存在则删除(无论是文件还是软链)
|
|
2045
|
+
if (fs.existsSync(dest)) {
|
|
2046
|
+
fs.unlinkSync(dest);
|
|
2047
|
+
}
|
|
2048
|
+
// 重新创建软链
|
|
2049
|
+
fs.symlinkSync(src, dest, 'dir'); // dir/file 根据实际类型
|
|
2050
|
+
}
|
|
2051
|
+
|
|
2030
2052
|
function filterCmdAndList(arg) {
|
|
2031
2053
|
arg = trim(arg) || lastFilterArg;
|
|
2032
2054
|
if (arg) {
|
|
@@ -2399,7 +2421,7 @@ function filterRequire(currSpace, cmdMatchStr) {
|
|
|
2399
2421
|
}
|
|
2400
2422
|
}
|
|
2401
2423
|
if (cmds.length !== 1) {
|
|
2402
|
-
throw `require "${cmdMatchStr}" not unique`
|
|
2424
|
+
throw `require "${cmdMatchStr}" not exist&unique`
|
|
2403
2425
|
}
|
|
2404
2426
|
return cmds[0];
|
|
2405
2427
|
}
|
|
@@ -2431,7 +2453,7 @@ async function _requireSource(currSpace, cmdMatchStr, force = false, $args) {
|
|
|
2431
2453
|
throw `service function ${serviceKey}/${prop} not found`;
|
|
2432
2454
|
}
|
|
2433
2455
|
return async (...args) => {
|
|
2434
|
-
return await Room.reqFn(`${serviceKey}/${prop}`, args);
|
|
2456
|
+
return await Room.reqFn(`${serviceKey}/${prop}`, args, $args);
|
|
2435
2457
|
}
|
|
2436
2458
|
}
|
|
2437
2459
|
})
|
package/deps/room.js
CHANGED
|
@@ -44,11 +44,11 @@ function onRoom() {
|
|
|
44
44
|
res.output = warnStr("Disable Remote")
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
|
+
if (!isRunningInBackground()) {
|
|
48
|
+
res.output = warnStr("Disable Remote")
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
47
51
|
if (vl(req.input)) {
|
|
48
|
-
if (!isRunningInBackground() && ['.nsir', '.N'].indexOf(req.input.trim()) === -1) {
|
|
49
|
-
res.output = warnStr("Disable Remote")
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
52
|
res.output = await setting.wrapperInput(req.input, true)
|
|
53
53
|
setting.promptId = Date.now()
|
|
54
54
|
}
|
|
@@ -112,15 +112,17 @@ async function initNodes() {
|
|
|
112
112
|
} catch (e) {
|
|
113
113
|
console.$debug("initNodes", e)
|
|
114
114
|
}
|
|
115
|
+
let isFirst = true
|
|
115
116
|
for (let line of resp.split("\n").map(trim)) {
|
|
116
|
-
let offline = line.indexOf('offline') !== -1
|
|
117
117
|
let ss = line.split(/\s+/);
|
|
118
118
|
if (/^\d+\.\d+\.\d+\.\d+$/.test(ss[0])) {
|
|
119
|
+
let offline = line.indexOf('offline') !== -1 || line.indexOf('active') === -1
|
|
119
120
|
nodes[ss[0]] = {
|
|
120
121
|
name: ss[1],
|
|
121
|
-
offline,
|
|
122
|
+
offline: !isFirst && offline,
|
|
122
123
|
account: ss[2]
|
|
123
124
|
}
|
|
125
|
+
isFirst = false
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
}
|
|
@@ -581,14 +583,24 @@ function busyPick(busyItems) {
|
|
|
581
583
|
}
|
|
582
584
|
}
|
|
583
585
|
|
|
584
|
-
|
|
586
|
+
function isMatchTarget(target, node, port) {
|
|
587
|
+
if (!target) {
|
|
588
|
+
return true;
|
|
589
|
+
}
|
|
590
|
+
target = String(target).trim()
|
|
591
|
+
if (target.includes(":")) {
|
|
592
|
+
return target === `${node}:${port}`
|
|
593
|
+
} else {
|
|
594
|
+
return target === node;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
async function reqFn(fnKey, args = [], reqTarget) {
|
|
585
599
|
let targets = setting.serviceFns[fnKey]
|
|
586
600
|
if (!targets) {
|
|
587
601
|
throw `service function ${fnKey} instance not found`;
|
|
588
602
|
}
|
|
589
|
-
targets = targets
|
|
590
|
-
.filter(i => i.active)
|
|
591
|
-
.filter(i => !isDisableConnect(i.node, i.port));
|
|
603
|
+
targets = targets.filter(i => isMatchTarget(reqTarget, i.node, i.port) && i.active && !isDisableConnect(i.node, i.port));
|
|
592
604
|
let target = null;
|
|
593
605
|
if (targets.length > 0) {
|
|
594
606
|
target = busyPick(targets);
|
package/deps/util.js
CHANGED
|
@@ -333,6 +333,10 @@ function createConsole(uniqueName, _logToFile, _errorToFile) {
|
|
|
333
333
|
}
|
|
334
334
|
setting.lastChangeFlag = flag
|
|
335
335
|
}
|
|
336
|
+
if (!is$ && uniqueName && quite && hasFlag) {
|
|
337
|
+
// ignore
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
336
340
|
if (is$ || (uniqueName && quite) || (setting.lastOutput && !hasFlag && 'debug' === key)) {
|
|
337
341
|
if ((key === 'table' || key === 'nable') && typeof args[0] === "object") {
|
|
338
342
|
args = ['', ...args]
|
|
@@ -2066,11 +2070,17 @@ function getTextComments(text) {
|
|
|
2066
2070
|
function wrapperJsirText(text) {
|
|
2067
2071
|
return text
|
|
2068
2072
|
.replace(/^require\s*\(\s*(["'`][ei][^a-zA-Z]+)/mg, 'await $require($1')
|
|
2069
|
-
// .replace(/([\s=;]require\s*\(\s*["'`])\.\/([ei][^a-zA-Z]+)/g, '$1$2')
|
|
2070
2073
|
.replace(/([\s=;])require\s*\(\s*(["'`][ei][^a-zA-Z]+)/g, '$1await $require($2')
|
|
2074
|
+
|
|
2075
|
+
.replace(/^require\s*\(\s*(["'`][^/.]+\/[ei][^a-zA-Z]+)/mg, 'await $require($1')
|
|
2076
|
+
.replace(/([\s=;])require\s*\(\s*(["'`][^/.]+\/[ei][^a-zA-Z]+)/g, '$1await $require($2')
|
|
2077
|
+
|
|
2078
|
+
.replace(/^require\s*\(\s*(["'`])\.\//mg, 'await $require($1')
|
|
2071
2079
|
.replace(/([\s=;])require\s*\(\s*(["'`])\.\//g, '$1await $require($2')
|
|
2072
|
-
|
|
2080
|
+
|
|
2073
2081
|
.replace(/^import\s*\(/mg, '$import(')
|
|
2082
|
+
.replace(/([\s=;])import\s*\(/g, '$1$import(')
|
|
2083
|
+
|
|
2074
2084
|
.replace(/^module\.exports\s*=\s*/m, 'return ')
|
|
2075
2085
|
;
|
|
2076
2086
|
}
|
|
@@ -2375,5 +2385,6 @@ module.exports = {
|
|
|
2375
2385
|
currentJsir,
|
|
2376
2386
|
currentRoom,
|
|
2377
2387
|
currentRooms,
|
|
2378
|
-
uid
|
|
2388
|
+
uid,
|
|
2389
|
+
consoleStrs
|
|
2379
2390
|
}
|