<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Waqqas Jabbar</title>
    <description>The latest articles on DEV Community by Waqqas Jabbar (@waqqas).</description>
    <link>https://dev.to/waqqas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F192470%2Fcfce454b-8dc1-4d3f-8b83-a2d979e7d17b.jpeg</url>
      <title>DEV Community: Waqqas Jabbar</title>
      <link>https://dev.to/waqqas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/waqqas"/>
    <language>en</language>
    <item>
      <title>React-Native: CI friendly way to make changes to third-party packages</title>
      <dc:creator>Waqqas Jabbar</dc:creator>
      <pubDate>Sun, 01 Sep 2019 17:42:27 +0000</pubDate>
      <link>https://dev.to/waqqas/react-native-ci-friendly-way-to-make-changes-to-third-party-packages-5g1p</link>
      <guid>https://dev.to/waqqas/react-native-ci-friendly-way-to-make-changes-to-third-party-packages-5g1p</guid>
      <description>&lt;p&gt;Have you been in a situation where you installed a package and it doesn't work with the latest version of react-native because the path of RN header file has changed? I ran into a similar problem and here's how I fixed it.&lt;/p&gt;

&lt;p&gt;I was working on a react-native project and wanted to detect changes when the silent switch is flipped on or off. As usual, I searched and found a nifty package &lt;a href="https://github.com/gnestor/react-native-silent-switch"&gt;&lt;code&gt;(react-native-silent-switch)&lt;/code&gt;&lt;/a&gt; that did the job. I added that in my project as mentioned in its documentation and hit a snag. It gave an error during compilation due to wrong path in header file &lt;code&gt;RCTSilentSwitch.h&lt;/code&gt;. Normally I would switch to some similar package which doesn't have this problem, but in this case I couldn't find a better alternative. (Maybe I should write one)&lt;/p&gt;

&lt;p&gt;I could have modified the file but it has two problems. One, any other developer has to manually do those changes on hiss side, and, secondly, my CI build would fail. The build would fail because the file was part of a node packages this is installed via &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I needed a way to modify &lt;code&gt;RCTSilentSwitch.h&lt;/code&gt; AFTER it has been installed by &lt;code&gt;npm&lt;/code&gt; and BEFORE it start compiling. My initial reaction was to use the &lt;code&gt;post-install&lt;/code&gt; stage to patch the file, but I thought, there might be something out there for it too. So, I searched again and found another cool package that did just that. It was aptly named &lt;a href="https://github.com/ds300/patch-package"&gt;&lt;code&gt;patch-package&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;patch-package&lt;/code&gt; allows you to modify the code in &lt;code&gt;node_modules&lt;/code&gt; directory, in the form of patches. The usage was quite simple too.&lt;/p&gt;

&lt;p&gt;I followed the following steps to get my build working again:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Installed &lt;code&gt;patch-package&lt;/code&gt; as dev dependencies by following the &lt;a href="https://github.com/ds300/patch-package#set-up"&gt;setup instructions&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;I changed the required include path in &lt;code&gt;RCTSilentSwitch.h&lt;/code&gt; and generated a patch file using the following command:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;yarn patch-package react-native-silent-switch&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;A patch file was generated in &lt;code&gt;patches&lt;/code&gt; directory. It's content is as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gh"&gt;diff --git a/node_modules/react-native-silent-switch/RCTSilentSwitch.h b/node_modules/react-native-silent-switch/RCTSilentSwitch.h
index 61c955f..0adef09 100644
&lt;/span&gt;&lt;span class="gd"&gt;--- a/node_modules/react-native-silent-switch/RCTSilentSwitch.h
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/node_modules/react-native-silent-switch/RCTSilentSwitch.h
&lt;/span&gt;&lt;span class="p"&gt;@@ -1,4 +1,4 @@&lt;/span&gt;
&lt;span class="gd"&gt;-#import "RCTBridgeModule.h"
&lt;/span&gt;&lt;span class="gi"&gt;+#import "React/RCTBridgeModule.h"
&lt;/span&gt; #import "SharkfoodMuteSwitchDetector.h"

 @interface RCTSilentSwitch : NSObject &amp;lt;RCTBridgeModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;I removed the &lt;code&gt;node_modules&lt;/code&gt; directory and ran &lt;code&gt;yarn install&lt;/code&gt; and confirmed that the patch was applied. It printed the following messages at the end.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ patch-package
patch-package 6.1.2
Applying patches...
react-native-silent-switch@0.1.0 ✔
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using &lt;code&gt;patch-package&lt;/code&gt;, I was able to make small changes in the &lt;code&gt;node_modules&lt;/code&gt; directory in a way that is CI friendly.&lt;/p&gt;

&lt;p&gt;Although I used this approach for a react-native package, it can be used for any third-party package that is installed in &lt;code&gt;node_modules&lt;/code&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>patch</category>
      <category>ci</category>
      <category>nodemodules</category>
    </item>
  </channel>
</rss>
