Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-istanbul

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-istanbul - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

9

dist/index.d.ts
import type { Plugin } from 'vite';
import { IstanbulPluginOptions } from './transform';
interface IstanbulPluginOptions {
include?: string | string[];
exclude?: string | string[];
extension?: string | string[];
}
declare global {
var __coverage__: any;
}
declare function istanbulPlugin(opts?: IstanbulPluginOptions): Plugin;
export = istanbulPlugin;
//# sourceMappingURL=index.d.ts.map
"use strict";
const transform_1 = require("./transform");
const server_1 = require("./server");
const core_1 = require("@babel/core");
const babel_plugin_istanbul_1 = require("babel-plugin-istanbul");
const TestExclude = require("test-exclude");
const COVERAGE_PUBLIC_PATH = '/__coverage__';
function createConfigureServer() {
return ({ app }) => {
// Return global code coverage (will probably be null).
app.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 = {}) {
const plugins = [babel_plugin_istanbul_1.default];
const cwd = process.cwd();
const exclude = new TestExclude({
cwd,
include: opts.include,
exclude: opts.exclude,
extension: opts.extension,
excludeNodeModules: true,
});
return function (srcCode, id) {
if (process.env.NODE_ENV == 'production' || id.startsWith('/@modules/')) {
// do not transform if this is a dep
// do not transform for production builds
return;
}
if (exclude.shouldInstrument(id)) {
const { code, map } = core_1.transformSync(srcCode, {
plugins, cwd,
filename: id,
ast: false,
sourceMaps: true,
inputSourceMap: this.getCombinedSourcemap(),
});
return { code, map };
}
};
}
function istanbulPlugin(opts) {
const transform = transform_1.createTransform(opts);
return {
transforms: [transform],
configureServer: server_1.serverPlugin,
name: 'vite:istanbul',
transform: createTransform(opts),
configureServer: createConfigureServer(),
};

@@ -10,0 +62,0 @@ }

8

package.json
{
"name": "vite-plugin-istanbul",
"version": "1.1.0",
"version": "2.0.0",
"author": "iFaxity (christian@faxity.se)",

@@ -33,12 +33,12 @@ "license": "MIT",

"peerDependencies": {
"vite": "^1.0.0-rc.4"
"vite": "^2.0.0-beta.12"
},
"devDependencies": {
"@babel/core": "^7.11.1",
"@types/babel__core": "^7.1.12",
"@types/node": "^14.0.27",
"babel-plugin-istanbul": "^6.0.0",
"test-exclude": "^6.0.0",
"typescript": "^3.9.7",
"vite": "^1.0.0-rc.4"
"typescript": "^3.9.7"
}
}

@@ -11,9 +11,11 @@ vite-plugin-istanbul

Version v2.x for Vite v2.0, for Vite v1.0 install v1.x of this plugin
Installation
--------------------------
`$ npm i -D vite-plugin-istanbul`
`npm i -D vite-plugin-istanbul`
or if you use yarn
`$ yarn add -D vite-plugin-istanbul`
`yarn add -D vite-plugin-istanbul`

@@ -61,9 +63,2 @@ API

Testing (TODO: not yet finished)
--------------------------
```sh
$ npm run test
```
License

@@ -70,0 +65,0 @@ --------------------------

@@ -1,15 +0,82 @@

import type { Plugin } from 'vite';
import { IstanbulPluginOptions, createTransform } from './transform';
import { serverPlugin } from './server';
import type { Plugin, ServerHook } from 'vite';
import type { TransformHook } from 'rollup';
import { transformSync } from '@babel/core';
import BabelPluginIstanbul from 'babel-plugin-istanbul';
import * as TestExclude from 'test-exclude';
interface IstanbulPluginOptions {
include?: string|string[];
exclude?: string|string[];
extension?: string|string[];
}
declare global {
var __coverage__: any;
}
const COVERAGE_PUBLIC_PATH = '/__coverage__';
function createConfigureServer(): ServerHook {
return ({ app }) => {
// Return global code coverage (will probably be null).
app.use((req, res, next) => {
if (req.url !== COVERAGE_PUBLIC_PATH) {
return next();
}
const coverage = (global.__coverage__) ?? null;
let data: string;
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: IstanbulPluginOptions = {}): TransformHook {
const plugins = [ BabelPluginIstanbul ];
const cwd = process.cwd();
const exclude = new TestExclude({
cwd,
include: opts.include,
exclude: opts.exclude,
extension: opts.extension,
excludeNodeModules: true,
});
return function (srcCode, id) {
if (process.env.NODE_ENV == 'production' || id.startsWith('/@modules/')) {
// do not transform if this is a dep
// do not transform for production builds
return;
}
if (exclude.shouldInstrument(id)) {
const { code, map } = transformSync(srcCode, {
plugins, cwd,
filename: id,
ast: false,
sourceMaps: true,
inputSourceMap: this.getCombinedSourcemap(),
});
return { code, map };
}
};
}
function istanbulPlugin(opts?: IstanbulPluginOptions): Plugin {
const transform = createTransform(opts);
return {
transforms: [ transform ],
configureServer: serverPlugin,
name: 'vite:istanbul',
transform: createTransform(opts),
configureServer: createConfigureServer(),
};
}
export = istanbulPlugin;

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc