{"_id":"env-hash","_rev":"306785","name":"env-hash","description":"Produces a hash value representing the state of a typical Node/NPM environment","dist-tags":{"latest":"1.1.0"},"maintainers":[{"name":"markfinger","email":"markfinger@gmail.com"}],"time":{"modified":"2021-06-03T19:34:08.000Z","created":"2016-01-30T06:21:27.305Z","1.1.0":"2016-08-21T00:27:12.930Z","1.0.1":"2016-02-22T08:23:37.860Z","1.0.0":"2016-02-22T07:41:38.105Z","0.0.1":"2016-01-30T06:21:27.305Z"},"users":{"langri-sha":true},"author":{"name":"Mark Finger"},"repository":{"type":"git","url":"git+https://github.com/markfinger/env-hash.git"},"versions":{"1.1.0":{"name":"env-hash","version":"1.1.0","description":"Produces a hash value representing the state of a typical Node/NPM environment","main":"lib/index.js","scripts":{"test":"mocha --reporter spec"},"repository":{"type":"git","url":"git+https://github.com/markfinger/env-hash.git"},"bugs":{"url":"https://github.com/markfinger/env-hash/issues"},"homepage":"https://github.com/markfinger/env-hash#readme","author":{"name":"Mark Finger"},"license":"MIT","dependencies":{"imurmurhash":"^0.1.4","lodash":"^4.5.1"},"devDependencies":{"async":"^1.5.2","chai":"^3.5.0","mkdirp":"^0.5.1","mocha":"^2.4.5","rimraf":"^2.5.2","yargs":"^4.1.0"},"gitHead":"0e4818853eb7ad716eab58396ea066e6b6c656fe","_id":"env-hash@1.1.0","_shasum":"cc7c670dbbe5f076b39b4854937996a7c640f030","_from":".","_npmVersion":"3.8.6","_nodeVersion":"6.1.0","_npmUser":{"name":"markfinger","email":"markfinger@gmail.com"},"maintainers":[{"name":"markfinger","email":"markfinger@gmail.com"}],"dist":{"shasum":"cc7c670dbbe5f076b39b4854937996a7c640f030","size":4619,"noattachment":false,"key":"/env-hash/-/env-hash-1.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/env-hash/download/env-hash-1.1.0.tgz"},"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/env-hash-1.1.0.tgz_1471739232697_0.4941541450098157"},"directories":{},"publish_time":1471739232930,"_cnpm_publish_time":1471739232930,"_hasShrinkwrap":false},"1.0.1":{"name":"env-hash","version":"1.0.1","description":"Produces a hash value representing the state of a typical Node/NPM environment","main":"lib/index.js","scripts":{"test":"mocha --require source-map-support/register --reporter spec 'lib/**/tests/*.js'","_test":"mocha --reporter spec 'lib/**/tests/*.js'","lint":"eslint runtime/*.js src/**","build":"./scripts/build.js"},"repository":{"type":"git","url":"git+https://github.com/markfinger/env-hash.git"},"bugs":{"url":"https://github.com/markfinger/env-hash/issues"},"homepage":"https://github.com/markfinger/env-hash#readme","author":{"name":"Mark Finger"},"license":"MIT","dependencies":{"imurmurhash":"^0.1.4","lodash":"^4.5.1"},"devDependencies":{"async":"^1.5.2","babel-cli":"^6.5.1","babel-eslint":"^5.0.0","babel-preset-es2015":"^6.5.0","chai":"^3.5.0","eslint":"^2.2.0","mkdirp":"^0.5.1","mocha":"^2.4.5","rimraf":"^2.5.2","source-map-support":"^0.4.0","yargs":"^4.1.0"},"gitHead":"b9e2f9acacb8be88eba2270665326d2382263ced","_id":"env-hash@1.0.1","_shasum":"cca11a66c3785fdfe0c4f504c1f4a385ec5bedb7","_from":".","_npmVersion":"3.7.1","_nodeVersion":"5.5.0","_npmUser":{"name":"markfinger","email":"markfinger@gmail.com"},"maintainers":[{"name":"markfinger","email":"markfinger@gmail.com"}],"dist":{"shasum":"cca11a66c3785fdfe0c4f504c1f4a385ec5bedb7","size":8671,"noattachment":false,"key":"/env-hash/-/env-hash-1.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/env-hash/download/env-hash-1.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-6-west.internal.npmjs.com","tmp":"tmp/env-hash-1.0.1.tgz_1456129414473_0.8049938890617341"},"directories":{},"publish_time":1456129417860,"_cnpm_publish_time":1456129417860,"_hasShrinkwrap":false},"1.0.0":{"name":"env-hash","version":"1.0.0","description":"Produces a hash value representing the state of a typical Node/NPM environment","main":"lib/index.js","scripts":{"test":"mocha --require source-map-support/register --reporter spec 'lib/**/tests/*.js'","_test":"mocha --reporter spec 'lib/**/tests/*.js'","lint":"eslint runtime/*.js src/**","build":"./scripts/build.js"},"repository":{"type":"git","url":"git+https://github.com/markfinger/env-hash.git"},"bugs":{"url":"https://github.com/markfinger/env-hash/issues"},"homepage":"https://github.com/markfinger/env-hash#readme","author":{"name":"Mark Finger"},"license":"MIT","dependencies":{"imurmurhash":"^0.1.4","lodash":"^4.5.1"},"devDependencies":{"async":"^1.5.2","babel-cli":"^6.5.1","babel-eslint":"^5.0.0","babel-preset-es2015":"^6.5.0","chai":"^3.5.0","eslint":"^2.2.0","mkdirp":"^0.5.1","mocha":"^2.4.5","rimraf":"^2.5.2","source-map-support":"^0.4.0","yargs":"^4.1.0"},"gitHead":"5b91eecddec0b24b1e94152fc66e6cec50cdcb97","_id":"env-hash@1.0.0","_shasum":"5c52bc1aa3896bef6954c751a8cee224809d4383","_from":".","_npmVersion":"3.7.1","_nodeVersion":"5.5.0","_npmUser":{"name":"markfinger","email":"markfinger@gmail.com"},"maintainers":[{"name":"markfinger","email":"markfinger@gmail.com"}],"dist":{"shasum":"5c52bc1aa3896bef6954c751a8cee224809d4383","size":8673,"noattachment":false,"key":"/env-hash/-/env-hash-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/env-hash/download/env-hash-1.0.0.tgz"},"_npmOperationalInternal":{"host":"packages-9-west.internal.npmjs.com","tmp":"tmp/env-hash-1.0.0.tgz_1456126894977_0.3201375773642212"},"directories":{},"publish_time":1456126898105,"_cnpm_publish_time":1456126898105,"_hasShrinkwrap":false},"0.0.1":{"name":"env-hash","version":"0.0.1","description":"env-hash ========","main":"index.js","directories":{"test":"tests"},"scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":"","license":"MIT","_id":"env-hash@0.0.1","_shasum":"4426f45b4c080e7c82fe97be6f47c4ab4f91b7e7","_from":".","_npmVersion":"3.5.3","_nodeVersion":"5.3.0","_npmUser":{"name":"markfinger","email":"markfinger@gmail.com"},"maintainers":[{"name":"markfinger","email":"markfinger@gmail.com"}],"dist":{"shasum":"4426f45b4c080e7c82fe97be6f47c4ab4f91b7e7","size":3147,"noattachment":false,"key":"/env-hash/-/env-hash-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/env-hash/download/env-hash-0.0.1.tgz"},"publish_time":1454134887305,"_cnpm_publish_time":1454134887305,"_hasShrinkwrap":false}},"readme":"# env-hash\n\nProduces a hash value representing the state of a _typical_ Node/NPM environment.\n\nBy default, the hash generated is a product of the mtimes and content of selected\nfiles and directories. By default, `package.json` and `node_modules` are used.\n\nThis package is used by [unfort](https://github.com/markfinger/unfort) to produce\nhash values that namespace cached data. This enables unfort to aggressively cache\ndata that will be invalidated automatically when the next generated hash differs\nfrom the previous.\n\n\n## Install\n\n`npm install --save env-hash`\n\n\n## Example\n\n```js\nimport envHash from 'env-hash';\n\nenvHash().then(hash => {\n  console.log(hash);\n  // something like 3983761008_3107418173\n});\n```\n\n## Options\n\nEnv-hash accepts three options, `root`, `files` and `directories`.\n\n- `root` is the origin directory that is prepended to all relative paths. Defaults to `process.cwd()`\n- `files` is an array of relative or absolute file paths. Defaults to `['package.json']`\n- `directories` is an array of relative or absolute directory paths. Defaults to `['node_modules']`\n\nOptions can be specified in an object passed to env-hash:\n\n```js\nimport envHash from 'env-hash';\n\nenvHash({\n  // defaults\n  root: process.cwd(),\n  files: ['package.json'],\n  directories: ['node_modules']\n}).then(hash => {\n  console.log(hash);\n  // something like 3983761008_3107418173\n});\n```\n\n\n## Background & trade-offs\n\nA section from the original research and design docs of unfort:\n\n> We aggressively cache path resolution of external packages, but, as always, cache\ninvalidation is a pain. To resolve if our cached data is still valid, we need a\nway to uniquely identify the state of the node_modules package tree.\n\n> The most accurate, but slowest, method would be to crawl node_modules and generate\na hash from the file tree. This would work well on small code bases, but more typical\npackage trees will introduce multiple seconds of overhead as the tree is crawled.\nWhile non-blocking IO would help to prevent unblock the event loop, crawling the tree\nwill still consume most of libuv's thread pool, let alone blocking any code that\ndepends on the result of the crawl.\n\n> A similar - and somewhat more performant - approach is to use the same mechanism that\nNPM uses to walk the tree, eg: recursively read the package.json, then look in\nnode_modules for more modules, etc. This still has a fair measure of IO overhead\nthough. It also requires you to introspect each package's package.json in some fashion,\neither hashing the contents, reading the version, or just stating the file.\n\n> The simplest - and most performant - solution would be to treat the root package.json\nas a canonical indicator, and simply hash its content. However, in practice this falls\napart as NPM will install packages that are semantic version compatible, but that may\nnot match the exact versions specified in package.json. Additionally, as NPM 3 builds\nthe dependency tree non-deterministically, the state of the node_modules tree can't be\nrelied upon without interrogating it.\n\n> A performant approach - that maintains some accuracy - is to do a shallow crawl of the\nnode_modules directory's contents, and build a hash from each directory's names and\nmtimes. This works reasonably well in practice, but does depend on NPM not making any\nchanges further up in the directory structure.\n\n> Mindful of both performance and accuracy requirements, we'll combine the package.json\nand shallow crawl approaches to produce a single hash which is then used to namespace\ncached data. This approach does add a bit of IO overhead, but it seems to work well\nenough for the purposes of rapidly detecting the state of an environment.","_attachments":{},"homepage":"https://github.com/markfinger/env-hash#readme","bugs":{"url":"https://github.com/markfinger/env-hash/issues"},"license":"MIT"}