fix wasm url prod (#2145)
Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
@ -21,6 +21,7 @@ import {
|
|||||||
CopilotWorkerOptions,
|
CopilotWorkerOptions,
|
||||||
LspWorker,
|
LspWorker,
|
||||||
} from 'editor/plugins/lsp/types'
|
} from 'editor/plugins/lsp/types'
|
||||||
|
import { wasmUrl } from 'lang/wasm'
|
||||||
|
|
||||||
const DEFAULT_FILE_NAME: string = 'main.kcl'
|
const DEFAULT_FILE_NAME: string = 'main.kcl'
|
||||||
|
|
||||||
@ -99,6 +100,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
|
|
||||||
const lspWorker = new Worker({ name: 'kcl' })
|
const lspWorker = new Worker({ name: 'kcl' })
|
||||||
const initEvent: KclWorkerOptions = {
|
const initEvent: KclWorkerOptions = {
|
||||||
|
wasmUrl: wasmUrl(),
|
||||||
token: token,
|
token: token,
|
||||||
baseUnit: defaultUnit.current,
|
baseUnit: defaultUnit.current,
|
||||||
devMode: DEV,
|
devMode: DEV,
|
||||||
@ -173,6 +175,7 @@ export const LspProvider = ({ children }: { children: React.ReactNode }) => {
|
|||||||
|
|
||||||
const lspWorker = new Worker({ name: 'copilot' })
|
const lspWorker = new Worker({ name: 'copilot' })
|
||||||
const initEvent: CopilotWorkerOptions = {
|
const initEvent: CopilotWorkerOptions = {
|
||||||
|
wasmUrl: wasmUrl(),
|
||||||
token: token,
|
token: token,
|
||||||
devMode: DEV,
|
devMode: DEV,
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,14 @@ export enum LspWorker {
|
|||||||
Copilot = 'copilot',
|
Copilot = 'copilot',
|
||||||
}
|
}
|
||||||
export interface KclWorkerOptions {
|
export interface KclWorkerOptions {
|
||||||
|
wasmUrl: string
|
||||||
token: string
|
token: string
|
||||||
baseUnit: UnitLength
|
baseUnit: UnitLength
|
||||||
devMode: boolean
|
devMode: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CopilotWorkerOptions {
|
export interface CopilotWorkerOptions {
|
||||||
|
wasmUrl: string
|
||||||
token: string
|
token: string
|
||||||
devMode: boolean
|
devMode: boolean
|
||||||
}
|
}
|
||||||
|
@ -18,29 +18,9 @@ import { EngineCommandManager } from 'lang/std/engineConnection'
|
|||||||
const intoServer: IntoServer = new IntoServer()
|
const intoServer: IntoServer = new IntoServer()
|
||||||
const fromServer: FromServer = FromServer.create()
|
const fromServer: FromServer = FromServer.create()
|
||||||
|
|
||||||
export const wasmUrl = () => {
|
|
||||||
const baseUrl =
|
|
||||||
typeof window === 'undefined'
|
|
||||||
? 'http://localhost:3000'
|
|
||||||
: window.location.origin.includes('tauri://localhost')
|
|
||||||
? 'tauri://localhost' // custom protocol for macOS
|
|
||||||
: window.location.origin.includes('tauri.localhost')
|
|
||||||
? 'http://tauri.localhost' // fallback for Windows
|
|
||||||
: window.location.origin.includes('localhost')
|
|
||||||
? 'http://localhost:3000'
|
|
||||||
: window.location.origin && window.location.origin !== 'null'
|
|
||||||
? window.location.origin
|
|
||||||
: 'http://localhost:3000'
|
|
||||||
const fullUrl = baseUrl + '/wasm_lib_bg.wasm'
|
|
||||||
console.log(`Worker full URL for WASM: ${fullUrl}`)
|
|
||||||
|
|
||||||
return fullUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialise the wasm module.
|
// Initialise the wasm module.
|
||||||
const initialise = async () => {
|
const initialise = async (wasmUrl: string) => {
|
||||||
const fullUrl = wasmUrl()
|
const input = await fetch(wasmUrl)
|
||||||
const input = await fetch(fullUrl)
|
|
||||||
const buffer = await input.arrayBuffer()
|
const buffer = await input.arrayBuffer()
|
||||||
return init(buffer)
|
return init(buffer)
|
||||||
}
|
}
|
||||||
@ -80,7 +60,10 @@ onmessage = function (event) {
|
|||||||
|
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case LspWorkerEventType.Init:
|
case LspWorkerEventType.Init:
|
||||||
initialise()
|
let { wasmUrl }: KclWorkerOptions | CopilotWorkerOptions = eventData as
|
||||||
|
| KclWorkerOptions
|
||||||
|
| CopilotWorkerOptions
|
||||||
|
initialise(wasmUrl)
|
||||||
.then((instantiatedModule) => {
|
.then((instantiatedModule) => {
|
||||||
console.log('Worker: WASM module loaded', worker, instantiatedModule)
|
console.log('Worker: WASM module loaded', worker, instantiatedModule)
|
||||||
const config = new ServerConfig(
|
const config = new ServerConfig(
|
||||||
|
Reference in New Issue
Block a user