vite-plugin-yaml icon indicating copy to clipboard operation
vite-plugin-yaml copied to clipboard

Sourcemap generation

Open tonyketcham opened this issue 3 years ago • 6 comments
trafficstars

On build, the plugin yields this warning:

[warn] Sourcemap is likely to be incorrect: a plugin (vite:transform-yaml) was used to transform files, 
but didn't generate a sourcemap for the transformation. Consult the plugin documentation for help

We should add sourcemap generation around the yaml file -> ESM conversion. A potentially useful resource to base this on could be: https://github.com/amireh/yaml-source-map

tonyketcham avatar May 21 '22 17:05 tonyketcham

Found these resources useful:

  • https://developer.chrome.com/blog/sourcemaps/#the-anatomy-of-a-source-map
  • https://github.com/tctree333/js-yaml-source-map
    • Note, this does not generate sourcemaps in the expected browser convention but provides a great resource on generating a sourcemap as js-yaml parses a file

tonyketcham avatar Oct 18 '22 08:10 tonyketcham

Is there a way to avoid having vite log this warning? I personally don't care about source maps for YAML files but I do care about warnings in the build 😉.

silverwind avatar Nov 09 '22 15:11 silverwind

I don't think sourcemaps are useful for this plugin because it outputs JS objects, where there is no way to reference a line back to the source file because JS objects have no concept of a line.

So I think this plugin should somehow indicate back to vite that it will not generate a sourcemap and hopefully that will make vite shut up.

silverwind avatar Nov 30 '22 10:11 silverwind

I think the sourcemap would be useful for mapping back through the conversion to which line in the original YAML file is incorrect, however the YAML processor essentially does that already with a well-formatted error displaying exactly which part of the file is causing an issue. Perhaps providing a null-ish source map would satisfy Vite's wants

tonyketcham avatar Dec 01 '22 00:12 tonyketcham

Of note is that the warning does not originate in vite itself, but in rollup.

Edit: also see https://rollupjs.org/guide/en/#warning-sourcemap-is-likely-to-be-incorrect

silverwind avatar Dec 01 '22 10:12 silverwind

https://github.com/Modyfi/vite-plugin-yaml/pull/9 will suppress the warning until it is figured out how to actually generate a sourcemap.

silverwind avatar Dec 20 '22 18:12 silverwind