Socket
Socket
Sign inDemoInstall

babel-plugin-istanbul

Package Overview
Dependencies
Maintainers
3
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-istanbul - npm Package Compare versions

Comparing version 5.2.0 to 6.0.0-beta.0

lib/load-nyc-config-sync.js

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [6.0.0-beta.0](https://github.com/istanbuljs/babel-plugin-istanbul/compare/v5.2.0...v6.0.0-beta.0) (2019-10-09)
### ⚠ BREAKING CHANGES
* Drop node.js 6 (#226)
### Features
* Add support for instrumenter options ([#227](https://github.com/istanbuljs/babel-plugin-istanbul/issues/227)) ([fe08f5b](https://github.com/istanbuljs/babel-plugin-istanbul/commit/fe08f5b)), closes [#208](https://github.com/istanbuljs/babel-plugin-istanbul/issues/208) [#212](https://github.com/istanbuljs/babel-plugin-istanbul/issues/212)
* Drop node.js 6 ([#226](https://github.com/istanbuljs/babel-plugin-istanbul/issues/226)) ([93db21a](https://github.com/istanbuljs/babel-plugin-istanbul/commit/93db21a)), closes [#209](https://github.com/istanbuljs/babel-plugin-istanbul/issues/209)
## [5.2.0](https://github.com/istanbuljs/babel-plugin-istanbul/compare/v5.1.4...v5.2.0) (2019-07-18)

@@ -7,0 +19,0 @@

131

lib/index.js

@@ -8,5 +8,7 @@ "use strict";

var _path = _interopRequireDefault(require("path"));
var _fs = require("fs");
var _path = require("path");
var _child_process = require("child_process");

@@ -17,10 +19,15 @@ var _helperPluginUtils = require("@babel/helper-plugin-utils");

const testExclude = require('test-exclude');
var _testExclude = _interopRequireDefault(require("test-exclude"));
const findUp = require('find-up');
var _schema = _interopRequireDefault(require("@istanbuljs/schema"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function getRealpath(n) {
try {
return (0, _fs.realpathSync)(n) || n;
return (0, _fs.realpathSync)(n) ||
/* istanbul ignore next */
n;
} catch (e) {
/* istanbul ignore next */
return n;

@@ -30,35 +37,73 @@ }

const memoize = new Map();
/* istanbul ignore next */
const memosep = _path.default.sep === '/' ? ':' : ';';
function loadNycConfig(cwd, opts) {
let memokey = cwd;
const args = [_path.default.resolve(__dirname, 'load-nyc-config-sync.js'), cwd];
if ('nycrcPath' in opts) {
args.push(opts.nycrcPath);
memokey += memosep + opts.nycrcPath;
}
/* execFileSync is expensive, avoid it if possible! */
if (memoize.has(memokey)) {
return memoize.get(memokey);
}
const result = JSON.parse((0, _child_process.execFileSync)(process.execPath, args));
const error = result['load-nyc-config-sync-error'];
if (error) {
throw new Error(error);
}
const config = { ..._schema.default.defaults.babelPluginIstanbul,
cwd,
...result
};
memoize.set(memokey, config);
return config;
}
function findConfig(opts) {
const cwd = getRealpath(opts.cwd || process.env.NYC_CWD ||
/* istanbul ignore next */
process.cwd());
const keys = Object.keys(opts);
const ignored = Object.keys(opts).filter(s => s === 'nycrcPath' || s === 'cwd');
if (keys.length > ignored.length) {
// explicitly configuring options in babel
// takes precedence.
return { ..._schema.default.defaults.babelPluginIstanbul,
cwd,
...opts
};
}
if (ignored.length === 0 && process.env.NYC_CONFIG) {
// defaults were already applied by nyc
return JSON.parse(process.env.NYC_CONFIG);
}
return loadNycConfig(cwd, opts);
}
function makeShouldSkip() {
let exclude;
return function shouldSkip(file, opts) {
if (!exclude || exclude.cwd !== opts.cwd) {
const cwd = getRealpath(process.env.NYC_CWD || process.cwd());
const nycConfig = process.env.NYC_CONFIG ? JSON.parse(process.env.NYC_CONFIG) : {};
let config = {};
if (Object.keys(opts).length > 0) {
// explicitly configuring options in babel
// takes precedence.
config = opts;
} else if (nycConfig.include || nycConfig.exclude) {
// nyc was configured in a parent process (keep these settings).
config = {
include: nycConfig.include,
exclude: nycConfig.exclude,
// Make sure this is true unless explicitly set to `false`. `undefined` is still `true`.
excludeNodeModules: nycConfig.excludeNodeModules !== false
};
} else {
// fallback to loading config from key in package.json.
config = {
configKey: 'nyc',
configPath: (0, _path.dirname)(findUp.sync('package.json', {
cwd
}))
};
}
exclude = testExclude(Object.assign({
cwd
}, config));
return function shouldSkip(file, nycConfig) {
if (!exclude || exclude.cwd !== nycConfig.cwd) {
exclude = (0, _testExclude.default)({
cwd: nycConfig.cwd,
include: nycConfig.include,
exclude: nycConfig.exclude,
extension: nycConfig.extension,
// Make sure this is true unless explicitly set to `false`. `undefined` is still `true`.
excludeNodeModules: nycConfig.excludeNodeModules !== false
});
}

@@ -72,4 +117,4 @@

api.assertVersion(7);
const shouldSkip = makeShouldSkip();
const t = api.types;
const shouldSkip = makeShouldSkip();
return {

@@ -80,5 +125,6 @@ visitor: {

this.__dv__ = null;
this.nycConfig = findConfig(this.opts);
const realPath = getRealpath(this.file.opts.filename);
if (shouldSkip(realPath, this.opts)) {
if (shouldSkip(realPath, this.nycConfig)) {
return;

@@ -97,4 +143,11 @@ }

this.__dv__ = (0, _istanbulLibInstrument.programVisitor)(t, realPath, {
coverageVariable: '__coverage__',
const visitorOptions = {};
Object.entries(_schema.default.defaults.instrumentVisitor).forEach(([name, defaultValue]) => {
if (name in this.nycConfig) {
visitorOptions[name] = this.nycConfig[name];
} else {
visitorOptions[name] = _schema.default.defaults.instrumentVisitor[name];
}
});
this.__dv__ = (0, _istanbulLibInstrument.programVisitor)(t, realPath, { ...visitorOptions,
inputSourceMap

@@ -101,0 +154,0 @@ });

{
"name": "babel-plugin-istanbul",
"version": "5.2.0",
"version": "6.0.0-beta.0",
"author": "Thai Pangsakulyanont @dtinth",

@@ -13,19 +13,20 @@ "license": "BSD-3-Clause",

"@babel/helper-plugin-utils": "^7.0.0",
"find-up": "^3.0.0",
"istanbul-lib-instrument": "^3.3.0",
"test-exclude": "^5.2.3"
"@istanbuljs/load-nyc-config": "^1.0.0-alpha.1",
"@istanbuljs/schema": "^0.1.1",
"istanbul-lib-instrument": "^4.0.0-alpha.1",
"test-exclude": "^6.0.0-alpha.1"
},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-transform-modules-commonjs": "^7.4.3",
"@babel/register": "^7.4.0",
"@babel/cli": "^7.6.2",
"@babel/core": "^7.6.2",
"@babel/plugin-transform-modules-commonjs": "^7.6.0",
"@babel/register": "^7.6.2",
"chai": "^4.2.0",
"coveralls": "^3.0.3",
"cross-env": "^5.2.0",
"mocha": "^6.1.4",
"nyc": "^14.1.0",
"coveralls": "^3.0.6",
"cross-env": "^6.0.3",
"mocha": "^6.2.1",
"nyc": "^15.0.0-alpha.0",
"pmock": "^0.2.3",
"standard": "^12.0.1",
"standard-version": "^6.0.1"
"standard": "^14.3.1",
"standard-version": "^7.0.0"
},

@@ -36,3 +37,3 @@ "scripts": {

"pretest": "standard && npm run release",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha test/*.js",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text mocha --timeout 5000 test/*.js",
"prepublish": "npm test && npm run release",

@@ -43,3 +44,3 @@ "version": "standard-version"

"ignore": [
"fixtures/has-inline-source-map.js"
"fixtures/*.js"
]

@@ -73,4 +74,4 @@ },

"engines": {
"node": ">=6"
"node": ">=8"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc