Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(concatenate): exports conflict between root and inner #1256

Merged
merged 3 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions crates/mako/src/generate/chunk_pot/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ pub(crate) fn runtime_code(context: &Arc<Context>) -> Result<String> {
cjs: context.config.cjs,
chunk_loading_global: context.config.output.chunk_loading_global.clone(),
pkg_name: get_pkg_name(&context.root),
concatenate_enabled: context
.config
.optimization
.as_ref()
.map_or(false, |o| o.concatenate_modules.unwrap_or(false)),
};
let app_runtime = app_runtime.render_once()?;
let app_runtime = app_runtime.replace(
Expand Down
1 change: 1 addition & 0 deletions crates/mako/src/generate/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ pub struct AppRuntimeTemplate {
pub pkg_name: Option<String>,
pub chunk_loading_global: String,
pub is_browser: bool,
pub concatenate_enabled: bool,
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl<'a> VisitMut for RootTransformer<'a> {
}
}

let define_exports: Stmt = member_expr!(DUMMY_SP, __mako_require__.e)
let define_exports: Stmt = member_expr!(DUMMY_SP, __mako_require__.es)
.as_call(
DUMMY_SP,
vec![
Expand Down
13 changes: 13 additions & 0 deletions crates/mako/templates/app_runtime.stpl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ function createRuntime(makoModules, entryModuleId, global) {
get: all[name],
});
};
<% if concatenate_enabled { %>
// Export Star util for concatenated modules
requireModule.es = function(to, from) {
Object.keys(from).forEach(function(k) {
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
Object.defineProperty(to, k, {
enumerable: true,
get: from[k]
});
}
});
};
<% } %>
requireModule.d = Object.defineProperty.bind(Object);

<% if has_dynamic_chunks || has_hmr { %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const {
injectSimpleJest,
parseBuildResult,
moduleDefinitionOf,
} = require("../../../scripts/test-utils");
const { files } = parseBuildResult(__dirname);
injectSimpleJest();

expect(files["index.js"]).not.toContain(moduleDefinitionOf("inner.js"));

require("./dist/index.js");
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const ext = "ext";

export const value = "ext";

export default "ext-default";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const root = require("./root.js");
require("./ext");

it("skip conflict exports from inner", () => {
expect(root).toStrictEqual({
ext: "ext",
value: "root",
notConflict: "inner-not-conflict",
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const value = "inner";
export const notConflict = "inner-not-conflict";

export default "inner-default";
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"entry": {
"index": "index.js"
},
"optimization": {
"skipModules": true,
"concatenateModules": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./inner";
export * from "./ext";
export const value = "root";
Loading