Skip to content

feat!: Consolidate Metadata Transformation Options into descriptorFields#2513

Open
timofei-iatsenko wants to merge 2 commits intonextfrom
feat/descriptorFields
Open

feat!: Consolidate Metadata Transformation Options into descriptorFields#2513
timofei-iatsenko wants to merge 2 commits intonextfrom
feat/descriptorFields

Conversation

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

@timofei-iatsenko timofei-iatsenko commented Apr 14, 2026

Description

Closes #2511

SWC Port lingui/swc-plugin#208

Check the issue for more info about proposal.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Examples update

Checklist

  • I have read the CONTRIBUTING and CODE_OF_CONDUCT docs
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
js-lingui Ready Ready Preview Apr 14, 2026 11:34am

Request Review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 14, 2026

size-limit report 📦

Path Size
packages/core/dist/index.mjs 1.69 KB (0%)
packages/detect-locale/dist/index.mjs 618 B (0%)
packages/react/dist/index.mjs 1.22 KB (0%)

Copy link
Copy Markdown

Copilot AI left a comment

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 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 / stripMessageField plugin options with descriptorFields (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 context is preserved when keeping message.

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.

Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
> **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.

Copilot uses AI. Check for mistakes.
Comment on lines +65 to 71
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"
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants