2018-07-23 18:46:30 +00:00
|
|
|
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
|
2018-11-09 00:09:18 +00:00
|
|
|
// We need to make sure this module loads, for its side effects.
|
|
|
|
import "./globals";
|
|
|
|
|
2018-10-17 17:04:28 +00:00
|
|
|
import * as flatbuffers from "./flatbuffers";
|
2018-10-04 01:18:23 +00:00
|
|
|
import * as msg from "gen/msg_generated";
|
2018-08-30 19:35:51 +00:00
|
|
|
import { assert, log, setLogDebug } from "./util";
|
2018-08-17 20:34:30 +00:00
|
|
|
import * as os from "./os";
|
2019-01-06 19:17:13 +00:00
|
|
|
import { DenoCompiler } from "./compiler";
|
2018-08-25 19:42:49 +00:00
|
|
|
import { libdeno } from "./libdeno";
|
2018-09-22 12:47:44 +00:00
|
|
|
import { args } from "./deno";
|
2018-09-09 22:54:42 +00:00
|
|
|
import { sendSync, handleAsyncMsgFromRust } from "./dispatch";
|
2018-11-05 17:55:59 +00:00
|
|
|
import { replLoop } from "./repl";
|
2018-10-16 00:52:33 +00:00
|
|
|
import { version } from "typescript";
|
2018-06-12 01:54:55 +00:00
|
|
|
|
2019-01-06 19:17:13 +00:00
|
|
|
const compiler = DenoCompiler.instance();
|
|
|
|
|
2018-10-04 01:18:23 +00:00
|
|
|
function sendStart(): msg.StartRes {
|
2018-10-17 17:04:28 +00:00
|
|
|
const builder = flatbuffers.createBuilder();
|
2018-10-04 01:18:23 +00:00
|
|
|
msg.Start.startStart(builder);
|
|
|
|
const startOffset = msg.Start.endStart(builder);
|
|
|
|
const baseRes = sendSync(builder, msg.Any.Start, startOffset);
|
2018-08-30 19:35:51 +00:00
|
|
|
assert(baseRes != null);
|
2018-10-04 01:18:23 +00:00
|
|
|
assert(msg.Any.StartRes === baseRes!.innerType());
|
|
|
|
const startRes = new msg.StartRes();
|
2018-10-04 01:12:23 +00:00
|
|
|
assert(baseRes!.inner(startRes) != null);
|
2018-08-30 19:35:51 +00:00
|
|
|
return startRes;
|
2018-07-06 15:27:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-22 01:14:52 +00:00
|
|
|
/* tslint:disable-next-line:no-default-export */
|
|
|
|
export default function denoMain() {
|
2018-09-06 02:13:36 +00:00
|
|
|
libdeno.recv(handleAsyncMsgFromRust);
|
2018-08-02 17:13:32 +00:00
|
|
|
|
2018-09-24 19:33:50 +00:00
|
|
|
// First we send an empty "Start" message to let the privileged side know we
|
2018-07-06 15:27:36 +00:00
|
|
|
// are ready. The response should be a "StartRes" message containing the CLI
|
2018-09-22 12:47:44 +00:00
|
|
|
// args and other info.
|
2018-08-30 19:35:51 +00:00
|
|
|
const startResMsg = sendStart();
|
2018-07-06 15:27:36 +00:00
|
|
|
|
2018-08-22 21:17:26 +00:00
|
|
|
setLogDebug(startResMsg.debugFlag());
|
2018-08-17 20:34:30 +00:00
|
|
|
|
2018-10-11 21:23:22 +00:00
|
|
|
// handle `--types`
|
|
|
|
if (startResMsg.typesFlag()) {
|
|
|
|
const defaultLibFileName = compiler.getDefaultLibFileName();
|
2019-01-06 19:17:13 +00:00
|
|
|
const defaultLibModule = compiler.resolveModule(defaultLibFileName, "");
|
|
|
|
console.log(defaultLibModule.sourceCode);
|
2018-10-11 21:23:22 +00:00
|
|
|
os.exit(0);
|
|
|
|
}
|
|
|
|
|
2018-10-16 00:52:33 +00:00
|
|
|
// handle `--version`
|
|
|
|
if (startResMsg.versionFlag()) {
|
|
|
|
console.log("deno:", startResMsg.denoVersion());
|
|
|
|
console.log("v8:", startResMsg.v8Version());
|
|
|
|
console.log("typescript:", version);
|
|
|
|
os.exit(0);
|
|
|
|
}
|
|
|
|
|
2019-01-06 19:16:42 +00:00
|
|
|
os.setPid(startResMsg.pid());
|
|
|
|
|
2018-07-06 15:27:36 +00:00
|
|
|
const cwd = startResMsg.cwd();
|
2018-07-13 07:24:07 +00:00
|
|
|
log("cwd", cwd);
|
2018-06-13 23:40:35 +00:00
|
|
|
|
2018-08-23 23:46:21 +00:00
|
|
|
for (let i = 1; i < startResMsg.argvLength(); i++) {
|
2018-09-22 12:47:44 +00:00
|
|
|
args.push(startResMsg.argv(i));
|
2018-06-13 23:40:35 +00:00
|
|
|
}
|
2018-09-22 12:47:44 +00:00
|
|
|
log("args", args);
|
|
|
|
Object.freeze(args);
|
|
|
|
const inputFn = args[0];
|
2018-08-17 20:34:30 +00:00
|
|
|
|
2018-09-24 19:33:50 +00:00
|
|
|
compiler.recompile = startResMsg.recompileFlag();
|
2018-11-05 17:55:59 +00:00
|
|
|
|
|
|
|
if (inputFn) {
|
2019-01-06 19:17:13 +00:00
|
|
|
compiler.run(inputFn, `${cwd}/`);
|
2018-11-05 17:55:59 +00:00
|
|
|
} else {
|
|
|
|
replLoop();
|
|
|
|
}
|
2018-07-22 01:14:52 +00:00
|
|
|
}
|