Skip to content

Commit 657d034

Browse files
feat: add initial browser demo setup with Vite and React components
1 parent 8abb7ee commit 657d034

62 files changed

Lines changed: 7473 additions & 14 deletions

Some content is hidden

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

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,8 @@ docs/docs.backup.json
9898

9999
**/.cache/
100100
perf-results.json
101+
102+
# Playwright
103+
test-results/
104+
playwright-report/
105+
libs/browser/e2e/fixtures/enclave-browser-bundle.mjs

apps/browser-demo/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Generated enclave bundle
2+
vendor/enclave-browser-bundle.mjs
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import baseConfig from '../../eslint.config.mjs';
2+
3+
export default [
4+
...baseConfig,
5+
{
6+
ignores: ['vendor/**'],
7+
},
8+
];

apps/browser-demo/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Browser Enclave Demo</title>
7+
</head>
8+
<body>
9+
<div id="root"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
</html>

apps/browser-demo/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "browser-demo",
3+
"version": "0.0.1",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"prebuild": "node scripts/build-enclave-bundle.mjs",
8+
"dev": "vite",
9+
"build": "vite build"
10+
},
11+
"dependencies": {
12+
"react": "^19.0.0",
13+
"react-dom": "^19.0.0"
14+
},
15+
"devDependencies": {
16+
"@types/react": "^19.0.0",
17+
"@types/react-dom": "^19.0.0",
18+
"@vitejs/plugin-react": "^4.5.2",
19+
"esbuild": "^0.25.0",
20+
"typescript": "~5.9.3",
21+
"vite": "^6.3.5"
22+
}
23+
}

apps/browser-demo/project.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "browser-demo",
3+
"sourceRoot": "apps/browser-demo/src",
4+
"projectType": "application",
5+
"targets": {
6+
"prebuild": {
7+
"executor": "nx:run-commands",
8+
"options": {
9+
"command": "node apps/browser-demo/scripts/build-enclave-bundle.mjs"
10+
}
11+
},
12+
"serve": {
13+
"executor": "nx:run-commands",
14+
"dependsOn": ["prebuild"],
15+
"options": {
16+
"command": "npx vite --config apps/browser-demo/vite.config.ts"
17+
}
18+
},
19+
"build": {
20+
"executor": "nx:run-commands",
21+
"dependsOn": ["prebuild"],
22+
"options": {
23+
"command": "npx vite build --config apps/browser-demo/vite.config.ts"
24+
},
25+
"outputs": ["{workspaceRoot}/dist/apps/browser-demo"]
26+
}
27+
}
28+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Minimal Buffer shim for the browser test bundle.
3+
* Only provides Buffer.byteLength which is used by @enclave-vm/ast's size-check.
4+
*/
5+
const _encoder = new TextEncoder();
6+
7+
if (typeof globalThis.Buffer === 'undefined') {
8+
globalThis.Buffer = {
9+
byteLength(str) {
10+
return _encoder.encode(String(str)).byteLength;
11+
},
12+
};
13+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Build a self-contained ESM bundle of @enclave-vm/browser for the demo app.
3+
*
4+
* Inlines all dependencies (ast, acorn, astring, zod) into a single ESM file.
5+
* Output goes to vendor/ so Vite can import it as a normal module.
6+
*/
7+
8+
import { build } from 'esbuild';
9+
import path from 'node:path';
10+
import { fileURLToPath } from 'node:url';
11+
12+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
13+
const root = path.resolve(__dirname, '../../..');
14+
15+
await build({
16+
entryPoints: [path.resolve(root, 'libs/browser/src/index.ts')],
17+
bundle: true,
18+
format: 'esm',
19+
outfile: path.resolve(__dirname, '../vendor/enclave-browser-bundle.mjs'),
20+
platform: 'browser',
21+
target: 'es2022',
22+
external: [],
23+
alias: {
24+
'@enclave-vm/ast': path.resolve(root, 'libs/ast/src/index.ts'),
25+
},
26+
inject: [path.resolve(__dirname, 'buffer-shim.mjs')],
27+
sourcemap: false,
28+
minify: false,
29+
logLevel: 'info',
30+
});

0 commit comments

Comments
 (0)