0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/main.ts

58 lines
1.4 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
/// <reference path="./plugins.d.ts" />
import "./globals";
2019-02-12 21:14:02 -05:00
import { assert, log } from "./util";
import * as os from "./os";
import { args } from "./deno";
import { setPrepareStackTrace } from "./error_stack";
import { replLoop } from "./repl";
2019-05-03 16:24:09 -04:00
import { xevalMain, XevalFunc } from "./xeval";
import { setVersions } from "./version";
2019-05-03 16:24:09 -04:00
import { window } from "./window";
2019-02-12 21:14:02 -05:00
import { setLocation } from "./location";
2018-06-11 21:54:55 -04:00
// builtin modules
import * as deno from "./deno";
export default function denoMain(
preserveDenoNamespace: boolean = true,
name?: string
): void {
2019-08-26 08:50:21 -04:00
const s = os.start(preserveDenoNamespace, name);
2019-08-26 08:50:21 -04:00
setVersions(s.denoVersion, s.v8Version);
// handle `--version`
2019-08-26 08:50:21 -04:00
if (s.versionFlag) {
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 08:50:21 -04:00
if (s.mainModule) {
assert(s.mainModule.length > 0);
setLocation(s.mainModule);
2019-02-12 21:14:02 -05:00
}
2019-08-26 08:50:21 -04:00
log("cwd", s.cwd);
2018-06-13 19:40:35 -04:00
2019-08-26 08:50:21 -04:00
for (let i = 1; i < s.argv.length; i++) {
args.push(s.argv[i]);
2018-06-13 19:40:35 -04:00
}
log("args", args);
Object.freeze(args);
2019-05-03 16:24:09 -04:00
if (window["_xevalWrapper"] !== undefined) {
2019-08-26 08:50:21 -04:00
xevalMain(window["_xevalWrapper"] as XevalFunc, s.xevalDelim);
} else if (!s.mainModule) {
replLoop();
}
2018-07-21 21:14:52 -04:00
}