How to use package-hash - 6 common examples

To help you get started, we’ve selected a few package-hash examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github avajs / ava / lib / babel-pipeline.js View on Github external
// Note that Babel ignores empty string values, even for NODE_ENV. Here
	// default to 'test' unless NODE_ENV is defined, in which case fall back to
	// Babel's default of 'development' if it's empty.
	const envName = process.env.BABEL_ENV || ('NODE_ENV' in process.env ? process.env.NODE_ENV : 'test') || 'development';

	// Prepare inputs for caching seeds. Compute a seed based on the Node.js
	// version and the project directory. Dependency hashes may vary based on the
	// Node.js version, e.g. with the @ava/stage-4 Babel preset. Certain plugins
	// and presets are provided as absolute paths, which wouldn't necessarily
	// be valid if the project directory changes. Also include `envName`, so
	// options can be cached even if users change BABEL_ENV or NODE_ENV between
	// runs.
	const seedInputs = [
		process.versions.node,
		packageHash.sync(require.resolve('../package.json')),
		projectDir,
		envName,
		concordance.serialize(concordance.describe(userOptions))
	];

	const partialCacheKey = md5Hex(seedInputs);
	const pluginAndPresetHashes = new Map();

	const ensureStage4 = wantsStage4(userOptions, projectDir, {experiments});
	const containsStage4 = makeValueChecker('../stage-4');
	const containsTransformTestFiles = makeValueChecker('@ava/babel-preset-transform-test-files');

	const loadOptions = filename => {
		const partialTestConfig = babel.loadPartialConfig({
			babelrc: false,
			babelrcRoots: [projectDir],
github novemberborn / hullabaloo-config-manager / test / hashDependencies.js View on Github external
test('hashes packages', async t => {
  const fromPackage = fixture('compare', 'node_modules', 'plugin')
  const filename = path.join(fromPackage, 'index.js')
  const hashed = await hashDependencies([
    {filename, fromPackage}
  ])
  t.deepEqual(hashed, [await packageHash(path.join(fromPackage, 'package.json'))])
})
github novemberborn / hullabaloo-config-manager / test / Verifier.js View on Github external
test.before(t => {
  const promises = []

  for (const pkg of [
    fixture('compare', 'node_modules', 'env-plugin', 'package.json'),
    fixture('compare', 'node_modules', 'plugin', 'package.json'),
    fixture('compare', 'node_modules', 'plugin-copy', 'package.json'),
    fixture('compare', 'node_modules', 'plugin-default-opts', 'package.json'),
    fixture('compare', 'node_modules', 'preset', 'package.json')
  ]) {
    promises.push(
      packageHash(pkg)
        .then(hash => (hashes[pkg] = hash)))
  }

  for (const fp of [
    fixture('compare', '.babelrc'),
    fixture('compare', 'dir', 'subdir', 'extended-by-babelrc.js'),
    fixture('compare', 'extended-by-virtual.json5'),
    fixture('compare', 'dir', 'extended-by-virtual-foo.json5'),
    fixture('compare', 'virtual.json')
  ]) {
    promises.push(
      new Promise((resolve, reject) => {
        fs.readFile(fp, (err, contents) => err ? reject(err) : resolve(contents))
      })
        .then(md5Hex)
        .then(hash => (hashes[fp] = hash)))
github avajs / ava / lib / babel-pipeline.js View on Github external
for (const item of [...plugins, ...presets]) {
		if (!item.file) {
			continue;
		}

		const {file: {resolved: filename}} = item;
		if (pluginAndPresetHashes.has(filename)) {
			inputs.push(pluginAndPresetHashes.get(filename));
			continue;
		}

		const [firstComponent] = path.relative(projectDir, filename).split(path.sep);
		let hash;
		if (firstComponent === 'node_modules') {
			hash = packageHash.sync(findUp.sync('package.json', {cwd: path.dirname(filename)}));
		} else {
			hash = md5Hex(stripBomBuf(fs.readFileSync(filename)));
		}

		pluginAndPresetHashes.set(filename, hash);
		inputs.push(hash);
	}

	return md5Hex(inputs);
}
github avajs / ava / lib / caching-precompiler.js View on Github external
_createTransform() {
		const salt = packageHash.sync([
			require.resolve('../package.json'),
			require.resolve('@babel/core/package.json')
		], this.babelCacheKeys);

		return cachingTransform({
			factory: this._init,
			cacheDir: this.cacheDirPath,
			hash: this._generateHash,
			salt,
			ext: '.js'
		});
	}
github istanbuljs / caching-transform / index.js View on Github external
function getOwnHash() {
	ownHash = packageHash.sync(path.join(__dirname, 'package.json'));
	return ownHash;
}

package-hash

Generates a hash for an installed npm package, useful for salting caches

ISC
Latest version published 6 years ago

Package Health Score

68 / 100
Full package analysis

Popular package-hash functions

Similar packages