Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@arms/rum-bundler-plugin-core

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@arms/rum-bundler-plugin-core - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

194

dist/index.js
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('unplugin'), require('path'), require('fs/promises')) :
typeof define === 'function' && define.amd ? define(['exports', 'unplugin', 'path', 'fs/promises'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.rumWebpackPlugin = {}, global.unplugin, global.path, global.fs));
})(this, (function (exports, unplugin, path, fs) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('unplugin'), require('path'), require('fs/promises'), require('chalk')) :
typeof define === 'function' && define.amd ? define(['exports', 'unplugin', 'path', 'fs/promises', 'chalk'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.rumWebpackPlugin = {}, global.unplugin, global.path, global.fs, global.chalk));
})(this, (function (exports, unplugin, path, fs, chalk) { 'use strict';

@@ -398,2 +398,3 @@ function _interopNamespaceDefault(e) {

//@ts-ignore
function createLogger(options) {

@@ -406,3 +407,4 @@ var _ref = options || {},

_ref$prefix = _ref.prefix,
prefix = _ref$prefix === void 0 ? 'ARMS RUM Plugin' : _ref$prefix;
prefix = _ref$prefix === void 0 ? '' : _ref$prefix;
var cPrefix = prefix && chalk.hex('#74ABBA')(prefix);
return {

@@ -415,3 +417,3 @@ debug: function debug(message) {

}
(_console = console).debug.apply(_console, ["".concat(prefix, " Debug: ").concat(message)].concat(params));
(_console = console).debug.apply(_console, ["".concat(cPrefix, " Debug: ").concat(message)].concat(params));
}

@@ -425,3 +427,3 @@ },

}
(_console2 = console).info.apply(_console2, ["".concat(prefix, " Info: ").concat(message)].concat(params));
(_console2 = console).info.apply(_console2, ["".concat(cPrefix, " ").concat(chalk.green('Info'), ": ").concat(message)].concat(params));
}

@@ -435,3 +437,3 @@ },

}
(_console3 = console).warn.apply(_console3, ["".concat(prefix, " Warn: ").concat(message)].concat(params));
(_console3 = console).warn.apply(_console3, ["".concat(cPrefix, " ").concat(chalk.hex('#FF851B')('Warn'), ": ").concat(message)].concat(params));
}

@@ -445,3 +447,3 @@ },

}
(_console4 = console).error.apply(_console4, ["".concat(prefix, " Error: ").concat(message)].concat(params));
(_console4 = console).error.apply(_console4, ["".concat(cPrefix, " ").concat(chalk.hex('#FF4136')('Error'), ": ").concat(message)].concat(params));
}

@@ -452,6 +454,2 @@ }

function isValidUUID(uuid) {
var UUID_REGEX = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
return UUID_REGEX.test(uuid);
}
function generateUUID() {

@@ -486,3 +484,3 @@ return generateGUID();

var SUPPORT_EXTENSIONS = ['.js', '.cjs', '.mjs'];
function handleUUIDInjection(_x, _x2) {
function handleUUIDInjection(_x, _x2, _x3) {
return _handleUUIDInjection.apply(this, arguments);

@@ -498,4 +496,4 @@ }

function _handleUUIDInjection() {
_handleUUIDInjection = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(bundlePaths, logger) {
var successCount, failedCount, sourceFilePaths, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, sourceFilePath, sourceFileContent, sourceMapPath, uuid;
_handleUUIDInjection = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(bundlePaths, logger, bundleToolType) {
var successCount, failedCount, sourceMapCount, sourceFilePaths, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, sourceFilePath, sourceFileContent, sourceMapPath, uuid, totalFiles;
return _regeneratorRuntime().wrap(function _callee$(_context) {

@@ -506,2 +504,3 @@ while (1) switch (_context.prev = _context.next) {

failedCount = 0;
sourceMapCount = 0;
sourceFilePaths = bundlePaths.filter(function (bundlePath) {

@@ -512,88 +511,94 @@ return SUPPORT_EXTENSIONS.includes(path__namespace.extname(bundlePath));

_didIteratorError = false;
_context.prev = 5;
_context.prev = 6;
_iterator = _asyncIterator(sourceFilePaths);
case 7:
_context.next = 9;
case 8:
_context.next = 10;
return _iterator.next();
case 9:
case 10:
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
_context.next = 36;
_context.next = 38;
break;
}
sourceFilePath = _step.value;
_context.prev = 11;
_context.next = 14;
_context.prev = 12;
_context.next = 15;
return fs__namespace.readFile(sourceFilePath);
case 14:
case 15:
sourceFileContent = _context.sent.toString();
_context.next = 17;
_context.next = 18;
return findSourceMapPath(sourceFileContent, sourceFilePath, logger);
case 17:
case 18:
sourceMapPath = _context.sent;
if (sourceMapPath) {
_context.next = 20;
_context.next = 21;
break;
}
return _context.abrupt("continue", 33);
case 20:
return _context.abrupt("continue", 35);
case 21:
sourceMapCount++;
// 注入 UUID
uuid = getExsitingUUID(sourceFileContent) || generateUUID();
_context.next = 23;
return injectUUIDIntoSourceFile(sourceFileContent, sourceFilePath, uuid);
case 23:
_context.next = 25;
return injectUUIDIntoSourceFile(sourceFileContent, sourceFilePath, uuid, bundleToolType);
case 25:
_context.next = 27;
return injectUUIDIntoSourceMap(sourceMapPath, uuid);
case 25:
case 27:
successCount++;
_context.next = 33;
_context.next = 35;
break;
case 28:
_context.prev = 28;
_context.t0 = _context["catch"](11);
case 30:
_context.prev = 30;
_context.t0 = _context["catch"](12);
logger.error(_context.t0.message);
failedCount++;
return _context.abrupt("continue", 33);
case 33:
return _context.abrupt("continue", 35);
case 35:
_iteratorAbruptCompletion = false;
_context.next = 7;
_context.next = 8;
break;
case 36:
_context.next = 42;
case 38:
_context.next = 44;
break;
case 38:
_context.prev = 38;
_context.t1 = _context["catch"](5);
case 40:
_context.prev = 40;
_context.t1 = _context["catch"](6);
_didIteratorError = true;
_iteratorError = _context.t1;
case 42:
_context.prev = 42;
_context.prev = 43;
case 44:
_context.prev = 44;
_context.prev = 45;
if (!(_iteratorAbruptCompletion && _iterator["return"] != null)) {
_context.next = 47;
_context.next = 49;
break;
}
_context.next = 47;
_context.next = 49;
return _iterator["return"]();
case 47:
_context.prev = 47;
case 49:
_context.prev = 49;
if (!_didIteratorError) {
_context.next = 50;
_context.next = 52;
break;
}
throw _iteratorError;
case 50:
return _context.finish(47);
case 51:
return _context.finish(42);
case 52:
logger.debug("%Successfully injected UUID into ".concat(successCount, " files, while ").concat(failedCount, " files failed."), 'color: green;');
return _context.finish(49);
case 53:
return _context.finish(44);
case 54:
if (!sourceMapCount) {
logger.warn('No source maps found for the bundle. Please ensure that source map generation is enabled in your bundler configuration');
} else {
totalFiles = successCount + failedCount;
logger.info("UUID Injection Update: ".concat(successCount, " successes, ").concat(failedCount, " failures. Total files processed: ").concat(totalFiles));
}
case 55:
case "end":
return _context.stop();
}
}, _callee, null, [[5, 38, 42, 52], [11, 28], [43,, 47, 51]]);
}, _callee, null, [[6, 40, 44, 54], [12, 30], [45,, 49, 53]]);
}));
return _handleUUIDInjection.apply(this, arguments);
}
function findSourceMapPath(_x3, _x4, _x5) {
function findSourceMapPath(_x4, _x5, _x6) {
return _findSourceMapPath.apply(this, arguments);

@@ -645,7 +650,4 @@ }

case 12:
if (!sourceMapPath) {
logger.debug("Could not find source map path for bundle: ".concat(sourceFilePath, ". Please check if sourcemaps are correctly configured in your build tool."));
}
return _context2.abrupt("return", sourceMapPath);
case 14:
case 13:
case "end":

@@ -659,9 +661,12 @@ return _context2.stop();

function getExsitingUUID(sourceFileContent) {
var uuid = '';
var matchResult = sourceFileContent.match(/^\s*\/\/# debugId=(.*)$/m);
if (matchResult) {
uuid = matchResult[1];
// 查看是否有 sentry 注入的 UUID
var sentryUUIDMatch = sourceFileContent.match(/sentry-dbid-([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/);
if (sentryUUIDMatch) {
return sentryUUIDMatch[1];
}
uuid = isValidUUID(uuid) ? uuid : '';
return uuid;
var debugIdUUIDMatch = sourceFileContent.match(/\/\/# debugId=([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})/);
if (debugIdUUIDMatch) {
return debugIdUUIDMatch[1];
}
return '';
}

@@ -675,3 +680,3 @@

*/
function injectUUIDIntoSourceFile(_x6, _x7, _x8) {
function injectUUIDIntoSourceFile(_x7, _x8, _x9, _x10) {
return _injectUUIDIntoSourceFile.apply(this, arguments);

@@ -685,4 +690,4 @@ }

function _injectUUIDIntoSourceFile() {
_injectUUIDIntoSourceFile = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceFileContent, sourceFilePath, uuid) {
var newContent;
_injectUUIDIntoSourceFile = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(sourceFileContent, sourceFilePath, uuid, bundleToolType) {
var newContent, debugIdSnippet, matchResult, len;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {

@@ -692,21 +697,31 @@ while (1) switch (_context3.prev = _context3.next) {

_context3.prev = 0;
newContent = sourceFileContent + "".concat(sourceFileContent.endsWith('\n') ? '' : '\n', "//# debugId=").concat(uuid);
_context3.next = 4;
newContent = '';
debugIdSnippet = generateDebugIdSnippet(uuid);
if (bundleToolType === 'vite') {
matchResult = sourceFileContent.match(/^(?:\s*|\/\*(?:.|\r|\n)*?\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/);
if (matchResult) {
len = matchResult[0].length;
newContent = sourceFileContent.slice(0, len - 1) + debugIdSnippet + sourceFileContent.slice(len);
}
} else {
newContent = debugIdSnippet + sourceFileContent;
}
_context3.next = 6;
return fs__namespace.writeFile(sourceFilePath, newContent);
case 4:
_context3.next = 9;
case 6:
_context3.next = 11;
break;
case 6:
_context3.prev = 6;
case 8:
_context3.prev = 8;
_context3.t0 = _context3["catch"](0);
throw new Error("Failed to write UUID to file ".concat(sourceFilePath, ": ").concat(_context3.t0.message));
case 9:
case 11:
case "end":
return _context3.stop();
}
}, _callee3, null, [[0, 6]]);
}, _callee3, null, [[0, 8]]);
}));
return _injectUUIDIntoSourceFile.apply(this, arguments);
}
function injectUUIDIntoSourceMap(_x9, _x10) {
function injectUUIDIntoSourceMap(_x11, _x12) {
return _injectUUIDIntoSourceMap.apply(this, arguments);

@@ -744,4 +759,7 @@ }

}
function generateDebugIdSnippet(debugId) {
return ";!function(){try{var e=\"undefined\"!=typeof window?window:\"undefined\"!=typeof global?global:\"undefined\"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._armsRumDebugIds=e._armsRumDebugIds||{},e._armsRumDebugIds[n]=\"".concat(debugId, "\",e._armsRumDebugIdIdentifier=\"armsRum-uuid-").concat(debugId, "\")}catch(e){}}();");
}
function rumUnpluginFactory(rumPlugins) {
function rumUnpluginFactory(rumPlugins, bundleToolType) {
return function (options) {

@@ -752,3 +770,4 @@ var _ref = options || {},

var logger = createLogger({
debug: debug
debug: debug,
prefix: 'ARMS RUM'
});

@@ -758,3 +777,3 @@ var plugins = [];

plugins.push(UUIDInjectionPlugin(function (bundlePaths) {
return handleUUIDInjection(bundlePaths, logger);
return handleUUIDInjection(bundlePaths, logger, bundleToolType);
}));

@@ -765,6 +784,6 @@ return plugins;

function createRumWebpackPlugin(rumPlugins) {
return unplugin.createWebpackPlugin(rumUnpluginFactory(rumPlugins));
return unplugin.createWebpackPlugin(rumUnpluginFactory(rumPlugins, 'webpack'));
}
function createRumVitePlugin(rumPlugins) {
return unplugin.createVitePlugin(rumUnpluginFactory(rumPlugins));
return unplugin.createVitePlugin(rumUnpluginFactory(rumPlugins, 'vite'));
}

@@ -776,2 +795,1 @@

}));
//# sourceMappingURL=index.js.map
{
"name": "@arms/rum-bundler-plugin-core",
"version": "0.0.1",
"version": "0.0.2",
"description": "rum bundler plugin core",

@@ -33,4 +33,5 @@ "author": "ly403664 <ly403664@alibaba-inc.com>",

"dependencies": {
"chalk": "^4.1.2",
"unplugin": "^1.14.1"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc