Skip to content

Commit

Permalink
fix(modern-module): correct use bailout reason
Browse files Browse the repository at this point in the history
  • Loading branch information
fi3ework committed Aug 9, 2024
1 parent 6f19caa commit e78c272
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
14 changes: 9 additions & 5 deletions crates/rspack_plugin_library/src/modern_module_library_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,16 @@ impl ModernModuleLibraryPlugin {
.iter()
.filter(|id| !concatenated_module_ids.contains(id))
.filter(|id| {
let module = module_graph
.module_by_identifier(id)
let mgm = module_graph
.module_graph_module_by_identifier(id)
.expect("should have module");
module
.get_concatenation_bailout_reason(&module_graph, &compilation.chunk_graph)
.is_none()
let reasons = &mgm.optimization_bailout;
reasons
.into_iter()

Check failure on line 83 in crates/rspack_plugin_library/src/modern_module_library_plugin.rs

View workflow job for this annotation

GitHub Actions / Rust check

this `.into_iter()` call is equivalent to `.iter()` and will not consume the `Vec`
// We did want force concatenate entry point here.
.filter(|r| !r.contains("Module is an entry point"))
.collect::<Vec<_>>()
.is_empty()
})
.collect::<HashSet<_>>();

Expand Down
93 changes: 93 additions & 0 deletions packages/rspack-test-tools/tests/__snapshots__/Config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,99 @@ const d = 'd'
"
`;
exports[`config config/library/modern-module-force-concaten step should pass: external module should bail out when bundling 1`] = `
"import { createRequire as __WEBPACK_EXTERNAL_createRequire } from \\"module\\";
var __webpack_modules__ = ({
\\"17\\": (function (module) {
module.exports = __WEBPACK_EXTERNAL_createRequire(import.meta.url)(\\"path\\");
}),
\\"441\\": (function (module, __unused_webpack_exports, __webpack_require__) {
const path = __webpack_require__(17)
module.exports = path.sep
}),
});
/************************************************************************/
// The module cache
var __webpack_module_cache__ = {};
// The require function
function __webpack_require__(moduleId) {
// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
// Return the exports of the module
return module.exports;
}
/************************************************************************/
// webpack/runtime/compat_get_default_export
(() => {
// getDefaultExport function for compatibility with non-harmony modules
__webpack_require__.n = function (module) {
var getter = module && module.__esModule ?
function () { return module['default']; } :
function () { return module; };
__webpack_require__.d(getter, { a: getter });
return getter;
};
})();
// webpack/runtime/define_property_getters
(() => {
__webpack_require__.d = function(exports, definition) {
for(var key in definition) {
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
}
}
};
})();
// webpack/runtime/has_own_property
(() => {
__webpack_require__.o = function (obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
})();
/************************************************************************/
// EXTERNAL MODULE: ./f/bar.cjs
var bar = __webpack_require__(\\"441\\");
var bar_default = /*#__PURE__*/__webpack_require__.n(bar);
;// CONCATENATED MODULE: ./f/foo.js
const foo = 'foo'
;// CONCATENATED MODULE: ./f/index.js
const value = foo + (bar_default())
export { value };
"
`;
exports[`config config/library/modern-module-force-concaten step should pass: harmony export should concat 1`] = `
"
;// CONCATENATED MODULE: ./a.js
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const path = require('path')

module.exports = path.sep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const foo = 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import bar from './bar.cjs'
import { foo } from './foo'

const value = foo + bar

export { value }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ module.exports = {
"b": "./b.cjs",
"c": "./c.js",
"d": "./d.mjs",
"e": "./e/index.js"
"e": "./e/index.js",
"f": "./f/index.js"
},
externals: {
path: 'node-commonjs path',
},
output: {
filename: `[name].js`,
Expand Down Expand Up @@ -34,6 +38,7 @@ module.exports = {
expect(assets['c.js']._value).toMatchSnapshot("unambiguous should bail out");
expect(assets['d.js']._value).toMatchSnapshot(".mjs should concat");
expect(assets['e.js']._value).toMatchSnapshot(".cjs should bail out when bundling");
expect(assets['f.js']._value).toMatchSnapshot("external module should bail out when bundling");
});
};
this.hooks.compilation.tap("testcase", handler);
Expand Down

0 comments on commit e78c272

Please sign in to comment.