Files

Return to Package Diff Home.
Brought to you by Intrinsic.

Package Diff: nyc @ 14.0.0 .. 14.1.0

bin/nyc.js

@@ -67,6 +67,7 @@
nyc.writeProcessIndex()
+ nyc.maybePurgeSourceMapCache()
if (argv.checkCoverage) {
nyc.checkCoverage({
lines: argv.lines,
@@ -85,5 +86,6 @@
})
} else {
// I don't have a clue what you're doing.
+ process.exitCode = 1
yargs.showHelp()
}

bin/wrap.js

@@ -16,6 +16,12 @@
delete process.env.NYC_PROCESSINFO_EXTERNAL_ID
}
+if (process.env.NYC_CONFIG_OVERRIDE) {
+ var override = JSON.parse(process.env.NYC_CONFIG_OVERRIDE)
+ config = Object.assign(config, override)
+ process.env.NYC_CONFIG = JSON.stringify(config)
+}
+
;(new NYC(config)).wrap()
sw.runMain()

CHANGELOG.md

@@ -2,6 +2,23 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
+# [14.1.0](https://github.com/istanbuljs/nyc/compare/v14.0.0...v14.1.0) (2019-04-24)
+
+
+### Bug Fixes
+
+* Do not crash when nyc is run inside itself. ([#1068](https://github.com/istanbuljs/nyc/issues/1068)) ([c4fcf5e](https://github.com/istanbuljs/nyc/commit/c4fcf5e)), closes [#1067](https://github.com/istanbuljs/nyc/issues/1067)
+* Exit with code 1 when nyc doesn't know what to do. ([#1070](https://github.com/istanbuljs/nyc/issues/1070)) ([21fb2c8](https://github.com/istanbuljs/nyc/commit/21fb2c8))
+* Purge source-map cache before reporting if cache is disabled. ([#1080](https://github.com/istanbuljs/nyc/issues/1080)) ([3d9eaa4](https://github.com/istanbuljs/nyc/commit/3d9eaa4))
+* Use correct config property for parser plugins ([#1082](https://github.com/istanbuljs/nyc/issues/1082)) ([a7bc7ae](https://github.com/istanbuljs/nyc/commit/a7bc7ae))
+
+
+### Features
+
+* add support for yaml configuration file ([#1054](https://github.com/istanbuljs/nyc/issues/1054)) ([ca37ffa](https://github.com/istanbuljs/nyc/commit/ca37ffa))
+
+
+
# [14.0.0](https://github.com/istanbuljs/nyc/compare/v13.3.0...v14.0.0) (2019-04-15)

index.js

@@ -32,7 +32,15 @@
require('../self-coverage-helper')
}
-function NYC (config) {
+function coverageFinder () {
+ var coverage = global.__coverage__
+ if (typeof __coverage__ === 'object') coverage = __coverage__
+ if (!coverage) coverage = global['__coverage__'] = {}
+ return coverage
+}
+
+class NYC {
+ constructor (config) {
config = config || {}
this.config = config
@@ -81,12 +89,12 @@
this.fakeRequire = null
this.processInfo = new ProcessInfo(config && config._processInfo)
- this.rootId = this.processInfo.root || this.generateUniqueID()
+ this.rootId = this.processInfo.root || uuid()
this.hashCache = {}
-}
+ }
-NYC.prototype._createTransform = function (ext) {
+ _createTransform (ext) {
var opts = {
salt: Hash.salt(this.config),
hashData: (input, metadata) => [metadata.filename],
@@ -105,25 +113,25 @@
opts.factory = this._transformFactory.bind(this)
}
return cachingTransform(opts)
-}
+ }
-NYC.prototype._disableCachingTransform = function () {
+ _disableCachingTransform () {
return !(this.cache && this.config.isChildProcess)
-}
+ }
-NYC.prototype._loadAdditionalModules = function () {
+ _loadAdditionalModules () {
this.require.forEach(requireModule => {
// Attempt to require the module relative to the directory being instrumented.
// Then try other locations, e.g. the nyc node_modules folder.
require(resolveFrom.silent(this.cwd, requireModule) || requireModule)
})
-}
+ }
-NYC.prototype.instrumenter = function () {
+ instrumenter () {
return this._instrumenter || (this._instrumenter = this._createInstrumenter())
-}
+ }
-NYC.prototype._createInstrumenter = function () {
+ _createInstrumenter () {
return this._instrumenterLib({
ignoreClassMethods: [].concat(this.config.ignoreClassMethod).filter(a => a),
produceSourceMap: this.config.produceSourceMap,
@@ -132,14 +140,14 @@
esModules: this.config.esModules,
plugins: this.config.parserPlugins
})
-}
+ }
-NYC.prototype.addFile = function (filename) {
+ addFile (filename) {
const source = this._readTranspiledSource(filename)
this._maybeInstrumentSource(source, filename)
-}
+ }
-NYC.prototype._readTranspiledSource = function (filePath) {
+ _readTranspiledSource (filePath) {
var source = null
var ext = path.extname(filePath)
if (typeof Module._extensions[ext] === 'undefined') {
@@ -151,9 +159,9 @@
}
}, filePath)
return source
-}
+ }
-NYC.prototype.addAllFiles = function () {
+ addAllFiles () {
this._loadAdditionalModules()
this.fakeRequire = true
@@ -169,9 +177,9 @@
this.fakeRequire = false
this.writeCoverageFile()
-}
+ }
-NYC.prototype.instrumentAllFiles = function (input, output, cb) {
+ instrumentAllFiles (input, output, cb) {
let inputDir = '.' + path.sep
const visitor = relFile => {
const inFile = path.resolve(inputDir, relFile)
@@ -211,24 +219,30 @@
return cb(err)
}
cb()
-}
+ }
-NYC.prototype._transform = function (code, filename) {
+ _transform (code, filename) {
const extname = path.extname(filename).toLowerCase()
const transform = this.transforms[extname] || (() => null)
return transform(code, { filename })
-}
+ }
-NYC.prototype._maybeInstrumentSource = function (code, filename) {
+ _maybeInstrumentSource (code, filename) {
if (!this.exclude.shouldInstrument(filename)) {
return null
}
return this._transform(code, filename)
-}
+ }
+
+ maybePurgeSourceMapCache () {
+ if (!this.cache) {
+ this.sourceMaps.purgeCache()
+ }
+ }
-NYC.prototype._transformFactory = function (cacheDir) {
+ _transformFactory (cacheDir) {
const instrumenter = this.instrumenter()
let instrumented
@@ -256,21 +270,21 @@
return instrumented
}
}
-}
+ }
-NYC.prototype._handleJs = function (code, options) {
+ _handleJs (code, options) {
// ensure the path has correct casing (see istanbuljs/nyc#269 and nodejs/node#6624)
const filename = path.resolve(this.cwd, options.filename)
return this._maybeInstrumentSource(code, filename) || code
-}
+ }
-NYC.prototype._addHook = function (type) {
+ _addHook (type) {
const handleJs = this._handleJs.bind(this)
const dummyMatcher = () => true // we do all processing in transformer
libHook['hook' + type](dummyMatcher, handleJs, { extensions: this.extensions })
-}
+ }
-NYC.prototype._addRequireHooks = function () {
+ _addRequireHooks () {
if (this.hookRequire) {
this._addHook('Require')
}
@@ -280,49 +294,47 @@
if (this.hookRunInThisContext) {
this._addHook('RunInThisContext')
}
-}
+ }
-NYC.prototype.cleanup = function () {
+ cleanup () {
if (!process.env.NYC_CWD) rimraf.sync(this.tempDirectory())
-}
+ }
-NYC.prototype.clearCache = function () {
+ clearCache () {
if (this.cache) {
rimraf.sync(this.cacheDirectory)
}
-}
+ }
-NYC.prototype.createTempDirectory = function () {
+ createTempDirectory () {
mkdirp.sync(this.tempDirectory())
if (this.cache) mkdirp.sync(this.cacheDirectory)
mkdirp.sync(this.processInfoDirectory())
-}
+ }
-NYC.prototype.reset = function () {
+ reset () {
this.cleanup()
this.createTempDirectory()
-}
+ }
-NYC.prototype._wrapExit = function () {
+ _wrapExit () {
// we always want to write coverage
// regardless of how the process exits.
onExit(() => {
this.writeCoverageFile()
}, { alwaysLast: true })
-}
+ }
-NYC.prototype.wrap = function (bin) {
+ wrap (bin) {
process.env.NYC_PROCESS_ID = this.processInfo.uuid
this._addRequireHooks()
this._wrapExit()
this._loadAdditionalModules()
return this
-}
-
-NYC.prototype.generateUniqueID = uuid
+ }
-NYC.prototype.writeCoverageFile = function () {
+ writeCoverageFile () {
var coverage = coverageFinder()
if (!coverage) return
@@ -360,16 +372,9 @@
JSON.stringify(this.processInfo),
'utf-8'
)
-}
-
-function coverageFinder () {
- var coverage = global.__coverage__
- if (typeof __coverage__ === 'object') coverage = __coverage__
- if (!coverage) coverage = global['__coverage__'] = {}
- return coverage
-}
+ }
-NYC.prototype.getCoverageMapFromAllCoverageFiles = function (baseDirectory) {
+ getCoverageMapFromAllCoverageFiles (baseDirectory) {
const map = libCoverage.createCoverageMap({})
this.eachReport(undefined, (report) => {
@@ -387,9 +392,9 @@
}
return map
-}
+ }
-NYC.prototype.report = function () {
+ report () {
var tree
var map = this.getCoverageMapFromAllCoverageFiles()
var context = libReport.createContext({
@@ -409,10 +414,10 @@
if (this._showProcessTree) {
this.showProcessTree()
}
-}
+ }
-// XXX(@isaacs) Index generation should move to istanbul-lib-processinfo
-NYC.prototype.writeProcessIndex = function () {
+ // XXX(@isaacs) Index generation should move to istanbul-lib-processinfo
+ writeProcessIndex () {
const dir = this.processInfoDirectory()
const pidToUid = new Map()
const infoByUid = new Map()
@@ -437,7 +442,7 @@
infos.forEach(info => {
if (info.parent) {
const parentInfo = infoByUid.get(info.parent)
- if (parentInfo.children.indexOf(info.uuid) === -1) {
+ if (parentInfo && !parentInfo.children.includes(info.uuid)) {
parentInfo.children.push(info.uuid)
}
}
@@ -483,15 +488,15 @@
})
fs.writeFileSync(path.resolve(dir, 'index.json'), JSON.stringify(index))
-}
+ }
-NYC.prototype.showProcessTree = function () {
+ showProcessTree () {
var processTree = ProcessInfo.buildProcessTree(this._loadProcessInfos())
console.log(processTree.render(this))
-}
+ }
-NYC.prototype.checkCoverage = function (thresholds, perFile) {
+ checkCoverage (thresholds, perFile) {
var map = this.getCoverageMapFromAllCoverageFiles()
var nyc = this
@@ -504,9 +509,9 @@
// ERROR: Coverage for lines (90.12%) does not meet global threshold (120%)
nyc._checkCoverage(map.getCoverageSummary(), thresholds)
}
-}
+ }
-NYC.prototype._checkCoverage = function (summary, thresholds, file) {
+ _checkCoverage (summary, thresholds, file) {
Object.keys(thresholds).forEach(function (key) {
var coverage = summary[key].pct
if (coverage < thresholds[key]) {
@@ -518,9 +523,9 @@
}
}
})
-}
+ }
-NYC.prototype._loadProcessInfos = function () {
+ _loadProcessInfos () {
return fs.readdirSync(this.processInfoDirectory()).map(f => {
let data
try {
@@ -540,9 +545,9 @@
infos[info.file] = info.data
return infos
}, {})
-}
+ }
-NYC.prototype.eachReport = function (filenames, iterator, baseDirectory) {
+ eachReport (filenames, iterator, baseDirectory) {
baseDirectory = baseDirectory || this.tempDirectory()
if (typeof filenames === 'function') {
@@ -568,9 +573,9 @@
iterator(report)
})
-}
+ }
-NYC.prototype.loadReports = function (filenames) {
+ loadReports (filenames) {
var reports = []
this.eachReport(filenames, (report) => {
@@ -578,18 +583,19 @@
})
return reports
-}
+ }
-NYC.prototype.tempDirectory = function () {
+ tempDirectory () {
return path.resolve(this.cwd, this._tempDirectory)
-}
+ }
-NYC.prototype.reportDirectory = function () {
+ reportDirectory () {
return path.resolve(this.cwd, this._reportDir)
-}
+ }
-NYC.prototype.processInfoDirectory = function () {
+ processInfoDirectory () {
return path.resolve(this.tempDirectory(), 'processinfo')
+ }
}
module.exports = NYC

lib/config-util.js

@@ -21,14 +21,21 @@
const rcOptions = [
argv.nycrcPath || '.nycrc',
'.nycrc.json',
+ '.nycrc.yml',
+ '.nycrc.yaml',
'nyc.config.js'
]
const rcPath = findUp.sync(rcOptions, { cwd: guessCWD(cwd) })
let config = {}
if (rcPath) {
- if (rcPath.toLowerCase().endsWith('.js')) {
+ const rcExt = path.extname(rcPath.toLowerCase())
+ if (rcExt === '.js') {
config = require(rcPath)
+ } else if (rcExt === '.yml' || rcExt === '.yaml') {
+ config = require('js-yaml').load(
+ fs.readFileSync(rcPath, 'utf8')
+ )
} else {
config = JSON.parse(
fs.readFileSync(rcPath, 'utf-8')

lib/instrumenters/istanbul.js

@@ -5,7 +5,7 @@
const mergeSourceMap = require('merge-source-map')
function InstrumenterIstanbul (options) {
- const plugins = options.parserPlugins
+ const { plugins } = options
const configPlugins = plugins ? { plugins } : {}
const instrumenter = createInstrumenter(Object.assign({

lib/source-maps.js

@@ -4,12 +4,16 @@
const fs = require('fs')
const path = require('path')
-const sourceMapCache = libSourceMaps.createSourceMapStore()
function SourceMaps (opts) {
this.cache = opts.cache
this.cacheDirectory = opts.cacheDirectory
this.loadedMaps = {}
- this._sourceMapCache = sourceMapCache
+ this._sourceMapCache = libSourceMaps.createSourceMapStore()
+}
+
+SourceMaps.prototype.purgeCache = function () {
+ this._sourceMapCache = libSourceMaps.createSourceMapStore()
+ this.loadedMaps = {}
}
SourceMaps.prototype.extractAndRegister = function (code, filename, hash) {

package.json

@@ -1,15 +1,17 @@
{
"name": "nyc",
- "version": "14.0.0",
+ "version": "14.1.0",
"description": "the Istanbul command line interface",
"main": "index.js",
"scripts": {
- "pretest": "npm run clean && npm run instrument",
- "test": "tap -t360 --no-cov -b ./test/*.js && npm run report",
- "posttest": "standard",
+ "lint": "standard",
+ "pretest": "npm run lint && npm run clean && npm run instrument",
+ "test": "tap -t360 --no-cov -b test/*.js",
+ "snap": "cross-env TAP_SNAPSHOT=1 npm test",
+ "posttest": "npm run report",
"clean": "rimraf ./.nyc_output ./node_modules/.cache ./.self_coverage ./test/fixtures/.nyc_output ./test/fixtures/node_modules/.cache ./self-coverage",
"instrument": "node ./build-self-coverage.js",
- "report": "node ./self-coverage/bin/nyc report --temp-dir ./.self_coverage/ -r text -r lcov",
+ "report": "node ./bin/nyc report --temp-dir ./.self_coverage/ -r text -r lcov",
"release": "standard-version"
},
"bin": {
@@ -74,19 +76,20 @@
"find-up": "^3.0.0",
"foreground-child": "^1.5.6",
"glob": "^7.1.3",
- "istanbul-lib-coverage": "^2.0.4",
- "istanbul-lib-hook": "^2.0.6",
- "istanbul-lib-instrument": "^3.2.0",
- "istanbul-lib-report": "^2.0.7",
- "istanbul-lib-source-maps": "^3.0.5",
- "istanbul-reports": "^2.2.2",
+ "istanbul-lib-coverage": "^2.0.5",
+ "istanbul-lib-hook": "^2.0.7",
+ "istanbul-lib-instrument": "^3.3.0",
+ "istanbul-lib-report": "^2.0.8",
+ "istanbul-lib-source-maps": "^3.0.6",
+ "istanbul-reports": "^2.2.4",
+ "js-yaml": "^3.13.1",
"make-dir": "^2.1.0",
"merge-source-map": "^1.1.0",
"resolve-from": "^4.0.0",
"rimraf": "^2.6.3",
"signal-exit": "^3.0.2",
"spawn-wrap": "^1.4.2",
- "test-exclude": "^5.2.2",
+ "test-exclude": "^5.2.3",
"uuid": "^3.3.2",
"yargs": "^13.2.2",
"yargs-parser": "^13.0.0"
@@ -95,16 +98,18 @@
"any-path": "^1.3.0",
"chai": "^4.2.0",
"coveralls": "^3.0.3",
+ "cross-env": "^5.2.0",
"is-windows": "^1.0.2",
"lodash": "^4.17.11",
"newline-regex": "^0.2.1",
+ "pify": "^4.0.1",
"requirejs": "^2.3.6",
"sanitize-filename": "^1.6.1",
"source-map-support": "^0.5.12",
"standard": "^12.0.1",
"standard-version": "^5.0.2",
"strip-indent": "^2.0.0",
- "tap": "^12.6.1",
+ "tap": "^12.6.5",
"which": "^1.3.1",
"zero-fill": "^2.2.3"
},

README.md

@@ -195,24 +195,7 @@
nyc report --reporter=<custom-reporter-name>
```
-## Producing instrumented source
-
-The `nyc instrument` command can produce a set of instrumented source files.
-These files are suitable for client side deployment in end to end testing.
-You can create an instrumented version of your source code by running:
-
-```bash
-nyc instrument <input> [output]
-```
-
-`<input>` can be any file or directory within the project root directory.
-The `[output]` directory is optional and can be located anywhere, if it is not set the instrumented code will be sent to `stdout`.
-For example, `nyc instrument . ./output` will produce instrumented versions of any source files it finds in `.` and store them in `./output`.
-
-Any existing output can be removed by specifying the `--delete` option.
-Run `nyc instrument --help` to display a full list of available command options.
-
-**Note:** `nyc instrument` will not copy the contents of a `.git` folder to the output directory.
+## [Producing instrumented source](./docs/instrument.md)
## Setting the project root directory
@@ -341,7 +324,15 @@
## Configuring `nyc`
-Any configuration options that can be set via the command line can also be specified in the `nyc` stanza of your package.json, or within a `.nycrc`, `.nycrc.json`, or `nyc.config.js` file:
+Any configuration options that can be set via the command line can also be specified in the `nyc` stanza of your package.json, or within a seperate configuration file - a variety of flavors are available:
+
+| File name | File Association |
+|-----------------|------------------|
+| `.nycrc` | JSON |
+| `.nycrc.json` | JSON |
+| `.nycrc.yaml` | YAML |
+| `.nycrc.yml` | YAML |
+| `nyc.config.js` | CommonJS export |
**package.json:**