🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

boot-drive

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boot-drive

Run an app from a Hyperdrive or Localdrive

latest
Source
npmnpm
Version
2.0.4
Version published
Weekly downloads
181
761.9%
Maintainers
2
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 29 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts