1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00
denoland-deno/main.ts

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-05-28 21:50:44 -04:00
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
// All rights reserved. MIT License.
2018-05-27 01:33:21 -04:00
// This allows us to have async/await in our code. It must be loaded first.
import "babel-polyfill";
2018-05-21 22:07:40 -04:00
import * as dispatch from "./dispatch";
2018-05-14 03:06:09 -04:00
import { main as pb } from "./msg.pb";
2018-05-21 22:07:40 -04:00
import * as runtime from "./runtime";
2018-05-19 05:38:51 -04:00
import * as util from "./util";
2018-05-14 01:30:56 -04:00
2018-05-21 22:07:40 -04:00
import { initTimers } from "./timers";
2018-05-27 03:46:18 -04:00
import { initFetch } from "./fetch";
2018-05-21 22:07:40 -04:00
2018-05-19 05:38:51 -04:00
// To control internal logging output
// Set with the -debug command-line flag.
export let debug = false;
2018-05-21 22:07:40 -04:00
let startCalled = false;
2018-05-29 03:43:54 -04:00
// denoMain is needed to allow hooks into the system.
// Also eventual snapshot support needs it.
(window as any)["denoMain"] = () => {
delete (window as any)["denoMain"];
2018-05-19 07:06:23 -04:00
2018-05-21 22:07:40 -04:00
initTimers();
2018-05-27 03:46:18 -04:00
initFetch();
2018-05-21 17:33:33 -04:00
2018-05-29 03:43:54 -04:00
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();
});
}