Skip to content

Conversation

JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Oct 13, 2025

Summary

Render cjs entry and default export for json entry module

See tests for detail

// input.json
{ "foo": 42 }

// output.js
var __webpack_export_foo = 42
export { __webpack_export_foo as foo }
export default { "foo": __webpack_export_foo }

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@Copilot Copilot AI review requested due to automatic review settings October 13, 2025 11:33
Copy link

netlify bot commented Oct 13, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit 6c47df0
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/68ece3a246190f0008e87fb4
😎 Deploy Preview https://deploy-preview-11860--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: bug fix release: bug related release(mr only) labels Oct 13, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the rendering of default exports for CommonJS (CJS) entries and JSON entries in module library output. The fix ensures that when using module library types, both CJS modules and JSON files generate appropriate default exports alongside named exports.

Key changes:

  • Added export type detection to determine when to render default exports
  • Refactored export rendering to support both named and default export patterns
  • Added comprehensive test coverage for both module and modern-module library types with JSON and CJS entries

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rspack_plugin_library/src/module_library_plugin.rs Updated export rendering logic to handle different export types and generate default exports when needed
crates/rspack_plugin_library/src/modern_module_library_plugin.rs Added export type detection and refactored export rendering functions to support both named and default exports
tests/rspack-test/configCases/library/module-json-entry/* Added test case for module library type with JSON entry
tests/rspack-test/configCases/library/modern-module-json-entry/* Added test case for modern-module library type with JSON entry
tests/rspack-test/configCases/library/modern-module-cjs-entry/* Added test case for modern-module library type with CJS entry
Comments suppressed due to low confidence (1)

crates/rspack_plugin_library/src/module_library_plugin.rs:1

  • [nitpick] Missing space after '=' operator. Should be 'module.exports = {' for consistent formatting.
use std::hash::Hash;

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

source.add(RawStringSource::from(exports_string));
} else if matches!(exports_type, ExportsType::Dynamic) {
// compat for css entry
render_as_default_export(&exports);
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of render_as_default_export(&exports) is not being used. This function returns a String that should be added to the source, but the return value is being discarded.

Suggested change
render_as_default_export(&exports);
source.add(RawStringSource::from(render_as_default_export(&exports)));

Copilot uses AI. Check for mistakes.

source.add(RawStringSource::from(exports_string));
} else if matches!(exports_type, ExportsType::Dynamic) {
// compat for css entry
render_as_default_export(&exports);
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of render_as_default_export(&exports) is not being used. This function returns a String that should be added to the source, but the return value is being discarded.

Suggested change
render_as_default_export(&exports);
source.add(RawStringSource::from(render_as_default_export(&exports)));

Copilot uses AI. Check for mistakes.

Comment on lines +455 to +456
} else {
local.clone()
Copy link

Copilot AI Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there's no exported name, the local variable name is used directly in the object literal, but this could create invalid JavaScript if the local name contains special characters or is a reserved word. Consider using property shorthand syntax or proper escaping.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

📦 Binary Size-limit

Comparing 6c47df0 to chore(deps): update patch npm dependencies (#11806) by renovate[bot]

🎉 Size decreased by 278.88KB from 47.89MB to 47.62MB (⬇️0.57%)

Copy link

codspeed-hq bot commented Oct 13, 2025

CodSpeed Performance Report

Merging #11860 will not alter performance

Comparing feat/json-export-default (6c47df0) with main (a915dab)

Summary

✅ 17 untouched

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant