fix(dev-bundle): keep sourcemaps usable when preserving usage stats - #25709
Closed
totally-not-ai[bot] wants to merge 2 commits into
Closed
totally-not-ai[bot] wants to merge 2 commits into
totally-not-ai[bot] wants to merge 2 commits into
Conversation
The usage statistics plugin returned the code of every module it saw without a sourcemap, which drops the module from the map of its chunk. As the transform hook sees every module of the bundle, all .map files of a dev bundle built with build.sourcemap enabled came out with no sources and no mappings. Follow-up to #25691, Related to #16679
The dev bundle test application did not contain a module the usage statistics plugin rewrites, so the branch that produces a sourcemap of its own was never run. It now imports a stand-in for the @vaadin/vaadin-usage-statistics module, and the test also asserts that the comment of that module is rewritten in the built chunk. The sourcemap assertions are shared with the production bundle test instead of being copied.
|
Contributor
Contributor
Author
|
Closing as a duplicate of #25708, which has the same change to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Dev bundles built with
build.sourcemapenabled produced.mapfiles with no sources and no mappings, so the browser could not map the bundle back to the original files. The usage statistics Vite plugin now leaves untouched modules alone and emits a proper sourcemap for the one module it rewrites.What changed
Behavior change: dev bundles built with
build.sourcemapenabled now get usable.mapfiles. This only affects apps that turn sourcemaps on for the dev bundle; nothing else in the build changes, and no public Java API is removed or renamed.vite.generated.ts: thevaadin:preserve-usage-statsplugin used to return the code of every module it saw without a sourcemap. The transform hook sees all modules of the bundle, so every module was dropped from its chunk's map. The plugin now returnsnullfor modules it does not touch, which keeps the maps the bundler already has.vaadin-dev-mode:startcomment) is now rewritten withMagicString, so the plugin hands back a real sourcemap for it (magic-stringwas already a build dependency).SourceMapTestUtilinflow-test-utilwith the sourcemap assertions that were previously private toSourceMapsIT, so the production and dev bundle tests share them.@vaadin/vaadin-usage-statisticsand builds withsourcemap: true, so the rewrite branch of the plugin is actually exercised.Follow-up to #25691, related to #16679.
API Changes
com.vaadin.flow.testutil.SourceMapTestUtil
Test summary
.js.mapof a dev bundle built withsourcemap: truehas non-empty sources, non-empty mappings, and the contents of each sourcelit-view.ts) and the rewritten usage statistics module/*! vaadin-dev-mode:startand no longer the original/** vaadin-dev-mode:startconsole.errorpaths (marker missing, rewritten comment fails the regexp)DevBundleSourceMapsIT.devBundleSourceMaps_pointToOriginalSources→ rows 1, 2DevBundleSourceMapsIT.usageStatisticsComment_isRewrittenInTheBundle→ row 3SourceMapsIT.bundleSourceMapsPointToOriginalSources→ row 4 (unchanged assertions, moved intoSourceMapTestUtil)Deliberately untested: the plugin's error logging branches (row 5), and
SourceMapTestUtilitself, which is covered indirectly by every test that calls it.