Skip to content

Commit

Permalink
automatically patch devicescript with missing imports
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Dec 8, 2022
1 parent e2e3c95 commit e4fe93f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/workers/devicescript/devicescript-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,18 @@ class WorkerHost {

let serviceSpecs: jdspec.ServiceSpec[]

const DEVICESCRIPT_PREFIX = 'import * as ds from "@devicescript/core"'
const handlers: { [index: string]: (props: any) => object | Promise<object> } =
{
compile: async (props: DeviceScriptCompileRequest) => {
const { source } = props
let { source = "" } = props
if (!serviceSpecs) throw new Error("specs missing")

if (source.indexOf(DEVICESCRIPT_PREFIX) < 0) {
source = DEVICESCRIPT_PREFIX + "\n\n" + source
}
const host = new WorkerHost(serviceSpecs)
const res = compile(source, { host })

return <Partial<DeviceScriptCompileResponse>>{
...res,
files: host.files,
Expand Down

0 comments on commit e4fe93f

Please sign in to comment.