New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pass real filepath to transform plugins #3483
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/DJ1gRy7xY8XrnWgepjnBiL7SDL2N |
@@ -181,7 +181,7 @@ async function runPipelineTransformStep( | |||
isDev, | |||
isPackage, | |||
fileExt: destExt, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s important that fileExt
not change! That would basically break all transform plugins
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ Tests look good, this PR looks good to go!
Before I merge, I’ll take a look at our most-used plugins and double-check this won’t break anything. If not, then we can push this in a patch and improve PostCSS support without needing to release the PostCSS plugin too. |
dd9f11e
to
eaa0096
Compare
Update: I found that this change would actually break an internal plugin in |
@@ -37,7 +37,7 @@ module.exports = function postcssPlugin(snowpackConfig, options) { | |||
|
|||
const encodedResult = await worker.transformAsync(contents, { | |||
config, | |||
filepath: id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id
is used in other parts of this file, and I believe those should stay as-is. This is the only line that causes errors, because filepath
needs to point to a real file on disk
@drwpow totally in favor of that, good call! |
Changes
In the dev server, our
transform
plugins receive a pseudo-URL, which neither exists on disk nor really at the final URL (but probably closer to the latter). The root cause here is when working with PostCSS on transformed files, you’ll get the following error:More details here: withastro/astro#481
Because we weren’t passing a real location on disk to PostCSS, it would fail running on any CSS that was generated from a non-
.css
file (e.g..astro
,.pcss
,.vue
, etc.)This PR adds a new
srcPath
option to plugins which is backwards-compatible, and fixes the original error.Testing
Tested manually; fixes the error and doesn’t cause any other known issues.
Docs
No docs changes needed