UNPKG

@splunk/rum-cli

Version:

Tools for handling symbol and mapping files for symbolication

80 lines (79 loc) 3.77 kB
"use strict"; /* * Copyright Splunk Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __asyncValues = (this && this.__asyncValues) || function (o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator], i; return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i); function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; } function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.computeSourceMapId = computeSourceMapId; const node_crypto_1 = require("node:crypto"); const filesystem_1 = require("../utils/filesystem"); const utils_1 = require("./utils"); /** * sourceMapId is computed by hashing the contents of the ".map" file, and then * formatting the hash to like a GUID. */ function computeSourceMapId(sourceMapFilePath, options) { return __awaiter(this, void 0, void 0, function* () { var _a, e_1, _b, _c; const hash = (0, node_crypto_1.createHash)('sha256').setEncoding('hex'); try { const fileStream = (0, filesystem_1.makeReadStream)(sourceMapFilePath); try { for (var _d = true, fileStream_1 = __asyncValues(fileStream), fileStream_1_1; fileStream_1_1 = yield fileStream_1.next(), _a = fileStream_1_1.done, !_a; _d = true) { _c = fileStream_1_1.value; _d = false; const chunk = _c; hash.update(chunk); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = fileStream_1.return)) yield _b.call(fileStream_1); } finally { if (e_1) throw e_1.error; } } } catch (e) { (0, utils_1.throwJsMapFileReadError)(e, sourceMapFilePath, options); } const sha = hash.digest('hex'); return shaToSourceMapId(sha); }); } function shaToSourceMapId(sha) { return [ sha.slice(0, 8), sha.slice(8, 12), sha.slice(12, 16), sha.slice(16, 20), sha.slice(20, 32), ].join('-'); }