LogoPear Docs

bare-bundle

Application bundle format for JavaScript

stable

bare-bundle — Application bundle format for JavaScript.

npm i bare-bundle

API

Bundle

new Bundle(opts?: BundleOptions)

Source

Create an empty Bundle, optionally supplying a custom File class to back stored files.

Parameters

ParameterTypeDefaultDescription
opts?BundleOptionsOptions; 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

ParameterTypeDefaultDescription
valuestring | Buffer | BundleThe 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

ParameterTypeDefaultDescription
valueunknownThe value to check.

Returns value is Bundletrue 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 booleantrue if the bundle contains no files, false otherwise.

exists(key: string): boolean

Source

Check whether a file exists at key.

Parameters

ParameterTypeDefaultDescription
keystringThe key of the file to look up.

Returns booleantrue 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

ParameterTypeDefaultDescription
keystringThe 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

ParameterTypeDefaultDescription
rootstring | URLThe base URL (or URL string) to resolve keys and specifiers against.
opts?BundleMountOptionsOptions; 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

ParameterTypeDefaultDescription
keystringThe 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

ParameterTypeDefaultDescription
opts?BundleToBufferOptionsOptions; 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

ParameterTypeDefaultDescription
rootstring | URLThe base URL (or URL string) to make keys and specifiers relative to.
opts?BundleMountOptionsOptions; 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

ParameterTypeDefaultDescription
keystringThe key (path) to store the file under.
datastringThe file contents.
opts?BundleWriteOptionsOptions; main, addon, asset, and executable default to false, and alias and imports to unset.

Returns this — The bundle itself, for chaining writes.

Throws

  • TypeErrorkey is 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

ParameterTypeDefaultDescription
datastring | BufferThe file contents; a string is converted to a Buffer.
opts?MemoryFileOptionsOptions; 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
}
Source

BundleOptions

interface BundleOptions {
  File?: typeof MemoryFile
}
Source

BundleWriteOptions

interface BundleWriteOptions {
  addon?: boolean
  alias?: string
  asset?: boolean
  executable?: boolean
  imports?: RecursiveStringObject
  main?: boolean
  mode?: number
}
Source

BundleMountOptions

interface BundleMountOptions {
  conditions?: { [condition: string]: string | URL }
}
Source

BundleToBufferOptions

interface BundleToBufferOptions {
  indent?: number
  shared?: boolean
}
Source

See also

On this page