react-native种怎么使用patches文件呢?

关于patches文件,那么需要知道diff是什么,diff和patch是什么关系,他们做什么用的,知道这些,我们就可以知道我们要做什么了。

那么patches文件夹内通常是我们对第三方库的.d.ts文件的类型一个补充或修改的差异,知道这个重点之后,我们就知道,我们需要的patch文件是第三方库的.d.ts文件更改前后的差异对比(这里就用到了diff,比较并记录前后差异)。例如下边的patch文件。

diff --git a/node_modules/react-native-ble-manager/dist/esm/types.d.ts b/node_modules/react-native-ble-manager/dist/esm/types.d.ts
index a9b198c..89b3327 100644
--- a/node_modules/react-native-ble-manager/dist/esm/types.d.ts
+++ b/node_modules/react-native-ble-manager/dist/esm/types.d.ts
@@ -202,22 +202,37 @@ export interface Descriptor {
     value: string;
     uuid: string;
 }
+export type iOSProperties = Array<
+  | 'Broadcast'
+  | 'Read'
+  | 'WriteWithoutResponse'
+  | 'Write'
+  | 'Notify'
+  | 'Indicate'
+  | 'AuthenticatedSignedWrites'
+  | 'ExtendedProperties'
+  | 'NotifyEncryptionRequired'
+  | 'IndicateEncryptionRequired'
+>;
+
+export type AndroidProperties = {
+  Broadcast?: "Broadcast";
+  Read?: "Read";
+  WriteWithoutResponse?: "WriteWithoutResponse";
+  Write?: "Write";
+  Notify?: "Notify";
+  Indicate?: "Indicate";
+  AuthenticatedSignedWrites?: "AuthenticatedSignedWrites";
+  ExtendedProperties?: "ExtendedProperties";
+  NotifyEncryptionRequired?: "NotifyEncryptionRequired";
+  IndicateEncryptionRequired?: "IndicateEncryptionRequired";
+};
+
 export interface Characteristic {
     /**
      * See https://developer.apple.com/documentation/corebluetooth/cbcharacteristicproperties
      */
-    properties: {
-        Broadcast?: "Broadcast";
-        Read?: "Read";
-        WriteWithoutResponse?: "WriteWithoutResponse";
-        Write?: "Write";
-        Notify?: "Notify";
-        Indicate?: "Indicate";
-        AuthenticatedSignedWrites?: "AuthenticatedSignedWrites";
-        ExtendedProperties?: "ExtendedProperties";
-        NotifyEncryptionRequired?: "NotifyEncryptionRequired";
-        IndicateEncryptionRequired?: "IndicateEncryptionRequired";
-    };
+    properties: iOSProperties | AndroidProperties;
     characteristic: string;
     service: string;
     descriptors?: Descriptor[];

那么我们该怎么生成这种patch文件呢?肯定不是我们手写的,上边的patch文件内容的前八行什么意思呢?这里简单介绍下

第一行 Git 版本控制系统中 diff 命令输出的一部分,用于展示两个文件之间的差异。下面是对这一行的详细解释:

  • diff --git: 这表示接下来的内容是 Git 用来展示两个文件之间差异的输出。--git 参数告诉 Git 接下来的差异是针对 Git 仓库中的文件。

  • a/b/: 这两个前缀分别表示 "before"(之前)和 "after"(之后)。它们用来区分差异中涉及的两个文件版本。

第二行 index a9b198c..89b3327 100644

  • 这部分显示了文件在 Git 中的索引,d132ad62 是文件在旧版本中的索引哈希值,be06d152 是文件在新版本中的索引哈希值。这些哈希值是 Git 用来唯一标识文件内容的。

  • 100644: 这是一个权限模式,表示文件的权限。在 Git 中,100644 表示该文件是一个普通文件,具有读写权限。

第五行 @@ -202,22 +202,37 @@

  • 这一行是 diff 输出中的一个特殊标记,它指示接下来的行是文件中发生变更的部分。@@ 后面跟着的是两个数字范围,分别对应原始文件和修改后文件中的行号。

生成patch文件的步骤

1.找到你需要改的第三方库的.d.ts文件,然后进行Type的修改

2.执行代码 yarn patch-package react-native-ble-manager(这里写你改的包的名)

3.滞后性结束会自己生成一个你需要的patch文件          

  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值