Socket
Socket
Sign inDemoInstall

hermes-profile-transformer

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.3 to 0.0.4

dist/index.debug.d.ts

78

dist/hermes-profile-transformer.cjs.development.js

@@ -5,3 +5,6 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var fs = require('fs');
var path = _interopDefault(require('path'));
var sourceMap = require('source-map');

@@ -212,2 +215,15 @@

/**
* The name needs to be modified if `http://` is present as this directs us to bundle files which does not add any information for the end user
* @param name
*/
var removeLinksIfExist = function removeLinksIfExist(name) {
// If the name includes `http://`, we can filter the name
if (name.includes('http://')) {
name = name.substring(0, name.lastIndexOf('('));
}
return name || 'anonymous';
};
/**
* Create a Duration Event from CPUProfileChunkNodes.

@@ -217,2 +233,3 @@ * @param {CPUProfileChunkNode} node

var createEvent = function createEvent(node) {

@@ -224,9 +241,5 @@ return {

ph: EventsPhase.DURATION_EVENTS_BEGIN,
name: node.callFrame.name,
name: removeLinksIfExist(node.callFrame.name),
cat: node.callFrame.category,
args: {
data: {
callFrame: node.callFrame
}
}
args: _extends({}, node.callFrame)
};

@@ -264,3 +277,3 @@ };

var nodeId = profile.samples[i];
var timeDelta = Math.max(profile.timeDeltas[i], 1);
var timeDelta = Math.max(profile.timeDeltas[i], 0);

@@ -420,3 +433,19 @@ var node = this._nodesById.get(nodeId);

/**
* Refer to the source maps for the bundleFileName. Throws error if args not set up in ChromeEvents
* This function is a helper to the changeNamesToSourceMaps. The category allocation logic is implemented here based on the sourcemap url (if available)
* @param defaultCategory The category the event is of by default without the use of Source maps
* @param url The URL which can be parsed to interpret the new category of the event (depends on node_modules)
*/
var improveCategories = function improveCategories(defaultCategory, url) {
var obtainCategory = function obtainCategory(url) {
var dirs = url.substring(url.lastIndexOf(path.sep + "node_modules" + path.sep)).split(path.sep);
return dirs.length > 2 && dirs[1] === 'node_modules' ? dirs[2] : defaultCategory;
};
return url ? obtainCategory(url) : defaultCategory;
};
/**
* Refer to the source maps for the bundleFileName and change the event names to derive
* from source maps which usually add more information for the user
* Throws error if args not set up in ChromeEvents
* @param {SourceMap} sourceMap

@@ -429,2 +458,3 @@ * @param {DurationEvent[]} chromeEvents

var changeNamesToSourceMaps = function changeNamesToSourceMaps(sourceMap$1, chromeEvents, indexBundleFileName) {

@@ -444,25 +474,21 @@ try {

if (event.args) {
var _event$args;
var sm = consumer.originalPositionFor({
line: Number(event.args.data.callFrame.line),
column: Number(event.args.data.callFrame.column)
line: Number(event.args.line),
column: Number(event.args.column)
});
event.args = {
data: {
callFrame: _extends({}, (_event$args = event.args) === null || _event$args === void 0 ? void 0 : _event$args.data.callFrame, {
url: sm.source,
line: sm.line,
column: sm.column
})
}
};
/**
* The name in source maps (for reasons I don't understand) is sometimes null, so OR-ing this
* to ensure a name is assigned.
* In case a name wasn't found, the URL is used
* Eg: /Users/saphal/Desktop/app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js => MessageQueue.js
* The categories can help us better visualise the profile if we modify the categories.
* We change these categories only in the root level and not deeper inside the args, just so we have our
* original categories as well as these modified categories (as the modified categories simply help with visualisation)
*/
event.name = sm.name || (event.args.data.callFrame.url ? "anonymous @ " + event.args.data.callFrame.url.split('/').pop() : event.args.data.callFrame.name);
event.cat = improveCategories(event.cat, sm.source);
event.args = _extends({}, event.args, {
url: sm.source,
line: sm.line,
column: sm.column,
params: sm.name,
allocatedCategory: event.cat,
allocatedName: event.name
});
} else {

@@ -469,0 +495,0 @@ throw new Error("Source maps could not be derived for an event at " + event.ts + " and with stackFrame ID " + event.sf);

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r=require("fs"),t=require("source-map");function n(){return(n=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function a(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function o(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return a(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?a(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}!function(e){e.DURATION_EVENTS_BEGIN="B",e.DURATION_EVENTS_END="E",e.COMPLETE_EVENTS="X",e.INSTANT_EVENTS="I",e.COUNTER_EVENTS="C",e.ASYNC_EVENTS_NESTABLE_START="b",e.ASYNC_EVENTS_NESTABLE_INSTANT="n",e.ASYNC_EVENTS_NESTABLE_END="e",e.FLOW_EVENTS_START="s",e.FLOW_EVENTS_STEP="t",e.FLOW_EVENTS_END="f",e.SAMPLE_EVENTS="P",e.OBJECT_EVENTS_CREATED="N",e.OBJECT_EVENTS_SNAPSHOT="O",e.OBJECT_EVENTS_DESTROYED="D",e.METADATA_EVENTS="M",e.MEMORY_DUMP_EVENTS_GLOBAL="V",e.MEMORY_DUMP_EVENTS_PROCESS="v",e.MARK_EVENTS="R",e.CLOCK_SYNC_EVENTS="c",e.CONTEXT_EVENTS_ENTER="(",e.CONTEXT_EVENTS_LEAVE=")",e.ASYNC_EVENTS_START="S",e.ASYNC_EVENTS_STEP_INTO="T",e.ASYNC_EVENTS_STEP_PAST="p",e.ASYNC_EVENTS_END="F",e.LINKED_ID_EVENTS="="}(e||(e={}));var i=function(){function r(e){this._profile=e,this._nodesById=this._createNodeMap(),this._activeNodeArraysById=this._createActiveNodeArrays()}var t=r.prototype;return t._createNodeMap=function(){for(var e,r=new Map,t=o(this._profile.nodes);!(e=t()).done;){var n=e.value;r.set(n.id,n)}return r},t._createActiveNodeArrays=function(){for(var e,r=this,t=new Map,n=function e(n){if(t.has(n))return t.get(n)||[];var a=r._nodesById.get(n);if(!a)throw new Error("No such node "+n);if(a.parent){var o=e(a.parent).concat([n]);return t.set(n,o),o}return[n]},a=o(this._profile.nodes);!(e=a()).done;){var i=e.value;t.set(i.id,n(i.id))}return t},t._getActiveNodeIds=function(e){var r=this._activeNodeArraysById.get(e);if(!r)throw new Error("No such node ID "+e);return r},t._createStartEndEventsForTransition=function(r,t,a){var o=this,i=a.filter((function(e){return!t.includes(e)})).map((function(e){return o._nodesById.get(e)})),s=t.filter((function(e){return!a.includes(e)})).map((function(e){return o._nodesById.get(e)})),u=function(t){return{ts:r,pid:o._profile.pid,tid:Number(o._profile.tid),ph:e.DURATION_EVENTS_BEGIN,name:t.callFrame.name,cat:t.callFrame.category,args:{data:{callFrame:t.callFrame}}}},c=i.map(u).map((function(r){return n({},r,{ph:e.DURATION_EVENTS_BEGIN})})),l=s.map(u).map((function(r){return n({},r,{ph:e.DURATION_EVENTS_END})}));return[].concat(l.reverse(),c)},t.createStartEndEvents=function(){var e=this._profile,r=e.samples.length;if(e.timeDeltas.length!==r||e.samples.length!==r)throw new Error("Invalid CPU profile length");for(var t=[],n=e.startTime,a=[],o=0;o<e.samples.length;o++){var i=e.samples[o],s=Math.max(e.timeDeltas[o],1);if(!this._nodesById.get(i))throw new Error("Missing node "+i);n+=s;var u=this._getActiveNodeIds(i);t.push.apply(t,this._createStartEndEventsForTransition(n,a,u)),a=u}return t.push.apply(t,this._createStartEndEventsForTransition(n,a,[])),t},r.createStartEndEvents=function(e){return new r(e).createStartEndEvents()},r.collectProfileEvents=function(e){if(e.samples.length>=0){var r=e.samples,t=e.stackFrames,n=r[0].pid,a=r[0].tid,o=Number(r[0].ts),i=this.constructNodes(r,t);return{id:"0x1",pid:n,tid:a,startTime:o,nodes:i.nodes,samples:i.sampleNumbers,timeDeltas:i.timeDeltas}}throw new Error("The hermes profile has zero samples")},r.constructNodes=function(e,r){e=e.map((function(e){return e.stackFrameData=r[e.sf],e}));var t=Object.keys(r).map((function(e){var t=r[e];return{id:Number(e),callFrame:n({},t,{url:t.name}),parent:r[e].parent}})),a=[],o=[],i=Number(e[0].ts);return e.forEach((function(e,r){if(a.push(e.sf),0===r)o.push(0);else{var t=Number(e.ts)-i;i=Number(e.ts),o.push(t)}})),{nodes:t,sampleNumbers:a,timeDeltas:o}},r}();"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var s=function(e){try{return Promise.resolve(function(t,n){try{var a=Promise.resolve(r.promises.readFile(e,"utf-8")).then((function(r){if(0===r.length)throw new Error(e+" is an empty file");return JSON.parse(r)}))}catch(e){return n(e)}return a&&a.then?a.then(void 0,n):a}(0,(function(e){throw new Error(e.message)})))}catch(e){return Promise.reject(e)}},u=function(e,r,a){try{var o={version:Number(e.version),file:a||"index.bundle",sources:e.sources,mappings:e.mappings,names:e.names};return Promise.resolve(new t.SourceMapConsumer(o)).then((function(e){var t=r.map((function(r){if(!r.args)throw new Error("Source maps could not be derived for an event at "+r.ts+" and with stackFrame ID "+r.sf);var t,a=e.originalPositionFor({line:Number(r.args.data.callFrame.line),column:Number(r.args.data.callFrame.column)});return r.args={data:{callFrame:n({},null===(t=r.args)||void 0===t?void 0:t.data.callFrame,{url:a.source,line:a.line,column:a.column})}},r.name=a.name||(r.args.data.callFrame.url?"anonymous @ "+r.args.data.callFrame.url.split("/").pop():r.args.data.callFrame.name),r}));return e.destroy(),t}))}catch(e){return Promise.reject(e)}};exports.default=function(e,r,t){try{return Promise.resolve(s(e)).then((function(e){var n=!1,a=i.collectProfileEvents(e),o=new i(a).createStartEndEvents(),c=function(){if(r)return Promise.resolve(s(r)).then((function(e){var r=u(e,o,t);return n=!0,r}))}();return c&&c.then?c.then((function(e){return n?e:o})):n?c:o}))}catch(e){return Promise.reject(e)}};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,r,t=require("fs"),n=(e=require("path"))&&"object"==typeof e&&"default"in e?e.default:e,o=require("source-map");function a(){return(a=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e}).apply(this,arguments)}function s(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}function i(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return s(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?s(e,void 0):void 0}}(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(t=e[Symbol.iterator]()).next.bind(t)}!function(e){e.DURATION_EVENTS_BEGIN="B",e.DURATION_EVENTS_END="E",e.COMPLETE_EVENTS="X",e.INSTANT_EVENTS="I",e.COUNTER_EVENTS="C",e.ASYNC_EVENTS_NESTABLE_START="b",e.ASYNC_EVENTS_NESTABLE_INSTANT="n",e.ASYNC_EVENTS_NESTABLE_END="e",e.FLOW_EVENTS_START="s",e.FLOW_EVENTS_STEP="t",e.FLOW_EVENTS_END="f",e.SAMPLE_EVENTS="P",e.OBJECT_EVENTS_CREATED="N",e.OBJECT_EVENTS_SNAPSHOT="O",e.OBJECT_EVENTS_DESTROYED="D",e.METADATA_EVENTS="M",e.MEMORY_DUMP_EVENTS_GLOBAL="V",e.MEMORY_DUMP_EVENTS_PROCESS="v",e.MARK_EVENTS="R",e.CLOCK_SYNC_EVENTS="c",e.CONTEXT_EVENTS_ENTER="(",e.CONTEXT_EVENTS_LEAVE=")",e.ASYNC_EVENTS_START="S",e.ASYNC_EVENTS_STEP_INTO="T",e.ASYNC_EVENTS_STEP_PAST="p",e.ASYNC_EVENTS_END="F",e.LINKED_ID_EVENTS="="}(r||(r={}));var u=function(){function e(e){this._profile=e,this._nodesById=this._createNodeMap(),this._activeNodeArraysById=this._createActiveNodeArrays()}var t=e.prototype;return t._createNodeMap=function(){for(var e,r=new Map,t=i(this._profile.nodes);!(e=t()).done;){var n=e.value;r.set(n.id,n)}return r},t._createActiveNodeArrays=function(){for(var e,r=this,t=new Map,n=function e(n){if(t.has(n))return t.get(n)||[];var o=r._nodesById.get(n);if(!o)throw new Error("No such node "+n);if(o.parent){var a=e(o.parent).concat([n]);return t.set(n,a),a}return[n]},o=i(this._profile.nodes);!(e=o()).done;){var a=e.value;t.set(a.id,n(a.id))}return t},t._getActiveNodeIds=function(e){var r=this._activeNodeArraysById.get(e);if(!r)throw new Error("No such node ID "+e);return r},t._createStartEndEventsForTransition=function(e,t,n){var o=this,s=n.filter((function(e){return!t.includes(e)})).map((function(e){return o._nodesById.get(e)})),i=t.filter((function(e){return!n.includes(e)})).map((function(e){return o._nodesById.get(e)})),u=function(t){return{ts:e,pid:o._profile.pid,tid:Number(o._profile.tid),ph:r.DURATION_EVENTS_BEGIN,name:(n=t.callFrame.name,n.includes("http://")&&(n=n.substring(0,n.lastIndexOf("("))),n||"anonymous"),cat:t.callFrame.category,args:a({},t.callFrame)};var n},c=s.map(u).map((function(e){return a({},e,{ph:r.DURATION_EVENTS_BEGIN})})),E=i.map(u).map((function(e){return a({},e,{ph:r.DURATION_EVENTS_END})}));return[].concat(E.reverse(),c)},t.createStartEndEvents=function(){var e=this._profile,r=e.samples.length;if(e.timeDeltas.length!==r||e.samples.length!==r)throw new Error("Invalid CPU profile length");for(var t=[],n=e.startTime,o=[],a=0;a<e.samples.length;a++){var s=e.samples[a],i=Math.max(e.timeDeltas[a],0);if(!this._nodesById.get(s))throw new Error("Missing node "+s);n+=i;var u=this._getActiveNodeIds(s);t.push.apply(t,this._createStartEndEventsForTransition(n,o,u)),o=u}return t.push.apply(t,this._createStartEndEventsForTransition(n,o,[])),t},e.createStartEndEvents=function(r){return new e(r).createStartEndEvents()},e.collectProfileEvents=function(e){if(e.samples.length>=0){var r=e.samples,t=e.stackFrames,n=r[0].pid,o=r[0].tid,a=Number(r[0].ts),s=this.constructNodes(r,t);return{id:"0x1",pid:n,tid:o,startTime:a,nodes:s.nodes,samples:s.sampleNumbers,timeDeltas:s.timeDeltas}}throw new Error("The hermes profile has zero samples")},e.constructNodes=function(e,r){e=e.map((function(e){return e.stackFrameData=r[e.sf],e}));var t=Object.keys(r).map((function(e){var t=r[e];return{id:Number(e),callFrame:a({},t,{url:t.name}),parent:r[e].parent}})),n=[],o=[],s=Number(e[0].ts);return e.forEach((function(e,r){if(n.push(e.sf),0===r)o.push(0);else{var t=Number(e.ts)-s;s=Number(e.ts),o.push(t)}})),{nodes:t,sampleNumbers:n,timeDeltas:o}},e}();"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var c=function(e){try{return Promise.resolve(function(r,n){try{var o=Promise.resolve(t.promises.readFile(e,"utf-8")).then((function(r){if(0===r.length)throw new Error(e+" is an empty file");return JSON.parse(r)}))}catch(e){return n(e)}return o&&o.then?o.then(void 0,n):o}(0,(function(e){throw new Error(e.message)})))}catch(e){return Promise.reject(e)}},E=function(e,r,t){try{var s={version:Number(e.version),file:t||"index.bundle",sources:e.sources,mappings:e.mappings,names:e.names};return Promise.resolve(new o.SourceMapConsumer(s)).then((function(e){var t=r.map((function(r){if(!r.args)throw new Error("Source maps could not be derived for an event at "+r.ts+" and with stackFrame ID "+r.sf);var t,o,s=e.originalPositionFor({line:Number(r.args.line),column:Number(r.args.column)});return r.cat=(t=r.cat,(o=s.source)?function(e){var r=e.substring(e.lastIndexOf(n.sep+"node_modules"+n.sep)).split(n.sep);return r.length>2&&"node_modules"===r[1]?r[2]:t}(o):t),r.args=a({},r.args,{url:s.source,line:s.line,column:s.column,params:s.name,allocatedCategory:r.cat,allocatedName:r.name}),r}));return e.destroy(),t}))}catch(e){return Promise.reject(e)}};exports.default=function(e,r,t){try{return Promise.resolve(c(e)).then((function(e){var n=!1,o=u.collectProfileEvents(e),a=new u(o).createStartEndEvents(),s=function(){if(r)return Promise.resolve(c(r)).then((function(e){var r=E(e,a,t);return n=!0,r}))}();return s&&s.then?s.then((function(e){return n?e:a})):n?s:a}))}catch(e){return Promise.reject(e)}};
//# sourceMappingURL=hermes-profile-transformer.cjs.production.min.js.map
import { promises } from 'fs';
import path from 'path';
import { SourceMapConsumer } from 'source-map';

@@ -207,2 +208,15 @@

/**
* The name needs to be modified if `http://` is present as this directs us to bundle files which does not add any information for the end user
* @param name
*/
var removeLinksIfExist = function removeLinksIfExist(name) {
// If the name includes `http://`, we can filter the name
if (name.includes('http://')) {
name = name.substring(0, name.lastIndexOf('('));
}
return name || 'anonymous';
};
/**
* Create a Duration Event from CPUProfileChunkNodes.

@@ -212,2 +226,3 @@ * @param {CPUProfileChunkNode} node

var createEvent = function createEvent(node) {

@@ -219,9 +234,5 @@ return {

ph: EventsPhase.DURATION_EVENTS_BEGIN,
name: node.callFrame.name,
name: removeLinksIfExist(node.callFrame.name),
cat: node.callFrame.category,
args: {
data: {
callFrame: node.callFrame
}
}
args: _extends({}, node.callFrame)
};

@@ -259,3 +270,3 @@ };

var nodeId = profile.samples[i];
var timeDelta = Math.max(profile.timeDeltas[i], 1);
var timeDelta = Math.max(profile.timeDeltas[i], 0);

@@ -415,3 +426,19 @@ var node = this._nodesById.get(nodeId);

/**
* Refer to the source maps for the bundleFileName. Throws error if args not set up in ChromeEvents
* This function is a helper to the changeNamesToSourceMaps. The category allocation logic is implemented here based on the sourcemap url (if available)
* @param defaultCategory The category the event is of by default without the use of Source maps
* @param url The URL which can be parsed to interpret the new category of the event (depends on node_modules)
*/
var improveCategories = function improveCategories(defaultCategory, url) {
var obtainCategory = function obtainCategory(url) {
var dirs = url.substring(url.lastIndexOf(path.sep + "node_modules" + path.sep)).split(path.sep);
return dirs.length > 2 && dirs[1] === 'node_modules' ? dirs[2] : defaultCategory;
};
return url ? obtainCategory(url) : defaultCategory;
};
/**
* Refer to the source maps for the bundleFileName and change the event names to derive
* from source maps which usually add more information for the user
* Throws error if args not set up in ChromeEvents
* @param {SourceMap} sourceMap

@@ -424,2 +451,3 @@ * @param {DurationEvent[]} chromeEvents

var changeNamesToSourceMaps = function changeNamesToSourceMaps(sourceMap, chromeEvents, indexBundleFileName) {

@@ -439,25 +467,21 @@ try {

if (event.args) {
var _event$args;
var sm = consumer.originalPositionFor({
line: Number(event.args.data.callFrame.line),
column: Number(event.args.data.callFrame.column)
line: Number(event.args.line),
column: Number(event.args.column)
});
event.args = {
data: {
callFrame: _extends({}, (_event$args = event.args) === null || _event$args === void 0 ? void 0 : _event$args.data.callFrame, {
url: sm.source,
line: sm.line,
column: sm.column
})
}
};
/**
* The name in source maps (for reasons I don't understand) is sometimes null, so OR-ing this
* to ensure a name is assigned.
* In case a name wasn't found, the URL is used
* Eg: /Users/saphal/Desktop/app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js => MessageQueue.js
* The categories can help us better visualise the profile if we modify the categories.
* We change these categories only in the root level and not deeper inside the args, just so we have our
* original categories as well as these modified categories (as the modified categories simply help with visualisation)
*/
event.name = sm.name || (event.args.data.callFrame.url ? "anonymous @ " + event.args.data.callFrame.url.split('/').pop() : event.args.data.callFrame.name);
event.cat = improveCategories(event.cat, sm.source);
event.args = _extends({}, event.args, {
url: sm.source,
line: sm.line,
column: sm.column,
params: sm.name,
allocatedCategory: event.cat,
allocatedName: event.name
});
} else {

@@ -464,0 +488,0 @@ throw new Error("Source maps could not be derived for an event at " + event.ts + " and with stackFrame ID " + event.sf);

import { DurationEvent } from '../types/EventInterfaces';
import { SourceMap } from '../types/SourceMaps';
/**
* Refer to the source maps for the bundleFileName. Throws error if args not set up in ChromeEvents
* Refer to the source maps for the bundleFileName and change the event names to derive
* from source maps which usually add more information for the user
* Throws error if args not set up in ChromeEvents
* @param {SourceMap} sourceMap

@@ -6,0 +8,0 @@ * @param {DurationEvent[]} chromeEvents

{
"version": "0.0.3",
"version": "0.0.4",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

@@ -149,2 +149,14 @@ /**

/**
* The name needs to be modified if `http://` is present as this directs us to bundle files which does not add any information for the end user
* @param name
*/
const removeLinksIfExist = (name: string): string => {
// If the name includes `http://`, we can filter the name
if (name.includes('http://')) {
name = name.substring(0, name.lastIndexOf('('));
}
return name || 'anonymous';
};
/**
* Create a Duration Event from CPUProfileChunkNodes.

@@ -158,5 +170,5 @@ * @param {CPUProfileChunkNode} node

ph: EventsPhase.DURATION_EVENTS_BEGIN,
name: node.callFrame.name,
name: removeLinksIfExist(node.callFrame.name),
cat: node.callFrame.category,
args: { data: { callFrame: node.callFrame } },
args: { ...node.callFrame },
});

@@ -193,3 +205,3 @@

const nodeId = profile.samples[i];
const timeDelta = Math.max(profile.timeDeltas[i], 1);
const timeDelta = Math.max(profile.timeDeltas[i], 0);
const node = this._nodesById.get(nodeId);

@@ -196,0 +208,0 @@ if (!node) throw new Error(`Missing node ${nodeId}`);

@@ -0,1 +1,2 @@

import path from 'path';
import { SourceMapConsumer, RawSourceMap } from 'source-map';

@@ -6,3 +7,25 @@ import { DurationEvent } from '../types/EventInterfaces';

/**
* Refer to the source maps for the bundleFileName. Throws error if args not set up in ChromeEvents
* This function is a helper to the changeNamesToSourceMaps. The category allocation logic is implemented here based on the sourcemap url (if available)
* @param defaultCategory The category the event is of by default without the use of Source maps
* @param url The URL which can be parsed to interpret the new category of the event (depends on node_modules)
*/
const improveCategories = (
defaultCategory: string,
url: string | null
): string => {
const obtainCategory = (url: string): string => {
const dirs = url
.substring(url.lastIndexOf(`${path.sep}node_modules${path.sep}`))
.split(path.sep);
return dirs.length > 2 && dirs[1] === 'node_modules'
? dirs[2]
: defaultCategory;
};
return url ? obtainCategory(url) : defaultCategory;
};
/**
* Refer to the source maps for the bundleFileName and change the event names to derive
* from source maps which usually add more information for the user
* Throws error if args not set up in ChromeEvents
* @param {SourceMap} sourceMap

@@ -33,26 +56,20 @@ * @param {DurationEvent[]} chromeEvents

const sm = consumer.originalPositionFor({
line: Number(event.args.data.callFrame.line),
column: Number(event.args.data.callFrame.column),
line: Number(event.args.line),
column: Number(event.args.column),
});
/**
* The categories can help us better visualise the profile if we modify the categories.
* We change these categories only in the root level and not deeper inside the args, just so we have our
* original categories as well as these modified categories (as the modified categories simply help with visualisation)
*/
event.cat = improveCategories(event.cat!, sm.source);
event.args = {
data: {
callFrame: {
...event.args?.data.callFrame,
url: sm.source,
line: sm.line,
column: sm.column,
},
},
...event.args,
url: sm.source,
line: sm.line,
column: sm.column,
params: sm.name,
allocatedCategory: event.cat,
allocatedName: event.name,
};
/**
* The name in source maps (for reasons I don't understand) is sometimes null, so OR-ing this
* to ensure a name is assigned.
* In case a name wasn't found, the URL is used
* Eg: /Users/saphal/Desktop/app/node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js => MessageQueue.js
*/
event.name =
sm.name ||
(event.args.data.callFrame.url
? `anonymous @ ${event.args.data.callFrame.url.split('/').pop()}`
: event.args.data.callFrame.name);
} else {

@@ -59,0 +76,0 @@ throw new Error(

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc