feat!: Consolidate Metadata Transformation Options into descriptorFields#2513
feat!: Consolidate Metadata Transformation Options into descriptorFields#2513timofei-iatsenko wants to merge 2 commits intonextfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
size-limit report 📦
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a breaking API change that replaces the legacy metadata-stripping flags (extract, stripMessageField, and SWC’s previous docs for stripping) with a single, explicit descriptorFields mode, aligning behavior with the proposal in issue #2511.
Changes:
- Replace
extract/stripMessageFieldplugin options withdescriptorFields(auto/all/id-only/message) and thread it through macro transforms. - Update CLI/extraction call-sites to use
descriptorFields: "all"for extraction. - Update docs and tests/snapshots to reflect the new configuration and ensure
contextis preserved when keepingmessage.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| website/docs/ref/swc-plugin.md | Documents the new descriptorFields option for the SWC plugin. |
| website/docs/guides/optimizing-bundle-size.md | Updates bundle-size guidance to use descriptorFields and explains keeping context with message. |
| packages/cli/src/extract-experimental/linguiEsbuildPlugin.ts | Switches extraction configuration from extract: true to descriptorFields: "all". |
| packages/cli/src/api/extractors/babel.ts | Switches Babel extraction configuration from extract: true to descriptorFields: "all". |
| packages/babel-plugin-lingui-macro/test/jsx-trans.test.ts | Renames/updates tests to validate descriptorFields behavior. |
| packages/babel-plugin-lingui-macro/test/js-t.test.ts | Renames/updates tests to validate descriptorFields behavior. |
| packages/babel-plugin-lingui-macro/test/snapshots/jsx-trans.test.ts.snap | Updates snapshot keys/outputs to match descriptorFields semantics. |
| packages/babel-plugin-lingui-macro/test/snapshots/js-t.test.ts.snap | Updates snapshot keys/outputs and ensures context is preserved in "message" mode. |
| packages/babel-plugin-lingui-macro/src/messageDescriptorUtils.ts | Centralizes field-preservation logic based on resolved descriptorFields mode. |
| packages/babel-plugin-lingui-macro/src/macroJsx.ts | Plumbs descriptorFields through JSX macro processing. |
| packages/babel-plugin-lingui-macro/src/macroJsx.test.ts | Updates unit test macro setup to use descriptorFields: "all". |
| packages/babel-plugin-lingui-macro/src/macroJsAst.ts | Replaces strip flags in macro context with descriptorFields. |
| packages/babel-plugin-lingui-macro/src/macroJsAst.test.ts | Updates unit test macro context construction to pass descriptorFields. |
| packages/babel-plugin-lingui-macro/src/macroJs.ts | Replaces strip flags with descriptorFields in JS macro processing. |
| packages/babel-plugin-lingui-macro/src/index.ts | Introduces the new public option, resolves "auto" to a concrete mode, and removes old flags. |
| packages/babel-plugin-extract-messages/test/extract-messages.test.ts | Updates extraction tests to use descriptorFields: "all". |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ``` | ||
|
|
||
| This keeps `id`, `message`, and `context` in the output. The `context` is preserved because it is required for correct message ID generation. | ||
|
|
There was a problem hiding this comment.
This guide was updated to use descriptorFields, but the repository still contains user-facing docs that reference the removed stripMessageField option (e.g. website/blog/2024-11-28-announcing-lingui-5.0/index.md). To avoid confusion during upgrades, please update those references (or add an explicit migration note) so all docs consistently describe the new option.
| > **Migration note:** If you're upgrading from older Lingui docs or examples, you may see references to `stripMessageField`. That option has been removed; use `descriptorFields` instead. |
| const mode = opts.descriptorFields ?? "auto" | ||
| if (mode !== "auto") { | ||
| return mode | ||
| } | ||
| // default to strip message in production if no explicit option is set and not during extract | ||
| return process.env.NODE_ENV === "production" && !opts.extract | ||
| // "auto": production → "id-only", otherwise → "all" | ||
| return process.env.NODE_ENV === "production" ? "id-only" : "all" | ||
| } |
There was a problem hiding this comment.
descriptorFields is a user-facing option that will often be provided from plain JS config. Right now any non-"auto" value is returned as-is (no runtime validation), so a typo like "idonly" would silently fall through and produce an unexpected output shape. Consider validating against the allowed set ("all" | "id-only" | "message" | "auto") and throwing a clear error when an invalid value is provided.
Description
Closes #2511
SWC Port lingui/swc-plugin#208
Check the issue for more info about proposal.
Types of changes
Checklist