2019-01-09 12:59:46 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2019-09-02 17:07:11 -04:00
|
|
|
import "./globals.ts";
|
|
|
|
|
|
|
|
import { assert, log } from "./util.ts";
|
|
|
|
import * as os from "./os.ts";
|
|
|
|
import { args } from "./deno.ts";
|
|
|
|
import { setPrepareStackTrace } from "./error_stack.ts";
|
|
|
|
import { replLoop } from "./repl.ts";
|
|
|
|
import { xevalMain, XevalFunc } from "./xeval.ts";
|
|
|
|
import { setVersions } from "./version.ts";
|
|
|
|
import { window } from "./window.ts";
|
|
|
|
import { setLocation } from "./location.ts";
|
2019-09-07 01:57:15 +09:00
|
|
|
import { setBuildInfo } from "./build.ts";
|
|
|
|
import { setSignals } from "./process.ts";
|
2019-09-02 17:07:11 -04:00
|
|
|
|
2019-09-08 01:27:18 +09:00
|
|
|
function denoMain(preserveDenoNamespace = true, name?: string): void {
|
2019-08-26 14:50:21 +02:00
|
|
|
const s = os.start(preserveDenoNamespace, name);
|
2018-08-02 13:13:32 -04:00
|
|
|
|
2019-09-07 01:57:15 +09:00
|
|
|
setBuildInfo(s.os, s.arch);
|
|
|
|
setSignals();
|
2019-09-04 11:12:21 +09:00
|
|
|
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
|
2019-01-29 11:41:28 +10:00
|
|
|
|
2019-07-29 19:11:08 +10:00
|
|
|
setPrepareStackTrace(Error);
|
|
|
|
|
2019-08-26 14:50:21 +02:00
|
|
|
if (s.mainModule) {
|
|
|
|
assert(s.mainModule.length > 0);
|
|
|
|
setLocation(s.mainModule);
|
2019-02-12 21:14:02 -05:00
|
|
|
}
|
|
|
|
|
2019-08-26 14:50:21 +02:00
|
|
|
log("cwd", s.cwd);
|
2018-06-14 01:40:35 +02:00
|
|
|
|
2019-08-26 14:50:21 +02:00
|
|
|
for (let i = 1; i < s.argv.length; i++) {
|
|
|
|
args.push(s.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) {
|
2019-08-26 14:50:21 +02:00
|
|
|
xevalMain(window["_xevalWrapper"] as XevalFunc, s.xevalDelim);
|
|
|
|
} else if (!s.mainModule) {
|
2018-11-05 09:55:59 -08:00
|
|
|
replLoop();
|
|
|
|
}
|
2018-07-22 03:14:52 +02:00
|
|
|
}
|
2019-09-02 17:07:11 -04:00
|
|
|
window["denoMain"] = denoMain;
|