@bundle-stats/utils
Advanced tools
Comparing version 1.15.1 to 2.0.0-beta.1
@@ -13,2 +13,15 @@ "use strict"; | ||
var _fileTypes = require("./file-types"); | ||
Object.keys(_fileTypes).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _fileTypes[key]; | ||
} | ||
}); | ||
}); | ||
var _metrics = require("./metrics"); | ||
@@ -28,5 +41,5 @@ | ||
exports.PACKAGES_SEPARATOR = PACKAGES_SEPARATOR; | ||
const SOURCE_PATH_WEBPACK_STATS = 'webpack.stats'; | ||
const SOURCE_PATH_WEBPACK_STATS = 'webpack'; | ||
exports.SOURCE_PATH_WEBPACK_STATS = SOURCE_PATH_WEBPACK_STATS; | ||
const SOURCE_PATHS = [SOURCE_PATH_WEBPACK_STATS]; | ||
exports.SOURCE_PATHS = SOURCE_PATHS; |
@@ -45,47 +45,17 @@ "use strict"; | ||
webpack: { | ||
assets: { | ||
totalSizeByTypeALL: { | ||
label: 'Total Bundle Size', | ||
description: 'Sum of all assets.', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeJS: { | ||
label: 'JS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeCSS: { | ||
label: 'CSS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeIMG: { | ||
label: 'IMG', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeMEDIA: { | ||
label: 'Media', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeFONT: { | ||
label: 'Fonts', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeHTML: { | ||
label: 'HTML', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeOTHER: { | ||
label: 'Other', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeJS: { | ||
label: 'Initial JS Size', | ||
description: 'Sum of all JS assets that are loaded initially(eg: `vendor.js`, `app.js`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeCSS: { | ||
label: 'Initial CSS Size', | ||
description: 'Sum of all CSS assets that are loaded initially(eg: `vendor.css`, `app.css`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
} | ||
totalSizeByTypeALL: { | ||
label: 'Total Bundle Size', | ||
description: 'Sum of all assets.', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeJS: { | ||
label: 'Initial JS Size', | ||
description: 'Sum of all JS assets that are loaded initially(eg: `vendor.js`, `app.js`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeCSS: { | ||
label: 'Initial CSS Size', | ||
description: 'Sum of all CSS assets that are loaded initially(eg: `vendor.css`, `app.css`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
cacheInvalidation: { | ||
@@ -126,2 +96,32 @@ label: 'Cache Invalidation', | ||
biggerIsBetter: false | ||
}, | ||
sizes: { | ||
totalSizeByTypeJS: { | ||
label: 'JS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeCSS: { | ||
label: 'CSS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeIMG: { | ||
label: 'IMG', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeMEDIA: { | ||
label: 'Media', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeFONT: { | ||
label: 'Fonts', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeHTML: { | ||
label: 'HTML', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeOTHER: { | ||
label: 'Other', | ||
type: METRIC_TYPE_FILE_SIZE | ||
} | ||
} | ||
@@ -128,0 +128,0 @@ }, |
@@ -7,14 +7,2 @@ "use strict"; | ||
var _assets = require("./assets"); | ||
Object.keys(_assets).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _assets[key]; | ||
} | ||
}); | ||
}); | ||
var _browsertime = require("./browsertime"); | ||
@@ -68,14 +56,2 @@ | ||
var _modules = require("./modules"); | ||
Object.keys(_modules).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _modules[key]; | ||
} | ||
}); | ||
}); | ||
var _metrics = require("./metrics"); | ||
@@ -93,26 +69,2 @@ | ||
var _stats = require("./stats"); | ||
Object.keys(_stats).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _stats[key]; | ||
} | ||
}); | ||
}); | ||
var _transforms = require("./transforms"); | ||
Object.keys(_transforms).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _transforms[key]; | ||
} | ||
}); | ||
}); | ||
var _utils = require("./utils"); | ||
@@ -119,0 +71,0 @@ |
"use strict"; | ||
require("core-js/modules/es.array.iterator"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,8 +12,4 @@ value: true | ||
var _omit2 = _interopRequireDefault(require("lodash/omit")); | ||
var _merge2 = _interopRequireDefault(require("lodash/merge")); | ||
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty")); | ||
var _get2 = _interopRequireDefault(require("lodash/get")); | ||
@@ -21,17 +19,16 @@ | ||
var _create = require("../stats/create"); | ||
var _createSummary = require("./create-summary"); | ||
var _createSummary = require("../stats/create-summary"); | ||
var webpack = _interopRequireWildcard(require("../webpack")); | ||
var _transforms = require("../transforms"); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const SOURCE_IDS = _config.SOURCE_PATHS.map(id => id.split('.')[0]); | ||
const SOURCE_FNS = { | ||
webpack | ||
}; | ||
const GENERIC_PROPS = ['meta', 'warnings', 'metrics']; | ||
/* | ||
@@ -41,36 +38,26 @@ * Create job from stats | ||
const createJob = (source, baseline) => _config.SOURCE_PATHS.reduce((agg, sourcePath) => { | ||
const rawData = (0, _get2.default)(source, sourcePath); | ||
const createJob = (source, baseline) => { | ||
const data = _config.SOURCE_PATHS.reduce((agg, rawDataPath) => { | ||
const rawData = (0, _get2.default)(source, rawDataPath); | ||
if (!rawData) { | ||
return agg; | ||
} | ||
if (!rawData) { | ||
return agg; | ||
} | ||
const sourceModule = SOURCE_FNS[sourcePath]; | ||
return (0, _merge2.default)({}, agg, { | ||
rawData: (0, _set2.default)({}, rawDataPath, rawData) | ||
}); | ||
}, (0, _omit2.default)(source, SOURCE_IDS)); | ||
if (!sourceModule) { | ||
return agg; | ||
} | ||
const stats = (0, _create.createStats)(baseline && baseline.rawData, data.rawData); | ||
const summary = (0, _createSummary.createStatsSummary)(baseline && baseline.stats, stats); | ||
const { | ||
meta | ||
} = (0, _transforms.metaWebpackTransform)((0, _get2.default)(data.rawData, _config.SOURCE_PATH_WEBPACK_STATS)); | ||
const { | ||
warnings: duplicatePackagesWarnings | ||
} = (0, _transforms.duplicatePackagesBundleTransform)((0, _transforms.packagesModulesBundleTransform)(_objectSpread({}, (0, _transforms.modulesWebpackTransform)((0, _get2.default)(data.rawData, _config.SOURCE_PATH_WEBPACK_STATS))))); | ||
const extractedData = sourceModule.extract(rawData, baseline); | ||
const summary = (0, _createSummary.createSummary)(SOURCE_FNS[sourcePath].SUMMARY_METRIC_PATHS, (0, _get2.default)(baseline, `metrics.${sourcePath}`, {}), (0, _get2.default)(extractedData, 'metrics', {})); | ||
return (0, _merge2.default)({}, agg, { | ||
rawData: (0, _set2.default)({}, sourcePath, rawData) | ||
}, { | ||
summary: (0, _set2.default)({}, sourcePath, summary) | ||
}, ...GENERIC_PROPS.map(genericPropName => ({ | ||
[genericPropName]: (0, _set2.default)({}, sourcePath, extractedData[genericPropName]) | ||
}))); | ||
}, {}); | ||
const warnings = _objectSpread({}, duplicatePackagesWarnings); | ||
return _objectSpread({}, data, { | ||
meta, | ||
stats, | ||
summary | ||
}, (0, _isEmpty2.default)(warnings) ? {} : { | ||
warnings | ||
}); | ||
}; | ||
exports.createJob = createJob; |
@@ -7,14 +7,2 @@ "use strict"; | ||
var _getAssetMetricStates = require("./get-asset-metric-states"); | ||
Object.keys(_getAssetMetricStates).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _getAssetMetricStates[key]; | ||
} | ||
}); | ||
}); | ||
var _getMetricChanged = require("./get-metric-changed"); | ||
@@ -21,0 +9,0 @@ |
"use strict"; | ||
require("core-js/modules/es.array.iterator"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createReport = exports.getModulesReport = exports.createRuns = exports.addMetricsData = void 0; | ||
exports.createReport = exports.getModulesReport = exports.addMetricsData = void 0; | ||
var _uniq2 = _interopRequireDefault(require("lodash/uniq")); | ||
var _pick2 = _interopRequireDefault(require("lodash/pick")); | ||
var _map2 = _interopRequireDefault(require("lodash/map")); | ||
@@ -20,8 +24,6 @@ | ||
var webpack = _interopRequireWildcard(require("../webpack")); | ||
var _metrics = require("../metrics"); | ||
var _getStatsByMetrics = require("../stats/get-stats-by-metrics"); | ||
var _transforms = require("../transforms"); | ||
var _delta = require("./delta"); | ||
@@ -31,2 +33,6 @@ | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -44,5 +50,3 @@ | ||
const SIZE_METRICS = ['webpack.assets.totalSizeByTypeJS', 'webpack.assets.totalSizeByTypeCSS', 'webpack.assets.totalSizeByTypeIMG', 'webpack.assets.totalSizeByTypeMEDIA', 'webpack.assets.totalSizeByTypeFONT', 'webpack.assets.totalSizeByTypeHTML', 'webpack.assets.totalSizeByTypeOTHER', 'webpack.assets.totalSizeByTypeALL', 'webpack.assets.totalInitialSizeCSS', 'webpack.assets.totalInitialSizeJS']; | ||
const addMetricsData = (entries, metricType) => entries.map(entry => { | ||
const addMetricsData = (entries, metricType, metricPrefix = '') => entries.map(entry => { | ||
const { | ||
@@ -55,3 +59,3 @@ runs | ||
formatter | ||
} = (0, _metrics.getMetricType)(entry.key, metricType); | ||
} = (0, _metrics.getMetricType)(metricPrefix ? [metricPrefix, entry.key].join('.') : entry.key, metricType); | ||
return _objectSpread({}, entry, { | ||
@@ -65,3 +69,3 @@ // Metric props | ||
runs: runs.map((run, index) => { | ||
if (!run || typeof run.value === 'undefined') { | ||
if (!run || typeof run.value === 'undefined' || run.value === null) { | ||
return null; | ||
@@ -90,32 +94,20 @@ } | ||
const createRuns = jobs => jobs.map(({ | ||
meta, | ||
internalBuildNumber, | ||
stats, | ||
rawData | ||
}) => { | ||
const webpackStats = (0, _get2.default)(rawData, _config.SOURCE_PATH_WEBPACK_STATS); | ||
const { | ||
modules | ||
} = (0, _transforms.modulesWebpackTransform)(webpackStats); | ||
return _objectSpread({ | ||
meta: _objectSpread({}, meta, { | ||
internalBuildNumber | ||
}), | ||
sizes: (0, _getStatsByMetrics.getStatsByMetrics)(stats, SIZE_METRICS) | ||
}, (0, _transforms.assetsWebpackTransform)(webpackStats), { | ||
modules | ||
}, (0, _transforms.packagesModulesBundleTransform)({ | ||
modules | ||
})); | ||
}); | ||
const getWebpackSizesMetrics = job => { | ||
const metrics = (0, _get2.default)(job, 'metrics.webpack.sizes', {}); | ||
return Object.entries(metrics).reduce((agg, [key, value]) => _objectSpread({}, agg, { | ||
[`webpack.sizes.${key}`]: value | ||
}), {}); | ||
}; | ||
exports.createRuns = createRuns; | ||
const getWebpackStatsMetrics = job => { | ||
const metrics = (0, _pick2.default)((0, _get2.default)(job, 'metrics.webpack', {}), webpack.SUMMARY_METRIC_PATHS); | ||
return Object.entries(metrics).reduce((agg, [key, value]) => _objectSpread({}, agg, { | ||
[`webpack.${key}`]: value | ||
}), {}); | ||
}; | ||
const getModulesReport = runs => (0, _map2.default)((0, _uniq2.default)((0, _flatMap2.default)(runs, ({ | ||
modules | ||
}) => Object.keys(modules))), chunkId => ({ | ||
const getModulesReport = jobs => (0, _map2.default)((0, _uniq2.default)((0, _flatMap2.default)(jobs, job => Object.keys((0, _get2.default)(job, 'metrics.webpack.modules', {})))), chunkId => ({ | ||
chunkId, | ||
chunkNames: (0, _uniq2.default)((0, _flatMap2.default)(runs, run => (0, _get2.default)(run, ['modules', chunkId, 'chunkNames']))), | ||
modules: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, run => (0, _get2.default)(run, ['modules', chunkId, 'modules']))), _config.METRIC_TYPE_FILE_SIZE) | ||
chunkNames: (0, _uniq2.default)((0, _flatMap2.default)(jobs, job => (0, _get2.default)(job, ['metrics', 'webpack', 'modules', chunkId, 'chunkNames']))), | ||
modules: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, job => (0, _get2.default)(job, ['metrics', 'webpack', 'modules', chunkId, 'modules']))), _config.METRIC_TYPE_FILE_SIZE) | ||
})); | ||
@@ -126,18 +118,18 @@ | ||
const createReport = jobs => { | ||
const runs = createRuns(jobs); | ||
const { | ||
warnings: duplicatePackagesWarnings | ||
} = (0, _transforms.duplicatePackagesBundleTransform)((0, _get2.default)(runs, '[0]', {})); | ||
const warnings = _objectSpread({}, duplicatePackagesWarnings); | ||
const warnings = (0, _get2.default)(jobs, '[0].warnings'); | ||
return _objectSpread({ | ||
runs: (0, _map2.default)(runs, 'meta') | ||
runs: jobs.map(({ | ||
internalBuildNumber, | ||
meta | ||
}) => _objectSpread({}, meta, { | ||
internalBuildNumber | ||
})) | ||
}, !(0, _isEmpty2.default)(warnings) ? { | ||
warnings | ||
} : {}, { | ||
sizes: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, 'sizes'))), | ||
assets: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, 'assets')), _config.METRIC_TYPE_FILE_SIZE), | ||
modules: getModulesReport(runs), | ||
packages: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, 'packages')), _config.METRIC_TYPE_FILE_SIZE) | ||
stats: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, getWebpackStatsMetrics))), | ||
sizes: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, getWebpackSizesMetrics))), | ||
assets: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, 'metrics.webpack.assets')), _config.METRIC_TYPE_FILE_SIZE), | ||
modules: getModulesReport(jobs), | ||
packages: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, 'metrics.webpack.packages')), _config.METRIC_TYPE_FILE_SIZE) | ||
}); | ||
@@ -144,0 +136,0 @@ }; |
@@ -43,14 +43,2 @@ "use strict"; | ||
var _extractData = require("./extract-data"); | ||
Object.keys(_extractData).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _extractData[key]; | ||
} | ||
}); | ||
}); | ||
var _format = require("./format"); | ||
@@ -57,0 +45,0 @@ |
@@ -13,2 +13,15 @@ "use strict"; | ||
var _fileTypes = require("./file-types"); | ||
Object.keys(_fileTypes).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _fileTypes[key]; | ||
} | ||
}); | ||
}); | ||
var _metrics = require("./metrics"); | ||
@@ -28,5 +41,5 @@ | ||
exports.PACKAGES_SEPARATOR = PACKAGES_SEPARATOR; | ||
const SOURCE_PATH_WEBPACK_STATS = 'webpack.stats'; | ||
const SOURCE_PATH_WEBPACK_STATS = 'webpack'; | ||
exports.SOURCE_PATH_WEBPACK_STATS = SOURCE_PATH_WEBPACK_STATS; | ||
const SOURCE_PATHS = [SOURCE_PATH_WEBPACK_STATS]; | ||
exports.SOURCE_PATHS = SOURCE_PATHS; |
@@ -45,47 +45,17 @@ "use strict"; | ||
webpack: { | ||
assets: { | ||
totalSizeByTypeALL: { | ||
label: 'Total Bundle Size', | ||
description: 'Sum of all assets.', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeJS: { | ||
label: 'JS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeCSS: { | ||
label: 'CSS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeIMG: { | ||
label: 'IMG', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeMEDIA: { | ||
label: 'Media', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeFONT: { | ||
label: 'Fonts', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeHTML: { | ||
label: 'HTML', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeOTHER: { | ||
label: 'Other', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeJS: { | ||
label: 'Initial JS Size', | ||
description: 'Sum of all JS assets that are loaded initially(eg: `vendor.js`, `app.js`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeCSS: { | ||
label: 'Initial CSS Size', | ||
description: 'Sum of all CSS assets that are loaded initially(eg: `vendor.css`, `app.css`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
} | ||
totalSizeByTypeALL: { | ||
label: 'Total Bundle Size', | ||
description: 'Sum of all assets.', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeJS: { | ||
label: 'Initial JS Size', | ||
description: 'Sum of all JS assets that are loaded initially(eg: `vendor.js`, `app.js`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalInitialSizeCSS: { | ||
label: 'Initial CSS Size', | ||
description: 'Sum of all CSS assets that are loaded initially(eg: `vendor.css`, `app.css`).', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
cacheInvalidation: { | ||
@@ -126,2 +96,32 @@ label: 'Cache Invalidation', | ||
biggerIsBetter: false | ||
}, | ||
sizes: { | ||
totalSizeByTypeJS: { | ||
label: 'JS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeCSS: { | ||
label: 'CSS', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeIMG: { | ||
label: 'IMG', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeMEDIA: { | ||
label: 'Media', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeFONT: { | ||
label: 'Fonts', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeHTML: { | ||
label: 'HTML', | ||
type: METRIC_TYPE_FILE_SIZE | ||
}, | ||
totalSizeByTypeOTHER: { | ||
label: 'Other', | ||
type: METRIC_TYPE_FILE_SIZE | ||
} | ||
} | ||
@@ -128,0 +128,0 @@ }, |
@@ -7,14 +7,2 @@ "use strict"; | ||
var _assets = require("./assets"); | ||
Object.keys(_assets).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _assets[key]; | ||
} | ||
}); | ||
}); | ||
var _browsertime = require("./browsertime"); | ||
@@ -68,14 +56,2 @@ | ||
var _modules = require("./modules"); | ||
Object.keys(_modules).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _modules[key]; | ||
} | ||
}); | ||
}); | ||
var _metrics = require("./metrics"); | ||
@@ -93,26 +69,2 @@ | ||
var _stats = require("./stats"); | ||
Object.keys(_stats).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _stats[key]; | ||
} | ||
}); | ||
}); | ||
var _transforms = require("./transforms"); | ||
Object.keys(_transforms).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _transforms[key]; | ||
} | ||
}); | ||
}); | ||
var _utils = require("./utils"); | ||
@@ -119,0 +71,0 @@ |
"use strict"; | ||
require("core-js/modules/es.array.iterator"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -10,8 +12,4 @@ value: true | ||
var _omit2 = _interopRequireDefault(require("lodash/omit")); | ||
var _merge2 = _interopRequireDefault(require("lodash/merge")); | ||
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty")); | ||
var _get2 = _interopRequireDefault(require("lodash/get")); | ||
@@ -21,17 +19,16 @@ | ||
var _create = require("../stats/create"); | ||
var _createSummary = require("./create-summary"); | ||
var _createSummary = require("../stats/create-summary"); | ||
var webpack = _interopRequireWildcard(require("../webpack")); | ||
var _transforms = require("../transforms"); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
const SOURCE_IDS = _config.SOURCE_PATHS.map(id => id.split('.')[0]); | ||
const SOURCE_FNS = { | ||
webpack | ||
}; | ||
const GENERIC_PROPS = ['meta', 'warnings', 'metrics']; | ||
/* | ||
@@ -41,36 +38,26 @@ * Create job from stats | ||
const createJob = (source, baseline) => _config.SOURCE_PATHS.reduce((agg, sourcePath) => { | ||
const rawData = (0, _get2.default)(source, sourcePath); | ||
const createJob = (source, baseline) => { | ||
const data = _config.SOURCE_PATHS.reduce((agg, rawDataPath) => { | ||
const rawData = (0, _get2.default)(source, rawDataPath); | ||
if (!rawData) { | ||
return agg; | ||
} | ||
if (!rawData) { | ||
return agg; | ||
} | ||
const sourceModule = SOURCE_FNS[sourcePath]; | ||
return (0, _merge2.default)({}, agg, { | ||
rawData: (0, _set2.default)({}, rawDataPath, rawData) | ||
}); | ||
}, (0, _omit2.default)(source, SOURCE_IDS)); | ||
if (!sourceModule) { | ||
return agg; | ||
} | ||
const stats = (0, _create.createStats)(baseline && baseline.rawData, data.rawData); | ||
const summary = (0, _createSummary.createStatsSummary)(baseline && baseline.stats, stats); | ||
const { | ||
meta | ||
} = (0, _transforms.metaWebpackTransform)((0, _get2.default)(data.rawData, _config.SOURCE_PATH_WEBPACK_STATS)); | ||
const { | ||
warnings: duplicatePackagesWarnings | ||
} = (0, _transforms.duplicatePackagesBundleTransform)((0, _transforms.packagesModulesBundleTransform)(_objectSpread({}, (0, _transforms.modulesWebpackTransform)((0, _get2.default)(data.rawData, _config.SOURCE_PATH_WEBPACK_STATS))))); | ||
const extractedData = sourceModule.extract(rawData, baseline); | ||
const summary = (0, _createSummary.createSummary)(SOURCE_FNS[sourcePath].SUMMARY_METRIC_PATHS, (0, _get2.default)(baseline, `metrics.${sourcePath}`, {}), (0, _get2.default)(extractedData, 'metrics', {})); | ||
return (0, _merge2.default)({}, agg, { | ||
rawData: (0, _set2.default)({}, sourcePath, rawData) | ||
}, { | ||
summary: (0, _set2.default)({}, sourcePath, summary) | ||
}, ...GENERIC_PROPS.map(genericPropName => ({ | ||
[genericPropName]: (0, _set2.default)({}, sourcePath, extractedData[genericPropName]) | ||
}))); | ||
}, {}); | ||
const warnings = _objectSpread({}, duplicatePackagesWarnings); | ||
return _objectSpread({}, data, { | ||
meta, | ||
stats, | ||
summary | ||
}, (0, _isEmpty2.default)(warnings) ? {} : { | ||
warnings | ||
}); | ||
}; | ||
exports.createJob = createJob; |
@@ -7,14 +7,2 @@ "use strict"; | ||
var _getAssetMetricStates = require("./get-asset-metric-states"); | ||
Object.keys(_getAssetMetricStates).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _getAssetMetricStates[key]; | ||
} | ||
}); | ||
}); | ||
var _getMetricChanged = require("./get-metric-changed"); | ||
@@ -21,0 +9,0 @@ |
"use strict"; | ||
require("core-js/modules/es.array.iterator"); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createReport = exports.getModulesReport = exports.createRuns = exports.addMetricsData = void 0; | ||
exports.createReport = exports.getModulesReport = exports.addMetricsData = void 0; | ||
var _uniq2 = _interopRequireDefault(require("lodash/uniq")); | ||
var _pick2 = _interopRequireDefault(require("lodash/pick")); | ||
var _map2 = _interopRequireDefault(require("lodash/map")); | ||
@@ -20,8 +24,6 @@ | ||
var webpack = _interopRequireWildcard(require("../webpack")); | ||
var _metrics = require("../metrics"); | ||
var _getStatsByMetrics = require("../stats/get-stats-by-metrics"); | ||
var _transforms = require("../transforms"); | ||
var _delta = require("./delta"); | ||
@@ -31,2 +33,6 @@ | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -44,5 +50,3 @@ | ||
const SIZE_METRICS = ['webpack.assets.totalSizeByTypeJS', 'webpack.assets.totalSizeByTypeCSS', 'webpack.assets.totalSizeByTypeIMG', 'webpack.assets.totalSizeByTypeMEDIA', 'webpack.assets.totalSizeByTypeFONT', 'webpack.assets.totalSizeByTypeHTML', 'webpack.assets.totalSizeByTypeOTHER', 'webpack.assets.totalSizeByTypeALL', 'webpack.assets.totalInitialSizeCSS', 'webpack.assets.totalInitialSizeJS']; | ||
const addMetricsData = (entries, metricType) => entries.map(entry => { | ||
const addMetricsData = (entries, metricType, metricPrefix = '') => entries.map(entry => { | ||
const { | ||
@@ -55,3 +59,3 @@ runs | ||
formatter | ||
} = (0, _metrics.getMetricType)(entry.key, metricType); | ||
} = (0, _metrics.getMetricType)(metricPrefix ? [metricPrefix, entry.key].join('.') : entry.key, metricType); | ||
return _objectSpread({}, entry, { | ||
@@ -65,3 +69,3 @@ // Metric props | ||
runs: runs.map((run, index) => { | ||
if (!run || typeof run.value === 'undefined') { | ||
if (!run || typeof run.value === 'undefined' || run.value === null) { | ||
return null; | ||
@@ -90,32 +94,20 @@ } | ||
const createRuns = jobs => jobs.map(({ | ||
meta, | ||
internalBuildNumber, | ||
stats, | ||
rawData | ||
}) => { | ||
const webpackStats = (0, _get2.default)(rawData, _config.SOURCE_PATH_WEBPACK_STATS); | ||
const { | ||
modules | ||
} = (0, _transforms.modulesWebpackTransform)(webpackStats); | ||
return _objectSpread({ | ||
meta: _objectSpread({}, meta, { | ||
internalBuildNumber | ||
}), | ||
sizes: (0, _getStatsByMetrics.getStatsByMetrics)(stats, SIZE_METRICS) | ||
}, (0, _transforms.assetsWebpackTransform)(webpackStats), { | ||
modules | ||
}, (0, _transforms.packagesModulesBundleTransform)({ | ||
modules | ||
})); | ||
}); | ||
const getWebpackSizesMetrics = job => { | ||
const metrics = (0, _get2.default)(job, 'metrics.webpack.sizes', {}); | ||
return Object.entries(metrics).reduce((agg, [key, value]) => _objectSpread({}, agg, { | ||
[`webpack.sizes.${key}`]: value | ||
}), {}); | ||
}; | ||
exports.createRuns = createRuns; | ||
const getWebpackStatsMetrics = job => { | ||
const metrics = (0, _pick2.default)((0, _get2.default)(job, 'metrics.webpack', {}), webpack.SUMMARY_METRIC_PATHS); | ||
return Object.entries(metrics).reduce((agg, [key, value]) => _objectSpread({}, agg, { | ||
[`webpack.${key}`]: value | ||
}), {}); | ||
}; | ||
const getModulesReport = runs => (0, _map2.default)((0, _uniq2.default)((0, _flatMap2.default)(runs, ({ | ||
modules | ||
}) => Object.keys(modules))), chunkId => ({ | ||
const getModulesReport = jobs => (0, _map2.default)((0, _uniq2.default)((0, _flatMap2.default)(jobs, job => Object.keys((0, _get2.default)(job, 'metrics.webpack.modules', {})))), chunkId => ({ | ||
chunkId, | ||
chunkNames: (0, _uniq2.default)((0, _flatMap2.default)(runs, run => (0, _get2.default)(run, ['modules', chunkId, 'chunkNames']))), | ||
modules: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, run => (0, _get2.default)(run, ['modules', chunkId, 'modules']))), _config.METRIC_TYPE_FILE_SIZE) | ||
chunkNames: (0, _uniq2.default)((0, _flatMap2.default)(jobs, job => (0, _get2.default)(job, ['metrics', 'webpack', 'modules', chunkId, 'chunkNames']))), | ||
modules: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, job => (0, _get2.default)(job, ['metrics', 'webpack', 'modules', chunkId, 'modules']))), _config.METRIC_TYPE_FILE_SIZE) | ||
})); | ||
@@ -126,18 +118,18 @@ | ||
const createReport = jobs => { | ||
const runs = createRuns(jobs); | ||
const { | ||
warnings: duplicatePackagesWarnings | ||
} = (0, _transforms.duplicatePackagesBundleTransform)((0, _get2.default)(runs, '[0]', {})); | ||
const warnings = _objectSpread({}, duplicatePackagesWarnings); | ||
const warnings = (0, _get2.default)(jobs, '[0].warnings'); | ||
return _objectSpread({ | ||
runs: (0, _map2.default)(runs, 'meta') | ||
runs: jobs.map(({ | ||
internalBuildNumber, | ||
meta | ||
}) => _objectSpread({}, meta, { | ||
internalBuildNumber | ||
})) | ||
}, !(0, _isEmpty2.default)(warnings) ? { | ||
warnings | ||
} : {}, { | ||
sizes: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, 'sizes'))), | ||
assets: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, 'assets')), _config.METRIC_TYPE_FILE_SIZE), | ||
modules: getModulesReport(runs), | ||
packages: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(runs, 'packages')), _config.METRIC_TYPE_FILE_SIZE) | ||
stats: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, getWebpackStatsMetrics))), | ||
sizes: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, getWebpackSizesMetrics))), | ||
assets: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, 'metrics.webpack.assets')), _config.METRIC_TYPE_FILE_SIZE), | ||
modules: getModulesReport(jobs), | ||
packages: addMetricsData((0, _metrics.mergeRunsById)((0, _map2.default)(jobs, 'metrics.webpack.packages')), _config.METRIC_TYPE_FILE_SIZE) | ||
}); | ||
@@ -144,0 +136,0 @@ }; |
@@ -43,14 +43,2 @@ "use strict"; | ||
var _extractData = require("./extract-data"); | ||
Object.keys(_extractData).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function () { | ||
return _extractData[key]; | ||
} | ||
}); | ||
}); | ||
var _format = require("./format"); | ||
@@ -57,0 +45,0 @@ |
{ | ||
"name": "@bundle-stats/utils", | ||
"version": "1.15.1", | ||
"version": "2.0.0-beta.1", | ||
"description": "BundleStats utils", | ||
@@ -18,3 +18,2 @@ "main": "lib/index.js", | ||
"lint": "eslint . --cache --cache-location ./node_modules/.eslintcache", | ||
"prepublishOnly": "npm run lint && npm test && npm run build", | ||
"test": "jest src" | ||
@@ -59,3 +58,4 @@ }, | ||
"lodash": "^4.17.11" | ||
} | ||
}, | ||
"gitHead": "f09d6d46d53efceeac4d4dbfd5285fc23e49cb56" | ||
} |
@@ -0,1 +1,2 @@ | ||
export * from './file-types'; | ||
export * from './metrics'; | ||
@@ -5,3 +6,3 @@ | ||
export const SOURCE_PATH_WEBPACK_STATS = 'webpack.stats'; | ||
export const SOURCE_PATH_WEBPACK_STATS = 'webpack'; | ||
export const SOURCE_PATHS = [SOURCE_PATH_WEBPACK_STATS]; |
@@ -39,47 +39,17 @@ import { | ||
webpack: { | ||
assets: { | ||
totalSizeByTypeALL: { | ||
label: 'Total Bundle Size', | ||
description: 'Sum of all assets.', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeJS: { | ||
label: 'JS', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeCSS: { | ||
label: 'CSS', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeIMG: { | ||
label: 'IMG', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeMEDIA: { | ||
label: 'Media', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeFONT: { | ||
label: 'Fonts', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeHTML: { | ||
label: 'HTML', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeOTHER: { | ||
label: 'Other', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalInitialSizeJS: { | ||
label: 'Initial JS Size', | ||
description: 'Sum of all JS assets that are loaded initially(eg: `vendor.js`, `app.js`).', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalInitialSizeCSS: { | ||
label: 'Initial CSS Size', | ||
description: 'Sum of all CSS assets that are loaded initially(eg: `vendor.css`, `app.css`).', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeALL: { | ||
label: 'Total Bundle Size', | ||
description: 'Sum of all assets.', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalInitialSizeJS: { | ||
label: 'Initial JS Size', | ||
description: 'Sum of all JS assets that are loaded initially(eg: `vendor.js`, `app.js`).', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalInitialSizeCSS: { | ||
label: 'Initial CSS Size', | ||
description: 'Sum of all CSS assets that are loaded initially(eg: `vendor.css`, `app.css`).', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
cacheInvalidation: { | ||
@@ -121,2 +91,32 @@ label: 'Cache Invalidation', | ||
}, | ||
sizes: { | ||
totalSizeByTypeJS: { | ||
label: 'JS', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeCSS: { | ||
label: 'CSS', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeIMG: { | ||
label: 'IMG', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeMEDIA: { | ||
label: 'Media', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeFONT: { | ||
label: 'Fonts', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeHTML: { | ||
label: 'HTML', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
totalSizeByTypeOTHER: { | ||
label: 'Other', | ||
type: METRIC_TYPE_FILE_SIZE, | ||
}, | ||
}, | ||
}, | ||
@@ -123,0 +123,0 @@ lighthouse: { |
@@ -1,2 +0,1 @@ | ||
export * from './assets'; | ||
export * from './browsertime'; | ||
@@ -6,6 +5,3 @@ export * from './config'; | ||
export * from './lighthouse'; | ||
export * from './modules'; | ||
export * from './metrics'; | ||
export * from './stats'; | ||
export * from './transforms'; | ||
export * from './utils'; |
@@ -1,16 +0,9 @@ | ||
import { | ||
get, isEmpty, merge, omit, set, | ||
} from 'lodash'; | ||
import { get, merge, set } from 'lodash'; | ||
import { SOURCE_PATH_WEBPACK_STATS, SOURCE_PATHS } from '../config'; | ||
import { createStats } from '../stats/create'; | ||
import { createStatsSummary } from '../stats/create-summary'; | ||
import { | ||
duplicatePackagesBundleTransform, | ||
metaWebpackTransform, | ||
modulesWebpackTransform, | ||
packagesModulesBundleTransform, | ||
} from '../transforms'; | ||
import { SOURCE_PATHS } from '../config'; | ||
import { createSummary } from './create-summary'; | ||
import * as webpack from '../webpack'; | ||
const SOURCE_IDS = SOURCE_PATHS.map((id) => id.split('.')[0]); | ||
const SOURCE_FNS = { webpack }; | ||
const GENERIC_PROPS = ['meta', 'warnings', 'metrics']; | ||
@@ -20,40 +13,31 @@ /* | ||
*/ | ||
export const createJob = (source, baseline) => { | ||
const data = SOURCE_PATHS.reduce((agg, rawDataPath) => { | ||
const rawData = get(source, rawDataPath); | ||
export const createJob = (source, baseline) => SOURCE_PATHS.reduce((agg, sourcePath) => { | ||
const rawData = get(source, sourcePath); | ||
if (!rawData) { | ||
return agg; | ||
} | ||
if (!rawData) { | ||
return agg; | ||
} | ||
return merge( | ||
{}, | ||
agg, | ||
{ | ||
rawData: set({}, rawDataPath, rawData), | ||
}, | ||
); | ||
}, omit(source, SOURCE_IDS)); | ||
const sourceModule = SOURCE_FNS[sourcePath]; | ||
const stats = createStats(baseline && baseline.rawData, data.rawData); | ||
const summary = createStatsSummary(baseline && baseline.stats, stats); | ||
const { meta } = metaWebpackTransform(get(data.rawData, SOURCE_PATH_WEBPACK_STATS)); | ||
if (!sourceModule) { | ||
return agg; | ||
} | ||
const { warnings: duplicatePackagesWarnings } = duplicatePackagesBundleTransform( | ||
packagesModulesBundleTransform({ | ||
...modulesWebpackTransform(get(data.rawData, SOURCE_PATH_WEBPACK_STATS)), | ||
}), | ||
const extractedData = sourceModule.extract(rawData, baseline); | ||
const summary = createSummary( | ||
SOURCE_FNS[sourcePath].SUMMARY_METRIC_PATHS, | ||
get(baseline, `metrics.${sourcePath}`, {}), | ||
get(extractedData, 'metrics', {}), | ||
); | ||
const warnings = { | ||
...duplicatePackagesWarnings, | ||
}; | ||
return { | ||
...data, | ||
meta, | ||
stats, | ||
summary, | ||
...isEmpty(warnings) ? {} : { warnings }, | ||
}; | ||
}; | ||
return merge( | ||
{}, | ||
agg, | ||
{ rawData: set({}, sourcePath, rawData) }, | ||
{ summary: set({}, sourcePath, summary) }, | ||
...GENERIC_PROPS.map((genericPropName) => ({ | ||
[genericPropName]: set({}, sourcePath, extractedData[genericPropName]), | ||
})), | ||
); | ||
}, {}); |
@@ -1,4 +0,3 @@ | ||
export * from './get-asset-metric-states'; | ||
export * from './get-metric-changed'; | ||
export * from './get-metric-type'; | ||
export * from './merge-runs-by-id'; |
import { | ||
flatMap, get, isEmpty, map, uniq, | ||
flatMap, get, isEmpty, map, pick, uniq, | ||
} from 'lodash'; | ||
import { METRIC_TYPE_FILE_SIZE, SOURCE_PATH_WEBPACK_STATS } from '../config'; | ||
import { METRIC_TYPE_FILE_SIZE } from '../config'; | ||
import * as webpack from '../webpack'; | ||
import { getMetricChanged, getMetricType, mergeRunsById } from '../metrics'; | ||
import { getStatsByMetrics } from '../stats/get-stats-by-metrics'; | ||
import { | ||
assetsWebpackTransform, | ||
duplicatePackagesBundleTransform, | ||
modulesWebpackTransform, | ||
packagesModulesBundleTransform, | ||
} from '../transforms'; | ||
import { getDelta, formatDelta } from './delta'; | ||
import { formatPercentage } from './format'; | ||
const SIZE_METRICS = [ | ||
'webpack.assets.totalSizeByTypeJS', | ||
'webpack.assets.totalSizeByTypeCSS', | ||
'webpack.assets.totalSizeByTypeIMG', | ||
'webpack.assets.totalSizeByTypeMEDIA', | ||
'webpack.assets.totalSizeByTypeFONT', | ||
'webpack.assets.totalSizeByTypeHTML', | ||
'webpack.assets.totalSizeByTypeOTHER', | ||
'webpack.assets.totalSizeByTypeALL', | ||
'webpack.assets.totalInitialSizeCSS', | ||
'webpack.assets.totalInitialSizeJS', | ||
]; | ||
export const addMetricsData = (entries, metricType) => entries.map((entry) => { | ||
export const addMetricsData = (entries, metricType, metricPrefix = '') => entries.map((entry) => { | ||
const { runs } = entry; | ||
const { biggerIsBetter, label, formatter } = getMetricType(entry.key, metricType); | ||
const { biggerIsBetter, label, formatter } = getMetricType( | ||
metricPrefix ? [metricPrefix, entry.key].join('.') : entry.key, | ||
metricType, | ||
); | ||
@@ -46,3 +30,3 @@ return { | ||
runs: runs.map((run, index) => { | ||
if (!run || typeof run.value === 'undefined') { | ||
if (!run || typeof run.value === 'undefined' || run.value === null) { | ||
return null; | ||
@@ -72,27 +56,28 @@ } | ||
export const createRuns = (jobs) => jobs.map(({ | ||
meta, internalBuildNumber, stats, rawData, | ||
}) => { | ||
const webpackStats = get(rawData, SOURCE_PATH_WEBPACK_STATS); | ||
const { modules } = modulesWebpackTransform(webpackStats); | ||
const getWebpackSizesMetrics = (job) => { | ||
const metrics = get(job, 'metrics.webpack.sizes', {}); | ||
return { | ||
meta: { | ||
...meta, | ||
internalBuildNumber, | ||
}, | ||
sizes: getStatsByMetrics(stats, SIZE_METRICS), | ||
...assetsWebpackTransform(webpackStats), | ||
modules, | ||
...packagesModulesBundleTransform({ modules }), | ||
}; | ||
}); | ||
return Object.entries(metrics).reduce((agg, [key, value]) => ({ | ||
...agg, | ||
[`webpack.sizes.${key}`]: value, | ||
}), {}); | ||
}; | ||
export const getModulesReport = (runs) => map( | ||
uniq(flatMap(runs, ({ modules }) => Object.keys(modules))), | ||
const getWebpackStatsMetrics = (job) => { | ||
const metrics = pick(get(job, 'metrics.webpack', {}), webpack.SUMMARY_METRIC_PATHS); | ||
return Object.entries(metrics).reduce((agg, [key, value]) => ({ | ||
...agg, | ||
[`webpack.${key}`]: value, | ||
}), {}); | ||
}; | ||
export const getModulesReport = (jobs) => map( | ||
uniq(flatMap(jobs, (job) => Object.keys(get(job, 'metrics.webpack.modules', {})))), | ||
(chunkId) => ({ | ||
chunkId, | ||
chunkNames: uniq(flatMap(runs, (run) => get(run, ['modules', chunkId, 'chunkNames']))), | ||
chunkNames: uniq(flatMap(jobs, (job) => get(job, ['metrics', 'webpack', 'modules', chunkId, 'chunkNames']))), | ||
modules: addMetricsData(mergeRunsById( | ||
map(runs, (run) => get(run, ['modules', chunkId, 'modules'])), | ||
map(jobs, (job) => get(job, ['metrics', 'webpack', 'modules', chunkId, 'modules'])), | ||
), METRIC_TYPE_FILE_SIZE), | ||
@@ -103,20 +88,16 @@ }), | ||
export const createReport = (jobs) => { | ||
const runs = createRuns(jobs); | ||
const warnings = get(jobs, '[0].warnings'); | ||
const { warnings: duplicatePackagesWarnings } = duplicatePackagesBundleTransform( | ||
get(runs, '[0]', {}), | ||
); | ||
const warnings = { | ||
...duplicatePackagesWarnings, | ||
}; | ||
return { | ||
runs: map(runs, 'meta'), | ||
runs: jobs.map(({ internalBuildNumber, meta }) => ({ | ||
...meta, | ||
internalBuildNumber, | ||
})), | ||
...!isEmpty(warnings) ? { warnings } : {}, | ||
sizes: addMetricsData(mergeRunsById(map(runs, 'sizes'))), | ||
assets: addMetricsData(mergeRunsById(map(runs, 'assets')), METRIC_TYPE_FILE_SIZE), | ||
modules: getModulesReport(runs), | ||
packages: addMetricsData(mergeRunsById(map(runs, 'packages')), METRIC_TYPE_FILE_SIZE), | ||
stats: addMetricsData(mergeRunsById(map(jobs, getWebpackStatsMetrics))), | ||
sizes: addMetricsData(mergeRunsById(map(jobs, getWebpackSizesMetrics))), | ||
assets: addMetricsData(mergeRunsById(map(jobs, 'metrics.webpack.assets')), METRIC_TYPE_FILE_SIZE), | ||
modules: getModulesReport(jobs), | ||
packages: addMetricsData(mergeRunsById(map(jobs, 'metrics.webpack.packages')), METRIC_TYPE_FILE_SIZE), | ||
}; | ||
}; |
export * from './create-report'; | ||
export * from './delta'; | ||
export * from './date'; | ||
export * from './extract-data'; | ||
export * from './format'; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
183873
115
4350
1
1