summaryrefslogtreecommitdiff
path: root/os.ts
blob: de4bdf436962ee3a4aacfd68313f80f8ed6e9472 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { ModuleInfo } from "./types";
import { sendMsg } from "./dispatch";
import { main as pb } from "./msg.pb";
import { assert } from "./util";

export function exit(code = 0): void {
  sendMsg("os", { exit: { code } });
}

export function sourceCodeFetch(
  moduleSpecifier: string,
  containingFile: string
): ModuleInfo {
  const res = sendMsg("os", {
    sourceCodeFetch: { moduleSpecifier, containingFile }
  });
  assert(res.command === pb.Msg.Command.SOURCE_CODE_FETCH_RES);
  return {
    moduleName: res.sourceCodeFetchResModuleName,
    filename: res.sourceCodeFetchResFilename,
    sourceCode: res.sourceCodeFetchResSourceCode,
    outputCode: res.sourceCodeFetchResOutputCode
  };
}

export function sourceCodeCache(
  filename: string,
  sourceCode: string,
  outputCode: string
): void {
  sendMsg("os", {
    sourceCodeCache: { filename, sourceCode, outputCode }
  });
}