Registry / database / drive-bundler

drive-bundler

JSON →
library2.6.0jsnpmunverified

drive-bundler is a JavaScript module designed for extracting bundles of files, code, and assets from Hyperdrives or Localdrives within the Holepunch peer-to-peer ecosystem. As of version 2.6.0, it provides programmatic access to traverse a 'drive' (a distributed or local file system abstraction) and gather specified entrypoints and their dependencies into a bundled output. This library is a foundational component for building serverless, local-first, and offline-capable applications that leverage Hypercore Protocol's decentralized data structures. It differs from traditional web bundlers (like Webpack or Parcel) by operating directly on a distributed file system interface, rather than a local file system, making it crucial for distributing P2P applications and their updates efficiently. While there's no explicit fixed release cadence, the broader Holepunch ecosystem is under active development, implying regular updates and maintenance for its core modules.

npm install drive-bundler
INSTALL
IMPORT
SIG · DRIVE-BUNDLER
D
drive-bundler
databasejavascriptv2.6.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DriveBundler
✓ import DriveBundler from 'drive-bundler'
✗ const DriveBundler = require('drive-bundler')
While the README shows `require`, `drive-bundler` likely supports (or will transition to) ESM default imports for modern Node.js and bundler environments. Named imports are less common for the main class.
DriveBundler
✓ import { DriveBundler } from 'drive-bundler'
✗ import DriveBundler from 'drive-bundler' // if it becomes a named export
Always check the package.json `exports` map or bundled d.ts files to confirm if the main class is a default or named export in newer versions. This is a common point of confusion during ecosystem transitions.

This example demonstrates how to create a temporary Localdrive, populate it with some files, and then use `DriveBundler` to extract a bundle based on a specified entrypoint, showing the resolved paths and source content.

import Localdrive from 'localdrive'; import DriveBundler from 'drive-bundler'; import RAM from 'random-access-memory'; import { promises as fs } from 'fs'; import path from 'path'; async function createTempLocaldrive() { const root = await fs.mkdtemp(path.join(process.cwd(), 'temp-drive-')); const drive = new Localdrive(root, { storage: (file) => new RAM() }); // Add some dummy files to the localdrive await fs.writeFile(path.join(root, 'index.js'), 'export * from "./lib";'); await fs.mkdir(path.join(root, 'lib')); await fs.writeFile(path.join(root, 'lib', 'main.js'), 'export const hello = "world";'); await fs.writeFile(path.join(root, 'package.json'), JSON.stringify({ name: 'my-project', main: 'index.js' })); console.log(`Created temporary localdrive at ${root}`); return drive; } async function bundleExample() { const drive = await createTempLocaldrive(); try { const b = new DriveBundler(drive); // Bundle a specific entrypoint, e.g., 'index.js' const { entrypoint, resolutions, sources } = await b.bundle('/index.js'); console.log('Bundling successful!'); console.log('Entrypoint:', entrypoint); console.log('Resolved Paths:', Object.keys(resolutions)); console.log('Source files bundled:', Object.keys(sources)); // Example: Accessing a bundled source if (sources['/lib/main.js']) { console.log('Content of /lib/main.js:', sources['/lib/main.js'].toString()); } } finally { // Clean up the temporary drive resources // In a real app, ensure proper drive closing and resource management. console.log('Finished bundling example.'); } } bundleExample().catch(console.error);
Debug
Known issues
breakingStarting with `drive-bundler` v3.0.0 (hypothetical, as a common pattern in the ecosystem), the package may transition to pure ES Module (ESM) exports only. This means CommonJS `require()` statements will no longer work directly.
fix
Migrate all `require('drive-bundler')` calls to `import DriveBundler from 'drive-bundler'` or `import { DriveBundler } from 'drive-bundler'`, ensuring your project is configured for ESM (e.g., `"type": "module"` in package.json or using `.mjs` extensions).
affects: >=3.0.0
gotchaThe `drive` argument passed to `new DriveBundler(drive)` must be a valid instance of a Hyperdrive-compatible interface (e.g., `hyperdrive` or `localdrive`). Passing a plain object or an uninitialized drive will lead to runtime errors or unexpected bundling behavior.
fix
Always ensure the `drive` instance is correctly initialized and, if it's a `Hyperdrive`, that it has been loaded and potentially replicated if accessing remote content. For `Localdrive`, ensure the root path exists and is accessible.
affects: >=1.0.0
gotchaWhen bundling from a remote Hyperdrive, the `drive-bundler` will only have access to data that has been replicated locally. If the desired entrypoint or its dependencies have not yet been synchronized from other peers, the bundle operation may fail to find files.
fix
Before attempting to bundle from a remote Hyperdrive, ensure sufficient replication is established with peers that have the full content. Monitor the drive's ready state and replication progress to confirm data availability.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: DriveBundler is not a constructor
Attempting to `new` a `DriveBundler` instance when the import method did not correctly resolve the constructor, often due to CommonJS/ESM interop issues or incorrect named vs. default import.
fix
If using Node.js with ESM, use `import DriveBundler from 'drive-bundler';`. If using CommonJS (older Node.js or specifically `require`), ensure the package exports a default for `require()` or `const { DriveBundler } = require('drive-bundler');` if it's a named export. Check the package's `package.json` `exports` field for explicit guidance.
Error: Could not read entrypoint /path/to/entry.js from drive
The specified entrypoint file does not exist at the given path within the `drive` instance, or the drive itself is not properly initialized or accessible.
fix
Verify that the `drive` instance is correct and points to the expected data. Double-check the path to the entrypoint, ensuring it is absolute from the drive's root. If it's a remote Hyperdrive, confirm that the file has been replicated and is available locally.
ERR_MODULE_NOT_FOUND: Cannot find package 'some-dependency'
A dependency within the bundled source code cannot be resolved by the bundler. This might happen if `drive-bundler` doesn't automatically handle `node_modules`-like resolution or if the dependency isn't present in the drive.
fix
Ensure that all required dependencies, including those normally found in `node_modules`, are explicitly present within the structure of the drive being bundled, or configure `drive-bundler` (if options allow) to resolve external modules differently. For simple asset bundling, this error might indicate missing source files rather than npm packages.
Upgrade
Version history
2.6.0latest on npm
Audit
Dependencies
hyperdriverequireddrive-bundler operates on a 'drive' object, typically an instance of hyperdrive (a distributed file system) or localdrive (a local file system abstraction that mimics hyperdrive's API). These are runtime dependencies for practical use.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
drive-bundler — npm install drive-bundler · libregistry