Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove isExecutable stuff. #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions leafCompiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ type FileStorageTypedArray = { [path: string]: Uint8Array };
const getFilename = (fullPath: string) => fullPath.replace(/^.*[\\\/]/, '');
const encoder = new TextEncoder();
const decoderUtf8 = new TextDecoder('utf-8');
const isExecutable: boolean = (Deno.mainModule == "file://$deno$/bundle.js");

const fileExists = (path: string | URL): boolean => {
try {
Expand Down Expand Up @@ -76,10 +75,6 @@ export class Leaf {
}

public static async compile(options: CompileOptions) {
if(isExecutable) {
return;
};

options.contentFolders.forEach((folder) => {
for (const entry of Array.from(walkSync(folder)).filter((item) => item.isFile)) {
this.registerFileInMemory(entry.path);
Expand All @@ -104,8 +99,7 @@ export class Leaf {
});

const fakeFileSystemString = `
globalThis["${fileSystemExecutable}"] = (Deno.mainModule == "file://$deno$/bundle.js");
\n \n globalThis["${fileSystemPropertyName}"] = ${this.storageToJson()}; \n \n
globalThis["${fileSystemPropertyName}"] = ${this.storageToJson()}; \n \n

const denoApiReadFileSync = Deno.readFileSync;
const denoApiReadFile = Deno.readFile;
Expand All @@ -115,16 +109,13 @@ export class Leaf {
${fakeMemMethods.join("\n")}

Deno.readFileSync = (path) => {
if(globalThis["${fileSystemExecutable}"] === true) {
try {
return globalThis["getFileInMem"](globalThis, path);
}
catch(e) {
return denoApiReadFileSync(path);
}
} else {
return denoApiReadFileSync(path);
try {
return globalThis["getFileInMem"](globalThis, path);
}
catch(e) {
console.info("Non Leaf read", path);
}
return denoApiReadFileSync(path);
}

Deno.readFile = async (path) => {
Expand Down