node/doc/api
Joyee Cheung ce8f085d26
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: https://github.com/nodejs/node/pull/50960
Refs: https://github.com/nodejs/single-executable/issues/68
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-02-02 15:25:34 +01:00
..
addons.md doc: cast GetInternalField() return type to v8::Value in addons.md 2023-09-07 08:51:00 +00:00
assert.md doc: fix params names 2023-05-06 19:41:58 +00:00
async_context.md 2023-04-18, Version 20.0.0 (Current) 2023-04-18 13:04:39 -03:00
async_hooks.md doc: declare path on example of async_hooks.executionAsyncId() 2023-07-18 20:00:50 +00:00
buffer.md doc: fix Buffer.allocUnsafe documentation 2023-11-15 14:51:25 +01:00
child_process.md doc: remove reference to resolved child_process v8 issue 2024-01-18 18:48:45 +00:00
cli.md src: support multi-line values for .env file 2024-01-31 13:09:13 +00:00
cluster.md doc: improve the documentation of the stdio option 2023-05-30 06:10:58 +00:00
console.md doc: update to align console.table row to the left 2023-11-06 16:47:53 +00:00
corepack.md doc: update corepack.md to account for 0.20.0 changes 2023-09-16 11:52:30 +02:00
crypto.md doc: remove ambiguous 'considered' 2023-12-20 18:45:58 +00:00
debugger.md debugger: improve validations and documents for watch and unwatch 2023-03-13 04:29:53 +00:00
deprecations.md doc: mark isWebAssemblyCompiledModule eol 2024-01-14 12:13:28 +00:00
dgram.md doc: fix typo in dgram docs 2023-10-18 00:46:38 +00:00
diagnostics_channel.md doc: correct tracingChannel.traceCallback() 2023-12-08 21:01:23 +00:00
dns.md doc: fix dns.lookup and dnsPromises.lookup description 2024-01-30 02:20:39 +01:00
documentation.md doc: add experimental stages 2023-01-14 14:25:08 +00:00
domain.md doc: fix typos 2023-04-23 13:34:08 +00:00
embedding.md src: add detailed embedder process initialization API 2022-08-05 19:46:08 +00:00
errors.md sea: support embedding assets 2024-02-02 15:25:34 +01:00
esm.md 2024-01-09, Version 20.11.0 'Iron' (LTS) 2024-01-09 20:47:16 +00:00
events.md doc: fix print results in events 2023-09-19 17:31:09 +00:00
fs.md fs: make offset, position & length args in fh.read() optional 2023-12-22 12:41:22 +00:00
globals.md doc: fix historical experimental fetch flag 2024-01-20 02:01:31 +00:00
http2.md http2: add h2 compat support for appendHeader 2024-01-12 16:09:57 +00:00
http.md http2: add h2 compat support for appendHeader 2024-01-12 16:09:57 +00:00
https.md doc: get rid of unnecessary eslint-skip comments 2023-11-22 19:03:33 +00:00
index.md src: add initial support for single executable applications 2023-02-18 02:49:18 +00:00
inspector.md doc: add notes on inspector breakpoints 2024-01-18 06:30:33 +00:00
intl.md doc: improve documentation about ICU data fallback 2023-09-22 13:24:23 +00:00
module.md doc: fix spelling mistake 2024-01-14 09:21:42 +00:00
modules.md esm: detect ESM syntax in ambiguous JavaScript 2023-10-20 15:44:56 +00:00
n-api.md 2024-01-15, Version 21.6.0 (Current) 2024-01-15 11:50:31 -03:00
net.md doc: fix type of connectionAttempt parameter 2024-01-19 16:12:16 +00:00
os.md doc: add loong64 to list of architectures 2023-10-16 20:19:31 +00:00
packages.md doc: add note regarding --experimental-detect-module 2023-12-10 00:35:03 +01:00
path.md doc: note that path.normalize deviates from POSIX 2024-01-29 15:45:38 +00:00
perf_hooks.md doc: update print results(detail) in PerformanceEntry 2023-11-17 13:49:26 +00:00
permissions.md doc: fix some policy scope typos 2024-01-08 20:39:17 +00:00
policy.md doc: add missing period 2023-08-10 15:37:10 +00:00
process.md src: add process.loadEnvFile and util.parseEnv 2024-01-23 18:46:26 +00:00
punycode.md doc: format doc/api/*.md with markdown formatter 2021-10-20 11:59:11 +02:00
querystring.md doc: get rid of unnecessary eslint-skip comments 2023-11-22 19:03:33 +00:00
readline.md doc: detailed description of keystrokes Ctrl-Y and Meta-Y 2023-08-08 19:51:43 +00:00
repl.md doc: harmonize fenced code snippet flags 2023-05-21 09:36:57 +02:00
report.md doc: use "file system" instead of "filesystem" 2023-01-14 01:10:38 +00:00
single-executable-applications.md sea: support embedding assets 2024-02-02 15:25:34 +01:00
stream.md 2023-11-29, Version 18.19.0 'Hydrogen' (LTS) 2023-11-29 18:11:08 +01:00
string_decoder.md doc: add print results for examples in StringDecoder 2023-08-27 15:32:47 +00:00
synopsis.md doc: clarify explaination text on how to run the example 2023-10-06 13:37:31 +00:00
test.md 2024-01-09, Version 20.11.0 'Iron' (LTS) 2024-01-09 20:47:16 +00:00
timers.md 2023-09-18, Version 18.18.0 'Hydrogen' (LTS) 2023-09-18 17:39:17 -04:00
tls.md 2023-11-29, Version 18.19.0 'Hydrogen' (LTS) 2023-11-29 18:11:08 +01:00
tracing.md src: trace threadpool event 2022-11-01 04:21:13 +00:00
tty.md doc: clarify tty.isRaw 2023-05-21 16:41:28 +00:00
url.md doc: fix history comments 2023-09-20 12:40:54 +00:00
util.md src: add process.loadEnvFile and util.parseEnv 2024-01-23 18:46:26 +00:00
v8.md doc,test: update the v8.startupSnapshot doc and test the example 2023-05-03 13:14:56 +00:00
vm.md vm: support using the default loader to handle dynamic import() 2024-02-01 11:45:42 +00:00
wasi.md 2024-01-09, Version 20.11.0 'Iron' (LTS) 2024-01-09 20:47:16 +00:00
webcrypto.md doc: use length argument in pbkdf2Key 2023-12-07 23:23:41 +00:00
webstreams.md stream: implement min option for ReadableStreamBYOBReader.read 2024-01-04 12:57:14 +01:00
worker_threads.md 2023-10-17, Version 21.0.0 (Current) 2023-10-17 12:45:37 -03:00
zlib.md doc: add lint rule to enforce trailing commas 2022-11-17 13:19:12 +00:00