diff --git a/src/workers/devicescript/devicescript-worker.ts b/src/workers/devicescript/devicescript-worker.ts index ed37e2ca15df..de5349e7f326 100644 --- a/src/workers/devicescript/devicescript-worker.ts +++ b/src/workers/devicescript/devicescript-worker.ts @@ -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 } = { 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 >{ ...res, files: host.files,