electrobun 0.0.19-beta.6 → 0.0.19-beta.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/BUILD.md ADDED
@@ -0,0 +1,90 @@
1
+ # Build System
2
+
3
+ This document describes Electrobun's build system and cross-platform compilation approach.
4
+
5
+ ## Overview
6
+
7
+ Electrobun uses a custom build system (`build.ts`) that handles:
8
+ - Vendoring dependencies (Bun, Zig, CEF, WebView2)
9
+ - Building native wrappers for each platform
10
+ - Creating distribution packages
11
+
12
+ ## Platform-Specific Native Wrappers
13
+
14
+ ### macOS
15
+ - Single `libNativeWrapper.dylib` with weak linking to CEF framework
16
+ - Uses `-weak_framework 'Chromium Embedded Framework'` for optional CEF support
17
+ - Gracefully falls back to WebKit when CEF is not bundled
18
+
19
+ ### Windows
20
+ - Single `libNativeWrapper.dll` with runtime CEF detection
21
+ - Links both WebView2 and CEF libraries at build time
22
+ - Uses runtime checks to determine which webview engine to use
23
+
24
+ ### Linux
25
+ **Dual Binary Approach** - Linux builds create two separate native wrapper binaries:
26
+
27
+ #### `libNativeWrapper.so` (GTK-only)
28
+ - Size: ~1.46MB
29
+ - Dependencies: WebKitGTK, GTK+3, AppIndicator only
30
+ - No CEF dependencies linked
31
+ - Used when `bundleCEF: false` in electrobun.config
32
+
33
+ #### `libNativeWrapper_cef.so` (CEF-enabled)
34
+ - Size: ~3.47MB
35
+ - Dependencies: WebKitGTK, GTK+3, AppIndicator + CEF libraries
36
+ - Full CEF functionality available
37
+ - Used when `bundleCEF: true` in electrobun.config
38
+
39
+ #### Why Dual Binaries?
40
+
41
+ Unlike macOS and Windows, Linux doesn't have reliable weak linking for shared libraries. Hard linking CEF libraries causes `dlopen` failures when CEF isn't bundled. The dual binary approach provides:
42
+
43
+ 1. **Small bundle sizes** - Developers can ship lightweight apps without CEF overhead
44
+ 2. **Flexibility** - Same codebase supports both system WebKitGTK and CEF rendering
45
+ 3. **Reliability** - No runtime linking failures or undefined symbols
46
+
47
+ #### CLI Binary Selection
48
+
49
+ The Electrobun CLI automatically copies the appropriate binary based on the `bundleCEF` setting:
50
+
51
+ ```typescript
52
+ const useCEF = config.build.linux?.bundleCEF;
53
+ const nativeWrapperSource = useCEF
54
+ ? PATHS.NATIVE_WRAPPER_LINUX_CEF
55
+ : PATHS.NATIVE_WRAPPER_LINUX;
56
+ ```
57
+
58
+ Both binaries are included in the distributed `electrobun` npm package, ensuring developers can toggle CEF support without recompilation.
59
+
60
+ ## Build Commands
61
+
62
+ ```bash
63
+ # Full build with all platforms
64
+ bun build.ts
65
+
66
+ # Development build with playground
67
+ bun dev:playground
68
+
69
+ # Release build
70
+ bun build.ts --release
71
+
72
+ # CI build
73
+ bun build.ts --ci
74
+ ```
75
+
76
+ ## Architecture Support
77
+
78
+ - **macOS**: ARM64 (Apple Silicon), x64 (Intel)
79
+ - **Windows**: x64 only (ARM Windows users run via automatic emulation)
80
+ - **Linux**: x64, ARM64
81
+
82
+ ### Windows Architecture Notes
83
+
84
+ Windows builds are created on ARM VMs but target x64 architecture. Both x64 and ARM Windows users use the same x64 binary:
85
+ - **x64 Windows**: Runs natively
86
+ - **ARM Windows**: Runs via automatic Windows emulation layer
87
+
88
+ This approach simplifies distribution while maintaining compatibility across Windows architectures.
89
+
90
+ The build system automatically detects the host architecture and downloads appropriate dependencies.
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync, spawn } = require('child_process');
4
+ const { existsSync, mkdirSync, createWriteStream, unlinkSync, chmodSync } = require('fs');
5
+ const { join, dirname } = require('path');
6
+ const https = require('https');
7
+ const tar = require('tar');
8
+
9
+ // Detect platform and architecture
10
+ function getPlatform() {
11
+ switch (process.platform) {
12
+ case 'win32': return 'win';
13
+ case 'darwin': return 'darwin';
14
+ case 'linux': return 'linux';
15
+ default: throw new Error(`Unsupported platform: ${process.platform}`);
16
+ }
17
+ }
18
+
19
+ function getArch() {
20
+ switch (process.arch) {
21
+ case 'arm64': return 'arm64';
22
+ case 'x64': return 'x64';
23
+ default: throw new Error(`Unsupported architecture: ${process.arch}`);
24
+ }
25
+ }
26
+
27
+ const platform = getPlatform();
28
+ // Always use x64 for Windows since we only build x64 Windows binaries
29
+ const arch = platform === 'win' ? 'x64' : getArch();
30
+ const binExt = platform === 'win' ? '.exe' : '';
31
+
32
+ // Paths
33
+ const electrobunDir = join(__dirname, '..');
34
+ const cacheDir = join(electrobunDir, '.cache');
35
+ const cliBinary = join(cacheDir, `electrobun${binExt}`);
36
+
37
+ async function downloadFile(url, filePath) {
38
+ return new Promise((resolve, reject) => {
39
+ mkdirSync(dirname(filePath), { recursive: true });
40
+ const file = createWriteStream(filePath);
41
+
42
+ https.get(url, (response) => {
43
+ if (response.statusCode === 302 || response.statusCode === 301) {
44
+ // Follow redirect
45
+ return downloadFile(response.headers.location, filePath).then(resolve).catch(reject);
46
+ }
47
+
48
+ if (response.statusCode !== 200) {
49
+ reject(new Error(`Download failed: ${response.statusCode}`));
50
+ return;
51
+ }
52
+
53
+ response.pipe(file);
54
+
55
+ file.on('finish', () => {
56
+ file.close();
57
+ resolve();
58
+ });
59
+
60
+ file.on('error', reject);
61
+ }).on('error', reject);
62
+ });
63
+ }
64
+
65
+ async function ensureCliBinary() {
66
+ // Check if CLI binary exists in bin location (where npm expects it)
67
+ const binLocation = join(electrobunDir, 'bin', 'electrobun' + binExt);
68
+ if (existsSync(binLocation)) {
69
+ return binLocation;
70
+ }
71
+
72
+ // Check if core dependencies already exist in cache
73
+ if (existsSync(cliBinary)) {
74
+ // Copy to bin location if it exists in cache but not in bin
75
+ mkdirSync(dirname(binLocation), { recursive: true });
76
+ const fs = require('fs');
77
+ fs.copyFileSync(cliBinary, binLocation);
78
+ if (platform !== 'win') {
79
+ chmodSync(binLocation, '755');
80
+ }
81
+ return binLocation;
82
+ }
83
+
84
+ console.log('Downloading electrobun CLI for your platform...');
85
+
86
+ // Get the package version to download the matching release
87
+ const packageJson = require(join(electrobunDir, 'package.json'));
88
+ const version = packageJson.version;
89
+ const tag = `v${version}`;
90
+
91
+ const tarballUrl = `https://github.com/blackboardsh/electrobun/releases/download/${tag}/electrobun-cli-${platform}-${arch}.tar.gz`;
92
+ const tarballPath = join(cacheDir, `electrobun-${platform}-${arch}.tar.gz`);
93
+
94
+ try {
95
+ // Download tarball
96
+ await downloadFile(tarballUrl, tarballPath);
97
+
98
+ // Extract CLI binary
99
+ await tar.x({
100
+ file: tarballPath,
101
+ cwd: cacheDir
102
+ // No strip needed - CLI tarball contains just the binary
103
+ });
104
+
105
+ // Clean up tarball
106
+ unlinkSync(tarballPath);
107
+
108
+ // Check if CLI binary was extracted
109
+ if (!existsSync(cliBinary)) {
110
+ throw new Error(`CLI binary not found at ${cliBinary} after extraction`);
111
+ }
112
+
113
+ // Make executable on Unix systems
114
+ if (platform !== 'win') {
115
+ chmodSync(cliBinary, '755');
116
+ }
117
+
118
+ // Copy CLI to bin location so npm scripts can find it
119
+ const binLocation = join(electrobunDir, 'bin', 'electrobun' + binExt);
120
+ mkdirSync(dirname(binLocation), { recursive: true });
121
+
122
+ // Copy the downloaded CLI to replace this script
123
+ const fs = require('fs');
124
+ fs.copyFileSync(cliBinary, binLocation);
125
+
126
+ // Make the bin location executable too
127
+ if (platform !== 'win') {
128
+ chmodSync(binLocation, '755');
129
+ }
130
+
131
+ console.log('electrobun CLI downloaded successfully!');
132
+ return binLocation;
133
+
134
+ } catch (error) {
135
+ throw new Error(`Failed to download electrobun CLI: ${error.message}`);
136
+ }
137
+ }
138
+
139
+ async function main() {
140
+ try {
141
+ const args = process.argv.slice(2);
142
+ const cliPath = await ensureCliBinary();
143
+
144
+ // Replace this process with the actual CLI
145
+ const child = spawn(cliPath, args, {
146
+ stdio: 'inherit',
147
+ cwd: process.cwd()
148
+ });
149
+
150
+ child.on('exit', (code) => {
151
+ process.exit(code || 0);
152
+ });
153
+
154
+ child.on('error', (error) => {
155
+ console.error('Failed to start electrobun CLI:', error.message);
156
+ process.exit(1);
157
+ });
158
+
159
+ } catch (error) {
160
+ console.error('Error:', error.message);
161
+ process.exit(1);
162
+ }
163
+ }
164
+
165
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrobun",
3
- "version": "0.0.19-beta.6",
3
+ "version": "0.0.19-beta.61",
4
4
  "description": "Build ultra fast, tiny, and cross-platform desktop apps with Typescript.",
5
5
  "license": "MIT",
6
6
  "author": "Blackboard Technologies Inc.",
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "type": "module",
20
20
  "bin": {
21
- "electrobun": "./bin/electrobun"
21
+ "electrobun": "./bin/electrobun.cjs"
22
22
  },
23
23
  "homepage": "https://electrobun.dev",
24
24
  "repository": {
@@ -26,12 +26,12 @@
26
26
  "url": "git+https://github.com/blackboardsh/electrobun.git"
27
27
  },
28
28
  "scripts": {
29
- "postinstall": "mkdir -p bin && bun build src/cli/index.ts --compile --outfile bin/electrobun",
29
+ "build:cli": "mkdir -p bin && bun build src/cli/index.ts --compile --outfile bin/electrobun",
30
30
  "start": "bun src/bun/index.ts",
31
31
  "check-zig-version": "vendors/zig/zig version",
32
32
  "build:dev": "bun build.ts",
33
33
  "build:release": "bun build.ts --release",
34
- "dev:playground": "bun build:dev && cd playground && npm install && bun build:dev && bun start",
34
+ "dev:playground": "bun build:dev && bun build:cli && cd playground && npm install && bun build:dev && bun start",
35
35
  "dev:playground:linux": "bun build:dev && npm link && cd playground && npm link electrobun && bun build:dev && bun start",
36
36
  "dev:playground:clean": "cd playground && rm -rf node_modules && npm install && cd .. && bun dev:playground",
37
37
  "dev:playground:rerun": "cd playground && bun start",
@@ -40,11 +40,17 @@
40
40
  "build:docs:release": "cd documentation && bun run build",
41
41
  "npm:publish": "bun build:release && npm publish",
42
42
  "npm:publish:beta": "bun build:release && npm publish --tag beta",
43
- "npm:version:beta": "npm version prerelease --preid=beta"
43
+ "npm:version:beta": "npm version prerelease --preid=beta",
44
+ "push:beta": "bun npm:version:beta && git push origin main --tags",
45
+ "push:patch": "npm version patch && git push origin main --tags",
46
+ "push:minor": "npm version minor && git push origin main --tags",
47
+ "push:major": "npm version major && git push origin main --tags",
48
+ "build:push:artifacts": "bun scripts/build-and-upload-artifacts.js"
49
+ },
50
+ "devDependencies": {
51
+ "@types/bun": "1.1.9"
44
52
  },
45
- "devDependencies": {},
46
53
  "dependencies": {
47
- "@types/bun": "1.1.9",
48
54
  "@oneidentity/zstd-js": "^1.0.3",
49
55
  "rpc-anywhere": "1.5.0",
50
56
  "tar": "^6.2.1"