Registry / devops / bit-bundler-utils

bit-bundler-utils

JSON →
library5.1.2jsnpmunverified

Bit-Bundler Utilities (`bit-bundler-utils`) is a Node.js helper library providing essential functionalities for projects built with `bit-bundler` and `bit-imports`. Currently at stable version 5.1.2, this package offers utilities for generating and managing unique module IDs, robustly resolving module and file paths, and asynchronously reading file contents from disk. Its path resolution capabilities are powered by `browser-resolve`, making it suitable for both Node.js and browser-compatible path handling. The library emphasizes stability and integration within the `bit-bundler` ecosystem, maintaining an `active` release cadence with regular patch updates to ensure reliability and address minor issues.

npm install bit-bundler-utils
INSTALL
IMPORT
SIG · BIT-BUNDLER-UTILS
B
bit-bundler-utils
devopsjavascriptv5.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

uniqueId
const uniqueId = require('bit-bundler-utils/uniqueId');
import uniqueId from 'bit-bundler-utils/uniqueId';
This module exports an object containing `getId` and `setId` methods. Direct ES module `import` syntax is generally not supported without bundler intervention, as this library is primarily CommonJS.
resolvePath
const resolvePath = require('bit-bundler-utils/resolvePath');
import resolvePath from 'bit-bundler-utils/resolvePath';
The `resolvePath` function is exported directly as a CommonJS module. It returns a Promise.
readFile
const readFile = require('bit-bundler-utils/readFile');
import readFile from 'bit-bundler-utils/readFile';
The `readFile` function is exported directly as a CommonJS module. It returns a Promise and handles binary files gracefully.

This quickstart demonstrates resolving a module path, reading its content, and using the unique ID generation and setting functionalities.

const resolvePath = require('bit-bundler-utils/resolvePath'); const readFile = require('bit-bundler-utils/readFile'); const uniqueId = require('bit-bundler-utils/uniqueId'); async function exampleUsage() { try { // Resolve a module path const result = await resolvePath({ name: 'some-local-module', baseUrl: process.cwd() }); console.log(`Resolved path for 'some-local-module': ${result.path}`); // Read a file's content const fileContent = await readFile({ path: result.path // Using the resolved path }); console.log(`Content snippet from ${result.path}: ${fileContent.source.substring(0, 100)}...`); // Generate and set unique IDs const id1 = uniqueId.getId('path/to/moduleA.js'); const id2 = uniqueId.getId('path/to/moduleB.js'); console.log(`ID for moduleA: ${id1}`); console.log(`ID for moduleB: ${id2}`); uniqueId.setId('path/to/special-module.js', 123); console.log(`Explicitly set ID for 'path/to/special-module.js'.`); } catch (error) { console.error('An error occurred:', error.message); } } exampleUsage();
Debug
Known issues
gotchaThe `uniqueId.setId` method will throw an exception if called more than once for the same `moduleId` but with a *different* `value`. It is designed to ensure a module ID maps to a single, consistent unique value after its initial setting.
fix
Ensure `uniqueId.setId` is called with the same `value` for subsequent calls with the same `moduleId`, or design your application to set the ID only once per module. Repeated calls with the *same* `moduleId` and `value` are permitted.
affects: >=1.0.0
gotchaThe `uniqueId.getId` method caches its results. Subsequent calls with the same `moduleId` will return the exact same generated ID without re-computation.
fix
Be aware of the caching behavior when testing or in scenarios where dynamic ID generation with different results for the same input might be expected. This is by design for performance and consistency within the `bit-bundler` ecosystem.
affects: >=1.0.0
gotchaThis library primarily uses CommonJS (`require()`) module syntax. While modern Node.js environments support ESM (`import`), direct ESM imports for `bit-bundler-utils`'s subpath exports might not work as expected or without additional bundler configuration.
fix
Prefer `const module = require('bit-bundler-utils/subpath');` syntax. If you must use ESM, ensure your build tool (e.g., Webpack, Rollup) is configured to handle CommonJS modules within an ESM project, or use dynamic `import()` for CJS modules if supported by your runtime.
affects: >=1.0.0
Errors
Common errors & fixes
Error: setId can only be set once with a different value. Original value was [original_value], new value is [new_value]
Attempting to call `uniqueId.setId` for the same `moduleId` with a `value` different from what was previously set.
fix
Review calls to `uniqueId.setId` to ensure consistency. If a module's unique ID needs to change, it indicates a design flaw or a need to reset the `uniqueId` state (which is not directly exposed by the API).
Cannot find module 'bit-bundler-utils/resolvePath'
The package `bit-bundler-utils` is not installed, or the specified subpath (`/resolvePath`, `/readFile`, `/uniqueId`) is incorrect.
fix
Ensure `bit-bundler-utils` is correctly installed via `npm install bit-bundler-utils` and that the `require()` path matches one of the documented subpath exports.
TypeError: [exported_function] is not a function
Incorrect module import syntax. This library is CommonJS-based, and direct `import` statements might not correctly resolve its exports or may treat the default export differently than expected.
fix
Change `import` statements to CommonJS `require()` syntax: `const resolvePath = require('bit-bundler-utils/resolvePath');`
Upgrade
Version history
5.1.2latest on npm
Audit
Dependencies
browser-resolverequiredUsed internally by the `resolvePath` utility for Node.js module resolution, enabling consistent path handling for both Node.js and browser environments.
Agent activity
11 hits · last 30 days
node
8
Amazon
1
Resources
bit-bundler-utils — npm install bit-bundler-utils · libregistry