2019-01-09 12:59:46 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-03-10 04:30:38 +11:00
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
|
2019-01-29 11:41:28 +10:00
|
|
|
/// <reference path="./plugins.d.ts" />
|
2018-11-09 11:09:18 +11:00
|
|
|
|
2019-01-29 11:41:28 +10:00
|
|
|
import "./globals";
|
|
|
|
|
2019-02-12 21:14:02 -05:00
|
|
|
import { assert, log } from "./util";
|
2018-08-17 16:34:30 -04:00
|
|
|
import * as os from "./os";
|
2018-09-22 20:47:44 +08:00
|
|
|
import { args } from "./deno";
|
2019-07-29 19:11:08 +10:00
|
|
|
import { setPrepareStackTrace } from "./error_stack";
|
2018-11-05 09:55:59 -08:00
|
|
|
import { replLoop } from "./repl";
|
2019-05-03 13:24:09 -07:00
|
|
|
import { xevalMain, XevalFunc } from "./xeval";
|
2019-02-19 08:43:02 +09:00
|
|
|
import { setVersions } from "./version";
|
2019-05-03 13:24:09 -07:00
|
|
|
import { window } from "./window";
|
2019-02-12 21:14:02 -05:00
|
|
|
import { setLocation } from "./location";
|
2018-06-12 03:54:55 +02:00
|
|
|
|
2019-01-09 12:59:46 -05:00
|
|
|
// builtin modules
|
|
|
|
import * as deno from "./deno";
|
2019-01-06 14:17:13 -05:00
|
|
|
|
2019-08-05 04:23:41 -07:00
|
|
|
export default function denoMain(
|
|
|
|
preserveDenoNamespace: boolean = true,
|
|
|
|
name?: string
|
|
|
|
): void {
|
|
|
|
const startResMsg = os.start(preserveDenoNamespace, name);
|
2018-08-02 13:13:32 -04:00
|
|
|
|
2019-02-19 08:43:02 +09:00
|
|
|
setVersions(startResMsg.denoVersion()!, startResMsg.v8Version()!);
|
|
|
|
|
2018-10-16 09:52:33 +09:00
|
|
|
// handle `--version`
|
|
|
|
if (startResMsg.versionFlag()) {
|
2019-02-19 08:43:02 +09:00
|
|
|
console.log("deno:", deno.version.deno);
|
|
|
|
console.log("v8:", deno.version.v8);
|
|
|
|
console.log("typescript:", deno.version.typescript);
|
2019-01-29 11:41:28 +10:00
|
|
|
os.exit(0);
|
|
|
|
}
|
|
|
|
|
2019-07-29 19:11:08 +10:00
|
|
|
setPrepareStackTrace(Error);
|
|
|
|
|
2019-02-12 21:14:02 -05:00
|
|
|
const mainModule = startResMsg.mainModule();
|
|
|
|
if (mainModule) {
|
|
|
|
assert(mainModule.length > 0);
|
|
|
|
setLocation(mainModule);
|
|
|
|
}
|
|
|
|
|
2018-07-06 11:27:36 -04:00
|
|
|
const cwd = startResMsg.cwd();
|
2018-07-13 03:24:07 -04:00
|
|
|
log("cwd", cwd);
|
2018-06-14 01:40:35 +02:00
|
|
|
|
2018-08-23 19:46:21 -04:00
|
|
|
for (let i = 1; i < startResMsg.argvLength(); i++) {
|
2018-09-22 20:47:44 +08:00
|
|
|
args.push(startResMsg.argv(i));
|
2018-06-14 01:40:35 +02:00
|
|
|
}
|
2018-09-22 20:47:44 +08:00
|
|
|
log("args", args);
|
|
|
|
Object.freeze(args);
|
2018-08-17 16:34:30 -04:00
|
|
|
|
2019-05-03 13:24:09 -07:00
|
|
|
if (window["_xevalWrapper"] !== undefined) {
|
|
|
|
xevalMain(window["_xevalWrapper"] as XevalFunc, startResMsg.xevalDelim());
|
|
|
|
} else if (!mainModule) {
|
2018-11-05 09:55:59 -08:00
|
|
|
replLoop();
|
|
|
|
}
|
2018-07-22 03:14:52 +02:00
|
|
|
}
|