@wutiange/log-listener-plugin 1.3.0-alpha.2 → 1.3.0-alpha.6
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +201 -201
- package/README.md +10 -2
- package/dist/src/HTTPInterceptor.d.ts +3 -2
- package/dist/src/HTTPInterceptor.js +29 -8
- package/dist/src/HTTPInterceptor.js.map +1 -1
- package/dist/src/{server.d.ts → Server.d.ts} +1 -0
- package/dist/src/{server.js → Server.js} +5 -2
- package/dist/src/Server.js.map +1 -0
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.d.ts +14 -0
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js +42 -0
- package/dist/src/__mocks__/react-native/Libraries/Blob/FileReader.js.map +1 -0
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.d.ts +17 -0
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js +35 -0
- package/dist/src/__mocks__/react-native/Libraries/Network/XHRInterceptor.js.map +1 -0
- package/dist/src/__tests__/HTTPInterceptor.test.d.ts +9 -0
- package/dist/src/__tests__/HTTPInterceptor.test.js +281 -0
- package/dist/src/__tests__/HTTPInterceptor.test.js.map +1 -0
- package/dist/src/__tests__/Server.test.d.ts +1 -0
- package/dist/src/__tests__/Server.test.js +155 -0
- package/dist/src/__tests__/Server.test.js.map +1 -0
- package/dist/src/__tests__/utils.test.d.ts +1 -0
- package/dist/src/__tests__/utils.test.js +108 -0
- package/dist/src/__tests__/utils.test.js.map +1 -0
- package/dist/src/logPlugin.d.ts +2 -1
- package/dist/src/logPlugin.js +13 -8
- package/dist/src/logPlugin.js.map +1 -1
- package/dist/src/utils.d.ts +4 -1
- package/dist/src/utils.js +75 -12
- package/dist/src/utils.js.map +1 -1
- package/package.json +54 -47
- package/dist/server.d.ts +0 -10
- package/dist/server.js +0 -45
- package/dist/server.js.map +0 -1
- package/dist/src/__tests__/console.test.d.ts +0 -1
- package/dist/src/__tests__/console.test.js +0 -29
- package/dist/src/__tests__/console.test.js.map +0 -1
- package/dist/src/server.js.map +0 -1
- package/src/HTTPInterceptor.ts +0 -319
- package/src/__tests__/console.test.ts +0 -26
- package/src/common.ts +0 -4
- package/src/logPlugin.ts +0 -238
- package/src/server.ts +0 -66
- package/src/utils.ts +0 -47
@@ -0,0 +1,108 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
+
const utils_1 = require("../utils");
|
13
|
+
describe('createClassWithErrorHandling', () => {
|
14
|
+
class TestClass {
|
15
|
+
normalMethod() {
|
16
|
+
return 'normal';
|
17
|
+
}
|
18
|
+
errorMethod() {
|
19
|
+
throw new Error('Test error');
|
20
|
+
}
|
21
|
+
asyncMethod() {
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
23
|
+
return 'async';
|
24
|
+
});
|
25
|
+
}
|
26
|
+
asyncErrorMethod() {
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
28
|
+
throw new Error('Async test error');
|
29
|
+
});
|
30
|
+
}
|
31
|
+
}
|
32
|
+
let consoleErrorSpy;
|
33
|
+
beforeEach(() => {
|
34
|
+
consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => { });
|
35
|
+
});
|
36
|
+
afterEach(() => {
|
37
|
+
consoleErrorSpy.mockRestore();
|
38
|
+
});
|
39
|
+
test('should not interfere with normal methods', () => {
|
40
|
+
const EnhancedClass = (0, utils_1.createClassWithErrorHandling)(TestClass);
|
41
|
+
const instance = new EnhancedClass();
|
42
|
+
expect(instance.normalMethod()).toBe('normal');
|
43
|
+
});
|
44
|
+
test('should catch and log errors from methods', () => {
|
45
|
+
const EnhancedClass = (0, utils_1.createClassWithErrorHandling)(TestClass);
|
46
|
+
const instance = new EnhancedClass();
|
47
|
+
expect(() => instance.errorMethod()).toThrow('Test error');
|
48
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('Error in errorMethod:', expect.any(Error));
|
49
|
+
});
|
50
|
+
test('should not interfere with async methods that resolve', () => __awaiter(void 0, void 0, void 0, function* () {
|
51
|
+
const EnhancedClass = (0, utils_1.createClassWithErrorHandling)(TestClass);
|
52
|
+
const instance = new EnhancedClass();
|
53
|
+
yield expect(instance.asyncMethod()).resolves.toBe('async');
|
54
|
+
}));
|
55
|
+
test('should catch and log errors from async methods that reject', () => __awaiter(void 0, void 0, void 0, function* () {
|
56
|
+
const EnhancedClass = (0, utils_1.createClassWithErrorHandling)(TestClass);
|
57
|
+
const instance = new EnhancedClass();
|
58
|
+
yield expect(instance.asyncErrorMethod()).rejects.toThrow('Async test error');
|
59
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('Error in asyncErrorMethod:', expect.any(Error));
|
60
|
+
}));
|
61
|
+
test('should handle methods added after instantiation', () => {
|
62
|
+
const EnhancedClass = (0, utils_1.createClassWithErrorHandling)(TestClass);
|
63
|
+
const instance = new EnhancedClass();
|
64
|
+
instance.dynamicMethod = function () {
|
65
|
+
throw new Error('Dynamic method error');
|
66
|
+
};
|
67
|
+
expect(() => instance.dynamicMethod()).toThrow('Dynamic method error');
|
68
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('Error in dynamicMethod:', expect.any(Error));
|
69
|
+
});
|
70
|
+
});
|
71
|
+
describe('hasPort function', () => {
|
72
|
+
test('should return true for URLs with explicit ports', () => {
|
73
|
+
expect((0, utils_1.hasPort)('http://example.com:8080')).toBe(true);
|
74
|
+
expect((0, utils_1.hasPort)('ftp://example.com:210')).toBe(true);
|
75
|
+
});
|
76
|
+
test('should return false for URLs without explicit ports', () => {
|
77
|
+
expect((0, utils_1.hasPort)('http://example.com')).toBe(false);
|
78
|
+
expect((0, utils_1.hasPort)('https://example.com')).toBe(false);
|
79
|
+
expect((0, utils_1.hasPort)('ftp://example.com')).toBe(false);
|
80
|
+
});
|
81
|
+
test('should return false for invalid URLs', () => {
|
82
|
+
expect((0, utils_1.hasPort)('not a url')).toBe(false);
|
83
|
+
expect((0, utils_1.hasPort)('http:/example.com')).toBe(false);
|
84
|
+
expect((0, utils_1.hasPort)('example.com:8080')).toBe(false);
|
85
|
+
});
|
86
|
+
test('should return false for empty input', () => {
|
87
|
+
expect((0, utils_1.hasPort)('')).toBe(false);
|
88
|
+
});
|
89
|
+
test('should return false for non-string input', () => {
|
90
|
+
expect((0, utils_1.hasPort)(null)).toBe(false);
|
91
|
+
expect((0, utils_1.hasPort)(undefined)).toBe(false);
|
92
|
+
expect((0, utils_1.hasPort)(123)).toBe(false);
|
93
|
+
expect((0, utils_1.hasPort)({})).toBe(false);
|
94
|
+
});
|
95
|
+
test('should handle URLs with default ports correctly', () => {
|
96
|
+
expect((0, utils_1.hasPort)('http://example.com:80')).toBe(false);
|
97
|
+
expect((0, utils_1.hasPort)('https://example.com:443')).toBe(false);
|
98
|
+
});
|
99
|
+
test('should handle URLs with IPv6 addresses', () => {
|
100
|
+
expect((0, utils_1.hasPort)('http://[2001:db8::1]:8080')).toBe(true);
|
101
|
+
expect((0, utils_1.hasPort)('https://[2001:db8::1]')).toBe(false);
|
102
|
+
});
|
103
|
+
test('should handle URLs with userinfo', () => {
|
104
|
+
expect((0, utils_1.hasPort)('http://user:pass@example.com:8080')).toBe(true);
|
105
|
+
expect((0, utils_1.hasPort)('http://user:pass@example.com')).toBe(false);
|
106
|
+
});
|
107
|
+
});
|
108
|
+
//# sourceMappingURL=utils.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
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K,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/logPlugin.d.ts
CHANGED
@@ -26,6 +26,7 @@ declare class LogPlugin {
|
|
26
26
|
req: (input: RequestInfo | URL, init?: RequestInit) => Promise<string>;
|
27
27
|
res: (id: number, response?: Response) => Promise<string>;
|
28
28
|
}
|
29
|
+
declare const SafeLogPlugin: typeof LogPlugin;
|
29
30
|
declare const logPlugin: LogPlugin;
|
30
|
-
export {
|
31
|
+
export { SafeLogPlugin };
|
31
32
|
export default logPlugin;
|
package/dist/src/logPlugin.js
CHANGED
@@ -12,8 +12,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
13
|
};
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
-
exports.
|
16
|
-
const
|
15
|
+
exports.SafeLogPlugin = void 0;
|
16
|
+
const Server_1 = __importDefault(require("./Server"));
|
17
17
|
const utils_1 = require("./utils");
|
18
18
|
const HTTPInterceptor_1 = require("./HTTPInterceptor");
|
19
19
|
class LogPlugin {
|
@@ -58,6 +58,7 @@ class LogPlugin {
|
|
58
58
|
console.error = common.error;
|
59
59
|
};
|
60
60
|
this.startRecordNetwork = () => {
|
61
|
+
var _a, _b;
|
61
62
|
HTTPInterceptor_1.httpInterceptor.addListener("send", (data) => {
|
62
63
|
var _a;
|
63
64
|
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData), { url: data.url, id: data.id, method: data.method, headers: data.requestHeaders, body: data.requestData, createTime: data.startTime }));
|
@@ -66,9 +67,12 @@ class LogPlugin {
|
|
66
67
|
var _a;
|
67
68
|
(_a = this.server) === null || _a === void 0 ? void 0 : _a.network(Object.assign(Object.assign({}, this.baseData), { headers: data.responseHeaders, body: data.responseData, requestId: data.id, statusCode: data.status, endTime: data.endTime }));
|
68
69
|
});
|
69
|
-
|
70
|
-
|
71
|
-
|
70
|
+
const url = (_b = (_a = this.server) === null || _a === void 0 ? void 0 : _a.getUrl) === null || _b === void 0 ? void 0 : _b.call(_a);
|
71
|
+
let ignoredUrls = [];
|
72
|
+
if (url) {
|
73
|
+
ignoredUrls = [`${url}/log`, `${url}/network`];
|
74
|
+
}
|
75
|
+
HTTPInterceptor_1.httpInterceptor.enable({ ignoredUrls });
|
72
76
|
};
|
73
77
|
this.setBaseUrl = (url) => {
|
74
78
|
if (!(url === null || url === void 0 ? void 0 : url.trim())) {
|
@@ -81,7 +85,7 @@ class LogPlugin {
|
|
81
85
|
this.server.updateUrl(url);
|
82
86
|
}
|
83
87
|
else {
|
84
|
-
this.server = new
|
88
|
+
this.server = new Server_1.default(url);
|
85
89
|
}
|
86
90
|
if (this.isAuto) {
|
87
91
|
this.startRecordNetwork();
|
@@ -167,7 +171,8 @@ class LogPlugin {
|
|
167
171
|
});
|
168
172
|
}
|
169
173
|
}
|
170
|
-
|
171
|
-
|
174
|
+
const SafeLogPlugin = (0, utils_1.createClassWithErrorHandling)(LogPlugin);
|
175
|
+
exports.SafeLogPlugin = SafeLogPlugin;
|
176
|
+
const logPlugin = new SafeLogPlugin();
|
172
177
|
exports.default = logPlugin;
|
173
178
|
//# sourceMappingURL=logPlugin.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"logPlugin.js","sourceRoot":"","sources":["../../src/logPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,
|
1
|
+
{"version":3,"file":"logPlugin.js","sourceRoot":"","sources":["../../src/logPlugin.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAA8B;AAC9B,mCAAuD;AACvD,uDAAoD;AAEpD,MAAM,SAAS;IAAf;QACU,WAAM,GAAkB,IAAI,CAAC;QAC7B,aAAQ,GAAwB,EAAE,CAAC;QACnC,YAAO,GAAkB,IAAI,CAAC;QAC9B,SAAI,GAAG,EAAE,CAAC;QACV,WAAM,G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ean): Promise<unknown>;
|
2
|
-
export declare function extractDomain(url: string): string;
|
3
2
|
export declare function hasPort(url: string): boolean;
|
3
|
+
type Constructor<T = {}> = new (...args: any[]) => T;
|
4
|
+
export declare function createClassWithErrorHandling<T extends Constructor>(BaseClass: T): T;
|
5
|
+
export declare function formDataToString(formData: FormData): string;
|
6
|
+
export {};
|
package/dist/src/utils.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.formDataToString = exports.createClassWithErrorHandling = exports.hasPort = exports.sleep = void 0;
|
4
4
|
function sleep(ms, isReject = false) {
|
5
5
|
return new Promise((resolve, reject) => {
|
6
6
|
setTimeout(isReject ? () => reject({
|
@@ -11,17 +11,6 @@ function sleep(ms, isReject = false) {
|
|
11
11
|
});
|
12
12
|
}
|
13
13
|
exports.sleep = sleep;
|
14
|
-
function extractDomain(url) {
|
15
|
-
if (!url || typeof url !== 'string') {
|
16
|
-
return url;
|
17
|
-
}
|
18
|
-
const match = url.match(/^(https?:\/\/)?([^/:]+)/i);
|
19
|
-
if (!match) {
|
20
|
-
return url;
|
21
|
-
}
|
22
|
-
return match[2];
|
23
|
-
}
|
24
|
-
exports.extractDomain = extractDomain;
|
25
14
|
function hasPort(url) {
|
26
15
|
if (!url || typeof url !== 'string') {
|
27
16
|
return false;
|
@@ -35,4 +24,78 @@ function hasPort(url) {
|
|
35
24
|
}
|
36
25
|
}
|
37
26
|
exports.hasPort = hasPort;
|
27
|
+
function createClassWithErrorHandling(BaseClass) {
|
28
|
+
return new Proxy(BaseClass, {
|
29
|
+
construct(target, args) {
|
30
|
+
const instance = new target(...args);
|
31
|
+
return new Proxy(instance, {
|
32
|
+
get(target, prop) {
|
33
|
+
const value = target[prop];
|
34
|
+
if (typeof value === 'function') {
|
35
|
+
return function (...args) {
|
36
|
+
try {
|
37
|
+
const result = value.apply(this, args);
|
38
|
+
if (result instanceof Promise) {
|
39
|
+
return result.catch((error) => {
|
40
|
+
console.error(`Error in ${String(prop)}:`, error);
|
41
|
+
throw error;
|
42
|
+
});
|
43
|
+
}
|
44
|
+
return result;
|
45
|
+
}
|
46
|
+
catch (error) {
|
47
|
+
console.error(`Error in ${String(prop)}:`, error);
|
48
|
+
throw error;
|
49
|
+
}
|
50
|
+
};
|
51
|
+
}
|
52
|
+
return value;
|
53
|
+
},
|
54
|
+
set(target, prop, value) {
|
55
|
+
if (typeof value === 'function') {
|
56
|
+
target[prop] = function (...args) {
|
57
|
+
try {
|
58
|
+
const result = value.apply(this, args);
|
59
|
+
if (result instanceof Promise) {
|
60
|
+
return result.catch((error) => {
|
61
|
+
console.error(`Error in ${String(prop)}:`, error);
|
62
|
+
throw error;
|
63
|
+
});
|
64
|
+
}
|
65
|
+
return result;
|
66
|
+
}
|
67
|
+
catch (error) {
|
68
|
+
console.error(`Error in ${String(prop)}:`, error);
|
69
|
+
throw error;
|
70
|
+
}
|
71
|
+
};
|
72
|
+
}
|
73
|
+
else {
|
74
|
+
target[prop] = value;
|
75
|
+
}
|
76
|
+
return true;
|
77
|
+
}
|
78
|
+
});
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}
|
82
|
+
exports.createClassWithErrorHandling = createClassWithErrorHandling;
|
83
|
+
function formDataToString(formData) {
|
84
|
+
const boundary = '----WebKitFormBoundary' + Math.random().toString(36).substr(2);
|
85
|
+
let result = '';
|
86
|
+
const parts = formData.getParts();
|
87
|
+
for (const part of parts) {
|
88
|
+
result += `--${boundary}\r\n`;
|
89
|
+
result += `Content-Disposition: ${part.headers['content-disposition']}\r\n`;
|
90
|
+
if (part.headers['content-type']) {
|
91
|
+
result += `Content-Type: ${part.headers['content-type']}\r\n`;
|
92
|
+
}
|
93
|
+
const value = 'string' in part ? part.string : part.uri;
|
94
|
+
result += `Content-Length: ${value.length}\r\n\r\n`;
|
95
|
+
result += `${value}\r\n`;
|
96
|
+
}
|
97
|
+
result += `--${boundary}--\r\n`;
|
98
|
+
return result;
|
99
|
+
}
|
100
|
+
exports.formDataToString = formDataToString;
|
38
101
|
//# 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":";;;AACA,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,GAAG,EAAE,SAAS;SACf,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AARD,sBAQC;AAGD,SAAgB,OAAO,CAAC,GAAW;IAEjC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QAEH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAI/B,OAAO,SAAS,CAAC,IAAI,KAAK,EAAE,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAEf,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAjBD,0BAiBC;AAKD,SAAgB,4BAA4B,CAAwB,SAAY;IAC9E,OAAO,IAAI,KAAK,CAAC,SAAS,EAAE;QAC1B,SAAS,CAAC,MAAS,EAAE,IAAW;YAC9B,MAAM,QAAQ,GAAG,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;YACrC,OAAO,IAAI,KAAK,CAAC,QAAQ,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AM,UAAU,CAAC;QACpD,MAAM,IAAI,GAAG,KAAK,MAAM,CAAC;IAC3B,CAAC;IACD,MAAM,IAAI,KAAK,QAAQ,QAAQ,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC;AAlBD,4CAkBC"}
|
package/package.json
CHANGED
@@ -1,47 +1,54 @@
|
|
1
|
-
{
|
2
|
-
"name": "@wutiange/log-listener-plugin",
|
3
|
-
"version": "1.3.0-alpha.
|
4
|
-
"description": "
|
5
|
-
"main": "dist/
|
6
|
-
"types": "dist/
|
7
|
-
"source": "
|
8
|
-
"repository": {
|
9
|
-
"
|
10
|
-
|
11
|
-
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"
|
15
|
-
"
|
16
|
-
|
17
|
-
|
18
|
-
"
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
"
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
"
|
31
|
-
"
|
32
|
-
"
|
33
|
-
"
|
34
|
-
"
|
35
|
-
},
|
36
|
-
"
|
37
|
-
"
|
38
|
-
|
39
|
-
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
}
|
1
|
+
{
|
2
|
+
"name": "@wutiange/log-listener-plugin",
|
3
|
+
"version": "1.3.0-alpha.6",
|
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
|
+
"repository": {
|
9
|
+
"type": "git",
|
10
|
+
"url": "https://github.com/wutiange/log-listener-plugin.git"
|
11
|
+
},
|
12
|
+
"author": "wutiange <wutiange20@qq,com>",
|
13
|
+
"license": "MIT",
|
14
|
+
"keywords": [
|
15
|
+
"react-native",
|
16
|
+
"log",
|
17
|
+
"debugger",
|
18
|
+
"charles"
|
19
|
+
],
|
20
|
+
"private": false,
|
21
|
+
"exports": {
|
22
|
+
"console": {
|
23
|
+
"default": "./dist/console.js"
|
24
|
+
},
|
25
|
+
"fetch": {
|
26
|
+
"default": "./dist/fetch.js"
|
27
|
+
}
|
28
|
+
},
|
29
|
+
"scripts": {
|
30
|
+
"build": "npm run test && tsc",
|
31
|
+
"dev": "ts-node ./index.ts",
|
32
|
+
"publish-alpha": "npm publish --access public --tag alpha",
|
33
|
+
"prepublishOnly": "npm run build",
|
34
|
+
"test": "jest"
|
35
|
+
},
|
36
|
+
"devDependencies": {
|
37
|
+
"@jest/globals": "^29.7.0",
|
38
|
+
"@types/jest": "^29.5.12",
|
39
|
+
"jest": "^29.7.0",
|
40
|
+
"ts-jest": "^29.1.2",
|
41
|
+
"ts-node": "^10.9.2",
|
42
|
+
"typescript": "^5.3.3",
|
43
|
+
"react-native": "0.73.5"
|
44
|
+
},
|
45
|
+
"peerDependencies": {
|
46
|
+
"react-native": "*"
|
47
|
+
},
|
48
|
+
"files": [
|
49
|
+
"package.json",
|
50
|
+
"README.md",
|
51
|
+
"LICENSE",
|
52
|
+
"dist"
|
53
|
+
]
|
54
|
+
}
|
package/dist/server.d.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
declare class Server {
|
2
|
-
private baseUrl;
|
3
|
-
private port;
|
4
|
-
constructor(url: string);
|
5
|
-
private send;
|
6
|
-
updateUrl(url: string): void;
|
7
|
-
log(data: Record<string, any>): Promise<string>;
|
8
|
-
network(data: Record<string, any>): Promise<string>;
|
9
|
-
}
|
10
|
-
export default Server;
|
package/dist/server.js
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
class Server {
|
13
|
-
constructor(url) {
|
14
|
-
this.baseUrl = '';
|
15
|
-
this.port = 27751;
|
16
|
-
this.updateUrl(url);
|
17
|
-
}
|
18
|
-
send(path, data) {
|
19
|
-
return __awaiter(this, void 0, void 0, function* () {
|
20
|
-
const result = yield fetch(`${this.baseUrl}:${this.port}/${path}`, {
|
21
|
-
method: 'POST',
|
22
|
-
headers: {
|
23
|
-
'Content-Type': 'application/json;charset=utf-8'
|
24
|
-
},
|
25
|
-
body: JSON.stringify(data)
|
26
|
-
});
|
27
|
-
return result.text();
|
28
|
-
});
|
29
|
-
}
|
30
|
-
updateUrl(url) {
|
31
|
-
this.baseUrl = url;
|
32
|
-
}
|
33
|
-
log(data) {
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
35
|
-
return this.send("log", data);
|
36
|
-
});
|
37
|
-
}
|
38
|
-
network(data) {
|
39
|
-
return __awaiter(this, void 0, void 0, function* () {
|
40
|
-
return this.send("network", data);
|
41
|
-
});
|
42
|
-
}
|
43
|
-
}
|
44
|
-
exports.default = Server;
|
45
|
-
//# sourceMappingURL=server.js.map
|
package/dist/server.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,MAAM,MAAM;IAGV,YAAY,GAAW;QAFf,YAAO,GAAG,EAAE,CAAC;QACb,SAAI,GAAG,KAAK,CAAA;QAElB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;IACrB,CAAC;IAEa,IAAI,CAAC,IAAY,EAAE,IAAyB;;YACxD,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE,EAAE;gBACjE,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE;oBACP,cAAc,EAAE,gCAAgC;iBACjD;gBACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;aAC3B,CAAC,CAAA;YACF,OAAO,MAAM,CAAC,IAAI,EAAE,CAAA;QACtB,CAAC;KAAA;IAED,SAAS,CAAC,GAAW;QACnB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAA;IACpB,CAAC;IAEK,GAAG,CAAC,IAAyB;;YACjC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAC/B,CAAC;KAAA;IAEK,OAAO,CAAC,IAAyB;;YACrC,OAAO,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAA;QACnC,CAAC;KAAA;CACF;AAED,kBAAe,MAAM,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
import '../../console';
|
@@ -1,29 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
require("../../console");
|
7
|
-
const index_1 = __importDefault(require("../../index"));
|
8
|
-
describe("重写日志", () => {
|
9
|
-
it("log 没有提前设置 url", () => {
|
10
|
-
console.log("log 是否正常打印");
|
11
|
-
expect(1).toBe(1);
|
12
|
-
});
|
13
|
-
it("log 提前设置了 url", () => {
|
14
|
-
index_1.default.setBaseUrl("http://192.168.118.103");
|
15
|
-
console.log("log 是否正常打印");
|
16
|
-
expect(1).toBe(1);
|
17
|
-
});
|
18
|
-
it('warn', () => {
|
19
|
-
index_1.default.setBaseUrl("http://192.168.118.103");
|
20
|
-
console.warn("warn 是否正常打印");
|
21
|
-
expect(1).toBe(1);
|
22
|
-
});
|
23
|
-
it('error', () => {
|
24
|
-
index_1.default.setBaseUrl("http://192.168.118.103");
|
25
|
-
console.error("error 是否正常打印");
|
26
|
-
expect(1).toBe(1);
|
27
|
-
});
|
28
|
-
});
|
29
|
-
//# sourceMappingURL=console.test.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"console.test.js","sourceRoot":"","sources":["../../../src/__tests__/console.test.ts"],"names":[],"mappings":";;;;;AAAA,yBAAsB;AACtB,wDAAgC;AAChC,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE;QACxB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACzB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE;QACvB,eAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;QAC3C,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACzB,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,MAAM,EAAE,GAAG,EAAE;QACd,eAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;QAC3C,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;QAC3B,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACf,eAAM,CAAC,UAAU,CAAC,wBAAwB,CAAC,CAAA;QAC3C,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;QAC7B,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CA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