From 9f2d22ed371b3a8c303434e15475537aa7297348 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Fri, 7 Mar 2025 17:08:01 -0800 Subject: [PATCH] actually use ts --- package.json | 2 +- src/client/shared/requests/xmlhttprequest.ts | 1 + src/client/swruntime.ts | 1 + src/shared/rewriters/js.ts | 6 ++--- src/shared/rewriters/worker.ts | 2 +- src/worker/fetch.ts | 4 ++-- tsconfig.json | 23 +++++++++++++------- 7 files changed, 24 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 5cf1a73..39efff8 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "https://github.com/MercuryWorkshop/scramjet" }, "scripts": { - "build": "rspack build --mode production", + "build": "tsc && rspack build --mode production", "rewriter:build": "cd rewriter/wasm/ && bash build.sh && cd ../../", "dev": "node server.js", "dev:debug": "DEBUG=1 node server.js", diff --git a/src/client/shared/requests/xmlhttprequest.ts b/src/client/shared/requests/xmlhttprequest.ts index b972b78..e5b8041 100644 --- a/src/client/shared/requests/xmlhttprequest.ts +++ b/src/client/shared/requests/xmlhttprequest.ts @@ -40,6 +40,7 @@ export default function (client: ScramjetClient, self: Self) { // sync xhr to service worker is not supported // there's a nice way of polyfilling this though, we can spin on an atomic using sharedarraybuffer. this will maintain the sync behavior + // @ts-expect-error ts dum const sab = new SharedArrayBuffer(1024, { maxByteLength: 2147483647 }); const view = new DataView(sab); diff --git a/src/client/swruntime.ts b/src/client/swruntime.ts index 4afdffd..88d296b 100644 --- a/src/client/swruntime.ts +++ b/src/client/swruntime.ts @@ -26,6 +26,7 @@ export class ScramjetServiceWorkerRuntime { } hook() { + // @ts-expect-error TODO this.client.global.registration = { // TODO IMPLEMENT SCOPES scope: this.client.url.href, diff --git a/src/shared/rewriters/js.ts b/src/shared/rewriters/js.ts index 7cf1d20..a78ba21 100644 --- a/src/shared/rewriters/js.ts +++ b/src/shared/rewriters/js.ts @@ -102,7 +102,7 @@ function rewriteJsWasm( } function rewriteJsInner( - js: string | ArrayBuffer, + js: string | Uint8Array, url: string | null, meta: URLMeta, module = false @@ -117,7 +117,7 @@ function rewriteJsInner( } export function rewriteJs( - js: string | ArrayBuffer, + js: string | Uint8Array, url: string | null, meta: URLMeta, module = false @@ -126,7 +126,7 @@ export function rewriteJs( } export function rewriteJsWithMap( - js: string | ArrayBuffer, + js: string | Uint8Array, url: string | null, meta: URLMeta, module = false diff --git a/src/shared/rewriters/worker.ts b/src/shared/rewriters/worker.ts index 912fe1d..7d29473 100644 --- a/src/shared/rewriters/worker.ts +++ b/src/shared/rewriters/worker.ts @@ -3,7 +3,7 @@ import { rewriteJs } from "./js"; import { URLMeta } from "./url"; export function rewriteWorkers( - js: string | ArrayBuffer, + js: string | Uint8Array, type: string, url: string, meta: URLMeta diff --git a/src/worker/fetch.ts b/src/worker/fetch.ts index d3f3d17..b341086 100644 --- a/src/worker/fetch.ts +++ b/src/worker/fetch.ts @@ -360,7 +360,7 @@ async function rewriteBody( } case "script": let { js, tag, map } = rewriteJsWithMap( - await response.arrayBuffer(), + new Uint8Array(await response.arrayBuffer()), response.finalURL, meta, workertype === "module" @@ -376,7 +376,7 @@ async function rewriteBody( case "sharedworker": case "worker": return rewriteWorkers( - await response.arrayBuffer(), + new Uint8Array(await response.arrayBuffer()), workertype, response.finalURL, meta diff --git a/tsconfig.json b/tsconfig.json index e9094b3..edc6a70 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,10 +1,17 @@ { - "compilerOptions": { - // "allowJs": true, - "rootDir": "./src", - "target": "ES2022", - "moduleResolution": "Bundler", - "module": "ES2022" - }, - "include": ["src"] + "compilerOptions": { + // "allowJs": true, + "rootDir": "./src", + "target": "ES2022", + "moduleResolution": "Bundler", + "module": "ES2022", + "noEmit": true, + "skipLibCheck": true + }, + "include": [ + "src" + ], + "exclude": [ + "node_modules" + ] }