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)
API
const boot = new Boot(drive, [options])
Creates a bootloader to run the drive.
Available options:
{
entrypoint: 'index.js',
cwd: '.',
absolutePrebuilds: false,
cache: {},
dependencies: new Map(),
additionalBuiltins: [],
builtinsMap: {},
sourceOverwrites: {},
host: require.addon.host || process.platform + '-' + process.arch ,
platform: process.platform,
arch: process.arch
}
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