For my netlify site apolloelements.dev (apollo-elements), I use patch-package to patch files in node_modules. I run patch-package in postinstall. This works great when the node_modules cache is clear, or if the cache hits but there are no changes in patches/*.diff
Netlify already automatically busts the node_modules cache whenever package.json (or package-lock.json?) changes. I’d like to add patches/*.diff to that list so that changes there also invalidate the cache.
I think you’ve correctly characterized the behavior shown here in our build-image:
which does this comparison:
…which has the basic effect you describe.
I don’t know of a way for you to accomplish that goal directly, but perhaps you could wrap the postinstall step in a conditional clause, since the error status returned to the shell is what causes the build to be marked as failed:
I don’t know what you can do in a postinstall script, but I’d guess it can be a shell script that you could catch that error on and self-clear the cache if you want to, or carry on without the patch (return 0 from the process even though patching failed), if you don’t need to do anything?
If you need to “do something” to fix things, such as say clearing your cache, you could from inside the script I describe, when you detect the patch system failing, choose to make an API call (you’ll want to set your API token as an environment variable in the UI to keep it safe and out of your public codebase: Netlify App) to the URL we use to trigger a build with cache cleared, before exiting the script with a non-zero status to terminate that build and allow the new one to start up.
What’s that API call?
POST https://api.netlify.com/api/v1/sites/SITE-ID-HERE/builds
If you do plan a PR, I’d still start with an issue filed there (feel free to ping back here with a link and we’ll make sure the team reviews ASAP!) and explain your plans so the team can review and ensure they think you’re working in a direction they can support, since we can’t merge a PR that breaks things for other customers and there may even be some works in progress that I don’t know about to support this already
The problem isn’t that the build fails necessarily, the build might even pass, but the cached node_modules mean I don’t receive the changes I made in the patch. This might have the effect of breaking a page in my app because it’s dependencies aren’t patched before the build.
Hi, @bennypowers. It took me a minute to understand the feature request and I think grok it now. I’ve made a comment in the issue filed to clarify exactly which code needs to be changed.
If you do have a PR which fixes this, please to feel free to share it via that repo.