fix(js): 修复模块被导入时副作用代码被重复执行 (#3070)

This commit is contained in:
Bread Grocery
2026-04-24 10:32:14 +08:00
committed by GitHub
parent 83637172fd
commit e06b105365
2 changed files with 4 additions and 2 deletions

View File

@@ -32,7 +32,8 @@ namespace BetterGenshinImpact.Core.Script
{
string content = await File.ReadAllTextAsync(targetPath);
string processedCode = RewriteScriptCode(content, targetPath);
return new StringDocument(new DocumentInfo(targetPath) { Category = ModuleCategory.Standard }, processedCode);
var documentInfo = new DocumentInfo(new Uri(targetPath)) { Category = ModuleCategory.Standard };
return new StringDocument(documentInfo, processedCode);
}
return await Default.LoadDocumentAsync(settings, sourceInfo, specifier, category, contextCallback);

View File

@@ -122,7 +122,8 @@ public class ScriptProject
string mainScriptPath = Path.Combine(ProjectPath, Manifest.Main);
string runtimeCode = loader.RewriteScriptCode(code, mainScriptPath);
var evaluation = engine.Evaluate(new DocumentInfo(mainScriptPath) { Category = ModuleCategory.Standard }, runtimeCode);
var documentInfo = new DocumentInfo(new Uri(mainScriptPath)) { Category = ModuleCategory.Standard };
var evaluation = engine.Evaluate(documentInfo, runtimeCode);
if (evaluation is Task task) await task;
}
else