mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
Add denoMain
This commit is contained in:
parent
95eb8dc5e4
commit
b6c0ad15fa
2 changed files with 31 additions and 20 deletions
3
main.go
3
main.go
|
@ -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,
|
||||
|
|
48
main.ts
48
main.ts
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue