ds300 / patch-package

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

Failed to apply patch for package @shopify/react-native-skia at path #415

Open amerllica opened 2 years ago

amerllica commented 2 years ago

TL;DR:

The patch-package is able to apply my changes on build.gradle file but cannot apply Canvas.tsx.

Explanation:

I want to change to files of @shopify/react-native-skia package:

  1. node_modules/@shopify/react-native-skia/android/build.gradle file which patch-package easily can brings up my changes ✅
  2. node_modules/@shopify/react-native-skia/src/renderer/Canvas.tsx file which patch-package is not able to change it and faced the following error:

Failed to apply patch for package @shopify/react-native-skia at path

This is my patch file name: patches/@shopify+react-native-skia+0.1.103.patch and the following box is its codes:

diff --git a/node_modules/@shopify/react-native-skia/android/build.gradle b/node_modules/@shopify/react-native-skia/android/build.gradle
index 598a1bd..bccd93f 100644
--- a/node_modules/@shopify/react-native-skia/android/build.gradle
+++ b/node_modules/@shopify/react-native-skia/android/build.gradle
@@ -25,7 +25,7 @@ def safeExtGet(prop, fallback) {
 }

 apply plugin: 'com.android.library'
-apply plugin: 'maven'
+apply plugin: 'maven-publish'

 buildscript {
     // The Android Gradle plugin is only required when opening the android folder stand-alone.
@@ -76,7 +76,7 @@ android {
         excludes = ["**/libc++_shared.so"]
     }

-    buildFeatures { prefab true }
+    // buildFeatures { prefab true }

     prefab {
         reactskia {
@@ -148,13 +148,18 @@ def configureReactNativePom(def pom) {
     }
 }

+configurations {
+  customConfig.extendsFrom implementation
+}
+
 afterEvaluate { project ->
     // some Gradle build hooks ref:
     // https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
     task androidJavadoc(type: Javadoc) {
         source = android.sourceSets.main.java.srcDirs
         classpath += files(android.bootClasspath)
-        classpath += files(project.getConfigurations().getByName('compile').asList())
+        // classpath += files(project.getConfigurations().getByName('compile').asList())
+        classpath += files(project.getConfigurations().getByName('customConfig').asList())
         include '**/*.java'
     }

@@ -164,7 +169,8 @@ afterEvaluate { project ->
     }

     task androidSourcesJar(type: Jar) {
-        classifier = 'sources'
+        // classifier = 'sources'
+        archiveClassifier = 'sources'
         from android.sourceSets.main.java.srcDirs
         include '**/*.java'
     }
@@ -178,7 +184,7 @@ afterEvaluate { project ->
         }
     }

-    artifacts {
+    /* artifacts {
         archives androidSourcesJar
         archives androidJavadocJar
     }
@@ -190,7 +196,15 @@ afterEvaluate { project ->
             repository url: "file://${projectDir}/../android/maven"
             configureReactNativePom pom
         }
-    }
+    } */
+    publishing {
+       publications {
+          maven(MavenPublication) {
+          artifact androidSourcesJar
+          artifact androidJavadocJar
+         }
+       }
+     }
 }

 task extractAARHeaders {
diff --git a/node_modules/@shopify/react-native-skia/android/cpp/api b/node_modules/@shopify/react-native-skia/android/cpp/api
index 31b7efc..9374a34 120000
--- a/node_modules/@shopify/react-native-skia/android/cpp/api
+++ b/node_modules/@shopify/react-native-skia/android/cpp/api
@@ -1 +1 @@
-/private/var/folders/mx/yrj8n_2x35531hhwjzxh0kp80000gn/T/tmp-30179IK4W1VoK5A8j/node_modules/@shopify/react-native-skia/cpp/api
\ No newline at end of file
+/Users/amerllica/WebstormProjects/kidspod-mobile-client/node_modules/@shopify/react-native-skia/cpp/api
\ No newline at end of file
diff --git a/node_modules/@shopify/react-native-skia/android/cpp/jsi b/node_modules/@shopify/react-native-skia/android/cpp/jsi
index e8edcb2..9503f22 120000
--- a/node_modules/@shopify/react-native-skia/android/cpp/jsi
+++ b/node_modules/@shopify/react-native-skia/android/cpp/jsi
@@ -1 +1 @@
-/private/var/folders/mx/yrj8n_2x35531hhwjzxh0kp80000gn/T/tmp-30179IK4W1VoK5A8j/node_modules/@shopify/react-native-skia/cpp/jsi
\ No newline at end of file
+/Users/amerllica/WebstormProjects/kidspod-mobile-client/node_modules/@shopify/react-native-skia/cpp/jsi
\ No newline at end of file
diff --git a/node_modules/@shopify/react-native-skia/android/cpp/rnskia b/node_modules/@shopify/react-native-skia/android/cpp/rnskia
index 892ec67..fe41a2e 120000
--- a/node_modules/@shopify/react-native-skia/android/cpp/rnskia
+++ b/node_modules/@shopify/react-native-skia/android/cpp/rnskia
@@ -1 +1 @@
-/private/var/folders/mx/yrj8n_2x35531hhwjzxh0kp80000gn/T/tmp-30179IK4W1VoK5A8j/node_modules/@shopify/react-native-skia/cpp/rnskia
\ No newline at end of file
+/Users/amerllica/WebstormProjects/kidspod-mobile-client/node_modules/@shopify/react-native-skia/cpp/rnskia
\ No newline at end of file
diff --git a/node_modules/@shopify/react-native-skia/android/cpp/skia b/node_modules/@shopify/react-native-skia/android/cpp/skia
index 38caa11..fe36a38 120000
--- a/node_modules/@shopify/react-native-skia/android/cpp/skia
+++ b/node_modules/@shopify/react-native-skia/android/cpp/skia
@@ -1 +1 @@
-/private/var/folders/mx/yrj8n_2x35531hhwjzxh0kp80000gn/T/tmp-30179IK4W1VoK5A8j/node_modules/@shopify/react-native-skia/cpp/skia
\ No newline at end of file
+/Users/amerllica/WebstormProjects/kidspod-mobile-client/node_modules/@shopify/react-native-skia/cpp/skia
\ No newline at end of file
diff --git a/node_modules/@shopify/react-native-skia/android/cpp/utils b/node_modules/@shopify/react-native-skia/android/cpp/utils
index 23f62b7..df4d597 120000
--- a/node_modules/@shopify/react-native-skia/android/cpp/utils
+++ b/node_modules/@shopify/react-native-skia/android/cpp/utils
@@ -1 +1 @@
-/private/var/folders/mx/yrj8n_2x35531hhwjzxh0kp80000gn/T/tmp-30179IK4W1VoK5A8j/node_modules/@shopify/react-native-skia/cpp/utils
\ No newline at end of file
+/Users/amerllica/WebstormProjects/kidspod-mobile-client/node_modules/@shopify/react-native-skia/cpp/utils
\ No newline at end of file
diff --git a/node_modules/@shopify/react-native-skia/src/renderer/Canvas.tsx b/node_modules/@shopify/react-native-skia/src/renderer/Canvas.tsx
index 282dab7..4e3f641 100644
--- a/node_modules/@shopify/react-native-skia/src/renderer/Canvas.tsx
+++ b/node_modules/@shopify/react-native-skia/src/renderer/Canvas.tsx
@@ -77,7 +77,7 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
 }

 export const Canvas = forwardRef<SkiaView, CanvasProps>(
-  ({ children, style, debug, mode, onTouch, fontMgr }, forwardedRef) => {
+  ({ children, style, debug, mode, onTouch, fontMgr, onDraw: onDrawFromProps }, forwardedRef) => {
     const defaultRef = useCanvasRef();
     const ref = forwardedRef || defaultRef;
     const [tick, setTick] = useState(0);
@@ -96,6 +96,9 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
     // Draw callback
     const onDraw = useDrawCallback(
       (canvas, info) => {
+        if (typeof onDrawFromProps === "function") {
+          onDrawFromProps(canvas, info);
+        }
         if (typeof ref === "function") {
           throw new Error(
             "Ref callbacks are not supported. Use useCanvasRef() or useRef() instead"

And I'm using @shopify/react-native-skia version 103, the package.json file must contains it like the following line:

"@shopify/react-native-skia": "https://github.com/Shopify/react-native-skia/releases/download/v0.1.103-alpha/shopify-react-native-skia-0.1.103.tgz",

Suggestion: It would be better if patch-package could return the error which it faced though, then the developer can understand how can settle it up.

milahu commented 2 years ago

@shopify/react-native-skia has 100 MB so this is a bad repro