Skip to content

Commit e283ed1

Browse files
committed
[scramjet] delete scramjet.all.js, add non esm builds of bundled
1 parent fc6b93c commit e283ed1

File tree

8 files changed

+77
-244
lines changed

8 files changed

+77
-244
lines changed

packages/scramjet/lib/noop.js

Whitespace-only changes.

packages/scramjet/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
},
3434
"exports": {
3535
".": {
36-
"types": "./dist/types/types.d.ts",
37-
"default": "./lib/noop.js"
36+
"types": "./dist/types/index.d.ts",
37+
"default": "./dist/scramjet.mjs"
3838
},
3939
"./path": {
4040
"types": "./lib/index.d.ts",
4141
"default": "./lib/index.cjs"
4242
},
4343
"./bundled": {
4444
"types": "./dist/types/index.d.ts",
45-
"default": "./dist/scramjet.bundle.js"
45+
"default": "./dist/scramjet_bundled.mjs"
4646
}
4747
},
4848
"files": [

packages/scramjet/src/client/entry.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,4 @@ export function loadAndHook(init: ScramjetClientEntryInit) {
5959
const urlchangeev = new UrlChangeEvent(client.url.href);
6060
if (!client.isSubframe) client.frame?.dispatchEvent(urlchangeev);
6161
}
62-
63-
Reflect.deleteProperty(globalThis, "WASM");
6462
}

packages/scramjet/src/entry.ts

Lines changed: 0 additions & 211 deletions
This file was deleted.

packages/scramjet/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22
// as such it exports everything in scramjet
33
// the entry point for scramjet.all.js (what most sites wil use) is entry.ts
44

5+
import { setWasm } from "@rewriters/wasm";
56
import "./global.d";
67
export * from "./client";
78
export * from "./controller";
89
export * from "./shared";
910
export * from "./worker";
10-
export * from "./entry";
1111
export * from "./symbols";
1212
export * from "./types";
13+
14+
declare const REWRITERWASM: string | undefined;
15+
16+
// bundled build will have the wasm binary inlined as a base64 string
17+
if (REWRITERWASM) {
18+
setWasm(Uint8Array.from(atob(REWRITERWASM), (c) => c.charCodeAt(0)));
19+
}

packages/scramjet/src/shared/rewriters/wasm.ts

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,17 @@ import { rewriteCss } from "@rewriters/css";
1111
import { rewriteJs } from "@rewriters/js";
1212
import { CookieJar } from "@/shared/cookie";
1313

14-
let wasm_u8: Uint8Array<ArrayBuffer>;
15-
16-
declare const REWRITERWASM: string | undefined;
17-
if (REWRITERWASM)
18-
wasm_u8 = Uint8Array.from(atob(REWRITERWASM), (c) => c.charCodeAt(0));
19-
else if (self.WASM)
20-
wasm_u8 = Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0));
21-
22-
// only use in sw
23-
export async function asyncSetWasm() {
24-
const buf = await fetch(config.files.wasm).then((r) => r.arrayBuffer());
25-
wasm_u8 = new Uint8Array(buf);
14+
let wasm_u8: Uint8Array;
15+
export function setWasm(u8: Uint8Array | ArrayBuffer) {
16+
wasm_u8 = u8 instanceof Uint8Array ? u8 : new Uint8Array(u8);
2617
}
2718

2819
export const textDecoder = new TextDecoder();
2920
let MAGIC = "\0asm".split("").map((x) => x.charCodeAt(0));
3021

3122
function initWasm() {
3223
if (!(wasm_u8 instanceof Uint8Array))
33-
throw new Error("rewriter wasm not found (was it fetched correctly?)");
24+
throw new Error("rewriter wasm not found (was setWasm called?)");
3425

3526
if (![...wasm_u8.slice(0, 4)].every((x, i) => x === MAGIC[i]))
3627
throw new Error(
@@ -39,7 +30,7 @@ function initWasm() {
3930
);
4031

4132
initSync({
42-
module: new WebAssembly.Module(wasm_u8),
33+
module: new WebAssembly.Module(wasm_u8 as unknown as BufferSource),
4334
});
4435
}
4536

packages/scramjet/src/types.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ export interface ScramjetInitConfig
7676
};
7777
}
7878
declare global {
79-
var $scramjetLoadController: () => typeof controller;
80-
var $scramjetLoadClient: () => typeof client;
81-
var $scramjetLoadWorker: () => typeof worker;
82-
var $scramjetVersion: ScramjetVersionInfo;
8379
interface Window {
8480
WASM: string;
8581
REAL_WASM: Uint8Array;

0 commit comments

Comments
 (0)