1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/main.ts

55 lines
1.4 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.
2018-05-29 05:27:27 -04:00
// tslint:disable-next-line:no-any
2018-05-29 03:43:54 -04:00
(window as any)["denoMain"] = () => {
2018-05-29 05:27:27 -04:00
// tslint:disable-next-line:no-any
2018-05-29 03:43:54 -04:00
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);
2018-06-05 04:43:00 -04:00
const {
startCwd: cwd,
startArgv: argv,
startDebugFlag: debugFlag,
startMainJs: mainJs,
startMainMap: mainMap
} = msg;
2018-05-29 03:43:54 -04:00
debug = debugFlag;
util.log("start", { cwd, argv, debugFlag });
runtime.setup(mainJs, mainMap);
const inputFn = argv[0];
const mod = runtime.resolveModule(inputFn, `${cwd}/`);
mod.compileAndRun();
});
2018-05-29 04:28:32 -04:00
};