forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
54 lines (43 loc) · 1.39 KB
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
// This allows us to have async/await in our code. It must be loaded first.
import "babel-polyfill";
import * as dispatch from "./dispatch";
import { main as pb } from "./msg.pb";
import * as runtime from "./runtime";
import * as util from "./util";
import { initTimers } from "./timers";
import { initFetch } from "./fetch";
// To control internal logging output
// Set with the -debug command-line flag.
export let debug = false;
let startCalled = false;
// denoMain is needed to allow hooks into the system.
// Also eventual snapshot support needs it.
// tslint:disable-next-line:no-any
(window as any)["denoMain"] = () => {
// tslint:disable-next-line:no-any
delete (window as any)["denoMain"];
initTimers();
initFetch();
dispatch.sub("start", (payload: Uint8Array) => {
if (startCalled) {
throw Error("start message received more than once!");
}
startCalled = true;
const msg = pb.Msg.decode(payload);
const {
startCwd: cwd,
startArgv: argv,
startDebugFlag: debugFlag,
startMainJs: mainJs,
startMainMap: mainMap
} = msg;
debug = debugFlag;
util.log("start", { cwd, argv, debugFlag });
runtime.setup(mainJs, mainMap);
const inputFn = argv[0];
const mod = runtime.resolveModule(inputFn, `${cwd}/`);
mod.compileAndRun();
});
};