Giter Site home page Giter Site logo

Comments (9)

rodnolan avatar rodnolan commented on May 4, 2024 3

the .gitattributes change fixed the problem! I decided to document the steps that I followed before I even began the experiment so I'm leaving those steps here in case someone can benefit from them.

Here are the steps I'm using to reproduce this.

cd \temp
react-native init patchpackagetest
cd patchpackagetest

yarn add --dev patch-package
react-native run-android

The sample app compiles, installs and runs without error. The next step is to add a dependency that requires a patch.

yarn add [email protected]
react-native link react-native-fbsdk

I change line 61 of FBSDKPackage.java to this:

// @Override invalid as of React Native 0.47.0 

The app compiles and runs so the next step is to generate the patch.

PS C:\temp\patchpackagetest> yarn patch-package react-native-fbsdk
yarn run v1.1.0
$ "C:\temp\patchpackagetest\node_modules\.bin\patch-package" "react-native-fbsdk"
☑ Creating temporary folder
☑ Building clean node_modules with yarn
☑ Diffing your files with clean files
✔ Created file patches/react-native-fbsdk+0.6.1.patch
Done in 70.35s.
PS C:\temp\patchpackagetest>

The generated patch file is 132,706 lines long... too big for here so I made it available [here]
instead (https://raw.githubusercontent.com/rodnolan/patchpackagetest/master/patches/react-native-fbsdk%2B0.6.1.patch).

git init .
git add .
git commit -m "generated patch file"
git remote add origin [email protected]:rodnolan/patchpackagetest.git
git push origin master

Deleted the patch file

del .\patches\react-native-fbsdk+0.6.1.patch

reinstated it

git reset --hard

dumped node_modules

del .\node_modules\*

updated package.json and committed

	"scripts": {
		"start": "node node_modules/react-native/local-cli/cli.js start",
		"test": "jest",
		"prepare": "patch-package"
	},
PS C:\temp\patchpackagetest> git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   package.json

no changes added to commit (use "git add" and/or "git commit -a")
PS C:\temp\patchpackagetest> git add .\package.json
warning: LF will be replaced by CRLF in package.json.
The file will have its original line endings in your working directory.
PS C:\temp\patchpackagetest> git commit -m 'adding patch-package script'
[master b217047] adding patch-package script
 1 file changed, 2 insertions(+), 1 deletion(-)
PS C:\temp\patchpackagetest> git push origin master
Enter passphrase for key '/c/Users/RodNolan/.ssh/rodnolan_id_rsa':
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 328 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To github.com:rodnolan/patchpackagetest.git
   0ff8eaf..b217047  master -> master
PS C:\temp\patchpackagetest>

I tried to re-install dependencies and got this nice new error message:

PS C:\temp\patchpackagetest> yarn install
yarn install v1.1.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from
stallation.
[3/4] Linking dependencies...
warning "[email protected]" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-alpha || ^7.0.0
eta || ^7.0.0".
[4/4] Building fresh packages...
$ patch-package
patch-package: Applying patches...

**ERROR** Failed to apply patch for package react-native-fbsdk

  This error was caused because Git cannot apply the following patch file:

    patches/react-native-fbsdk+0.6.1.patch

  This is usually caused by inconsistent whitespace in the patch file.


  It seems you're running Windows. Make sure you have a .gitattributes file
  in the root of your project with the following line:

    patches/*.patch eof=lf

  Then check out the patch files again to make them work properly

    rm -rf patches
    git checkout HEAD patches

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
PS C:\temp\patchpackagetest>

updated git attributes with the suggested addition, committed that change... (now I understand what you meant by the last comment!)

del .\patches\react-native-fbsdk+0.6.1.patch
git reset --hard
del .\node_modules\*

so I removed the existing patch file again, reapplied the fix, regenerated the patch with

yarn patch-package react-native-fbsdk

and got this:

diff --git a/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java b/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
index af2c3a9..d566538 100644
--- a/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
+++ b/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
@@ -58,7 +58,7 @@ public class FBSDKPackage implements ReactPackage {
         );
     }
 
-    @Override
+    // @Override react native 0.47.0 makes this invalid
     public List<Class<? extends JavaScriptModule>> createJSModules() {
         return Collections.emptyList();
     }

That's more in line with what I expected so I committed that new file and re-installed by dependencies again

del .\node_modules\*
yarn install

Bingo!

PS C:\temp\patchpackagetest> yarn install
yarn install v1.1.0
[1/4] Resolving packages...
[2/4] Fetching packages...
info [email protected]: The platform "win32" is incompatible with this module.
info "[email protected]" is an optional dependency and failed compatibility check. Excluding it from in
stallation.
[3/4] Linking dependencies...
warning "[email protected]" has unmet peer dependency "babel-core@^6.0.0 || ^7.0.0-alpha || ^7.0.0-b
eta || ^7.0.0".
[4/4] Building fresh packages...
$ patch-package
patch-package: Applying patches...
[email protected] ✔
Done in 24.68s.
PS C:\temp\patchpackagetest>

Thanks for this fix!

from patch-package.

ds300 avatar ds300 commented on May 4, 2024 1

I've figured out what's causing this issue, and it goes away if I re-write the patch files to get rid of CRLFs before applying them, regardless of whether the source files they're patching have CRLFs or just LFs. I'll push a fix out tonight.

from patch-package.

ds300 avatar ds300 commented on May 4, 2024

Thanks for the detailed report. I was hoping naïvely that that particular error message would only be shown when the versions do not match, but there seems to be some inconsistency with whitespace on Windows which means that perfectly good patches are not able to be applied by Git. I managed to fix this for a colleague by having him set core.autocrlf to true in the git global config, the re-clone the repo. This didn't help the reporter of #19 however. Still looking in to it, will keep you posted.

from patch-package.

ds300 avatar ds300 commented on May 4, 2024

This should be fixed now so I'll close this issue too. Thanks again for your report! If the issue remains for you please re-open this.

from patch-package.

rodnolan avatar rodnolan commented on May 4, 2024

I'm experiencing the same issue with version 3.4.1 unfortunately. I'm patching a different package but I get the exact same result.

...
Info:
    Patch was made for version 0.6.1
    Meanwhile node_modules/react-native-fbsdk is version 0.6.1
...

from patch-package.

rodnolan avatar rodnolan commented on May 4, 2024

Upon further investigation, I discovered that the patch generated by version 3.4.1 is 132,150 lines long. The only change I made was to comment out a single line in the original file. The patch file that was being generate by version 3.4.0 looked like this:

diff --git a/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java b/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
index af2c3a9..e862659 100644
--- a/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
+++ b/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBSDKPackage.java
@@ -58,7 +58,8 @@ public class FBSDKPackage implements ReactPackage {
         );
     }
 
-    @Override
+    // @Override
+    // removed in rn 0.47.0
     public List<Class<? extends JavaScriptModule>> createJSModules() {
         return Collections.emptyList();
     }

from patch-package.

ds300 avatar ds300 commented on May 4, 2024

Can you check whether you had Xcode running when you made the patch? Xcode edits files in node_modules while it's running. If not, mind zipping up the patch file for me to take a look at?

I'm looking into the other issue now.

from patch-package.

ds300 avatar ds300 commented on May 4, 2024

I've double-checked and 3.4.1 at least fixed the version of this issue that I managed to reproduce which was this:

  1. edit some file in node_modules/blah
  2. run yarn patch-package blah to create a patch file
  3. delete node_modules and run yarn to make sure the patch still applies
  4. commit the patch file
  5. delete the patch file
  6. git reset --hard to reinstate the patch file
  7. delete node modules
  8. run yarn again to apply the patch, but it fails

Does that differ from what you're doing?

from patch-package.

ds300 avatar ds300 commented on May 4, 2024

@rodnolan I reverted the change I made last night in light of #21 - Can you let me know how you fare with .gitattributes set up correctly and [email protected]?

from patch-package.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.