Skip to content

Commit e45b9b4

Browse files
committed
ES Modules now load correctly
1 parent 419224d commit e45b9b4

1 file changed

Lines changed: 5 additions & 14 deletions

File tree

src/main/java/com/roguecircuitry/repcraft/RepCraft.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.File;
44
import java.io.FileFilter;
55
import java.io.FileReader;
6-
import java.nio.file.Files;
76
import java.nio.file.Paths;
87

98
import com.google.gson.JsonObject;
@@ -14,6 +13,7 @@
1413

1514
import org.graalvm.polyglot.Context;
1615
import org.graalvm.polyglot.Value;
16+
import org.graalvm.polyglot.Source;
1717

1818
/**
1919
* Hello world!
@@ -80,29 +80,21 @@ public boolean accept(File f) {
8080
if (!pkgJson.has("main")) continue;
8181

8282
pkgJsonMain = pkgJson.get("main").getAsString();
83-
83+
8484
jsPluginFile = new File(pluginSubDir.getAbsoluteFile() + "/" + pkgJsonMain);
8585
if (!jsPluginFile.exists()) {
8686
System.err.println("Couldn't import 'main' : " + jsPluginFile.toPath() + ", ignoring!");
8787
continue;
8888
}
89-
9089
try {
91-
this.ctx.eval("js", new String(Files.readAllBytes(jsPluginFile.toPath())));
90+
Source src = Source.newBuilder("js", jsPluginFile).build();
91+
this.ctx.eval(src);
9292
} catch (Exception e) {
93-
//Technically we already handled this, just skip this script
93+
//Just skip this script
9494
e.printStackTrace();
9595
continue;
9696
}
9797
}
98-
99-
try {
100-
this.ctx.eval("js", "print('[js] Hello World');");
101-
} catch (Exception ex) {
102-
System.err.println(ex);
103-
return;
104-
}
105-
10698
jsc = new JSCommand(this);
10799

108100
this.getCommand("js").setExecutor(this.jsc);
@@ -118,6 +110,5 @@ public void put(String key, Object value) {
118110

119111
@Override
120112
public void onDisable() {
121-
122113
}
123114
}

0 commit comments

Comments
 (0)