How to use the package-hash.sync function in package-hash

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 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