Not able to include package.json in the patch
See original GitHub issueI was commenting on here as we are (for some unknown reason so far) not able to download the latest beta version which seem to fix the issue about the error after applying a patch.
@ds300 let me explain out situation so maybe you can point the way to go. We are having this issue: a third party package we are using has not properly set the folder directories to point to the /lib
and /es
folders.
We opened this PR for them to merge but even if that happens then the other package we want to use rc-slider. So in total this means waiting on two external PRs.
As a workaround we wanted to modify or local packages, patch them, to allow this changes which already make our build succesful but we are not able to include the package.json
file. We tried yarn patch-package rc-util --use-yarn --exclude /$.^/
as a void regexp to reenable the disbales package.json tracking for the patch but with no success.
As another workaround we modified the /es
files to patch the package but the patch-package is presenting the whitespace error This is usually caused by inconsistent whitespace in the patch file.
TL,DR: What would be the way to include package.json
in the patch?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:13
- Comments:21 (5 by maintainers)
Top GitHub Comments
The
--include
and--exclude
options are there - but they’re used when creating patches for other packages, not during postinstall (where you’re applying patches to the various npm packages). You also need to be providing the--exclude
option to override the default setting if you want to include changes to the package.json in the patch.So to use it, you would first:
node_modules/package-to-be-patched
so that they contained what you needed, thenYou won’t be able to change the dependencies in another project’s package.json, because the patch is only applied after the dependencies have been installed. But you can do things like add a typescript type definition file to a project and update its package.json file to point to your new types.
If you can add an example for disabling the default exclude, that’d be fantastic.
The other time that being able to patch package.json is desirable is when adding typescript type definitions to a package that doesn’t have its own type definitions, so that you can add the “types” field to the package’s package.json file pointing to your new type definition file.
Edit: It doesn’t seem to matter what the exclude regex is, package.json is hardcoded to be excluded in the diff inside makePatch at: https://github.com/ds300/patch-package/blob/10c0a51d8f73fe67d414ef998a3eec6a001c14ba/src/makePatch.ts#L123-L126 and: https://github.com/ds300/patch-package/blob/10c0a51d8f73fe67d414ef998a3eec6a001c14ba/src/makePatch.ts#L135-L138
At present, the only way to be able to include package.json in the diff is to first patch patch-package to comment out those two lines in the compiled code. There’s a bit of humour there in using patch-package to patch patch-package itself…
Patch: patch-package+5.1.1.patch - to allow enabling patching of package.json if you also use a regex that doesn’t include it (e.g.
--exclude '\*.txt'
).