diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2018-05-29 03:43:54 -0400 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-05-29 03:43:54 -0400 |
commit | b6c0ad15fae9f747dbf91525caf6189beb358f76 (patch) | |
tree | d1fcff52a8473017a762ccad046f8d34136ca1e1 | |
parent | 95eb8dc5e493cb73b062c9543deb85e32799adc8 (diff) |
Add denoMain
-rw-r--r-- | main.go | 3 | ||||
-rw-r--r-- | main.ts | 48 |
2 files changed, 31 insertions, 20 deletions
@@ -64,6 +64,9 @@ func main() { cwd, err := os.Getwd() check(err) + err = worker.Load("deno_main.js", "denoMain()") + exitOnError(err) + var command = Msg_START // TODO use proto3 PubMsg("start", &Msg{ Command: command, @@ -17,27 +17,35 @@ import { initFetch } from "./fetch"; export let debug = false; let startCalled = false; -dispatch.sub("start", (payload: Uint8Array) => { - if (startCalled) { - throw Error("start message received more than once!"); - } - startCalled = true; - - const msg = pb.Msg.decode(payload); - const cwd = msg.startCwd; - const argv = msg.startArgv; - const debugFlag = msg.startDebugFlag; - const mainJs = msg.startMainJs; - const mainMap = msg.startMainMap; - - debug = debugFlag; - util.log("start", { cwd, argv, debugFlag }); +// denoMain is needed to allow hooks into the system. +// Also eventual snapshot support needs it. +(window as any)["denoMain"] = () => { + delete (window as any)["denoMain"]; initTimers(); initFetch(); - runtime.setup(mainJs, mainMap); - const inputFn = argv[0]; - const mod = runtime.resolveModule(inputFn, `${cwd}/`); - mod.compileAndRun(); -}); + dispatch.sub("start", (payload: Uint8Array) => { + if (startCalled) { + throw Error("start message received more than once!"); + } + startCalled = true; + + const msg = pb.Msg.decode(payload); + const cwd = msg.startCwd; + const argv = msg.startArgv; + const debugFlag = msg.startDebugFlag; + const mainJs = msg.startMainJs; + const mainMap = msg.startMainMap; + + debug = debugFlag; + util.log("start", { cwd, argv, debugFlag }); + + runtime.setup(mainJs, mainMap); + + const inputFn = argv[0]; + const mod = runtime.resolveModule(inputFn, `${cwd}/`); + mod.compileAndRun(); + }); +} + |