Repository navigation
feat(vue-extractor): make the underlying extractor configurable - #2729
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2729 +/- ##
===========================================
+ Coverage 77.05% 89.94% +12.89%
===========================================
Files 84 138 +54
Lines 2157 4474 +2317
Branches 555 1336 +781
===========================================
+ Hits 1662 4024 +2362
- Misses 382 401 +19
+ Partials 113 49 -64 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for the review.
|
|
i think it's worth merging/releasing this one first lingui/swc-plugin#287 (review) Then bump a version of native-tools here and drop workarounds and related tests. |
|
Sounds good. Once a |
|
Hi @ybai08, I just released the new version of |
`createVueExtractor({ extractor })` passes the code compiled from .vue
files to the given extractor instead of the Babel one, so Vue projects
can use the SWC extractor from @lingui/native-tools.
The source maps are also inlined into that code, as the SWC extractor
reads inline source maps but not `ctx.sourceMaps`, so positions still
point into the .vue file.
Closes lingui#2719
…ools reads ctx.sourceMaps @lingui/native-tools 0.2.0 (lingui/swc-plugin#287) makes the SWC extractor read ctx.sourceMaps, so the inline copy of the map is no longer needed. Bump the dev dependency to ^0.2.0, as cli and vite-plugin use.
e6e92b0 to
3f96bd0
Compare
|
Thanks for the release, @andrii-bodnar, and sorry this took a week. Done in 3f96bd0:
I also rebased onto After
|
andrii-bodnar
left a comment
There was a problem hiding this comment.
@ybai08 thank you!
Description
This implements the API proposed in #2719.
createVueExtractor()accepts anextractoroption, which receives the code compiled from the.vuefile instead of the hardcoded Babel extractor:The default is still the Babel extractor, so existing configs behave the same.
One extra change was needed for the SWC extractor. The Vue extractor passes each block's source map as
ctx.sourceMaps, andcreateSwcExtractor()(native-tools 0.1.6) doesn't read it. It does read an inline//# sourceMappingURL=data:...comment, though. Without that, template messages ended up with positions inside the compiled render function (test.vue.ts:4,test.vue.ts:8) rather than in the.vuefile. The Vue extractor now inlines the map into the code it passes on, in addition toctx.sourceMaps. Babel still usesctx.sourceMapsfirst, and the existing snapshots don't change. If you'd rather havecreateSwcExtractorreadctx.sourceMapsin native-tools, I can drop this part.With the SWC extractor, file and line now match the Babel extractor for every message in the fixture. Columns still differ, because the two extractors count them differently (for example 21 vs 20 for the same call), so the test compares file and line only.
<script setup>messages report the wrong file and line no matter which extractor runs, because Vue doesn't generate a source map for that block. That fix is a separate PR (#2728). The two PRs touch the same lines invue-extractor.ts, so whichever merges second needs a small rebase. With both changes applied together, the extractor-vue tests pass.The
vue/compiler-sfcpeer dependency idea from the issue comment isn't part of this PR.Types of changes
Fixes #2719
Checklist
Tests:
<script>,<script setup>and<template>code along with the source map.createSwcExtractor()runs through the Vue extractor on the existingtest.vuefixture. Its ids, messages, comments, files and lines must equal what the Babel path gives.@lingui/native-toolsis added as a devDependency of@lingui/extractor-vuefor that test. Without the change invue-extractor.ts, the first test fails. With the option but without the inlined map, the second one fails.Docs: there is a new "Underlying Extractor" section in
website/docs/ref/extractor-vue.md.Commands run (Node 22.23, after
yarn release:build):yarn vitest --run packages/extractor-vue: 6 passedyarn test: 94 files, 1612 passed, 2 skippedyarn lint:eslint,yarn workspace @lingui/extractor-vue check-types,prettier --checkon the package and the doc page: cleanlingui extractwithextractors: [swc, createVueExtractor({ extractor: swc })]ontest.vue: all 6 messages extracted, withApp.vue:<line>referencesNot run:
yarn test:e2e,yarn test:types, and the docs site build (website/isn't installed).