1
0
This commit is contained in:
Zef Hemel 2023-01-01 11:28:25 -08:00 committed by GitHub
parent 8d3688b2fd
commit e4ebaa2cf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 24 additions and 10 deletions

View File

@ -47,9 +47,7 @@ async function prepareAssets(dist: string) {
`${dist}/web/main.css`, `${dist}/web/main.css`,
compiler.to_string("expanded") as string, compiler.to_string("expanded") as string,
); );
const globalManifest = await plugOsBundle( const globalManifest = await plugOsBundle("./plugs/global.plug.yaml");
new URL(`./plugs/global.plug.yaml`, import.meta.url).pathname,
);
await Deno.writeTextFile( await Deno.writeTextFile(
`${dist}/web/global.plug.json`, `${dist}/web/global.plug.json`,
JSON.stringify(globalManifest, null, 2), JSON.stringify(globalManifest, null, 2),

View File

@ -59,6 +59,8 @@ export function lezerToParseTree(
} }
export function parse(language: Language, text: string): ParseTree { 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); const tree = lezerToParseTree(text, language.parser.parse(text).topNode);
return tree; return tree;
} }

View File

@ -57,6 +57,8 @@ export class AssetBundle {
} }
writeFileSync(path: string, data: Uint8Array) { writeFileSync(path: string, data: Uint8Array) {
// Replace \ with / for windows
path = path.replaceAll("\\", "/");
const mimeType = mime.getType(path) || "application/octet-stream"; const mimeType = mime.getType(path) || "application/octet-stream";
this.bundle[path] = base64EncodedDataUrl(mimeType, data); this.bundle[path] = base64EncodedDataUrl(mimeType, data);
} }

View File

@ -76,11 +76,13 @@ export async function bundle(
continue; continue;
} }
let jsFunctionName = "default", let jsFunctionName = "default",
filePath = path.join(rootPath, def.path); filePath: string = def.path;
if (filePath.indexOf(":") !== -1) { if (filePath.indexOf(":") !== -1) {
[filePath, jsFunctionName] = filePath.split(":"); [filePath, jsFunctionName] = filePath.split(":");
} }
// Resolve path
filePath = path.join(rootPath, filePath);
def.code = await compile( def.code = await compile(
filePath, filePath,
jsFunctionName, jsFunctionName,

View File

@ -49,8 +49,9 @@ export async function compile(
inFile = await Deno.makeTempFile({ suffix: ".ts" }); inFile = await Deno.makeTempFile({ suffix: ".ts" });
await Deno.writeTextFile( await Deno.writeTextFile(
inFile, inFile,
`import {${functionName}} from "${ `import {${functionName}} from "file://${
path.resolve(filePath) // Replacaing \ with / for Windows
path.resolve(filePath).replaceAll("\\", "\\\\")
}";export default ${functionName};`, }";export default ${functionName};`,
); );
} }

View File

@ -130,10 +130,12 @@ Deno.test("Run a deno sandbox", async () => {
import { bundle as plugOsBundle } from "./bin/plugos-bundle.ts"; import { bundle as plugOsBundle } from "./bin/plugos-bundle.ts";
import { esbuild } from "./compile.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 () => { Deno.test("Preload dependencies", async () => {
const globalModules = await plugOsBundle( const globalModules = await plugOsBundle(
`${__dirname}../plugs/global.plug.yaml`, `${__dirname}../plugs/global.plug.yaml`,
); );

View File

@ -2,11 +2,12 @@ import { assert } from "../../test_deps.ts";
import { FileMeta } from "../../common/types.ts"; import { FileMeta } from "../../common/types.ts";
import { path } from "../deps.ts"; import { path } from "../deps.ts";
import fileSystemSyscalls from "./fs.deno.ts"; import fileSystemSyscalls from "./fs.deno.ts";
import { urlToPathname } from "../util.ts";
const fakeCtx = {} as any; const fakeCtx = {} as any;
Deno.test("Test FS operations", async () => { 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 syscalls = fileSystemSyscalls(thisFolder);
const allFiles: FileMeta[] = await syscalls["fs.listFiles"]( const allFiles: FileMeta[] = await syscalls["fs.listFiles"](
fakeCtx, fakeCtx,

View File

@ -5,3 +5,8 @@ export function safeRun(fn: () => Promise<void>) {
// throw e; // throw e;
}); });
} }
export function urlToPathname(url: URL) {
// For Windows, remove prefix /
return url.pathname.replace(/^\/(\w:)/, "$1");
}

View File

@ -12,6 +12,7 @@ import { createSandbox } from "../../plugos/environments/deno_sandbox.ts";
import { loadMarkdownExtensions } from "../../common/markdown_parser/markdown_ext.ts"; import { loadMarkdownExtensions } from "../../common/markdown_parser/markdown_ext.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts"; import { renderMarkdownToHtml } from "./markdown_render.ts";
import { assertEquals } from "../../test_deps.ts"; import { assertEquals } from "../../test_deps.ts";
import { urlToPathname } from "../../plugos/util.ts";
Deno.test("Markdown render", async () => { Deno.test("Markdown render", async () => {
const system = new System<any>("server"); const system = new System<any>("server");
@ -19,7 +20,7 @@ Deno.test("Markdown render", async () => {
await system.load(tasksPlug, createSandbox); await system.load(tasksPlug, createSandbox);
const lang = buildMarkdown(loadMarkdownExtensions(system)); const lang = buildMarkdown(loadMarkdownExtensions(system));
const testFile = Deno.readTextFileSync( 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); const tree = parse(lang, testFile);
renderMarkdownToHtml(tree, { renderMarkdownToHtml(tree, {