-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
fix: load PostCSS plugins based on the current file path instead of process.cwd() #229
Conversation
I like your way to look file from config path |
Released in 3.1.2 |
Wow, that was fast :) Thank you! |
This change broke the loading of plugins defined as follows:
I'm running postcss from the directory where the config file is located and the lib folder is in that directory. The message I get is:
Based on what I'm observing, I don't think this change should have been made in a patch release. This seems to a breaking change, which should have warranted a major release. I'm also curious to know why it can't find the file that seems to be in the right place, but there are ways I can work around it.
|
It shouldn't really be a breaking change since it didn't intentionally break something, you probably just found a bug. Could you possibly recreate it in a GH repo? so it can be debugged |
Changing the mechanism for how modules and scripts are required is a breaking change. The issue clearly states that the behavior is being changed. If you don't want to adhere to semver, that's your choice. But you can't argue that this is a patch fix. It's already reproducible with an existing GH repo. You can see the problem in this build: https://github.com/asciidoctor/asciidoctor/runs/5150765869?check_suite_focus=true build from this commit hash: https://github.com/asciidoctor/asciidoctor/tree/1cfe82949c2634e4efa145c23be3014711575708/src/stylesheets |
This line:
changed to this line:
That's not a patch fix. And the description of this PR starts with "Notable Changes". Nothing about a patch release should be notable. |
The difference is that the |
@mojavelinux I tend to agree that a major version is warranted if the official API has changed. I'm not very familiar with this project, so I'm not sure whether or not the relative path syntax you're using was ever part of the official API. I don't see such examples in the README or in tests, so I'm not sure. Given the likelihood that other people are affected by this change of behaviour, documented or not, perhaps it would make sense to revert this PR, release another patch including the revert, then revert the revert and release a major version? In addition, we may want to add your particular example to the README, using That way we're all happy :) |
It is, and that isn't what we did here. We tried to fix the mechanism as it contained a bug. Point is, if it worked bug-free, you would've never noticed because it wouldn't have been "breaking". The fact you (probably) discovered a bug makes it seem breaking. Anyway, i'll see if i can take a look unless andrey beats me to it |
@fwouts Sounds very reasonable to me. I had followed a tutorial somewhere that explained how to set up a custom PostCSS rule inside the project. Unfortunately, I can't recall the location of that tutorial. But that's how I knew to use the relative path. I'm happy to contribute a change to the documentation to show that you can use a standalone JS file, but that it must be specified as an absolute path. As I stated above, I understand what's now required. I posted to make you aware that it broke my build and it has the potential to break others. And, naturally, people don't expect a patch release to break things. That's why I brought it up. |
@ai FYI the problem here is that we had since we don't pass a directory anymore, but a file, this results in if we always pass a file path to const require = create(rootFile); then if we ever want to resolve from a directory, do the resolve at the call-site rather than inside |
Yeap, please send PR. |
@43081j’s fix was released in 3.1.3. @mojavelinux old behaviour was a bug (and was not officially documented). Of course, we can be extra-cautiou and release notable fixes as major changes, but PostCSS ecosystem is very slow for updates. It could take a years to update all tools using We can document new behaviour and make in official. Please, send PR. |
Thanks for the fix. I'll proceed with a PR to the docs. |
Notable Changes
Currently, postcss-load-config can only work when the desired PostCSS plugins can be loaded from
process.cwd()
. It does not work, for example, when postcss-load-config is used to load a PostCSS config file from a different directory, and that PostCSS config file uses a plugin that isn't available in the current working directory.Until #227, a workaround was to call
process.chdir()
before invoking postcss-load-config, as it would appropriately update the require path and find the PostCSS plugins. This workaround was discussed in vitejs/vite#4000 for example.Since #227,
process.cwd()
is invoked once at module initialisation time, which is a subtly different behaviour fromimport-cwd
which invokedprocess.cwd()
repeatedly on every require (see https://github.com/sindresorhus/import-cwd/blob/8e204cbf8b4fc0743e4ebeebd0acfbbd17fee87b/index.js#L4). This broke the workaround of callingprocess.chdir()
since it would have no effect on later invocations of postcss-load-config.A better approach was suggested by @43081j in vitejs/vite#4000 (comment), which relies on using the PostCSS config file as the search path for loading PostCSS plugins, instead of
process.cwd()
. This seems sensible, and all tests pass, but I may be missing a subtle requirement here.If this behaviour isn't desirable, we could at least restore the old workaround by replacing:
with:
(effectively deferring the call to
process.cwd()
)Commit Message Summary (CHANGELOG)
Type
SemVer
Issues
Checklist