Skip to content

Commit

Permalink
feat: configure vite
Browse files Browse the repository at this point in the history
  • Loading branch information
4e6 committed May 13, 2024
1 parent 014b991 commit d77d8a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 50 deletions.
4 changes: 0 additions & 4 deletions app/gui2/src/stores/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ function resolveLsUrl(config: GuiConfig): LsUrls {
if (engine.rpcUrl != null && engine.dataUrl != null) {
const dataUrl = engine.dataUrl
const rpcUrl = engine.rpcUrl
/*
let ydocUrl
if (engine.ydocUrl == null || engine.ydocUrl === '') {
ydocUrl = new URL(location.origin)
Expand All @@ -61,9 +60,6 @@ function resolveLsUrl(config: GuiConfig): LsUrls {
ydocUrl = new URL(engine.rpcUrl)
ydocUrl.port = '1234'
}
*/
const ydocUrl = new URL(engine.rpcUrl)
ydocUrl.port = '1234'
ydocUrl.pathname = '/project'

return {
Expand Down
47 changes: 4 additions & 43 deletions app/gui2/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import vue from '@vitejs/plugin-vue'
import { getDefines, readEnvironmentFromFile } from 'enso-common/src/appConfig'
import { spawn, type ChildProcessWithoutNullStreams } from 'node:child_process'
import { existsSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import postcssNesting from 'postcss-nesting'
import tailwindcss from 'tailwindcss'
Expand All @@ -16,9 +14,7 @@ const localServerPort = 8080
const projectManagerUrl = 'ws://127.0.0.1:30535'

const IS_CLOUD_BUILD = process.env.CLOUD_BUILD === 'true'
const IS_POLYGLOT_YDOC_SERVER_DEBUG = process.env.POLYGLOT_YDOC_SERVER_DEBUG === 'true'
const IS_POLYGLOT_YDOC_SERVER =
process.env.POLYGLOT_YDOC_SERVER === 'true' || IS_POLYGLOT_YDOC_SERVER_DEBUG
const IS_POLYGLOT_YDOC_SERVER = process.env.POLYGLOT_YDOC_SERVER === 'true'

await readEnvironmentFromFile()

Expand All @@ -32,7 +28,7 @@ export default defineConfig({
envDir: fileURLToPath(new URL('.', import.meta.url)),
plugins: [
vue(),
//gatewayServer(),
gatewayServer(),
...(process.env.ELECTRON_DEV_MODE === 'true' ?
[
(await import('@vitejs/plugin-react')).default({
Expand Down Expand Up @@ -99,48 +95,13 @@ export default defineConfig({
},
})

let ydocServer: ChildProcessWithoutNullStreams | null
function gatewayServer(): Plugin {
return {
name: 'gateway-server',
configureServer(server) {
if (server.httpServer == null) return
if (IS_POLYGLOT_YDOC_SERVER || server.httpServer == null) return

if (IS_POLYGLOT_YDOC_SERVER) {
const ydocServerJar = fileURLToPath(
new URL(
'../../lib/java/ydoc-server/target/ydoc-server-assembly-0.1.0-SNAPSHOT.jar',
import.meta.url,
),
)
const runYdocServer = () => {
const args = []
if (IS_POLYGLOT_YDOC_SERVER_DEBUG) {
args.push('-DinspectPort=34567')
}
args.push('-jar', ydocServerJar)
ydocServer = spawn('java', args)
if (IS_POLYGLOT_YDOC_SERVER_DEBUG) {
ydocServer.stdout.on('data', (data) => console.log(`ydoc: ${data}`))
}
ydocServer.stderr.on('data', (data) => console.log(`ydoc: ${data}`))
}
if (!existsSync(ydocServerJar)) {
const cwd = fileURLToPath(new URL('../..', import.meta.url))
const sbt = spawn('sbt', ['ydoc-server/assembly'], { cwd })
sbt.stdout.on('data', (data) => console.log(`sbt: ${data}`))
sbt.on('exit', runYdocServer)
} else {
runYdocServer()
}
} else {
createGatewayServer(server.httpServer, undefined)
}
},
buildEnd() {
if (ydocServer == null) return

ydocServer.kill('SIGTERM')
createGatewayServer(server.httpServer, undefined)
},
}
}
Expand Down
10 changes: 7 additions & 3 deletions lib/java/ydoc-server/src/main/java/org/enso/ydoc/Ydoc.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.enso.ydoc.polyfill.ParserPolyfill;
import org.enso.ydoc.polyfill.web.WebEnvironment;
import org.graalvm.polyglot.Context;
Expand Down Expand Up @@ -34,8 +35,10 @@ public Context.Builder getContextBuilder() {
public void start() throws ExecutionException, InterruptedException, IOException {
var ydoc = Main.class.getResource(YDOC_SERVER_PATH);
if (ydoc == null) {
throw new AssertionError(YDOC_SERVER_PATH + " not found in resources. You probably need to first built it with: "
+ "`npm --workspace=enso-gui2 run build-ydoc-server-polyglot`");
throw new AssertionError(
YDOC_SERVER_PATH
+ " not found in resources. You probably need to first built it with: "
+ "`npm --workspace=enso-gui2 run build-ydoc-server-polyglot`");
}
var ydocJs = Source.newBuilder("js", ydoc).mimeType("application/javascript+module").build();

Expand All @@ -56,9 +59,10 @@ public void start() throws ExecutionException, InterruptedException, IOException
@Override
public void close() throws Exception {
executor.shutdownNow();
executor.awaitTermination(3, TimeUnit.SECONDS);
parser.close();
if (context != null) {
context.close();
context.close(true);
}
}
}

0 comments on commit d77d8a5

Please sign in to comment.