@wutiange/log-listener-plugin 2.0.1-alpha.3 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +163 -163
  3. package/dist/src/HTTPInterceptor.js +2 -1
  4. package/dist/src/HTTPInterceptor.js.map +1 -1
  5. package/dist/src/__tests__/Server.test.js +4 -4
  6. package/dist/src/__tests__/Server.test.js.map +1 -1
  7. package/dist/src/__tests__/console.test.d.ts +1 -0
  8. package/dist/src/__tests__/console.test.js +29 -0
  9. package/dist/src/__tests__/console.test.js.map +1 -0
  10. package/dist/src/__tests__/utils.test.js +5 -1
  11. package/dist/src/__tests__/utils.test.js.map +1 -1
  12. package/dist/src/common.d.ts +1 -7
  13. package/dist/src/common.js +2 -14
  14. package/dist/src/common.js.map +1 -1
  15. package/dist/src/logPlugin.js +22 -17
  16. package/dist/src/logPlugin.js.map +1 -1
  17. package/dist/src/server.d.ts +21 -0
  18. package/dist/src/{Server.js → server.js} +47 -31
  19. package/dist/src/server.js.map +1 -0
  20. package/dist/src/utils.js +4 -4
  21. package/dist/src/utils.js.map +1 -1
  22. package/index.ts +3 -3
  23. package/package.json +59 -59
  24. package/src/HTTPInterceptor.ts +340 -339
  25. package/src/Server.ts +178 -167
  26. package/src/__mocks__/react-native/Libraries/Blob/FileReader.js +44 -44
  27. package/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +39 -39
  28. package/src/__tests__/HTTPInterceptor.test.ts +322 -322
  29. package/src/__tests__/Server.test.ts +149 -149
  30. package/src/__tests__/utils.test.ts +113 -112
  31. package/src/common.ts +57 -70
  32. package/src/logPlugin.ts +231 -224
  33. package/src/logger.ts +14 -14
  34. package/src/utils.ts +112 -112
  35. package/tsconfig.json +26 -26
  36. package/dist/src/Server.d.ts +0 -20
  37. package/dist/src/Server.js.map +0 -1
@@ -26,19 +26,16 @@ class LogPlugin {
26
26
  this.storage = (0, common_1.getDefaultStorage)();
27
27
  this.init = () => __awaiter(this, void 0, void 0, function* () {
28
28
  this.server = new Server_1.default();
29
- if (!this.storage) {
30
- logger_1.default.warn(common_1.LOG_KEY, '你并没有设置 storage ,这会导致 App 杀死后可能需要重新加入日志系统才能收集日志数据,建议你设置 storage 。');
31
- }
32
- else {
29
+ if (this.storage) {
33
30
  const urlsStr = yield this.storage.getItem(common_1.URLS_KEY);
34
31
  if (urlsStr) {
35
32
  const urls = JSON.parse(urlsStr);
36
- this.server.setBaseUrlObj(urls);
33
+ this.server.setBaseUrlArr(new Set(urls));
37
34
  }
38
35
  }
39
- this.server.addUrlsListener((_, urlsObj) => {
36
+ this.server.addUrlsListener((urlArr) => {
40
37
  if (this.storage) {
41
- this.storage.setItem(common_1.URLS_KEY, JSON.stringify(urlsObj));
38
+ this.storage.setItem(common_1.URLS_KEY, JSON.stringify(urlArr));
42
39
  }
43
40
  HTTPInterceptor_1.httpInterceptor.setIgnoredUrls(this.handleIgnoredUrls());
44
41
  });
@@ -68,16 +65,25 @@ class LogPlugin {
68
65
  };
69
66
  this.startRecordLog = () => {
70
67
  console.log = (...data) => {
71
- logger_1.default.log(...data);
72
68
  this.log(...data);
69
+ if (!__DEV__) {
70
+ return;
71
+ }
72
+ logger_1.default.log(...data);
73
73
  };
74
74
  console.warn = (...data) => {
75
- logger_1.default.warn(...data);
76
75
  this.warn(...data);
76
+ if (!__DEV__) {
77
+ return;
78
+ }
79
+ logger_1.default.warn(...data);
77
80
  };
78
81
  console.error = (...data) => {
79
- logger_1.default.error(...data);
80
82
  this.error(...data);
83
+ if (!__DEV__) {
84
+ return;
85
+ }
86
+ logger_1.default.error(...data);
81
87
  };
82
88
  };
83
89
  this.stopRecordLog = () => {
@@ -87,13 +93,12 @@ class LogPlugin {
87
93
  };
88
94
  this.handleIgnoredUrls = () => {
89
95
  var _a, _b;
90
- const urls = (_b = (_a = this.server) === null || _a === void 0 ? void 0 : _a.getUrls) === null || _b === void 0 ? void 0 : _b.call(_a);
91
- let ignoredUrls = [];
92
- if (urls === null || urls === void 0 ? void 0 : urls.length) {
93
- ignoredUrls = urls.reduce((acc, url) => {
94
- acc.push(`${url}/log`, `${url}/network`, `${url}/join`);
95
- return acc;
96
- }, []);
96
+ const urls = (_b = (_a = this.server) === null || _a === void 0 ? void 0 : _a.getBaseUrlArr) === null || _b === void 0 ? void 0 : _b.call(_a);
97
+ const ignoredUrls = [];
98
+ if (urls === null || urls === void 0 ? void 0 : urls.size) {
99
+ urls.forEach((url) => {
100
+ ignoredUrls.push(`${url}/log`, `${url}/network`, `${url}/join`);
101
+ });
97
102
  }
98
103
  return ignoredUrls;
99
104
  };
@@ -1 +1 @@
1
- {"version":3,"file":"logPlugin.js","sourceRoot":"","sources":["../../src/logPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,mCAAuD;AACvD,uDAAoD;AACpD,qCAA6F;AAC7F,sDAA8B;AA4B9B,MAAM,SAAS;IAMb;QALQ,WAAM,GAAkB,IAAI,CAAC;QAC7B,YAAO,GAAkB,IAAI,CAAC;QAC9B,WAAM,GAAG,KAAK,CAAA;QACd,YAAO,GAAmB,IAAA,0BAAiB,GAAE,CAAC;QAM9C,SAAI,GAAG,GAAS,EAAE;YACxB,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,EAAE,CAAC;YAC3B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;gBAClB,gBAAM,CAAC,IAAI,CAAC,gBAAO,EAAE,kEAAkE,CAAC,CAAA;YAC1F,CAAC;iBAAM,CAAC;gBACN,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAQ,CAAC,CAAA;gBACpD,IAAI,OAAO,EAAE,CAAC;oBACZ,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;oBAChC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;gBACjC,CAAC;YACH,CAAC;YAGD,IAAI,CAAC,MAAM,CAAC,eA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I,CAAC,IAAI,EAAE,CAAA;IACb,CAAC;CA0LF;AACD,MAAM,aAAa,GAAG,IAAA,oCAA4B,EAAC,SAAS,CAAC,CAAA;AAEpD,sCAAa;AADtB,MAAM,SAAS,GAAG,IAAI,aAAa,EAAE,CAAC;AAEtC,kBAAe,SAAS,CAAC"}
@@ -0,0 +1,21 @@
1
+ declare class Server {
2
+ private baseUrlArr;
3
+ private urlsObj;
4
+ private timeout;
5
+ private baseData;
6
+ private urlsListener;
7
+ private innerBaseData;
8
+ constructor(url?: string | Set<string>, timeout?: number);
9
+ addUrlsListener: (onNewUrlCallback: (urls: Set<string>) => void) => void;
10
+ private requestJoin;
11
+ private handleZeroConf;
12
+ updateTimeout(timeout?: number): void;
13
+ private send;
14
+ updateUrl(url?: string): void;
15
+ setBaseUrlArr(urlArr?: Set<string>): void;
16
+ getBaseUrlArr(): Set<string>;
17
+ updateBaseData(data?: Record<string, any>): void;
18
+ log: (data: Record<string, any>) => Promise<void>;
19
+ network: (data: Record<string, any>) => Promise<void>;
20
+ }
21
+ export default Server;
@@ -19,7 +19,8 @@ const md5_1 = __importDefault(require("crypto-js/md5"));
19
19
  const DEFAULT_PORT = 27751;
20
20
  class Server {
21
21
  constructor(url, timeout = 30000) {
22
- this.baseUrlObj = {};
22
+ this.baseUrlArr = new Set();
23
+ this.urlsObj = new Map();
23
24
  this.baseData = {};
24
25
  this.innerBaseData = {};
25
26
  this.addUrlsListener = (onNewUrlCallback) => {
@@ -48,7 +49,6 @@ class Server {
48
49
  return true;
49
50
  });
50
51
  this.send = (path, data) => __awaiter(this, void 0, void 0, function* () {
51
- var _a;
52
52
  const request = (url, _data) => __awaiter(this, void 0, void 0, function* () {
53
53
  yield Promise.race([
54
54
  fetch(`${url}/${path}`, {
@@ -66,18 +66,21 @@ class Server {
66
66
  (0, utils_1.sleep)(this.timeout, true),
67
67
  ]);
68
68
  });
69
- try {
70
- if (Object.keys(this.baseUrlObj).length === 0) {
71
- return;
72
- }
73
- yield Promise.all(this.getUrls().map((e) => __awaiter(this, void 0, void 0, function* () { return request(e, data); })));
69
+ if (this.baseUrlArr.size === 0) {
70
+ return;
74
71
  }
75
- catch (error) {
76
- if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes("Network request failed")) {
77
- return;
72
+ this.baseUrlArr.forEach((e) => __awaiter(this, void 0, void 0, function* () {
73
+ var _a, _b;
74
+ try {
75
+ yield request(e, data);
78
76
  }
79
- logger_1.default.warn(common_1.LOG_KEY, "上报日志失败", error);
80
- }
77
+ catch (error) {
78
+ if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes("Network request failed")) || ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes("Timeout"))) {
79
+ return;
80
+ }
81
+ logger_1.default.warn(common_1.LOG_KEY, "上报日志失败", error);
82
+ }
83
+ }));
81
84
  });
82
85
  this.log = (data) => __awaiter(this, void 0, void 0, function* () {
83
86
  return this.send("log", data);
@@ -89,7 +92,7 @@ class Server {
89
92
  this.updateUrl(url);
90
93
  }
91
94
  else {
92
- this.setBaseUrlObj(url !== null && url !== void 0 ? url : {});
95
+ this.setBaseUrlArr(url !== null && url !== void 0 ? url : new Set());
93
96
  }
94
97
  this.timeout = timeout;
95
98
  this.innerBaseData = (0, common_1.getBaseData)();
@@ -108,22 +111,34 @@ class Server {
108
111
  var _a;
109
112
  try {
110
113
  const { path, token } = (_a = service.txt) !== null && _a !== void 0 ? _a : {};
111
- if (!(path && token) || this.baseUrlObj[token]) {
114
+ const url = `http://${service.host}:${service.port}`;
115
+ if (!(path && token) || this.baseUrlArr.has(url)) {
112
116
  return;
113
117
  }
114
- const url = `http://${service.host}:${service.port}`;
115
118
  if (!(yield this.requestJoin(`${url}${path}`, token))) {
116
119
  return;
117
120
  }
118
- this.baseUrlObj[token] = url;
121
+ this.baseUrlArr.add(url);
122
+ this.urlsObj.set(service.name, url);
119
123
  if (this.urlsListener) {
120
- this.urlsListener(this.getUrls(), this.baseUrlObj);
124
+ this.urlsListener(this.baseUrlArr);
121
125
  }
122
126
  }
123
127
  catch (error) {
124
128
  logger_1.default.warn(common_1.LOG_KEY, "加入日志系统失败---", error);
125
129
  }
126
130
  }));
131
+ zeroconf.on("remove", (name) => {
132
+ const currentUrl = this.urlsObj.get(name);
133
+ this.baseUrlArr.delete(currentUrl);
134
+ this.urlsObj.delete(name);
135
+ if (this.urlsListener) {
136
+ this.urlsListener(this.baseUrlArr);
137
+ }
138
+ });
139
+ zeroconf.on("error", (err) => {
140
+ logger_1.default.warn(common_1.LOG_KEY, "zeroconf出现错误", err);
141
+ });
127
142
  zeroconf.scan("http", "tcp");
128
143
  }
129
144
  catch (error) {
@@ -134,27 +149,28 @@ class Server {
134
149
  updateTimeout(timeout = 3000) {
135
150
  this.timeout = timeout;
136
151
  }
137
- getUrls() {
138
- return Object.values(this.baseUrlObj).map((e) => {
139
- if ((0, utils_1.hasPort)(e)) {
140
- return e;
141
- }
142
- return `${e}:${DEFAULT_PORT}`;
143
- });
144
- }
145
- updateUrl(url) {
152
+ updateUrl(url = '') {
146
153
  const tempUrl = url.includes("http") ? url : `http://${url}`;
147
154
  if (!url) {
148
- delete this.baseUrlObj["Default"];
155
+ const currentUrl = this.urlsObj.get("Default");
156
+ this.baseUrlArr.delete(currentUrl);
157
+ this.urlsObj.delete("Default");
158
+ }
159
+ else if (!(0, utils_1.hasPort)(tempUrl)) {
160
+ this.updateUrl(`${tempUrl}:${DEFAULT_PORT}`);
149
161
  }
150
162
  else {
151
- this.baseUrlObj["Default"] = tempUrl;
163
+ this.baseUrlArr.add(tempUrl);
164
+ this.urlsObj.set("Default", tempUrl);
152
165
  }
153
166
  }
154
- setBaseUrlObj(urlObj) {
155
- this.baseUrlObj = urlObj;
167
+ setBaseUrlArr(urlArr = new Set()) {
168
+ this.baseUrlArr = urlArr;
169
+ }
170
+ getBaseUrlArr() {
171
+ return this.baseUrlArr;
156
172
  }
157
- updateBaseData(data) {
173
+ updateBaseData(data = {}) {
158
174
  this.baseData = data;
159
175
  }
160
176
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Server.js","sourceRoot":"","sources":["../../src/Server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,mCAAyC;AAEzC,qCAAgD;AAChD,sDAA8B;AAC9B,wDAAgC;AAGhC,MAAM,YAAY,GAAG,KAAK,CAAC;AAC3B,MAAM,MAAM;IAQV,YAAY,GAA0B,EAAE,UAAkB,KAAK;QAPvD,eAAU,GAAgB,IAAI,GAAG,EAAE,CAAC;QACpC,YAAO,GAAwB,IAAI,GAAG,EAAE,CAAC;QAEzC,aAAQ,GAAwB,EAAE,CAAC;QAEnC,kBAAa,GAA2B,EAAE,CAAC;QAanD,oBAAe,GAAG,CAChB,gBAA6C,EAC7C,EAAE;YACF,IAAI,CAAC,YAAY,GAAG,gBAAgB,CAAC;QACvC,CAAC,CAAC;QAEM,gBAAW,GAAG,CAAO,GAAW,EAAE,KAAa,EAAE,EAAE;;YACzD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAChC,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,gCAAgC;iBACjD;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,KAAK;oBACL,KAAK,EAAE,MAAA,IAAI,CAAC,aAAa,CAAC,KAAK,mCAAI,GAAG,IAAI,CAAC,aAAa,CAAC,UAAU,IAAI,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE;oBACrG,EAAE,EAAE,IAAA,aAAG,EAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE;iBACvD,CAAC;aACH,CAAC,CAAC;YACH,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;gBAC5B,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,QA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AC,CAAC;QACvC,CAAC;IACH,CAAC;IAED,aAAa,CAAC,SAAsB,IAAI,GAAG,EAAE;QAC3C,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC;IAC3B,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,cAAc,CAAC,OAA4B,EAAE;QAC3C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CASF;AAED,kBAAe,MAAM,CAAC"}
package/dist/src/utils.js CHANGED
@@ -44,14 +44,14 @@ function createClassWithErrorHandling(BaseClass) {
44
44
  const result = value.apply(this, args);
45
45
  if (result instanceof Promise) {
46
46
  return result.catch((error) => {
47
- console.error(`Error in ${String(prop)}:`, error);
47
+ logger_1.default.error(`Error in ${String(prop)}:`, error);
48
48
  throw error;
49
49
  });
50
50
  }
51
51
  return result;
52
52
  }
53
53
  catch (error) {
54
- console.error(`Error in ${String(prop)}:`, error);
54
+ logger_1.default.error(`Error in ${String(prop)}:`, error);
55
55
  throw error;
56
56
  }
57
57
  };
@@ -65,14 +65,14 @@ function createClassWithErrorHandling(BaseClass) {
65
65
  const result = value.apply(this, args);
66
66
  if (result instanceof Promise) {
67
67
  return result.catch((error) => {
68
- console.error(`Error in ${String(prop)}:`, error);
68
+ logger_1.default.error(`Error in ${String(prop)}:`, error);
69
69
  throw error;
70
70
  });
71
71
  }
72
72
  return result;
73
73
  }
74
74
  catch (error) {
75
- console.error(`Error in ${String(prop)}:`, error);
75
+ logger_1.default.error(`Error in ${String(prop)}:`, error);
76
76
  throw error;
77
77
  }
78
78
  };
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;;;AAGA,sBAQC;AAGD,0BAkBC;AAKD,oEAmDC;AAGD,4CAkBC;AA7GD,0DAA4B;AAC5B,sDAA8B;AAE9B,SAAgB,KAAK,CAAC,EAAU,EAAE,WAAoB,KAAK;IACzD,OAAO,IAA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AC;4BACd,CAAC;wBACH,CAAC,CAAC;oBACJ,CAAC;yBAAM,CAAC;wBACN,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC;oBACvB,CAAC;oBACD,OAAO,IAAI,CAAC;gBACd,CAAC;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAGD,SAAgB,gBAAgB,CAAC,QAAkB;IACjD,MAAM,QAAQ,GACZ,wBAAwB,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAClE,IAAI,MAAM,GAAG,EAAE,CAAC;IAEhB,MAAM,KAAK,GAAI,QAAgB,CAAC,QAAQ,EAAE,CAAC;IAC3C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,QAAQ,MAAM,CAAC;QAC9B,MAAM,IAAI,wBAAwB,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC;QAC5E,IAAI,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YACjC,MAAM,IAAI,iBAAiB,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC;QAChE,CAAC;QACD,MAAM,KAAK,GAAG,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;QACxD,MAAM,IAAI,mBAAmB,KAAK,CAAC,MAAM,UAAU,CAAC;QACpD,MAAM,IAAI,GAAG,KAAK,MAAM,CAAC;IAC3B,CAAC;IACD,MAAM,IAAI,KAAK,QAAQ,QAAQ,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import logPlugin from './src/logPlugin';
2
-
3
- export default logPlugin;
1
+ import logPlugin from './src/logPlugin';
2
+
3
+ export default logPlugin;
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "@wutiange/log-listener-plugin",
3
- "version": "2.0.1-alpha.3",
4
- "description": "log-record 客户端对应的的插件\r\nLog-record client corresponding plugin",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "source": "index.ts",
8
- "react-native": "index.ts",
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/wutiange/log-listener-plugin.git"
12
- },
13
- "author": "wutiange <wutiange20@qq,com>",
14
- "license": "MIT",
15
- "keywords": [
16
- "react-native",
17
- "log",
18
- "debugger",
19
- "charles"
20
- ],
21
- "private": false,
22
- "scripts": {
23
- "build": "npm run test && tsc",
24
- "dev": "ts-node ./index.ts",
25
- "publish-alpha": "npm publish --access public --tag alpha",
26
- "prepublishOnly": "npm run build",
27
- "test": "jest"
28
- },
29
- "devDependencies": {
30
- "@jest/globals": "^29.7.0",
31
- "@types/crypto-js": "^4.2.2",
32
- "@types/jest": "^29.5.12",
33
- "@types/react-native-zeroconf": "^0.13.1",
34
- "@types/url-parse": "^1.4.11",
35
- "jest": "^29.7.0",
36
- "ts-jest": "^29.1.2",
37
- "ts-node": "^10.9.2",
38
- "typescript": "^5.3.3"
39
- },
40
- "peerDependencies": {
41
- "react-native": "*",
42
- "react-native-device-info": "^14.0.0",
43
- "react-native-zeroconf": "^0.13.8",
44
- "@react-native-async-storage/async-storage": "*"
45
- },
46
- "files": [
47
- "package.json",
48
- "README.md",
49
- "LICENSE",
50
- "dist",
51
- "src",
52
- "index.ts",
53
- "tsconfig.json"
54
- ],
55
- "dependencies": {
56
- "crypto-js": "^4.2.0",
57
- "url-parse": "^1.5.10"
58
- }
59
- }
1
+ {
2
+ "name": "@wutiange/log-listener-plugin",
3
+ "version": "2.0.1",
4
+ "description": "log-record 客户端对应的的插件\r\nLog-record client corresponding plugin",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "source": "index.ts",
8
+ "react-native": "index.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/wutiange/log-listener-plugin.git"
12
+ },
13
+ "author": "wutiange <wutiange20@qq,com>",
14
+ "license": "MIT",
15
+ "keywords": [
16
+ "react-native",
17
+ "log",
18
+ "debugger",
19
+ "charles"
20
+ ],
21
+ "private": false,
22
+ "scripts": {
23
+ "build": "npm run test && tsc",
24
+ "dev": "ts-node ./index.ts",
25
+ "publish-alpha": "npm publish --access public --tag alpha",
26
+ "prepublishOnly": "npm run build",
27
+ "test": "jest"
28
+ },
29
+ "devDependencies": {
30
+ "@jest/globals": "^29.7.0",
31
+ "@types/crypto-js": "^4.2.2",
32
+ "@types/jest": "^29.5.12",
33
+ "@types/react-native-zeroconf": "^0.13.1",
34
+ "@types/url-parse": "^1.4.11",
35
+ "jest": "^29.7.0",
36
+ "ts-jest": "^29.1.2",
37
+ "ts-node": "^10.9.2",
38
+ "typescript": "^5.3.3"
39
+ },
40
+ "peerDependencies": {
41
+ "react-native": "*",
42
+ "react-native-device-info": "^14.0.0",
43
+ "react-native-zeroconf": "^0.13.8",
44
+ "@react-native-async-storage/async-storage": "*"
45
+ },
46
+ "files": [
47
+ "package.json",
48
+ "README.md",
49
+ "LICENSE",
50
+ "dist",
51
+ "src",
52
+ "index.ts",
53
+ "tsconfig.json"
54
+ ],
55
+ "dependencies": {
56
+ "crypto-js": "^4.2.0",
57
+ "url-parse": "^1.5.10"
58
+ }
59
+ }