-
-
Notifications
You must be signed in to change notification settings - Fork 749
WIP: feat: Treeshake macro implementation #10740
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
Draft
ScriptedAlchemy
wants to merge
28
commits into
main
Choose a base branch
from
treeshake-macro
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
+4,225
−310
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…lugin ConsumeShared modules now participate in export usage analysis like normal modules: - Detect ConsumeShared module type and route to enhanced processing - Apply same usage state logic (Used, OnlyPropertiesUsed, side-effects) - Handle mangling and inlining constraints from dependencies - Enable proper tree-shaking of unused ConsumeShared exports - Maintain fallback module completeness for module federation reliability This allows ConsumeShared proxy modules to be tree-shaken based on actual usage while preserving fallback modules for runtime safety. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Implement copy_metadata_from_fallback() and copy_exports_from_fallback() methods - Add CompilationFinishModules hook for proper lifecycle timing - Enable comprehensive export analysis with prefetched export info - Support ProvidedExports variants (ProvidedNames, ProvidedAll, Unknown) - Copy export provision status, mangling capabilities, and nested structures - Add proper error handling and diagnostic reporting for metadata copying failures This ensures ConsumeShared proxy modules accurately reflect their fallback module's export capabilities for tree-shaking analysis. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add conditional tree-shaking comments to ESM export dependencies - Implement ConsumeShared module detection in export specifier templates - Use macro format: /* @common:if [condition="treeShake.{shareKey}.{export}"] */ - Add fallback module detection via incoming connection analysis - Support both direct ConsumeShared parents and fallback modules - Remove extra EXPORT comments from runtime modules for cleaner output This enables build tools to conditionally include exports based on tree-shaking analysis while maintaining module federation compatibility. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ration - Add ShareUsagePlugin for ConsumeShared module analysis - Add SharedExportUsagePlugin for general export tracking - Implement enhanced dependency analysis using get_referenced_exports() - Add comprehensive export usage types and data structures - Support incoming connection analysis for accurate usage detection - Enable detailed usage reporting with JSON output capabilities These plugins provide deep insights into module federation export usage patterns and support advanced tree-shaking analysis workflows. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add comprehensive basic example with module federation setup - Include analysis scripts and debug tooling for export tracking - Add package configuration and build scripts for testing - Update dependency manifests and IDE configurations - Provide JSON analysis output and extraction utilities This testing infrastructure enables validation of the ConsumeShared tree-shaking implementation and provides debugging capabilities. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…rt processing - Add intelligent ConsumeShared macro detection in ESM export init fragments - Implement object literal processing for ConsumeShared default exports - Add share_key extraction from existing condition strings - Support automatic @common:endif closure for ConsumeShared declarations - Handle complex nested export structures with conditional macro wrapping This provides sophisticated macro handling for ConsumeShared modules, ensuring proper conditional export inclusion in generated code. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add enhanced share usage plugin for advanced analysis workflows - Include legacy export usage plugin version for comparison - Add test documentation for ConsumeShared usage validation - Provide additional debugging and development tools These supplementary tools support research and development of the ConsumeShared tree-shaking implementation. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Add sophisticated object literal parsing for ConsumeShared exports - Implement unused exports detection from share-usage.json - Enhance replacement enforcement for proper macro ordering - Clean up import dependencies and improve source manipulation - Support complex nested object structures in export expressions This provides more robust handling of ConsumeShared export patterns and ensures proper macro application in complex scenarios. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
… module federation This commit implements two key improvements for rspack's module federation and tree-shaking: 1. **Conditional Pure Annotations**: Added logic to conditionally apply `/* #__PURE__ */` annotations to `__webpack_require__` calls based on import type: - Named/default imports (`import { foo } from 'bar'`) get pure annotations for better tree-shaking - Side-effect imports (`import './style.css'`) do NOT get pure annotations to preserve side effects - Module factories and fallback functions get pure annotations appropriately 2. **TreeShake Macro Annotations**: Enhanced ConsumeShared modules to wrap ALL exports with conditional compilation macros: - Export declarations wrapped with `/* @common:if [condition="treeShake.MODULE.EXPORT"] */ ... /* @common:endif */` - Default export objects wrapped with macro annotations - Only applies to ConsumeShared modules, regular modules remain unchanged 3. **NO_SIDE_EFFECTS Annotation**: Added `// #__NO_SIDE_EFFECTS__` annotation to the main require function definition for better bundler optimization. The implementation correctly distinguishes between: - ConsumeShared modules (get treeshake macros on ALL exports) - Regular modules (no macro annotations) - Side-effect imports vs named imports (for pure annotations) - Entry points vs module imports (entry points preserve side effects) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
❌ Deploy Preview for rspack failed. Why did it fail? →
|
- Add comprehensive error handling for string parsing operations - Validate bounds before slicing to prevent panics - Add detailed warning logs for malformed patterns - Improve robustness of ConsumeShared macro processing 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
CodSpeed Performance ReportMerging #10740 will not alter performanceComparing Summary
|
- Add comprehensive documentation and type annotations - Implement sophisticated ConsumeShared module integration - Enhance template system with advanced code generation - Add proper runtime requirement and init fragment management - Improve export handling with tree-shaking macro support - Follow rspack minimalist conventions and naming patterns - Add development mode debug comments and error handling - Optimize performance with better export usage analysis 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ractices Enhanced ESMExportImportedSpecifierDependency with comprehensive improvements: - Advanced error diagnostics with context and recovery suggestions - Sophisticated template generation with runtime condition support - Performance optimizations through enhanced mode calculation - Comprehensive export resolution with validation - Enhanced connection state management for tree shaking - Improved documentation following rspack conventions - Better circular dependency and conflict detection - Enhanced comment generation with contextual information Applied research findings for enterprise-grade dependency handling matching sophistication of core rspack ESM dependency patterns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Enhanced error handling with comprehensive diagnostic integration - Added sophisticated dependency template with advanced code generation - Improved module graph integration with runtime condition support - Added source map support and resource identifier generation - Implemented proper ConsumeShared module detection with fallback support - Enhanced export specification with terminal binding and priority - Added comprehensive validation and fallback rendering - Followed rspack's minimalist documentation and naming conventions - Added performance optimizations with export usage caching - Implemented proper side effect detection for module evaluation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Fixed the "borrow of moved value" error on line 605 where add_diagnostic was being moved. Changed the function signatures to accept mutable references instead of consuming the closure, allowing multiple uses of add_diagnostic throughout the function. Changes: - Updated create_consume_shared_module to accept &mut impl FnMut(Diagnostic) - Updated get_required_version to accept &mut impl FnMut(Diagnostic) - Updated all call sites to use mutable references 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Remove unused import ExportProvided - Add missing import IntoTWithDiagnosticArray - Fix InternalError conversion to use Diagnostic::warn/error methods - Remove duplicate find_fallback_module_id method definition - Add lifetime parameters to fix lifetime issues in batch_prefetch_exports - Fix iterator usage by collecting to Vec before checking is_empty() - Fix export metadata type mismatch (Option<bool> vs bool) - Fix diagnostic formatting to use render_report instead of Display - Prefix unused variables with underscore - Replace all RspackSeverity usages with rspack_error::Severity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
… test suite - Reverted esm_export_expression_dependency.rs to minimally invasive implementation - Added ConsumeShared macro comment generation for tree-shaking - Created comprehensive Node.js test runner with proper setup/teardown - Cleaned up example directory by removing unused analysis scripts - Added validation for macro comments and share-usage.json output - Fixed dependency versions to use workspace references 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ebase - Updated esm_export_expression_dependency.rs with minimal ConsumeShared macro support - Reverted common_js_exports_dependency.rs to minimal implementation from main branch - Added ConsumeShared macro generation for CommonJS export dependencies - Enhanced esm_export_imported_specifier_dependency.rs with ConsumeShared support - Removed legacy export usage analysis plugins and types - Cleaned up module federation plugin exports and dependencies - Updated share usage plugin with streamlined implementation - Fixed consume_shared_module.rs to support macro key generation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…ation - Removed excessive comments and helper methods from CommonJS and ESM dependency files - Simplified ConsumeShared macro logic with cleaner helper functions - Enhanced test suite to validate 15 macro comments across shared modules - Improved code organization and maintainability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces several changes across multiple files to enhance functionality related to module dependency handling, export tracking, and runtime template generation. The key updates focus on supporting
ConsumeShared
modules, improving export handling with conditional macros, and introducing new utility functions for processing shared object literals. Additionally, there are minor formatting adjustments and code improvements for better readability.Enhancements for
ConsumeShared
Modules:Support for
ConsumeShared
Modules:get_consume_shared_key
in theModule
trait to retrieve theshare_key
forConsumeShared
modules.CommonJsExportRequireDependencyTemplate
andCommonJsExportsDependencyTemplate
to wrap exports and assignments with conditional macros based on theshare_key
. [1] [2] [3]Handling Object Literals in
ConsumeShared
Exports:extract_share_key_from_condition
andprocess_consume_shared_object_literal
to process object literals inConsumeShared
modules, ensuring all properties are wrapped with conditional macros.Improvements to Runtime Template:
Export Purity Annotation:
/* #__PURE__ */
. [1] [2]ConsumeShared Export Wrapping:
ESMExportExpressionDependencyTemplate
to wrap fallback exports inConsumeShared
modules with conditional macros. This includes handling connections fromConsumeShared
modules. [1] [2]Utility and Codebase Enhancements:
CowUtils
for efficient string manipulation ininit_fragment.rs
.Related links
Checklist