unjs / unplugin

Unified plugin system for Vite, Rollup, Webpack, esbuild, Rolldown, and more
https://unplugin.unjs.io
MIT License
2.9k stars 104 forks source link

fix(esbuild): sourcemaps in transform result can be a string #377

Closed snowystinger closed 3 months ago

snowystinger commented 3 months ago

πŸ”— Linked issue

Brought up over here https://github.com/devongovett/unplugin-parcel-macros/issues/4

❓ Type of change

πŸ“š Description

The type cast to any on https://github.com/unjs/unplugin/blob/867b71d8f52a6fe8b32b0de801cdf3351da6ff79/src/esbuild/index.ts#L288 was hiding a bug where the result could be a string. When it was, you'd get an error such as Cannot create property 'sourcesContent' on string '{"version":3,"sources":["test.js"]

I'm not quite sure how to write a test for this, though, as I'm not entirely sure how this actually occurs other than possibly when passed across languages, ie rust to js. Any pointers are welcome. I'd thought to change https://github.com/unjs/unplugin/blob/867b71d8f52a6fe8b32b0de801cdf3351da6ff79/test/fixtures/transform/unplugin.js#L35 by wrapping it in a JSON.stringify, but that didn't work.

πŸ“ Checklist