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-bundlerVerified import paths — ran on the pinned version, not inferred.
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.
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).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.
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.
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.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.
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.