feature: (esbuild): add --esbuild-define flag with dead code elimination#82
Conversation
Adds a new --esbuild-define CLI flag that accepts a JSON object of
string key-value pairs and passes them to esbuild's define option.
When defines are present, minifySyntax is automatically enabled so
esbuild performs dead code elimination — removing unreachable branches
entirely without mangling names or collapsing whitespace.
This enables zero-cost optional infrastructure code in PLV8 functions
(e.g. snapshot capture, debug logging) that can be compiled out in
production builds:
plv8ify generate --input-file input.ts \
--esbuild-define '{"ENABLE_SNAPSHOT_CAPTURE":"false"}'
Changes:
- src/interfaces/Bundler.ts: add optional define to BundleArgs
- src/interfaces/PLV8ify.ts: add optional esbuildDefine to BuildArgs
- src/impl/EsBuild.ts: spread define + minifySyntax into esbuild options when defines present
- src/impl/PLV8ifyCLI.ts: thread esbuildDefine through build() to bundle()
- src/helpers/ParseCLI.ts: add esbuildDefine to CLIConfig; add --esbuild-define optional flag with JSON parsing
- src/commands/generate.ts: destructure and pass esbuildDefine to plv8ify.build()
- src/impl/EsBuild.test.ts: tests for DCE with ENABLE_FEATURE=true/false and backward compat
- src/test-fixtures/define.fixture.ts: fixture for define tests
- README.md: new section and flag table entry documenting the feature
Backward compatible: omitting --esbuild-define produces identical output to current behavior.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
@mattiarossi I assume you read the code + tested it already? Asking because I see claude code traces :D, will try to get this merged later today! Merging might not release it anymore. IIRC I got a email from npm about 2FA that I haven't addressed yet. On my list. |
Yes, I used claude code to make a pull request of the patch that was originally created, also used claude to create the tests as well. |
|
Perfect, thank you. I will try to get to reviewing it as soon as possible. Targeting today evening. |
divyenduz
left a comment
There was a problem hiding this comment.
LGTM, thanks for the contribution ✅
|
There is some issue with the release pipeline (I need to configure 2FA + (update: that would happen after the easter holidays, so 2nd or 3rd week of April, sorry for the delay 🙏🏼) |
|
Fix release CI via #84 In the future, you can use I will document this process separately in README.md. This particular change is released in version |
Adds a new --esbuild-define CLI flag that accepts a JSON object of string key-value pairs and passes them to esbuild's define option. When defines are present, minifySyntax is automatically enabled so esbuild performs dead code elimination — removing unreachable branches entirely without mangling names or collapsing whitespace.
This enables zero-cost optional infrastructure code in PLV8 functions (e.g. snapshot capture, debug logging) that can be compiled out in production builds:
plv8ify generate --input-file input.ts
--esbuild-define '{"ENABLE_SNAPSHOT_CAPTURE":"false"}'
Changes:
Backward compatible: omitting --esbuild-define produces identical output to current behavior.