Skip to content

Commit

Permalink
Merge pull request #177 from webpack-contrib/filter-out-missing-modules
Browse files Browse the repository at this point in the history
Filter out modules that are not part of parsed bundle
  • Loading branch information
th0r authored May 13, 2018
2 parents 30fda2e + e55d7bd commit 12501d5
Show file tree
Hide file tree
Showing 4 changed files with 544 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function getViewerData(bundleStats, bundleDir, opts) {

// Picking modules from current bundle script
asset.modules = _(modules)
.filter(statModule => assetHasModule(statAsset, statModule))
.filter(statModule => assetHasModule(statAsset, statModule, parsedModules))
.each(statModule => {
if (parsedModules) {
statModule.parsedSrc = parsedModules[statModule.id];
Expand Down Expand Up @@ -118,10 +118,20 @@ function getBundleModules(bundleStats) {
.value();
}

function assetHasModule(statAsset, statModule) {
return _.some(statModule.chunks, moduleChunk =>
function assetHasModule(statAsset, statModule, parsedModules) {
// Checking if this module is the part of asset chunks
const moduleIsInsideAsset = _.some(statModule.chunks, moduleChunk =>
_.includes(statAsset.chunks, moduleChunk)
);

return (
moduleIsInsideAsset &&
// ...and that we have found it during parsing
(
!parsedModules ||
_.has(parsedModules, statModule.id)
)
);
}

function createModulesTree(modules) {
Expand Down
18 changes: 18 additions & 0 deletions test/analyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ describe('Analyzer', function () {
require('./stats/with-module-concatenation-info/expected-chart-data')
);
});

it("should filter out modules that we could't find during parsing", async function () {
generateReportFrom('with-missing-parsed-module/stats.json');
const chartData = await getChartData();
forEachChartItem(chartData, item => {
expect(typeof item.parsedSize).to.equal('number');
});
});
});

function generateReportFrom(statsFilename) {
Expand All @@ -68,6 +76,16 @@ async function getChartData() {
.evaluate(() => window.chartData);
}

function forEachChartItem(chartData, cb) {
for (const item of chartData) {
cb(item);

if (item.groups) {
forEachChartItem(item.groups, cb);
}
}
}

async function expectValidReport(opts) {
const {
bundleLabel = 'bundle.js',
Expand Down
109 changes: 109 additions & 0 deletions test/stats/with-missing-parsed-module/bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/static/bundles/";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = "./client/index.js");
/******/ })
/************************************************************************/
/******/ ({

/***/ "./client/App.vue":
/*!************************!*\
!*** ./client/App.vue ***!
\************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _App_vue_vue_type_template_id_278f674b__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./App.vue?vue&type=template&id=278f674b */ \"./client/App.vue?vue&type=template&id=278f674b\");\n/* harmony import */ var _App_vue_vue_type_script_lang_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./App.vue?vue&type=script&lang=js */ \"./client/App.vue?vue&type=script&lang=js\");\n/* empty/unused harmony star reexport *//* harmony import */ var _node_modules_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../node_modules/vue-loader/lib/runtime/componentNormalizer.js */ \"./node_modules/vue-loader/lib/runtime/componentNormalizer.js\");\n\n\n\n\n\n/* normalize component */\n\nvar component = Object(_node_modules_vue_loader_lib_runtime_componentNormalizer_js__WEBPACK_IMPORTED_MODULE_2__[\"default\"])(\n _App_vue_vue_type_script_lang_js__WEBPACK_IMPORTED_MODULE_1__[\"default\"],\n _App_vue_vue_type_template_id_278f674b__WEBPACK_IMPORTED_MODULE_0__[\"render\"],\n _App_vue_vue_type_template_id_278f674b__WEBPACK_IMPORTED_MODULE_0__[\"staticRenderFns\"],\n false,\n null,\n null,\n null\n \n)\n\n/* hot reload */\nif (false) { var api; }\ncomponent.options.__file = \"client/App.vue\"\n/* harmony default export */ __webpack_exports__[\"default\"] = (component.exports);\n\n//# sourceURL=webpack:///./client/App.vue?");

/***/ }),

/***/ "./client/App.vue?vue&type=script&lang=js":
/*!************************************************!*\
!*** ./client/App.vue?vue&type=script&lang=js ***!
\************************************************/
/*! exports provided: default */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _node_modules_babel_loader_lib_index_js_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_script_lang_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../node_modules/babel-loader/lib!../node_modules/vue-loader/lib??vue-loader-options!./App.vue?vue&type=script&lang=js */ \"./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/index.js??vue-loader-options!./client/App.vue?vue&type=script&lang=js\");\n/* empty/unused harmony star reexport */ /* harmony default export */ __webpack_exports__[\"default\"] = (_node_modules_babel_loader_lib_index_js_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_script_lang_js__WEBPACK_IMPORTED_MODULE_0__[\"default\"]); \n\n//# sourceURL=webpack:///./client/App.vue?");

/***/ }),

/***/ "./client/App.vue?vue&type=template&id=278f674b":
/*!******************************************************!*\
!*** ./client/App.vue?vue&type=template&id=278f674b ***!
\******************************************************/
/*! exports provided: render, staticRenderFns */
/***/ (function(module, __webpack_exports__, __webpack_require__) {

"use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_template_id_278f674b__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! -!../node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!../node_modules/vue-loader/lib??vue-loader-options!./App.vue?vue&type=template&id=278f674b */ \"./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib/index.js??vue-loader-options!./client/App.vue?vue&type=template&id=278f674b\");\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"render\", function() { return _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_template_id_278f674b__WEBPACK_IMPORTED_MODULE_0__[\"render\"]; });\n\n/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, \"staticRenderFns\", function() { return _node_modules_vue_loader_lib_loaders_templateLoader_js_vue_loader_options_node_modules_vue_loader_lib_index_js_vue_loader_options_App_vue_vue_type_template_id_278f674b__WEBPACK_IMPORTED_MODULE_0__[\"staticRenderFns\"]; });\n\n\n\n//# sourceURL=webpack:///./client/App.vue?");

/***/ })
/******/ });
Loading

0 comments on commit 12501d5

Please sign in to comment.