ds300 / patch-package

Fix broken node modules instantly 🏃🏽‍♀️💨
MIT License
10.32k stars 288 forks source link

Patch fails when created with v5 #36

Closed rt2zz closed 6 years ago

rt2zz commented 6 years ago

I get the following

This error was caused because Git cannot apply the following patch file:
    patches/react-scripts+1.0.17.patch
  This is usually caused by inconsistent whitespace in the patch file.

when CI tries to apply the patch that I created locally (OSX) with patch package 5. Downgrading to v3 resolves the issue.

ds300 commented 6 years ago

Thanks for the report! Hope you don't mind answering a couple more questions:

  1. What's your CI env like? Linux? Git version?
  2. Did you re-create the patch file after downgrading? Or is it the one you made with v5?
rt2zz commented 6 years ago
  1. CI i travis, default setup linux. Not sure about git version...
  2. yes, I had to recreate the patch. Specifically here was my proces
    1. upgrade to v5
    2. update patch
    3. CI fail
    4. downgrade to v3
    5. CI still fail
    6. recreate patch

Since the patch always applied fine locally, unfortunately I did not have the constitution to debug further on travis. My local git is 2.15

ds300 commented 6 years ago

Thanks for those details. I'm going to look into this over the next week or so. Probably going to end up doing pure-JS patch application if I can. git-apply has been giving me a lot of grief -_-

rt2zz commented 6 years ago

cool, I love this package btw! thank you.

FWIW v3 is working great atm

mauritsd commented 6 years ago

I think I'm having the same issue, but downgrading to v3 doesn't fix the problem for me:

I get the following error after 'yarn':

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

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

    patches/react-native-maps+0.19.0.patch

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

If I manually try to apply the patch with "git apply -v --ignore-whitespace patches/react-native-maps+0.19.0.patch":

Checking patch node_modules/react-native-maps/lib/components/MapView.js.orig...
Checking patch node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMap.m...
Checking patch node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m...
error: while searching for:

@interface AIRGoogleMapManager() <GMSMapViewDelegate>
{
  BOOL didCallOnMapReady;
}

@end

error: patch failed: node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m:32
error: node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m: patch does not apply

If I check AIRGoogleMapManager.m:32 the content it's looking for seems to be there, but it's still failing somehow... If I apply using GNU patch with --ignore-white-space/-l set it does apply (ignore me forgetting to specify it's a unified diff ;-)):

Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|patch-package
|new file mode 100644
|--- /dev/null
|+++ b/node_modules/react-native-maps/lib/components/MapView.js.orig
--------------------------
Patching file node_modules/react-native-maps/lib/components/MapView.js.orig using Plan A...
Hunk #1 succeeded at 1.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- a/node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMap.m
|+++ b/node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMap.m
--------------------------
Patching file node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMap.m using Plan A...
Hunk #1 succeeded at 34.
Hunk #2 succeeded at 50.
Hunk #3 succeeded at 152.
Hmm...  The next patch looks like a unified diff to me...
The text leading up to this was:
--------------------------
|--- a/node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m
|+++ b/node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m
--------------------------
Patching file node_modules/react-native-maps/lib/ios/AirGoogleMaps/AIRGoogleMapManager.m using Plan A...
Hunk #1 succeeded at 32.
Hunk #2 succeeded at 318.
done
ds300 commented 6 years ago

Thanks for this @mauritsd — I should have some time this weekend to take a look at making the patch application js-based rather than using Git, which seems to have quite flaky behaviour across platforms and versions.

ds300 commented 6 years ago

I looked into doing pure-js patch application and I think it would be a lot of work and there would be a bunch of edge cases to deal with, some of which I'm probably not going to anticipate before publishing.

Something I could do to mitigate this problem in the meantime would be to use patch to apply patches on *nix machines and fall back to git apply on windows. For some reason patch seems to be a lot less flaky than git apply

mauritsd commented 6 years ago

That'd be fine; I'm also on macOS.

Is there a definitive diagnosis as to why 'git apply' fails? I'll have a look at the patch file and the destination file with a hex editor...

mauritsd commented 6 years ago

I've figured out why it fails in my particular instance. When patch-package generates the diff it specifies the --ignore-space-at-eol option to git-diff. Through testing I've found out that this, when coupled with indented lines without content (e.g. " \n"), will cause git-diff to generate patch files which are not accepted by git-apply, even with --ignore-whitespace and friends. If I remove the --ignore-space-at-eol option from patch-package the patch file is a bit less clean but does apply.

Maybe an idea to allow the user to specify which git-diff options to use?

ds300 commented 6 years ago

Thanks for the investigation! Maybe I should just not use the --ignore-space-at-eol flag? Allowing configuration of the git command would let people solve these issues on their own, but man I'd love to have something that just works for everyone. Feels like that should exist too.

On Tue, 30 Jan 2018, 15:52 Maurits Dijkstra, notifications@github.com wrote:

I've figured out why it fails in my particular instance. When patch-package generates the diff it specifies the --ignore-space-at-eol option to git-diff. Through testing I've found out that this, when coupled with indented lines without content (e.g. " \n"), will cause git-diff to generate patch files which are not accepted by git-apply to fail, even with --ignore-whitespace and friends. If I remove the --ignore-space-at-eol option from patch-package the patch file is a bit less clean but does apply.

Maybe an idea to allow the user to specify which git-diff options to use?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ds300/patch-package/issues/36#issuecomment-361637048, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL1qdeMznUVIzjdwFoeG7peBX7TVN5Xks5tPzqfgaJpZM4Q-Wpv .

mauritsd commented 6 years ago

I think the 'right' course of action is to fix git-apply, but that's more of a long term solution...

By the way, git-merge does have an option to ignore spaces at EOL (-Xignore-space-at-eol).

dinvlad commented 6 years ago

Same issue here with v5 and CircleCI. Patches appear flaky from one build to another (e.g. it succeeds if I install packages on my local Mac using Yarn with --frozen-lockfile, but the same command fails in Circle). Is there a suggested workaround? Thx

EDIT: the problem reappears even when I regenerate the patch (either via patch-package and diff -u) on a local Linux system.

dinvlad commented 6 years ago

Moreover, downgrading to v5.0.0 (which has been working for me for an entire month) does fix the problem. So it seems there might have been some regression in the last 2 releases (5.1.0/5.1.1).

ds300 commented 6 years ago

Thanks for the report. Weird that for you 5.1 is flaky but 5.0 is not. I didn't change the way git apply is invoked except to potentially re-order the cli options. It would be funny if that's causing the issue.

As a temporary workaround you could call patch instead of patch-package in your prepare hook. See the README for an example. I'm planning to make patch-package use it by default soon.

dinvlad commented 6 years ago

Hmm, I've just had this problem with 5.0 as well. Updated to 5.1.1 and now it works again! Not sure why it was misbehaving earlier - will update if anything changes again. Thanks

ds300 commented 6 years ago

😂 😩 Must find some time to fix this soon. Thanks for the update.

dinvlad commented 6 years ago

I think it has something to do with caching of node_modules (that is what I use in CircleCI at least). If yarn.lock hasn't changed, my config will re-use the cached versions of all packages. But if a package was updated, even though I run yarn --frozen-lockfile in CI, it may still update that package without an error. Not sure how this would lead to inconsistency with the applied patch (apart from direct incompatibility with the new version of the package, though I do check that it works on my local system before CI). But purging the cache seems to help (not always though, it seems).

brunolemos commented 6 years ago

I'm having this bug. I have 4 old patches that work fine, but the 5th doesn't:

patch-package: Applying patches...
react-native@0.54.0 ✔

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

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

    patches/react-native-camera+1.0.2.patch

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

Log

See npm log ``` 77 info lifecycle app@2.12.1~prepare: app@2.12.1 78 verbose lifecycle app@2.12.1~prepare: unsafe-perm in lifecycle true 79 verbose lifecycle app@2.12.1~prepare: PATH: /Users/brunolemos/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/brunolemos/Projects/g2i/app/app-native/node_modules/.bin:/Users/brunolemos/.fastlane/bin:/Users/brunolemos/.rvm/gems/ruby-2.4.0/bin:/Users/brunolemos/.rvm/gems/ruby-2.4.0@global/bin:/Users/brunolemos/.rvm/rubies/ruby-2.4.0/bin:/Users/brunolemos/.rvm/gems/ruby-2.4.0/bin:/Users/brunolemos/.npm-global/bin:/usr/local/bin/mongo/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/brunolemos/Library/Android/sdk//bin:/Users/brunolemos/Library/Android/sdk/platform-tools/:/Users/brunolemos/.rvm/bin 80 verbose lifecycle app@2.12.1~prepare: CWD: /Users/brunolemos/Projects/g2i/app/app-native 81 silly lifecycle app@2.12.1~prepare: Args: [ '-c', 'patch-package' ] 82 silly lifecycle app@2.12.1~prepare: Returned: code: 1 signal: null 83 info lifecycle app@2.12.1~prepare: Failed to exec prepare script 84 verbose stack Error: app@2.12.1 prepare: `patch-package` 84 verbose stack Exit status 1 84 verbose stack at EventEmitter. (/Users/brunolemos/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16) 84 verbose stack at emitTwo (events.js:126:13) 84 verbose stack at EventEmitter.emit (events.js:214:7) 84 verbose stack at ChildProcess. (/Users/brunolemos/.npm-global/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 84 verbose stack at emitTwo (events.js:126:13) 84 verbose stack at ChildProcess.emit (events.js:214:7) 84 verbose stack at maybeClose (internal/child_process.js:925:16) 84 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) 85 verbose pkgid app@2.12.1 86 verbose cwd /Users/brunolemos/Projects/g2i/app/app-native 87 verbose Darwin 17.4.0 88 verbose argv "/usr/local/bin/node" "/Users/brunolemos/.npm-global/bin/npm" "install" 89 verbose node v8.9.0 90 verbose npm v5.7.1 91 error code ELIFECYCLE 92 error errno 1 93 error app@2.12.1 prepare: `patch-package` 93 error Exit status 1 94 error Failed at the app@2.12.1 prepare script. 94 error This is probably not a problem with npm. There is likely additional logging output above. 95 verbose exit [ 1, true ] ```

Env

macOS 10.13.3 nodejs 8.9.0 npm 5.7.1 patch-package 5.1.1 react-native 0.54.0 react-native-camera 1.0.2 (pull request)

Patch

See full patch content ```diff patch-package --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorManager.h +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorManager.h @@ -8,13 +8,17 @@ #import #import +#if __has_include() #import #import +#endif + @protocol RNFaceDetectorDelegate - (void)onFacesDetected:(NSArray *)faces; @end +#if __has_include() @interface RNFaceDetectorManager : NSObject - (NSDictionary *)constantsToExport; @@ -31,3 +35,4 @@ - (void)stopFaceDetection; @end +#endif --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorManager.m +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorManager.m @@ -5,6 +5,7 @@ // Created by Joao Guilherme Daros Fidelis on 21/01/18. // +#if __has_include() #import #import "RNCamera.h" #import "RNFaceEncoder.h" @@ -272,3 +273,4 @@ static NSDictionary *defaultFaceDetectorOptions = nil; } @end +#endif --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorModule.h +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorModule.h @@ -6,7 +6,9 @@ // #import +#if __has_include() #import +#endif @interface RNFaceDetectorModule : NSObject @end --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorModule.m +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorModule.m @@ -5,6 +5,7 @@ // Created by Joao Guilherme Daros Fidelis on 21/01/18. // +#if __has_include() #import "RNFaceDetectorModule.h" #import "RNFaceEncoder.h" #import "RNFileSystem.h" @@ -193,3 +194,4 @@ RCT_EXPORT_METHOD(detectFaces:(nonnull NSDictionary *)options } @end +#endif --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorUtils.h +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorUtils.h @@ -5,6 +5,7 @@ // Created by Joao Guilherme Daros Fidelis on 21/01/18. // +#if __has_include() #import #import #import @@ -33,3 +34,4 @@ typedef NS_ENUM(NSInteger, RNFaceDetectionClassifications) { + (CGAffineTransform)transformFromDeviceOutput:(GMVDataOutput *)dataOutput toInterfaceVideoOrientation:(AVCaptureVideoOrientation)interfaceVideoOrientation; @end +#endif --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorUtils.m +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceDetectorUtils.m @@ -5,6 +5,7 @@ // Created by Joao Guilherme Daros Fidelis on 21/01/18. // +#if __has_include() #import "RNCameraUtils.h" #import "RNFaceDetectorUtils.h" #import "RNFaceDetectorPointTransformCalculator.h" @@ -75,3 +76,4 @@ NSString *const RNGMVDataOutputHeightKey = @"Height"; } @end +#endif --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceEncoder.h +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceEncoder.h @@ -6,6 +6,7 @@ // #import +#if __has_include() #import @interface RNFaceEncoder : NSObject @@ -15,3 +16,4 @@ - (NSDictionary *)encode:(GMVFaceFeature *)face; @end +#endif --- a/node_modules/react-native-camera/ios/FaceDetector/RNFaceEncoder.m +++ b/node_modules/react-native-camera/ios/FaceDetector/RNFaceEncoder.m @@ -7,6 +7,7 @@ #import "RNFaceEncoder.h" +#if __has_include() #define cDefaultFloatComparisonEpsilon 0.0001 #define cModEqualFloatsWithEpsilon(dividend, divisor, modulo, epsilon) \ fabs( fmod(dividend, divisor) - modulo ) < epsilon @@ -117,3 +118,4 @@ cModEqualFloatsWithEpsilon(dividend, divisor, modulo, cDefaultFloatComparisonEps } @end +#endif --- a/node_modules/react-native-camera/ios/RN/RNCamera.m +++ b/node_modules/react-native-camera/ios/RN/RNCamera.m @@ -284,6 +284,7 @@ static NSDictionary *defaultFaceDetectorOptions = nil; [device unlockForConfiguration]; } +#if __has_include() - (void)updateFaceDetecting:(id)faceDetecting { [_faceDetectorManager setIsEnabled:faceDetecting]; @@ -303,6 +304,7 @@ static NSDictionary *defaultFaceDetectorOptions = nil; { [_faceDetectorManager setClassificationsDetected:requestedClassifications]; } +#endif - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { @@ -382,7 +384,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; // At the time of writing AVCaptureMovieFileOutput and AVCaptureVideoDataOutput (> GMVDataOutput) // cannot coexist on the same AVSession (see: https://stackoverflow.com/a/4986032/1123156). // We stop face detection here and restart it in when AVCaptureMovieFileOutput finishes recording. +#if __has_include() [_faceDetectorManager stopFaceDetection]; +#endif [self setupMovieFileCapture]; } @@ -443,7 +447,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; self.stillImageOutput = stillImageOutput; } +#if __has_include() [_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer]; +#endif [self setupOrDisableBarcodeScanner]; __weak RNCamera *weakSelf = self; @@ -469,7 +475,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; return; #endif dispatch_async(self.sessionQueue, ^{ +#if __has_include() [_faceDetectorManager stopFaceDetection]; +#endif [self.previewLayer removeFromSuperlayer]; [self.session commitConfiguration]; [self.session stopRunning]; @@ -722,9 +730,12 @@ static NSDictionary *defaultFaceDetectorOptions = nil; self.videoRecordedReject = nil; [self cleanupMovieFileCapture]; + +#if __has_include() // If face detection has been running prior to recording to file // we reenable it here (see comment in -record). [_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer]; +#endif if (self.session.sessionPreset != AVCaptureSessionPresetHigh) { [self updateSessionPreset:AVCaptureSessionPresetHigh]; @@ -738,11 +749,13 @@ static NSDictionary *defaultFaceDetectorOptions = nil; Class faceDetectorManagerClass = NSClassFromString(@"RNFaceDetectorManager"); Class faceDetectorManagerStubClass = NSClassFromString(@"RNFaceDetectorManagerStub"); +#if __has_include() if (faceDetectorManagerClass) { return [[faceDetectorManagerClass alloc] initWithSessionQueue:_sessionQueue delegate:self]; } else if (faceDetectorManagerStubClass) { return [[faceDetectorManagerStubClass alloc] init]; } +#endif return nil; } --- a/node_modules/react-native-camera/ios/RN/RNCameraManager.m +++ b/node_modules/react-native-camera/ios/RN/RNCameraManager.m @@ -86,11 +86,15 @@ RCT_EXPORT_VIEW_PROPERTY(onFacesDetected, RCTDirectEventBlock); + (NSDictionary *)faceDetectorConstants { +#if __has_include() #if __has_include("RNFaceDetectorManager.h") return [RNFaceDetectorManager constants]; #else return [RNFaceDetectorManagerStub constants]; #endif +#else + return [NSDictionary new]; +#endif } RCT_CUSTOM_VIEW_PROPERTY(type, NSInteger, RNCamera) new file mode 100644 --- /dev/null +++ b/node_modules/react-native-camera/ios/RNCamera.xcodeproj/xcuserdata/brunolemos.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + RNCamera.xcscheme + + orderHint + 55 + + + + old mode 100644 new mode 100755 old mode 100644 new mode 100755 --- a/node_modules/react-native-camera/src/RNCamera.js +++ b/node_modules/react-native-camera/src/RNCamera.js @@ -106,9 +106,9 @@ export default class Camera extends React.Component { flashMode: CameraManager.FlashMode, autoFocus: CameraManager.AutoFocus, whiteBalance: CameraManager.WhiteBalance, - faceDetectionMode: CameraManager.FaceDetection.Mode, - faceDetectionLandmarks: CameraManager.FaceDetection.Landmarks, - faceDetectionClassifications: CameraManager.FaceDetection.Classifications, + faceDetectionMode: (CameraManager.FaceDetection || {}).Mode, + faceDetectionLandmarks: (CameraManager.FaceDetection || {}).Landmarks, + faceDetectionClassifications: (CameraManager.FaceDetection || {}).Classifications, }; static propTypes = { @@ -144,10 +144,10 @@ export default class Camera extends React.Component { autoFocus: CameraManager.AutoFocus.on, flashMode: CameraManager.FlashMode.off, whiteBalance: CameraManager.WhiteBalance.auto, - faceDetectionMode: CameraManager.FaceDetection.fast, + faceDetectionMode: (CameraManager.FaceDetection || {}).fast, barCodeTypes: Object.values(CameraManager.BarCodeType), - faceDetectionLandmarks: CameraManager.FaceDetection.Landmarks.none, - faceDetectionClassifications: CameraManager.FaceDetection.Classifications.none, + faceDetectionLandmarks: ((CameraManager.FaceDetection || {}).Landmarks || {}).none, + faceDetectionClassifications: ((CameraManager.FaceDetection || {}).Classifications || {}).none, permissionDialogTitle: '', permissionDialogMessage: '', notAuthorizedView: ( old mode 100644 new mode 100755 old mode 100644 new mode 100755 ```

Investigation

After further investigation, this is the part causing the problem:
See problematic patch content ```diff --- a/node_modules/react-native-camera/ios/RN/RNCamera.m +++ b/node_modules/react-native-camera/ios/RN/RNCamera.m @@ -284,6 +284,7 @@ static NSDictionary *defaultFaceDetectorOptions = nil; [device unlockForConfiguration]; } +#if __has_include() - (void)updateFaceDetecting:(id)faceDetecting { [_faceDetectorManager setIsEnabled:faceDetecting]; @@ -303,6 +304,7 @@ static NSDictionary *defaultFaceDetectorOptions = nil; { [_faceDetectorManager setClassificationsDetected:requestedClassifications]; } +#endif - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { @@ -382,7 +384,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; // At the time of writing AVCaptureMovieFileOutput and AVCaptureVideoDataOutput (> GMVDataOutput) // cannot coexist on the same AVSession (see: https://stackoverflow.com/a/4986032/1123156). // We stop face detection here and restart it in when AVCaptureMovieFileOutput finishes recording. +#if __has_include() [_faceDetectorManager stopFaceDetection]; +#endif [self setupMovieFileCapture]; } @@ -443,7 +447,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; self.stillImageOutput = stillImageOutput; } +#if __has_include() [_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer]; +#endif [self setupOrDisableBarcodeScanner]; __weak RNCamera *weakSelf = self; @@ -469,7 +475,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; return; #endif dispatch_async(self.sessionQueue, ^{ +#if __has_include() [_faceDetectorManager stopFaceDetection]; +#endif [self.previewLayer removeFromSuperlayer]; [self.session commitConfiguration]; [self.session stopRunning]; @@ -722,9 +730,12 @@ static NSDictionary *defaultFaceDetectorOptions = nil; self.videoRecordedReject = nil; [self cleanupMovieFileCapture]; + +#if __has_include() // If face detection has been running prior to recording to file // we reenable it here (see comment in -record). [_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer]; +#endif if (self.session.sessionPreset != AVCaptureSessionPresetHigh) { [self updateSessionPreset:AVCaptureSessionPresetHigh]; @@ -738,11 +749,13 @@ static NSDictionary *defaultFaceDetectorOptions = nil; Class faceDetectorManagerClass = NSClassFromString(@"RNFaceDetectorManager"); Class faceDetectorManagerStubClass = NSClassFromString(@"RNFaceDetectorManagerStub"); +#if __has_include() if (faceDetectorManagerClass) { return [[faceDetectorManagerClass alloc] initWithSessionQueue:_sessionQueue delegate:self]; } else if (faceDetectorManagerStubClass) { return [[faceDetectorManagerStubClass alloc] init]; } +#endif return nil; } ```


You can compare with the pull request and see some numbers are off.

brunolemos commented 6 years ago

I made the changes again on the file above, this time it decided to work 🤔 The difference between the new and old patches are indeed only spaces:

screenshot

See new generated patch ```diff --- a/node_modules/react-native-camera/ios/RN/RNCamera.m +++ b/node_modules/react-native-camera/ios/RN/RNCamera.m @@ -284,6 +284,7 @@ static NSDictionary *defaultFaceDetectorOptions = nil; [device unlockForConfiguration]; } +#if __has_include() - (void)updateFaceDetecting:(id)faceDetecting { [_faceDetectorManager setIsEnabled:faceDetecting]; @@ -303,6 +304,7 @@ static NSDictionary *defaultFaceDetectorOptions = nil; { [_faceDetectorManager setClassificationsDetected:requestedClassifications]; } +#endif - (void)takePicture:(NSDictionary *)options resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { @@ -382,7 +384,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; // At the time of writing AVCaptureMovieFileOutput and AVCaptureVideoDataOutput (> GMVDataOutput) // cannot coexist on the same AVSession (see: https://stackoverflow.com/a/4986032/1123156). // We stop face detection here and restart it in when AVCaptureMovieFileOutput finishes recording. +#if __has_include() [_faceDetectorManager stopFaceDetection]; +#endif [self setupMovieFileCapture]; } @@ -443,7 +447,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; self.stillImageOutput = stillImageOutput; } +#if __has_include() [_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer]; +#endif [self setupOrDisableBarcodeScanner]; __weak RNCamera *weakSelf = self; @@ -469,7 +475,9 @@ static NSDictionary *defaultFaceDetectorOptions = nil; return; #endif dispatch_async(self.sessionQueue, ^{ +#if __has_include() [_faceDetectorManager stopFaceDetection]; +#endif [self.previewLayer removeFromSuperlayer]; [self.session commitConfiguration]; [self.session stopRunning]; @@ -722,9 +730,11 @@ static NSDictionary *defaultFaceDetectorOptions = nil; self.videoRecordedReject = nil; [self cleanupMovieFileCapture]; +#if __has_include() // If face detection has been running prior to recording to file // we reenable it here (see comment in -record). [_faceDetectorManager maybeStartFaceDetectionOnSession:_session withPreviewLayer:_previewLayer]; +#endif if (self.session.sessionPreset != AVCaptureSessionPresetHigh) { [self updateSessionPreset:AVCaptureSessionPresetHigh]; @@ -738,11 +748,13 @@ static NSDictionary *defaultFaceDetectorOptions = nil; Class faceDetectorManagerClass = NSClassFromString(@"RNFaceDetectorManager"); Class faceDetectorManagerStubClass = NSClassFromString(@"RNFaceDetectorManagerStub"); +#if __has_include() if (faceDetectorManagerClass) { return [[faceDetectorManagerClass alloc] initWithSessionQueue:_sessionQueue delegate:self]; } else if (faceDetectorManagerStubClass) { return [[faceDetectorManagerStubClass alloc] init]; } +#endif return nil; } ```


How to prevent this from happening again?

lkduerig commented 6 years ago

I was also having this issue. I tried downgrading versions and all kinds of things which didn't work. Removing the cache key and all the lines it included from travis.yml resolved the problem.

Here is the full list of steps I took before reaching this solution:

I think the step to delete the original patch may not have been necessary, but I am not entirely sure. Definitely the step for patch #2 was not useful. I hope any of this helps anyone else having this issue.

dinvlad commented 6 years ago

FWIW, not sure if the same could be done in Travis, but in CircleCI it's easy enough to update the cache key by just adding a number to it, like so:

- restore_cache:
    keys:
      - cache-{{ checksum "yarn.lock" }}-1
      - cache-

One can always just increment the number if the cache key needs to be busted again. Hope that helps.

lkduerig commented 6 years ago

I'll keep that in mind next time around, thanks for the tip @dinvlad.

I hope this issue finds a solution, this is an incredibly useful module. @ds300 , thanks so much for the great work on this!

ds300 commented 6 years ago

Thanks for the detailed tips Liisa!

Update for this thread: Last night I made a lot of progress working on custom pure-TypeScript patch application. That will make these errors go away soon.

On Thu, 22 Mar 2018, 08:28 Liisa Duerig-Laitinen, notifications@github.com wrote:

I'll keep that in mind next time around, thanks for the tip @dinvlad https://github.com/dinvlad.

I hope this issue finds a solution, this is an incredibly useful module. @ds300 https://github.com/ds300 , thanks so much for the great work on this!

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/ds300/patch-package/issues/36#issuecomment-375216238, or mute the thread https://github.com/notifications/unsubscribe-auth/ABL1qQEqCsTc1vKjkVYxBta0f7MbmAKmks5tg2CXgaJpZM4Q-Wpv .

ds300 commented 6 years ago

Another update for this thread: You can try out the 6.0.0-X pre-release builds, which use the new TS-only patch application (yay! no more git apply 🎉). It should fix these errors in 99.9% of cases. I have a few more bits to iron out before making a full release. You can follow progress in #45

ds300 commented 6 years ago

Oh no. Apparently the publish didn't go through last night. Should work now.

npm i --save-dev patch-package@beta

or

yarn add --dev patch-package@beta
sfratini commented 6 years ago

@ds300 I was having the same issue and for now, I can confirm the beta works :)

davidlampon commented 6 years ago

@ds300 The @beta is pointing to this version (and I guess the good one is v6.0.0-3):

https://github.com/ds300/patch-package/releases/tag/v3.5.3-0

ds300 commented 6 years ago

Weird, for me it's pointing to the correct one, v6.0.0-3

image

image

Are you using yarn or npm?

ds300 commented 6 years ago

Also this: image

davidlampon commented 6 years ago

@ds300 Maybe it's because we are behind a private npm repo but we (both of us) only have the chance to install up to 5.1.1. Please, ignore this if we are the only ones reporting the problem.

Update: indeed it was, fixed now by our internal IT team =) Update2: v6.0.0-3 fixed the white space problem. Thanks!

DanielRuf commented 6 years ago

Is this fixed and can it be closed?

ds300 commented 6 years ago

Yes! It is fixed in patch-package@beta. Need to find some time to push out a full release soon. Might as well close this now though, since it's not tied to a specific issue but a kind of genre of issues that I don't have to worry about any more :)

pstanton commented 6 years ago

i'm getting the same with a patch that was supposedly working for over a month, nothing updated that i know of...

v5.1.1

JoschaP commented 5 years ago

This problem also occurs when someone creates a patch with npm/npx and his colleague tries to apply the patch with Yarn..

Maybe we can implement a notice for such a human problems in the fail message?