[6a3a178] | 1 | "use strict";
|
---|
| 2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
---|
| 3 | if (k2 === undefined) k2 = k;
|
---|
| 4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
---|
| 5 | }) : (function(o, m, k, k2) {
|
---|
| 6 | if (k2 === undefined) k2 = k;
|
---|
| 7 | o[k2] = m[k];
|
---|
| 8 | }));
|
---|
| 9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
---|
| 10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
---|
| 11 | }) : function(o, v) {
|
---|
| 12 | o["default"] = v;
|
---|
| 13 | });
|
---|
| 14 | var __importStar = (this && this.__importStar) || function (mod) {
|
---|
| 15 | if (mod && mod.__esModule) return mod;
|
---|
| 16 | var result = {};
|
---|
| 17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
---|
| 18 | __setModuleDefault(result, mod);
|
---|
| 19 | return result;
|
---|
| 20 | };
|
---|
| 21 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
---|
| 22 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
---|
| 23 | };
|
---|
| 24 | Object.defineProperty(exports, "__esModule", { value: true });
|
---|
| 25 | const convert = __importStar(require("convert-source-map"));
|
---|
| 26 | const istanbul_lib_instrument_1 = require("istanbul-lib-instrument");
|
---|
| 27 | const loaderUtils = __importStar(require("loader-utils"));
|
---|
| 28 | const merge_source_map_1 = __importDefault(require("merge-source-map"));
|
---|
| 29 | const path = __importStar(require("path"));
|
---|
| 30 | const schema_utils_1 = __importDefault(require("schema-utils"));
|
---|
| 31 | const optionsSchema = __importStar(require("./options-schema.json"));
|
---|
| 32 | const options_js_1 = require("./options.js");
|
---|
| 33 | /**
|
---|
| 34 | * Adds code coverage instrumentation using Istanbul.
|
---|
| 35 | *
|
---|
| 36 | * If the source code has an existing source map, then it is used to re-map the instrumented
|
---|
| 37 | * code back to the original source.
|
---|
| 38 | */
|
---|
| 39 | function default_1(source, sourceMap) {
|
---|
| 40 | let options = loaderUtils.getOptions(this);
|
---|
| 41 | options = Object.assign(options_js_1.defaultOptions, options);
|
---|
| 42 | schema_utils_1.default(optionsSchema, options, "Coverage Istanbul Loader");
|
---|
| 43 | // If there's no external sourceMap file, then check for an inline sourceMap
|
---|
| 44 | if (!sourceMap) {
|
---|
| 45 | sourceMap = getInlineSourceMap.call(this, source);
|
---|
| 46 | }
|
---|
| 47 | // Instrument the code
|
---|
| 48 | let instrumenter = istanbul_lib_instrument_1.createInstrumenter(options);
|
---|
| 49 | instrumenter.instrument(source, this.resourcePath, done.bind(this), sourceMap);
|
---|
| 50 | function done(error, instrumentedSource) {
|
---|
| 51 | // Get the source map for the instrumented code
|
---|
| 52 | let instrumentedSourceMap = instrumenter.lastSourceMap();
|
---|
| 53 | if (sourceMap && instrumentedSourceMap) {
|
---|
| 54 | // Re-map the source map to the original source code
|
---|
| 55 | instrumentedSourceMap = merge_source_map_1.default(sourceMap, instrumentedSourceMap);
|
---|
| 56 | }
|
---|
| 57 | this.callback(error, instrumentedSource, instrumentedSourceMap);
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | exports.default = default_1;
|
---|
| 61 | /**
|
---|
| 62 | * If the source code has an inline base64-encoded source map,
|
---|
| 63 | * then this function decodes it, parses it, and returns it.
|
---|
| 64 | */
|
---|
| 65 | function getInlineSourceMap(source) {
|
---|
| 66 | try {
|
---|
| 67 | // Check for an inline source map
|
---|
| 68 | const inlineSourceMap = convert.fromSource(source)
|
---|
| 69 | || convert.fromMapFileSource(source, path.dirname(this.resourcePath));
|
---|
| 70 | if (inlineSourceMap) {
|
---|
| 71 | // Use the inline source map
|
---|
| 72 | return inlineSourceMap.sourcemap;
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | catch (e) {
|
---|
| 76 | // Exception is thrown by fromMapFileSource when there is no source map file
|
---|
| 77 | if (e instanceof Error && e.message.includes("An error occurred while trying to read the map file at")) {
|
---|
| 78 | this.emitWarning(e);
|
---|
| 79 | }
|
---|
| 80 | else {
|
---|
| 81 | throw e;
|
---|
| 82 | }
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | //# sourceMappingURL=index.js.map |
---|