LogoPear Docs

bare-bundle-id

Construct a unique ID for a bundle

stable

bare-bundle-id — Construct a unique ID for a bundle.

npm i bare-bundle-id

Usage

const Bundle = require('bare-bundle')
const id = require('bare-bundle-id')

const bundle = new Bundle()
  .write('/foo.js', "module.exports = require('./bar')", {
    main: true,
    imports: {
      './bar': '/bar.js'
    }
  })
  .write('/bar.js', 'module.exports = 42')

bundle.id = id(bundle).toString('hex')
// 33824862...

API

Functions

id(bundle: Bundle): Buffer

Source

Returns a 32-byte BLAKE2b hash of bundle's sorted file entries (path, contents, and mode), uniquely identifying the bundle's contents.

Parameters

ParameterTypeDefaultDescription
bundleBundleThe bare-bundle instance to hash; its file entries are sorted by path before hashing, so the ID is stable regardless of the order they were written in.

See also

On this page