2.0.4 • Published 3 months ago

boot-drive v2.0.4

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

boot-drive

Run an app from a Hyperdrive or Localdrive

npm i boot-drive

Usage

First prepare the drive

const Boot = require('@holepunchto/boot-drive')

const boot = new Boot(drive)
await boot.warmup()

Then you can start it

const exported = boot.start()
console.log(exported)

Or you could just bundle it

const source = boot.stringify()
console.log(source) // eval(source) or save it into a file

API

const boot = new Boot(drive, [options])

Creates a bootloader to run the drive.

Available options:

{
  entrypoint: 'index.js', // Main file to be run at start
  cwd: '.', // Working directory for `prebuilds/`
  absolutePrebuilds: false, // If `true`, will use `cwd` for the stringified prebuilds path
  cache: {}, // Used at runtime for `require.cache`, you can share it between boots
  dependencies: new Map(), // Used in `warmup()`, you can share linker deps between boots
  additionalBuiltins: [], // For adding modules to be imported by Node's native `require`
  builtinsMap: {}, // mappings of core builtins, e.g. fs -> bare-fs
  sourceOverwrites: {}, // Key/Value object where you can map filenames to source code
  host: require.addon.host || process.platform + '-' + process.arch , // used for prebuilds sub-folder
  platform: process.platform, // legacy
  arch: process.arch // legacy
}

When running a drive, there is require.builtinRequire provided by the JS runtime itself.

await boot.warmup([entrypoint])

Prepares the drive.

If entrypoint is not set, then it will try /package.json main property.

If it fails to find an entrypoint then it will use index.js by default.

const exports = boot.start([entrypoint])

Runs the drive.

absolutePrebuilds is always forced to be true by default when using boot.start().

const source = boot.stringify([entrypoint])

Bundles and stringifies the dependencies and source code of the drive.

Without absolutePrebuilds native modules has to always be in ./prebuilds/ related to the source file.

License

Apache-2.0

2.0.3

3 months ago

2.0.2

3 months ago

2.0.4

3 months ago

1.0.2

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.5

1 year ago

0.0.6

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago