0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-02-01 12:16:11 -05:00

Add denoMain

This commit is contained in:
Ryan Dahl 2018-05-29 03:43:54 -04:00
parent 95eb8dc5e4
commit b6c0ad15fa
2 changed files with 31 additions and 20 deletions

View file

@ -64,6 +64,9 @@ func main() {
cwd, err := os.Getwd() cwd, err := os.Getwd()
check(err) check(err)
err = worker.Load("deno_main.js", "denoMain()")
exitOnError(err)
var command = Msg_START // TODO use proto3 var command = Msg_START // TODO use proto3
PubMsg("start", &Msg{ PubMsg("start", &Msg{
Command: command, Command: command,

48
main.ts
View file

@ -17,27 +17,35 @@ import { initFetch } from "./fetch";
export let debug = false; export let debug = false;
let startCalled = false; let startCalled = false;
dispatch.sub("start", (payload: Uint8Array) => { // denoMain is needed to allow hooks into the system.
if (startCalled) { // Also eventual snapshot support needs it.
throw Error("start message received more than once!"); (window as any)["denoMain"] = () => {
} delete (window as any)["denoMain"];
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 });
initTimers(); initTimers();
initFetch(); initFetch();
runtime.setup(mainJs, mainMap);
const inputFn = argv[0]; dispatch.sub("start", (payload: Uint8Array) => {
const mod = runtime.resolveModule(inputFn, `${cwd}/`); if (startCalled) {
mod.compileAndRun(); 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();
});
}