This commit is contained in:
lalBi94
2023-03-05 13:23:23 +01:00
commit 7bc56c09b5
14034 changed files with 1834369 additions and 0 deletions

14
node_modules/package-hash/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,14 @@
ISC License (ISC)
Copyright (c) 2016-2017, Mark Wubben <mark@novemberborn.net> (novemberborn.net)
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

79
node_modules/package-hash/README.md generated vendored Normal file
View File

@@ -0,0 +1,79 @@
# package-hash
Generates a hash for an installed npm package, useful for salting caches.
[AVA](https://github.com/sindresorhus/ava) for example caches precompiled test
files. It generates a salt for its cache based on the various packages that are
used when compiling the test files.
`package-hash` can generate an appropriate hash based on the package location
(on disk) and the `package.json` file. This hash is salted with a hash
for the `package-hash` itself.
`package-hash` can detect when the package-to-be-hashed is a Git repository. In
the AVA example this is useful when you're debugging one of the packages used to
compile the test files. You can clone it locally and use `npm link` so AVA can
find the clone. The hash will include the HEAD (`.git/HEAD`) and its
corresponding ref (e.g. `.git/refs/heads/master`), any packed refs
(`.git/packed-refs`), as well as the diff (`git diff`) for any non-committed
changes. This makes it really easy to test your changes without having to
explicitly clear the cache in the parent project.
## Installation
```console
$ npm install --save package-hash
```
## Usage
```js
const packageHash = require('package-hash')
// Asynchronously:
const hash = await packageHash(require.resolve('babel-core/package.json'))
// Synchronously:
const hash = packageHash.sync(require.resolve('babel-core/package.json'))
```
`packageHash()` / `packageHash.sync()` must be called with a file path for an
existing `package.json` file. To get the path to an npm package it's easiest to
use `require.resolve('the-name/package.json')`.
You can provide multiple paths:
```js
const hash = await packageHash([
require.resolve('babel-core/package.json'),
require.resolve('babel-preset-es2015/package.json')
])
```
An optional salt value can also be provided:
```js
const hash = await packageHash(require.resolve('babel-core/package.json'), 'salt value')
```
## API
### `packageHash(paths, salt?)`
`paths: string | string[]` ➜ can be a single file path, or an array of paths.
`salt: Array | Buffer | Object | string` ➜ optional. If an `Array` or `Object` (not `null`) it is first converted to a JSON string.
Returns a promise for the hex-encoded hash string.
### `packageHash.sync(paths, salt?)`
`paths: string | string[]` ➜ can be a single file path, or an array of paths.
`salt: Array | Buffer | Object | string` ➜ optional. If an `Array` or `Object` (not `null`) it is first converted to a JSON string.
Returns a hex-encoded hash string.
## Compatibility
`package-hash` has been tested with Node.js 8 and above, including Windows
support.

162
node_modules/package-hash/index.js generated vendored Normal file
View File

@@ -0,0 +1,162 @@
'use strict'
const cp = require('child_process') // eslint-disable-line security/detect-child-process
const path = require('path')
const {promisify} = require('util')
const fs = require('graceful-fs')
const flattenDeep = require('lodash.flattendeep')
const hasha = require('hasha')
const releaseZalgo = require('release-zalgo')
const PACKAGE_FILE = require.resolve('./package.json')
const TEN_MEBIBYTE = 1024 * 1024 * 10
const execFile = promisify(cp.execFile)
const readFile = {
async: promisify(fs.readFile),
sync: fs.readFileSync
}
const tryReadFile = {
async (file) {
return readFile.async(file).catch(() => null)
},
sync (file) {
try {
return fs.readFileSync(file)
} catch (err) {
return null
}
}
}
const tryExecFile = {
async (file, args, options) {
return execFile(file, args, options)
.then(({stdout}) => stdout)
.catch(() => null)
},
sync (file, args, options) {
try {
return cp.execFileSync(file, args, options)
} catch (err) {
return null
}
}
}
const git = {
tryGetRef (zalgo, dir, head) {
const m = /^ref: (.+)$/.exec(head.toString('utf8').trim())
if (!m) return null
return zalgo.run(tryReadFile, path.join(dir, '.git', m[1]))
},
tryGetDiff (zalgo, dir) {
return zalgo.run(tryExecFile,
'git',
// Attempt to get consistent output no matter the platform. Diff both
// staged and unstaged changes.
['--no-pager', 'diff', 'HEAD', '--no-color', '--no-ext-diff'],
{
cwd: dir,
maxBuffer: TEN_MEBIBYTE,
env: Object.assign({}, process.env, {
// Force the GIT_DIR to prevent git from diffing a parent repository
// in case the directory isn't actually a repository.
GIT_DIR: path.join(dir, '.git')
}),
// Ignore stderr.
stdio: ['ignore', 'pipe', 'ignore']
})
}
}
function addPackageData (zalgo, pkgPath) {
const dir = path.dirname(pkgPath)
return zalgo.all([
dir,
zalgo.run(readFile, pkgPath),
zalgo.run(tryReadFile, path.join(dir, '.git', 'HEAD'))
.then(head => {
if (!head) return []
return zalgo.all([
zalgo.run(tryReadFile, path.join(dir, '.git', 'packed-refs')),
git.tryGetRef(zalgo, dir, head),
git.tryGetDiff(zalgo, dir)
])
.then(results => {
return [head].concat(results.filter(Boolean))
})
})
])
}
function computeHash (zalgo, paths, pepper, salt) {
const inputs = []
if (pepper) inputs.push(pepper)
if (typeof salt !== 'undefined') {
if (Buffer.isBuffer(salt) || typeof salt === 'string') {
inputs.push(salt)
} else if (typeof salt === 'object' && salt !== null) {
inputs.push(JSON.stringify(salt))
} else {
throw new TypeError('Salt must be an Array, Buffer, Object or string')
}
}
// TODO: Replace flattenDeep with Array#flat(Infinity) after node.js 10 is dropped
return zalgo.all(paths.map(pkgPath => addPackageData(zalgo, pkgPath)))
.then(furtherInputs => hasha(flattenDeep([inputs, furtherInputs]), {algorithm: 'sha256'}))
}
let ownHash = null
let ownHashPromise = null
function run (zalgo, paths, salt) {
if (!ownHash) {
return zalgo.run({
async () {
if (!ownHashPromise) {
ownHashPromise = computeHash(zalgo, [PACKAGE_FILE])
}
return ownHashPromise
},
sync () {
return computeHash(zalgo, [PACKAGE_FILE])
}
})
.then(hash => {
ownHash = Buffer.from(hash, 'hex')
ownHashPromise = null
return run(zalgo, paths, salt)
})
}
if (paths === PACKAGE_FILE && typeof salt === 'undefined') {
// Special case that allow the pepper value to be obtained. Mainly here for
// testing purposes.
return zalgo.returns(ownHash.toString('hex'))
}
paths = Array.isArray(paths) ? paths : [paths]
return computeHash(zalgo, paths, ownHash, salt)
}
module.exports = (paths, salt) => {
try {
return run(releaseZalgo.async(), paths, salt)
} catch (err) {
return Promise.reject(err)
}
}
module.exports.sync = (paths, salt) => {
const result = run(releaseZalgo.sync(), paths, salt)
return releaseZalgo.unwrapSync(result)
}

60
node_modules/package-hash/package.json generated vendored Normal file
View File

@@ -0,0 +1,60 @@
{
"name": "package-hash",
"version": "4.0.0",
"description": "Generates a hash for an installed npm package, useful for salting caches",
"main": "index.js",
"files": [
"index.js"
],
"engines": {
"node": ">=8"
},
"scripts": {
"lint": "as-i-preach",
"unpack-fixtures": "node scripts/unpack-fixtures.js",
"pregenerate-fixture-index": "npm run unpack-fixtures",
"generate-fixture-index": "node scripts/generate-fixture-index.js",
"pretest": "npm run unpack-fixtures",
"test": "ava",
"posttest": "npm run lint",
"coverage": "nyc npm test",
"watch:test": "npm run test -- --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/novemberborn/package-hash.git"
},
"author": "Mark Wubben (https://novemberborn.net/)",
"license": "ISC",
"bugs": {
"url": "https://github.com/novemberborn/package-hash/issues"
},
"homepage": "https://github.com/novemberborn/package-hash#readme",
"dependencies": {
"graceful-fs": "^4.1.15",
"hasha": "^5.0.0",
"lodash.flattendeep": "^4.4.0",
"release-zalgo": "^1.0.0"
},
"devDependencies": {
"@novemberborn/as-i-preach": "^11.0.0",
"ava": "^1.4.1",
"codecov": "^3.3.0",
"nyc": "^13.3.0",
"rimraf": "^2.6.3",
"tar": "^4.4.8"
},
"nyc": {
"cache": true,
"exclude": [
"scripts",
"test"
],
"reporter": [
"html",
"lcov",
"text"
]
},
"standard-engine": "@novemberborn/as-i-preach"
}