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

28
node_modules/nyc/lib/commands/check-coverage.js generated vendored Normal file
View File

@@ -0,0 +1,28 @@
'use strict'
const NYC = require('../../index.js')
const { cliWrapper, suppressEPIPE, setupOptions } = require('./helpers.js')
exports.command = 'check-coverage'
exports.describe = 'check whether coverage is within thresholds provided'
exports.builder = function (yargs) {
yargs
.demandCommand(0, 0)
.example('$0 check-coverage --lines 95', "check whether the JSON in nyc's output folder meets the thresholds provided")
setupOptions(yargs, 'check-coverage')
}
exports.handler = cliWrapper(async argv => {
process.env.NYC_CWD = process.cwd()
const nyc = new NYC(argv)
await nyc.checkCoverage({
lines: argv.lines,
functions: argv.functions,
branches: argv.branches,
statements: argv.statements
}, argv['per-file']).catch(suppressEPIPE)
})

74
node_modules/nyc/lib/commands/helpers.js generated vendored Normal file
View File

@@ -0,0 +1,74 @@
'use strict'
const decamelize = require('decamelize')
const schema = require('@istanbuljs/schema')
/* These options still need to be connected to the instrumenter
* Disabling them for now also avoids the issue with OSX cutting
* off the error help screen at 8192 characters.
*/
const blockOptions = [
'coverageVariable',
'coverageGlobalScope',
'coverageGlobalScopeFunc'
]
module.exports = {
setupOptions (yargs, command, cwd) {
Object.entries(schema.nyc.properties).forEach(([name, setup]) => {
if (blockOptions.includes(name)) {
return
}
const option = {
description: setup.description,
default: setup.default,
type: setup.type
}
if (name === 'cwd') {
if (command !== null) {
return
}
option.default = cwd
option.global = true
}
if (option.type === 'array') {
option.type = 'string'
}
if ('nycAlias' in setup) {
option.alias = setup.nycAlias
}
const optionName = decamelize(name, '-')
yargs.option(optionName, option)
if (!setup.nycCommands.includes(command)) {
yargs.hide(optionName)
}
})
},
/* istanbul ignore next: unsure how to test this */
suppressEPIPE (error) {
/* Prevent dumping error when `nyc npm t|head` causes stdout to
* be closed when reporting runs. */
if (error.code !== 'EPIPE') {
throw error
}
},
cliWrapper (execute) {
return argv => {
execute(argv).catch(error => {
try {
console.error(error.message)
} catch (_) {
/* We need to run process.exit(1) even if stderr is destroyed */
}
process.exit(1)
})
}
}
}

63
node_modules/nyc/lib/commands/instrument.js generated vendored Normal file
View File

@@ -0,0 +1,63 @@
'use strict'
const NYC = require('../../index.js')
const path = require('path')
const { promisify } = require('util')
const resolveFrom = require('resolve-from')
const rimraf = promisify(require('rimraf'))
const { cliWrapper, setupOptions } = require('./helpers.js')
exports.command = 'instrument <input> [output]'
exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location'
exports.builder = function (yargs) {
yargs
.demandCommand(0, 0)
.example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
setupOptions(yargs, 'instrument')
}
exports.handler = cliWrapper(async argv => {
if (argv.output && !argv.inPlace && (path.resolve(argv.cwd, argv.input) === path.resolve(argv.cwd, argv.output))) {
throw new Error('cannot instrument files in place, <input> must differ from <output>. Set \'--in-place\' to force')
}
if (path.relative(argv.cwd, path.resolve(argv.cwd, argv.input)).startsWith('..')) {
throw new Error('cannot instrument files outside project root directory')
}
if (argv.delete && argv.inPlace) {
throw new Error('cannot use \'--delete\' when instrumenting files in place')
}
if (argv.delete && argv.output && argv.output.length !== 0) {
const relPath = path.relative(process.cwd(), path.resolve(argv.output))
if (relPath !== '' && !relPath.startsWith('..')) {
await rimraf(argv.output)
} else {
throw new Error(`attempt to delete '${process.cwd()}' or containing directory.`)
}
}
// If instrument is set to false enable a noop instrumenter.
argv.instrumenter = (argv.instrument)
? './lib/instrumenters/istanbul'
: './lib/instrumenters/noop'
if (argv.inPlace) {
argv.output = argv.input
argv.completeCopy = false
}
const nyc = new NYC(argv)
if (!argv.useSpawnWrap) {
nyc.require.forEach(requireModule => {
const mod = resolveFrom.silent(nyc.cwd, requireModule) || requireModule
require(mod)
})
}
await nyc.instrumentAllFiles(argv.input, argv.output)
})

46
node_modules/nyc/lib/commands/merge.js generated vendored Normal file
View File

@@ -0,0 +1,46 @@
'use strict'
const path = require('path')
const makeDir = require('make-dir')
const fs = require('../fs-promises')
const { cliWrapper, setupOptions } = require('./helpers.js')
const NYC = require('../../index.js')
exports.command = 'merge <input-directory> [output-file]'
exports.describe = 'merge istanbul format coverage output in a given folder'
exports.builder = function (yargs) {
yargs
.demandCommand(0, 0)
.example('$0 merge ./out coverage.json', 'merge together reports in ./out and output as coverage.json')
.positional('input-directory', {
describe: 'directory containing multiple istanbul coverage files',
type: 'text',
default: './.nyc_output'
})
.positional('output-file', {
describe: 'file to output combined istanbul format coverage to',
type: 'text',
default: 'coverage.json'
})
setupOptions(yargs, 'merge')
yargs.default('exclude-after-remap', false)
}
exports.handler = cliWrapper(async argv => {
process.env.NYC_CWD = process.cwd()
const nyc = new NYC(argv)
const inputStat = await fs.stat(argv.inputDirectory).catch(error => {
throw new Error(`failed access input directory ${argv.inputDirectory} with error:\n\n${error.message}`)
})
if (!inputStat.isDirectory()) {
throw new Error(`${argv.inputDirectory} was not a directory`)
}
await makeDir(path.dirname(argv.outputFile))
const map = await nyc.getCoverageMapFromAllCoverageFiles(argv.inputDirectory)
await fs.writeFile(argv.outputFile, JSON.stringify(map, null, 2), 'utf8')
console.info(`coverage files in ${argv.inputDirectory} merged into ${argv.outputFile}`)
})

30
node_modules/nyc/lib/commands/report.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
'use strict'
const NYC = require('../../index.js')
const { cliWrapper, suppressEPIPE, setupOptions } = require('./helpers.js')
exports.command = 'report'
exports.describe = 'run coverage report for .nyc_output'
exports.builder = function (yargs) {
yargs
.demandCommand(0, 0)
.example('$0 report --reporter=lcov', 'output an HTML lcov report to ./coverage')
setupOptions(yargs, 'report')
}
exports.handler = cliWrapper(async argv => {
process.env.NYC_CWD = process.cwd()
var nyc = new NYC(argv)
await nyc.report().catch(suppressEPIPE)
if (argv.checkCoverage) {
await nyc.checkCoverage({
lines: argv.lines,
functions: argv.functions,
branches: argv.branches,
statements: argv.statements
}, argv['per-file']).catch(suppressEPIPE)
}
})