Dependency cleanup

pull/87/head
Zef Hemel 2022-10-07 16:27:47 +02:00
parent 8f289b7c25
commit bc1c38d77c
20 changed files with 153 additions and 88 deletions

View File

@ -2,6 +2,6 @@
"editor.formatOnSave": true,
"typescriptHero.imports.stringQuoteStyle": "\"",
"deno.enable": true,
"deno.importMap": "",
"deno.importMap": "import_map.json",
"deno.config": "deno.json"
}

View File

@ -6,13 +6,15 @@ import { denoPlugin } from "./packages/esbuild_deno_loader/mod.ts";
import { copy } from "https://deno.land/std@0.158.0/fs/copy.ts";
import sass from "https://deno.land/x/denosass@1.0.4/mod.ts";
import { bundleFolder } from "./json_bundle.ts";
import { bundleRun } from "./packages/plugos/bin/plugos-bundle.ts";
// @ts-ignore trust me
const esbuild: typeof esbuildWasm = Deno.run === undefined
? esbuildWasm
: esbuildNative;
async function copyAssets(dest: string) {
async function prepareAssets(dest: string) {
await copy("packages/web/fonts", dest, { overwrite: true });
await copy("packages/web/index.html", `${dest}/index.html`, {
overwrite: true,
@ -27,6 +29,14 @@ async function copyAssets(dest: string) {
"dist/main.css",
compiler.to_string("expanded") as string,
);
// await bundleRun({
// _: [`${__dirname}../plugs/global.plug.yaml`],
// debug: true,
// dist: tmpDist,
// exclude: [],
// });
await bundleFolder("dist", "dist_bundle.json");
}
async function bundle(): Promise<void> {
@ -48,7 +58,7 @@ async function bundle(): Promise<void> {
} else {
console.log("watch build succeeded.");
}
copyAssets("dist").catch(console.error);
prepareAssets("dist").catch(console.error);
},
},
plugins: [
@ -58,7 +68,7 @@ async function bundle(): Promise<void> {
],
}),
]);
await copyAssets("dist");
await prepareAssets("dist");
console.log("Built!");
}
await bundle();

View File

@ -2,11 +2,11 @@ export {
autocompletion,
CompletionContext,
completionKeymap,
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state";
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state,@lezer/common";
export type {
Completion,
CompletionResult,
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state";
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state,@lezer/common,@codemirror/view";
export * as YAML from "https://deno.land/std@0.158.0/encoding/yaml.ts";
export * as path from "https://deno.land/std@0.158.0/path/mod.ts";
@ -23,18 +23,13 @@ export {
historyKeymap,
indentWithTab,
standardKeymap,
} from "https://esm.sh/@codemirror/commands@6.1.1?external=@codemirror/state";
} from "@codemirror/commands";
export {
closeBrackets,
closeBracketsKeymap,
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state";
} from "https://esm.sh/@codemirror/autocomplete@6.3.0?external=@codemirror/state,@codemirror/commands,@lezer/common,@codemirror/view";
export {
styleTags,
Tag,
tagHighlighter,
tags,
} from "https://esm.sh/@lezer/highlight@1.1.1";
export { styleTags, Tag, tagHighlighter, tags } from "@lezer/highlight";
export type {
BlockContext,
@ -42,7 +37,7 @@ export type {
LeafBlockParser,
MarkdownConfig,
MarkdownExtension,
} from "https://esm.sh/@lezer/markdown@1.0.2";
} from "@lezer/markdown";
export {
Emoji,
@ -54,11 +49,11 @@ export {
Superscript,
Table,
TaskList,
} from "https://esm.sh/@lezer/markdown@1.0.2";
} from "@lezer/markdown";
export type { SyntaxNode, Tree } from "https://esm.sh/@lezer/common@1.0.1";
export type { SyntaxNode, Tree } from "@lezer/common";
export { searchKeymap } from "https://esm.sh/@codemirror/search@6.2.1?external=@codemirror/state";
export { searchKeymap } from "https://esm.sh/@codemirror/search@6.2.1?external=@codemirror/state,@codemirror/view";
export {
Decoration,
drawSelection,
@ -70,11 +65,10 @@ export {
ViewPlugin,
ViewUpdate,
WidgetType,
} from "https://esm.sh/@codemirror/view@6.3.0?external=@codemirror/state";
export type {
DecorationSet,
KeyBinding,
} from "https://esm.sh/@codemirror/view@6.3.0?external=@codemirror/state";
} from "@codemirror/view";
export type { DecorationSet, KeyBinding } from "@codemirror/view";
export { markdown } from "https://esm.sh/@codemirror/lang-markdown@6.0.1?external=@codemirror/state,@lezer/common,@codemirror/language,@lezer/markdown,@codemirror/view,@lezer/highlight";
export {
EditorSelection,
@ -86,11 +80,11 @@ export {
} from "@codemirror/state";
export type { ChangeSpec, StateCommand } from "@codemirror/state";
export {
defaultHighlightStyle,
defineLanguageFacet,
foldNodeProp,
HighlightStyle,
indentNodeProp,
// bla
Language,
languageDataProp,
LanguageDescription,
@ -98,4 +92,4 @@ export {
ParseContext,
syntaxHighlighting,
syntaxTree,
} from "https://esm.sh/@codemirror/language@6.2.1?external=@codemirror/state";
} from "@codemirror/language";

View File

@ -1,3 +1,5 @@
export * from "./dep_common.ts";
export { Database as SQLite } from "https://deno.land/x/sqlite3@0.6.1/mod.ts";
export { Application, Router } from "https://deno.land/x/oak@v11.1.0/mod.ts";
export { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts";

15
dist_bundle.json Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,12 @@
{
"imports": {
"@codemirror/state": "https://esm.sh/@codemirror/state@6.1.2",
"@lezer/common": "https://esm.sh/@lezer/common@1.0.1",
"@lezer/markdown": "https://esm.sh/@lezer/markdown@1.0.2?external=@lezer/common,@codemirror/language,@lezer/highlight",
"@codemirror/language": "https://esm.sh/@codemirror/language@6.2.1?external=@codemirror/state,@lezer/common,@lezer/lr,@codemirror/view,@lezer/highlight",
"@codemirror/commands": "https://esm.sh/@codemirror/commands@6.1.1?external=@codemirror/state,@codemirror/view",
"@codemirror/view": "https://esm.sh/@codemirror/view@6.3.0?external=@codemirror/state,@lezer/common",
"@lezer/highlight": "https://esm.sh/@lezer/highlight@1.1.1?external=@lezer/common",
"$sb/": "./packages/",
"handlebars": "https://esm.sh/handlebars",
"@lezer/lr": "https://esm.sh/@lezer/lr",

12
json_bundle.ts Normal file
View File

@ -0,0 +1,12 @@
import { walk } from "https://deno.land/std@0.159.0/fs/mod.ts";
import { b64encode } from "./dep_common.ts";
export async function bundleFolder(path: string, bundlePath: string) {
const bundle: Record<string, string> = {};
for await (const { path: filePath } of walk(path, { includeDirs: false })) {
console.log("Bundling", filePath);
const b64content = b64encode(await Deno.readFile(filePath));
bundle[filePath] = b64content;
}
await Deno.writeTextFile(bundlePath, JSON.stringify(bundle, null, 2));
}

View File

@ -1,14 +1,14 @@
// Changes made to this file:
// - ignore language facet stuff, always assume markdown
import {
ChangeSpec,
EditorSelection,
StateCommand,
SyntaxNode,
syntaxTree,
Text,
Tree,
} from "../../../dep_common.ts";
import { syntaxTree } from "../../../dep_common.ts";
import { SyntaxNode, Tree } from "../../../dep_common.ts";
import { markdownLanguage } from "./markdown.ts";
function nodeStart(node: SyntaxNode, doc: Text) {

View File

@ -0,0 +1,21 @@
import { b64decode } from "../../dep_common.ts";
type AssetBundle = Record<string, string>;
export function assetReadFileSync(
bundle: AssetBundle,
path: string,
): ArrayBuffer {
const content = bundle[path];
if (!content) {
throw new Error(`No such file ${path}`);
}
return b64decode(content);
}
export function assetReadTextFileSync(
bundle: AssetBundle,
path: string,
): string {
return new TextDecoder().decode(assetReadFileSync(bundle, path));
}

View File

@ -1,7 +1,7 @@
import type { SyntaxNode } from "../../dep_common.ts";
import type { Language } from "../../dep_common.ts";
import { ParseTree } from "./tree.ts";
import type { SyntaxNode } from "../../dep_common.ts";
import type { Language } from "../../dep_common.ts";
export function lezerToParseTree(
text: string,
n: SyntaxNode,

View File

@ -1,21 +1,23 @@
import { styleTags, tags as t } from "../../dep_common.ts";
import {
BlockContext,
Language,
LeafBlock,
LeafBlockParser,
markdown,
MarkdownConfig,
styleTags,
Table,
tags as t,
TaskList,
} from "../../dep_common.ts";
import { markdown } from "./markdown/index.ts";
import * as ct from "./customtags.ts";
import { Language } from "../../dep_common.ts";
import {
MDExt,
mdExtensionStyleTags,
mdExtensionSyntaxConfig,
} from "./markdown_ext.ts";
// import { markdown } from "./markdown/index.ts";
export const pageLinkRegex = /^\[\[([^\]]+)\]\]/;
const WikiLink: MarkdownConfig = {

View File

@ -71,7 +71,7 @@ type BundleArgs = {
exclude?: string[] | string;
};
export async function run(args: BundleArgs) {
export async function bundleRun(args: BundleArgs) {
console.log("Args", args);
async function buildAll() {
@ -92,25 +92,6 @@ export async function run(args: BundleArgs) {
}
await buildAll();
// if (args.watch) {
// console.log("Watching for changes...");
// for await (const event of Deno.watchFs(".", {
// recursive: true,
// })) {
// if (
// event.filename.endsWith(".plug.yaml") ||
// filename.endsWith(".js") ||
// filename.endsWith(".css") ||
// filename.endsWith(".png") ||
// filename.endsWith(".jpg") ||
// filename.endsWith(".gif") ||
// (filename.endsWith(".ts") && !filename.endsWith("_in.ts"))
// ) {
// console.log("Change detected", eventType, filename);
// await buildAll();
// }
// }
// }
}
if (import.meta.main) {
@ -131,6 +112,6 @@ if (import.meta.main) {
? args.exclude.split(",")
: [];
await run(args);
await bundleRun(args);
esbuild.stop();
}

View File

@ -2,8 +2,8 @@ import { createSandbox } from "./environments/deno_sandbox.ts";
import { System } from "./system.ts";
import {
assertEquals,
assert,
assertEquals,
} from "https://deno.land/std@0.158.0/testing/asserts.ts";
import { denoPlugin } from "../esbuild_deno_loader/mod.ts";
@ -88,7 +88,7 @@ Deno.test("Run a deno sandbox", async () => {
},
},
},
createSandbox
createSandbox,
);
assertEquals(await plug.invoke("addTen", [10]), 20);
for (let i = 0; i < 100; i++) {
@ -112,8 +112,8 @@ Deno.test("Run a deno sandbox", async () => {
} catch (e: any) {
assert(
e.message.indexOf(
"Missing permission 'restricted' for syscall restrictedSyscall"
) !== -1
"Missing permission 'restricted' for syscall restrictedSyscall",
) !== -1,
);
}
assertEquals(await plug.invoke("dangerousTest", []), "yay");
@ -121,9 +121,8 @@ Deno.test("Run a deno sandbox", async () => {
await system.unloadAll();
});
import { run as bundleRun } from "./bin/plugos-bundle.ts";
import { bundleRun } from "./bin/plugos-bundle.ts";
import { esbuild } from "./compile.ts";
import { safeRun } from "./util.ts";
const __dirname = new URL(".", import.meta.url).pathname;
Deno.test("Preload dependencies", async () => {
@ -135,7 +134,7 @@ Deno.test("Preload dependencies", async () => {
exclude: [],
});
const globalModules = JSON.parse(
Deno.readTextFileSync(`${tmpDist}/global.plug.json`)
Deno.readTextFileSync(`${tmpDist}/global.plug.json`),
);
await bundleRun({
_: [`${__dirname}test.plug.yaml`],
@ -158,7 +157,7 @@ Deno.test("Preload dependencies", async () => {
console.log("Loading test module");
const testPlug = await system.load(
JSON.parse(Deno.readTextFileSync(`${tmpDist}/test.plug.json`)),
createSandbox
createSandbox,
);
console.log("Running");

View File

@ -16,6 +16,7 @@ import {
import type { QueryProviderEvent } from "./engine.ts";
import { applyQuery } from "./engine.ts";
import { removeQueries } from "./util.ts";
import * as YAML from "yaml";
export async function indexData({ name, tree }: IndexTreeEvent) {
let dataObjects: { key: string; value: Object }[] = [];
@ -60,7 +61,7 @@ export async function indexData({ name, tree }: IndexTreeEvent) {
export function extractMeta(
parseTree: ParseTree,
removeKeys: string[] = []
removeKeys: string[] = [],
): any {
let data: any = {};
addParentPointers(parseTree);
@ -95,13 +96,13 @@ export function extractMeta(
return;
}
let codeText = codeTextNode.children![0].text!;
data = parseYaml(codeText);
data = YAML.parse(codeText);
if (removeKeys.length > 0) {
let newData = { ...data };
for (let key of removeKeys) {
delete newData[key];
}
codeTextNode.children![0].text = stringifyYaml(newData).trim();
codeTextNode.children![0].text = YAML.stringify(newData).trim();
// If nothing is left, let's just delete this thing
if (Object.keys(newData).length === 0) {
return null;

View File

@ -1,4 +1,8 @@
import { Application, path, Router, SQLite } from "../../dep_server.ts";
import { Application, mime, path, Router, SQLite } from "../../dep_server.ts";
import {
assetReadFileSync,
assetReadTextFileSync,
} from "../common/asset_bundle.ts";
import { Manifest, SilverBulletHooks } from "../common/manifest.ts";
import { loadMarkdownExtensions } from "../common/markdown_ext.ts";
import buildMarkdown from "../common/parser.ts";
@ -41,7 +45,7 @@ const safeFilename = /^[a-zA-Z0-9_\-\.]+$/;
export type ServerOptions = {
port: number;
pagesPath: string;
distDir: string;
assetBundle: Record<string, string>;
builtinPlugDir: string;
password?: string;
};
@ -63,16 +67,17 @@ export class ExpressServer {
spacePrimitives: SpacePrimitives;
abortController?: AbortController;
globalModules: Manifest;
assetBundle: Record<string, string>;
constructor(options: ServerOptions) {
this.port = options.port;
this.app = new Application();
this.builtinPlugDir = options.builtinPlugDir;
this.distDir = options.distDir;
this.assetBundle = options.assetBundle;
this.password = options.password;
this.globalModules = JSON.parse(
Deno.readTextFileSync(`${this.distDir}/global.plug.json`),
assetReadTextFileSync(this.assetBundle, `dist/global.plug.json`),
);
// Set up the PlugOS System
@ -324,14 +329,22 @@ export class ExpressServer {
// Serve static files (javascript, css, html)
this.app.use(async (ctx, next) => {
if (ctx.request.url.pathname === "/") {
return ctx.send({
root: "/",
path: `${this.distDir}/index.html`,
});
ctx.response.headers.set("Content-type", "text/html");
ctx.response.body = assetReadTextFileSync(
this.assetBundle,
"dist/index.html",
);
return;
}
const root = this.distDir;
try {
await ctx.send({ root });
ctx.response.body = assetReadFileSync(
this.assetBundle,
`dist${ctx.request.url.pathname}`,
);
ctx.response.headers.set(
"Content-type",
mime.getType(ctx.request.url.pathname)!,
);
} catch {
await next();
}
@ -349,10 +362,11 @@ export class ExpressServer {
// Fallback, serve index.html
this.app.use((ctx) => {
return ctx.send({
root: "/",
path: `${this.distDir}/index.html`,
});
ctx.response.headers.set("Content-type", "text/html");
ctx.response.body = assetReadTextFileSync(
this.assetBundle,
"dist/index.html",
);
});
this.abortController = new AbortController();

View File

@ -20,15 +20,18 @@ if (!args._.length) {
const pagesPath = path.resolve(Deno.cwd(), args._[0] as string);
const port = args.port ? +args.port : 3000;
const webappDistDir = new URL("./../../dist", import.meta.url).pathname;
console.log("Webapp dist dir", webappDistDir);
// const webappDistDir = new URL("./../../dist", import.meta.url).pathname;
// console.log("Webapp dist dir", webappDistDir);
import assetBundle from "../../dist_bundle.json" assert { type: "json" };
const plugDistDir = new URL("./../plugs/dist", import.meta.url).pathname;
console.log("Pages dir", pagesPath);
const expressServer = new ExpressServer({
port: port,
pagesPath: pagesPath,
distDir: webappDistDir,
assetBundle: assetBundle,
builtinPlugDir: plugDistDir,
password: args.password,
});

View File

@ -1,14 +1,14 @@
import {
faRunning,
faHome,
faSun,
faMoon,
faRunning,
faSun,
} from "https://esm.sh/@fortawesome/free-solid-svg-icons@6.2.0";
import { FontAwesomeIcon } from "https://esm.sh/@fortawesome/react-fontawesome@0.2.0";
import { useState } from "../../../dep_web.ts";
import { Notification } from "../types.ts";
import { isMacLike } from "../../common/util.ts";
import {React} from "../../../dep_web.ts"
import { React } from "../../../dep_web.ts";
function prettyName(s: string | undefined): string {
if (!s) {
@ -87,7 +87,8 @@ export function TopBar({
onActionClick();
e.stopPropagation();
}}
title={"Open the command palette (" + (isMac ? "Cmd" : "Ctrl") + "+/)"}
title={"Open the command palette (" + (isMac ? "Cmd" : "Ctrl") +
"+/)"}
>
<FontAwesomeIcon icon={faRunning} />
</button>

View File

@ -7,6 +7,7 @@ import {
closeBracketsKeymap,
completionKeymap,
CompletionResult,
defaultHighlightStyle,
drawSelection,
dropCursor,
EditorSelection,
@ -27,7 +28,9 @@ import {
ViewUpdate,
} from "../../dep_common.ts";
import { SilverBulletHooks } from "../common/manifest.ts";
import { markdown } from "../common/markdown/index.ts";
// import { markdown } from "../common/_markdown/index.ts";
import { markdown } from "../../dep_common.ts";
import { loadMarkdownExtensions, MDExt } from "../common/markdown_ext.ts";
import buildMarkdown from "../common/parser.ts";
import { Space } from "../common/spaces/space.ts";
@ -39,6 +42,7 @@ import { EventHook } from "../plugos/hooks/event.ts";
import { eventSyscalls } from "../plugos/syscalls/event.ts";
import sandboxSyscalls from "../plugos/syscalls/sandbox.ts";
import { System } from "../plugos/system.ts";
import { AppEvent, ClickEvent } from "./app_event.ts";
import { CommandPalette } from "./components/command_palette.tsx";
import { FilterList } from "./components/filter.tsx";
@ -409,7 +413,7 @@ export class Editor {
extensions: [
markdown({
base: buildMarkdown(this.mdExtensions),
// addKeymap: true,
addKeymap: true,
}),
syntaxHighlighting(customMarkdownStyle(this.mdExtensions)),
autocompletion({