What is @rushstack/package-deps-hash?
@rushstack/package-deps-hash is a utility for computing a hash based on the contents of a package and its dependencies. This is particularly useful for build systems and caching mechanisms where you need to determine if a package or its dependencies have changed.
What are @rushstack/package-deps-hash's main functionalities?
Compute Package Hash
This feature allows you to compute a hash for a given package directory. The hash is based on the contents of the package and its dependencies, which can be used to determine if any changes have occurred.
const { getPackageDeps } = require('@rushstack/package-deps-hash');
const path = require('path');
async function computeHash() {
const packagePath = path.resolve(__dirname, 'path/to/your/package');
const packageDeps = await getPackageDeps(packagePath);
console.log(packageDeps);
}
computeHash();
Custom File Globs
This feature allows you to specify custom file globs to include in the hash computation. This can be useful if you want to include or exclude specific files or types of files in the hash calculation.
const { getPackageDeps } = require('@rushstack/package-deps-hash');
const path = require('path');
async function computeHashWithGlobs() {
const packagePath = path.resolve(__dirname, 'path/to/your/package');
const customGlobs = ['**/*.js', '**/*.json'];
const packageDeps = await getPackageDeps(packagePath, { globs: customGlobs });
console.log(packageDeps);
}
computeHashWithGlobs();
Other packages similar to @rushstack/package-deps-hash
hasha
hasha is a package for hashing files and strings using various algorithms. It is more general-purpose compared to @rushstack/package-deps-hash, which is specifically designed for hashing package dependencies.
crypto
crypto is a built-in Node.js module that provides cryptographic functionality, including hashing. While it can be used to hash files and strings, it does not provide the same level of convenience for hashing package dependencies as @rushstack/package-deps-hash.
webpack
webpack is a module bundler that includes functionality for hashing the contents of bundles. While it can be used to achieve similar goals, it is a much larger and more complex tool compared to @rushstack/package-deps-hash.