patch-package
patch-package copied to clipboard
Patch is unrecognized if it is for a version prefixed with a 'v'
This package happily creates a diff patch for a package that has a version starting with a 'v' but then fails to apply that patch, throwing the following warning:
Unrecognized patch file in patches directory serverless-plugin-aws-alerts+v1.7.3.patch
If I edit PackageDetails.js to drop the 'v' from the version, it somehow just works:
function parseNameAndVersion(s) {
const parts = s.split("+");
parts[1] = '1.7.3'
switch (parts.length) {
The logic in parseNameAndVersion
seems odd to me as you are returning the package name as name/version if the version doesn't match a regex of digits:
return { name: `${nameOrScope}/${versionOrName}` };
Yet, in getPackageDetailsFromPatchFilename
you explicitly expect that you will have a version key in a map after returning from parseNameAndVersion
:
const lastPart = parts[parts.length - 1];
if (!lastPart.version) {
return null;
}
Seems you assume that if versionOrName
isn't a digit then the parts must correspond to scope/name, which is false in this case.
In my case, the obvious work-around that somehow works is to drop the 'v' from the patch name, but this isn't obvious to anyone who expects the plugin to just work out of the box. :)
This should be fixed as it effectively breaks the entire purpose.
Oh my, you just saved my whole works 🙏. I don't understand why this hasn't been fixed yet.
really, why this is not fixed yet?
I managed to work around the issue I was going to patch a completely different way so I haven't tested this let alone put up a PR -- but skimming the code, this regex here:
https://github.com/ds300/patch-package/blob/c7c63bf80b3c6b8640b933e20229121b4edfc100/src/PackageDetails.ts#L39
Does it fix to change that to
part.match(/^v?\d+\.\d+\.\d+.*$/)
That's probably not a "great" fix -- assuming versions have a format at all is maybe not a good idea and the code should maybe be refactored? -- but might help with the immediate issue here?
I can confirm, running a command like npx patch-package @pulumi/aws
produces a file called @pulumi+aws+v5.13.0.patch
, which results in Unrecognized patch file in patches directory @pulumi+aws+v5.13.0.patch
After renaming the file to @pulumi+aws+5.13.0.patch
(removing the v
), the problem is gone.