Skip to content

Commit

Permalink
Migration to Deno 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zefhemel committed Oct 10, 2024
1 parent 3319c7f commit 6a30284
Show file tree
Hide file tree
Showing 31 changed files with 60 additions and 99 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -31,4 +31,4 @@ jobs:
draft: false
files: |
website/CHANGELOG.md
dist/silverbullet.js
dist/silverbullet.js
6 changes: 3 additions & 3 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -37,4 +37,4 @@ jobs:
with:
draft: true
files: |
silverbullet-*.zip
silverbullet-*.zip
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 8 additions & 5 deletions cmd/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion cmd/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 1 addition & 39 deletions cmd/test/runtime.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions common/space_lua/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/spaces/disk_space_primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/spaces/fallback_space_primitives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion common/syscalls/jsonschema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function jsonschemaSyscalls(): SysCallMapping {
text = text.replace(/^data[\.\s]/, "");
return text;
}
} catch (e) {
} catch (e: any) {
return e.message;
}
},
Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
4 changes: 0 additions & 4 deletions lib/deps_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
12 changes: 6 additions & 6 deletions lib/plugos/worker_runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ declare global {
function syscall(name: string, ...args: any[]): Promise<any>;
}

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)
Expand All @@ -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 = {
Expand All @@ -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) => {
Expand All @@ -69,12 +67,14 @@ export function setupMessageListener(
// deno-lint-ignore ban-types
functionMapping: Record<string, Function>,
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;
Expand Down
2 changes: 1 addition & 1 deletion plugs/index/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion plugs/index/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ async function lintYaml(
): Promise<LintDiagnostic | undefined> {
try {
await YAML.parse(yamlText);
} catch (e) {
} catch (e: any) {
const errorMatch = errorRegex.exec(e.message);
if (errorMatch) {
console.log("YAML error", e.message);
Expand Down
2 changes: 1 addition & 1 deletion server/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
4 changes: 2 additions & 2 deletions web/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions web/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -503,7 +503,7 @@ export class Client implements ConfigContainer {
async initSpace(): Promise<SpacePrimitives> {
this.httpSpacePrimitives = new HttpSpacePrimitives(
location.origin,
window.silverBulletConfig.spaceFolderPath,
globalThis.silverBulletConfig.spaceFolderPath,
);

let remoteSpacePrimitives: SpacePrimitives = this.httpSpacePrimitives;
Expand Down
2 changes: 1 addition & 1 deletion web/client_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions web/cm_plugins/code_copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CodeCopyWidget extends WidgetType {
super();
}

eq(other: CodeCopyWidget) {
override eq(other: CodeCopyWidget) {
return other.value == this.value;
}

Expand Down Expand Up @@ -53,7 +53,7 @@ class CodeCopyWidget extends WidgetType {
return wrap;
}

ignoreEvent() {
override ignoreEvent() {
return true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions web/cm_plugins/iframe_widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 6a30284

Please sign in to comment.