Commit cea5295
sea: support embedding assets
With this patch:
Users can now include assets by adding a key-path dictionary
to the configuration as the `assets` field. At build time, Node.js
would read the assets from the specified paths and bundle them into
the preparation blob. In the generated executable, users can retrieve
the assets using the `sea.getAsset()` and `sea.getAssetAsBlob()` API.
```json
{
"main": "/path/to/bundled/script.js",
"output": "/path/to/write/the/generated/blob.blob",
"assets": {
"a.jpg": "/path/to/a.jpg",
"b.txt": "/path/to/b.txt"
}
}
```
The single-executable application can access the assets as follows:
```cjs
const { getAsset } = require('node:sea');
// Returns a copy of the data in an ArrayBuffer
const image = getAsset('a.jpg');
// Returns a string decoded from the asset as UTF8.
const text = getAsset('b.txt', 'utf8');
// Returns a Blob containing the asset.
const blob = getAssetAsBlob('a.jpg');
```
Drive-by: update the documentation to include a section dedicated
to the injected main script and refer to it as "injected main
script" instead of "injected module" because it's a script, not
a module.
PR-URL: #50960
Refs: nodejs/single-executable#68
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>1 parent 47186fb commit cea5295Copy full SHA for cea5295
File tree
Expand file treeCollapse file tree
12 files changed
+578
-12
lines changedOpen diff view settings
Filter options
- doc/api
- lib
- internal
- bootstrap
- src
- test
- fixtures/sea
- sequential
Expand file treeCollapse file tree
12 files changed
+578
-12
lines changedOpen diff view settings
Collapse file
+22Lines changed: 22 additions & 0 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
2364 | 2364 | |
2365 | 2365 | |
2366 | 2366 | |
| 2367 | + |
| 2368 | + |
| 2369 | + |
| 2370 | + |
| 2371 | + |
| 2372 | + |
| 2373 | + |
| 2374 | + |
| 2375 | + |
| 2376 | + |
| 2377 | + |
2367 | 2378 | |
2368 | 2379 | |
2369 | 2380 | |
| ||
2510 | 2521 | |
2511 | 2522 | |
2512 | 2523 | |
| 2524 | + |
| 2525 | + |
| 2526 | + |
| 2527 | + |
| 2528 | + |
| 2529 | + |
| 2530 | + |
| 2531 | + |
| 2532 | + |
| 2533 | + |
| 2534 | + |
2513 | 2535 | |
2514 | 2536 | |
2515 | 2537 | |
|
Collapse file
doc/api/single-executable-applications.md
Copy file name to clipboardExpand all lines: doc/api/single-executable-applications.md+100-10Lines changed: 100 additions & 10 deletions
- Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
178 | 178 | |
179 | 179 | |
180 | 180 | |
181 | | - |
| 181 | + |
| 182 | + |
| 183 | + |
| 184 | + |
| 185 | + |
182 | 186 | |
183 | 187 | |
184 | 188 | |
185 | 189 | |
186 | 190 | |
187 | 191 | |
188 | 192 | |
| 193 | + |
| 194 | + |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | + |
| 199 | + |
| 200 | + |
| 201 | + |
| 202 | + |
| 203 | + |
| 204 | + |
| 205 | + |
| 206 | + |
| 207 | + |
| 208 | + |
| 209 | + |
| 210 | + |
| 211 | + |
| 212 | + |
| 213 | + |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | + |
| 218 | + |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
189 | 227 | |
190 | 228 | |
191 | 229 | |
| ||
229 | 267 | |
230 | 268 | |
231 | 269 | |
232 | | - |
| 270 | + |
233 | 271 | |
234 | | - |
| 272 | + |
235 | 273 | |
236 | | - |
| 274 | + |
| 275 | + |
| 276 | + |
| 277 | + |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | + |
| 285 | + |
| 286 | + |
| 287 | + |
| 288 | + |
| 289 | + |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
| 299 | + |
| 300 | + |
| 301 | + |
| 302 | + |
| 303 | + |
| 304 | + |
| 305 | + |
| 306 | + |
| 307 | + |
| 308 | + |
| 309 | + |
| 310 | + |
| 311 | + |
| 312 | + |
| 313 | + |
| 314 | + |
| 315 | + |
| 316 | + |
| 317 | + |
| 318 | + |
| 319 | + |
| 320 | + |
| 321 | + |
237 | 322 | |
238 | 323 | |
239 | 324 | |
| ||
250 | 335 | |
251 | 336 | |
252 | 337 | |
253 | | - |
| 338 | + |
254 | 339 | |
255 | | - |
256 | | - |
| 340 | + |
| 341 | + |
257 | 342 | |
258 | | - |
| 343 | + |
259 | 344 | |
260 | | - |
261 | | - |
| 345 | + |
| 346 | + |
| 347 | + |
| 348 | + |
262 | 349 | |
263 | 350 | |
264 | 351 | |
| ||
298 | 385 | |
299 | 386 | |
300 | 387 | |
| 388 | + |
301 | 389 | |
302 | 390 | |
303 | 391 | |
| 392 | + |
| 393 | + |
304 | 394 | |
305 | 395 | |
306 | 396 | |
|
Collapse file
lib/internal/bootstrap/realm.js
Copy file name to clipboardExpand all lines: lib/internal/bootstrap/realm.js+1Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
128 | 128 | |
129 | 129 | |
130 | 130 | |
| 131 | + |
131 | 132 | |
132 | 133 | |
133 | 134 | |
|
Collapse file
+4Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
1632 | 1632 | |
1633 | 1633 | |
1634 | 1634 | |
| 1635 | + |
| 1636 | + |
1635 | 1637 | |
1636 | 1638 | |
1637 | 1639 | |
| ||
1715 | 1717 | |
1716 | 1718 | |
1717 | 1719 | |
| 1720 | + |
| 1721 | + |
1718 | 1722 | |
1719 | 1723 | |
1720 | 1724 | |
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
| 1 | + |
| 2 | + |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | + |
Collapse file
+48Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
4 | 4 | |
5 | 5 | |
6 | 6 | |
| 7 | + |
7 | 8 | |
8 | 9 | |
9 | 10 | |
| ||
101 | 102 | |
102 | 103 | |
103 | 104 | |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | + |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | + |
| 146 | + |
| 147 | + |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | + |
104 | 152 | |
Collapse file
+3Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
6 | 6 | |
7 | 7 | |
8 | 8 | |
| 9 | + |
9 | 10 | |
10 | 11 | |
11 | 12 | |
| ||
15 | 16 | |
16 | 17 | |
17 | 18 | |
| 19 | + |
18 | 20 | |
19 | 21 | |
20 | 22 | |
21 | 23 | |
22 | 24 | |
| 25 | + |
23 | 26 | |
24 | 27 | |
25 | 28 | |
|
0 commit comments