UNPKG

@storybook/addon-coverage

Version:

Tools to support code coverage in Storybook

75 lines (73 loc) 3.08 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/loader/webpack5-istanbul-loader.ts var webpack5_istanbul_loader_exports = {}; __export(webpack5_istanbul_loader_exports, { default: () => webpack5_istanbul_loader_default }); module.exports = __toCommonJS(webpack5_istanbul_loader_exports); var import_convert_source_map = require("convert-source-map"); var import_fs = __toESM(require("fs")); var import_path = __toESM(require("path")); function sanitizeSourceMap(rawSourceMap) { return typeof rawSourceMap === "string" ? JSON.parse(rawSourceMap) : rawSourceMap; } function webpack5_istanbul_loader_default(source, sourceMap) { let map = sourceMap ? sanitizeSourceMap(sourceMap) : getInlineSourceMap.call(this, source); const options = this.getOptions(); const callback = this.async(); if (!map) { callback(null, source, sourceMap); return; } const instrumenter = options.instrumenter; const code = instrumenter.instrumentSync(source, this.resourcePath, map); const lastSourceMap = instrumenter.lastSourceMap(); callback(null, code, lastSourceMap); } function getInlineSourceMap(source) { try { const inlineSourceMap = (0, import_convert_source_map.fromSource)(source) || (0, import_convert_source_map.fromMapFileSource)(source, function(filename) { return import_fs.default.readFileSync( import_path.default.resolve(import_path.default.dirname(this.resourcePath), filename), "utf-8" ); }); if (inlineSourceMap) { return inlineSourceMap.sourcemap; } } catch (e) { if (e instanceof Error && e.message.includes( "An error occurred while trying to read the map file at" )) { this.emitWarning(e); } else { throw e; } } }