solforge 0.1.6 → 0.2.0

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.
Files changed (194) hide show
  1. package/.agi/agi.sqlite +0 -0
  2. package/.claude/settings.local.json +9 -0
  3. package/.github/workflows/release-binaries.yml +133 -0
  4. package/.tmp/.787ebcdbf7b8fde8-00000000.hm +0 -0
  5. package/.tmp/.bffe6efebdf8aedc-00000000.hm +0 -0
  6. package/AGENTS.md +271 -0
  7. package/CLAUDE.md +106 -0
  8. package/PROJECT_STRUCTURE.md +124 -0
  9. package/README.md +367 -393
  10. package/SOLANA_KIT_GUIDE.md +251 -0
  11. package/SOLFORGE.md +119 -0
  12. package/biome.json +34 -0
  13. package/bun.lock +743 -0
  14. package/docs/bun-single-file-executable.md +585 -0
  15. package/docs/cli-plan.md +154 -0
  16. package/docs/data-indexing-plan.md +214 -0
  17. package/docs/gui-roadmap.md +202 -0
  18. package/drizzle/0000_friendly_millenium_guard.sql +53 -0
  19. package/drizzle/0001_stale_sentinels.sql +2 -0
  20. package/drizzle/meta/0000_snapshot.json +329 -0
  21. package/drizzle/meta/0001_snapshot.json +345 -0
  22. package/drizzle/meta/_journal.json +20 -0
  23. package/drizzle.config.ts +12 -0
  24. package/index.ts +21 -0
  25. package/mint.sh +47 -0
  26. package/package.json +45 -69
  27. package/postcss.config.js +6 -0
  28. package/rpc-server.ts.backup +519 -0
  29. package/server/index.ts +5 -0
  30. package/server/lib/base58.ts +33 -0
  31. package/server/lib/faucet.ts +110 -0
  32. package/server/lib/spl-token.ts +57 -0
  33. package/server/methods/TEMPLATE.md +117 -0
  34. package/server/methods/account/get-account-info.ts +90 -0
  35. package/server/methods/account/get-balance.ts +27 -0
  36. package/server/methods/account/get-multiple-accounts.ts +83 -0
  37. package/server/methods/account/get-parsed-account-info.ts +21 -0
  38. package/server/methods/account/index.ts +12 -0
  39. package/server/methods/account/parsers/index.ts +52 -0
  40. package/server/methods/account/parsers/loader-upgradeable.ts +66 -0
  41. package/server/methods/account/parsers/spl-token.ts +237 -0
  42. package/server/methods/account/parsers/system.ts +4 -0
  43. package/server/methods/account/request-airdrop.ts +219 -0
  44. package/server/methods/admin/adopt-mint-authority.ts +94 -0
  45. package/server/methods/admin/clone-program-accounts.ts +55 -0
  46. package/server/methods/admin/clone-program.ts +152 -0
  47. package/server/methods/admin/clone-token-accounts.ts +117 -0
  48. package/server/methods/admin/clone-token-mint.ts +82 -0
  49. package/server/methods/admin/create-mint.ts +114 -0
  50. package/server/methods/admin/create-token-account.ts +137 -0
  51. package/server/methods/admin/helpers.ts +70 -0
  52. package/server/methods/admin/index.ts +10 -0
  53. package/server/methods/admin/list-mints.ts +21 -0
  54. package/server/methods/admin/load-program.ts +52 -0
  55. package/server/methods/admin/mint-to.ts +278 -0
  56. package/server/methods/block/get-block-height.ts +5 -0
  57. package/server/methods/block/get-block.ts +35 -0
  58. package/server/methods/block/get-blocks-with-limit.ts +23 -0
  59. package/server/methods/block/get-latest-blockhash.ts +12 -0
  60. package/server/methods/block/get-slot.ts +5 -0
  61. package/server/methods/block/index.ts +6 -0
  62. package/server/methods/block/is-blockhash-valid.ts +23 -0
  63. package/server/methods/epoch/get-cluster-nodes.ts +17 -0
  64. package/server/methods/epoch/get-epoch-info.ts +16 -0
  65. package/server/methods/epoch/get-epoch-schedule.ts +15 -0
  66. package/server/methods/epoch/get-highest-snapshot-slot.ts +9 -0
  67. package/server/methods/epoch/get-leader-schedule.ts +8 -0
  68. package/server/methods/epoch/get-max-retransmit-slot.ts +9 -0
  69. package/server/methods/epoch/get-max-shred-insert-slot.ts +9 -0
  70. package/server/methods/epoch/get-slot-leader.ts +6 -0
  71. package/server/methods/epoch/get-slot-leaders.ts +9 -0
  72. package/server/methods/epoch/get-stake-activation.ts +9 -0
  73. package/server/methods/epoch/get-stake-minimum-delegation.ts +9 -0
  74. package/server/methods/epoch/get-vote-accounts.ts +19 -0
  75. package/server/methods/epoch/index.ts +13 -0
  76. package/server/methods/epoch/minimum-ledger-slot.ts +5 -0
  77. package/server/methods/fee/get-fee-calculator-for-blockhash.ts +12 -0
  78. package/server/methods/fee/get-fee-for-message.ts +8 -0
  79. package/server/methods/fee/get-fee-rate-governor.ts +16 -0
  80. package/server/methods/fee/get-fees.ts +14 -0
  81. package/server/methods/fee/get-recent-prioritization-fees.ts +22 -0
  82. package/server/methods/fee/index.ts +5 -0
  83. package/server/methods/get-address-lookup-table.ts +31 -0
  84. package/server/methods/index.ts +265 -0
  85. package/server/methods/performance/get-recent-performance-samples.ts +25 -0
  86. package/server/methods/performance/get-transaction-count.ts +5 -0
  87. package/server/methods/performance/index.ts +2 -0
  88. package/server/methods/program/get-block-commitment.ts +9 -0
  89. package/server/methods/program/get-block-production.ts +14 -0
  90. package/server/methods/program/get-block-time.ts +21 -0
  91. package/server/methods/program/get-blocks.ts +11 -0
  92. package/server/methods/program/get-first-available-block.ts +9 -0
  93. package/server/methods/program/get-genesis-hash.ts +6 -0
  94. package/server/methods/program/get-identity.ts +6 -0
  95. package/server/methods/program/get-inflation-governor.ts +15 -0
  96. package/server/methods/program/get-inflation-rate.ts +10 -0
  97. package/server/methods/program/get-inflation-reward.ts +12 -0
  98. package/server/methods/program/get-largest-accounts.ts +8 -0
  99. package/server/methods/program/get-parsed-program-accounts.ts +12 -0
  100. package/server/methods/program/get-parsed-token-accounts-by-delegate.ts +12 -0
  101. package/server/methods/program/get-parsed-token-accounts-by-owner.ts +12 -0
  102. package/server/methods/program/get-program-accounts.ts +221 -0
  103. package/server/methods/program/get-supply.ts +13 -0
  104. package/server/methods/program/get-token-account-balance.ts +64 -0
  105. package/server/methods/program/get-token-accounts-by-delegate.ts +81 -0
  106. package/server/methods/program/get-token-accounts-by-owner.ts +390 -0
  107. package/server/methods/program/get-token-largest-accounts.ts +80 -0
  108. package/server/methods/program/get-token-supply.ts +38 -0
  109. package/server/methods/program/index.ts +21 -0
  110. package/server/methods/solforge/index.ts +155 -0
  111. package/server/methods/system/get-health.ts +5 -0
  112. package/server/methods/system/get-minimum-balance-for-rent-exemption.ts +13 -0
  113. package/server/methods/system/get-version.ts +9 -0
  114. package/server/methods/system/index.ts +3 -0
  115. package/server/methods/transaction/get-confirmed-transaction.ts +11 -0
  116. package/server/methods/transaction/get-parsed-transaction.ts +21 -0
  117. package/server/methods/transaction/get-signature-statuses.ts +72 -0
  118. package/server/methods/transaction/get-signatures-for-address.ts +45 -0
  119. package/server/methods/transaction/get-transaction.ts +428 -0
  120. package/server/methods/transaction/index.ts +7 -0
  121. package/server/methods/transaction/send-transaction.ts +232 -0
  122. package/server/methods/transaction/simulate-transaction.ts +56 -0
  123. package/server/rpc-server.ts +474 -0
  124. package/server/types.ts +74 -0
  125. package/server/ws-server.ts +171 -0
  126. package/sf.config.json +38 -0
  127. package/src/cli/bootstrap.ts +67 -0
  128. package/src/cli/commands/airdrop.ts +37 -0
  129. package/src/cli/commands/config.ts +39 -0
  130. package/src/cli/commands/mint.ts +187 -0
  131. package/src/cli/commands/program-clone.ts +124 -0
  132. package/src/cli/commands/program-load.ts +64 -0
  133. package/src/cli/commands/rpc-start.ts +46 -0
  134. package/src/cli/commands/token-adopt-authority.ts +37 -0
  135. package/src/cli/commands/token-clone.ts +113 -0
  136. package/src/cli/commands/token-create.ts +81 -0
  137. package/src/cli/main.ts +130 -0
  138. package/src/cli/run-solforge.ts +98 -0
  139. package/src/cli/setup-utils.ts +54 -0
  140. package/src/cli/setup-wizard.ts +256 -0
  141. package/src/cli/utils/args.ts +15 -0
  142. package/src/config/index.ts +130 -0
  143. package/src/db/index.ts +83 -0
  144. package/src/db/schema/accounts.ts +23 -0
  145. package/src/db/schema/address-signatures.ts +31 -0
  146. package/src/db/schema/index.ts +5 -0
  147. package/src/db/schema/meta-kv.ts +9 -0
  148. package/src/db/schema/transactions.ts +29 -0
  149. package/src/db/schema/tx-accounts.ts +33 -0
  150. package/src/db/tx-store.ts +229 -0
  151. package/src/gui/public/app.css +1 -0
  152. package/src/gui/public/index.html +19 -0
  153. package/src/gui/server.ts +297 -0
  154. package/src/gui/src/api.ts +127 -0
  155. package/src/gui/src/app.tsx +390 -0
  156. package/src/gui/src/components/airdrop-mint-form.tsx +216 -0
  157. package/src/gui/src/components/clone-program-modal.tsx +183 -0
  158. package/src/gui/src/components/clone-token-modal.tsx +211 -0
  159. package/src/gui/src/components/modal.tsx +127 -0
  160. package/src/gui/src/components/programs-panel.tsx +112 -0
  161. package/src/gui/src/components/status-panel.tsx +122 -0
  162. package/src/gui/src/components/tokens-panel.tsx +116 -0
  163. package/src/gui/src/hooks/use-interval.ts +17 -0
  164. package/src/gui/src/index.css +529 -0
  165. package/src/gui/src/main.tsx +17 -0
  166. package/src/migrations-bundled.ts +17 -0
  167. package/src/rpc/start.ts +44 -0
  168. package/tailwind.config.js +27 -0
  169. package/test-client.ts +120 -0
  170. package/tmp/inspect-html.ts +4 -0
  171. package/tmp/response-test.ts +5 -0
  172. package/tmp/test-html.ts +5 -0
  173. package/tmp/test-server.ts +13 -0
  174. package/tsconfig.json +24 -23
  175. package/LICENSE +0 -21
  176. package/scripts/postinstall.cjs +0 -103
  177. package/src/api-server-entry.ts +0 -109
  178. package/src/commands/add-program.ts +0 -337
  179. package/src/commands/init.ts +0 -122
  180. package/src/commands/list.ts +0 -136
  181. package/src/commands/mint.ts +0 -336
  182. package/src/commands/start.ts +0 -878
  183. package/src/commands/status.ts +0 -99
  184. package/src/commands/stop.ts +0 -406
  185. package/src/config/manager.ts +0 -157
  186. package/src/index.ts +0 -188
  187. package/src/services/api-server.ts +0 -532
  188. package/src/services/port-manager.ts +0 -177
  189. package/src/services/process-registry.ts +0 -154
  190. package/src/services/program-cloner.ts +0 -317
  191. package/src/services/token-cloner.ts +0 -809
  192. package/src/services/validator.ts +0 -295
  193. package/src/types/config.ts +0 -110
  194. package/src/utils/shell.ts +0 -110
@@ -0,0 +1,585 @@
1
+
2
+ Bun's bundler implements a `--compile` flag for generating a standalone binary from a TypeScript or JavaScript file.
3
+
4
+ {% codetabs %}
5
+
6
+ ```bash
7
+ $ bun build ./cli.ts --compile --outfile mycli
8
+ ```
9
+
10
+ ```ts#cli.ts
11
+ console.log("Hello world!");
12
+ ```
13
+
14
+ {% /codetabs %}
15
+
16
+ This bundles `cli.ts` into an executable that can be executed directly:
17
+
18
+ ```
19
+ $ ./mycli
20
+ Hello world!
21
+ ```
22
+
23
+ All imported files and packages are bundled into the executable, along with a copy of the Bun runtime. All built-in Bun and Node.js APIs are supported.
24
+
25
+ ## Cross-compile to other platforms
26
+
27
+ The `--target` flag lets you compile your standalone executable for a different operating system, architecture, or version of Bun than the machine you're running `bun build` on.
28
+
29
+ To build for Linux x64 (most servers):
30
+
31
+ ```sh
32
+ bun build --compile --target=bun-linux-x64 ./index.ts --outfile myapp
33
+
34
+ # To support CPUs from before 2013, use the baseline version (nehalem)
35
+ bun build --compile --target=bun-linux-x64-baseline ./index.ts --outfile myapp
36
+
37
+ # To explicitly only support CPUs from 2013 and later, use the modern version (haswell)
38
+ # modern is faster, but baseline is more compatible.
39
+ bun build --compile --target=bun-linux-x64-modern ./index.ts --outfile myapp
40
+ ```
41
+
42
+ To build for Linux ARM64 (e.g. Graviton or Raspberry Pi):
43
+
44
+ ```sh
45
+ # Note: the default architecture is x64 if no architecture is specified.
46
+ bun build --compile --target=bun-linux-arm64 ./index.ts --outfile myapp
47
+ ```
48
+
49
+ To build for Windows x64:
50
+
51
+ ```sh
52
+ bun build --compile --target=bun-windows-x64 ./path/to/my/app.ts --outfile myapp
53
+
54
+ # To support CPUs from before 2013, use the baseline version (nehalem)
55
+ bun build --compile --target=bun-windows-x64-baseline ./path/to/my/app.ts --outfile myapp
56
+
57
+ # To explicitly only support CPUs from 2013 and later, use the modern version (haswell)
58
+ bun build --compile --target=bun-windows-x64-modern ./path/to/my/app.ts --outfile myapp
59
+
60
+ # note: if no .exe extension is provided, Bun will automatically add it for Windows executables
61
+ ```
62
+
63
+ To build for macOS arm64:
64
+
65
+ ```sh
66
+ bun build --compile --target=bun-darwin-arm64 ./path/to/my/app.ts --outfile myapp
67
+ ```
68
+
69
+ To build for macOS x64:
70
+
71
+ ```sh
72
+ bun build --compile --target=bun-darwin-x64 ./path/to/my/app.ts --outfile myapp
73
+ ```
74
+
75
+ #### Supported targets
76
+
77
+ The order of the `--target` flag does not matter, as long as they're delimited by a `-`.
78
+
79
+ | --target | Operating System | Architecture | Modern | Baseline | Libc |
80
+ | --------------------- | ---------------- | ------------ | ------ | -------- | ----- |
81
+ | bun-linux-x64 | Linux | x64 | ✅ | ✅ | glibc |
82
+ | bun-linux-arm64 | Linux | arm64 | ✅ | N/A | glibc |
83
+ | bun-windows-x64 | Windows | x64 | ✅ | ✅ | - |
84
+ | ~~bun-windows-arm64~~ | Windows | arm64 | ❌ | ❌ | - |
85
+ | bun-darwin-x64 | macOS | x64 | ✅ | ✅ | - |
86
+ | bun-darwin-arm64 | macOS | arm64 | ✅ | N/A | - |
87
+ | bun-linux-x64-musl | Linux | x64 | ✅ | ✅ | musl |
88
+ | bun-linux-arm64-musl | Linux | arm64 | ✅ | N/A | musl |
89
+
90
+ On x64 platforms, Bun uses SIMD optimizations which require a modern CPU supporting AVX2 instructions. The `-baseline` build of Bun is for older CPUs that don't support these optimizations. Normally, when you install Bun we automatically detect which version to use but this can be harder to do when cross-compiling since you might not know the target CPU. You usually don't need to worry about it on Darwin x64, but it is relevant for Windows x64 and Linux x64. If you or your users see `"Illegal instruction"` errors, you might need to use the baseline version.
91
+
92
+ ## Build-time constants
93
+
94
+ Use the `--define` flag to inject build-time constants into your executable, such as version numbers, build timestamps, or configuration values:
95
+
96
+ ```bash
97
+ $ bun build --compile --define BUILD_VERSION='"1.2.3"' --define BUILD_TIME='"2024-01-15T10:30:00Z"' src/cli.ts --outfile mycli
98
+ ```
99
+
100
+ These constants are embedded directly into your compiled binary at build time, providing zero runtime overhead and enabling dead code elimination optimizations.
101
+
102
+ {% callout type="info" %}
103
+ For comprehensive examples and advanced patterns, see the [Build-time constants guide](/guides/runtime/build-time-constants).
104
+ {% /callout %}
105
+
106
+ ## Deploying to production
107
+
108
+ Compiled executables reduce memory usage and improve Bun's start time.
109
+
110
+ Normally, Bun reads and transpiles JavaScript and TypeScript files on `import` and `require`. This is part of what makes so much of Bun "just work", but it's not free. It costs time and memory to read files from disk, resolve file paths, parse, transpile, and print source code.
111
+
112
+ With compiled executables, you can move that cost from runtime to build-time.
113
+
114
+ When deploying to production, we recommend the following:
115
+
116
+ ```sh
117
+ bun build --compile --minify --sourcemap ./path/to/my/app.ts --outfile myapp
118
+ ```
119
+
120
+ ### Bytecode compilation
121
+
122
+ To improve startup time, enable bytecode compilation:
123
+
124
+ ```sh
125
+ bun build --compile --minify --sourcemap --bytecode ./path/to/my/app.ts --outfile myapp
126
+ ```
127
+
128
+ Using bytecode compilation, `tsc` starts 2x faster:
129
+
130
+ {% image src="https://github.com/user-attachments/assets/dc8913db-01d2-48f8-a8ef-ac4e984f9763" width="689" /%}
131
+
132
+ Bytecode compilation moves parsing overhead for large input files from runtime to bundle time. Your app starts faster, in exchange for making the `bun build` command a little slower. It doesn't obscure source code.
133
+
134
+ **Experimental:** Bytecode compilation is an experimental feature introduced in Bun v1.1.30. Only `cjs` format is supported (which means no top-level-await). Let us know if you run into any issues!
135
+
136
+ ### What do these flags do?
137
+
138
+ The `--minify` argument optimizes the size of the transpiled output code. If you have a large application, this can save megabytes of space. For smaller applications, it might still improve start time a little.
139
+
140
+ The `--sourcemap` argument embeds a sourcemap compressed with zstd, so that errors & stacktraces point to their original locations instead of the transpiled location. Bun will automatically decompress & resolve the sourcemap when an error occurs.
141
+
142
+ The `--bytecode` argument enables bytecode compilation. Every time you run JavaScript code in Bun, JavaScriptCore (the engine) will compile your source code into bytecode. We can move this parsing work from runtime to bundle time, saving you startup time.
143
+
144
+ ## Act as the Bun CLI
145
+
146
+ {% note %}
147
+
148
+ New in Bun v1.2.16
149
+
150
+ {% /note %}
151
+
152
+ You can run a standalone executable as if it were the `bun` CLI itself by setting the `BUN_BE_BUN=1` environment variable. When this variable is set, the executable will ignore its bundled entrypoint and instead expose all the features of Bun's CLI.
153
+
154
+ For example, consider an executable compiled from a simple script:
155
+
156
+ ```sh
157
+ $ cat such-bun.js
158
+ console.log("you shouldn't see this");
159
+
160
+ $ bun build --compile ./such-bun.js
161
+ [3ms] bundle 1 modules
162
+ [89ms] compile such-bun
163
+ ```
164
+
165
+ Normally, running `./such-bun` with arguments would execute the script. However, with the `BUN_BE_BUN=1` environment variable, it acts just like the `bun` binary:
166
+
167
+ ```sh
168
+ # Executable runs its own entrypoint by default
169
+ $ ./such-bun install
170
+ you shouldn't see this
171
+
172
+ # With the env var, the executable acts like the `bun` CLI
173
+ $ BUN_BE_BUN=1 ./such-bun install
174
+ bun install v1.2.16-canary.1 (1d1db811)
175
+ Checked 63 installs across 64 packages (no changes) [5.00ms]
176
+ ```
177
+
178
+ This is useful for building CLI tools on top of Bun that may need to install packages, bundle dependencies, run different or local files and more without needing to download a separate binary or install bun.
179
+
180
+ ## Full-stack executables
181
+
182
+ {% note %}
183
+
184
+ New in Bun v1.2.17
185
+
186
+ {% /note %}
187
+
188
+ Bun's `--compile` flag can create standalone executables that contain both server and client code, making it ideal for full-stack applications. When you import an HTML file in your server code, Bun automatically bundles all frontend assets (JavaScript, CSS, etc.) and embeds them into the executable. When Bun sees the HTML import on the server, it kicks off a frontend build process to bundle JavaScript, CSS, and other assets.
189
+
190
+ {% codetabs %}
191
+
192
+ ```ts#server.ts
193
+ import { serve } from "bun";
194
+ import index from "./index.html";
195
+
196
+ const server = serve({
197
+ routes: {
198
+ "/": index,
199
+ "/api/hello": { GET: () => Response.json({ message: "Hello from API" }) },
200
+ },
201
+ });
202
+
203
+ console.log(`Server running at http://localhost:${server.port}`);
204
+ ```
205
+
206
+ ```html#index.html
207
+ <!DOCTYPE html>
208
+ <html>
209
+ <head>
210
+ <title>My App</title>
211
+ <link rel="stylesheet" href="./styles.css">
212
+ </head>
213
+ <body>
214
+ <h1>Hello World</h1>
215
+ <script src="./app.js"></script>
216
+ </body>
217
+ </html>
218
+ ```
219
+
220
+ ```js#app.js
221
+ console.log("Hello from the client!");
222
+ ```
223
+
224
+ ```css#styles.css
225
+ body {
226
+ background-color: #f0f0f0;
227
+ }
228
+ ```
229
+
230
+ {% /codetabs %}
231
+
232
+ To build this into a single executable:
233
+
234
+ ```sh
235
+ bun build --compile ./server.ts --outfile myapp
236
+ ```
237
+
238
+ This creates a self-contained binary that includes:
239
+
240
+ - Your server code
241
+ - The Bun runtime
242
+ - All frontend assets (HTML, CSS, JavaScript)
243
+ - Any npm packages used by your server
244
+
245
+ The result is a single file that can be deployed anywhere without needing Node.js, Bun, or any dependencies installed. Just run:
246
+
247
+ ```sh
248
+ ./myapp
249
+ ```
250
+
251
+ Bun automatically handles serving the frontend assets with proper MIME types and cache headers. The HTML import is replaced with a manifest object that `Bun.serve` uses to efficiently serve pre-bundled assets.
252
+
253
+ For more details on building full-stack applications with Bun, see the [full-stack guide](/docs/bundler/fullstack).
254
+
255
+ ## Worker
256
+
257
+ To use workers in a standalone executable, add the worker's entrypoint to the CLI arguments:
258
+
259
+ ```sh
260
+ $ bun build --compile ./index.ts ./my-worker.ts --outfile myapp
261
+ ```
262
+
263
+ Then, reference the worker in your code:
264
+
265
+ ```ts
266
+ console.log("Hello from Bun!");
267
+
268
+ // Any of these will work:
269
+ new Worker("./my-worker.ts");
270
+ new Worker(new URL("./my-worker.ts", import.meta.url));
271
+ new Worker(new URL("./my-worker.ts", import.meta.url).href);
272
+ ```
273
+
274
+ As of Bun v1.1.25, when you add multiple entrypoints to a standalone executable, they will be bundled separately into the executable.
275
+
276
+ In the future, we may automatically detect usages of statically-known paths in `new Worker(path)` and then bundle those into the executable, but for now, you'll need to add it to the shell command manually like the above example.
277
+
278
+ If you use a relative path to a file not included in the standalone executable, it will attempt to load that path from disk relative to the current working directory of the process (and then error if it doesn't exist).
279
+
280
+ ## SQLite
281
+
282
+ You can use `bun:sqlite` imports with `bun build --compile`.
283
+
284
+ By default, the database is resolved relative to the current working directory of the process.
285
+
286
+ ```js
287
+ import db from "./my.db" with { type: "sqlite" };
288
+
289
+ console.log(db.query("select * from users LIMIT 1").get());
290
+ ```
291
+
292
+ That means if the executable is located at `/usr/bin/hello`, the user's terminal is located at `/home/me/Desktop`, it will look for `/home/me/Desktop/my.db`.
293
+
294
+ ```
295
+ $ cd /home/me/Desktop
296
+ $ ./hello
297
+ ```
298
+
299
+ ## Embed assets & files
300
+
301
+ Standalone executables support embedding files.
302
+
303
+ To embed files into an executable with `bun build --compile`, import the file in your code.
304
+
305
+ ```ts
306
+ // this becomes an internal file path
307
+ import icon from "./icon.png" with { type: "file" };
308
+ import { file } from "bun";
309
+
310
+ export default {
311
+ fetch(req) {
312
+ // Embedded files can be streamed from Response objects
313
+ return new Response(file(icon));
314
+ },
315
+ };
316
+ ```
317
+
318
+ Embedded files can be read using `Bun.file`'s functions or the Node.js `fs.readFile` function (in `"node:fs"`).
319
+
320
+ For example, to read the contents of the embedded file:
321
+
322
+ ```js
323
+ import icon from "./icon.png" with { type: "file" };
324
+ import { file } from "bun";
325
+
326
+ const bytes = await file(icon).arrayBuffer();
327
+ // await fs.promises.readFile(icon)
328
+ // fs.readFileSync(icon)
329
+ ```
330
+
331
+ ### Embed SQLite databases
332
+
333
+ If your application wants to embed a SQLite database, set `type: "sqlite"` in the import attribute and the `embed` attribute to `"true"`.
334
+
335
+ ```js
336
+ import myEmbeddedDb from "./my.db" with { type: "sqlite", embed: "true" };
337
+
338
+ console.log(myEmbeddedDb.query("select * from users LIMIT 1").get());
339
+ ```
340
+
341
+ This database is read-write, but all changes are lost when the executable exits (since it's stored in memory).
342
+
343
+ ### Embed N-API Addons
344
+
345
+ As of Bun v1.0.23, you can embed `.node` files into executables.
346
+
347
+ ```js
348
+ const addon = require("./addon.node");
349
+
350
+ console.log(addon.hello());
351
+ ```
352
+
353
+ Unfortunately, if you're using `@mapbox/node-pre-gyp` or other similar tools, you'll need to make sure the `.node` file is directly required or it won't bundle correctly.
354
+
355
+ ### Embed directories
356
+
357
+ To embed a directory with `bun build --compile`, use a shell glob in your `bun build` command:
358
+
359
+ ```sh
360
+ $ bun build --compile ./index.ts ./public/**/*.png
361
+ ```
362
+
363
+ Then, you can reference the files in your code:
364
+
365
+ ```ts
366
+ import icon from "./public/assets/icon.png" with { type: "file" };
367
+ import { file } from "bun";
368
+
369
+ export default {
370
+ fetch(req) {
371
+ // Embedded files can be streamed from Response objects
372
+ return new Response(file(icon));
373
+ },
374
+ };
375
+ ```
376
+
377
+ This is honestly a workaround, and we expect to improve this in the future with a more direct API.
378
+
379
+ ### Listing embedded files
380
+
381
+ To get a list of all embedded files, use `Bun.embeddedFiles`:
382
+
383
+ ```js
384
+ import "./icon.png" with { type: "file" };
385
+ import { embeddedFiles } from "bun";
386
+
387
+ console.log(embeddedFiles[0].name); // `icon-${hash}.png`
388
+ ```
389
+
390
+ `Bun.embeddedFiles` returns an array of `Blob` objects which you can use to get the size, contents, and other properties of the files.
391
+
392
+ ```ts
393
+ embeddedFiles: Blob[]
394
+ ```
395
+
396
+ The list of embedded files excludes bundled source code like `.ts` and `.js` files.
397
+
398
+ #### Content hash
399
+
400
+ By default, embedded files have a content hash appended to their name. This is useful for situations where you want to serve the file from a URL or CDN and have fewer cache invalidation issues. But sometimes, this is unexpected and you might want the original name instead:
401
+
402
+ To disable the content hash, pass `--asset-naming` to `bun build --compile` like this:
403
+
404
+ ```sh
405
+ $ bun build --compile --asset-naming="[name].[ext]" ./index.ts
406
+ ```
407
+
408
+ ## Minification
409
+
410
+ To trim down the size of the executable a little, pass `--minify` to `bun build --compile`. This uses Bun's minifier to reduce the code size. Overall though, Bun's binary is still way too big and we need to make it smaller.
411
+
412
+ ## Using Bun.build() API
413
+
414
+ You can also generate standalone executables using the `Bun.build()` JavaScript API. This is useful when you need programmatic control over the build process.
415
+
416
+ ### Basic usage
417
+
418
+ ```js
419
+ await Bun.build({
420
+ entrypoints: ["./app.ts"],
421
+ outdir: "./dist",
422
+ compile: {
423
+ target: "bun-windows-x64",
424
+ outfile: "myapp.exe",
425
+ },
426
+ });
427
+ ```
428
+
429
+ ### Windows metadata with Bun.build()
430
+
431
+ When targeting Windows, you can specify metadata through the `windows` object:
432
+
433
+ ```js
434
+ await Bun.build({
435
+ entrypoints: ["./app.ts"],
436
+ outdir: "./dist",
437
+ compile: {
438
+ target: "bun-windows-x64",
439
+ outfile: "myapp.exe",
440
+ windows: {
441
+ title: "My Application",
442
+ publisher: "My Company Inc",
443
+ version: "1.2.3.4",
444
+ description: "A powerful application built with Bun",
445
+ copyright: "© 2024 My Company Inc",
446
+ hideConsole: false, // Set to true for GUI applications
447
+ icon: "./icon.ico", // Path to icon file
448
+ },
449
+ },
450
+ });
451
+ ```
452
+
453
+ ### Cross-compilation with Bun.build()
454
+
455
+ You can cross-compile for different platforms:
456
+
457
+ ```js
458
+ // Build for multiple platforms
459
+ const platforms = [
460
+ { target: "bun-windows-x64", outfile: "app-windows.exe" },
461
+ { target: "bun-linux-x64", outfile: "app-linux" },
462
+ { target: "bun-darwin-arm64", outfile: "app-macos" },
463
+ ];
464
+
465
+ for (const platform of platforms) {
466
+ await Bun.build({
467
+ entrypoints: ["./app.ts"],
468
+ outdir: "./dist",
469
+ compile: platform,
470
+ });
471
+ }
472
+ ```
473
+
474
+ ## Windows-specific flags
475
+
476
+ When compiling a standalone executable for Windows, there are several platform-specific options that can be used to customize the generated `.exe` file:
477
+
478
+ ### Visual customization
479
+
480
+ - `--windows-icon=path/to/icon.ico` - Set the executable file icon
481
+ - `--windows-hide-console` - Disable the background terminal window (useful for GUI applications)
482
+
483
+ ### Metadata customization
484
+
485
+ You can embed version information and other metadata into your Windows executable:
486
+
487
+ - `--windows-title <STR>` - Set the product name (appears in file properties)
488
+ - `--windows-publisher <STR>` - Set the company name
489
+ - `--windows-version <STR>` - Set the version number (e.g. "1.2.3.4")
490
+ - `--windows-description <STR>` - Set the file description
491
+ - `--windows-copyright <STR>` - Set the copyright information
492
+
493
+ #### Example with all metadata flags:
494
+
495
+ ```sh
496
+ bun build --compile ./app.ts \
497
+ --outfile myapp.exe \
498
+ --windows-title "My Application" \
499
+ --windows-publisher "My Company Inc" \
500
+ --windows-version "1.2.3.4" \
501
+ --windows-description "A powerful application built with Bun" \
502
+ --windows-copyright "© 2024 My Company Inc"
503
+ ```
504
+
505
+ This metadata will be visible in Windows Explorer when viewing the file properties:
506
+
507
+ 1. Right-click the executable in Windows Explorer
508
+ 2. Select "Properties"
509
+ 3. Go to the "Details" tab
510
+
511
+ #### Version string format
512
+
513
+ The `--windows-version` flag accepts version strings in the following formats:
514
+
515
+ - `"1"` - Will be normalized to "1.0.0.0"
516
+ - `"1.2"` - Will be normalized to "1.2.0.0"
517
+ - `"1.2.3"` - Will be normalized to "1.2.3.0"
518
+ - `"1.2.3.4"` - Full version format
519
+
520
+ Each version component must be a number between 0 and 65535.
521
+
522
+ {% callout %}
523
+
524
+ These flags currently cannot be used when cross-compiling because they depend on Windows APIs. They are only available when building on Windows itself.
525
+
526
+ {% /callout %}
527
+
528
+ ## Code signing on macOS
529
+
530
+ To codesign a standalone executable on macOS (which fixes Gatekeeper warnings), use the `codesign` command.
531
+
532
+ ```sh
533
+ $ codesign --deep --force -vvvv --sign "XXXXXXXXXX" ./myapp
534
+ ```
535
+
536
+ We recommend including an `entitlements.plist` file with JIT permissions.
537
+
538
+ ```xml#entitlements.plist
539
+ <?xml version="1.0" encoding="UTF-8"?>
540
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
541
+ <plist version="1.0">
542
+ <dict>
543
+ <key>com.apple.security.cs.allow-jit</key>
544
+ <true/>
545
+ <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
546
+ <true/>
547
+ <key>com.apple.security.cs.disable-executable-page-protection</key>
548
+ <true/>
549
+ <key>com.apple.security.cs.allow-dyld-environment-variables</key>
550
+ <true/>
551
+ <key>com.apple.security.cs.disable-library-validation</key>
552
+ <true/>
553
+ </dict>
554
+ </plist>
555
+ ```
556
+
557
+ To codesign with JIT support, pass the `--entitlements` flag to `codesign`.
558
+
559
+ ```sh
560
+ $ codesign --deep --force -vvvv --sign "XXXXXXXXXX" --entitlements entitlements.plist ./myapp
561
+ ```
562
+
563
+ After codesigning, verify the executable:
564
+
565
+ ```sh
566
+ $ codesign -vvv --verify ./myapp
567
+ ./myapp: valid on disk
568
+ ./myapp: satisfies its Designated Requirement
569
+ ```
570
+
571
+ {% callout %}
572
+
573
+ Codesign support requires Bun v1.2.4 or newer.
574
+
575
+ {% /callout %}
576
+
577
+ ## Unsupported CLI arguments
578
+
579
+ Currently, the `--compile` flag can only accept a single entrypoint at a time and does not support the following flags:
580
+
581
+ - `--outdir` — use `outfile` instead.
582
+ - `--splitting`
583
+ - `--public-path`
584
+ - `--target=node` or `--target=browser`
585
+ - `--no-bundle` - we always bundle everything into the executable.