1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-24 15:19:26 -05:00
denoland-deno/os.ts
2018-05-25 16:16:28 -04:00

42 lines
1.1 KiB
TypeScript

import { ModuleInfo } from "./types";
import { sendMsg } from "./dispatch";
import { main as pb } from "./msg.pb";
import { assert } from "./util";
export function exit(exitCode = 0): void {
sendMsg("os", {
command: pb.Msg.Command.EXIT,
exitCode
});
}
export function sourceCodeFetch(
moduleSpecifier: string,
containingFile: string
): ModuleInfo {
const res = sendMsg("os", {
command: pb.Msg.Command.SOURCE_CODE_FETCH,
sourceCodeFetchModuleSpecifier: moduleSpecifier,
sourceCodeFetchContainingFile: 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", {
command: pb.Msg.Command.SOURCE_CODE_CACHE,
sourceCodeCacheFilename: filename,
sourceCodeCacheSourceCode: sourceCode,
sourceCodeCacheOutputCode: outputCode
});
}