Skip to content
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

Don't warn about mismatched versions when using multiple patches for the same library #541

Open
elliottkember opened this issue Oct 31, 2024 · 1 comment · May be fixed by #542
Open

Don't warn about mismatched versions when using multiple patches for the same library #541

elliottkember opened this issue Oct 31, 2024 · 1 comment · May be fixed by #542

Comments

@elliottkember
Copy link

elliottkember commented Oct 31, 2024

I just found out about #43 which will make our patches really easy to work with by separating patches from each other. What a great feature!

Unfortunately we have enabled --error-on-warn to ensure we keep our patches up to date, and so the warnings we get from multi-patch names causes our builds to break.

I've patched patch-package with patch-package locally to skip + version patches, to work around this and avoid the warning. I'm sure there are some gotchas with the .includes('+') syntax I've used here (NPM versions that include the + character?) but I thought I should submit this as an issue to see whether it could be applied.

Here is the diff that solved my problem:

diff --git a/node_modules/patch-package/dist/applyPatches.js b/node_modules/patch-package/dist/applyPatches.js
index c0217cf..90f3eda 100644
--- a/node_modules/patch-package/dist/applyPatches.js
+++ b/node_modules/patch-package/dist/applyPatches.js
@@ -92,13 +92,19 @@ function applyPatchesForApp({ appPath, reverse, patchDir, shouldExitWithError, s
                 // yay patch was applied successfully
                 // print warning if version mismatch
                 if (installedPackageVersion !== version) {
-                    warnings.push(createVersionMismatchWarning({
-                        packageName: name,
-                        actualVersion: installedPackageVersion,
-                        originalVersion: version,
-                        pathSpecifier,
-                        path,
-                    }));
+                    // Ignore multi-patch versions
+                    if (version.includes('+') && version.split('+')[0] === installedPackageVersion) {
+                        console.log("Ignoring multi-patch version mismatch for", pathSpecifier);
+                    } else {
+                        warnings.push(createVersionMismatchWarning({
+                            packageName: name,
+                            actualVersion: installedPackageVersion,
+                            originalVersion: version,
+                            pathSpecifier,
+                            path,
+                        }));
+                        
+                    }
                 }
                 console.log(`${chalk_1.default.bold(pathSpecifier)}@${version} ${chalk_1.default.green("✔")}`);
             }

This issue body was partially generated by patch-package ❤️

@elliottkember
Copy link
Author

Oops, a side note – turns out the local patch of patch-package doesn't work, because it only applies the patch after installation. This means in CI, when the packages are all checked out fresh, the patch-package patch isn't applied and the warning persists!

@elliottkember elliottkember linked a pull request Oct 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant