Fixes #107
This commit is contained in:
parent
8d3688b2fd
commit
e4ebaa2cf4
4
build.ts
4
build.ts
@ -47,9 +47,7 @@ async function prepareAssets(dist: string) {
|
||||
`${dist}/web/main.css`,
|
||||
compiler.to_string("expanded") as string,
|
||||
);
|
||||
const globalManifest = await plugOsBundle(
|
||||
new URL(`./plugs/global.plug.yaml`, import.meta.url).pathname,
|
||||
);
|
||||
const globalManifest = await plugOsBundle("./plugs/global.plug.yaml");
|
||||
await Deno.writeTextFile(
|
||||
`${dist}/web/global.plug.json`,
|
||||
JSON.stringify(globalManifest, null, 2),
|
||||
|
@ -59,6 +59,8 @@ export function lezerToParseTree(
|
||||
}
|
||||
|
||||
export function parse(language: Language, text: string): ParseTree {
|
||||
// Remove \r for Windows before parsing
|
||||
text = text.replaceAll("\r", "");
|
||||
const tree = lezerToParseTree(text, language.parser.parse(text).topNode);
|
||||
return tree;
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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");
|
||||
}
|
@ -12,6 +12,7 @@ import { createSandbox } from "../../plugos/environments/deno_sandbox.ts";
|
||||
import { loadMarkdownExtensions } from "../../common/markdown_parser/markdown_ext.ts";
|
||||
import { renderMarkdownToHtml } from "./markdown_render.ts";
|
||||
import { assertEquals } from "../../test_deps.ts";
|
||||
import { urlToPathname } from "../../plugos/util.ts";
|
||||
|
||||
Deno.test("Markdown render", async () => {
|
||||
const system = new System<any>("server");
|
||||
@ -19,7 +20,7 @@ Deno.test("Markdown render", async () => {
|
||||
await system.load(tasksPlug, createSandbox);
|
||||
const lang = buildMarkdown(loadMarkdownExtensions(system));
|
||||
const testFile = Deno.readTextFileSync(
|
||||
new URL("test/example.md", import.meta.url).pathname,
|
||||
urlToPathname(new URL("test/example.md", import.meta.url)),
|
||||
);
|
||||
const tree = parse(lang, testFile);
|
||||
renderMarkdownToHtml(tree, {
|
||||
|
Loading…
Reference in New Issue
Block a user