diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index e367b09d..74596e5c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -33,8 +33,8 @@ jobs: - name: Setup Deno uses: denoland/setup-deno@v1 with: - deno-version: v1.46 - + deno-version: v2.0.0 + - name: Run bundle build run: | deno task build diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5fc4db6c..39d74ef8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,9 +14,9 @@ jobs: - name: Setup repo uses: actions/checkout@v3 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: v1.46 + deno-version: v2.0 - name: Run build run: deno task build - name: Bundle @@ -31,4 +31,4 @@ jobs: draft: false files: | website/CHANGELOG.md - dist/silverbullet.js \ No newline at end of file + dist/silverbullet.js diff --git a/.github/workflows/server.yml b/.github/workflows/server.yml index 25bd7aa4..e1e484fe 100644 --- a/.github/workflows/server.yml +++ b/.github/workflows/server.yml @@ -14,9 +14,9 @@ jobs: uses: actions/checkout@v3 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: v1.46 + deno-version: v2.0 - name: Build bundles run: | @@ -37,4 +37,4 @@ jobs: with: draft: true files: | - silverbullet-*.zip \ No newline at end of file + silverbullet-*.zip diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2add49e..06eb0693 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -18,9 +18,9 @@ jobs: uses: actions/checkout@v3 - name: Setup Deno - uses: denoland/setup-deno@v1 + uses: denoland/setup-deno@v2 with: - deno-version: v1.46 + deno-version: v2.0 - name: Run build run: deno task build diff --git a/.gitpod.Dockerfile b/.gitpod.Dockerfile index 0601e274..ed0d8ad4 100644 --- a/.gitpod.Dockerfile +++ b/.gitpod.Dockerfile @@ -1,6 +1,6 @@ FROM gitpod/workspace-full:latest -RUN curl -fsSL https://deno.land/x/install/install.sh | sh -s v1.46.1 +RUN curl -fsSL https://deno.land/x/install/install.sh | sh -s v2.0.0 RUN /home/gitpod/.deno/bin/deno completions bash > /home/gitpod/.bashrc.d/90-deno && \ echo 'export DENO_INSTALL="/home/gitpod/.deno"' >> /home/gitpod/.bashrc.d/90-deno && \ echo 'export PATH="$DENO_INSTALL/bin:$PATH"' >> /home/gitpod/.bashrc.d/90-deno diff --git a/Dockerfile b/Dockerfile index ea73547a..7060b4c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM denoland/deno:debian-1.46.1 +FROM denoland/deno:debian-2.0.0 # The volume that will keep the space data diff --git a/cmd/compile.ts b/cmd/compile.ts index fee7a696..94dcad3d 100644 --- a/cmd/compile.ts +++ b/cmd/compile.ts @@ -3,11 +3,14 @@ import { denoPlugins } from "@luca/esbuild-deno-loader"; import * as esbuild from "esbuild"; import { bundleAssets } from "../lib/asset_bundle/builder.ts"; import type { Manifest } from "../lib/plugos/types.ts"; -import { version } from "../version.ts"; +// import { version } from "../version.ts"; -// const workerRuntimeUrl = new URL("./worker_runtime.ts", import.meta.url); -const workerRuntimeUrl = - `https://deno.land/x/silverbullet@${version}/lib/plugos/worker_runtime.ts`; +const workerRuntimeUrl = new URL( + "../lib/plugos/worker_runtime.ts", + import.meta.url, +); +// const workerRuntimeUrl = +// `https://deno.land/x/silverbullet@${version}/lib/plugos/worker_runtime.ts`; export type CompileOptions = { debug?: boolean; @@ -89,7 +92,7 @@ const manifest = ${JSON.stringify(manifest, null, 2)}; export const plug = {manifest, functionMapping}; -setupMessageListener(functionMapping, manifest); +setupMessageListener(functionMapping, manifest, self.postMessage); `; // console.log("Code:", jsFile); diff --git a/cmd/sync.ts b/cmd/sync.ts index d2e06458..48afd5f2 100644 --- a/cmd/sync.ts +++ b/cmd/sync.ts @@ -52,7 +52,7 @@ export async function syncCommand( snapshot = new Map( Object.entries(JSON.parse(await Deno.readTextFile(options.snapshot))), ); - } catch (e) { + } catch (e: any) { console.warn( "Failed to read snapshot file", e.message, diff --git a/cmd/test/runtime.test.ts b/cmd/test/runtime.test.ts index 9f9e1d7c..7031ef50 100644 --- a/cmd/test/runtime.test.ts +++ b/cmd/test/runtime.test.ts @@ -1,14 +1,9 @@ import { createSandbox } from "../../lib/plugos/sandboxes/deno_worker_sandbox.ts"; import { System } from "../../lib/plugos/system.ts"; -import { assert, assertEquals } from "@std/assert"; +import { assertEquals } from "@std/assert"; import { compileManifest } from "../compile.ts"; import * as esbuild from "esbuild"; -import { - createSandbox as createNoSandbox, - runWithSystemLock, -} from "../../lib/plugos/sandboxes/no_sandbox.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; -import { sleep } from "../../lib/async.ts"; Deno.test("Run a deno sandbox", { sanitizeResources: false, @@ -56,39 +51,6 @@ Deno.test("Run a deno sandbox", { await system.unloadAll(); - // Now load directly from module - const { plug: plugExport } = await import( - `file://${workerPath}` - ); - - const plug2 = await system.load("test", createNoSandbox(plugExport)); - - let running = false; - await Promise.all([ - runWithSystemLock(system, async () => { - console.log("Starting first run"); - running = true; - await sleep(5); - assertEquals({ - addedNumbers: 3, - yamlMessage: "hello: world\n", - }, await plug2.invoke("boot", [])); - console.log("Done first run"); - running = false; - }), - runWithSystemLock(system, async () => { - assert(!running); - console.log("Starting second run"); - assertEquals({ - addedNumbers: 3, - yamlMessage: "hello: world\n", - }, await plug2.invoke("boot", [])); - console.log("Done second run"); - }), - ]); - - await system.unloadAll(); - await Deno.remove(tempDir, { recursive: true }); esbuild.stop(); diff --git a/common/space_lua/runtime.ts b/common/space_lua/runtime.ts index f2f8258d..0b363c18 100644 --- a/common/space_lua/runtime.ts +++ b/common/space_lua/runtime.ts @@ -433,14 +433,14 @@ export class LuaReturn extends Error { export class LuaRuntimeError extends Error { constructor( - readonly message: string, + override readonly message: string, public context: ASTCtx, cause?: Error, ) { super(message, cause); } - toString() { + override toString() { return `LuaRuntimeError: ${this.message} at ${this.context.from}, ${this.context.to}`; } } diff --git a/common/spaces/disk_space_primitives.ts b/common/spaces/disk_space_primitives.ts index 34171b89..520a8a4b 100644 --- a/common/spaces/disk_space_primitives.ts +++ b/common/spaces/disk_space_primitives.ts @@ -243,7 +243,7 @@ async function* walkPreserveSymlinks( if (dirEntry.isSymlink) { try { entry = await Deno.stat(fullPath); - } catch (e) { + } catch (e: any) { console.error("Error reading symlink", fullPath, e.message); } } diff --git a/common/spaces/fallback_space_primitives.ts b/common/spaces/fallback_space_primitives.ts index aefae7df..e5e43931 100644 --- a/common/spaces/fallback_space_primitives.ts +++ b/common/spaces/fallback_space_primitives.ts @@ -21,7 +21,7 @@ export class FallbackSpacePrimitives implements SpacePrimitives { async readFile(name: string): Promise<{ data: Uint8Array; meta: FileMeta }> { try { return await this.primary.readFile(name); - } catch (e) { + } catch (e: any) { if (e.message === "Not found") { console.info("Reading file content from fallback for", name); } else { @@ -58,7 +58,7 @@ export class FallbackSpacePrimitives implements SpacePrimitives { try { const meta = await this.fallback.getFileMeta(name); return { ...meta, noSync: true }; - } catch (fallbackError) { + } catch (fallbackError: any) { console.error( "Error during getFileMeta fallback", fallbackError.message, diff --git a/common/syscalls/jsonschema.ts b/common/syscalls/jsonschema.ts index ff8e1a71..1d225c97 100644 --- a/common/syscalls/jsonschema.ts +++ b/common/syscalls/jsonschema.ts @@ -35,7 +35,7 @@ export function jsonschemaSyscalls(): SysCallMapping { text = text.replace(/^data[\.\s]/, ""); return text; } - } catch (e) { + } catch (e: any) { return e.message; } }, diff --git a/deno.json b/deno.json index a04d6185..5787cc88 100644 --- a/deno.json +++ b/deno.json @@ -159,8 +159,8 @@ "react-icons/types": "https://deno.land/x/react_icons@1.0.9/mod.ts", "s3_lite_client/": "https://deno.land/x/s3_lite_client@0.4.0/", "style-mod": "https://esm.sh/style-mod@4.1.2", - "turndown": "https://cdn.skypack.dev/turndown@7.2.0", + "turndown": "https://esm.sh/turndown@7.2.0", "ajv": "https://esm.sh/ajv@8.17.1?target=es2022", - "turndown-plugin-gfm": "https://cdn.skypack.dev/@joplin/turndown-plugin-gfm@1.0.56" + "turndown-plugin-gfm": "https://esm.sh/@joplin/turndown-plugin-gfm@1.0.56" } } diff --git a/lib/deps_server.ts b/lib/deps_server.ts index 33007965..6dc57483 100644 --- a/lib/deps_server.ts +++ b/lib/deps_server.ts @@ -6,8 +6,4 @@ export { walk } from "https://deno.land/std@0.165.0/fs/mod.ts"; export * as path from "https://deno.land/std@0.165.0/path/mod.ts"; export { mime } from "https://deno.land/x/mimetypes@v1.0.0/mod.ts"; export * as YAML from "https://deno.land/std@0.184.0/yaml/mod.ts"; -export { - createClient, - type DynamoDBClient, -} from "https://denopkg.com/chiefbiiko/dynamodb@55e60a5/mod.ts"; export { Cron } from "https://deno.land/x/croner@4.4.1/src/croner.js"; diff --git a/lib/plugos/worker_runtime.ts b/lib/plugos/worker_runtime.ts index a173ad54..c9160b1e 100644 --- a/lib/plugos/worker_runtime.ts +++ b/lib/plugos/worker_runtime.ts @@ -6,6 +6,10 @@ declare global { function syscall(name: string, ...args: any[]): Promise; } +let workerPostMessage = (_msg: ControllerMessage): void => { + throw new Error("Not initialized yet"); +}; + // Are we running in a (web) worker? // Determines if we're running in a web worker environment (Deno or browser) @@ -18,8 +22,6 @@ const runningAsWebWorker = typeof window === "undefined" && // @ts-ignore: globalThis typeof globalThis.WebSocketPair === "undefined"; -// console.log("Running as web worker:", runningAsWebWorker); - if (typeof Deno === "undefined") { // @ts-ignore: Deno hack self.Deno = { @@ -46,10 +48,6 @@ const pendingRequests = new Map< let syscallReqId = 0; -function workerPostMessage(msg: ControllerMessage) { - self.postMessage(msg); -} - if (runningAsWebWorker) { globalThis.syscall = async (name: string, ...args: any[]) => { return await new Promise((resolve, reject) => { @@ -69,12 +67,14 @@ export function setupMessageListener( // deno-lint-ignore ban-types functionMapping: Record, manifest: any, + postMessageFn: (msg: ControllerMessage) => void, ) { if (!runningAsWebWorker) { // Don't do any of this stuff if this is not a web worker // This caters to the NoSandbox run mode return; } + workerPostMessage = postMessageFn; self.addEventListener("message", (event: { data: WorkerMessage }) => { (async () => { const data = event.data; diff --git a/plugs/index/lint.ts b/plugs/index/lint.ts index e1c4eeba..7a8b3732 100644 --- a/plugs/index/lint.ts +++ b/plugs/index/lint.ts @@ -191,7 +191,7 @@ async function lintYaml( }; } } - } catch (e) { + } catch (e: any) { const errorMatch = errorRegex.exec(e.message); if (errorMatch) { console.log("YAML error", e.message); diff --git a/plugs/index/page.ts b/plugs/index/page.ts index 88fc3300..f544693f 100644 --- a/plugs/index/page.ts +++ b/plugs/index/page.ts @@ -155,7 +155,7 @@ async function lintYaml( ): Promise { try { await YAML.parse(yamlText); - } catch (e) { + } catch (e: any) { const errorMatch = errorRegex.exec(e.message); if (errorMatch) { console.log("YAML error", e.message); diff --git a/server/crypto.ts b/server/crypto.ts index eda441b6..094c3295 100644 --- a/server/crypto.ts +++ b/server/crypto.ts @@ -78,7 +78,7 @@ export class JWTIssuer { const data = encoder.encode(message); // Generate the hash - const hashBuffer = await window.crypto.subtle.digest("SHA-256", data); + const hashBuffer = await globalThis.crypto.subtle.digest("SHA-256", data); // Transform the hash into a hex string return Array.from(new Uint8Array(hashBuffer)).map((b) => diff --git a/web/boot.ts b/web/boot.ts index 0489bb88..16718b10 100644 --- a/web/boot.ts +++ b/web/boot.ts @@ -10,14 +10,14 @@ safeRun(async () => { syncMode ? "in Sync Mode" : "in Online Mode", ); - if (window.silverBulletConfig.readOnly) { + if (globalThis.silverBulletConfig.readOnly) { console.log("Running in read-only mode"); } const client = new Client( document.getElementById("sb-root")!, syncMode, - window.silverBulletConfig.readOnly, + globalThis.silverBulletConfig.readOnly, ); // @ts-ignore: on purpose globalThis.client = client; diff --git a/web/client.ts b/web/client.ts index 0b697bb2..6fdea817 100644 --- a/web/client.ts +++ b/web/client.ts @@ -147,7 +147,7 @@ export class Client implements ConfigContainer { this.fullSyncCompleted = true; } // Generate a semi-unique prefix for the database so not to reuse databases for different space paths - this.dbPrefix = "" + simpleHash(window.silverBulletConfig.spaceFolderPath); + this.dbPrefix = "" + simpleHash(globalThis.silverBulletConfig.spaceFolderPath); this.onLoadPageRef = parsePageRefFromURI(); } @@ -503,7 +503,7 @@ export class Client implements ConfigContainer { async initSpace(): Promise { this.httpSpacePrimitives = new HttpSpacePrimitives( location.origin, - window.silverBulletConfig.spaceFolderPath, + globalThis.silverBulletConfig.spaceFolderPath, ); let remoteSpacePrimitives: SpacePrimitives = this.httpSpacePrimitives; diff --git a/web/client_system.ts b/web/client_system.ts index d8c0ea2c..b5170d3a 100644 --- a/web/client_system.ts +++ b/web/client_system.ts @@ -63,7 +63,7 @@ export class ClientSystem extends CommonSystem { ds, eventHook, readOnlyMode, - window.silverBulletConfig.enableSpaceScript, + globalThis.silverBulletConfig.enableSpaceScript, ); // Only set environment to "client" when running in thin client mode, otherwise we run everything locally (hybrid) this.system = new System( diff --git a/web/cm_plugins/code_copy.ts b/web/cm_plugins/code_copy.ts index 5691097e..588a835a 100644 --- a/web/cm_plugins/code_copy.ts +++ b/web/cm_plugins/code_copy.ts @@ -20,7 +20,7 @@ class CodeCopyWidget extends WidgetType { super(); } - eq(other: CodeCopyWidget) { + override eq(other: CodeCopyWidget) { return other.value == this.value; } @@ -53,7 +53,7 @@ class CodeCopyWidget extends WidgetType { return wrap; } - ignoreEvent() { + override ignoreEvent() { return true; } } diff --git a/web/cm_plugins/iframe_widget.ts b/web/cm_plugins/iframe_widget.ts index 9b0fa61f..72c894c8 100644 --- a/web/cm_plugins/iframe_widget.ts +++ b/web/cm_plugins/iframe_widget.ts @@ -67,13 +67,13 @@ export class IFrameWidget extends WidgetType { return iframe; } - get estimatedHeight(): number { + override get estimatedHeight(): number { const cachedHeight = this.client.getCachedWidgetHeight(this.bodyText); // console.log("Calling estimated height", this.bodyText, cachedHeight); return cachedHeight > 0 ? cachedHeight : 150; } - eq(other: WidgetType): boolean { + override eq(other: WidgetType): boolean { return ( other instanceof IFrameWidget && other.bodyText === this.bodyText diff --git a/web/cm_plugins/inline_content.ts b/web/cm_plugins/inline_content.ts index 60e37f83..b5e2bbc3 100644 --- a/web/cm_plugins/inline_content.ts +++ b/web/cm_plugins/inline_content.ts @@ -32,12 +32,12 @@ class InlineContentWidget extends WidgetType { super(); } - eq(other: InlineContentWidget) { + override eq(other: InlineContentWidget) { return other.url === this.url && other.title === this.title && JSON.stringify(other.dim) === JSON.stringify(this.dim); } - get estimatedHeight(): number { + override get estimatedHeight(): number { const cachedHeight = this.client.getCachedWidgetHeight( `content:${this.url}`, ); diff --git a/web/cm_plugins/markdown_widget.ts b/web/cm_plugins/markdown_widget.ts index 2b6ba7a8..fa115b55 100644 --- a/web/cm_plugins/markdown_widget.ts +++ b/web/cm_plugins/markdown_widget.ts @@ -295,12 +295,12 @@ export class MarkdownWidget extends WidgetType { } } - get estimatedHeight(): number { + override get estimatedHeight(): number { const cacheItem = this.client.getWidgetCache(this.cacheKey); return cacheItem ? cacheItem.height : -1; } - eq(other: WidgetType): boolean { + override eq(other: WidgetType): boolean { return ( other instanceof MarkdownWidget && other.bodyText === this.bodyText && other.cacheKey === this.cacheKey diff --git a/web/cm_plugins/table.ts b/web/cm_plugins/table.ts index 3d619331..6db2186f 100644 --- a/web/cm_plugins/table.ts +++ b/web/cm_plugins/table.ts @@ -65,7 +65,7 @@ class TableViewWidget extends WidgetType { return dom; } - get estimatedHeight(): number { + override get estimatedHeight(): number { const height = this.client.getCachedWidgetHeight( `table:${this.tableBodyText}`, ); @@ -73,7 +73,7 @@ class TableViewWidget extends WidgetType { return height; } - eq(other: WidgetType): boolean { + override eq(other: WidgetType): boolean { return ( other instanceof TableViewWidget && other.tableBodyText === this.tableBodyText diff --git a/web/cm_plugins/util.ts b/web/cm_plugins/util.ts index 4b567c5d..eccac5ef 100644 --- a/web/cm_plugins/util.ts +++ b/web/cm_plugins/util.ts @@ -62,7 +62,7 @@ export class LinkWidget extends WidgetType { return anchor; } - eq(other: WidgetType): boolean { + override eq(other: WidgetType): boolean { return other instanceof LinkWidget && this.options.from === other.options.from && this.options.text === other.options.text && diff --git a/web/editor_ui.tsx b/web/editor_ui.tsx index 2edc51e2..ebaab326 100644 --- a/web/editor_ui.tsx +++ b/web/editor_ui.tsx @@ -228,7 +228,7 @@ export class MainUI { }} actionButtons={[ // Sync button - ...(!window.silverBulletConfig.syncOnly && + ...(!globalThis.silverBulletConfig.syncOnly && !viewState.config.hideSyncButton) // If we support syncOnly, don't show this toggle button ? [{ diff --git a/web/navigator.ts b/web/navigator.ts index ca8dadd2..5a81df2b 100644 --- a/web/navigator.ts +++ b/web/navigator.ts @@ -58,18 +58,18 @@ export class PathPageNavigator { const cleanState = { ...currentState, pos: undefined, anchor: undefined }; this.openPages.set(currentState.page || this.indexPage, cleanState); if (!replaceState) { - window.history.replaceState( + globalThis.history.replaceState( cleanState, "", `/${encodePageURI(currentState.page)}`, ); - window.history.pushState( + globalThis.history.pushState( pageRef, "", `/${encodePageURI(pageRef.page)}`, ); } else { - window.history.replaceState( + globalThis.history.replaceState( pageRef, "", `/${encodePageURI(pageRef.page)}`, diff --git a/web/syscalls/editor.ts b/web/syscalls/editor.ts index 26d8cedb..8c5a0b67 100644 --- a/web/syscalls/editor.ts +++ b/web/syscalls/editor.ts @@ -91,7 +91,7 @@ export function editorSyscalls(client: Client): SysCallMapping { ); }, "editor.goHistory": (_ctx, delta: number) => { - window.history.go(delta); + globalThis.history.go(delta); }, "editor.downloadFile": (_ctx, filename: string, dataUrl: string) => { const link = document.createElement("a");