Fixes #107
This commit is contained in:
@@ -57,6 +57,8 @@ export class AssetBundle {
|
||||
}
|
||||
|
||||
writeFileSync(path: string, data: Uint8Array) {
|
||||
// Replace \ with / for windows
|
||||
path = path.replaceAll("\\", "/");
|
||||
const mimeType = mime.getType(path) || "application/octet-stream";
|
||||
this.bundle[path] = base64EncodedDataUrl(mimeType, data);
|
||||
}
|
||||
|
||||
@@ -76,11 +76,13 @@ export async function bundle(
|
||||
continue;
|
||||
}
|
||||
let jsFunctionName = "default",
|
||||
filePath = path.join(rootPath, def.path);
|
||||
filePath: string = def.path;
|
||||
if (filePath.indexOf(":") !== -1) {
|
||||
[filePath, jsFunctionName] = filePath.split(":");
|
||||
}
|
||||
|
||||
// Resolve path
|
||||
filePath = path.join(rootPath, filePath);
|
||||
|
||||
def.code = await compile(
|
||||
filePath,
|
||||
jsFunctionName,
|
||||
|
||||
+3
-2
@@ -49,8 +49,9 @@ export async function compile(
|
||||
inFile = await Deno.makeTempFile({ suffix: ".ts" });
|
||||
await Deno.writeTextFile(
|
||||
inFile,
|
||||
`import {${functionName}} from "${
|
||||
path.resolve(filePath)
|
||||
`import {${functionName}} from "file://${
|
||||
// Replacaing \ with / for Windows
|
||||
path.resolve(filePath).replaceAll("\\", "\\\\")
|
||||
}";export default ${functionName};`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -130,10 +130,12 @@ Deno.test("Run a deno sandbox", async () => {
|
||||
|
||||
import { bundle as plugOsBundle } from "./bin/plugos-bundle.ts";
|
||||
import { esbuild } from "./compile.ts";
|
||||
import { urlToPathname } from "./util.ts";
|
||||
|
||||
const __dirname = new URL(".", import.meta.url).pathname;
|
||||
const __dirname = urlToPathname(new URL(".", import.meta.url));
|
||||
|
||||
Deno.test("Preload dependencies", async () => {
|
||||
|
||||
const globalModules = await plugOsBundle(
|
||||
`${__dirname}../plugs/global.plug.yaml`,
|
||||
);
|
||||
|
||||
@@ -2,11 +2,12 @@ import { assert } from "../../test_deps.ts";
|
||||
import { FileMeta } from "../../common/types.ts";
|
||||
import { path } from "../deps.ts";
|
||||
import fileSystemSyscalls from "./fs.deno.ts";
|
||||
import { urlToPathname } from "../util.ts";
|
||||
|
||||
const fakeCtx = {} as any;
|
||||
|
||||
Deno.test("Test FS operations", async () => {
|
||||
const thisFolder = path.dirname(new URL(import.meta.url).pathname);
|
||||
const thisFolder = path.resolve(path.dirname(urlToPathname(new URL(import.meta.url))));
|
||||
const syscalls = fileSystemSyscalls(thisFolder);
|
||||
const allFiles: FileMeta[] = await syscalls["fs.listFiles"](
|
||||
fakeCtx,
|
||||
|
||||
@@ -5,3 +5,8 @@ export function safeRun(fn: () => Promise<void>) {
|
||||
// throw e;
|
||||
});
|
||||
}
|
||||
|
||||
export function urlToPathname(url: URL) {
|
||||
// For Windows, remove prefix /
|
||||
return url.pathname.replace(/^\/(\w:)/, "$1");
|
||||
}
|
||||
Reference in New Issue
Block a user