-
Notifications
You must be signed in to change notification settings - Fork 226
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
[pub]: Support patch-package like npm #4509
Comments
Hi everyone, I was the one asking @Ahmadre about this on my adventure to learn Flutter. I have a strong Java-background and came to the NodeJS/TypeScript-world, where patches are kinda needed a lot. In case not everyone knows about the working of patch-packages, it uses the way how NodeJS works with dependencies. These are stored in a directory called To create that This way you only have to store the actual patches inside a project-specific folder, and not to modify the system pub cache (like the current existing https://pub.dev/packages/patch_package does). It would need some kind of execution-hook to run after |
I somewhat like the idea of having a set of local patches to apply on top of a package. It seems to me that I think something similar could be build for pub. Pub stores all hosted packages in the PUB_CACHE which is considered immutable and shared between therefore it should not be modified directly. But for example https://pub.dev/packages/vendor allows you to take a hosted package and inline it into a third_party folder. @jonasfj might have more ideas. (It is of course also possible to just use a dependency override and a git dependency to do this - that would probably be the preferred workflow in most cases.) |
Yes, thats an external created "addon" for a lot of NodeJS projects, but NodeJS allows to have "postinstall"-hooks, where packages can register themselves to execute custom commands (of course this can be an attack vector on its own). Having the functionality of having patches only, reduces code-duplication (be it by forking or having copying a local copy of the 3rd party lib, and using |
Each to his own - I would much prefer a git clone with layered commits that support merges.
Yeah - we don't have any plans of adding post-install hooks. You would have to run a separate command (you could though make one command wrapping |
@sigurdm I'm not sure we should completely dismiss the idea of post-install hooks in the root-package. Example:
Ofcourse this means that patch-packages like this:
There could be some overlap with build hooks here, so maybe we shouldn't jump ahead and do it just yet. On topic, I haven't seen the patch-package concept before. I've done a bunch of node.js stuff a few years ago, but I think I just monkey patched things 🤣 I did steal the idea for I think it would be cool to extend
What
Having But if you change the version of a vendored package in
It will always ask for confirmation before executing the plan. But if Yes, using
But it does have some upsides:
Personally, I'm not sure I'd love to manage patch files with git. It works for small things. And while it will scale surprisingly far, it can become very painful. Honestly, if you're not publishing you package to pub.dev, suppose you're developing a Flutter application, I'd consider:
Both of these options are painful in their own ways:
I haven't seen the patch-package concept yet, but it's somewhat interesting. It could certainly work for pub, we'd just need to copy the package from Though, if it were to happen in a third-party tool rewriting I guess that's another problem with a post-install hook, if such a post-install hook modifies Just saying: post-install hook can have negative implication for the developer user experience, it would certainly make hot-reload harder / slower, unless it just ignored it. |
Feature Request
Today I was helping a friend of mine which was developing for the first time with Flutter & Dart and he was seeing an issue with a nullable bug in a package he was using in his flutter project.
He asked me how he could instantly fix this issue locally, without forking the repository and all this overhead and without cloning the repo locally and referencing to it with pubspec.yaml?
And he was asking about if there's a
patch-package
like npm (see: https://github.com/ds300/patch-package)?I was kind of surprised as a long term flutter developer since 2019, that we don't have
patch-package
like in nodejs projects 🤔 .As a reference how exactly that works: https://dev.to/zhnedyalkow/the-easiest-way-to-patch-your-npm-package-4ece
Can we please also have
patch-package
functionality fordart pub
? It would be nice if these quickpatches
could be applied as a post-hook afterdart pub get
automatically.Environment details
Dart info:
Using following platforms:
Using following browsers:
The text was updated successfully, but these errors were encountered: