1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-24 08:00:10 -05:00
denoland-deno/js/main.ts

52 lines
1.4 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
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";
import * as Deno from "./deno.ts";
function denoMain(preserveDenoNamespace: boolean = true, name?: string): void {
2019-08-26 14:50:21 +02:00
const s = os.start(preserveDenoNamespace, name);
2019-08-26 14:50:21 +02:00
setVersions(s.denoVersion, s.v8Version);
// handle `--version`
2019-08-26 14:50:21 +02:00
if (s.versionFlag) {
const { console } = window;
console.log("deno:", Deno.version.deno);
console.log("v8:", Deno.version.v8);
console.log("typescript:", Deno.version.typescript);
os.exit(0);
}
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
}
log("args", args);
Object.freeze(args);
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) {
replLoop();
}
2018-07-22 03:14:52 +02:00
}
window["denoMain"] = denoMain;