Skip to content

Fix issues #42 #49 #51 #60 #61

Merged
MathieuSoysal merged 13 commits into
masterfrom
fix-issues
May 12, 2026
Merged

Fix issues #42 #49 #51 #60 #61
MathieuSoysal merged 13 commits into
masterfrom
fix-issues

Conversation

@MathieuSoysal

Copy link
Copy Markdown
Owner

closes : #49 #51 #60 #42

This pull request introduces significant enhancements to support inlining direct external dependencies as modules, improves code clarity, and updates the Rust edition and minimum supported Rust version. The main changes add a mechanism to detect and inline external crate libraries directly into the bundled output, ensuring correct handling of crate paths and improving test coverage for edge cases. Several code quality improvements and test refactorings are also included.

External dependencies inlining:

  • Added a method external_lib_paths to CargoProject that returns a mapping from each direct dependency's crate name to its library entry point path, excluding the root package and non-library dependencies. (src/cargo_project.rs)
  • Updated Bundler to use the new CodeTransformer::with_external_libs constructor, passing in the external library paths for inlining. (src/bundler.rs)
  • Extended CodeTransformer to support inlining external libraries as mod <name> { ... } blocks at the top of the bundled output, only for dependencies actually referenced in the code. (src/transformer.rs) [1] [2]

Crate path handling and robustness:

  • Improved expand_crate_path to avoid stripping single-segment paths matching the crate name, preventing empty paths and related panics. Added a regression test for this scenario. (src/transformer.rs) [1] [2]
  • Refactored utility methods in CodeTransformer for clearer Rust idioms and conciseness, such as using if let ... && ... patterns. (src/transformer.rs)

Rust edition and MSRV update:

  • Updated the Rust edition to "2024" and minimum supported Rust version to "1.91.0" in Cargo.toml.

Test and code quality improvements:

  • Refactored test project creation code in test files to use format string interpolation for better readability. (tests/cli_tests.rs, tests/comprehensive_tests.rs) [1] [2] [3]
  • Updated various test assertions and string handling to use idiomatic Rust, such as writeln! for string building and direct format string interpolation. (tests/comprehensive_tests.rs, tests/integration_tests.rs) [1] [2] [3] [4] [5]

Minor improvements:

  • Made Bundler::set_config and CodeTransformer::with_external_libs const where possible for improved API clarity. (src/bundler.rs, src/transformer.rs) [1] [2]
  • Improved file change message formatting in the watch command for clarity. (src/main.rs)

MathieuSoysal and others added 10 commits May 4, 2026 16:03
… consistency

Co-authored-by: Copilot <copilot@github.com>
…expand_crate_path fixes : #51

Co-authored-by: Copilot <copilot@github.com>
… transformation

- Introduced `error_tests.rs` to validate the display and source behavior of `BundlerError`.
- Added `file_manager_tests.rs` to test file reading, existence checks, and module file finding.
- Created `transformer_tests.rs` to cover various aspects of code transformation, including configuration defaults, attribute handling, and module expansion.

Co-authored-by: Copilot <copilot@github.com>
…als during minification

Co-authored-by: Copilot <copilot@github.com>

Copilot AI left a comment

Copy link
Copy Markdown

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 enhances CG-Bundler to inline direct external Cargo dependencies into the bundled output (addressing issues like “extern crates are not bundled”), improves robustness of crate path expansion, updates the crate to Rust edition 2024 / higher MSRV, and significantly expands test coverage (including new regression tests for reported issues).

Changes:

  • Add CargoProject::external_lib_paths and wire Bundler/CodeTransformer to inline referenced direct dependency libraries as mod <crate> { ... }.
  • Fix crate-path expansion edge case (single-segment path equal to crate name) and improve minification behavior (string/placeholder handling, <- spacing regression).
  • Add/refactor extensive tests across bundler, transformer, file manager, cargo project, error handling, and CLI behaviors.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/cargo_project.rs Adds external dependency discovery (external_lib_paths) for inlining.
src/bundler.rs Uses transformer constructor that receives external lib paths.
src/transformer.rs Implements external dependency inlining into mod <name> { ... } blocks; refactors helpers; adjusts crate-path expansion.
src/main.rs Updates minification logic (literal placeholdering + <- fix), improves watch output formatting, and adds broad CLI/unit tests.
src/file_manager.rs Moves unit tests out of the module (now covered by integration tests).
Cargo.toml Updates edition to 2024 and raises rust-version.
.gitignore Ignores .vscode.
tests/unit_tests.rs Refactors assertions/formatting and minor test improvements.
tests/transformer_tests.rs New: focused transformer test suite (regressions + internal behaviors).
tests/integration_tests.rs Adds regression test for issue #49 and refactors string building/formatting in tests.
tests/file_manager_tests.rs New: FileManager test coverage moved to tests/.
tests/error_tests.rs New: BundlerError display/source/from impl tests.
tests/comprehensive_tests.rs Refactors test project generation and improves assertions/string building.
tests/cli_tests.rs Refactors test project generation formatting.
tests/cargo_project_tests.rs New: CargoProject behavior tests including external_lib_paths.
tests/bundler_tests.rs New: Bundler API and basic bundle behavior tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.rs Outdated
Comment thread src/transformer.rs Outdated
Comment thread src/transformer.rs Outdated
Comment thread src/transformer.rs Outdated
Comment thread tests/integration_tests.rs Outdated
Comment thread src/cargo_project.rs Outdated
- Added `rustfmt_fmt.rs` for formatting Rust code using rustfmt with a fallback mechanism.
- Introduced `test_support.rs` for shared test fixtures to create minimal Cargo projects.
- Refactored `transformer.rs` by splitting functionality into dedicated modules: `docs.rs`, `expansion.rs`, and `visit_mut_impl.rs`.
- Moved documentation-related functions to `docs.rs` for better organization.
- Implemented external library expansion and module handling in `expansion.rs`.
- Enhanced `visit_mut_impl.rs` to handle AST traversal and transformation.
- Updated tests to ensure formatting and transformation functionalities work as expected.
@sonarqubecloud

Copy link
Copy Markdown

@MathieuSoysal MathieuSoysal merged commit fa76d21 into master May 12, 2026
12 checks passed
@MathieuSoysal MathieuSoysal deleted the fix-issues branch May 12, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants