@storybook/addon-coverage
Advanced tools
Comparing version 0.1.0-canary.27.1e3cf2f.0 to 0.1.0-canary.27.86a1d28.0
@@ -15,3 +15,3 @@ "use strict"; | ||
console.log("[addon-coverage] Adding istanbul plugin to vite config"); | ||
console.log("[addon-coverage] Adding istanbul plugin to Vite config"); | ||
viteConfig.build = viteConfig.build || {}; | ||
@@ -35,3 +35,3 @@ viteConfig.build.sourcemap = true; | ||
console.log("[addon-coverage] Adding istanbul plugin to babel config"); | ||
console.log("[addon-coverage] Adding istanbul plugin to Babel config"); | ||
babelConfig.plugins || (babelConfig.plugins = []); | ||
@@ -50,12 +50,3 @@ babelConfig.plugins.push(["istanbul", { ...options.istanbul, | ||
const swc = async (swcConfig, options) => { | ||
var _swcConfig$jsc$experi, _options$istanbul7, _options$istanbul8, _options$istanbul9; | ||
console.log("[addon-coverage] Adding istanbul plugin to SWC config"); | ||
(_swcConfig$jsc$experi = swcConfig.jsc.experimental).plugins || (_swcConfig$jsc$experi.plugins = []); | ||
swcConfig.jsc.experimental.plugins.push(["swc-plugin-coverage-instrument", { ...options.istanbul, | ||
include: Array.from(((_options$istanbul7 = options.istanbul) === null || _options$istanbul7 === void 0 ? void 0 : _options$istanbul7.include) || []), | ||
exclude: [options.configDir + "/**", ..._constants.defaultExclude, ...Array.from(((_options$istanbul8 = options.istanbul) === null || _options$istanbul8 === void 0 ? void 0 : _options$istanbul8.exclude) || [])], | ||
extension: ((_options$istanbul9 = options.istanbul) === null || _options$istanbul9 === void 0 ? void 0 : _options$istanbul9.extension) || _constants.defaultExtensions, | ||
coverageVariable: "__coverage__" | ||
}]); | ||
swcConfig.parseMap = true; | ||
return swcConfig; | ||
@@ -67,53 +58,35 @@ }; | ||
const webpackFinal = async (webpackConfig, options) => { | ||
var _webpackConfig$module; | ||
var _webpackConfig$module, _options$istanbul7; | ||
if (options.useWebpackConfig !== true) return webpackConfig; | ||
(_webpackConfig$module = webpackConfig.module).rules || (_webpackConfig$module.rules = []); | ||
const extensions = options.istanbul.extension || /\.(mjs|cjs|tsx?|jsx?)$/; | ||
const extensions = ((_options$istanbul7 = options.istanbul) === null || _options$istanbul7 === void 0 ? void 0 : _options$istanbul7.extension) || /\.(mjs|cjs|tsx?|jsx?)$/; | ||
console.log("[addon-coverage] Adding istanbul loader to Webpack config"); | ||
webpackConfig.module.rules.push({ | ||
test: extensions, | ||
loader: "@jsdevtools/coverage-istanbul-loader", | ||
enforce: "post", | ||
options: options.istanbul || {}, | ||
include: modulePath => { | ||
var _options$istanbul8; | ||
if (options.useSwcPlugin) { | ||
console.log("[addon-coverage] Adding istanbul plugin to SWC config"); | ||
webpackConfig.module.rules.push({ | ||
test: extensions, | ||
use: [{ | ||
loader: require.resolve('swc-loader'), | ||
options: { | ||
parseMap: true, | ||
jsc: { | ||
experimental: { | ||
plugins: [["swc-plugin-coverage-instrument", { ...options.istanbul, | ||
coverageVariable: options.istanbul.coverageVariable || "__coverage__" | ||
}]] | ||
} | ||
} | ||
} | ||
}], | ||
include: options.istanbul.include || [], | ||
exclude: options.istanbul.exclude || (modulePath => { | ||
return _constants.defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
}) | ||
}); | ||
} else { | ||
console.log("[addon-coverage] Adding istanbul plugin to Webpack config"); | ||
webpackConfig.module.rules.push({ | ||
test: extensions, | ||
use: [{ | ||
loader: require.resolve('swc-loader'), | ||
options: { | ||
parseMap: true | ||
} | ||
}], | ||
exclude: options.istanbul.exclude || (modulePath => { | ||
return _constants.defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
}) | ||
}, { | ||
test: extensions, | ||
loader: '@jsdevtools/coverage-istanbul-loader', | ||
enforce: 'post', | ||
options: options.istanbul || {}, | ||
exclude: options.istanbul.exclude || (modulePath => { | ||
return _constants.defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
}) | ||
}); | ||
} | ||
if ((_options$istanbul8 = options.istanbul) !== null && _options$istanbul8 !== void 0 && _options$istanbul8.include) { | ||
const includeRegexes = options.istanbul.include.map(pattern => new RegExp(pattern)); | ||
return includeRegexes.some(pattern => pattern.test(modulePath)); | ||
} else { | ||
return true; | ||
} | ||
}, | ||
exclude: modulePath => { | ||
var _options$istanbul9; | ||
const excludeRegexes = _constants.defaultExcludeRegexes; | ||
if ((_options$istanbul9 = options.istanbul) !== null && _options$istanbul9 !== void 0 && _options$istanbul9.exclude) { | ||
excludeRegexes.push(...options.istanbul.exclude.map(pattern => new RegExp(pattern))); | ||
} | ||
return _constants.defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
} | ||
}); | ||
return webpackConfig; | ||
@@ -120,0 +93,0 @@ }; |
@@ -7,3 +7,3 @@ import { defaultExclude, defaultExcludeRegexes, defaultExtensions } from "./constants"; | ||
console.log("[addon-coverage] Adding istanbul plugin to vite config"); | ||
console.log("[addon-coverage] Adding istanbul plugin to Vite config"); | ||
viteConfig.build = viteConfig.build || {}; | ||
@@ -24,3 +24,3 @@ viteConfig.build.sourcemap = true; | ||
console.log("[addon-coverage] Adding istanbul plugin to babel config"); | ||
console.log("[addon-coverage] Adding istanbul plugin to Babel config"); | ||
babelConfig.plugins ||= []; | ||
@@ -36,65 +36,40 @@ babelConfig.plugins.push(["istanbul", { ...options.istanbul, | ||
export const swc = async (swcConfig, options) => { | ||
var _options$istanbul7, _options$istanbul8, _options$istanbul9; | ||
console.log("[addon-coverage] Adding istanbul plugin to SWC config"); | ||
swcConfig.jsc.experimental.plugins ||= []; | ||
swcConfig.jsc.experimental.plugins.push(["swc-plugin-coverage-instrument", { ...options.istanbul, | ||
include: Array.from(((_options$istanbul7 = options.istanbul) === null || _options$istanbul7 === void 0 ? void 0 : _options$istanbul7.include) || []), | ||
exclude: [options.configDir + "/**", ...defaultExclude, ...Array.from(((_options$istanbul8 = options.istanbul) === null || _options$istanbul8 === void 0 ? void 0 : _options$istanbul8.exclude) || [])], | ||
extension: ((_options$istanbul9 = options.istanbul) === null || _options$istanbul9 === void 0 ? void 0 : _options$istanbul9.extension) || defaultExtensions, | ||
coverageVariable: "__coverage__" | ||
}]); | ||
swcConfig.parseMap = true; | ||
return swcConfig; | ||
}; | ||
export const webpackFinal = async (webpackConfig, options) => { | ||
var _options$istanbul7; | ||
if (options.useWebpackConfig !== true) return webpackConfig; | ||
webpackConfig.module.rules ||= []; | ||
const extensions = options.istanbul.extension || /\.(mjs|cjs|tsx?|jsx?)$/; | ||
const extensions = ((_options$istanbul7 = options.istanbul) === null || _options$istanbul7 === void 0 ? void 0 : _options$istanbul7.extension) || /\.(mjs|cjs|tsx?|jsx?)$/; | ||
console.log("[addon-coverage] Adding istanbul loader to Webpack config"); | ||
webpackConfig.module.rules.push({ | ||
test: extensions, | ||
loader: "@jsdevtools/coverage-istanbul-loader", | ||
enforce: "post", | ||
options: options.istanbul || {}, | ||
include: modulePath => { | ||
var _options$istanbul8; | ||
if (options.useSwcPlugin) { | ||
console.log("[addon-coverage] Adding istanbul plugin to SWC config"); | ||
webpackConfig.module.rules.push({ | ||
test: extensions, | ||
use: [{ | ||
loader: require.resolve('swc-loader'), | ||
options: { | ||
parseMap: true, | ||
jsc: { | ||
experimental: { | ||
plugins: [["swc-plugin-coverage-instrument", { ...options.istanbul, | ||
coverageVariable: options.istanbul.coverageVariable || "__coverage__" | ||
}]] | ||
} | ||
} | ||
} | ||
}], | ||
include: options.istanbul.include || [], | ||
exclude: options.istanbul.exclude || (modulePath => { | ||
return defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
}) | ||
}); | ||
} else { | ||
console.log("[addon-coverage] Adding istanbul plugin to Webpack config"); | ||
webpackConfig.module.rules.push({ | ||
test: extensions, | ||
use: [{ | ||
loader: require.resolve('swc-loader'), | ||
options: { | ||
parseMap: true | ||
} | ||
}], | ||
exclude: options.istanbul.exclude || (modulePath => { | ||
return defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
}) | ||
}, { | ||
test: extensions, | ||
loader: '@jsdevtools/coverage-istanbul-loader', | ||
enforce: 'post', | ||
options: options.istanbul || {}, | ||
exclude: options.istanbul.exclude || (modulePath => { | ||
return defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
}) | ||
}); | ||
} | ||
if ((_options$istanbul8 = options.istanbul) !== null && _options$istanbul8 !== void 0 && _options$istanbul8.include) { | ||
const includeRegexes = options.istanbul.include.map(pattern => new RegExp(pattern)); | ||
return includeRegexes.some(pattern => pattern.test(modulePath)); | ||
} else { | ||
return true; | ||
} | ||
}, | ||
exclude: modulePath => { | ||
var _options$istanbul9; | ||
const excludeRegexes = defaultExcludeRegexes; | ||
if ((_options$istanbul9 = options.istanbul) !== null && _options$istanbul9 !== void 0 && _options$istanbul9.exclude) { | ||
excludeRegexes.push(...options.istanbul.exclude.map(pattern => new RegExp(pattern))); | ||
} | ||
return defaultExcludeRegexes.some(pattern => pattern.test(modulePath)); | ||
} | ||
}); | ||
return webpackConfig; | ||
}; |
@@ -6,3 +6,3 @@ import type { TransformOptions } from "@babel/core"; | ||
export declare const babel: (babelConfig: TransformOptions, options: Options & AddonOptionsBabel) => Promise<TransformOptions>; | ||
export declare const swc: (swcConfig: Record<string, any>, options: Options & AddonOptionsVite) => Promise<Record<string, any>>; | ||
export declare const swc: (swcConfig: Record<string, any>, options: Options & AddonOptionsWebpack) => Promise<Record<string, any>>; | ||
export declare const webpackFinal: (webpackConfig: Record<string, any>, options: Options & AddonOptionsWebpack) => Promise<Record<string, any>>; |
@@ -42,2 +42,4 @@ import type { IstanbulPluginOptions as IstanbulOptionsVite } from "vite-plugin-istanbul"; | ||
export declare type AddonOptionsWebpack = { | ||
useWebpackConfig?: boolean; | ||
useSwcConfig?: boolean; | ||
useSwcPlugin: true; | ||
@@ -50,2 +52,4 @@ istanbul?: { | ||
} | { | ||
useWebpackConfig?: boolean; | ||
useSwcConfig?: boolean; | ||
useSwcPlugin: false; | ||
@@ -52,0 +56,0 @@ istanbul?: { |
{ | ||
"name": "@storybook/addon-coverage", | ||
"version": "0.1.0-canary.27.1e3cf2f.0", | ||
"version": "0.1.0-canary.27.86a1d28.0", | ||
"description": "Tools to support code coverage in Storybook", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
27552
14
265