Skip to content

Commit

Permalink
update: configure webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
4e6 committed Mar 25, 2024
1 parent cdf45ff commit d31f221
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
3 changes: 2 additions & 1 deletion app/gui2/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = {
entry: './ydoc-server/server.ts',
output: {
filename: 'ydoc-server-bundle.js',
path: path.resolve(__dirname, '../../target')
path: path.resolve(__dirname, '../../lib/java/js-websocket/target/classes'),
publicPath: ''
},
resolve: {
extensions: [".ts", ".js"]
Expand Down
2 changes: 1 addition & 1 deletion app/gui2/ydoc-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { setupGatewayClient } from './ydoc'

const wss = new WebSocketServer({ host: 'localhost', port: 1234 })

wss.onconnect = (socket, url) => setupGatewayClient(socket, "language-server-url", url)
wss.onconnect = (socket, url) => setupGatewayClient(socket, "ws://localhost:8080", url)

wss.start()
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,9 @@ lazy val `js-websocket` = project
.enablePlugins(JPMSPlugin)
.configs(Test)
.settings(
crossPaths := false,
autoScalaLibrary := false,
run / fork := true,
modulePath := {
JPMSUtils.filterModulesFromUpdate(
update.value,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.enso.polyfill;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

public final class ClasspathResource {

private static final String FILE_NAME_SEPARATOR = "-";

private ClasspathResource() {}

public static URI createTempFile(String name) throws IOException {
var tempFileName = Path.of(name).getFileName().toString();
var target = Files.createTempFile(null, FILE_NAME_SEPARATOR + tempFileName);
target.toFile().deleteOnExit();

try (InputStream in = ClasspathResource.class.getResourceAsStream(name)) {
Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
}

return target.toUri();
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
package org.enso.polyfill.websocket;
package org.enso.polyfill;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executors;

import org.enso.polyfill.websocket.WebSocketPolyfill;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.HostAccess;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.io.IOAccess;

public class Main {

private static final String DEMO_PATH = "/all-y-websocket.js";
private static final String YDOC_SERVER_PATH = "/ydoc-server-bundle.js";
private static final String WASM_PATH = "/153299079965dcf860b5.wasm";

private Main() {
}

public static void main(String[] args) throws Exception {
var demo = Main.class.getResource(DEMO_PATH);
ClasspathResource.createTempFile(WASM_PATH);
var demo = ClasspathResource.createTempFile(YDOC_SERVER_PATH);
if (demo == null) {
throw new IOException("Cannot find " + DEMO_PATH);
throw new IOException("Cannot find " + YDOC_SERVER_PATH);
}
var commonJsRoot = new File(demo.toURI()).getParent();
var commonJsRoot = new File(demo).getParent();

HostAccess hostAccess = HostAccess.newBuilder(HostAccess.EXPLICIT)
.allowArrayAccess(true)
Expand All @@ -41,7 +46,7 @@ public static void main(String[] args) throws Exception {

try (var executor = Executors.newSingleThreadExecutor()) {
var webSocketPolyfill = new WebSocketPolyfill(executor);
var demoJs = Source.newBuilder("js", demo)
var demoJs = Source.newBuilder("js", demo.toURL())
.mimeType("application/javascript+module")
.build();

Expand All @@ -57,5 +62,4 @@ public static void main(String[] args) throws Exception {
System.in.read();
}
}

}

0 comments on commit d31f221

Please sign in to comment.