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

babel-timing

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-timing - npm Package Compare versions

Comparing version 0.6.1 to 0.7.0

src/render/aggregateByPlugins/index.js

10

CHANGELOG.md
# Changelog
## 0.7.0
### Breaking Changes
- Change `ResultList` shape
### New Features
- Add `aggregateBy` option
## 0.6.1

@@ -4,0 +14,0 @@

10

cli.js

@@ -42,2 +42,6 @@ #!/usr/bin/env node

.option(
'--aggregate-by <files | plugins>',
'aggregate output data by files or plugins'
)
.option(
'--pagination-size <number-of-entries>',

@@ -50,3 +54,6 @@ 'number of entries displayed per page'

const results = JSON.parse(fs.readFileSync(program.readResults));
return render(results, ({output, outputPath, paginationSize} = program));
return render(
results,
({output, outputPath, aggregateBy, paginationSize} = program)
);
}

@@ -66,4 +73,5 @@

outputPath,
aggregateBy,
paginationSize,
} = program)
);

2

package.json
{
"name": "babel-timing",
"version": "0.6.1",
"version": "0.7.0",
"description": "Measure Babel compilation time",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -207,2 +207,8 @@ # Babel timing

#### `aggregateBy` / `--aggregate-by`
Type: `string`<br />
Default: `'files'`
Output results aggregated by `files` or `plugins`.
## How it works

@@ -214,3 +220,3 @@

**Compilation info** are extracted into the following data **structure**:
**Compilation info** are by default extracted into the following data **structure**:

@@ -220,7 +226,7 @@ ```typescript

name: string;
totalTime: number;
time: number;
plugins: {
plugin: string;
name: string;
time: number;
timePerVisit: number;
time: number;
visits: number;

@@ -227,0 +233,0 @@ }[];

@@ -11,3 +11,3 @@ var differ = require('ansi-diff-stream');

['File', entry => entry.name],
['Total time(ms)', entry => entry.totalTime.toFixed(3)],
['Total time(ms)', entry => entry.time.toFixed(3)],
],

@@ -19,3 +19,3 @@ selectable: true,

output.unmount();
renderPluginList({results, resultIndex: selected, diff, paginationSize});
renderFileDetails({results, resultIndex: selected, diff, paginationSize});
},

@@ -30,3 +30,3 @@ onSelectedCommandInfo: 'show file detail',

function renderPluginList({results, resultIndex, diff, paginationSize} = {}) {
function renderFileDetails({results, resultIndex, diff, paginationSize} = {}) {
const fileResult = results[resultIndex];

@@ -37,3 +37,3 @@ const output = new Table({

entriesMap: [
['pluginAlias', entry => entry.plugin],
['pluginAlias', entry => entry.name],
['time(ms)', entry => entry.time.toFixed(3)],

@@ -56,3 +56,63 @@ ['visits', entry => entry.visits],

function renderPluginList({results, selected = 0, diff, paginationSize} = {}) {
const output = new Table({
title: 'Babel timing - plugins called',
entries: results,
entriesMap: [
['Plugin', entry => entry.name],
['Total time(ms)', entry => entry.time.toFixed(3)],
],
selectable: true,
selected,
onSelected: selected => {
diff.clear();
output.unmount();
renderPluginDetails({
results,
resultIndex: selected,
diff,
paginationSize,
});
},
onSelectedCommandInfo: 'show plugin detail',
paginationSize,
onRender: output => {
diff.write(output);
},
});
}
function renderPluginDetails({
results,
resultIndex,
diff,
paginationSize,
} = {}) {
const pluginResult = results[resultIndex];
const output = new Table({
title: `Babel timing - info for plugin: ${pluginResult.name}`,
entries: pluginResult.files,
entriesMap: [
['file', entry => entry.name],
['time(ms)', entry => entry.time.toFixed(3)],
['visits', entry => entry.visits],
['time/visit(ms)', entry => entry.timePerVisit.toFixed(3)],
],
onEscape: () => {
diff.clear();
output.unmount();
renderPluginList({results, selected: resultIndex, diff, paginationSize});
},
onEscapeCommandInfo: 'back to results list',
paginationSize,
onRender: output => {
diff.write(output);
},
});
}
function renderer(results = [], {paginationSize} = {}) {
// Duck type results to tell if data is aggregated by files or plugins.
// @TODO Find a better way to adjust renderer on data type
isFileList = results[0].hasOwnProperty('plugins');
enableKeyPressEvent();

@@ -64,3 +124,4 @@

renderFileList({
const renderer = isFileList ? renderFileList : renderPluginList;
renderer({
results,

@@ -67,0 +128,0 @@ diff,

const path = require('path');
const fs = require('fs');
const cliRenderer = require('./cliRenderer');
const aggregateByPlugins = require('./aggregateByPlugins');
const joinSamePackageResults = require('./joinSamePackageResults');

@@ -13,2 +14,3 @@ const {sortByProperty} = require('../utils');

outputPath = './babel-timing-results.json',
aggregateBy = 'files',
paginationSize,

@@ -20,4 +22,9 @@ } = {}

}
results = results.sort(sortByProperty('totalTime'));
if (aggregateBy === 'plugins') {
results = aggregateByPlugins(results);
}
results = results.sort(sortByProperty('time'));
switch (output) {

@@ -24,0 +31,0 @@ case 'return': {

@@ -18,3 +18,3 @@ const mergeWith = require('lodash.mergewith');

if (key === 'plugins') {
return Timer.mergeResults(objValue, srcValue);
return Timer.mergePluginsProp(objValue, srcValue);
}

@@ -21,0 +21,0 @@ if (typeof objValue === 'string') {

@@ -22,2 +22,3 @@ const fs = require('fs');

outputPath,
aggregateBy,
paginationSize,

@@ -78,5 +79,11 @@ verbose = false,

return render(results, {expandPackages, output, outputPath, paginationSize});
return render(results, {
expandPackages,
output,
outputPath,
aggregateBy,
paginationSize,
});
}
module.exports = babelTiming;

@@ -7,7 +7,7 @@ const mergeWith = require('lodash.mergewith');

// name: string,
// totalTime: number,
// time: number,
// plugins: {
// plugin: string,
// name: string,
// time: number,
// timePerVisit: number,
// time: number,
// visits: number,

@@ -60,3 +60,3 @@ // }[]

return {
plugin: pluginAlias,
name: pluginAlias,
...entry,

@@ -70,3 +70,3 @@ };

name: this._file,
totalTime: Timer.getTotalTime(plugins),
time: Timer.getTotalTime(plugins),
plugins,

@@ -93,3 +93,3 @@ };

static mergeResults(...resultArrays) {
static mergePluginsProp(...pluginsArrays) {
function mergeStrategy(objValue, srcValue) {

@@ -104,11 +104,11 @@ if (typeof objValue === 'string') {

const results = resultArrays.reduce(flatten, []);
const results = pluginsArrays.reduce(flatten, []);
return (
results
// Get list of plugin names
.map(entry => entry.plugin)
.map(entry => entry.name)
.filter(onlyUnique)
// Merge data entries with same plugin name
.map(pluginName => {
const samePlugin = results.filter(data => data.plugin === pluginName);
const samePlugin = results.filter(data => data.name === pluginName);
return mergeWith(...samePlugin, mergeStrategy);

@@ -115,0 +115,0 @@ })

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc