Skip to content

Instantly share code, notes, and snippets.

@chu-yik
Created December 21, 2018 14:43
Show Gist options
  • Save chu-yik/9004085ca73cda971fe7097963859968 to your computer and use it in GitHub Desktop.
Save chu-yik/9004085ca73cda971fe7097963859968 to your computer and use it in GitHub Desktop.
How to fix whitespace in .patch file

Fix whitespace in .patch files

  1. go to package.json and remove postinstall from scripts
  • i.e. remove this line:
"postinstall": "patch-package && rm -f ./node_modules/react-native/local-cli/core/__fixtures__/files/package.json",
  • this is to stop broken patches from being auto applied after yarn
  • DO NOT commit this change
  1. do a clean yarn
rm -rf node_modules && yarn
  • or run the full set command here
  • this step should NOT produce error, if it does, you might have done something wrong in #1
  1. test your .patch by git apply
git apply patches/rn-collapsing-tab-bar+0.1.4.patch
  • this should show a bunch of warnings / errors:
patches/rn-collapsing-tab-bar+0.1.4.patch:51: trailing whitespace.
        
patches/rn-collapsing-tab-bar+0.1.4.patch:115: trailing whitespace.
		
patches/rn-collapsing-tab-bar+0.1.4.patch:129: trailing whitespace.
	 
patches/rn-collapsing-tab-bar+0.1.4.patch:149: trailing whitespace.
			(isExpanded  
patches/rn-collapsing-tab-bar+0.1.4.patch:150: trailing whitespace.
			? this.collapsableBarHeight/2 
error: patch failed: node_modules/rn-collapsing-tab-bar/index.js:179
error: node_modules/rn-collapsing-tab-bar/index.js: patch does not apply

  • this step is just to let you understand how bad your patch is... :P
  1. ask git apply to fix whitespace while applying your .patch
  • do:
git apply --whitespace=fix patches/rn-collapsing-tab-bar+0.1.4.patch
  • this should apply your patch and fix any bad whitespace(s):
warning: squelched 5 whitespace errors
warning: 8 lines applied after fixing whitespace errors.
  1. generate your .patch again
yarn patch-package rn-collapsing-tab-bar
  1. revert changes in step #1 and test
rm -rf node_modules && yarn
  • if this produce no error then the .patch file should be good
  • push changes and be done :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment