2018-05-28 21:50:44 -04:00
|
|
|
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
|
|
|
// All rights reserved. MIT License.
|
2018-05-21 18:53:53 -04:00
|
|
|
import { ModuleInfo } from "./types";
|
2018-06-05 04:10:27 -04:00
|
|
|
import { pubInternal } from "./dispatch";
|
2018-06-13 13:37:24 -04:00
|
|
|
import { deno as pb } from "./msg.pb";
|
2018-05-25 15:24:24 -04:00
|
|
|
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 {
|
2018-06-05 04:10:27 -04:00
|
|
|
pubInternal("os", {
|
2018-05-25 15:36:13 -04:00
|
|
|
command: pb.Msg.Command.EXIT,
|
|
|
|
exitCode
|
|
|
|
});
|
2018-05-14 17:27:34 -04:00
|
|
|
}
|
|
|
|
|
2018-05-25 17:21:06 -04:00
|
|
|
export function codeFetch(
|
2018-05-19 04:47:40 -04:00
|
|
|
moduleSpecifier: string,
|
|
|
|
containingFile: string
|
|
|
|
): ModuleInfo {
|
2018-06-05 04:10:27 -04:00
|
|
|
const res = pubInternal("os", {
|
2018-05-25 17:21:06 -04:00
|
|
|
command: pb.Msg.Command.CODE_FETCH,
|
|
|
|
codeFetchModuleSpecifier: moduleSpecifier,
|
|
|
|
codeFetchContainingFile: containingFile
|
2018-05-17 09:47:09 -04:00
|
|
|
});
|
2018-05-25 17:21:06 -04:00
|
|
|
assert(res.command === pb.Msg.Command.CODE_FETCH_RES);
|
2018-05-25 15:24:24 -04:00
|
|
|
return {
|
2018-05-25 17:21:06 -04:00
|
|
|
moduleName: res.codeFetchResModuleName,
|
|
|
|
filename: res.codeFetchResFilename,
|
|
|
|
sourceCode: res.codeFetchResSourceCode,
|
|
|
|
outputCode: res.codeFetchResOutputCode
|
2018-05-25 15:24:24 -04:00
|
|
|
};
|
2018-05-17 09:47:09 -04:00
|
|
|
}
|
|
|
|
|
2018-05-25 17:21:06 -04:00
|
|
|
export function codeCache(
|
2018-05-17 09:47:09 -04:00
|
|
|
filename: string,
|
|
|
|
sourceCode: string,
|
|
|
|
outputCode: string
|
|
|
|
): void {
|
2018-06-05 04:10:27 -04:00
|
|
|
pubInternal("os", {
|
2018-05-25 17:21:06 -04:00
|
|
|
command: pb.Msg.Command.CODE_CACHE,
|
|
|
|
codeCacheFilename: filename,
|
|
|
|
codeCacheSourceCode: sourceCode,
|
|
|
|
codeCacheOutputCode: outputCode
|
2018-05-15 04:39:03 -04:00
|
|
|
});
|
2018-05-17 09:47:09 -04:00
|
|
|
}
|
2018-05-27 12:49:20 -04:00
|
|
|
|
|
|
|
export function readFileSync(filename: string): Uint8Array {
|
2018-06-05 04:10:27 -04:00
|
|
|
const res = pubInternal("os", {
|
2018-05-27 12:49:20 -04:00
|
|
|
command: pb.Msg.Command.READ_FILE_SYNC,
|
|
|
|
readFileSyncFilename: filename
|
|
|
|
});
|
|
|
|
return res.readFileSyncData;
|
|
|
|
}
|
2018-05-28 14:39:02 -04:00
|
|
|
|
|
|
|
export function writeFileSync(
|
|
|
|
filename: string,
|
|
|
|
data: Uint8Array,
|
|
|
|
perm: number
|
|
|
|
): void {
|
2018-06-05 04:10:27 -04:00
|
|
|
pubInternal("os", {
|
2018-05-28 14:39:02 -04:00
|
|
|
command: pb.Msg.Command.WRITE_FILE_SYNC,
|
|
|
|
writeFileSyncFilename: filename,
|
|
|
|
writeFileSyncData: data,
|
|
|
|
writeFileSyncPerm: perm
|
|
|
|
});
|
|
|
|
}
|