feat: 脚本操作传入上下文 require (仅对应的环境支持)"

This commit is contained in:
xream
2024-08-29 13:34:08 +08:00
committed by xream
6 changed files with 50 additions and 6 deletions

View File

@@ -182,7 +182,6 @@ ecn = comma "ecn" equals flag:bool { proxy.ecn = flag; }
download_bandwidth = comma "download-bandwidth" equals match:[^,]+ { proxy.down = match.join(""); }
salamander_password = comma "salamander-password" equals match:[^,]+ { proxy['obfs-password'] = match.join(""); proxy.obfs = 'salamander'; }
tag = match:[^=,]* { proxy.name = match.join("").trim(); }
comma = _ "," _
equals = _ "=" _

View File

@@ -987,6 +987,7 @@ function createDynamicFunction(name, script, $arguments) {
'scriptResourceCache',
'flowUtils',
'produceArtifact',
'require',
`${script}\n return ${name}`,
)(
$arguments,
@@ -1002,6 +1003,7 @@ function createDynamicFunction(name, script, $arguments) {
scriptResourceCache,
flowUtils,
produceArtifact,
eval(`typeof require !== "undefined"`) ? require : undefined,
);
} else {
return new Function(
@@ -1012,7 +1014,7 @@ function createDynamicFunction(name, script, $arguments) {
'scriptResourceCache',
'flowUtils',
'produceArtifact',
'require',
`${script}\n return ${name}`,
)(
$arguments,
@@ -1022,6 +1024,7 @@ function createDynamicFunction(name, script, $arguments) {
scriptResourceCache,
flowUtils,
produceArtifact,
eval(`typeof require !== "undefined"`) ? require : undefined,
);
}
}