@wutiange/log-listener-plugin 1.3.2 → 2.0.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +130 -24
- package/dist/src/HTTPInterceptor.d.ts +1 -0
- package/dist/src/HTTPInterceptor.js +12 -9
- package/dist/src/HTTPInterceptor.js.map +1 -1
- package/dist/src/Server.d.ts +13 -6
- package/dist/src/Server.js +119 -41
- package/dist/src/Server.js.map +1 -1
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js.map +1 -1
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +0 -1
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js.map +1 -1
- package/dist/src/__tests__/Server.test.js +89 -114
- package/dist/src/__tests__/Server.test.js.map +1 -1
- package/dist/src/common.d.ts +19 -10
- package/dist/src/common.js +63 -4
- package/dist/src/common.js.map +1 -1
- package/dist/src/logPlugin.d.ts +12 -9
- package/dist/src/logPlugin.js +87 -82
- package/dist/src/logPlugin.js.map +1 -1
- package/dist/src/logger.d.ts +6 -0
- package/dist/src/logger.js +16 -0
- package/dist/src/logger.js.map +1 -0
- package/dist/src/utils.js +12 -7
- package/dist/src/utils.js.map +1 -1
- package/index.ts +3 -0
- package/package.json +18 -12
- package/src/HTTPInterceptor.ts +339 -0
- package/src/Server.ts +166 -0
- package/src/__mocks__/react-native/Libraries/Blob/FileReader.js +45 -0
- package/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +39 -0
- package/src/__tests__/HTTPInterceptor.test.ts +322 -0
- package/src/__tests__/Server.test.ts +175 -0
- package/src/__tests__/utils.test.ts +113 -0
- package/src/common.ts +70 -0
- package/src/logPlugin.ts +224 -0
- package/src/logger.ts +15 -0
- package/src/utils.ts +112 -0
- package/tsconfig.json +27 -0
package/dist/src/logPlugin.js
CHANGED
@@ -16,18 +16,48 @@ exports.SafeLogPlugin = void 0;
|
|
16
16
|
const Server_1 = __importDefault(require("./Server"));
|
17
17
|
const utils_1 = require("./utils");
|
18
18
|
const HTTPInterceptor_1 = require("./HTTPInterceptor");
|
19
|
+
const common_1 = require("./common");
|
20
|
+
const logger_1 = __importDefault(require("./logger"));
|
19
21
|
class LogPlugin {
|
20
22
|
constructor() {
|
21
23
|
this.server = null;
|
22
|
-
this.baseData = {};
|
23
24
|
this.timeout = null;
|
24
|
-
this.host = '';
|
25
25
|
this.isAuto = false;
|
26
|
-
this.
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
this.storage = (0, common_1.getDefaultStorage)();
|
27
|
+
this.init = () => __awaiter(this, void 0, void 0, function* () {
|
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 {
|
33
|
+
const urlsStr = yield this.storage.getItem(common_1.URLS_KEY);
|
34
|
+
if (urlsStr) {
|
35
|
+
const urls = JSON.parse(urlsStr);
|
36
|
+
this.server.setBaseUrlObj(urls);
|
37
|
+
}
|
30
38
|
}
|
39
|
+
this.server.addUrlsListener((_, urlsObj) => {
|
40
|
+
if (this.storage) {
|
41
|
+
this.storage.setItem(common_1.URLS_KEY, JSON.stringify(urlsObj));
|
42
|
+
}
|
43
|
+
HTTPInterceptor_1.httpInterceptor.setIgnoredUrls(this.handleIgnoredUrls());
|
44
|
+
});
|
45
|
+
});
|
46
|
+
this.config = ({ storage, timeout, testUrl, isAuto, baseData = {} }) => {
|
47
|
+
if (isAuto) {
|
48
|
+
this.auto();
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
this.unAuto();
|
52
|
+
}
|
53
|
+
this.storage = storage !== null && storage !== void 0 ? storage : (0, common_1.getDefaultStorage)();
|
54
|
+
this.setTimeout(timeout !== null && timeout !== void 0 ? timeout : common_1.DEFAULT_TIMEOUT);
|
55
|
+
this.setBaseUrl(testUrl);
|
56
|
+
this.setBaseData(baseData);
|
57
|
+
};
|
58
|
+
this.auto = () => {
|
59
|
+
this.startRecordNetwork();
|
60
|
+
this.startRecordLog();
|
31
61
|
this.isAuto = true;
|
32
62
|
};
|
33
63
|
this.unAuto = () => {
|
@@ -37,56 +67,69 @@ class LogPlugin {
|
|
37
67
|
this.isAuto = false;
|
38
68
|
};
|
39
69
|
this.startRecordLog = () => {
|
40
|
-
const common = require('./common');
|
41
70
|
console.log = (...data) => {
|
71
|
+
logger_1.default.log(...data);
|
42
72
|
this.log(...data);
|
43
|
-
common.log(...data);
|
44
73
|
};
|
45
74
|
console.warn = (...data) => {
|
75
|
+
logger_1.default.warn(...data);
|
46
76
|
this.warn(...data);
|
47
|
-
common.warn(...data);
|
48
77
|
};
|
49
78
|
console.error = (...data) => {
|
79
|
+
logger_1.default.error(...data);
|
50
80
|
this.error(...data);
|
51
|
-
common.error(...data);
|
52
81
|
};
|
53
82
|
};
|
54
83
|
this.stopRecordLog = () => {
|
55
|
-
|
56
|
-
console.
|
57
|
-
console.
|
58
|
-
console.error = common.error;
|
84
|
+
console.log = logger_1.default.log;
|
85
|
+
console.warn = logger_1.default.warn;
|
86
|
+
console.error = logger_1.default.error;
|
59
87
|
};
|
60
|
-
this.
|
88
|
+
this.handleIgnoredUrls = () => {
|
61
89
|
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
|
+
}, []);
|
97
|
+
}
|
98
|
+
return ignoredUrls;
|
99
|
+
};
|
100
|
+
this.startRecordNetwork = () => {
|
62
101
|
HTTPInterceptor_1.httpInterceptor.addListener("send", (data) => {
|
63
102
|
var _a;
|
64
|
-
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(
|
103
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network({
|
104
|
+
url: data.url,
|
105
|
+
id: data.id,
|
106
|
+
method: data.method,
|
107
|
+
headers: data.requestHeaders,
|
108
|
+
body: data.requestData,
|
109
|
+
createTime: data.startTime
|
110
|
+
});
|
65
111
|
});
|
66
112
|
HTTPInterceptor_1.httpInterceptor.addListener("response", (data) => {
|
67
113
|
var _a;
|
68
|
-
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(
|
114
|
+
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network({
|
115
|
+
headers: data.responseHeaders,
|
116
|
+
body: data.responseData,
|
117
|
+
requestId: data.id,
|
118
|
+
statusCode: data.status,
|
119
|
+
endTime: data.endTime
|
120
|
+
});
|
69
121
|
});
|
70
|
-
|
71
|
-
let ignoredUrls = [];
|
72
|
-
if (url) {
|
73
|
-
ignoredUrls = [`${url}/log`, `${url}/network`];
|
74
|
-
}
|
75
|
-
HTTPInterceptor_1.httpInterceptor.enable({ ignoredUrls });
|
122
|
+
HTTPInterceptor_1.httpInterceptor.enable({ ignoredUrls: this.handleIgnoredUrls() });
|
76
123
|
};
|
77
124
|
this.setBaseUrl = (url) => {
|
78
|
-
|
79
|
-
HTTPInterceptor_1.httpInterceptor.disable();
|
80
|
-
this.stopRecordLog();
|
81
|
-
return;
|
82
|
-
}
|
83
|
-
this.host = url.includes("http") ? url : `http://${url}`;
|
125
|
+
const tempUrl = url === null || url === void 0 ? void 0 : url.trim();
|
84
126
|
if (this.server) {
|
85
|
-
this.server.updateUrl(
|
127
|
+
this.server.updateUrl(tempUrl);
|
86
128
|
}
|
87
129
|
else {
|
88
|
-
this.server = new Server_1.default(
|
130
|
+
this.server = new Server_1.default(tempUrl);
|
89
131
|
}
|
132
|
+
HTTPInterceptor_1.httpInterceptor.setIgnoredUrls(this.handleIgnoredUrls());
|
90
133
|
if (this.isAuto) {
|
91
134
|
this.startRecordNetwork();
|
92
135
|
this.startRecordLog();
|
@@ -106,69 +149,31 @@ class LogPlugin {
|
|
106
149
|
return null;
|
107
150
|
};
|
108
151
|
this.setBaseData = (data = {}) => {
|
109
|
-
this.
|
152
|
+
this.server.updateBaseData(data);
|
110
153
|
};
|
111
154
|
this._log = (level, tag, ...data) => {
|
112
155
|
var _a;
|
113
|
-
const sendData =
|
156
|
+
const sendData = {
|
157
|
+
message: data,
|
158
|
+
tag,
|
159
|
+
level: level !== null && level !== void 0 ? level : 'log',
|
160
|
+
createTime: Date.now(),
|
161
|
+
};
|
114
162
|
(_a = this.server) === null || _a === void 0 ? void 0 : _a.log(sendData);
|
115
163
|
};
|
116
164
|
this.tag = (tag, ...data) => {
|
117
|
-
this._log(
|
165
|
+
this._log(common_1.Level.LOG, tag, ...data);
|
118
166
|
};
|
119
167
|
this.log = (...data) => {
|
120
|
-
this._log(
|
168
|
+
this._log(common_1.Level.LOG, common_1.Tag.DEFAULT, ...data);
|
121
169
|
};
|
122
170
|
this.warn = (...data) => {
|
123
|
-
this._log(
|
171
|
+
this._log(common_1.Level.WARN, common_1.Tag.DEFAULT, ...data);
|
124
172
|
};
|
125
173
|
this.error = (...data) => {
|
126
|
-
this._log(
|
127
|
-
};
|
128
|
-
this.
|
129
|
-
var _a, _b, _c;
|
130
|
-
let url = null;
|
131
|
-
let method = (_a = init === null || init === void 0 ? void 0 : init.method) !== null && _a !== void 0 ? _a : 'get';
|
132
|
-
let headers = init === null || init === void 0 ? void 0 : init.headers;
|
133
|
-
let body = init === null || init === void 0 ? void 0 : init.body;
|
134
|
-
if (input instanceof Request) {
|
135
|
-
url = input.url;
|
136
|
-
method = (_b = input.method) !== null && _b !== void 0 ? _b : 'get';
|
137
|
-
headers = input.headers.map;
|
138
|
-
body = input.body;
|
139
|
-
}
|
140
|
-
else if (input instanceof URL) {
|
141
|
-
url = input.href;
|
142
|
-
}
|
143
|
-
else {
|
144
|
-
url = input;
|
145
|
-
}
|
146
|
-
return (_c = this.server) === null || _c === void 0 ? void 0 : _c.network(Object.assign(Object.assign({}, this.baseData), { url, id: uniqueId, method,
|
147
|
-
headers,
|
148
|
-
body, createTime: Date.now() }));
|
149
|
-
});
|
150
|
-
this._res = (uniqueId, id, response) => __awaiter(this, void 0, void 0, function* () {
|
151
|
-
var _d;
|
152
|
-
const body = yield (response === null || response === void 0 ? void 0 : response.text());
|
153
|
-
return (_d = this.server) === null || _d === void 0 ? void 0 : _d.network(Object.assign(Object.assign({}, this.baseData), { headers: (response === null || response === void 0 ? void 0 : response.headers).map, body, requestId: uniqueId !== null && uniqueId !== void 0 ? uniqueId : Number(id), statusCode: response === null || response === void 0 ? void 0 : response.status, endTime: Date.now() }));
|
154
|
-
});
|
155
|
-
this.resTimeout = (uniqueId) => __awaiter(this, void 0, void 0, function* () {
|
156
|
-
var _e;
|
157
|
-
return (_e = this.server) === null || _e === void 0 ? void 0 : _e.network(Object.assign(Object.assign({}, this.baseData), { isTimeout: true, requestId: uniqueId }));
|
158
|
-
});
|
159
|
-
this.resResponseError = (uniqueId) => __awaiter(this, void 0, void 0, function* () {
|
160
|
-
var _f;
|
161
|
-
return (_f = this.server) === null || _f === void 0 ? void 0 : _f.network(Object.assign(Object.assign({}, this.baseData), { isResponseError: true, requestId: uniqueId }));
|
162
|
-
});
|
163
|
-
this.uniqueRes = (uniqueId, response) => __awaiter(this, void 0, void 0, function* () {
|
164
|
-
return this._res(uniqueId, undefined, response);
|
165
|
-
});
|
166
|
-
this.req = (input, init) => __awaiter(this, void 0, void 0, function* () {
|
167
|
-
return this.uniqueReq(undefined, input, init);
|
168
|
-
});
|
169
|
-
this.res = (id, response) => __awaiter(this, void 0, void 0, function* () {
|
170
|
-
return this._res(undefined, id, response);
|
171
|
-
});
|
174
|
+
this._log(common_1.Level.ERROR, common_1.Tag.DEFAULT, ...data);
|
175
|
+
};
|
176
|
+
this.init();
|
172
177
|
}
|
173
178
|
}
|
174
179
|
const SafeLogPlugin = (0, utils_1.createClassWithErrorHandling)(LogPlugin);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logPlugin.js","sourceRoot":"","sources":["../../src/logPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,mCAAuD;AACvD,uDAAoD;
|
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,eAAe,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE;gBACzC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;oBACjB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,C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G,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;YACvB,IAAI,CAAC,IAAI,CAAC,cAAK,CAAC,GAAG,EAAE,YAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC7C,CAAC,CAAA;QAED,SAAI,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;YACxB,IAAI,CAAC,IAAI,CAAC,cAAK,CAAC,IAAI,EAAE,YAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAA;QAED,UAAK,GAAG,CAAC,GAAG,IAAW,EAAE,EAAE;YACzB,IAAI,CAAC,IAAI,CAAC,cAAK,CAAC,KAAK,EAAE,YAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;QAC/C,CAAC,CAAA;QAlLC,IAAI,CAAC,IAAI,EAAE,CAAA;IACb,CAAC;CAmLF;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,16 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const [log, warn, error] = [console.log, console.warn, console.error];
|
4
|
+
const logger = {
|
5
|
+
log: (...data) => {
|
6
|
+
log(...data);
|
7
|
+
},
|
8
|
+
warn: (...data) => {
|
9
|
+
warn(...data);
|
10
|
+
},
|
11
|
+
error: (...data) => {
|
12
|
+
error(...data);
|
13
|
+
},
|
14
|
+
};
|
15
|
+
exports.default = logger;
|
16
|
+
//# sourceMappingURL=logger.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":";;AAAA,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;AAEtE,MAAM,MAAM,GAAG;IACb,GAAG,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACtB,GAAG,CAAC,GAAG,IAAI,CAAC,CAAA;IACd,CAAC;IACD,IAAI,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACvB,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;IACf,CAAC;IACD,KAAK,EAAE,CAAC,GAAG,IAAW,EAAE,EAAE;QACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAA;IAChB,CAAC;CACF,CAAA;AAED,kBAAe,MAAM,CAAA"}
|
package/dist/src/utils.js
CHANGED
@@ -1,29 +1,36 @@
|
|
1
1
|
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
6
|
+
exports.sleep = sleep;
|
7
|
+
exports.hasPort = hasPort;
|
8
|
+
exports.createClassWithErrorHandling = createClassWithErrorHandling;
|
9
|
+
exports.formDataToString = formDataToString;
|
10
|
+
const url_parse_1 = __importDefault(require("url-parse"));
|
11
|
+
const logger_1 = __importDefault(require("./logger"));
|
4
12
|
function sleep(ms, isReject = false) {
|
5
13
|
return new Promise((resolve, reject) => {
|
6
14
|
setTimeout(isReject ? () => reject({
|
7
15
|
code: 11001,
|
8
16
|
key: '@wutiange/log-listener-plugin%%timeout',
|
9
|
-
|
17
|
+
message: 'Timeout'
|
10
18
|
}) : resolve, ms);
|
11
19
|
});
|
12
20
|
}
|
13
|
-
exports.sleep = sleep;
|
14
21
|
function hasPort(url) {
|
15
22
|
if (!url || typeof url !== 'string') {
|
16
23
|
return false;
|
17
24
|
}
|
18
25
|
try {
|
19
|
-
const parsedUrl = new
|
26
|
+
const parsedUrl = new url_parse_1.default(url);
|
20
27
|
return parsedUrl.port !== '';
|
21
28
|
}
|
22
29
|
catch (error) {
|
30
|
+
logger_1.default.error(error);
|
23
31
|
return false;
|
24
32
|
}
|
25
33
|
}
|
26
|
-
exports.hasPort = hasPort;
|
27
34
|
function createClassWithErrorHandling(BaseClass) {
|
28
35
|
return new Proxy(BaseClass, {
|
29
36
|
construct(target, args) {
|
@@ -79,7 +86,6 @@ function createClassWithErrorHandling(BaseClass) {
|
|
79
86
|
}
|
80
87
|
});
|
81
88
|
}
|
82
|
-
exports.createClassWithErrorHandling = createClassWithErrorHandling;
|
83
89
|
function formDataToString(formData) {
|
84
90
|
const boundary = '----WebKitFormBoundary' + Math.random().toString(36).substr(2);
|
85
91
|
let result = '';
|
@@ -97,5 +103,4 @@ function formDataToString(formData) {
|
|
97
103
|
result += `--${boundary}--\r\n`;
|
98
104
|
return result;
|
99
105
|
}
|
100
|
-
exports.formDataToString = formDataToString;
|
101
106
|
//# sourceMappingURL=utils.js.map
|
package/dist/src/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
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,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;YACjC,IAAI,EAAE,KAAK;YACX,GAAG,EAAE,wCAAwC;YAC7C,OAAO,EAAE,SAAS;SACnB,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CA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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
ADDED
package/package.json
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wutiange/log-listener-plugin",
|
3
|
-
"version": "1.
|
3
|
+
"version": "2.0.1-alpha.1",
|
4
4
|
"description": "log-record 客户端对应的的插件\r\nLog-record client corresponding plugin",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
7
7
|
"source": "index.ts",
|
8
|
+
"react-native": "index.ts",
|
8
9
|
"repository": {
|
9
10
|
"type": "git",
|
10
11
|
"url": "https://github.com/wutiange/log-listener-plugin.git"
|
@@ -18,14 +19,6 @@
|
|
18
19
|
"charles"
|
19
20
|
],
|
20
21
|
"private": false,
|
21
|
-
"exports": {
|
22
|
-
"console": {
|
23
|
-
"default": "./dist/console.js"
|
24
|
-
},
|
25
|
-
"fetch": {
|
26
|
-
"default": "./dist/fetch.js"
|
27
|
-
}
|
28
|
-
},
|
29
22
|
"scripts": {
|
30
23
|
"build": "npm run test && tsc",
|
31
24
|
"dev": "ts-node ./index.ts",
|
@@ -35,19 +28,32 @@
|
|
35
28
|
},
|
36
29
|
"devDependencies": {
|
37
30
|
"@jest/globals": "^29.7.0",
|
31
|
+
"@types/crypto-js": "^4.2.2",
|
38
32
|
"@types/jest": "^29.5.12",
|
33
|
+
"@types/react-native-zeroconf": "^0.13.1",
|
34
|
+
"@types/url-parse": "^1.4.11",
|
39
35
|
"jest": "^29.7.0",
|
40
36
|
"ts-jest": "^29.1.2",
|
41
37
|
"ts-node": "^10.9.2",
|
42
38
|
"typescript": "^5.3.3"
|
43
39
|
},
|
44
40
|
"peerDependencies": {
|
45
|
-
"react-native": "*"
|
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": "*"
|
46
45
|
},
|
47
46
|
"files": [
|
48
47
|
"package.json",
|
49
48
|
"README.md",
|
50
49
|
"LICENSE",
|
51
|
-
"dist"
|
52
|
-
|
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
|
+
}
|
53
59
|
}
|