bare-bundle
Application bundle format for JavaScript
bare-bundle — Application bundle format for JavaScript.
npm i bare-bundleAPI
Bundle
new Bundle(opts?: BundleOptions)
Source
Create an empty Bundle, optionally supplying a custom File class to back stored files.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | BundleOptions | — | Options; File defaults to MemoryFile. |
addons: string[]
Source
The keys of files in the bundle that are native addons.
assets: string[]
Source
The keys of files in the bundle that are non-JavaScript assets.
Bundle.from(value: string | Buffer | Bundle): Bundle
Source
Coerce value — a serialized bundle string, a Buffer, or an existing Bundle — into a Bundle.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | string | Buffer | Bundle | — | The serialized bundle string or buffer to parse, or an existing Bundle. |
Returns Bundle — The parsed Bundle, or value itself if it is already a Bundle.
Throws
INVALID_BUNDLE_HEADER— the serialized header is not valid JSON.
Bundle.isBundle(value: unknown): value is Bundle
Source
Check whether value is a Bundle.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | unknown | — | The value to check. |
Returns value is Bundle — true if value is a Bundle instance or exposes the bundle kind symbol, false otherwise.
Bundle.version: number
Source
The bundle format version this implementation produces and expects.
empty(): boolean
Source
Check whether the bundle contains no files.
Returns boolean — true if the bundle contains no files, false otherwise.
exists(key: string): boolean
Source
Check whether a file exists at key.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | — | The key of the file to look up. |
Returns boolean — true if a file exists at key, false otherwise.
files: Record<string, MemoryFile>
Source
The bundle's files, keyed by path, as MemoryFile instances.
id: string | null
Source
An optional identifier for the bundle, or null if unset.
imports: RecursiveStringObject
Source
The bundle's import map, mapping specifiers to file keys.
keys(): string[]
Source
Return the keys of all files in the bundle.
main: string | null
Source
The key of the bundle's entry file, or null if unset.
mode(key: string): number
Source
Return the file mode (permission bits) of the file at key, or 0 if it doesn't exist.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | — | The key of the file to look up. |
mount(root: string | URL, opts?: BundleMountOptions): Bundle
Source
Return a copy of the bundle with all file keys and import/resolution specifiers rewritten as absolute URLs resolved against root.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
root | string | URL | — | The base URL (or URL string) to resolve keys and specifiers against. |
opts? | BundleMountOptions | — | Options; conditions maps import-map condition names to per-condition roots. |
Returns Bundle — A new Bundle with rewritten keys; the original bundle is left unchanged.
read(key: string): Buffer
Source
Return the contents of the file at key as a Buffer, or null if it doesn't exist.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | — | The key of the file to read. |
resolutions: RecursiveStringObject
Source
The bundle's per-file import resolutions map, used to override the default import map for specific files.
toBuffer(opts?: BundleToBufferOptions): Buffer
Source
Serialize the bundle to a single Buffer containing its header and file contents.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts? | BundleToBufferOptions | — | Options; indent defaults to 0 and shared to false. |
unmount(root: string | URL, opts?: BundleMountOptions): Bundle
Source
Return a copy of the bundle with all file keys and import/resolution specifiers rewritten as paths relative to root, reversing mount().
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
root | string | URL | — | The base URL (or URL string) to make keys and specifiers relative to. |
opts? | BundleMountOptions | — | Options; conditions maps import-map condition names to per-condition roots. |
Returns Bundle — A new Bundle with rewritten keys; the original bundle is left unchanged.
version: number
Source
The bundle format version this implementation produces and expects.
write(key: string, data: string, opts?: BundleWriteOptions): this
Source
Add or replace the file at key with data, optionally marking it as the main entry, an addon, an asset, or aliased in the import map.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
key | string | — | The key (path) to store the file under. |
data | string | — | The file contents. |
opts? | BundleWriteOptions | — | Options; main, addon, asset, and executable default to false, and alias and imports to unset. |
Returns this — The bundle itself, for chaining writes.
Throws
TypeError—keyis not a string.
MemoryFile
new MemoryFile(data: string | Buffer, opts?: MemoryFileOptions)
Source
Create a MemoryFile from data, optionally marking it executable or setting an explicit mode.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | string | Buffer | — | The file contents; a string is converted to a Buffer. |
opts? | MemoryFileOptions | — | Options; mode defaults to 0o755 when executable is true, otherwise 0o644. |
mode(): number
Source
Return the file's mode (permission bits).
read(): Buffer
Source
Return the file's contents as a Buffer.
size(): number
Source
Return the file's byte length.
Types
MemoryFileOptions
interface MemoryFileOptions {
executable?: boolean
mode?: number
}BundleOptions
interface BundleOptions {
File?: typeof MemoryFile
}BundleWriteOptions
interface BundleWriteOptions {
addon?: boolean
alias?: string
asset?: boolean
executable?: boolean
imports?: RecursiveStringObject
main?: boolean
mode?: number
}BundleMountOptions
interface BundleMountOptions {
conditions?: { [condition: string]: string | URL }
}BundleToBufferOptions
interface BundleToBufferOptions {
indent?: number
shared?: boolean
}See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.