Skip to content

Commit f3fc99d

Browse files
authored
Merge pull request #25 from Percslol/main
[chrome] [scramjet/controller] [scramjet/demo] misc improvements
2 parents 5e66ad6 + 2ede895 commit f3fc99d

File tree

28 files changed

+294
-152
lines changed

28 files changed

+294
-152
lines changed

.github/workflows/main.yml

Lines changed: 126 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,15 @@ jobs:
129129
name: scramjet
130130
path: |
131131
packages/scramjet/packages/core/dist/*
132-
frontend:
133-
name: Build Frontend
132+
133+
package-validation:
134+
name: Validate Package Structure
134135
runs-on: ubuntu-latest
135-
permissions: write-all
136136
needs: [build]
137137

138138
steps:
139139
- name: Checkout code
140140
uses: actions/checkout@v4
141-
with:
142-
submodules: recursive
143141

144142
- name: Setup pnpm
145143
uses: pnpm/action-setup@v4
@@ -156,65 +154,21 @@ jobs:
156154
- name: Get artifacts
157155
uses: actions/download-artifact@v4
158156
with:
159-
name: scramjet
160-
path: packages/scramjet/packages/core/dist
161-
162-
- name: Build Dreamland
163-
run: pnpm build:dreamland
164-
165-
# - name: Get Chii submodule commit hash
166-
# id: chii-hash
167-
# run: echo "hash=$(git submodule status chii | awk '{print $1}')" >> $GITHUB_OUTPUT
168-
169-
# - name: Cache Chii build output
170-
# id: chii-cache
171-
# uses: actions/cache@v4
172-
# with:
173-
# path: |
174-
# chii/public
175-
# chii/front_end/dist
176-
# key: chii-${{ runner.os }}-${{ steps.chii-hash.outputs.hash }}
177-
178-
# - name: Install Depot Tools
179-
# if: steps.chii-cache.outputs.cache-hit != 'true'
180-
# uses: newkdev/setup-depot-tools@v1.0.1
181-
182-
# - name: Initialize Chii front_end
183-
# if: steps.chii-cache.outputs.cache-hit != 'true'
184-
# run: |
185-
# cd chii
186-
# pnpm init:front_end
187-
188-
# - name: Build Chii
189-
# if: steps.chii-cache.outputs.cache-hit != 'true'
190-
# run: |
191-
# cd chii
192-
# pnpm build
193-
194-
- name: Build Frontend
195-
run: |
196-
SKIP_CORE=1 pnpm build
197-
VITE_PUTER_BRANDING=1 VITE_ISOLATION_ORIGIN="https://puter.zone" pnpm build:chrome
157+
name: packaged-scramjet
158+
path: packages/scramjet/packages/core
198159

199-
- name: Upload Artifact (dist)
200-
uses: actions/upload-artifact@v4
201-
with:
202-
name: frontend
203-
path: |
204-
./packages/chrome/dist
160+
- name: Extract package
161+
run: tar xvf mercuryworkshop-scramjet-*.tgz package --strip-components=1
162+
working-directory: packages/scramjet/packages/core
205163

206-
- name: Upload pages artifact
207-
uses: actions/upload-pages-artifact@v3
208-
with:
209-
path: "./packages/chrome/dist"
164+
- name: Run package validation tests
165+
run: pnpm test:package
166+
working-directory: packages/scramjet/packages/core
210167

211-
- name: Deploy to github
212-
id: deployment
213-
uses: actions/deploy-pages@v4
214168
tests:
215169
name: Run Scramjet Tests
216170
runs-on: ubuntu-latest
217-
needs: build
171+
needs: [build, package-validation]
218172
env:
219173
PLAYWRIGHT_BROWSERS_PATH: .playwright-browsers
220174
steps:
@@ -262,7 +216,7 @@ jobs:
262216
rewritertests:
263217
name: "Run Rewriter Tests"
264218
runs-on: ubuntu-latest
265-
needs: [build]
219+
needs: [build, package-validation]
266220

267221
steps:
268222
- name: Checkout code
@@ -290,3 +244,116 @@ jobs:
290244
- name: Run Tests
291245
run: cargo test
292246
working-directory: packages/scramjet/packages/core/rewriter/native
247+
248+
frontend:
249+
name: Build Frontend
250+
runs-on: ubuntu-latest
251+
permissions: write-all
252+
needs: [build, package-validation]
253+
254+
steps:
255+
- name: Checkout code
256+
uses: actions/checkout@v4
257+
with:
258+
submodules: recursive
259+
260+
- name: Setup pnpm
261+
uses: pnpm/action-setup@v4
262+
263+
- name: Setup Node.js
264+
uses: actions/setup-node@v4
265+
with:
266+
node-version: "22"
267+
cache: "pnpm"
268+
269+
- name: Install dependencies
270+
run: pnpm install
271+
272+
- name: Get artifacts
273+
uses: actions/download-artifact@v4
274+
with:
275+
name: scramjet
276+
path: packages/scramjet/packages/core/dist
277+
278+
- name: Build Dreamland
279+
run: pnpm build:dreamland
280+
281+
# - name: Get Chii submodule commit hash
282+
# id: chii-hash
283+
# run: echo "hash=$(git submodule status chii | awk '{print $1}')" >> $GITHUB_OUTPUT
284+
285+
# - name: Cache Chii build output
286+
# id: chii-cache
287+
# uses: actions/cache@v4
288+
# with:
289+
# path: |
290+
# chii/public
291+
# chii/front_end/dist
292+
# key: chii-${{ runner.os }}-${{ steps.chii-hash.outputs.hash }}
293+
294+
# - name: Install Depot Tools
295+
# if: steps.chii-cache.outputs.cache-hit != 'true'
296+
# uses: newkdev/setup-depot-tools@v1.0.1
297+
298+
# - name: Initialize Chii front_end
299+
# if: steps.chii-cache.outputs.cache-hit != 'true'
300+
# run: |
301+
# cd chii
302+
# pnpm init:front_end
303+
304+
# - name: Build Chii
305+
# if: steps.chii-cache.outputs.cache-hit != 'true'
306+
# run: |
307+
# cd chii
308+
# pnpm build
309+
310+
- name: Build Frontend
311+
run: |
312+
SKIP_CORE=1 pnpm build
313+
VITE_PUTER_BRANDING=1 VITE_ISOLATION_ORIGIN="https://puter.zone" pnpm build:chrome
314+
315+
- name: Upload Artifact (dist)
316+
uses: actions/upload-artifact@v4
317+
with:
318+
name: frontend
319+
path: |
320+
./packages/chrome/dist
321+
322+
pages:
323+
name: Upload to Github Pages
324+
runs-on: ubuntu-latest
325+
# make sure to add rewritertests and tests, omitting them due to bugs currently
326+
needs: [frontend]
327+
permissions: write-all
328+
if: github.ref == 'refs/heads/main'
329+
330+
steps:
331+
- name: Checkout code
332+
uses: actions/checkout@v4
333+
334+
- name: Setup pnpm
335+
uses: pnpm/action-setup@v4
336+
337+
- name: Setup Node.js
338+
uses: actions/setup-node@v4
339+
with:
340+
node-version: "22"
341+
cache: "pnpm"
342+
343+
- name: Install dependencies
344+
run: pnpm install
345+
346+
- name: Get artifacts
347+
uses: actions/download-artifact@v4
348+
with:
349+
name: frontend
350+
path: "./packages/chrome/dist"
351+
352+
- name: Upload pages artifact
353+
uses: actions/upload-pages-artifact@v3
354+
with:
355+
path: "./packages/chrome/dist"
356+
357+
- name: Deploy to github
358+
id: deployment
359+
uses: actions/deploy-pages@v4

amplify.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ frontend:
5252
- pnpm build
5353
- VITE_PUTER_BRANDING=1 VITE_ISOLATION_ORIGIN="https://puter.zone" pnpm build:chrome
5454

55-
5655
artifacts:
5756
baseDirectory: packages/scramjet/packages/core/dist
5857
files:

packages/chrome/src/proxy/Controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ export async function controllerForURL(url: URL): Promise<Controller> {
217217
let channel = new MessageChannel();
218218

219219
const controllerId = makeId();
220-
let prefix = new URL(baseurl + basePrefix + controllerId);
220+
let prefix = new URL(baseurl.origin + basePrefix + controllerId + "/");
221221

222222
controller = new Controller(prefix, controllerId, channel, rootdomain);
223223
controllers.push(controller);

packages/chrome/src/proxy/scramjet.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,29 +244,26 @@ export function createFetchHandler(controller: Controller) {
244244

245245
const getWorkerInjectScripts: ScramjetInterface["getWorkerInjectScripts"] = (
246246
meta,
247-
js,
248-
type
247+
type,
248+
script
249249
) => {
250-
const module = type === "module";
251250
let str = "";
252-
const script = (script: string) => {
253-
if (module) {
254-
str += `import "${script}"\n`;
255-
} else {
256-
str += `importScripts("${script}");\n`;
257-
}
258-
};
259251

260252
const injectLoad = `
261253
$injectLoad({
262254
config: ${JSON.stringify(makeConfig())},
263255
cookies: null,
264256
wisp: ${JSON.stringify(wispUrl)},
257+
codecEncode: ${codecEncode.toString()},
258+
codecDecode: ${codecDecode.toString()},
259+
prefix: "${controller.prefix.href}",
265260
});
266261
`;
267-
script(controller.prefix.href + virtualWasmPath);
268-
script(controller.prefix.href + virtualInjectPath);
269-
script(`data:application/javascript;base64,${base64Encode(injectLoad)}`);
262+
str += script(controller.prefix.href + virtualWasmPath);
263+
str += script(controller.prefix.href + virtualInjectPath);
264+
str += script(
265+
`data:application/javascript;base64,${base64Encode(injectLoad)}`
266+
);
270267

271268
return str;
272269
};

packages/inject/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,6 @@ function $injectLoadError(
178178
}
179179

180180
// @ts-expect-error
181-
window.$injectLoadError = $injectLoadError;
181+
globalThis.$injectLoadError = $injectLoadError;
182182
// @ts-expect-error
183-
window.$injectLoad = $injectLoad;
183+
globalThis.$injectLoad = $injectLoad;

packages/inject/src/scramjet.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ export function loadScramjet({
2525
setWasm(Uint8Array.from(atob(self.WASM), (c) => c.charCodeAt(0)));
2626
delete (self as any).WASM;
2727

28-
const transport = new LibcurlClient({ wisp });
28+
if (SCRAMJETCLIENT in globalThis) {
29+
//@ts-expect-error god bless america
30+
client = globalThis[SCRAMJETCLIENT];
31+
return;
32+
}
2933

30-
if (SCRAMJETCLIENT in self) return;
34+
const transport = new LibcurlClient({ wisp });
3135

3236
client = new ScramjetClient(globalThis, {
3337
context: {
@@ -41,6 +45,9 @@ export function loadScramjet({
4145
prefix: new URL(prefix),
4246
},
4347
transport,
48+
shouldPassthroughWebsocket: (url) => {
49+
return url === wisp;
50+
},
4451
sendSetCookie: async (url: URL, cookie: string) => {},
4552
});
4653
client.hook();

packages/scramjet/devserver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const branch = execSync("git rev-parse --abbrev-ref HEAD", {
2727
const packagejson = JSON.parse(await fs.readFile("./package.json", "utf-8"));
2828
const version = packagejson.version;
2929

30-
const DEMO_PORT = process.env.CHROME_PORT || 4141;
30+
const DEMO_PORT = process.env.DEMO_PORT || 4141;
3131
const WISP_PORT = process.env.WISP_PORT || 4142;
3232

3333
process.env.VITE_WISP_URL =

packages/scramjet/jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
"types": []
1616
},
1717
"include": ["static/**/*", "dist/types/index.d.ts"],
18-
"exclude": ["node_modules", "dist", "src/**/*", "tests/**/*"]
18+
"exclude": ["node_modules", "dist", "src/**/*", "packages/core/tests/**/*"]
1919
}

packages/scramjet/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"license": "AGPL-3.0-only",
99
"packageManager": "pnpm@10.12.1",
1010
"scripts": {
11+
"dev": "node --no-warnings=ExperimentalWarning devserver.ts",
1112
"preinstall": "npx only-allow pnpm"
1213
},
1314
"devDependencies": {

0 commit comments

Comments
 (0)