feat(napi/minify): expose treeshake options#15109
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
treeshake options
treeshake optionstreeshake options
treeshake optionstreeshake options
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for configuring treeshake options through the NAPI minifier interface. The changes allow users to control dead code elimination behavior by configuring annotations, manual pure functions, property read side effects, and global variable access side effects.
- Defines a new
TreeShakeOptionsstruct in Rust with conversion logic to the internal oxc_minifier types - Adds a
treeshakefield to theCompressOptionsstruct - Updates TypeScript type definitions with the new treeshake options interface
- Adds comprehensive test coverage for all treeshake configuration options
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| napi/minify/src/options.rs | Adds TreeShakeOptions struct, implements conversion to oxc_minifier types, and integrates treeshake options into CompressOptions |
| napi/minify/index.d.ts | Adds TypeScript interface definitions for TreeShakeOptions and updates CompressOptions interface |
| napi/minify/test/minify.test.ts | Adds test suite covering treeshake options including annotations, manual pure functions, and property read side effects |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot change to try_from to fix the compile error |
|
@copilot fix lint |
Done in e235a5e. Fixed clippy lint by using inline format args ( |
Merge activity
|
feat(napi/minify): expose `treeshake` options ## Completed: - [x] Understand the problem: Need to expose TreeShakeOptions to JavaScript users - [x] Explore existing code structure and TreeShakeOptions in oxc_minifier - [x] Build the project to ensure clean state - [x] Add TreeShakeOptions struct with all fields - [x] Update CompressOptions to accept optional treeshake field - [x] Implement conversion from NAPI TreeShakeOptions to oxc_minifier::TreeShakeOptions - [x] Build and verify TypeScript definitions are generated correctly - [x] Add tests for treeshake options - [x] Run all tests successfully - [x] Format code with just fmt - [x] Address all review feedback: - Renamed TreeShakeOptionsNapi to TreeShakeOptions - Changed property_read_side_effects to accept boolean | 'always' - Changed @default from true to 'always' for property_read_side_effects - Reverted From implementation back to use reference (From<&TreeShakeOptions>) - Changed to TryFrom to properly handle validation errors - Added validation for propertyReadSideEffects string values - Fixed clippy lint for inline format args ## Changes Made: 1. Added `TreeShakeOptions` struct with fields: - `annotations`: Whether to respect pure annotations (@__PURE__, #__NO_SIDE_EFFECTS__) - `manual_pure_functions`: List of function names to treat as pure - `property_read_side_effects`: Whether property reads have side effects (boolean | 'always', default: 'always') - `unknown_global_side_effects`: Whether accessing global variables has side effects 2. Updated `CompressOptions` to include optional `treeshake` field 3. Implemented `TryFrom<&TreeShakeOptions>` trait with proper error handling for invalid values 4. Added validation that rejects invalid string values for propertyReadSideEffects 5. Added tests covering treeshake functionality including error cases 6. Fixed all lint issues All tests pass successfully! <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > Add bindings for treeshake option here: > https://github.com/oxc-project/oxc/blob/3fbb307367a31817a297dee299fec580912675db/napi/minify/src/options.rs#L90 </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
e235a5e to
1c31cb1
Compare
feat(napi/minify): expose
treeshakeoptionsCompleted:
Changes Made:
TreeShakeOptionsstruct with fields:annotations: Whether to respect pure annotations (@PURE, #NO_SIDE_EFFECTS)manual_pure_functions: List of function names to treat as pureproperty_read_side_effects: Whether property reads have side effects (boolean | 'always', default: 'always')unknown_global_side_effects: Whether accessing global variables has side effectsCompressOptionsto include optionaltreeshakefieldTryFrom<&TreeShakeOptions>trait with proper error handling for invalid valuesAll tests pass successfully!
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.