1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00
denoland-deno/os.ts

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2018-05-21 18:53:53 -04:00
import { ModuleInfo } from "./types";
2018-05-23 11:31:53 -04:00
import { sendMsg } from "./dispatch";
import { main as pb } from "./msg.pb";
import { assert } from "./util";
2018-05-14 17:27:34 -04:00
2018-05-25 15:36:13 -04:00
export function exit(exitCode = 0): void {
sendMsg("os", {
command: pb.Msg.Command.EXIT,
exitCode
});
2018-05-14 17:27:34 -04:00
}
export function codeFetch(
2018-05-19 04:47:40 -04:00
moduleSpecifier: string,
containingFile: string
): ModuleInfo {
2018-05-23 11:31:53 -04:00
const res = sendMsg("os", {
command: pb.Msg.Command.CODE_FETCH,
codeFetchModuleSpecifier: moduleSpecifier,
codeFetchContainingFile: containingFile
});
assert(res.command === pb.Msg.Command.CODE_FETCH_RES);
return {
moduleName: res.codeFetchResModuleName,
filename: res.codeFetchResFilename,
sourceCode: res.codeFetchResSourceCode,
outputCode: res.codeFetchResOutputCode
};
}
export function codeCache(
filename: string,
sourceCode: string,
outputCode: string
): void {
2018-05-23 11:31:53 -04:00
sendMsg("os", {
command: pb.Msg.Command.CODE_CACHE,
codeCacheFilename: filename,
codeCacheSourceCode: sourceCode,
codeCacheOutputCode: outputCode
});
}
2018-05-27 12:49:20 -04:00
export function readFileSync(filename: string): Uint8Array {
const res = sendMsg("os", {
command: pb.Msg.Command.READ_FILE_SYNC,
readFileSyncFilename: filename
});
return res.readFileSyncData;
}