Skip to content

Commit be708d2

Browse files
authored
Refactor scramjet to compile to a single bundle, eliminating the need for globals containing state (#2)
* get basic all bundle to build * update all imports to not use $scramjet * bump rspack * get unified bundle working, update demo ui to use new paths * fix build
1 parent 6c14633 commit be708d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+536
-609
lines changed

INTERCEPTION_PROXY_BIBLE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# The Interception Proxy Bible

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default [
5353
"@typescript-eslint/no-explicit-any": "off",
5454
"@typescript-eslint/ban-ts-comment": "off",
5555
"@typescript-eslint/ban-types": "off",
56-
56+
"@typescript-eslint/no-require-imports": "off",
5757
"@typescript-eslint/no-unused-vars": [
5858
"warn",
5959
{

frontend/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<title>Vite + TS</title>
88

9-
<script src="/scram/scramjet.controller.js"></script>
9+
<script src="/scram/scramjet.all.js"></script>
1010
</head>
1111

1212
<body>

lib/index.d.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
declare const scramjetPath: string;
22

33
import * as controller from "../dist/types/controller/index.ts";
4+
import * as worker from "../dist/types/worker/index.ts";
45
import * as types from "../dist/types/types.ts";
56
import * as frame from "../dist/types/controller/frame.ts";
67

78
declare global {
8-
const ScramjetController: typeof controller.ScramjetController;
9-
const ScramjetFrame: typeof frame.ScramjetFrame;
9+
function $scramjetLoadController(): typeof controller;
10+
function $scramjetLoadWorker(): typeof worker;
11+
function $scramjetLoadClient(config: ScramjetConfig);
1012
type ScramjetController = controller.ScramjetController;
1113
type ScramjetFrame = frame.ScramjetFrame;
1214

1315
type ScramjetConfig = types.ScramjetConfig;
1416
type ScramjetInitConfig = types.ScramjetInitConfig;
17+
var $scramjetVersion: {
18+
build: string;
19+
version: string;
20+
};
1521
}
1622
export { scramjetPath };

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
"@nebula-services/bare-server-node": "^2.0.4",
4444
"@playwright/test": "^1.53.1",
4545
"@rsdoctor/rspack-plugin": "^1.1.5",
46-
"@rspack/cli": "^1.4.1",
47-
"@rspack/core": "^1.4.1",
46+
"@rspack/cli": "^1.4.8",
47+
"@rspack/core": "^1.4.8",
4848
"@types/eslint": "^9.6.1",
4949
"@types/estree": "^1.0.8",
5050
"@types/node": "^24.0.6",

pnpm-lock.yaml

Lines changed: 159 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rspack.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ export default defineConfig({
1414
mode: "development",
1515
devtool: "source-map",
1616
entry: {
17-
shared: join(__dirname, "src/shared/index.ts"),
18-
worker: join(__dirname, "src/worker/index.ts"),
19-
client: join(__dirname, "src/client/index.ts"),
20-
controller: join(__dirname, "src/controller/index.ts"),
17+
all: join(__dirname, "src/entry.ts"),
18+
// shared: join(__dirname, "src/shared/index.ts"),
19+
// worker: join(__dirname, "src/worker/index.ts"),
20+
// client: join(__dirname, "src/client/index.ts"),
21+
// controller: join(__dirname, "src/controller/index.ts"),
2122
sync: join(__dirname, "src/sync.ts"),
2223
},
2324
resolve: {

src/client/client.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ import { createLocationProxy } from "./location";
88
import { nativeGetOwnPropertyDescriptor } from "./natives";
99
import {
1010
BareClient,
11-
CookieStore,
12-
config,
13-
unrewriteUrl,
14-
rewriteUrl,
15-
} from "../shared";
16-
import type { BareClient as BareClientType } from "@mercuryworkshop/bare-mux";
11+
type BareClient as BareClientType,
12+
} from "@mercuryworkshop/bare-mux";
1713
import { createWrapFn } from "./shared/wrap";
1814
import { NavigateEvent } from "./events";
19-
import type { URLMeta } from "../shared/rewriters/url";
15+
import {
16+
rewriteUrl,
17+
unrewriteUrl,
18+
type URLMeta,
19+
} from "../shared/rewriters/url";
2020
import { SourceMaps } from "./shared/sourcemaps";
21+
import { config } from "../shared";
22+
import { CookieStore } from "../shared/cookie";
2123

2224
type NativeStore = {
2325
store: Record<string, any>;
@@ -365,15 +367,14 @@ export class ScramjetClient {
365367
}
366368

367369
hook() {
368-
// @ts-ignore
369370
const context = import.meta.webpackContext(".", {
370371
recursive: true,
371372
});
372373

373374
const modules: ScramjetModule[] = [];
374375

375376
for (const key of context.keys()) {
376-
const module: ScramjetModule = context(key);
377+
const module = context(key) as ScramjetModule;
377378
if (!key.endsWith(".ts")) continue;
378379
if (
379380
(key.startsWith("./dom/") && "window" in this.global) ||

src/client/document.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rewriteUrl } from "../shared";
1+
import { rewriteUrl } from "../shared/rewriters/url";
22
import { ScramjetClient } from "./client";
33
import { getOwnPropertyDescriptorHandler } from "./helpers";
44

src/client/dom/beacon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rewriteUrl } from "../../shared";
1+
import { rewriteUrl } from "../../shared/rewriters/url";
22
import { ScramjetClient } from "../client";
33

44
export default function (client: ScramjetClient, _self: Self) {

0 commit comments

Comments
 (0)