Socket
Socket
Sign inDemoInstall

vite-plugin-istanbul

Package Overview
Dependencies
3
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.0 to 2.4.0

9

CHANGELOG.md

@@ -1,11 +0,6 @@

# [2.3.0](https://github.com/ifaxity/vite-plugin-istanbul/compare/v2.2.2...v2.3.0) (2021-11-26)
# [2.4.0](https://github.com/ifaxity/vite-plugin-istanbul/compare/v2.3.0...v2.4.0) (2022-01-17)
### Bug Fixes
* Missing comma ([af295ad](https://github.com/ifaxity/vite-plugin-istanbul/commit/af295ad9e2cf97cee4ac0cb6a2ebce7971b034e9))
### Features
* Option for cwd ([ab1c2f8](https://github.com/ifaxity/vite-plugin-istanbul/commit/ab1c2f8160fdcbe8658fa32e3f2ebf892ca9c24a))
* Support for env files from config ([4accd4a](https://github.com/ifaxity/vite-plugin-istanbul/commit/4accd4ac43bf9593b0d9be3472dd35c799817d67))

@@ -1,2 +0,5 @@

import type { Plugin } from 'vite';
import { Plugin } from 'vite';
declare global {
var __coverage__: any;
}
interface IstanbulPluginOptions {

@@ -11,7 +14,4 @@ include?: string | string[];

}
declare global {
var __coverage__: any;
}
declare function istanbulPlugin(opts?: IstanbulPluginOptions): Plugin;
export = istanbulPlugin;
declare const _default: (opts?: IstanbulPluginOptions) => Plugin;
export = _default;
//# sourceMappingURL=index.d.ts.map

@@ -5,4 +5,6 @@ "use strict";

};
const vite_1 = require("vite");
const istanbul_lib_instrument_1 = require("istanbul-lib-instrument");
const test_exclude_1 = __importDefault(require("test-exclude"));
const chalk_1 = require("chalk");
// Custom extensions to include .vue files

@@ -12,2 +14,4 @@ const DEFAULT_EXTENSION = ['.js', '.cjs', '.mjs', '.ts', '.tsx', '.jsx', '.vue'];

const PLUGIN_NAME = 'vite:istanbul';
const MODULE_PREFIX = '/@modules/';
const NULL_STRING = '\0';
function sanitizeSourceMap(sourceMap) {

@@ -17,34 +21,17 @@ // JSON parse/stringify trick required for istanbul to accept the SourceMap

}
function createConfigureServer() {
return ({ middlewares }) => {
// Returns the current code coverage in the global scope
middlewares.use((req, res, next) => {
var _a;
if (req.url !== COVERAGE_PUBLIC_PATH) {
return next();
}
const coverage = (_a = (global.__coverage__)) !== null && _a !== void 0 ? _a : null;
let data;
try {
data = JSON.stringify(coverage, null, 4);
}
catch (ex) {
return next(ex);
}
res.setHeader('Content-Type', 'application/json');
res.statusCode = 200;
res.end(data);
});
};
}
function createTransform(opts = {}) {
var _a;
module.exports = function istanbulPlugin(opts = {}) {
var _a, _b, _c, _d;
// Only instrument when we want to, as we only want instrumentation in test
// By default the plugin is always on
const requireEnv = (_a = opts === null || opts === void 0 ? void 0 : opts.requireEnv) !== null && _a !== void 0 ? _a : false;
const checkProd = (_b = opts === null || opts === void 0 ? void 0 : opts.checkProd) !== null && _b !== void 0 ? _b : true;
const logger = (0, vite_1.createLogger)('warn', { prefix: 'vite-plugin-istanbul' });
const exclude = new test_exclude_1.default({
cwd: opts.cwd || process.cwd(),
cwd: (_c = opts.cwd) !== null && _c !== void 0 ? _c : process.cwd(),
include: opts.include,
exclude: opts.exclude,
extension: (_a = opts.extension) !== null && _a !== void 0 ? _a : DEFAULT_EXTENSION,
extension: (_d = opts.extension) !== null && _d !== void 0 ? _d : DEFAULT_EXTENSION,
excludeNodeModules: true,
});
const instrumenter = istanbul_lib_instrument_1.createInstrumenter({
const instrumenter = (0, istanbul_lib_instrument_1.createInstrumenter)({
preserveComments: true,

@@ -55,37 +42,8 @@ produceSourceMap: true,

});
return function (srcCode, id) {
if (id.startsWith('/@modules/') || id.startsWith('\0')) {
// do not transform if this is a dep
return;
}
if (exclude.shouldInstrument(id)) {
const sourceMap = sanitizeSourceMap(this.getCombinedSourcemap());
const code = instrumenter.instrumentSync(srcCode, id, sourceMap);
const map = instrumenter.lastSourceMap();
// Required to cast to correct mapping value
return { code, map };
}
};
}
function istanbulPlugin(opts = {}) {
var _a, _b, _c;
// Only instrument when we want to, as we only want instrumentation in test
// By default the plugin is always on
const env = (opts.cypress ? process.env.CYPRESS_COVERAGE : process.env.VITE_COVERAGE);
const envValue = env === null || env === void 0 ? void 0 : env.toLowerCase();
const requireEnv = (_a = opts === null || opts === void 0 ? void 0 : opts.requireEnv) !== null && _a !== void 0 ? _a : false;
const prodCheck = (_b = opts === null || opts === void 0 ? void 0 : opts.checkProd) !== null && _b !== void 0 ? _b : true;
if ((prodCheck && ((_c = process.env.NODE_ENV) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'production') ||
(!requireEnv && envValue === 'false') ||
(requireEnv && envValue !== 'true')) {
return { name: PLUGIN_NAME };
}
// Lazy check the active status of the plugin
// as this gets fed after config is fully resolved
let enabled = true;
return {
name: PLUGIN_NAME,
transform: createTransform(opts),
configureServer: createConfigureServer(),
config(config) {
config.build = config.build || {};
config.build.sourcemap = true; // enforce sourcemapping
},
apply: 'serve',
// istanbul only knows how to instrument JavaScript,

@@ -95,5 +53,63 @@ // this allows us to wait until the whole code is JavaScript to

enforce: 'post',
config(config) {
var _a;
if (((_a = config.build) === null || _a === void 0 ? void 0 : _a.sourcemap) != true) {
logger.warn(`${PLUGIN_NAME}> ${(0, chalk_1.yellow)('Sourcemaps not enabled and will be automatically enabled for code coverage to be accurate.')}`);
// Enforce sourcemapping,
config.build = config.build || {};
config.build.sourcemap = true;
}
},
configResolved(config) {
var _a;
// We need to check if the plugin should enable after all configuration is resolved
// As config can be modified by other plugins and from .env variables
const { isProduction } = config;
const { CYPRESS_COVERAGE, VITE_COVERAGE } = config.env;
const env = (_a = (opts.cypress ? CYPRESS_COVERAGE : VITE_COVERAGE)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
if ((checkProd && isProduction) ||
(!requireEnv && env === 'false') ||
(requireEnv && env !== 'true')) {
enabled = false;
}
},
configureServer({ middlewares }) {
if (!enabled) {
return;
}
// Returns the current code coverage in the global scope
middlewares.use((req, res, next) => {
var _a;
if (req.url !== COVERAGE_PUBLIC_PATH) {
return next();
}
const coverage = (_a = (global.__coverage__)) !== null && _a !== void 0 ? _a : null;
let data;
try {
data = JSON.stringify(coverage, null, 4);
}
catch (ex) {
return next(ex);
}
res.setHeader('Content-Type', 'application/json');
res.statusCode = 200;
res.end(data);
});
},
transform(srcCode, id) {
if (!enabled || id.startsWith(MODULE_PREFIX) || id.startsWith(NULL_STRING)) {
// do not transform if this is a dep
// do not transform if plugin is not enabled
return;
}
if (exclude.shouldInstrument(id)) {
const sourceMap = sanitizeSourceMap(this.getCombinedSourcemap());
const code = instrumenter.instrumentSync(srcCode, id, sourceMap);
const map = instrumenter.lastSourceMap();
// Required to cast to correct mapping value
return { code, map };
}
},
};
}
module.exports = istanbulPlugin;
};
//# sourceMappingURL=index.js.map
{
"name": "vite-plugin-istanbul",
"version": "2.3.0",
"version": "2.4.0",
"author": "iFaxity (christian@faxity.se)",

@@ -32,2 +32,3 @@ "license": "MIT",

"dependencies": {
"chalk": "^4.1.2",
"istanbul-lib-instrument": "^4.0.3",

@@ -41,4 +42,4 @@ "test-exclude": "^6.0.0"

"typescript": "^4.3.5",
"vite": "^2.4.2"
"vite": "^2.7.10"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc