UNPKG

@ima/dev-utils

Version:

IMA.js dev utils used used mainly in @ima/cli and other dev-related utilities.

36 lines (35 loc) 1.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractSourceMappingUrl = void 0; const helpers_1 = require("./helpers"); /** * Extracts sourceMappingURL from the provided file contents. * Based on https://github.com/facebook/create-react-app/blob/main/packages/react-error-overlay/src/utils/getSourceMap.js#L79. * * @param {string} fileUri The uri of the source file. * @param {string} fileContents Source file file contents. * @returns {string|null} */ function extractSourceMappingUrl(fileUri, fileContents) { let match = null; for (;;) { const next = helpers_1.RE_SOURCE_MAPPING_URL.exec(fileContents); if (next == null) { break; } match = next; } if (!(match && match[1])) { return null; } const sourceMappingUrl = match[1].toString(); // Inline base64 source map if (sourceMappingUrl.includes('data:')) { throw new Error(`Sorry, base64 inline source-map encoding is not supported ${fileUri}.`); } // Prefix source map filename with path from fileUri const lastSlashIndex = fileUri.lastIndexOf('/'); const mapFileUri = fileUri.substring(0, lastSlashIndex + 1) + sourceMappingUrl; return mapFileUri; } exports.extractSourceMappingUrl = extractSourceMappingUrl;