From 64affc5546b1bf313008242d167263a5a8f62cfe Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Mon, 8 Jul 2024 22:54:14 +0800 Subject: [PATCH 01/13] refactor --- packages/base/package.json | 8 ---- packages/mp-base/package.json | 6 --- packages/page-spy-base/package.json | 38 ++++++++++++++++++ packages/{base => page-spy-base}/src/atom.ts | 4 +- .../{base => page-spy-base}/src/client.ts | 0 .../{base => page-spy-base}/src/config.ts | 0 .../{base => page-spy-base}/src/constants.ts | 0 packages/page-spy-base/src/index.ts | 11 ++++++ .../src/message/index.ts | 2 +- .../src/message/server-type.ts | 0 .../src/network/base.ts | 6 +-- .../src/network/common.ts | 2 +- .../src/request-item.ts | 2 +- .../src/socket-base.ts | 4 +- .../index.ts => page-spy-base/src/utils.ts} | 0 .../tests/atom.test.ts | 0 .../tests/index.test.ts | 0 .../tests/network/base.test.ts | 0 .../tests/network/common.test.ts | 0 .../{base => page-spy-base}/tests/ua.test.ts | 0 packages/page-spy-base/tsconfig.json | 8 ++++ packages/page-spy-browser/package.json | 1 + packages/page-spy-mp-base/package.json | 39 +++++++++++++++++++ .../src/api/index.ts | 0 .../src/config.ts | 0 .../src/helpers/socket.ts | 0 .../src/index.ts | 0 .../src/plugins/console.ts | 0 .../src/plugins/error.ts | 0 .../src/plugins/network/index.ts | 0 .../src/plugins/network/proxy/base.ts | 0 .../src/plugins/network/proxy/request.ts | 0 .../src/plugins/storage.ts | 0 .../src/plugins/system.ts | 0 .../src/types.d.ts | 0 .../src/utils.ts | 0 .../tests/init.test.ts | 0 .../tests/mock/mp.ts | 0 .../tests/mock/request.ts | 0 .../tests/mock/storage.ts | 0 .../tests/plugins/console.test.ts | 0 .../tests/plugins/error.test.ts | 0 .../tests/plugins/network.test.ts | 0 .../tests/plugins/storage.test.ts | 0 .../tests/plugins/util.ts | 0 .../tests/setup.ts | 0 .../tests/utils.test.ts | 0 .../{mp-base => page-spy-mp-base}/yarn.lock | 0 tsconfig.json | 17 ++------ 49 files changed, 110 insertions(+), 38 deletions(-) delete mode 100644 packages/base/package.json delete mode 100644 packages/mp-base/package.json create mode 100644 packages/page-spy-base/package.json rename packages/{base => page-spy-base}/src/atom.ts (98%) rename packages/{base => page-spy-base}/src/client.ts (100%) rename packages/{base => page-spy-base}/src/config.ts (100%) rename packages/{base => page-spy-base}/src/constants.ts (100%) create mode 100644 packages/page-spy-base/src/index.ts rename packages/{base => page-spy-base}/src/message/index.ts (96%) rename packages/{base => page-spy-base}/src/message/server-type.ts (100%) rename packages/{base => page-spy-base}/src/network/base.ts (94%) rename packages/{base => page-spy-base}/src/network/common.ts (99%) rename packages/{base => page-spy-base}/src/request-item.ts (93%) rename packages/{base => page-spy-base}/src/socket-base.ts (99%) rename packages/{base/src/index.ts => page-spy-base/src/utils.ts} (100%) rename packages/{base => page-spy-base}/tests/atom.test.ts (100%) rename packages/{base => page-spy-base}/tests/index.test.ts (100%) rename packages/{base => page-spy-base}/tests/network/base.test.ts (100%) rename packages/{base => page-spy-base}/tests/network/common.test.ts (100%) rename packages/{base => page-spy-base}/tests/ua.test.ts (100%) create mode 100644 packages/page-spy-base/tsconfig.json create mode 100644 packages/page-spy-mp-base/package.json rename packages/{mp-base => page-spy-mp-base}/src/api/index.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/config.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/helpers/socket.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/index.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/console.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/error.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/network/index.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/network/proxy/base.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/network/proxy/request.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/storage.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/plugins/system.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/types.d.ts (100%) rename packages/{mp-base => page-spy-mp-base}/src/utils.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/init.test.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/mock/mp.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/mock/request.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/mock/storage.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/plugins/console.test.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/plugins/error.test.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/plugins/network.test.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/plugins/storage.test.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/plugins/util.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/setup.ts (100%) rename packages/{mp-base => page-spy-mp-base}/tests/utils.test.ts (100%) rename packages/{mp-base => page-spy-mp-base}/yarn.lock (100%) diff --git a/packages/base/package.json b/packages/base/package.json deleted file mode 100644 index 86a67ca2..00000000 --- a/packages/base/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "name": "@huolala-tech/page-spy-base", - "private": true, - "description": "The common utils of PageSpy.", - "dependencies": { - "@huolala-tech/page-spy-types": "*" - } -} diff --git a/packages/mp-base/package.json b/packages/mp-base/package.json deleted file mode 100644 index e2918581..00000000 --- a/packages/mp-base/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "@huolala-tech/page-spy-mp-base", - "private": true, - "description": "The base files of PageSpy mini program.", - "dependencies": {} -} diff --git a/packages/page-spy-base/package.json b/packages/page-spy-base/package.json new file mode 100644 index 00000000..a179ea0d --- /dev/null +++ b/packages/page-spy-base/package.json @@ -0,0 +1,38 @@ +{ + "name": "@huolala-tech/page-spy-base", + "version": "1.9.0", + "description": "The common utils of PageSpy.", + "dependencies": { + "@huolala-tech/page-spy-types": "*" + }, + "license": "MIT", + "main": "dist/iife/index.min.js", + "module": "dist/esm/index.min.js", + "types": "types/index.d.ts", + "scripts": { + "build": "tsc" + }, + "publishConfig": { + "access": "public" + }, + "homepage": "https://www.pagespy.org/", + "repository": { + "type": "git", + "url": "git+https://github.com/HuolalaTech/page-spy.git" + }, + "bugs": { + "url": "https://github.com/HuolalaTech/page-spy/issues" + }, + "files": [ + "dist", + "types" + ], + "keywords": [ + "pagespy", + "debug", + "remote", + "inspect", + "devtools", + "reactnative" + ] +} diff --git a/packages/base/src/atom.ts b/packages/page-spy-base/src/atom.ts similarity index 98% rename from packages/base/src/atom.ts rename to packages/page-spy-base/src/atom.ts index 4461bb25..0be240c4 100644 --- a/packages/base/src/atom.ts +++ b/packages/page-spy-base/src/atom.ts @@ -10,7 +10,7 @@ import { isPlainObject, isPrototype, makePrimitiveValue, -} from './index'; +} from './utils'; export class Atom { private store: Record = {}; @@ -172,4 +172,4 @@ export class Atom { } } -export default new Atom(); +export const atom = new Atom(); diff --git a/packages/base/src/client.ts b/packages/page-spy-base/src/client.ts similarity index 100% rename from packages/base/src/client.ts rename to packages/page-spy-base/src/client.ts diff --git a/packages/base/src/config.ts b/packages/page-spy-base/src/config.ts similarity index 100% rename from packages/base/src/config.ts rename to packages/page-spy-base/src/config.ts diff --git a/packages/base/src/constants.ts b/packages/page-spy-base/src/constants.ts similarity index 100% rename from packages/base/src/constants.ts rename to packages/page-spy-base/src/constants.ts diff --git a/packages/page-spy-base/src/index.ts b/packages/page-spy-base/src/index.ts new file mode 100644 index 00000000..73617a54 --- /dev/null +++ b/packages/page-spy-base/src/index.ts @@ -0,0 +1,11 @@ +export * from './message/index'; +export * from './message/server-type'; +export * from './network/base'; +export * from './network/common'; +export * from './atom'; +export * from './client'; +export * from './config'; +export * from './constants'; +export * from './request-item'; +export * from './socket-base'; +export * from './utils'; diff --git a/packages/base/src/message/index.ts b/packages/page-spy-base/src/message/index.ts similarity index 96% rename from packages/base/src/message/index.ts rename to packages/page-spy-base/src/message/index.ts index f99ce00a..16a95b74 100644 --- a/packages/base/src/message/index.ts +++ b/packages/page-spy-base/src/message/index.ts @@ -1,5 +1,5 @@ import type { SpyMessage, SpySocket } from '@huolala-tech/page-spy-types'; -import { getRandomId } from '../index'; +import { getRandomId } from '../utils'; import * as SERVER_MESSAGE_TYPE from './server-type'; export function makeMessage< diff --git a/packages/base/src/message/server-type.ts b/packages/page-spy-base/src/message/server-type.ts similarity index 100% rename from packages/base/src/message/server-type.ts rename to packages/page-spy-base/src/message/server-type.ts diff --git a/packages/base/src/network/base.ts b/packages/page-spy-base/src/network/base.ts similarity index 94% rename from packages/base/src/network/base.ts rename to packages/page-spy-base/src/network/base.ts index 2edbb6a5..26e6c08f 100644 --- a/packages/base/src/network/base.ts +++ b/packages/page-spy-base/src/network/base.ts @@ -1,11 +1,11 @@ import { makeMessage } from '../message/index'; -import { psLog } from '../index'; -import RequestItem from '../request-item'; +import { psLog } from '../utils'; +import { RequestItem } from '../request-item'; import { SocketStoreBase } from '../socket-base'; import { ReqReadyState } from './common'; type RequestStore = Record; -export default class NetworkProxyBase { +export class NetworkProxyBase { private reqMap: RequestStore = Object.create(null); constructor(private socketStore: SocketStoreBase) {} diff --git a/packages/base/src/network/common.ts b/packages/page-spy-base/src/network/common.ts similarity index 99% rename from packages/base/src/network/common.ts rename to packages/page-spy-base/src/network/common.ts index 63a8f355..f68c0042 100644 --- a/packages/base/src/network/common.ts +++ b/packages/page-spy-base/src/network/common.ts @@ -9,7 +9,7 @@ import { isTypedArray, isURLSearchParams, toStringTag, -} from '../index'; +} from '../utils'; // File size is not recommended to exceed the MAX_SIZE, // big size files would result negative performance impact distinctly in local-test. diff --git a/packages/base/src/request-item.ts b/packages/page-spy-base/src/request-item.ts similarity index 93% rename from packages/base/src/request-item.ts rename to packages/page-spy-base/src/request-item.ts index 046e0c10..4201e957 100644 --- a/packages/base/src/request-item.ts +++ b/packages/page-spy-base/src/request-item.ts @@ -1,6 +1,6 @@ import { SpyNetwork } from '@huolala-tech/page-spy-types'; -export default class RequestItem implements SpyNetwork.RequestInfo { +export class RequestItem implements SpyNetwork.RequestInfo { id = ''; name: string = ''; diff --git a/packages/base/src/socket-base.ts b/packages/page-spy-base/src/socket-base.ts similarity index 99% rename from packages/base/src/socket-base.ts rename to packages/page-spy-base/src/socket-base.ts index 1ebc85f4..0758b0a5 100644 --- a/packages/base/src/socket-base.ts +++ b/packages/page-spy-base/src/socket-base.ts @@ -5,14 +5,14 @@ import { SpyMessage, SpySocket, SpyBase } from '@huolala-tech/page-spy-types'; import { PackedEvent } from '@huolala-tech/page-spy-types/lib/socket-event'; -import { getRandomId, psLog, stringifyData } from './index'; +import { getRandomId, psLog, stringifyData } from './utils'; import { makeMessage, makeBroadcastMessage, makeUnicastMessage, } from './message'; import * as SERVER_MESSAGE_TYPE from './message/server-type'; -import atom from './atom'; +import { atom } from './atom'; import Client from './client'; type InteractiveType = SpyMessage.InteractiveType; diff --git a/packages/base/src/index.ts b/packages/page-spy-base/src/utils.ts similarity index 100% rename from packages/base/src/index.ts rename to packages/page-spy-base/src/utils.ts diff --git a/packages/base/tests/atom.test.ts b/packages/page-spy-base/tests/atom.test.ts similarity index 100% rename from packages/base/tests/atom.test.ts rename to packages/page-spy-base/tests/atom.test.ts diff --git a/packages/base/tests/index.test.ts b/packages/page-spy-base/tests/index.test.ts similarity index 100% rename from packages/base/tests/index.test.ts rename to packages/page-spy-base/tests/index.test.ts diff --git a/packages/base/tests/network/base.test.ts b/packages/page-spy-base/tests/network/base.test.ts similarity index 100% rename from packages/base/tests/network/base.test.ts rename to packages/page-spy-base/tests/network/base.test.ts diff --git a/packages/base/tests/network/common.test.ts b/packages/page-spy-base/tests/network/common.test.ts similarity index 100% rename from packages/base/tests/network/common.test.ts rename to packages/page-spy-base/tests/network/common.test.ts diff --git a/packages/base/tests/ua.test.ts b/packages/page-spy-base/tests/ua.test.ts similarity index 100% rename from packages/base/tests/ua.test.ts rename to packages/page-spy-base/tests/ua.test.ts diff --git a/packages/page-spy-base/tsconfig.json b/packages/page-spy-base/tsconfig.json new file mode 100644 index 00000000..95002ef8 --- /dev/null +++ b/packages/page-spy-base/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "target": "ESNext", + "outDir": "dist" + }, + "include": ["src"] +} diff --git a/packages/page-spy-browser/package.json b/packages/page-spy-browser/package.json index 880a19dd..4220ef8a 100644 --- a/packages/page-spy-browser/package.json +++ b/packages/page-spy-browser/package.json @@ -33,6 +33,7 @@ "dependencies": { "@babel/runtime": "^7.13.0", "@huolala-tech/page-spy-types": "^1.9.0", + "@huolala-tech/page-spy-base": "*", "copy-to-clipboard": "^3.3.1" }, "devDependencies": { diff --git a/packages/page-spy-mp-base/package.json b/packages/page-spy-mp-base/package.json new file mode 100644 index 00000000..fe44a9bd --- /dev/null +++ b/packages/page-spy-mp-base/package.json @@ -0,0 +1,39 @@ +{ + "name": "@huolala-tech/page-spy-mp-base", + "version": "1.9.0", + "description": "The base of PageSpy for miniprogram.", + "license": "MIT", + "main": "dist/iife/index.min.js", + "module": "dist/esm/index.min.js", + "types": "types/index.d.ts", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@huolala-tech/eval5": "^0.0.1", + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-types": "*" + }, + "publishConfig": { + "access": "public" + }, + "homepage": "https://www.pagespy.org/", + "repository": { + "type": "git", + "url": "git+https://github.com/HuolalaTech/page-spy.git" + }, + "bugs": { + "url": "https://github.com/HuolalaTech/page-spy/issues" + }, + "files": [ + "dist", + "types" + ], + "keywords": [ + "pagespy", + "debug", + "remote", + "inspect", + "devtools" + ] +} diff --git a/packages/mp-base/src/api/index.ts b/packages/page-spy-mp-base/src/api/index.ts similarity index 100% rename from packages/mp-base/src/api/index.ts rename to packages/page-spy-mp-base/src/api/index.ts diff --git a/packages/mp-base/src/config.ts b/packages/page-spy-mp-base/src/config.ts similarity index 100% rename from packages/mp-base/src/config.ts rename to packages/page-spy-mp-base/src/config.ts diff --git a/packages/mp-base/src/helpers/socket.ts b/packages/page-spy-mp-base/src/helpers/socket.ts similarity index 100% rename from packages/mp-base/src/helpers/socket.ts rename to packages/page-spy-mp-base/src/helpers/socket.ts diff --git a/packages/mp-base/src/index.ts b/packages/page-spy-mp-base/src/index.ts similarity index 100% rename from packages/mp-base/src/index.ts rename to packages/page-spy-mp-base/src/index.ts diff --git a/packages/mp-base/src/plugins/console.ts b/packages/page-spy-mp-base/src/plugins/console.ts similarity index 100% rename from packages/mp-base/src/plugins/console.ts rename to packages/page-spy-mp-base/src/plugins/console.ts diff --git a/packages/mp-base/src/plugins/error.ts b/packages/page-spy-mp-base/src/plugins/error.ts similarity index 100% rename from packages/mp-base/src/plugins/error.ts rename to packages/page-spy-mp-base/src/plugins/error.ts diff --git a/packages/mp-base/src/plugins/network/index.ts b/packages/page-spy-mp-base/src/plugins/network/index.ts similarity index 100% rename from packages/mp-base/src/plugins/network/index.ts rename to packages/page-spy-mp-base/src/plugins/network/index.ts diff --git a/packages/mp-base/src/plugins/network/proxy/base.ts b/packages/page-spy-mp-base/src/plugins/network/proxy/base.ts similarity index 100% rename from packages/mp-base/src/plugins/network/proxy/base.ts rename to packages/page-spy-mp-base/src/plugins/network/proxy/base.ts diff --git a/packages/mp-base/src/plugins/network/proxy/request.ts b/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts similarity index 100% rename from packages/mp-base/src/plugins/network/proxy/request.ts rename to packages/page-spy-mp-base/src/plugins/network/proxy/request.ts diff --git a/packages/mp-base/src/plugins/storage.ts b/packages/page-spy-mp-base/src/plugins/storage.ts similarity index 100% rename from packages/mp-base/src/plugins/storage.ts rename to packages/page-spy-mp-base/src/plugins/storage.ts diff --git a/packages/mp-base/src/plugins/system.ts b/packages/page-spy-mp-base/src/plugins/system.ts similarity index 100% rename from packages/mp-base/src/plugins/system.ts rename to packages/page-spy-mp-base/src/plugins/system.ts diff --git a/packages/mp-base/src/types.d.ts b/packages/page-spy-mp-base/src/types.d.ts similarity index 100% rename from packages/mp-base/src/types.d.ts rename to packages/page-spy-mp-base/src/types.d.ts diff --git a/packages/mp-base/src/utils.ts b/packages/page-spy-mp-base/src/utils.ts similarity index 100% rename from packages/mp-base/src/utils.ts rename to packages/page-spy-mp-base/src/utils.ts diff --git a/packages/mp-base/tests/init.test.ts b/packages/page-spy-mp-base/tests/init.test.ts similarity index 100% rename from packages/mp-base/tests/init.test.ts rename to packages/page-spy-mp-base/tests/init.test.ts diff --git a/packages/mp-base/tests/mock/mp.ts b/packages/page-spy-mp-base/tests/mock/mp.ts similarity index 100% rename from packages/mp-base/tests/mock/mp.ts rename to packages/page-spy-mp-base/tests/mock/mp.ts diff --git a/packages/mp-base/tests/mock/request.ts b/packages/page-spy-mp-base/tests/mock/request.ts similarity index 100% rename from packages/mp-base/tests/mock/request.ts rename to packages/page-spy-mp-base/tests/mock/request.ts diff --git a/packages/mp-base/tests/mock/storage.ts b/packages/page-spy-mp-base/tests/mock/storage.ts similarity index 100% rename from packages/mp-base/tests/mock/storage.ts rename to packages/page-spy-mp-base/tests/mock/storage.ts diff --git a/packages/mp-base/tests/plugins/console.test.ts b/packages/page-spy-mp-base/tests/plugins/console.test.ts similarity index 100% rename from packages/mp-base/tests/plugins/console.test.ts rename to packages/page-spy-mp-base/tests/plugins/console.test.ts diff --git a/packages/mp-base/tests/plugins/error.test.ts b/packages/page-spy-mp-base/tests/plugins/error.test.ts similarity index 100% rename from packages/mp-base/tests/plugins/error.test.ts rename to packages/page-spy-mp-base/tests/plugins/error.test.ts diff --git a/packages/mp-base/tests/plugins/network.test.ts b/packages/page-spy-mp-base/tests/plugins/network.test.ts similarity index 100% rename from packages/mp-base/tests/plugins/network.test.ts rename to packages/page-spy-mp-base/tests/plugins/network.test.ts diff --git a/packages/mp-base/tests/plugins/storage.test.ts b/packages/page-spy-mp-base/tests/plugins/storage.test.ts similarity index 100% rename from packages/mp-base/tests/plugins/storage.test.ts rename to packages/page-spy-mp-base/tests/plugins/storage.test.ts diff --git a/packages/mp-base/tests/plugins/util.ts b/packages/page-spy-mp-base/tests/plugins/util.ts similarity index 100% rename from packages/mp-base/tests/plugins/util.ts rename to packages/page-spy-mp-base/tests/plugins/util.ts diff --git a/packages/mp-base/tests/setup.ts b/packages/page-spy-mp-base/tests/setup.ts similarity index 100% rename from packages/mp-base/tests/setup.ts rename to packages/page-spy-mp-base/tests/setup.ts diff --git a/packages/mp-base/tests/utils.test.ts b/packages/page-spy-mp-base/tests/utils.test.ts similarity index 100% rename from packages/mp-base/tests/utils.test.ts rename to packages/page-spy-mp-base/tests/utils.test.ts diff --git a/packages/mp-base/yarn.lock b/packages/page-spy-mp-base/yarn.lock similarity index 100% rename from packages/mp-base/yarn.lock rename to packages/page-spy-mp-base/yarn.lock diff --git a/tsconfig.json b/tsconfig.json index e9a2c452..338c02db 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,8 +1,7 @@ { - "compileOnSave": false, "compilerOptions": { "rootDir": ".", - "declaration": false, + "declaration": true, "noEmit": true, "strict": true, "resolveJsonModule": true, @@ -16,18 +15,8 @@ "esModuleInterop": true, "allowSyntheticDefaultImports": true, "forceConsistentCasingInFileNames": true, - "noFallthroughCasesInSwitch": true, "isolatedModules": true, - "allowJs": true, - "baseUrl": ".", - "paths": { - "base/*": ["./packages/base/*"], - "mp-base/*": ["./packages/mp-base/*"], - "page-spy-browser/*": ["./packages/page-spy-browser/*"], - "page-spy-wechat/*": ["./packages/page-spy-wechat/*"], - "page-spy-react-native/*": ["./packages/page-spy-react-native/*"], - "page-spy-plugins/*": ["./packages/page-spy-plugins/*"] - } + "allowJs": true }, - "exclude": ["**/node_modules", "**/dist", "packages/page-spy-harmony"] + "exclude": ["**/dist", "packages/page-spy-harmony"] } From a96ead5432ba6bd4b0964ee2ec78ad4436eb7d64 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 13:49:57 +0800 Subject: [PATCH 02/13] refactor page-spy-(base|mp-base|browser) --- jest.config.ts | 10 ++-- packages/page-spy-base/package.json | 8 ++-- packages/page-spy-base/src/client.ts | 2 +- packages/page-spy-base/src/socket-base.ts | 2 +- packages/page-spy-base/tests/atom.test.ts | 2 +- packages/page-spy-base/tests/index.test.ts | 2 +- .../page-spy-base/tests/network/base.test.ts | 6 +-- .../tests/network/common.test.ts | 2 +- packages/page-spy-base/tests/ua.test.ts | 2 +- packages/page-spy-base/tsconfig.json | 3 ++ packages/page-spy-browser/package.json | 4 +- packages/page-spy-browser/rollup.config.mjs | 8 +--- packages/page-spy-browser/src/api/index.ts | 4 +- .../page-spy-browser/src/component/content.ts | 2 +- packages/page-spy-browser/src/config.ts | 46 ++++++++++++++++++- .../page-spy-browser/src/helpers/socket.ts | 10 ++-- packages/page-spy-browser/src/index.ts | 15 ++++-- .../page-spy-browser/src/plugins/console.ts | 6 +-- .../page-spy-browser/src/plugins/database.ts | 5 +- .../page-spy-browser/src/plugins/error.ts | 7 +-- .../src/plugins/network/proxy/base.ts | 4 +- .../src/plugins/network/proxy/beacon-proxy.ts | 5 +- .../src/plugins/network/proxy/fetch-proxy.ts | 4 +- .../src/plugins/network/proxy/sse-proxy.ts | 9 ++-- .../src/plugins/network/proxy/xhr-proxy.ts | 6 +-- packages/page-spy-browser/src/plugins/page.ts | 5 +- .../page-spy-browser/src/plugins/storage.ts | 4 +- .../src/plugins/system/feature.ts | 2 +- .../src/plugins/system/index.ts | 4 +- .../tests/helpers/blob.test.ts | 2 +- .../tests/helpers/socket.test.ts | 4 +- packages/page-spy-browser/tests/init.test.ts | 6 +-- .../tests/plugins/network/common.test.ts | 4 +- .../tests/plugins/network/fetch-proxy.test.ts | 2 +- .../tests/plugins/network/util.ts | 2 +- .../tests/plugins/network/xhr-proxy.test.ts | 2 +- packages/page-spy-browser/tests/tsconfig.json | 3 ++ packages/page-spy-browser/tsconfig.json | 9 ++++ packages/page-spy-browser/types/index.d.ts | 41 ----------------- packages/page-spy-mp-base/package.json | 16 +++++-- packages/page-spy-mp-base/src/api/index.ts | 5 +- packages/page-spy-mp-base/src/config.ts | 2 +- .../page-spy-mp-base/src/helpers/socket.ts | 10 ++-- packages/page-spy-mp-base/src/index.ts | 15 ++++-- .../page-spy-mp-base/src/plugins/console.ts | 5 +- .../page-spy-mp-base/src/plugins/error.ts | 7 +-- .../src/plugins/network/proxy/base.ts | 4 +- .../src/plugins/network/proxy/request.ts | 12 +++-- .../page-spy-mp-base/src/plugins/storage.ts | 6 +-- .../page-spy-mp-base/src/plugins/system.ts | 5 +- packages/page-spy-mp-base/tests/init.test.ts | 16 +++---- packages/page-spy-mp-base/tests/mock/mp.ts | 2 +- .../page-spy-mp-base/tests/mock/storage.ts | 2 +- .../tests/plugins/console.test.ts | 2 +- .../tests/plugins/error.test.ts | 2 +- .../tests/plugins/network.test.ts | 2 +- .../tests/plugins/storage.test.ts | 4 +- .../page-spy-mp-base/tests/plugins/util.ts | 4 +- packages/page-spy-mp-base/tests/setup.ts | 2 +- packages/page-spy-mp-base/tests/utils.test.ts | 2 +- packages/page-spy-mp-base/tsconfig.cjs.json | 13 ++++++ packages/page-spy-mp-base/tsconfig.esm.json | 13 ++++++ tsconfig.json | 5 +- tsconfig.paths.json | 12 +++++ yarn.lock | 5 ++ 65 files changed, 250 insertions(+), 187 deletions(-) create mode 100644 packages/page-spy-browser/tests/tsconfig.json create mode 100644 packages/page-spy-browser/tsconfig.json create mode 100644 packages/page-spy-mp-base/tsconfig.cjs.json create mode 100644 packages/page-spy-mp-base/tsconfig.esm.json create mode 100644 tsconfig.paths.json diff --git a/jest.config.ts b/jest.config.ts index c9a34989..2d9cf3dc 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,6 +1,6 @@ import type { Config } from 'jest'; import { pathsToModuleNameMapper } from 'ts-jest'; -import tsConfig from './tsconfig.json'; +import tsConfig from './tsconfig.paths.json'; const moduleNameMapper = { ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { @@ -36,7 +36,7 @@ const config: Config = { }, preset: 'ts-jest', testEnvironment: 'jsdom', - testMatch: ['**/packages/base/tests/**/*.test.ts'], + testMatch: ['**/packages/page-spy-base/tests/**/*.test.ts'], moduleNameMapper, }, { @@ -59,9 +59,11 @@ const config: Config = { color: 'green', }, preset: 'ts-jest', - testMatch: ['**/packages/mp-base/tests/**/*.test.ts'], + testMatch: ['**/packages/page-spy-mp-base/tests/**/*.test.ts'], moduleNameMapper, - setupFilesAfterEnv: ['/packages/mp-base/tests/setup.ts'], + setupFilesAfterEnv: [ + '/packages/page-spy-mp-base/tests/setup.ts', + ], }, ], }; diff --git a/packages/page-spy-base/package.json b/packages/page-spy-base/package.json index a179ea0d..c066d552 100644 --- a/packages/page-spy-base/package.json +++ b/packages/page-spy-base/package.json @@ -6,11 +6,11 @@ "@huolala-tech/page-spy-types": "*" }, "license": "MIT", - "main": "dist/iife/index.min.js", - "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", "scripts": { - "build": "tsc" + "build": "yarn clean && tsc", + "clean": "rm -rf ./dist" }, "publishConfig": { "access": "public" diff --git a/packages/page-spy-base/src/client.ts b/packages/page-spy-base/src/client.ts index b2e5d2f2..1bc51b7d 100644 --- a/packages/page-spy-base/src/client.ts +++ b/packages/page-spy-base/src/client.ts @@ -71,7 +71,7 @@ export const combineName = ({ }: SpyClient.ClientInfo) => `${osType}/${osVersion} ${browserType}/${browserVersion}`; -export default class Client { +export class Client { static info: SpyClient.ClientInfo = { // browserName and framework should be overwritten by package implementation\ osType: 'unknown', diff --git a/packages/page-spy-base/src/socket-base.ts b/packages/page-spy-base/src/socket-base.ts index 0758b0a5..562c5572 100644 --- a/packages/page-spy-base/src/socket-base.ts +++ b/packages/page-spy-base/src/socket-base.ts @@ -13,7 +13,7 @@ import { } from './message'; import * as SERVER_MESSAGE_TYPE from './message/server-type'; import { atom } from './atom'; -import Client from './client'; +import { Client } from './client'; type InteractiveType = SpyMessage.InteractiveType; type InternalMsgType = SpyMessage.InternalMsgType; diff --git a/packages/page-spy-base/tests/atom.test.ts b/packages/page-spy-base/tests/atom.test.ts index be8b6ed2..558f3450 100644 --- a/packages/page-spy-base/tests/atom.test.ts +++ b/packages/page-spy-base/tests/atom.test.ts @@ -1,4 +1,4 @@ -import atom from 'base/src/atom'; +import { atom } from '../src'; // jest.mock('base/src/utils/atom.ts'); beforeEach(() => { diff --git a/packages/page-spy-base/tests/index.test.ts b/packages/page-spy-base/tests/index.test.ts index 51478a81..7fdf4575 100644 --- a/packages/page-spy-base/tests/index.test.ts +++ b/packages/page-spy-base/tests/index.test.ts @@ -1,4 +1,4 @@ -import { makePrimitiveValue, getValueType, isArrayLike } from 'base/src/index'; +import { makePrimitiveValue, getValueType, isArrayLike } from '../src'; describe('makePrimitiveValue: convert data to showable string', () => { it('✅ Primitive is ok', () => { diff --git a/packages/page-spy-base/tests/network/base.test.ts b/packages/page-spy-base/tests/network/base.test.ts index c2d7647d..4e6bede8 100644 --- a/packages/page-spy-base/tests/network/base.test.ts +++ b/packages/page-spy-base/tests/network/base.test.ts @@ -2,9 +2,9 @@ import { SocketState, SocketStoreBase, SocketWrapper, -} from 'base/src/socket-base'; -import NetworkProxyBase from 'base/src/network/base'; -import RequestItem from 'base/src/request-item'; + NetworkProxyBase, + RequestItem, +} from '../../src'; class PlatformSocketWrapper extends SocketWrapper { init(url: string): void { diff --git a/packages/page-spy-base/tests/network/common.test.ts b/packages/page-spy-base/tests/network/common.test.ts index 8cc21182..af0156b2 100644 --- a/packages/page-spy-base/tests/network/common.test.ts +++ b/packages/page-spy-base/tests/network/common.test.ts @@ -1,4 +1,4 @@ -import { getFormattedBody } from 'base/src/network/common'; +import { getFormattedBody } from '../../src'; describe('Network common utils', () => { it('getFormattedBody()', () => { diff --git a/packages/page-spy-base/tests/ua.test.ts b/packages/page-spy-base/tests/ua.test.ts index 49c655cf..77906270 100644 --- a/packages/page-spy-base/tests/ua.test.ts +++ b/packages/page-spy-base/tests/ua.test.ts @@ -1,4 +1,4 @@ -import { parseUserAgent } from 'base/src/client'; +import { parseUserAgent } from '../src'; // The following `userAgent` info generated by ChatGpt. describe('Parse navigator.userAgent', () => { diff --git a/packages/page-spy-base/tsconfig.json b/packages/page-spy-base/tsconfig.json index 95002ef8..34229bab 100644 --- a/packages/page-spy-base/tsconfig.json +++ b/packages/page-spy-base/tsconfig.json @@ -1,7 +1,10 @@ { "extends": "../../tsconfig.json", "compilerOptions": { + "rootDir": "./src", "target": "ESNext", + "module": "ESNext", + "noEmit": false, "outDir": "dist" }, "include": ["src"] diff --git a/packages/page-spy-browser/package.json b/packages/page-spy-browser/package.json index 4220ef8a..33fc4a83 100644 --- a/packages/page-spy-browser/package.json +++ b/packages/page-spy-browser/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "dist/iife/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -32,8 +32,8 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0", "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-types": "^1.9.0", "copy-to-clipboard": "^3.3.1" }, "devDependencies": { diff --git a/packages/page-spy-browser/rollup.config.mjs b/packages/page-spy-browser/rollup.config.mjs index b50e4c02..4a20ee83 100644 --- a/packages/page-spy-browser/rollup.config.mjs +++ b/packages/page-spy-browser/rollup.config.mjs @@ -23,7 +23,7 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - // exclude: '**/tests/**/*.test.ts', + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, @@ -34,12 +34,6 @@ const plugins = [ extract: false, plugins: [autoprefixer()], }), - alias({ - entries: [ - { find: 'page-spy-browser', replacement: root }, - { find: 'base', replacement: resolve(root, '../base') }, - ], - }), terser(), ]; diff --git a/packages/page-spy-browser/src/api/index.ts b/packages/page-spy-browser/src/api/index.ts index c3fe4f17..11adca2e 100644 --- a/packages/page-spy-browser/src/api/index.ts +++ b/packages/page-spy-browser/src/api/index.ts @@ -1,5 +1,5 @@ -import { getRandomId } from 'base/src'; -import { InitConfig } from 'page-spy-browser/types'; +import { getRandomId } from '@huolala-tech/page-spy-base'; +import { InitConfig } from '../config'; interface TResponse { code: string; diff --git a/packages/page-spy-browser/src/component/content.ts b/packages/page-spy-browser/src/component/content.ts index 32433c6b..b7b53109 100644 --- a/packages/page-spy-browser/src/component/content.ts +++ b/packages/page-spy-browser/src/component/content.ts @@ -1,4 +1,4 @@ -import { isCN } from 'base/src'; +import { isCN } from '@huolala-tech/page-spy-base'; interface ContentParams { className?: string; diff --git a/packages/page-spy-browser/src/config.ts b/packages/page-spy-browser/src/config.ts index 0587bfa1..3ba74670 100644 --- a/packages/page-spy-browser/src/config.ts +++ b/packages/page-spy-browser/src/config.ts @@ -1,7 +1,49 @@ -import { ConfigBase } from 'base/src/config'; -import type { InitConfig } from 'page-spy-browser/types/index'; +import { ConfigBase } from '@huolala-tech/page-spy-base'; +import { InitConfigBase } from '@huolala-tech/page-spy-types'; import logoUrl from './assets/logo.svg'; +type InternalPlugins = + | 'ConsolePlugin' + | 'ErrorPlugin' + | 'NetworkPlugin' + | 'StoragePlugin' + | 'DatabasePlugin' + | 'PagePlugin' + | 'SystemPlugin'; + +export interface InitConfig extends InitConfigBase { + /** + * Client host. Form example, "https://example.com". + */ + clientOrigin?: string; + /** + * Indicate whether auto render the widget on the bottom-left corner. + * You can manually render later by calling "window.$pageSpy.render()" + * if passed false. + * @default true + */ + autoRender?: boolean; + /** + * All internal plugins are carried with PageSpy by default out of the box. + * You can disable some plugins as needed. + */ + disabledPlugins?: (InternalPlugins | string)[]; + /** + * Indicate whether enable offline mode. Once enabled, PageSpy will not + * make network requests and send data by server. Collected data can be + * exported with "DataHarborPlugin" and then replayed in the debugger. + */ + offline?: boolean; + /** + * Customize logo source url. + */ + logo?: string; + /** + * Customize logo style. + */ + logoStyle?: Object; +} + export class Config extends ConfigBase { protected privateKeys: (keyof InitConfig)[] = ['secret']; diff --git a/packages/page-spy-browser/src/helpers/socket.ts b/packages/page-spy-browser/src/helpers/socket.ts index 9ad3463f..416ad7fe 100644 --- a/packages/page-spy-browser/src/helpers/socket.ts +++ b/packages/page-spy-browser/src/helpers/socket.ts @@ -1,13 +1,13 @@ -import { stringifyData } from 'base/src'; -import { ROOM_SESSION_KEY } from 'base/src/constants'; -import { UPDATE_ROOM_INFO } from 'base/src/message/server-type'; import { + stringifyData, + ROOM_SESSION_KEY, + UPDATE_ROOM_INFO, SocketStoreBase, SocketState, SocketWrapper, WebSocketEvents, -} from 'base/src/socket-base'; -import { InitConfig } from 'page-spy-browser/types'; +} from '@huolala-tech/page-spy-base'; +import { InitConfig } from '../config'; export class WebSocketWrapper extends SocketWrapper { private socketInstance: WebSocket | null = null; diff --git a/packages/page-spy-browser/src/index.ts b/packages/page-spy-browser/src/index.ts index b6426176..7ccb50d1 100644 --- a/packages/page-spy-browser/src/index.ts +++ b/packages/page-spy-browser/src/index.ts @@ -1,14 +1,20 @@ -import type { InitConfig } from 'page-spy-browser/types/index'; import copy from 'copy-to-clipboard'; -import { getAuthSecret, isArray, isClass, psLog } from 'base/src'; -import { ROOM_SESSION_KEY } from 'base/src/constants'; +import { + Client, + getAuthSecret, + isArray, + isClass, + psLog, + ROOM_SESSION_KEY, + SocketState, +} from '@huolala-tech/page-spy-base'; import type { PageSpyPlugin, PageSpyPluginLifecycle, PageSpyPluginLifecycleArgs, PluginOrder, } from '@huolala-tech/page-spy-types'; -import { SocketState } from 'base/src/socket-base'; +import type { InitConfig } from './config'; import { Modal } from './component/modal'; import { Content } from './component/content'; @@ -29,7 +35,6 @@ import './index.less'; // eslint-disable-next-line import/order import { Config } from './config'; import { Toast } from './component/toast'; -import Client from 'base/src/client'; const Identifier = '__pageSpy'; diff --git a/packages/page-spy-browser/src/plugins/console.ts b/packages/page-spy-browser/src/plugins/console.ts index 8216457c..44ffa73b 100644 --- a/packages/page-spy-browser/src/plugins/console.ts +++ b/packages/page-spy-browser/src/plugins/console.ts @@ -1,12 +1,10 @@ -import { makeMessage } from 'base/src/message'; -import socketStore from 'page-spy-browser/src/helpers/socket'; import type { SpyConsole, PageSpyPlugin, SpyBase, } from '@huolala-tech/page-spy-types'; -import atom from 'base/src/atom'; -import { getRandomId } from 'base/src'; +import { atom, getRandomId, makeMessage } from '@huolala-tech/page-spy-base'; +import socketStore from '../helpers/socket'; export default class ConsolePlugin implements PageSpyPlugin { public name: string = 'ConsolePlugin'; diff --git a/packages/page-spy-browser/src/plugins/database.ts b/packages/page-spy-browser/src/plugins/database.ts index a5d1188d..01b02a18 100644 --- a/packages/page-spy-browser/src/plugins/database.ts +++ b/packages/page-spy-browser/src/plugins/database.ts @@ -1,8 +1,7 @@ import { DBInfo, DBStoreInfo } from '@huolala-tech/page-spy-types/lib/database'; -import { psLog } from 'base/src'; -import socketStore from 'page-spy-browser/src/helpers/socket'; -import { makeMessage } from 'base/src/message'; +import { psLog, makeMessage } from '@huolala-tech/page-spy-base'; import { SpyDatabase, PageSpyPlugin } from '@huolala-tech/page-spy-types'; +import socketStore from '../helpers/socket'; export function promisify(req: IDBRequest): Promise { return new Promise((resolve, reject) => { diff --git a/packages/page-spy-browser/src/plugins/error.ts b/packages/page-spy-browser/src/plugins/error.ts index 1d3da21b..318dfcd8 100644 --- a/packages/page-spy-browser/src/plugins/error.ts +++ b/packages/page-spy-browser/src/plugins/error.ts @@ -1,9 +1,6 @@ -/* eslint-disable class-methods-use-this */ -import atom from 'base/src/atom'; -import { makeMessage } from 'base/src/message'; -import socketStore from 'page-spy-browser/src/helpers/socket'; +import { atom, formatErrorObj, makeMessage } from '@huolala-tech/page-spy-base'; import type { SpyConsole, PageSpyPlugin } from '@huolala-tech/page-spy-types'; -import { formatErrorObj } from 'base/src'; +import socketStore from '../helpers/socket'; export default class ErrorPlugin implements PageSpyPlugin { public name = 'ErrorPlugin'; diff --git a/packages/page-spy-browser/src/plugins/network/proxy/base.ts b/packages/page-spy-browser/src/plugins/network/proxy/base.ts index d2e7b03b..30526561 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/base.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/base.ts @@ -1,5 +1,5 @@ -import socketStore from 'page-spy-browser/src/helpers/socket'; -import NetworkProxyBase from 'base/src/network/base'; +import { NetworkProxyBase } from '@huolala-tech/page-spy-base'; +import socketStore from '../../../helpers/socket'; export default class WebNetworkProxyBase extends NetworkProxyBase { constructor() { diff --git a/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts index 1eb0ade4..e8e32326 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts @@ -1,9 +1,10 @@ -import { getRandomId, psLog } from 'base/src'; import { addContentTypeHeader, + getRandomId, + psLog, getFormattedBody, resolveUrlInfo, -} from 'base/src/network/common'; +} from '@huolala-tech/page-spy-base'; import WebNetworkProxyBase from './base'; export default class BeaconProxy extends WebNetworkProxyBase { diff --git a/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts index fc61d327..0f0cb5b9 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts @@ -6,14 +6,12 @@ import { isString, isURL, psLog, -} from 'base/src'; -import { addContentTypeHeader, getFormattedBody, MAX_SIZE, Reason, resolveUrlInfo, -} from 'base/src/network/common'; +} from '@huolala-tech/page-spy-base'; import WebNetworkProxyBase from './base'; export default class FetchProxy extends WebNetworkProxyBase { diff --git a/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts index c4214380..76f4ae46 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts @@ -1,6 +1,9 @@ -import { getRandomId } from 'base/src'; -import RequestItem from 'base/src/request-item'; -import { ReqReadyState, resolveUrlInfo } from 'base/src/network/common'; +import { + getRandomId, + RequestItem, + ReqReadyState, + resolveUrlInfo, +} from '@huolala-tech/page-spy-base'; import WebNetworkProxyBase from './base'; const OriginEventSource = window.EventSource; diff --git a/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts index 1e60c91a..102ccc06 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts @@ -7,15 +7,13 @@ import { getObjectKeys, psLog, blob2base64Async, -} from 'base/src'; -import RequestItem from 'base/src/request-item'; -import { MAX_SIZE, Reason, addContentTypeHeader, getFormattedBody, resolveUrlInfo, -} from 'base/src/network/common'; + RequestItem, +} from '@huolala-tech/page-spy-base'; import WebNetworkProxyBase from './base'; declare global { diff --git a/packages/page-spy-browser/src/plugins/page.ts b/packages/page-spy-browser/src/plugins/page.ts index 8d211fc8..4ffbd3aa 100644 --- a/packages/page-spy-browser/src/plugins/page.ts +++ b/packages/page-spy-browser/src/plugins/page.ts @@ -1,13 +1,12 @@ -import socketStore from 'page-spy-browser/src/helpers/socket'; import type { PageSpyPlugin } from '@huolala-tech/page-spy-types'; -import { makeMessage } from 'base/src/message'; +import { makeMessage } from '@huolala-tech/page-spy-base'; +import socketStore from '../helpers/socket'; export default class PagePlugin implements PageSpyPlugin { public name = 'PagePlugin'; public static hasInitd = false; - // eslint-disable-next-line class-methods-use-this public onInit() { if (PagePlugin.hasInitd) return; PagePlugin.hasInitd = true; diff --git a/packages/page-spy-browser/src/plugins/storage.ts b/packages/page-spy-browser/src/plugins/storage.ts index c91983cb..9389020d 100644 --- a/packages/page-spy-browser/src/plugins/storage.ts +++ b/packages/page-spy-browser/src/plugins/storage.ts @@ -1,6 +1,6 @@ -import { makeMessage } from 'base/src/message'; +import { makeMessage } from '@huolala-tech/page-spy-base'; import { SpyStorage, PageSpyPlugin } from '@huolala-tech/page-spy-types'; -import socketStore from 'page-spy-browser/src/helpers/socket'; +import socketStore from '../helpers/socket'; export class StoragePlugin implements PageSpyPlugin { public name = 'StoragePlugin'; diff --git a/packages/page-spy-browser/src/plugins/system/feature.ts b/packages/page-spy-browser/src/plugins/system/feature.ts index d95ae4b1..37a8b730 100644 --- a/packages/page-spy-browser/src/plugins/system/feature.ts +++ b/packages/page-spy-browser/src/plugins/system/feature.ts @@ -1,4 +1,4 @@ -import { getObjectKeys, hasOwnProperty } from 'base/src'; +import { getObjectKeys, hasOwnProperty } from '@huolala-tech/page-spy-base'; import type { SpySystem } from '@huolala-tech/page-spy-types'; export const FEATURE_MAP: SpySystem.Feature = { diff --git a/packages/page-spy-browser/src/plugins/system/index.ts b/packages/page-spy-browser/src/plugins/system/index.ts index 7563a927..b2287c0b 100644 --- a/packages/page-spy-browser/src/plugins/system/index.ts +++ b/packages/page-spy-browser/src/plugins/system/index.ts @@ -1,7 +1,7 @@ -import socketStore from 'page-spy-browser/src/helpers/socket'; -import { makeMessage } from 'base/src/message'; +import { makeMessage } from '@huolala-tech/page-spy-base'; import '../../deps/modernizr'; import { SpySystem, PageSpyPlugin } from '@huolala-tech/page-spy-types'; +import socketStore from '../../helpers/socket'; import { computeResult } from './feature'; window.Modernizr.addTest( diff --git a/packages/page-spy-browser/tests/helpers/blob.test.ts b/packages/page-spy-browser/tests/helpers/blob.test.ts index 4f3153b2..a82aa511 100644 --- a/packages/page-spy-browser/tests/helpers/blob.test.ts +++ b/packages/page-spy-browser/tests/helpers/blob.test.ts @@ -1,4 +1,4 @@ -import { blob2base64Async } from 'base/src'; +import { blob2base64Async } from 'page-spy-base/src'; describe('blob2base64Async', () => { test('should convert a Blob to base64', async () => { diff --git a/packages/page-spy-browser/tests/helpers/socket.test.ts b/packages/page-spy-browser/tests/helpers/socket.test.ts index 3a9a1d0f..baccb170 100644 --- a/packages/page-spy-browser/tests/helpers/socket.test.ts +++ b/packages/page-spy-browser/tests/helpers/socket.test.ts @@ -4,9 +4,9 @@ import type { ConnectEvent, ErrorEvent, } from '@huolala-tech/page-spy-types/lib/socket-event'; -import * as SERVER_MESSAGE_TYPE from 'base/src/message/server-type'; +import * as SERVER_MESSAGE_TYPE from 'page-spy-base/src'; import { SpyMessage } from '@huolala-tech/page-spy-types'; -import { SocketState } from 'base/src/socket-base'; +import { SocketState } from 'page-spy-base/src'; // Mock micro task delay const sleep = (t = 100) => new Promise((r) => setTimeout(r, t)); diff --git a/packages/page-spy-browser/tests/init.test.ts b/packages/page-spy-browser/tests/init.test.ts index 95daf891..081b1498 100644 --- a/packages/page-spy-browser/tests/init.test.ts +++ b/packages/page-spy-browser/tests/init.test.ts @@ -7,11 +7,9 @@ import PagePlugin from 'page-spy-browser/src/plugins/page'; import { StoragePlugin } from 'page-spy-browser/src/plugins/storage'; import { SpyConsole } from '@huolala-tech/page-spy-types'; import socketStore from 'page-spy-browser/src/helpers/socket'; -import { ROOM_SESSION_KEY } from 'base/src/constants'; -import { Config } from 'page-spy-browser/src/config'; -import { isBrowser } from 'base/src'; +import { ROOM_SESSION_KEY } from 'page-spy-base/src'; +import { isBrowser } from 'page-spy-base/src'; import Request from 'page-spy-browser/src/api'; -import { JSDOM } from 'jsdom'; import { DatabasePlugin } from 'page-spy-browser/src/plugins/database'; const sleep = (t = 100) => new Promise((r) => setTimeout(r, t)); diff --git a/packages/page-spy-browser/tests/plugins/network/common.test.ts b/packages/page-spy-browser/tests/plugins/network/common.test.ts index 7ef5363d..fbec1ff5 100644 --- a/packages/page-spy-browser/tests/plugins/network/common.test.ts +++ b/packages/page-spy-browser/tests/plugins/network/common.test.ts @@ -5,8 +5,8 @@ import { getContentType, getFormattedBody, resolveUrlInfo, -} from 'base/src/network/common'; -import { isBrowser, toStringTag } from 'base/src'; +} from 'page-spy-base/src'; +import { isBrowser, toStringTag } from 'page-spy-base/src'; describe('Network utilities', () => { // format the USP and FormData data which be used in request payload, diff --git a/packages/page-spy-browser/tests/plugins/network/fetch-proxy.test.ts b/packages/page-spy-browser/tests/plugins/network/fetch-proxy.test.ts index 84972989..aaee53b1 100644 --- a/packages/page-spy-browser/tests/plugins/network/fetch-proxy.test.ts +++ b/packages/page-spy-browser/tests/plugins/network/fetch-proxy.test.ts @@ -1,7 +1,7 @@ import NetworkPlugin from 'page-spy-browser/src/plugins/network'; import startServer from '../../server/index'; import data from '../../server/data.json'; -import { Reason } from 'base/src/network/common'; +import { Reason } from 'page-spy-base/src'; import { computeRequestMapInfo } from './util'; const port = 6688; diff --git a/packages/page-spy-browser/tests/plugins/network/util.ts b/packages/page-spy-browser/tests/plugins/network/util.ts index b33b7fe1..87f5e655 100644 --- a/packages/page-spy-browser/tests/plugins/network/util.ts +++ b/packages/page-spy-browser/tests/plugins/network/util.ts @@ -1,6 +1,6 @@ import BeaconProxy from 'page-spy-browser/src/plugins/network/proxy/beacon-proxy'; import FetchProxy from 'page-spy-browser/src/plugins/network/proxy/fetch-proxy'; -import RequestItem from 'base/src/request-item'; +import RequestItem from 'page-spy-base/src'; import XhrProxy from 'page-spy-browser/src/plugins/network/proxy/xhr-proxy'; type RequestStore = Record; diff --git a/packages/page-spy-browser/tests/plugins/network/xhr-proxy.test.ts b/packages/page-spy-browser/tests/plugins/network/xhr-proxy.test.ts index d4b21912..6f88076e 100644 --- a/packages/page-spy-browser/tests/plugins/network/xhr-proxy.test.ts +++ b/packages/page-spy-browser/tests/plugins/network/xhr-proxy.test.ts @@ -1,7 +1,7 @@ import NetworkPlugin from 'page-spy-browser/src/plugins/network'; import startServer from '../../server/index'; import data from '../../server/data.json'; -import { Reason } from 'base/src/network/common'; +import { Reason } from 'page-spy-base/src'; import { computeRequestMapInfo } from './util'; const port = 6677; diff --git a/packages/page-spy-browser/tests/tsconfig.json b/packages/page-spy-browser/tests/tsconfig.json new file mode 100644 index 00000000..b437ab5b --- /dev/null +++ b/packages/page-spy-browser/tests/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": ["../../../tsconfig.paths.json"] +} diff --git a/packages/page-spy-browser/tsconfig.json b/packages/page-spy-browser/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-browser/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-browser/types/index.d.ts b/packages/page-spy-browser/types/index.d.ts index a5f38ffb..7b51e25d 100644 --- a/packages/page-spy-browser/types/index.d.ts +++ b/packages/page-spy-browser/types/index.d.ts @@ -6,47 +6,6 @@ import { PageSpyPluginLifecycleArgs, } from '@huolala-tech/page-spy-types'; -type InternalPlugins = - | 'ConsolePlugin' - | 'ErrorPlugin' - | 'NetworkPlugin' - | 'StoragePlugin' - | 'DatabasePlugin' - | 'PagePlugin' - | 'SystemPlugin'; -export interface InitConfig extends InitConfigBase { - /** - * Client host. Form example, "https://example.com". - */ - clientOrigin?: string; - /** - * Indicate whether auto render the widget on the bottom-left corner. - * You can manually render later by calling "window.$pageSpy.render()" - * if passed false. - * @default true - */ - autoRender?: boolean; - /** - * All internal plugins are carried with PageSpy by default out of the box. - * You can disable some plugins as needed. - */ - disabledPlugins?: (InternalPlugins | string)[]; - /** - * Indicate whether enable offline mode. Once enabled, PageSpy will not - * make network requests and send data by server. Collected data can be - * exported with "DataHarborPlugin" and then replayed in the debugger. - */ - offline?: boolean; - /** - * Customize logo source url. - */ - logo?: string; - /** - * Customize logo style. - */ - logoStyle?: Object; -} - interface PageSpyBrowser extends PageSpyBase { root: HTMLElement | null; config: Required | null; diff --git a/packages/page-spy-mp-base/package.json b/packages/page-spy-mp-base/package.json index fe44a9bd..c88a6bb7 100644 --- a/packages/page-spy-mp-base/package.json +++ b/packages/page-spy-mp-base/package.json @@ -3,11 +3,14 @@ "version": "1.9.0", "description": "The base of PageSpy for miniprogram.", "license": "MIT", - "main": "dist/iife/index.min.js", - "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "main": "dist/cjs/index.js", + "module": "dist/esm/index.js", + "types": "dist/types/index.d.ts", "scripts": { - "build": "tsc" + "build": "yarn clean && yarn build:cjs && yarn build:esm ", + "build:esm": "tsc --project tsconfig.esm.json", + "build:cjs": "tsc --project tsconfig.cjs.json", + "clean": "rm -rf dist" }, "dependencies": { "@huolala-tech/eval5": "^0.0.1", @@ -35,5 +38,8 @@ "remote", "inspect", "devtools" - ] + ], + "devDependencies": { + "typescript": "^5.5.3" + } } diff --git a/packages/page-spy-mp-base/src/api/index.ts b/packages/page-spy-mp-base/src/api/index.ts index 3edfbb08..01bf3706 100644 --- a/packages/page-spy-mp-base/src/api/index.ts +++ b/packages/page-spy-mp-base/src/api/index.ts @@ -1,7 +1,6 @@ import type { SpyMP } from '@huolala-tech/page-spy-types'; -import Client, { combineName } from 'base/src/client'; -import { getMPSDK, joinQuery, promisifyMPApi } from 'mp-base/src/utils'; -import { getRandomId } from 'base/src'; +import { Client, combineName, getRandomId } from '@huolala-tech/page-spy-base'; +import { getMPSDK, joinQuery, promisifyMPApi } from '../utils'; import { Config } from '../config'; interface TResponse { diff --git a/packages/page-spy-mp-base/src/config.ts b/packages/page-spy-mp-base/src/config.ts index 81a343b0..f6479191 100644 --- a/packages/page-spy-mp-base/src/config.ts +++ b/packages/page-spy-mp-base/src/config.ts @@ -1,4 +1,4 @@ -import { ConfigBase } from 'base/src/config'; +import { ConfigBase } from '@huolala-tech/page-spy-base'; import type { SpyMP } from '@huolala-tech/page-spy-types'; export class Config extends ConfigBase { diff --git a/packages/page-spy-mp-base/src/helpers/socket.ts b/packages/page-spy-mp-base/src/helpers/socket.ts index 85427fee..bac525eb 100644 --- a/packages/page-spy-mp-base/src/helpers/socket.ts +++ b/packages/page-spy-mp-base/src/helpers/socket.ts @@ -1,14 +1,14 @@ -import { ROOM_SESSION_KEY } from 'base/src/constants'; import { + Client, SocketStoreBase, SocketState, SocketWrapper, -} from 'base/src/socket-base'; -import { UPDATE_ROOM_INFO } from 'base/src/message/server-type'; + combineName, + UPDATE_ROOM_INFO, + ROOM_SESSION_KEY, +} from '@huolala-tech/page-spy-base'; import type { SpyMP } from '@huolala-tech/page-spy-types'; -import Client, { combineName } from 'base/src/client'; import { getMPSDK, utilAPI } from '../utils'; -import { DataItem } from 'packages/page-spy-types/lib/client'; export class MPSocketWrapper extends SocketWrapper { private socketInstance: MPSocket | null = null; diff --git a/packages/page-spy-mp-base/src/index.ts b/packages/page-spy-mp-base/src/index.ts index c1c5ba07..844e5f3f 100644 --- a/packages/page-spy-mp-base/src/index.ts +++ b/packages/page-spy-mp-base/src/index.ts @@ -1,4 +1,13 @@ -import { getAuthSecret, isArray, isClass, psLog } from 'base/src'; +import { + Client, + atom, + getAuthSecret, + isArray, + isClass, + psLog, + SocketState, + ROOM_SESSION_KEY, +} from '@huolala-tech/page-spy-base'; import type { SpyMP, PageSpyPlugin, @@ -6,8 +15,6 @@ import type { PluginOrder, PageSpyPluginLifecycleArgs, } from '@huolala-tech/page-spy-types'; -import { SocketState } from 'base/src/socket-base'; -import { ROOM_SESSION_KEY } from 'base/src/constants'; import ConsolePlugin from './plugins/console'; import ErrorPlugin from './plugins/error'; @@ -22,8 +29,6 @@ import Request from './api'; // eslint-disable-next-line import/order import { Config } from './config'; import { getMPSDK, utilAPI } from './utils'; -import Client from 'base/src/client'; -import atom from 'base/src/atom'; type UpdateConfig = { title?: string; diff --git a/packages/page-spy-mp-base/src/plugins/console.ts b/packages/page-spy-mp-base/src/plugins/console.ts index 25d10c84..1806e16c 100644 --- a/packages/page-spy-mp-base/src/plugins/console.ts +++ b/packages/page-spy-mp-base/src/plugins/console.ts @@ -1,10 +1,9 @@ -import { makeMessage } from 'base/src/message'; -import socketStore from 'mp-base/src/helpers/socket'; import type { SpyConsole, PageSpyPlugin, } from '@huolala-tech/page-spy-types/index'; -import atom from 'base/src/atom'; +import { atom, makeMessage } from '@huolala-tech/page-spy-base'; +import socketStore from '../helpers/socket'; import { joinQuery } from '../utils'; export default class ConsolePlugin implements PageSpyPlugin { diff --git a/packages/page-spy-mp-base/src/plugins/error.ts b/packages/page-spy-mp-base/src/plugins/error.ts index 61b8c2ce..958a108f 100644 --- a/packages/page-spy-mp-base/src/plugins/error.ts +++ b/packages/page-spy-mp-base/src/plugins/error.ts @@ -1,13 +1,10 @@ -/* eslint-disable class-methods-use-this */ -import atom from 'base/src/atom'; -import { makeMessage } from 'base/src/message'; -import socketStore from 'mp-base/src/helpers/socket'; +import { atom, makeMessage, formatErrorObj } from '@huolala-tech/page-spy-base'; import type { SpyConsole, PageSpyPlugin, } from '@huolala-tech/page-spy-types/index'; +import socketStore from '../helpers/socket'; import { getMPSDK } from '../utils'; -import { formatErrorObj } from 'base/src'; // TODO this plugin should test on multiple platforms export default class ErrorPlugin implements PageSpyPlugin { diff --git a/packages/page-spy-mp-base/src/plugins/network/proxy/base.ts b/packages/page-spy-mp-base/src/plugins/network/proxy/base.ts index 3b360da1..c8a75526 100644 --- a/packages/page-spy-mp-base/src/plugins/network/proxy/base.ts +++ b/packages/page-spy-mp-base/src/plugins/network/proxy/base.ts @@ -1,5 +1,5 @@ -import socketStore from 'mp-base/src/helpers/socket'; -import NetworkProxyBase from 'base/src/network/base'; +import { NetworkProxyBase } from '@huolala-tech/page-spy-base'; +import socketStore from '../../../helpers/socket'; export default class MPNetworkProxyBase extends NetworkProxyBase { constructor() { diff --git a/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts b/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts index 883e876a..687f9b6b 100644 --- a/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts +++ b/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts @@ -1,6 +1,12 @@ -import { getRandomId, isPlainObject, psLog, toStringTag } from 'base/src/index'; -import { ReqReadyState, toLowerKeys } from 'base/src/network/common'; -import { getMPSDK } from 'mp-base/src/utils'; +import { + ReqReadyState, + toLowerKeys, + getRandomId, + isPlainObject, + psLog, + toStringTag, +} from '@huolala-tech/page-spy-base'; +import { getMPSDK } from '../../../utils'; import MPNetworkProxyBase from './base'; export default class MPWeixinRequestProxy extends MPNetworkProxyBase { diff --git a/packages/page-spy-mp-base/src/plugins/storage.ts b/packages/page-spy-mp-base/src/plugins/storage.ts index f3611e06..af06146f 100644 --- a/packages/page-spy-mp-base/src/plugins/storage.ts +++ b/packages/page-spy-mp-base/src/plugins/storage.ts @@ -1,9 +1,7 @@ -import { makeMessage } from 'base/src/message'; +import { makeMessage, Client, psLog } from '@huolala-tech/page-spy-base'; import type { SpyStorage, PageSpyPlugin } from '@huolala-tech/page-spy-types'; -import socketStore from 'mp-base/src/helpers/socket'; -import { psLog } from 'base/src'; +import socketStore from '../helpers/socket'; import { getMPSDK, utilAPI } from '../utils'; -import Client from 'base/src/client'; export function mpDataStringify(data: any) { const typeOfValue = typeof data; diff --git a/packages/page-spy-mp-base/src/plugins/system.ts b/packages/page-spy-mp-base/src/plugins/system.ts index ea4bd2df..b61137ef 100644 --- a/packages/page-spy-mp-base/src/plugins/system.ts +++ b/packages/page-spy-mp-base/src/plugins/system.ts @@ -1,7 +1,6 @@ -import socketStore from 'mp-base/src/helpers/socket'; -import { makeMessage } from 'base/src/message'; import type { SpySystem, PageSpyPlugin } from '@huolala-tech/page-spy-types'; -import Client, { combineName } from 'base/src/client'; +import { Client, combineName, makeMessage } from '@huolala-tech/page-spy-base'; +import socketStore from '../helpers/socket'; export default class SystemPlugin implements PageSpyPlugin { public name = 'SystemPlugin'; diff --git a/packages/page-spy-mp-base/tests/init.test.ts b/packages/page-spy-mp-base/tests/init.test.ts index 2bd73fd7..a5d2ecb7 100644 --- a/packages/page-spy-mp-base/tests/init.test.ts +++ b/packages/page-spy-mp-base/tests/init.test.ts @@ -1,14 +1,14 @@ -import { isBrowser } from 'base/src'; -import SDK from 'mp-base/src/index'; +import { isBrowser } from 'page-spy-base/src'; +import SDK from 'page-spy-mp-base/src/index'; -import ConsolePlugin from 'mp-base/src/plugins/console'; -import StoragePlugin from 'mp-base/src/plugins/storage'; -import NetworkPlugin from 'mp-base/src/plugins/network'; -import ErrorPlugin from 'mp-base/src/plugins/error'; -import SystemPlugin from 'mp-base/src/plugins/system'; +import ConsolePlugin from 'page-spy-mp-base/src/plugins/console'; +import StoragePlugin from 'page-spy-mp-base/src/plugins/storage'; +import NetworkPlugin from 'page-spy-mp-base/src/plugins/network'; +import ErrorPlugin from 'page-spy-mp-base/src/plugins/error'; +import SystemPlugin from 'page-spy-mp-base/src/plugins/system'; import { SpyConsole } from '@huolala-tech/page-spy-types/index'; -import { ROOM_SESSION_KEY } from 'base/src/constants'; +import { ROOM_SESSION_KEY } from 'page-spy-base/src'; import { initStorageMock } from './mock/storage'; import { mp } from './setup'; diff --git a/packages/page-spy-mp-base/tests/mock/mp.ts b/packages/page-spy-mp-base/tests/mock/mp.ts index 8e522e8b..abfbd5fe 100644 --- a/packages/page-spy-mp-base/tests/mock/mp.ts +++ b/packages/page-spy-mp-base/tests/mock/mp.ts @@ -1,4 +1,4 @@ -import { SocketState } from 'base/src/socket-base'; +import { SocketState } from 'page-spy-base/src'; import { mockRequest } from './request'; import EventEmitter from 'events'; type CBType = (event?: any) => any; diff --git a/packages/page-spy-mp-base/tests/mock/storage.ts b/packages/page-spy-mp-base/tests/mock/storage.ts index 2c1c5f40..be082dab 100644 --- a/packages/page-spy-mp-base/tests/mock/storage.ts +++ b/packages/page-spy-mp-base/tests/mock/storage.ts @@ -1,4 +1,4 @@ -import { getMPSDK } from 'mp-base/src/utils'; +import { getMPSDK } from 'page-spy-mp-base/src/utils'; export function mockWXStorage(): MPStorageAPI { let store: Record = {}; diff --git a/packages/page-spy-mp-base/tests/plugins/console.test.ts b/packages/page-spy-mp-base/tests/plugins/console.test.ts index 32b22523..5a8fa8d6 100644 --- a/packages/page-spy-mp-base/tests/plugins/console.test.ts +++ b/packages/page-spy-mp-base/tests/plugins/console.test.ts @@ -1,4 +1,4 @@ -import ConsolePlugin from 'mp-base/src/plugins/console'; +import ConsolePlugin from 'page-spy-mp-base/src/plugins/console'; afterEach(() => { jest.restoreAllMocks(); diff --git a/packages/page-spy-mp-base/tests/plugins/error.test.ts b/packages/page-spy-mp-base/tests/plugins/error.test.ts index eb40822e..84a77f72 100644 --- a/packages/page-spy-mp-base/tests/plugins/error.test.ts +++ b/packages/page-spy-mp-base/tests/plugins/error.test.ts @@ -1,4 +1,4 @@ -import ErrorPlugin from 'mp-base/src/plugins/error'; +import ErrorPlugin from 'page-spy-mp-base/src/plugins/error'; import { mp } from '../setup'; const plugin = new ErrorPlugin(); diff --git a/packages/page-spy-mp-base/tests/plugins/network.test.ts b/packages/page-spy-mp-base/tests/plugins/network.test.ts index 20ac1bae..c4b7de47 100644 --- a/packages/page-spy-mp-base/tests/plugins/network.test.ts +++ b/packages/page-spy-mp-base/tests/plugins/network.test.ts @@ -1,4 +1,4 @@ -import NetworkPlugin from 'mp-base/src/plugins/network'; +import NetworkPlugin from 'page-spy-mp-base/src/plugins/network'; import { computeRequestMapInfo } from './util'; import { mp } from '../setup'; diff --git a/packages/page-spy-mp-base/tests/plugins/storage.test.ts b/packages/page-spy-mp-base/tests/plugins/storage.test.ts index 52964949..253c96fb 100644 --- a/packages/page-spy-mp-base/tests/plugins/storage.test.ts +++ b/packages/page-spy-mp-base/tests/plugins/storage.test.ts @@ -1,4 +1,6 @@ -import StoragePlugin, { mpDataStringify } from 'mp-base/src/plugins/storage'; +import StoragePlugin, { + mpDataStringify, +} from 'page-spy-mp-base/src/plugins/storage'; import { initStorageMock } from '../mock/storage'; import { mp } from '../setup'; diff --git a/packages/page-spy-mp-base/tests/plugins/util.ts b/packages/page-spy-mp-base/tests/plugins/util.ts index 7f937f77..0f1590a1 100644 --- a/packages/page-spy-mp-base/tests/plugins/util.ts +++ b/packages/page-spy-mp-base/tests/plugins/util.ts @@ -1,5 +1,5 @@ -import RequestProxy from 'mp-base/src/plugins/network/proxy/request'; -import RequestItem from 'base/src/request-item'; +import RequestProxy from 'page-spy-mp-base/src/plugins/network/proxy/request'; +import RequestItem from 'page-spy-base/src'; type RequestStore = Record; interface RequestsInfo { diff --git a/packages/page-spy-mp-base/tests/setup.ts b/packages/page-spy-mp-base/tests/setup.ts index 815cdf38..4b99fe14 100644 --- a/packages/page-spy-mp-base/tests/setup.ts +++ b/packages/page-spy-mp-base/tests/setup.ts @@ -1,6 +1,6 @@ import { initStorageMock, mockWXStorage } from './mock/storage'; import { MockMP } from './mock/mp'; -import { getMPSDK, setMPSDK } from 'mp-base/src/utils'; +import { getMPSDK, setMPSDK } from 'page-spy-mp-base/src/utils'; Object.defineProperty(globalThis, 'name', { value: '小程序单元测试', diff --git a/packages/page-spy-mp-base/tests/utils.test.ts b/packages/page-spy-mp-base/tests/utils.test.ts index c7b311f0..4b358924 100644 --- a/packages/page-spy-mp-base/tests/utils.test.ts +++ b/packages/page-spy-mp-base/tests/utils.test.ts @@ -1,4 +1,4 @@ -import { joinQuery, promisifyMPApi } from 'mp-base/src/utils'; +import { joinQuery, promisifyMPApi } from 'page-spy-mp-base/src/utils'; afterEach(() => { jest.clearAllMocks(); diff --git a/packages/page-spy-mp-base/tsconfig.cjs.json b/packages/page-spy-mp-base/tsconfig.cjs.json new file mode 100644 index 00000000..4a9ddaa8 --- /dev/null +++ b/packages/page-spy-mp-base/tsconfig.cjs.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "target": "ESNext", + "module": "CommonJS", + "moduleResolution": "Node", + "noEmit": false, + "outDir": "dist/cjs", + "declaration": false + }, + "include": ["src"] +} diff --git a/packages/page-spy-mp-base/tsconfig.esm.json b/packages/page-spy-mp-base/tsconfig.esm.json new file mode 100644 index 00000000..ed9f8e8f --- /dev/null +++ b/packages/page-spy-mp-base/tsconfig.esm.json @@ -0,0 +1,13 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "target": "ESNext", + "module": "ESNext", + "noEmit": false, + "outDir": "dist/esm", + "declaration": true, + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/tsconfig.json b/tsconfig.json index 338c02db..f970014d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,12 @@ { + "extends": "./tsconfig.paths.json", "compilerOptions": { "rootDir": ".", - "declaration": true, "noEmit": true, + "declaration": true, "strict": true, "resolveJsonModule": true, - "moduleResolution": "node", + "moduleResolution": "Bundler", "importHelpers": true, "target": "esnext", "module": "esnext", diff --git a/tsconfig.paths.json b/tsconfig.paths.json new file mode 100644 index 00000000..3fc7d58c --- /dev/null +++ b/tsconfig.paths.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "page-spy-base/*": ["./packages/page-spy-base/*"], + "page-spy-mp-base/*": ["./packages/page-spy-mp-base/*"], + "page-spy-browser/*": ["./packages/page-spy-browser/*"], + "page-spy-wechat/*": ["./packages/page-spy-wechat/*"], + "page-spy-react-native/*": ["./packages/page-spy-react-native/*"] + } + } +} diff --git a/yarn.lock b/yarn.lock index 891d315a..c5fb6fea 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11079,6 +11079,11 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== +typescript@^5.5.3: + version "5.5.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.3.tgz#e1b0a3c394190838a0b168e771b0ad56a0af0faa" + integrity sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ== + uglify-js@^3.1.4: version "3.17.4" resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz#61678cf5fa3f5b7eb789bb345df29afb8257c22c" From 6542abc4bc5b0f8118507e704f4e68b580c47393 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 15:59:44 +0800 Subject: [PATCH 03/13] refactor page-spy-(alipay|taro|uniapp|wechat) --- packages/page-spy-alipay/package.json | 12 ++++----- packages/page-spy-alipay/rollup.config.mjs | 18 +------------ packages/page-spy-alipay/src/index.ts | 6 ++--- packages/page-spy-alipay/tsconfig.json | 9 +++++++ packages/page-spy-base/package.json | 2 +- .../{src/types.d.ts => global.d.ts} | 0 packages/page-spy-mp-base/package.json | 22 ++++++++++------ packages/page-spy-mp-base/src/index.ts | 2 ++ packages/page-spy-mp-base/tsconfig.cjs.json | 13 ---------- .../{tsconfig.esm.json => tsconfig.json} | 7 +++--- packages/page-spy-mp-base/yarn.lock | 4 --- packages/page-spy-taro/package.json | 12 +++------ packages/page-spy-taro/rollup.config.mjs | 22 ++-------------- packages/page-spy-taro/src/index.ts | 20 ++++++++------- packages/page-spy-taro/tsconfig.json | 9 +++++++ packages/page-spy-uniapp/package.json | 12 ++++----- packages/page-spy-uniapp/rollup.config.mjs | 18 +------------ packages/page-spy-uniapp/src/index.ts | 25 ++++++++----------- packages/page-spy-uniapp/tsconfig.json | 9 +++++++ packages/page-spy-wechat/package.json | 12 ++++----- packages/page-spy-wechat/rollup.config.mjs | 17 +------------ packages/page-spy-wechat/src/index.ts | 9 ++++--- packages/page-spy-wechat/tsconfig.json | 9 +++++++ 23 files changed, 108 insertions(+), 161 deletions(-) create mode 100644 packages/page-spy-alipay/tsconfig.json rename packages/page-spy-mp-base/{src/types.d.ts => global.d.ts} (100%) delete mode 100644 packages/page-spy-mp-base/tsconfig.cjs.json rename packages/page-spy-mp-base/{tsconfig.esm.json => tsconfig.json} (60%) delete mode 100644 packages/page-spy-mp-base/yarn.lock create mode 100644 packages/page-spy-taro/tsconfig.json create mode 100644 packages/page-spy-uniapp/tsconfig.json create mode 100644 packages/page-spy-wechat/tsconfig.json diff --git a/packages/page-spy-alipay/package.json b/packages/page-spy-alipay/package.json index 71c40985..4844c34b 100644 --- a/packages/page-spy-alipay/package.json +++ b/packages/page-spy-alipay/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "dist/cjs/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -31,14 +31,16 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0" + "@huolala-tech/page-spy-types": "^1.9.0", + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-mp-base": "*" }, "devDependencies": { "@babel/core": "^7.14.0", - "@babel/plugin-transform-runtime": "^7.23.6", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", "@rollup/plugin-alias": "^4.0.3", + "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-image": "^2.1.1", @@ -46,13 +48,9 @@ "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", - "autoprefixer": "^10.3.4", "core-js": "3", - "less": "^4.1.1", - "postcss": "^8.4.21", "rollup": "^3.10.0", "rollup-plugin-delete": "^2.0.0", - "rollup-plugin-postcss": "^4.0.1", "rollup-plugin-typescript2": "^0.34.1" }, "prettier": { diff --git a/packages/page-spy-alipay/rollup.config.mjs b/packages/page-spy-alipay/rollup.config.mjs index 9fa48612..91070a73 100644 --- a/packages/page-spy-alipay/rollup.config.mjs +++ b/packages/page-spy-alipay/rollup.config.mjs @@ -1,20 +1,15 @@ import typescript from 'rollup-plugin-typescript2'; import del from 'rollup-plugin-delete'; import babel from '@rollup/plugin-babel'; -import postcss from 'rollup-plugin-postcss'; -import autoprefixer from 'autoprefixer'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ @@ -23,23 +18,12 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - // exclude: '**/tests/**/*.test.ts', + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - postcss({ - extensions: ['.css', '.less'], - extract: false, - plugins: [autoprefixer()], - }), - alias({ - entries: [ - { find: 'mp-base', replacement: resolve(root, '../mp-base') }, - { find: 'base', replacement: resolve(root, '../base') }, - ], - }), terser(), ]; diff --git a/packages/page-spy-alipay/src/index.ts b/packages/page-spy-alipay/src/index.ts index da8072cf..50301f7a 100644 --- a/packages/page-spy-alipay/src/index.ts +++ b/packages/page-spy-alipay/src/index.ts @@ -1,7 +1,5 @@ -import { setMPSDK, utilAPI } from 'mp-base/src/utils'; -import PageSpy from 'mp-base/src'; -import { SocketStoreBase } from 'base/src/socket-base'; -import Client from 'base/src/client'; +import PageSpy, { setMPSDK, utilAPI } from '@huolala-tech/page-spy-mp-base'; +import { Client, SocketStoreBase } from '@huolala-tech/page-spy-base'; import { SpyClient } from 'packages/page-spy-types'; // reassign the global.mp to uni diff --git a/packages/page-spy-alipay/tsconfig.json b/packages/page-spy-alipay/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-alipay/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-base/package.json b/packages/page-spy-base/package.json index c066d552..3b8f88f8 100644 --- a/packages/page-spy-base/package.json +++ b/packages/page-spy-base/package.json @@ -1,6 +1,6 @@ { "name": "@huolala-tech/page-spy-base", - "version": "1.9.0", + "version": "1.0.0", "description": "The common utils of PageSpy.", "dependencies": { "@huolala-tech/page-spy-types": "*" diff --git a/packages/page-spy-mp-base/src/types.d.ts b/packages/page-spy-mp-base/global.d.ts similarity index 100% rename from packages/page-spy-mp-base/src/types.d.ts rename to packages/page-spy-mp-base/global.d.ts diff --git a/packages/page-spy-mp-base/package.json b/packages/page-spy-mp-base/package.json index c88a6bb7..fc885982 100644 --- a/packages/page-spy-mp-base/package.json +++ b/packages/page-spy-mp-base/package.json @@ -1,15 +1,21 @@ { "name": "@huolala-tech/page-spy-mp-base", - "version": "1.9.0", + "version": "1.0.0", "description": "The base of PageSpy for miniprogram.", "license": "MIT", - "main": "dist/cjs/index.js", - "module": "dist/esm/index.js", - "types": "dist/types/index.d.ts", + "main": "./dist/index.js", + "types": "./dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + }, + "./global": { + "types": "./global.d.ts" + } + }, "scripts": { - "build": "yarn clean && yarn build:cjs && yarn build:esm ", - "build:esm": "tsc --project tsconfig.esm.json", - "build:cjs": "tsc --project tsconfig.cjs.json", + "build": "yarn clean && tsc", "clean": "rm -rf dist" }, "dependencies": { @@ -30,7 +36,7 @@ }, "files": [ "dist", - "types" + "types.d.ts" ], "keywords": [ "pagespy", diff --git a/packages/page-spy-mp-base/src/index.ts b/packages/page-spy-mp-base/src/index.ts index 844e5f3f..fa058500 100644 --- a/packages/page-spy-mp-base/src/index.ts +++ b/packages/page-spy-mp-base/src/index.ts @@ -293,3 +293,5 @@ INTERNAL_PLUGINS.forEach((p) => { }); export default PageSpy; +export * from './utils'; +export * from './helpers/socket'; diff --git a/packages/page-spy-mp-base/tsconfig.cjs.json b/packages/page-spy-mp-base/tsconfig.cjs.json deleted file mode 100644 index 4a9ddaa8..00000000 --- a/packages/page-spy-mp-base/tsconfig.cjs.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "target": "ESNext", - "module": "CommonJS", - "moduleResolution": "Node", - "noEmit": false, - "outDir": "dist/cjs", - "declaration": false - }, - "include": ["src"] -} diff --git a/packages/page-spy-mp-base/tsconfig.esm.json b/packages/page-spy-mp-base/tsconfig.json similarity index 60% rename from packages/page-spy-mp-base/tsconfig.esm.json rename to packages/page-spy-mp-base/tsconfig.json index ed9f8e8f..d94f6180 100644 --- a/packages/page-spy-mp-base/tsconfig.esm.json +++ b/packages/page-spy-mp-base/tsconfig.json @@ -5,9 +5,8 @@ "target": "ESNext", "module": "ESNext", "noEmit": false, - "outDir": "dist/esm", - "declaration": true, - "declarationDir": "dist/types" + "outDir": "dist", + "declaration": true }, - "include": ["src"] + "include": ["src", "global.d.ts"] } diff --git a/packages/page-spy-mp-base/yarn.lock b/packages/page-spy-mp-base/yarn.lock deleted file mode 100644 index fb57ccd1..00000000 --- a/packages/page-spy-mp-base/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - diff --git a/packages/page-spy-taro/package.json b/packages/page-spy-taro/package.json index 5384dc73..e0ebf380 100644 --- a/packages/page-spy-taro/package.json +++ b/packages/page-spy-taro/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "dist/cjs/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -31,28 +31,24 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0" + "@huolala-tech/page-spy-types": "^1.9.0", + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-mp-base": "*" }, "devDependencies": { "@babel/core": "^7.14.0", - "@babel/plugin-transform-runtime": "^7.23.6", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", - "@rollup/plugin-image": "^2.1.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", - "autoprefixer": "^10.3.4", "core-js": "3", - "less": "^4.1.1", - "postcss": "^8.4.21", "rollup": "^3.10.0", "rollup-plugin-delete": "^2.0.0", - "rollup-plugin-postcss": "^4.0.1", "rollup-plugin-typescript2": "^0.34.1" }, "prettier": { diff --git a/packages/page-spy-taro/rollup.config.mjs b/packages/page-spy-taro/rollup.config.mjs index 086981de..3157d1f0 100644 --- a/packages/page-spy-taro/rollup.config.mjs +++ b/packages/page-spy-taro/rollup.config.mjs @@ -1,45 +1,27 @@ import typescript from 'rollup-plugin-typescript2'; import del from 'rollup-plugin-delete'; import babel from '@rollup/plugin-babel'; -import postcss from 'rollup-plugin-postcss'; -import autoprefixer from 'autoprefixer'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; -import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ - image(), json(), nodeResolve(), commonjs(), typescript({ - // exclude: 'tests/**/*', + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - postcss({ - extensions: ['.css', '.less'], - extract: false, - plugins: [autoprefixer()], - }), - alias({ - entries: [ - { find: 'mp-base', replacement: resolve(root, '../mp-base') }, - { find: 'base', replacement: resolve(root, '../base') }, - ], - }), terser(), ]; @@ -80,5 +62,5 @@ export default { }), del({ targets: ['dist/*'] }), ], - external: ['@tarojs/taro'] + external: ['@tarojs/taro'], }; diff --git a/packages/page-spy-taro/src/index.ts b/packages/page-spy-taro/src/index.ts index c7344683..30b8bddc 100644 --- a/packages/page-spy-taro/src/index.ts +++ b/packages/page-spy-taro/src/index.ts @@ -1,12 +1,14 @@ -import { setCustomGlobal, setMPSDK } from 'mp-base/src/utils'; -import PageSpy from 'mp-base/src'; -import { SpyClient, SpyMP } from 'packages/page-spy-types'; -import { SocketStoreBase, SocketWrapper } from 'base/src/socket-base'; -import { psLog } from 'base/src'; -import { MPSocketWrapper } from 'mp-base/src/helpers/socket'; -import Client from 'base/src/client'; +/// -declare var tt: MPSDK; +import PageSpy, { + MPSocketWrapper, + setCustomGlobal, + setMPSDK, +} from '@huolala-tech/page-spy-mp-base'; +import { SpyClient, SpyMP } from '@huolala-tech/page-spy-types'; +import { Client, psLog } from '@huolala-tech/page-spy-base'; + +declare const tt: any; class PageSpyTaro extends PageSpy { constructor( @@ -14,7 +16,7 @@ class PageSpyTaro extends PageSpy { taro: any; }, ) { - const taro = init.taro; + const { taro } = init; if ( !taro || typeof taro !== 'object' || diff --git a/packages/page-spy-taro/tsconfig.json b/packages/page-spy-taro/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-taro/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-uniapp/package.json b/packages/page-spy-uniapp/package.json index 4f85a9f7..5b67d766 100644 --- a/packages/page-spy-uniapp/package.json +++ b/packages/page-spy-uniapp/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "dist/cjs/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -31,14 +31,16 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0" + "@huolala-tech/page-spy-types": "^1.9.0", + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-mp-base": "*" }, "devDependencies": { "@babel/core": "^7.14.0", - "@babel/plugin-transform-runtime": "^7.23.6", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", "@rollup/plugin-alias": "^4.0.3", + "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-image": "^2.1.1", @@ -46,13 +48,9 @@ "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", - "autoprefixer": "^10.3.4", "core-js": "3", - "less": "^4.1.1", - "postcss": "^8.4.21", "rollup": "^3.10.0", "rollup-plugin-delete": "^2.0.0", - "rollup-plugin-postcss": "^4.0.1", "rollup-plugin-typescript2": "^0.34.1" }, "prettier": { diff --git a/packages/page-spy-uniapp/rollup.config.mjs b/packages/page-spy-uniapp/rollup.config.mjs index 656c76c4..91070a73 100644 --- a/packages/page-spy-uniapp/rollup.config.mjs +++ b/packages/page-spy-uniapp/rollup.config.mjs @@ -1,20 +1,15 @@ import typescript from 'rollup-plugin-typescript2'; import del from 'rollup-plugin-delete'; import babel from '@rollup/plugin-babel'; -import postcss from 'rollup-plugin-postcss'; -import autoprefixer from 'autoprefixer'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ @@ -23,23 +18,12 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - // exclude: 'tests/**/*', + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - postcss({ - extensions: ['.css', '.less'], - extract: false, - plugins: [autoprefixer()], - }), - alias({ - entries: [ - { find: 'mp-base', replacement: resolve(root, '../mp-base') }, - { find: 'base', replacement: resolve(root, '../base') }, - ], - }), terser(), ]; diff --git a/packages/page-spy-uniapp/src/index.ts b/packages/page-spy-uniapp/src/index.ts index 90967c93..680cb9d4 100644 --- a/packages/page-spy-uniapp/src/index.ts +++ b/packages/page-spy-uniapp/src/index.ts @@ -1,22 +1,17 @@ -import { setMPSDK } from 'mp-base/src/utils'; -import PageSpy from 'mp-base/src'; -import Client from 'base/src/client'; -import { SocketStoreBase } from 'base/src/socket-base'; -import { psLog } from 'base/src'; -import { MPSocketWrapper } from 'mp-base/src/helpers/socket'; -import { SpyClient } from 'packages/page-spy-types'; +/// -declare const uni: any; +import PageSpy, { + setMPSDK, + MPSocketWrapper, +} from '@huolala-tech/page-spy-mp-base'; +import { psLog, Client, SocketStoreBase } from '@huolala-tech/page-spy-base'; +import { SpyClient } from '@huolala-tech/page-spy-types'; + +declare const uni: MPSDK; setMPSDK(uni); -const info = uni.getSystemInfoSync() as { - osName: string; - osVersion: string; - appVersion: string; - hostName: string; - uniPlatform: string; -}; +const info = uni.getSystemInfoSync(); let browserType: SpyClient.ClientInfo['browserType'] = 'unknown'; diff --git a/packages/page-spy-uniapp/tsconfig.json b/packages/page-spy-uniapp/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-uniapp/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-wechat/package.json b/packages/page-spy-wechat/package.json index b417704c..f5f57adc 100644 --- a/packages/page-spy-wechat/package.json +++ b/packages/page-spy-wechat/package.json @@ -5,7 +5,7 @@ "license": "MIT", "main": "dist/cjs/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -31,14 +31,16 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0" + "@huolala-tech/page-spy-types": "^1.9.0", + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-mp-base": "*" }, "devDependencies": { "@babel/core": "^7.14.0", - "@babel/plugin-transform-runtime": "^7.23.6", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", "@rollup/plugin-alias": "^4.0.3", + "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-image": "^2.1.1", @@ -46,13 +48,9 @@ "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", - "autoprefixer": "^10.3.4", "core-js": "3", - "less": "^4.1.1", - "postcss": "^8.4.21", "rollup": "^3.10.0", "rollup-plugin-delete": "^2.0.0", - "rollup-plugin-postcss": "^4.0.1", "rollup-plugin-typescript2": "^0.34.1" }, "prettier": { diff --git a/packages/page-spy-wechat/rollup.config.mjs b/packages/page-spy-wechat/rollup.config.mjs index 9fa48612..a1313a1c 100644 --- a/packages/page-spy-wechat/rollup.config.mjs +++ b/packages/page-spy-wechat/rollup.config.mjs @@ -1,18 +1,14 @@ import typescript from 'rollup-plugin-typescript2'; import del from 'rollup-plugin-delete'; import babel from '@rollup/plugin-babel'; -import postcss from 'rollup-plugin-postcss'; -import autoprefixer from 'autoprefixer'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve } from 'path'; const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); @@ -23,23 +19,12 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - // exclude: '**/tests/**/*.test.ts', + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - postcss({ - extensions: ['.css', '.less'], - extract: false, - plugins: [autoprefixer()], - }), - alias({ - entries: [ - { find: 'mp-base', replacement: resolve(root, '../mp-base') }, - { find: 'base', replacement: resolve(root, '../base') }, - ], - }), terser(), ]; diff --git a/packages/page-spy-wechat/src/index.ts b/packages/page-spy-wechat/src/index.ts index c4c74d6c..cb261023 100644 --- a/packages/page-spy-wechat/src/index.ts +++ b/packages/page-spy-wechat/src/index.ts @@ -1,7 +1,8 @@ -import { setMPSDK } from 'mp-base/src/utils'; -import PageSpy from 'mp-base/src'; -import Client from 'base/src/client'; -import { SpyClient } from 'packages/page-spy-types'; +/// + +import PageSpy, { setMPSDK } from '@huolala-tech/page-spy-mp-base'; +import { Client } from '@huolala-tech/page-spy-base'; +import { SpyClient } from '@huolala-tech/page-spy-types'; declare const wx: MPSDK; diff --git a/packages/page-spy-wechat/tsconfig.json b/packages/page-spy-wechat/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-wechat/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} From 569db8ee6f4fe42c5321d25677954ea93c3bbce6 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 17:37:23 +0800 Subject: [PATCH 04/13] refactor page-spy-(data-harbor|rrweb|react-native|rn-async-storage) --- .../page-spy-plugin-data-harbor/package.json | 3 +- .../rollup.config.mjs | 30 ++++++++++--------- .../src/harbor/idb-container.ts | 2 +- .../src/harbor/index.ts | 4 +-- .../page-spy-plugin-data-harbor/src/index.ts | 26 +++++++++------- .../src/utils/download.ts | 2 +- .../src/utils/index.ts | 3 +- .../src/utils/upload.ts | 2 +- .../page-spy-plugin-data-harbor/tsconfig.json | 9 ++++++ .../types/index.d.ts | 27 ----------------- .../package.json | 6 ++-- .../rollup.config.mjs | 13 +++----- .../src/index.ts | 6 ++-- .../tsconfig.json | 9 ++++++ .../types/index.d.ts | 3 -- packages/page-spy-plugin-rrweb/package.json | 7 ++--- .../page-spy-plugin-rrweb/rollup.config.mjs | 10 ++----- packages/page-spy-plugin-rrweb/src/index.ts | 12 ++++---- packages/page-spy-plugin-rrweb/tsconfig.json | 9 ++++++ packages/page-spy-react-native/package.json | 10 +++---- .../page-spy-react-native/rollup.config.mjs | 21 ++++--------- .../page-spy-react-native/src/api/index.ts | 7 ++--- packages/page-spy-react-native/src/config.ts | 18 +++++++++-- packages/page-spy-react-native/src/env.d.ts | 1 + .../src/helpers/socket.ts | 18 ++++++----- packages/page-spy-react-native/src/index.ts | 14 +++++---- .../src/plugins/console.ts | 9 ++---- .../src/plugins/error.ts | 11 +++---- .../src/plugins/network/proxy/base.ts | 5 ++-- .../src/plugins/network/proxy/fetch-proxy.ts | 4 +-- .../src/plugins/network/proxy/xhr-proxy.ts | 10 +++---- .../src/plugins/system.ts | 4 +-- packages/page-spy-react-native/tsconfig.json | 9 ++++++ .../page-spy-react-native/types/index.d.ts | 28 ----------------- packages/page-spy-react-native/yarn.lock | 22 -------------- packages/page-spy-types/lib/index.d.ts | 1 + tsconfig.json | 1 - yarn.lock | 2 +- 38 files changed, 165 insertions(+), 213 deletions(-) create mode 100644 packages/page-spy-plugin-data-harbor/tsconfig.json delete mode 100644 packages/page-spy-plugin-data-harbor/types/index.d.ts create mode 100644 packages/page-spy-plugin-rn-async-storage/tsconfig.json delete mode 100644 packages/page-spy-plugin-rn-async-storage/types/index.d.ts create mode 100644 packages/page-spy-plugin-rrweb/tsconfig.json create mode 100644 packages/page-spy-react-native/src/env.d.ts create mode 100644 packages/page-spy-react-native/tsconfig.json delete mode 100644 packages/page-spy-react-native/types/index.d.ts delete mode 100644 packages/page-spy-react-native/yarn.lock diff --git a/packages/page-spy-plugin-data-harbor/package.json b/packages/page-spy-plugin-data-harbor/package.json index 798a441d..f849aff4 100644 --- a/packages/page-spy-plugin-data-harbor/package.json +++ b/packages/page-spy-plugin-data-harbor/package.json @@ -6,7 +6,7 @@ "license": "MIT", "main": "dist/iife/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -27,6 +27,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", + "@huolala-tech/page-spy-base": "*", "fflate": "^0.8.1" }, "devDependencies": { diff --git a/packages/page-spy-plugin-data-harbor/rollup.config.mjs b/packages/page-spy-plugin-data-harbor/rollup.config.mjs index 0bcf79d5..094345bc 100644 --- a/packages/page-spy-plugin-data-harbor/rollup.config.mjs +++ b/packages/page-spy-plugin-data-harbor/rollup.config.mjs @@ -5,12 +5,10 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve, dirname } from 'path'; +import { dirname } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const getBabel = (mode) => { return babel({ @@ -42,15 +40,12 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - tsconfigOverride: { include: ['packages/page-spy-plugin-data-harbor/src'] }, + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - alias({ - entries: [{ find: 'base', replacement: resolve(root, '../base') }], - }), terser(), ]; @@ -60,12 +55,19 @@ const plugins = [ export default [ { input: 'src/index.ts', - output: { - file: pkg.main, - format: 'iife', - name: 'DataHarborPlugin', - sourcemap: true - }, + output: [ + { + file: pkg.main, + format: 'iife', + name: 'DataHarborPlugin', + sourcemap: true, + }, + { + file: pkg.module, + format: 'esm', + sourcemap: true, + }, + ], plugins: [ ...plugins, getBabel('iife'), @@ -77,7 +79,7 @@ export default [ output: { file: pkg.module, format: 'esm', - sourcemap: true + sourcemap: true, }, plugins: [ ...plugins, diff --git a/packages/page-spy-plugin-data-harbor/src/harbor/idb-container.ts b/packages/page-spy-plugin-data-harbor/src/harbor/idb-container.ts index 21330424..be3de70c 100644 --- a/packages/page-spy-plugin-data-harbor/src/harbor/idb-container.ts +++ b/packages/page-spy-plugin-data-harbor/src/harbor/idb-container.ts @@ -1,4 +1,4 @@ -import { psLog } from 'base/src'; +import { psLog } from '@huolala-tech/page-spy-base'; import { Container, PRIVATE_DB_NAME, diff --git a/packages/page-spy-plugin-data-harbor/src/harbor/index.ts b/packages/page-spy-plugin-data-harbor/src/harbor/index.ts index d288107b..53274678 100644 --- a/packages/page-spy-plugin-data-harbor/src/harbor/index.ts +++ b/packages/page-spy-plugin-data-harbor/src/harbor/index.ts @@ -1,4 +1,4 @@ -import { isBrowser, isNumber } from 'base/src'; +import { isBrowser, isNumber } from '@huolala-tech/page-spy-base'; interface HarborConfig { maximum?: number; @@ -14,7 +14,7 @@ export class Harbor { // Specify the maximum bytes of single harbor's container. // Default 10MB. - private maximum = 10 * 1024 * 1024; + maximum = 10 * 1024 * 1024; constructor(config?: HarborConfig) { if (config && isNumber(config.maximum) && config.maximum >= 0) { diff --git a/packages/page-spy-plugin-data-harbor/src/index.ts b/packages/page-spy-plugin-data-harbor/src/index.ts index 7f576e86..e037724c 100644 --- a/packages/page-spy-plugin-data-harbor/src/index.ts +++ b/packages/page-spy-plugin-data-harbor/src/index.ts @@ -4,11 +4,15 @@ import type { OnMountedParams, PageSpyPlugin, PluginOrder, + InitConfigBase, } from '@huolala-tech/page-spy-types'; -import { isBrowser, isPlainObject, psLog } from 'base/src'; +import { + isBrowser, + isPlainObject, + psLog, + RequestItem, +} from '@huolala-tech/page-spy-base'; import { strFromU8, zlibSync, strToU8 } from 'fflate'; -import type RequestItem from 'base/src/request-item'; -import type { InitConfig } from 'page-spy-browser/types'; import { Harbor } from './harbor'; import { DownloadArgs, handleDownload, startDownload } from './utils/download'; import { UploadArgs, handleUpload, startUpload } from './utils/upload'; @@ -48,10 +52,10 @@ export default class DataHarborPlugin implements PageSpyPlugin { public name = 'DataHarborPlugin'; // "Harbor" is an abstraction for scheduling data actions. - private harbor: Harbor; + public harbor: Harbor; // Specify which types of data to collect. - private caredData: Record = { + public caredData: Record = { console: true, network: true, storage: true, @@ -59,15 +63,15 @@ export default class DataHarborPlugin implements PageSpyPlugin { 'rrweb-event': true, }; - private apiBase: string = ''; + public apiBase: string = ''; - private $pageSpyConfig: InitConfig | null = null; + public $pageSpyConfig: InitConfigBase | null = null; - private filename: DataHarborConfig['filename'] = () => { + public filename: DataHarborConfig['filename'] = () => { return new Date().toLocaleString(); }; - private onDownload: DataHarborConfig['onDownload']; + public onDownload: DataHarborConfig['onDownload']; public static hasInited = false; @@ -89,7 +93,7 @@ export default class DataHarborPlugin implements PageSpyPlugin { this.harbor = new Harbor({ maximum: config.maximum }); } - public async onInit({ socketStore, config }: OnInitParams) { + public async onInit({ socketStore, config }: OnInitParams) { if (DataHarborPlugin.hasInited) return; DataHarborPlugin.hasInited = true; @@ -182,7 +186,7 @@ export default class DataHarborPlugin implements PageSpyPlugin { } } - private isCaredPublicData(message: SpyMessage.MessageItem) { + public isCaredPublicData(message: SpyMessage.MessageItem) { if (!message) return false; const { type } = message; switch (type) { diff --git a/packages/page-spy-plugin-data-harbor/src/utils/download.ts b/packages/page-spy-plugin-data-harbor/src/utils/download.ts index 452b6983..5d7e0b86 100644 --- a/packages/page-spy-plugin-data-harbor/src/utils/download.ts +++ b/packages/page-spy-plugin-data-harbor/src/utils/download.ts @@ -1,4 +1,4 @@ -import { isCN, psLog } from 'base/src'; +import { isCN, psLog } from '@huolala-tech/page-spy-base'; import type { Harbor } from '../harbor'; import type { CacheMessageItem } from '../index'; import { DOWNLOAD_TIPS } from './TIP_CONTENT'; diff --git a/packages/page-spy-plugin-data-harbor/src/utils/index.ts b/packages/page-spy-plugin-data-harbor/src/utils/index.ts index 162ddaec..aff35065 100644 --- a/packages/page-spy-plugin-data-harbor/src/utils/index.ts +++ b/packages/page-spy-plugin-data-harbor/src/utils/index.ts @@ -1,5 +1,4 @@ -import { isBrowser } from 'base/src'; -import { ROOM_SESSION_KEY } from 'base/src/constants'; +import { isBrowser, ROOM_SESSION_KEY } from '@huolala-tech/page-spy-base'; export const getDeviceId = () => { if (isBrowser()) { diff --git a/packages/page-spy-plugin-data-harbor/src/utils/upload.ts b/packages/page-spy-plugin-data-harbor/src/utils/upload.ts index ac62585f..57944b9c 100644 --- a/packages/page-spy-plugin-data-harbor/src/utils/upload.ts +++ b/packages/page-spy-plugin-data-harbor/src/utils/upload.ts @@ -1,4 +1,4 @@ -import { isCN, psLog, removeEndSlash } from 'base/src'; +import { isCN, psLog, removeEndSlash } from '@huolala-tech/page-spy-base'; import type { Harbor } from '../harbor'; import { UPLOAD_TIPS } from './TIP_CONTENT'; import { formatFilename } from '.'; diff --git a/packages/page-spy-plugin-data-harbor/tsconfig.json b/packages/page-spy-plugin-data-harbor/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-plugin-data-harbor/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-plugin-data-harbor/types/index.d.ts b/packages/page-spy-plugin-data-harbor/types/index.d.ts deleted file mode 100644 index 66ad1591..00000000 --- a/packages/page-spy-plugin-data-harbor/types/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { PageSpyPlugin } from '@huolala-tech/page-spy-types'; - -type DataType = 'console' | 'network' | 'rrweb-event'; - -interface DataHarborConfig { - // Specify the maximum bytes of single harbor's container. - // Default 10 * 1024 * 1024. - maximum?: number; - - // Specify which types of data to collect. - caredData?: Record; - - // Customize the log's filename - filename?: () => string; - - // Customize the "Download Log Data" - // (Version required: @huolala-tech/page-spy-plugin-data-harbor^1.0.6) - onDownload?: (data: CacheMessageItem[]) => void; -} - -declare class DataHarborPlugin implements PageSpyPlugin { - name: string; - constructor(config?: DataHarborConfig); - onInit({ socketStore }: OnInitParams): Promise; -} - -export default DataHarborPlugin; diff --git a/packages/page-spy-plugin-rn-async-storage/package.json b/packages/page-spy-plugin-rn-async-storage/package.json index 454af840..9d043925 100644 --- a/packages/page-spy-plugin-rn-async-storage/package.json +++ b/packages/page-spy-plugin-rn-async-storage/package.json @@ -6,7 +6,7 @@ "license": "MIT", "main": "dist/cjs/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ "dist", "types" @@ -26,12 +26,14 @@ "build:watch": "rollup -c -w" }, "dependencies": { - "@babel/runtime": "^7.13.0" + "@babel/runtime": "^7.13.0", + "@huolala-tech/page-spy-base": "*" }, "devDependencies": { "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", + "@huolala-tech/page-spy-react-native": "*", "@huolala-tech/page-spy-types": "^1.9.0", "@react-native-async-storage/async-storage": "^1.23.1", "@rollup/plugin-alias": "^4.0.3", diff --git a/packages/page-spy-plugin-rn-async-storage/rollup.config.mjs b/packages/page-spy-plugin-rn-async-storage/rollup.config.mjs index 123c1f05..9c8b5559 100644 --- a/packages/page-spy-plugin-rn-async-storage/rollup.config.mjs +++ b/packages/page-spy-plugin-rn-async-storage/rollup.config.mjs @@ -5,12 +5,10 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve, dirname } from 'path'; +import { dirname } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); /** @@ -34,15 +32,12 @@ export default { nodeResolve(), commonjs(), typescript({ - tsconfigOverride: { include: ['packages/page-spy-plugin-rn-async-storage/src'] }, + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - alias({ - entries: [{ find: 'base', replacement: resolve(root, '../base') }], - }), terser(), babel({ /** @@ -64,5 +59,5 @@ export default { }), del({ targets: [dirname(pkg.module)] }), ], - external: ['@react-native-async-storage/async-storage'] -} + external: ['@react-native-async-storage/async-storage'], +}; diff --git a/packages/page-spy-plugin-rn-async-storage/src/index.ts b/packages/page-spy-plugin-rn-async-storage/src/index.ts index b9f06334..f3617572 100644 --- a/packages/page-spy-plugin-rn-async-storage/src/index.ts +++ b/packages/page-spy-plugin-rn-async-storage/src/index.ts @@ -1,4 +1,4 @@ -import { makeMessage } from 'base/src/message'; +import { makeMessage } from '@huolala-tech/page-spy-base'; import type { SpyStorage, PageSpyPlugin, @@ -6,11 +6,11 @@ import type { SpyBase, } from '@huolala-tech/page-spy-types'; import AsyncStorage from '@react-native-async-storage/async-storage'; -import type { InitConfig } from 'page-spy-react-native/types'; +import type { InitConfig } from '@huolala-tech/page-spy-react-native'; import type { Callback, MultiCallback, -} from '@react-native-async-storage/async-storage/src/types'; +} from '@react-native-async-storage/async-storage/lib/typescript/types'; export default class RNAsyncStoragePlugin implements PageSpyPlugin { public name = 'RNAsyncStoragePlugin'; diff --git a/packages/page-spy-plugin-rn-async-storage/tsconfig.json b/packages/page-spy-plugin-rn-async-storage/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-plugin-rn-async-storage/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-plugin-rn-async-storage/types/index.d.ts b/packages/page-spy-plugin-rn-async-storage/types/index.d.ts deleted file mode 100644 index e40a32ea..00000000 --- a/packages/page-spy-plugin-rn-async-storage/types/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { PageSpyPlugin } from '@huolala-tech/page-spy-types'; - -declare class RNAsyncStoragePlugin implements PageSpyPlugin {} diff --git a/packages/page-spy-plugin-rrweb/package.json b/packages/page-spy-plugin-rrweb/package.json index 56be14fe..94e40121 100644 --- a/packages/page-spy-plugin-rrweb/package.json +++ b/packages/page-spy-plugin-rrweb/package.json @@ -6,10 +6,9 @@ "license": "MIT", "main": "dist/iife/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "publishConfig": { "access": "public" @@ -27,6 +26,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", + "@huolala-tech/page-spy-base": "*", "@huolala-tech/page-spy-types": "^1.9.0", "rrweb": "^2.0.0-alpha.4" }, @@ -34,7 +34,6 @@ "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.0.1", diff --git a/packages/page-spy-plugin-rrweb/rollup.config.mjs b/packages/page-spy-plugin-rrweb/rollup.config.mjs index 49d31b45..64985871 100644 --- a/packages/page-spy-plugin-rrweb/rollup.config.mjs +++ b/packages/page-spy-plugin-rrweb/rollup.config.mjs @@ -5,12 +5,10 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve, dirname } from 'path'; +import { dirname } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const getBabel = (mode) => { return babel({ @@ -42,16 +40,12 @@ const plugins = [ nodeResolve(), commonjs(), typescript({ - // exclude: 'tests/**/*', - tsconfigOverride: { include: ['packages/page-spy-plugin-rrweb/src'] }, + useTsconfigDeclarationDir: true, }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - alias({ - entries: [{ find: 'base', replacement: resolve(root, '../base') }], - }), terser(), ]; diff --git a/packages/page-spy-plugin-rrweb/src/index.ts b/packages/page-spy-plugin-rrweb/src/index.ts index 51256693..853e587d 100644 --- a/packages/page-spy-plugin-rrweb/src/index.ts +++ b/packages/page-spy-plugin-rrweb/src/index.ts @@ -1,10 +1,12 @@ -import { OnInitParams, PageSpyPlugin } from '@huolala-tech/page-spy-types'; +import { + InitConfigBase, + OnInitParams, + PageSpyPlugin, +} from '@huolala-tech/page-spy-types'; import { record } from 'rrweb'; import type { recordOptions } from 'rrweb/typings/types'; import type { eventWithTime, listenerHandler } from '@rrweb/types'; -import { makeMessage } from 'base/src/message'; -import { isBrowser, psLog } from 'base/src'; -import type { InitConfig } from 'page-spy-browser/types'; +import { makeMessage, isBrowser, psLog } from '@huolala-tech/page-spy-base'; interface Options extends recordOptions { // The data from 'rrweb-event' is typically larger (more interactions and complex @@ -25,7 +27,7 @@ export default class RRWebPlugin implements PageSpyPlugin { constructor(public options: Options = {}) {} - public onInit({ socketStore }: OnInitParams) { + public onInit({ socketStore }: OnInitParams) { if (!isBrowser()) { psLog.warn(`${this.name} can only used in browser environment`); return; diff --git a/packages/page-spy-plugin-rrweb/tsconfig.json b/packages/page-spy-plugin-rrweb/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-plugin-rrweb/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} diff --git a/packages/page-spy-react-native/package.json b/packages/page-spy-react-native/package.json index dc475f5c..b834eefa 100644 --- a/packages/page-spy-react-native/package.json +++ b/packages/page-spy-react-native/package.json @@ -5,10 +5,9 @@ "license": "MIT", "main": "dist/cjs/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "homepage": "https://www.pagespy.org/", "repository": { @@ -31,14 +30,15 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0" + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-types": "^1.9.0", + "promise": "^8.3.0" }, "devDependencies": { "@babel/core": "^7.14.0", "@babel/plugin-transform-runtime": "^7.23.6", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-node-resolve": "^15.0.1", diff --git a/packages/page-spy-react-native/rollup.config.mjs b/packages/page-spy-react-native/rollup.config.mjs index 76021d3a..bf8628f6 100644 --- a/packages/page-spy-react-native/rollup.config.mjs +++ b/packages/page-spy-react-native/rollup.config.mjs @@ -8,18 +8,15 @@ import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import fs from 'fs'; -import { resolve } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ nodeResolve(), commonjs(), typescript({ - // exclude: '**/tests/**/*.test.ts', + useTsconfigDeclarationDir: true, }), babel({ exclude: ['node_modules/**'], @@ -46,13 +43,6 @@ const plugins = [ extract: false, plugins: [autoprefixer()], }), - alias({ - entries: [ - { find: 'mp-base', replacement: resolve(root, '../mp-base') }, - { find: 'base', replacement: resolve(root, '../base') }, - { find: 'page-spy-react-native', replacement: resolve(root, '../page-spy-react-native') } - ], - }), terser(), ]; @@ -73,9 +63,10 @@ export default { sourcemap: true, }, ], - plugins: [ - ...plugins, - del({ targets: ['dist/*'] }), + plugins: [...plugins, del({ targets: ['dist/*'] })], + external: [ + 'react-native', + 'promise/setimmediate/rejection-tracking', + 'promise/setimmediate/es6-extensions', ], - external: ['react-native','promise/setimmediate/rejection-tracking','promise/setimmediate/es6-extensions'] }; diff --git a/packages/page-spy-react-native/src/api/index.ts b/packages/page-spy-react-native/src/api/index.ts index db3a6109..aa3e3be0 100644 --- a/packages/page-spy-react-native/src/api/index.ts +++ b/packages/page-spy-react-native/src/api/index.ts @@ -1,8 +1,6 @@ -import { Config } from '../config'; +import { Client, getRandomId, combineName } from '@huolala-tech/page-spy-base'; +import { Config, InitConfig } from '../config'; import { joinQuery } from '../utils'; -import { InitConfig } from 'page-spy-react-native/types'; -import { getRandomId } from 'base/src'; -import Client, { combineName } from 'base/src/client'; interface TResponse { code: string; @@ -55,6 +53,7 @@ export default class Request { }) .then((res) => res.json()) .then((res: TResponse) => { + // eslint-disable-next-line @typescript-eslint/no-shadow const { name, address } = res.data || {}; const roomUrl = this.getRoomUrl(address); return { diff --git a/packages/page-spy-react-native/src/config.ts b/packages/page-spy-react-native/src/config.ts index 1f4146d5..5e06d87e 100644 --- a/packages/page-spy-react-native/src/config.ts +++ b/packages/page-spy-react-native/src/config.ts @@ -1,8 +1,22 @@ -import { ConfigBase } from 'base/src/config'; -import { InitConfig } from 'page-spy-react-native/types'; +import { ConfigBase } from '@huolala-tech/page-spy-base'; +import { InitConfigBase } from '@huolala-tech/page-spy-types'; + +type InternalPlugins = + | 'ConsolePlugin' + | 'ErrorPlugin' + | 'NetworkPlugin' + | 'SystemPlugin'; +export interface InitConfig extends InitConfigBase { + /** + * All internal plugins are carried with PageSpy by default out of the box. + * You can disable some plugins as needed. + */ + disabledPlugins?: (InternalPlugins | string)[]; +} export class Config extends ConfigBase { protected privateKeys: (keyof InitConfig)[] = ['secret']; + // I need to use generic type on this method, so it can't be static /* eslint-disable-next-line class-methods-use-this */ protected defaultConfig() { diff --git a/packages/page-spy-react-native/src/env.d.ts b/packages/page-spy-react-native/src/env.d.ts new file mode 100644 index 00000000..b5a73efd --- /dev/null +++ b/packages/page-spy-react-native/src/env.d.ts @@ -0,0 +1 @@ +declare const PKG_VERSION: string; diff --git a/packages/page-spy-react-native/src/helpers/socket.ts b/packages/page-spy-react-native/src/helpers/socket.ts index 77c2d4e6..e7c9963a 100644 --- a/packages/page-spy-react-native/src/helpers/socket.ts +++ b/packages/page-spy-react-native/src/helpers/socket.ts @@ -1,16 +1,18 @@ -import { getRandomId, stringifyData } from 'base/src'; -import atom from 'base/src/atom'; -import Client, { combineName } from 'base/src/client'; -import { makeMessage } from 'base/src/message'; -import { UPDATE_ROOM_INFO } from 'base/src/message/server-type'; import { + getRandomId, + stringifyData, + combineName, + UPDATE_ROOM_INFO, + makeMessage, + Client, + atom, SocketStoreBase, SocketState, SocketWrapper, WebSocketEvents, -} from 'base/src/socket-base'; -import { SpyBase } from 'packages/page-spy-types'; -import { InitConfig } from 'page-spy-react-native/types'; +} from '@huolala-tech/page-spy-base'; +import { SpyBase } from '@huolala-tech/page-spy-types'; +import { InitConfig } from '../config'; export class RNWebSocketWrapper extends SocketWrapper { private socketInstance: WebSocket | null = null; diff --git a/packages/page-spy-react-native/src/index.ts b/packages/page-spy-react-native/src/index.ts index a65f23b6..8ffd32c7 100644 --- a/packages/page-spy-react-native/src/index.ts +++ b/packages/page-spy-react-native/src/index.ts @@ -1,4 +1,10 @@ -import { getAuthSecret, getRandomId, isArray, isClass, psLog } from 'base/src'; +import { + getAuthSecret, + isArray, + isClass, + psLog, + Client, +} from '@huolala-tech/page-spy-base'; import type { PageSpyPlugin, PageSpyPluginLifecycle, @@ -7,6 +13,7 @@ import type { SpyClient, } from '@huolala-tech/page-spy-types'; +import { Platform } from 'react-native'; import ConsolePlugin from './plugins/console'; import ErrorPlugin from './plugins/error'; import NetworkPlugin from './plugins/network'; @@ -16,10 +23,7 @@ import socketStore from './helpers/socket'; import Request from './api'; // eslint-disable-next-line import/order -import { Config } from './config'; -import { InitConfig } from '../types'; -import { Platform } from 'react-native'; -import Client from 'base/src/client'; +import { Config, InitConfig } from './config'; const osMap: Record = { android: 'android', diff --git a/packages/page-spy-react-native/src/plugins/console.ts b/packages/page-spy-react-native/src/plugins/console.ts index b11e17b8..70b5c078 100644 --- a/packages/page-spy-react-native/src/plugins/console.ts +++ b/packages/page-spy-react-native/src/plugins/console.ts @@ -1,10 +1,5 @@ -import { makeMessage } from 'base/src/message'; -import type { - SpyConsole, - PageSpyPlugin, - SpyBase, -} from '@huolala-tech/page-spy-types/index'; -import atom from 'base/src/atom'; +import type { SpyConsole, PageSpyPlugin } from '@huolala-tech/page-spy-types'; +import { atom, makeMessage } from '@huolala-tech/page-spy-base'; import socketStore from '../helpers/socket'; export default class ConsolePlugin implements PageSpyPlugin { diff --git a/packages/page-spy-react-native/src/plugins/error.ts b/packages/page-spy-react-native/src/plugins/error.ts index 59510fd6..4d47f512 100644 --- a/packages/page-spy-react-native/src/plugins/error.ts +++ b/packages/page-spy-react-native/src/plugins/error.ts @@ -1,17 +1,14 @@ -import atom from 'base/src/atom'; -import { makeMessage } from 'base/src/message'; +import { atom, makeMessage, formatErrorObj } from '@huolala-tech/page-spy-base'; import type { SpyConsole, PageSpyPlugin, } from '@huolala-tech/page-spy-types/index'; -import socketStore from '../helpers/socket'; import { ErrorHandlerCallback } from 'react-native'; // @ts-ignore import LocalPromise from 'promise/setimmediate/es6-extensions'; // @ts-ignore import RejectTracking from 'promise/setimmediate/rejection-tracking'; - -import { formatErrorObj } from 'base/src'; +import socketStore from '../helpers/socket'; // TODO this plugin should test on multiple platforms export default class ErrorPlugin implements PageSpyPlugin { @@ -57,8 +54,8 @@ export default class ErrorPlugin implements PageSpyPlugin { this.errorHandler(error); // origin error message console.warn('Possible Unhandled Promise Rejection (id: ' + id + '):'); - var errStr = (error && (error.stack || error)) + ''; - errStr.split('\n').forEach(function (line) { + const errStr = (error && (error.stack || error)) + ''; + errStr.split('\n').forEach((line) => { console.warn(' ' + line); }); }, diff --git a/packages/page-spy-react-native/src/plugins/network/proxy/base.ts b/packages/page-spy-react-native/src/plugins/network/proxy/base.ts index 8a688a87..b88c0596 100644 --- a/packages/page-spy-react-native/src/plugins/network/proxy/base.ts +++ b/packages/page-spy-react-native/src/plugins/network/proxy/base.ts @@ -1,5 +1,6 @@ -import NetworkProxyBase from 'base/src/network/base'; -import socketStore from 'page-spy-react-native/src/helpers/socket'; +import { NetworkProxyBase } from '@huolala-tech/page-spy-base'; +import socketStore from '../../../helpers/socket'; + export default class RNNetworkProxyBase extends NetworkProxyBase { constructor() { super(socketStore); diff --git a/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts b/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts index a7550a24..f5cd198f 100644 --- a/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts +++ b/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts @@ -6,14 +6,12 @@ import { isString, isURL, psLog, -} from 'base/src'; -import { addContentTypeHeader, getFormattedBody, MAX_SIZE, Reason, resolveUrlInfo, -} from 'base/src/network/common'; +} from '@huolala-tech/page-spy-base'; import RNNetworkProxyBase from './base'; import { IS_FETCH_HEADER } from './xhr-proxy'; diff --git a/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts b/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts index 0d04b985..1c601d89 100644 --- a/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts +++ b/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts @@ -7,15 +7,13 @@ import { getObjectKeys, psLog, blob2base64Async, -} from 'base/src'; -import RequestItem from 'base/src/request-item'; -import { + RequestItem, MAX_SIZE, Reason, addContentTypeHeader, getFormattedBody, resolveUrlInfo, -} from 'base/src/network/common'; +} from '@huolala-tech/page-spy-base'; import RNNetworkProxyBase from './base'; /** @@ -91,7 +89,7 @@ class XhrProxy extends RNNetworkProxyBase { "The request object is not found on XMLHttpRequest's setRequestHeader event", ); } /* c8 ignore stop */ - return setRequestHeader.apply(this, [key, value]); + setRequestHeader.apply(this, [key, value]); }; XMLHttpRequest.prototype.send = function (body) { @@ -149,7 +147,7 @@ class XhrProxy extends RNNetworkProxyBase { req.endTime = Date.now(); req.costTime = req.endTime - (req.startTime || req.endTime); - let responseType = XMLReq.responseType; + let { responseType } = XMLReq; if ( !responseType || (XMLReq.isFetch && responseType === 'blob') diff --git a/packages/page-spy-react-native/src/plugins/system.ts b/packages/page-spy-react-native/src/plugins/system.ts index 36b96b0e..a080bea5 100644 --- a/packages/page-spy-react-native/src/plugins/system.ts +++ b/packages/page-spy-react-native/src/plugins/system.ts @@ -1,8 +1,6 @@ -import { getRandomId } from 'base/src'; -import { makeMessage } from 'base/src/message'; +import { makeMessage, Client, combineName } from '@huolala-tech/page-spy-base'; import type { SpySystem, PageSpyPlugin } from '@huolala-tech/page-spy-types'; import socketStore from '../helpers/socket'; -import Client, { combineName } from 'base/src/client'; export default class SystemPlugin implements PageSpyPlugin { public name = 'SystemPlugin'; diff --git a/packages/page-spy-react-native/tsconfig.json b/packages/page-spy-react-native/tsconfig.json new file mode 100644 index 00000000..170fe32a --- /dev/null +++ b/packages/page-spy-react-native/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["./src"] +} diff --git a/packages/page-spy-react-native/types/index.d.ts b/packages/page-spy-react-native/types/index.d.ts deleted file mode 100644 index 82bc8e92..00000000 --- a/packages/page-spy-react-native/types/index.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { - PageSpyBase, - PageSpyPlugin, - InitConfigBase, -} from '@huolala-tech/page-spy-types'; - -type InternalPlugins = - | 'ConsolePlugin' - | 'ErrorPlugin' - | 'NetworkPlugin' - | 'SystemPlugin'; -export interface InitConfig extends InitConfigBase { - /** - * All internal plugins are carried with PageSpy by default out of the box. - * You can disable some plugins as needed. - */ - disabledPlugins?: (InternalPlugins | string)[]; -} - -interface PageSpyConstructor { - new (config: InitConfig): PageSpyBase; - instance: PageSpyBase | null; - registerPlugin(plugin: PageSpyPlugin): void; -} - -declare const PageSpy: PageSpyConstructor; - -export default PageSpy; diff --git a/packages/page-spy-react-native/yarn.lock b/packages/page-spy-react-native/yarn.lock deleted file mode 100644 index 7f860126..00000000 --- a/packages/page-spy-react-native/yarn.lock +++ /dev/null @@ -1,22 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -"@babel/runtime@^7.8.4": - version "7.24.4" - resolved "https://registry.npmmirror.com/@babel/runtime/-/runtime-7.24.4.tgz#de795accd698007a66ba44add6cc86542aff1edd" - integrity sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA== - dependencies: - regenerator-runtime "^0.14.0" - -"@huolala-tech/eval5@^0.0.1": - version "0.0.1" - resolved "https://registry.npmmirror.com/@huolala-tech/eval5/-/eval5-0.0.1.tgz#0ac20da88ce6345617ec01c0972f9fee6bbd6357" - integrity sha512-iYqXB5KM5OVowPBVUEgPyJXSEveXkuBMOafAMtXvSUuQG7r/iJ6qB4n6Ws/MzTtD6hZ4HJk5mnEWE9ymZraFoQ== - dependencies: - "@babel/runtime" "^7.8.4" - -regenerator-runtime@^0.14.0: - version "0.14.1" - resolved "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz#356ade10263f685dda125100cd862c1db895327f" - integrity sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw== diff --git a/packages/page-spy-types/lib/index.d.ts b/packages/page-spy-types/lib/index.d.ts index cfaea4c4..c848ca4f 100644 --- a/packages/page-spy-types/lib/index.d.ts +++ b/packages/page-spy-types/lib/index.d.ts @@ -51,6 +51,7 @@ export interface InitConfigBase { * @private */ secret?: string; + [key: string]: any; } export interface UpdateConfig { diff --git a/tsconfig.json b/tsconfig.json index f970014d..72c5bb5c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,4 @@ { - "extends": "./tsconfig.paths.json", "compilerOptions": { "rootDir": ".", "noEmit": true, diff --git a/yarn.lock b/yarn.lock index c5fb6fea..aebdb0a6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9437,7 +9437,7 @@ promise.series@^0.2.0: promise@^8.3.0: version "8.3.0" - resolved "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz#8cb333d1edeb61ef23869fbb8a4ea0279ab60e0a" + resolved "https://registry.yarnpkg.com/promise/-/promise-8.3.0.tgz#8cb333d1edeb61ef23869fbb8a4ea0279ab60e0a" integrity sha512-rZPNPKTOYVNEEKFaq1HqTgOwZD+4/YHS5ukLzQCypkj+OkYx7iv0mA91lJlpPPZ8vMau3IIGj5Qlwrx+8iiSmg== dependencies: asap "~2.0.6" From 6c2e3c26aa8a92d695b44b4fa0fd0ef67e9a8e4b Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 17:46:47 +0800 Subject: [PATCH 05/13] tests: add tsconfig.json --- packages/page-spy-alipay/types/index.d.ts | 15 --------------- packages/page-spy-base/tests/atom.test.ts | 2 +- packages/page-spy-base/tests/index.test.ts | 6 +++++- packages/page-spy-base/tests/network/base.test.ts | 2 +- .../page-spy-base/tests/network/common.test.ts | 2 +- packages/page-spy-base/tests/tsconfig.json | 3 +++ packages/page-spy-base/tests/ua.test.ts | 2 +- packages/page-spy-browser/tests/tsconfig.json | 2 +- packages/page-spy-mp-base/tests/plugins/util.ts | 2 +- packages/page-spy-mp-base/tests/setup.ts | 2 +- packages/page-spy-mp-base/tests/tsconfig.json | 4 ++++ 11 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 packages/page-spy-alipay/types/index.d.ts create mode 100644 packages/page-spy-base/tests/tsconfig.json create mode 100644 packages/page-spy-mp-base/tests/tsconfig.json diff --git a/packages/page-spy-alipay/types/index.d.ts b/packages/page-spy-alipay/types/index.d.ts deleted file mode 100644 index add2381f..00000000 --- a/packages/page-spy-alipay/types/index.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { - SpyMP, - PageSpyBase, - PageSpyPlugin, -} from '@huolala-tech/page-spy-types'; - -interface PageSpyConstructor { - new (config: SpyMP.MPInitConfig): PageSpyBase; - instance: PageSpyBase | null; - registerPlugin(plugin: PageSpyPlugin): void; -} - -declare const PageSpy: PageSpyConstructor; - -export default PageSpy; diff --git a/packages/page-spy-base/tests/atom.test.ts b/packages/page-spy-base/tests/atom.test.ts index 558f3450..e3204306 100644 --- a/packages/page-spy-base/tests/atom.test.ts +++ b/packages/page-spy-base/tests/atom.test.ts @@ -1,4 +1,4 @@ -import { atom } from '../src'; +import { atom } from 'page-spy-base/src'; // jest.mock('base/src/utils/atom.ts'); beforeEach(() => { diff --git a/packages/page-spy-base/tests/index.test.ts b/packages/page-spy-base/tests/index.test.ts index 7fdf4575..c91bb9f9 100644 --- a/packages/page-spy-base/tests/index.test.ts +++ b/packages/page-spy-base/tests/index.test.ts @@ -1,4 +1,8 @@ -import { makePrimitiveValue, getValueType, isArrayLike } from '../src'; +import { + makePrimitiveValue, + getValueType, + isArrayLike, +} from 'page-spy-base/src'; describe('makePrimitiveValue: convert data to showable string', () => { it('✅ Primitive is ok', () => { diff --git a/packages/page-spy-base/tests/network/base.test.ts b/packages/page-spy-base/tests/network/base.test.ts index 4e6bede8..92cb3544 100644 --- a/packages/page-spy-base/tests/network/base.test.ts +++ b/packages/page-spy-base/tests/network/base.test.ts @@ -4,7 +4,7 @@ import { SocketWrapper, NetworkProxyBase, RequestItem, -} from '../../src'; +} from 'page-spy-base/src'; class PlatformSocketWrapper extends SocketWrapper { init(url: string): void { diff --git a/packages/page-spy-base/tests/network/common.test.ts b/packages/page-spy-base/tests/network/common.test.ts index af0156b2..ed5bb85d 100644 --- a/packages/page-spy-base/tests/network/common.test.ts +++ b/packages/page-spy-base/tests/network/common.test.ts @@ -1,4 +1,4 @@ -import { getFormattedBody } from '../../src'; +import { getFormattedBody } from 'page-spy-base/src'; describe('Network common utils', () => { it('getFormattedBody()', () => { diff --git a/packages/page-spy-base/tests/tsconfig.json b/packages/page-spy-base/tests/tsconfig.json new file mode 100644 index 00000000..4ed731df --- /dev/null +++ b/packages/page-spy-base/tests/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": ["../../../tsconfig.paths.json", "../../../tsconfig.json"] +} diff --git a/packages/page-spy-base/tests/ua.test.ts b/packages/page-spy-base/tests/ua.test.ts index 77906270..9abc431c 100644 --- a/packages/page-spy-base/tests/ua.test.ts +++ b/packages/page-spy-base/tests/ua.test.ts @@ -1,4 +1,4 @@ -import { parseUserAgent } from '../src'; +import { parseUserAgent } from 'page-spy-base/src'; // The following `userAgent` info generated by ChatGpt. describe('Parse navigator.userAgent', () => { diff --git a/packages/page-spy-browser/tests/tsconfig.json b/packages/page-spy-browser/tests/tsconfig.json index b437ab5b..4ed731df 100644 --- a/packages/page-spy-browser/tests/tsconfig.json +++ b/packages/page-spy-browser/tests/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": ["../../../tsconfig.paths.json"] + "extends": ["../../../tsconfig.paths.json", "../../../tsconfig.json"] } diff --git a/packages/page-spy-mp-base/tests/plugins/util.ts b/packages/page-spy-mp-base/tests/plugins/util.ts index 0f1590a1..2486fe0e 100644 --- a/packages/page-spy-mp-base/tests/plugins/util.ts +++ b/packages/page-spy-mp-base/tests/plugins/util.ts @@ -1,5 +1,5 @@ import RequestProxy from 'page-spy-mp-base/src/plugins/network/proxy/request'; -import RequestItem from 'page-spy-base/src'; +import { RequestItem } from 'page-spy-base/src'; type RequestStore = Record; interface RequestsInfo { diff --git a/packages/page-spy-mp-base/tests/setup.ts b/packages/page-spy-mp-base/tests/setup.ts index 4b99fe14..625b98fa 100644 --- a/packages/page-spy-mp-base/tests/setup.ts +++ b/packages/page-spy-mp-base/tests/setup.ts @@ -1,4 +1,4 @@ -import { initStorageMock, mockWXStorage } from './mock/storage'; +import { initStorageMock } from './mock/storage'; import { MockMP } from './mock/mp'; import { getMPSDK, setMPSDK } from 'page-spy-mp-base/src/utils'; diff --git a/packages/page-spy-mp-base/tests/tsconfig.json b/packages/page-spy-mp-base/tests/tsconfig.json new file mode 100644 index 00000000..23a61ee0 --- /dev/null +++ b/packages/page-spy-mp-base/tests/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": ["../../../tsconfig.paths.json", "../../../tsconfig.json"], + "include": ["../global.d.ts", "."] +} From 987258e003b0bb0682bf705ba8b1a5ee36cdd436 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 17:48:41 +0800 Subject: [PATCH 06/13] types: remove manual types file --- packages/page-spy-browser/types/index.d.ts | 27 ------------------- .../page-spy-plugin-rrweb/types/index.d.ts | 17 ------------ packages/page-spy-taro/types/index.d.ts | 22 --------------- packages/page-spy-uniapp/types/index.d.ts | 15 ----------- packages/page-spy-wechat/types/index.d.ts | 15 ----------- 5 files changed, 96 deletions(-) delete mode 100644 packages/page-spy-browser/types/index.d.ts delete mode 100644 packages/page-spy-plugin-rrweb/types/index.d.ts delete mode 100644 packages/page-spy-taro/types/index.d.ts delete mode 100644 packages/page-spy-uniapp/types/index.d.ts delete mode 100644 packages/page-spy-wechat/types/index.d.ts diff --git a/packages/page-spy-browser/types/index.d.ts b/packages/page-spy-browser/types/index.d.ts deleted file mode 100644 index 7b51e25d..00000000 --- a/packages/page-spy-browser/types/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - InitConfigBase, - PageSpyBase, - PageSpyPlugin, - PageSpyPluginLifecycle, - PageSpyPluginLifecycleArgs, -} from '@huolala-tech/page-spy-types'; - -interface PageSpyBrowser extends PageSpyBase { - root: HTMLElement | null; - config: Required | null; - render(): void; - triggerPlugins( - lifecycle: T, - ...args: PageSpyPluginLifecycleArgs - ): void; -} - -interface PageSpyConstructor { - new (config?: InitConfig): PageSpyBrowser; - instance: PageSpyBrowser | null; - registerPlugin(plugin: PageSpyPlugin): void; -} - -declare const PageSpy: PageSpyConstructor; - -export default PageSpy; diff --git a/packages/page-spy-plugin-rrweb/types/index.d.ts b/packages/page-spy-plugin-rrweb/types/index.d.ts deleted file mode 100644 index 2d7bf1b5..00000000 --- a/packages/page-spy-plugin-rrweb/types/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { - InitConfigBase, - OnInitParams, - PageSpyPlugin, -} from '@huolala-tech/page-spy-types'; -import type { recordOptions } from 'rrweb/typings/types'; -import type { eventWithTime } from '@rrweb/types'; - -interface Options extends recordOptions {} - -declare class RRWebPlugin implements PageSpyPlugin { - name: string; - constructor(options?: Options); - onInit({ socketStore }: OnInitParams): Promise; -} - -export default RRWebPlugin; diff --git a/packages/page-spy-taro/types/index.d.ts b/packages/page-spy-taro/types/index.d.ts deleted file mode 100644 index aa02e4d7..00000000 --- a/packages/page-spy-taro/types/index.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { - PageSpyBase, - SpyMP, - PageSpyPlugin, -} from '@huolala-tech/page-spy-types'; - -declare interface MPTaroInitConfig extends SpyMP.MPInitConfig { - /** - * The Taro global object. - */ - taro: any; -} - -declare interface PageSpyConstructor { - new (config: MPTaroInitConfig): PageSpyBase; - instance: PageSpyBase | null; - registerPlugin(plugin: PageSpyPlugin): void; -} - -declare const PageSpy: PageSpyConstructor; - -export default PageSpy; diff --git a/packages/page-spy-uniapp/types/index.d.ts b/packages/page-spy-uniapp/types/index.d.ts deleted file mode 100644 index 08ca00d4..00000000 --- a/packages/page-spy-uniapp/types/index.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - PageSpyBase, - SpyMP, - PageSpyPlugin, -} from '@huolala-tech/page-spy-types'; - -interface PageSpyConstructor { - new (config: SpyMP.MPInitConfig): PageSpyBase; - instance: PageSpyBase | null; - registerPlugin(plugin: PageSpyPlugin): void; -} - -declare const PageSpy: PageSpyConstructor; - -export default PageSpy; diff --git a/packages/page-spy-wechat/types/index.d.ts b/packages/page-spy-wechat/types/index.d.ts deleted file mode 100644 index 03a26eff..00000000 --- a/packages/page-spy-wechat/types/index.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { - PageSpyBase, - PageSpyPlugin, - SpyMP, -} from '@huolala-tech/page-spy-types'; - -interface PageSpyConstructor { - new (config: SpyMP.MPInitConfig): PageSpyBase; - instance: PageSpyBase | null; - registerPlugin(plugin: PageSpyPlugin): void; -} - -declare const PageSpy: PageSpyConstructor; - -export default PageSpy; From af16de3720b93f21ed0c66f874fb4c08d79049e5 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 21:08:02 +0800 Subject: [PATCH 07/13] tests: update config --- jest.config.ts | 37 ++++++++++++++----- packages/page-spy-alipay/src/index.ts | 2 +- packages/page-spy-base/tests/index.test.ts | 4 +- .../tests/plugins/network/util.ts | 2 +- .../src/index.ts | 4 +- tsconfig.json | 2 +- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/jest.config.ts b/jest.config.ts index 2d9cf3dc..d7078064 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -1,9 +1,25 @@ -import type { Config } from 'jest'; -import { pathsToModuleNameMapper } from 'ts-jest'; -import tsConfig from './tsconfig.paths.json'; +import { JestConfigWithTsJest, pathsToModuleNameMapper } from 'ts-jest'; +import tsconfigBase from './tsconfig.json'; +import tsconfigPath from './tsconfig.paths.json'; + +// tell ts-jest about the path mapping info +const tsCompilerOptions = { + ...tsconfigBase.compilerOptions, + ...tsconfigPath.compilerOptions, +}; + +// use ts-jest to transpile .js, .jsx, .ts, .tsx +const transform: any = { + '^.+\\.[tj]sx?$': [ + 'ts-jest', + { + tsconfig: tsCompilerOptions, + }, + ], +}; const moduleNameMapper = { - ...pathsToModuleNameMapper(tsConfig.compilerOptions.paths, { + ...pathsToModuleNameMapper(tsconfigPath.compilerOptions.paths, { prefix: '/', }), '\\.(css|less|svg|png|jpg)$': @@ -16,9 +32,10 @@ const moduleNameMapper = { * - moduleNameMapper * - testMatch * - preset + * - transform */ -const config: Config = { +const config: JestConfigWithTsJest = { collectCoverageFrom: [ 'packages/**/*.ts', '!packages/**/*.d.ts', @@ -34,36 +51,36 @@ const config: Config = { name: 'Base', color: 'cyanBright', }, - preset: 'ts-jest', testEnvironment: 'jsdom', testMatch: ['**/packages/page-spy-base/tests/**/*.test.ts'], moduleNameMapper, + transform, }, { displayName: { name: 'Browser', color: 'yellow', }, - preset: 'ts-jest', testEnvironment: 'jsdom', testMatch: ['**/packages/page-spy-browser/tests/**/*.test.ts'], - moduleNameMapper, setupFilesAfterEnv: [ '/packages/page-spy-browser/tests/setup.ts', 'jest-canvas-mock', ], + moduleNameMapper, + transform, }, { displayName: { name: 'MPBase', color: 'green', }, - preset: 'ts-jest', testMatch: ['**/packages/page-spy-mp-base/tests/**/*.test.ts'], - moduleNameMapper, setupFilesAfterEnv: [ '/packages/page-spy-mp-base/tests/setup.ts', ], + moduleNameMapper, + transform, }, ], }; diff --git a/packages/page-spy-alipay/src/index.ts b/packages/page-spy-alipay/src/index.ts index 50301f7a..85102990 100644 --- a/packages/page-spy-alipay/src/index.ts +++ b/packages/page-spy-alipay/src/index.ts @@ -1,6 +1,6 @@ import PageSpy, { setMPSDK, utilAPI } from '@huolala-tech/page-spy-mp-base'; import { Client, SocketStoreBase } from '@huolala-tech/page-spy-base'; -import { SpyClient } from 'packages/page-spy-types'; +import { SpyClient } from '@huolala-tech/page-spy-types'; // reassign the global.mp to uni diff --git a/packages/page-spy-base/tests/index.test.ts b/packages/page-spy-base/tests/index.test.ts index c91bb9f9..bb5a895d 100644 --- a/packages/page-spy-base/tests/index.test.ts +++ b/packages/page-spy-base/tests/index.test.ts @@ -12,7 +12,7 @@ describe('makePrimitiveValue: convert data to showable string', () => { { received: Infinity, expected: 'Infinity' }, { received: -Infinity, expected: '-Infinity' }, { received: NaN, expected: 'NaN' }, - { received: 123n, expected: '123n' }, + { received: BigInt(123), expected: '123n' }, { received: Symbol('foo'), expected: 'Symbol(foo)' }, { received: null, expected: null }, ].forEach(({ received, expected }) => { @@ -44,7 +44,7 @@ describe('getValueType', () => { expect(getValueType(new String())).toBe('object'); expect(getValueType(123)).toBe('number'); - expect(getValueType(123n)).toBe('bigint'); + expect(getValueType(BigInt(123))).toBe('bigint'); expect(getValueType(new Number(123))).toBe('object'); expect(getValueType(() => {})).toBe('function'); diff --git a/packages/page-spy-browser/tests/plugins/network/util.ts b/packages/page-spy-browser/tests/plugins/network/util.ts index 87f5e655..4b38fd1a 100644 --- a/packages/page-spy-browser/tests/plugins/network/util.ts +++ b/packages/page-spy-browser/tests/plugins/network/util.ts @@ -1,6 +1,6 @@ import BeaconProxy from 'page-spy-browser/src/plugins/network/proxy/beacon-proxy'; import FetchProxy from 'page-spy-browser/src/plugins/network/proxy/fetch-proxy'; -import RequestItem from 'page-spy-base/src'; +import { RequestItem } from 'page-spy-base/src'; import XhrProxy from 'page-spy-browser/src/plugins/network/proxy/xhr-proxy'; type RequestStore = Record; diff --git a/packages/page-spy-plugin-rn-async-storage/src/index.ts b/packages/page-spy-plugin-rn-async-storage/src/index.ts index f3617572..e8c48d2a 100644 --- a/packages/page-spy-plugin-rn-async-storage/src/index.ts +++ b/packages/page-spy-plugin-rn-async-storage/src/index.ts @@ -4,9 +4,9 @@ import type { PageSpyPlugin, OnInitParams, SpyBase, + InitConfigBase, } from '@huolala-tech/page-spy-types'; import AsyncStorage from '@react-native-async-storage/async-storage'; -import type { InitConfig } from '@huolala-tech/page-spy-react-native'; import type { Callback, MultiCallback, @@ -22,7 +22,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { private static socketStore: SpyBase.SocketStoreType | null = null; // eslint-disable-next-line class-methods-use-this - public onInit(params: OnInitParams) { + public onInit(params: OnInitParams) { if (RNAsyncStoragePlugin.hasInitd) return; RNAsyncStoragePlugin.hasInitd = true; diff --git a/tsconfig.json b/tsconfig.json index 72c5bb5c..598f304b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "resolveJsonModule": true, "moduleResolution": "Bundler", "importHelpers": true, - "target": "esnext", + "target": "ESNext", "module": "esnext", "lib": ["DOM", "DOM.Iterable", "esnext"], "skipLibCheck": true, From ca4676d31bdb0209b5c145914e2b80591d398f6d Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 22:45:49 +0800 Subject: [PATCH 08/13] update 'files' field package.json --- packages/page-spy-alipay/package.json | 5 ++--- packages/page-spy-base/package.json | 1 + packages/page-spy-browser/package.json | 3 +-- packages/page-spy-mp-base/package.json | 2 +- packages/page-spy-plugin-data-harbor/package.json | 3 +-- packages/page-spy-plugin-mp-eval/package.json | 13 ++++++------- .../page-spy-plugin-mp-eval/rollup.config.mjs | 13 +++++-------- packages/page-spy-plugin-mp-eval/src/index.ts | 15 +++++++++------ packages/page-spy-plugin-mp-eval/types/index.d.ts | 5 ----- .../page-spy-plugin-rn-async-storage/package.json | 3 +-- packages/page-spy-taro/package.json | 3 +-- packages/page-spy-uniapp/package.json | 3 +-- packages/page-spy-wechat/package.json | 3 +-- 13 files changed, 30 insertions(+), 42 deletions(-) delete mode 100644 packages/page-spy-plugin-mp-eval/types/index.d.ts diff --git a/packages/page-spy-alipay/package.json b/packages/page-spy-alipay/package.json index 4844c34b..dfb638ee 100644 --- a/packages/page-spy-alipay/package.json +++ b/packages/page-spy-alipay/package.json @@ -7,13 +7,12 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "homepage": "https://www.pagespy.org/", "repository": { "type": "git", - "url": "https://github.com/HuolalaTech/page-spy" + "url": "git+https://github.com/HuolalaTech/page-spy.git" }, "keywords": [ "pagespy", diff --git a/packages/page-spy-base/package.json b/packages/page-spy-base/package.json index 3b8f88f8..3cdfdb24 100644 --- a/packages/page-spy-base/package.json +++ b/packages/page-spy-base/package.json @@ -7,6 +7,7 @@ }, "license": "MIT", "main": "./dist/index.js", + "module": "./dist/index.js", "types": "./dist/index.d.ts", "scripts": { "build": "yarn clean && tsc", diff --git a/packages/page-spy-browser/package.json b/packages/page-spy-browser/package.json index 33fc4a83..41a2e39d 100644 --- a/packages/page-spy-browser/package.json +++ b/packages/page-spy-browser/package.json @@ -7,8 +7,7 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "homepage": "https://www.pagespy.org/", "repository": { diff --git a/packages/page-spy-mp-base/package.json b/packages/page-spy-mp-base/package.json index fc885982..eaa1bcfd 100644 --- a/packages/page-spy-mp-base/package.json +++ b/packages/page-spy-mp-base/package.json @@ -36,7 +36,7 @@ }, "files": [ "dist", - "types.d.ts" + "global.d.ts" ], "keywords": [ "pagespy", diff --git a/packages/page-spy-plugin-data-harbor/package.json b/packages/page-spy-plugin-data-harbor/package.json index f849aff4..10676e13 100644 --- a/packages/page-spy-plugin-data-harbor/package.json +++ b/packages/page-spy-plugin-data-harbor/package.json @@ -8,8 +8,7 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "publishConfig": { "access": "public" diff --git a/packages/page-spy-plugin-mp-eval/package.json b/packages/page-spy-plugin-mp-eval/package.json index 25b0662e..1ca9e9ec 100644 --- a/packages/page-spy-plugin-mp-eval/package.json +++ b/packages/page-spy-plugin-mp-eval/package.json @@ -4,12 +4,11 @@ "description": "Used for code evaluation in mini program.", "homepage": "https://github.com/HuolalaTech/page-spy/tree/main/packages/page-spy-plugin-mp-eval", "license": "MIT", - "main": "dist/iife/index.min.js", + "main": "dist/esm/index.min.js", "module": "dist/esm/index.min.js", - "types": "types/index.d.ts", + "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "publishConfig": { "access": "public" @@ -27,15 +26,15 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "fflate": "^0.8.1" + "@huolala-tech/eval5": "^0.0.1", + "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-mp-base": "*" }, "devDependencies": { "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@huolala-tech/eval5": "^0.0.1", "@huolala-tech/page-spy-types": "^1.9.0", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.0.1", diff --git a/packages/page-spy-plugin-mp-eval/rollup.config.mjs b/packages/page-spy-plugin-mp-eval/rollup.config.mjs index 9640e9c9..f1f2738b 100644 --- a/packages/page-spy-plugin-mp-eval/rollup.config.mjs +++ b/packages/page-spy-plugin-mp-eval/rollup.config.mjs @@ -5,12 +5,10 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve, dirname } from 'path'; +import { dirname } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const getBabel = (mode) => { return babel({ @@ -36,14 +34,13 @@ const getBabel = (mode) => { const plugins = [ nodeResolve(), commonjs(), - typescript(), + typescript({ + useTsconfigDeclarationDir: true, + }), replace({ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - alias({ - entries: [{ find: 'base', replacement: resolve(root, '../base') }], - }), terser(), ]; @@ -56,7 +53,7 @@ export default [ output: { file: pkg.module, format: 'esm', - sourcemap: true + sourcemap: true, }, plugins: [ ...plugins, diff --git a/packages/page-spy-plugin-mp-eval/src/index.ts b/packages/page-spy-plugin-mp-eval/src/index.ts index f1dc1973..2f52d781 100644 --- a/packages/page-spy-plugin-mp-eval/src/index.ts +++ b/packages/page-spy-plugin-mp-eval/src/index.ts @@ -1,10 +1,13 @@ -import { OnInitParams, PageSpyPlugin, SpyBase } from 'packages/page-spy-types'; import { Interpreter } from '@huolala-tech/eval5'; -import { makeMessage } from 'base/src/message'; -import { getRandomId } from 'base/src'; -import { getGlobal } from 'mp-base/src/utils'; -import { SocketStoreType } from 'packages/page-spy-types/lib/base'; -import type { Atom } from 'base/src/atom'; +import { makeMessage, getRandomId } from '@huolala-tech/page-spy-base'; +import { getGlobal } from '@huolala-tech/page-spy-mp-base'; +import type { + OnInitParams, + PageSpyPlugin, + SpyBase, +} from '@huolala-tech/page-spy-types'; +import type { Atom } from '@huolala-tech/page-spy-base'; +import type { SocketStoreType } from '@huolala-tech/page-spy-types/lib/base'; export default class MPEvalPlugin implements PageSpyPlugin { public name: string = 'MPEvalPlugin'; diff --git a/packages/page-spy-plugin-mp-eval/types/index.d.ts b/packages/page-spy-plugin-mp-eval/types/index.d.ts deleted file mode 100644 index 3d02bc95..00000000 --- a/packages/page-spy-plugin-mp-eval/types/index.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { PageSpyPlugin } from '@huolala-tech/page-spy-types'; - -declare class MPEvalPlugin implements PageSpyPlugin {} - -export default MPEvalPlugin; diff --git a/packages/page-spy-plugin-rn-async-storage/package.json b/packages/page-spy-plugin-rn-async-storage/package.json index 9d043925..403b97f7 100644 --- a/packages/page-spy-plugin-rn-async-storage/package.json +++ b/packages/page-spy-plugin-rn-async-storage/package.json @@ -8,8 +8,7 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "publishConfig": { "access": "public" diff --git a/packages/page-spy-taro/package.json b/packages/page-spy-taro/package.json index e0ebf380..af038eee 100644 --- a/packages/page-spy-taro/package.json +++ b/packages/page-spy-taro/package.json @@ -7,8 +7,7 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "homepage": "https://www.pagespy.org/", "repository": { diff --git a/packages/page-spy-uniapp/package.json b/packages/page-spy-uniapp/package.json index 5b67d766..06f7dbd0 100644 --- a/packages/page-spy-uniapp/package.json +++ b/packages/page-spy-uniapp/package.json @@ -7,8 +7,7 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "homepage": "https://www.pagespy.org/", "repository": { diff --git a/packages/page-spy-wechat/package.json b/packages/page-spy-wechat/package.json index f5f57adc..2f357676 100644 --- a/packages/page-spy-wechat/package.json +++ b/packages/page-spy-wechat/package.json @@ -7,8 +7,7 @@ "module": "dist/esm/index.min.js", "types": "dist/types/index.d.ts", "files": [ - "dist", - "types" + "dist" ], "homepage": "https://www.pagespy.org/", "repository": { From 0aaf2d09052d24d21e2276bccc982661e3adb17c Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 22:46:01 +0800 Subject: [PATCH 09/13] update 'files' field package.json --- packages/page-spy-plugin-mp-eval/tsconfig.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 packages/page-spy-plugin-mp-eval/tsconfig.json diff --git a/packages/page-spy-plugin-mp-eval/tsconfig.json b/packages/page-spy-plugin-mp-eval/tsconfig.json new file mode 100644 index 00000000..5755a90e --- /dev/null +++ b/packages/page-spy-plugin-mp-eval/tsconfig.json @@ -0,0 +1,9 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "dist", + "declarationDir": "dist/types" + }, + "include": ["src"] +} From 5afe927b3e3031d3f02337f5b15dad4c6c1fea87 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 23:01:54 +0800 Subject: [PATCH 10/13] remove unused deps from package.json --- packages/page-spy-alipay/package.json | 1 - packages/page-spy-plugin-data-harbor/package.json | 1 - packages/page-spy-plugin-rn-async-storage/package.json | 1 - packages/page-spy-taro/package.json | 1 - packages/page-spy-uniapp/package.json | 1 - packages/page-spy-wechat/package.json | 1 - 6 files changed, 6 deletions(-) diff --git a/packages/page-spy-alipay/package.json b/packages/page-spy-alipay/package.json index dfb638ee..bc25a33f 100644 --- a/packages/page-spy-alipay/package.json +++ b/packages/page-spy-alipay/package.json @@ -38,7 +38,6 @@ "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", diff --git a/packages/page-spy-plugin-data-harbor/package.json b/packages/page-spy-plugin-data-harbor/package.json index 10676e13..34efaec8 100644 --- a/packages/page-spy-plugin-data-harbor/package.json +++ b/packages/page-spy-plugin-data-harbor/package.json @@ -34,7 +34,6 @@ "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", "@huolala-tech/page-spy-types": "^1.9.0", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.0.1", diff --git a/packages/page-spy-plugin-rn-async-storage/package.json b/packages/page-spy-plugin-rn-async-storage/package.json index 403b97f7..be3f8629 100644 --- a/packages/page-spy-plugin-rn-async-storage/package.json +++ b/packages/page-spy-plugin-rn-async-storage/package.json @@ -35,7 +35,6 @@ "@huolala-tech/page-spy-react-native": "*", "@huolala-tech/page-spy-types": "^1.9.0", "@react-native-async-storage/async-storage": "^1.23.1", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.0.1", diff --git a/packages/page-spy-taro/package.json b/packages/page-spy-taro/package.json index af038eee..722422db 100644 --- a/packages/page-spy-taro/package.json +++ b/packages/page-spy-taro/package.json @@ -38,7 +38,6 @@ "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-json": "^6.0.0", diff --git a/packages/page-spy-uniapp/package.json b/packages/page-spy-uniapp/package.json index 06f7dbd0..13d94100 100644 --- a/packages/page-spy-uniapp/package.json +++ b/packages/page-spy-uniapp/package.json @@ -38,7 +38,6 @@ "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", diff --git a/packages/page-spy-wechat/package.json b/packages/page-spy-wechat/package.json index 2f357676..ccd21cde 100644 --- a/packages/page-spy-wechat/package.json +++ b/packages/page-spy-wechat/package.json @@ -38,7 +38,6 @@ "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", From 054fe8b9039d85ef05f15e68e267bcfcfa56825e Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Tue, 9 Jul 2024 23:36:46 +0800 Subject: [PATCH 11/13] update package deps from package.json --- packages/page-spy-alipay/package.json | 7 +++---- packages/page-spy-alipay/rollup.config.mjs | 2 -- packages/page-spy-base/package.json | 5 ++--- packages/page-spy-browser/package.json | 3 +-- packages/page-spy-browser/rollup.config.mjs | 3 --- packages/page-spy-mp-base/package.json | 4 ++-- packages/page-spy-plugin-data-harbor/package.json | 2 +- packages/page-spy-plugin-mp-eval/package.json | 4 ++-- packages/page-spy-plugin-rn-async-storage/package.json | 4 ++-- packages/page-spy-plugin-rrweb/package.json | 2 +- packages/page-spy-react-native/package.json | 3 +-- packages/page-spy-react-native/rollup.config.mjs | 7 ------- packages/page-spy-taro/package.json | 6 +++--- packages/page-spy-uniapp/package.json | 7 +++---- packages/page-spy-uniapp/rollup.config.mjs | 2 -- packages/page-spy-wechat/package.json | 7 +++---- packages/page-spy-wechat/rollup.config.mjs | 3 --- 17 files changed, 24 insertions(+), 47 deletions(-) diff --git a/packages/page-spy-alipay/package.json b/packages/page-spy-alipay/package.json index bc25a33f..b13aa4ed 100644 --- a/packages/page-spy-alipay/package.json +++ b/packages/page-spy-alipay/package.json @@ -30,9 +30,9 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0", - "@huolala-tech/page-spy-base": "*", - "@huolala-tech/page-spy-mp-base": "*" + "@huolala-tech/page-spy-base": "^1.0.0", + "@huolala-tech/page-spy-mp-base": "^1.0.0", + "@huolala-tech/page-spy-types": "^1.9.0" }, "devDependencies": { "@babel/core": "^7.14.0", @@ -41,7 +41,6 @@ "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", - "@rollup/plugin-image": "^2.1.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", diff --git a/packages/page-spy-alipay/rollup.config.mjs b/packages/page-spy-alipay/rollup.config.mjs index 91070a73..055f4adc 100644 --- a/packages/page-spy-alipay/rollup.config.mjs +++ b/packages/page-spy-alipay/rollup.config.mjs @@ -6,14 +6,12 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ - image(), json(), nodeResolve(), commonjs(), diff --git a/packages/page-spy-base/package.json b/packages/page-spy-base/package.json index 3cdfdb24..d0ea5b83 100644 --- a/packages/page-spy-base/package.json +++ b/packages/page-spy-base/package.json @@ -3,7 +3,7 @@ "version": "1.0.0", "description": "The common utils of PageSpy.", "dependencies": { - "@huolala-tech/page-spy-types": "*" + "@huolala-tech/page-spy-types": "^1.9.0" }, "license": "MIT", "main": "./dist/index.js", @@ -25,8 +25,7 @@ "url": "https://github.com/HuolalaTech/page-spy/issues" }, "files": [ - "dist", - "types" + "dist" ], "keywords": [ "pagespy", diff --git a/packages/page-spy-browser/package.json b/packages/page-spy-browser/package.json index 41a2e39d..69884900 100644 --- a/packages/page-spy-browser/package.json +++ b/packages/page-spy-browser/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-base": "^1.0.0", "@huolala-tech/page-spy-types": "^1.9.0", "copy-to-clipboard": "^3.3.1" }, @@ -40,7 +40,6 @@ "@babel/plugin-transform-runtime": "^7.23.6", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@rollup/plugin-alias": "^4.0.3", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-image": "^2.1.1", diff --git a/packages/page-spy-browser/rollup.config.mjs b/packages/page-spy-browser/rollup.config.mjs index 4a20ee83..b3c46107 100644 --- a/packages/page-spy-browser/rollup.config.mjs +++ b/packages/page-spy-browser/rollup.config.mjs @@ -8,13 +8,10 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import alias from '@rollup/plugin-alias'; import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -import { resolve } from 'path'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ diff --git a/packages/page-spy-mp-base/package.json b/packages/page-spy-mp-base/package.json index eaa1bcfd..91e388c3 100644 --- a/packages/page-spy-mp-base/package.json +++ b/packages/page-spy-mp-base/package.json @@ -20,8 +20,8 @@ }, "dependencies": { "@huolala-tech/eval5": "^0.0.1", - "@huolala-tech/page-spy-base": "*", - "@huolala-tech/page-spy-types": "*" + "@huolala-tech/page-spy-base": "^1.0.0", + "@huolala-tech/page-spy-types": "^1.9.0" }, "publishConfig": { "access": "public" diff --git a/packages/page-spy-plugin-data-harbor/package.json b/packages/page-spy-plugin-data-harbor/package.json index 34efaec8..42849d88 100644 --- a/packages/page-spy-plugin-data-harbor/package.json +++ b/packages/page-spy-plugin-data-harbor/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-base": "^1.0.0", "fflate": "^0.8.1" }, "devDependencies": { diff --git a/packages/page-spy-plugin-mp-eval/package.json b/packages/page-spy-plugin-mp-eval/package.json index 1ca9e9ec..f84a4b57 100644 --- a/packages/page-spy-plugin-mp-eval/package.json +++ b/packages/page-spy-plugin-mp-eval/package.json @@ -27,8 +27,8 @@ "dependencies": { "@babel/runtime": "^7.13.0", "@huolala-tech/eval5": "^0.0.1", - "@huolala-tech/page-spy-base": "*", - "@huolala-tech/page-spy-mp-base": "*" + "@huolala-tech/page-spy-base": "^1.0.0", + "@huolala-tech/page-spy-mp-base": "^1.0.0" }, "devDependencies": { "@babel/core": "^7.14.0", diff --git a/packages/page-spy-plugin-rn-async-storage/package.json b/packages/page-spy-plugin-rn-async-storage/package.json index be3f8629..db0a1f58 100644 --- a/packages/page-spy-plugin-rn-async-storage/package.json +++ b/packages/page-spy-plugin-rn-async-storage/package.json @@ -26,13 +26,12 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-base": "*" + "@huolala-tech/page-spy-base": "^1.0.0" }, "devDependencies": { "@babel/core": "^7.14.0", "@babel/preset-env": "^7.14.1", "@babel/preset-typescript": "^7.13.0", - "@huolala-tech/page-spy-react-native": "*", "@huolala-tech/page-spy-types": "^1.9.0", "@react-native-async-storage/async-storage": "^1.23.1", "@rollup/plugin-babel": "^6.0.3", @@ -59,6 +58,7 @@ "not op_mini all" ], "peerDependencies": { + "@huolala-tech/page-spy-react-native": "^1.9.0", "@react-native-async-storage/async-storage": "^1.23.1" } } diff --git a/packages/page-spy-plugin-rrweb/package.json b/packages/page-spy-plugin-rrweb/package.json index 94e40121..3f5066e0 100644 --- a/packages/page-spy-plugin-rrweb/package.json +++ b/packages/page-spy-plugin-rrweb/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-base": "^1.0.0", "@huolala-tech/page-spy-types": "^1.9.0", "rrweb": "^2.0.0-alpha.4" }, diff --git a/packages/page-spy-react-native/package.json b/packages/page-spy-react-native/package.json index b834eefa..bf732f18 100644 --- a/packages/page-spy-react-native/package.json +++ b/packages/page-spy-react-native/package.json @@ -30,7 +30,7 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-base": "*", + "@huolala-tech/page-spy-base": "^1.0.0", "@huolala-tech/page-spy-types": "^1.9.0", "promise": "^8.3.0" }, @@ -44,7 +44,6 @@ "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", - "autoprefixer": "^10.3.4", "core-js": "3", "react-native": "^0.74.1", "rollup": "^3.10.0", diff --git a/packages/page-spy-react-native/rollup.config.mjs b/packages/page-spy-react-native/rollup.config.mjs index bf8628f6..a283f1a0 100644 --- a/packages/page-spy-react-native/rollup.config.mjs +++ b/packages/page-spy-react-native/rollup.config.mjs @@ -2,8 +2,6 @@ import typescript from 'rollup-plugin-typescript2'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import babel from '@rollup/plugin-babel'; import del from 'rollup-plugin-delete'; -import postcss from 'rollup-plugin-postcss'; -import autoprefixer from 'autoprefixer'; import commonjs from '@rollup/plugin-commonjs'; import nodeResolve from '@rollup/plugin-node-resolve'; import replace from '@rollup/plugin-replace'; @@ -38,11 +36,6 @@ const plugins = [ PKG_VERSION: `"${pkg.version}"`, preventAssignment: true, }), - postcss({ - extensions: ['.css', '.less'], - extract: false, - plugins: [autoprefixer()], - }), terser(), ]; diff --git a/packages/page-spy-taro/package.json b/packages/page-spy-taro/package.json index 722422db..8f80b095 100644 --- a/packages/page-spy-taro/package.json +++ b/packages/page-spy-taro/package.json @@ -30,9 +30,9 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0", - "@huolala-tech/page-spy-base": "*", - "@huolala-tech/page-spy-mp-base": "*" + "@huolala-tech/page-spy-base": "^1.0.0", + "@huolala-tech/page-spy-mp-base": "^1.0.0", + "@huolala-tech/page-spy-types": "^1.9.0" }, "devDependencies": { "@babel/core": "^7.14.0", diff --git a/packages/page-spy-uniapp/package.json b/packages/page-spy-uniapp/package.json index 13d94100..d9601daf 100644 --- a/packages/page-spy-uniapp/package.json +++ b/packages/page-spy-uniapp/package.json @@ -30,9 +30,9 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0", - "@huolala-tech/page-spy-base": "*", - "@huolala-tech/page-spy-mp-base": "*" + "@huolala-tech/page-spy-base": "^1.0.0", + "@huolala-tech/page-spy-mp-base": "^1.0.0", + "@huolala-tech/page-spy-types": "^1.9.0" }, "devDependencies": { "@babel/core": "^7.14.0", @@ -41,7 +41,6 @@ "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", - "@rollup/plugin-image": "^2.1.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", diff --git a/packages/page-spy-uniapp/rollup.config.mjs b/packages/page-spy-uniapp/rollup.config.mjs index 91070a73..055f4adc 100644 --- a/packages/page-spy-uniapp/rollup.config.mjs +++ b/packages/page-spy-uniapp/rollup.config.mjs @@ -6,14 +6,12 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ - image(), json(), nodeResolve(), commonjs(), diff --git a/packages/page-spy-wechat/package.json b/packages/page-spy-wechat/package.json index ccd21cde..63bb5c9f 100644 --- a/packages/page-spy-wechat/package.json +++ b/packages/page-spy-wechat/package.json @@ -30,9 +30,9 @@ }, "dependencies": { "@babel/runtime": "^7.13.0", - "@huolala-tech/page-spy-types": "^1.9.0", - "@huolala-tech/page-spy-base": "*", - "@huolala-tech/page-spy-mp-base": "*" + "@huolala-tech/page-spy-base": "^1.0.0", + "@huolala-tech/page-spy-mp-base": "^1.0.0", + "@huolala-tech/page-spy-types": "^1.9.0" }, "devDependencies": { "@babel/core": "^7.14.0", @@ -41,7 +41,6 @@ "@huolala-tech/eval5": "^0.0.1", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-commonjs": "^24.0.1", - "@rollup/plugin-image": "^2.1.1", "@rollup/plugin-json": "^6.0.0", "@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-replace": "^5.0.5", diff --git a/packages/page-spy-wechat/rollup.config.mjs b/packages/page-spy-wechat/rollup.config.mjs index a1313a1c..055f4adc 100644 --- a/packages/page-spy-wechat/rollup.config.mjs +++ b/packages/page-spy-wechat/rollup.config.mjs @@ -6,15 +6,12 @@ import nodeResolve from '@rollup/plugin-node-resolve'; import json from '@rollup/plugin-json'; import replace from '@rollup/plugin-replace'; import terser from '@rollup/plugin-terser'; -import image from '@rollup/plugin-image'; import { DEFAULT_EXTENSIONS } from '@babel/core'; import fs from 'fs'; -const root = process.cwd(); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); const plugins = [ - image(), json(), nodeResolve(), commonjs(), From 47ec88803e786fa36bd2ae49bfb90c09955c1821 Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Wed, 10 Jul 2024 00:09:08 +0800 Subject: [PATCH 12/13] update yarn.lock --- yarn.lock | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/yarn.lock b/yarn.lock index aebdb0a6..1dfeeccc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2255,13 +2255,6 @@ mkdirp "^1.0.4" rimraf "^3.0.2" -"@rollup/plugin-alias@^4.0.3": - version "4.0.4" - resolved "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-4.0.4.tgz#67734ec44a7747916aa52a3b1a0e8d459dbf3ae2" - integrity sha512-0CaAY238SMtYAWEXXptWSR8iz8NYZnH7zNBKuJ14xFJSGwLtPgjvXYsoApAHfzYXXH1ejxpVw7WlHss3zhh9SQ== - dependencies: - slash "^4.0.0" - "@rollup/plugin-babel@^6.0.3": version "6.0.4" resolved "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-6.0.4.tgz#bd698e351fa9aa9619fcae780aea2a603d98e4c4" @@ -10278,11 +10271,6 @@ slash@3.0.0, slash@^3.0.0: resolved "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -slash@^4.0.0: - version "4.0.0" - resolved "https://registry.npmjs.org/slash/-/slash-4.0.0.tgz#2422372176c4c6c5addb5e2ada885af984b396a7" - integrity sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew== - slice-ansi@^2.0.0: version "2.1.0" resolved "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636" From 8322cabcebc4531cca31d221e61d369e77c5decb Mon Sep 17 00:00:00 2001 From: "blucas.wu" <15555602203@163.com> Date: Wed, 10 Jul 2024 09:24:10 +0800 Subject: [PATCH 13/13] use public instead of private --- packages/page-spy-base/src/atom.ts | 10 ++--- packages/page-spy-base/src/network/base.ts | 6 +-- packages/page-spy-base/src/socket-base.ts | 42 +++++++++---------- .../page-spy-browser/src/component/toast.ts | 2 +- .../page-spy-browser/src/helpers/socket.ts | 2 +- .../page-spy-browser/src/plugins/console.ts | 8 ++-- .../page-spy-browser/src/plugins/database.ts | 22 +++++----- .../page-spy-browser/src/plugins/error.ts | 12 +++--- .../src/plugins/network/proxy/beacon-proxy.ts | 4 +- .../src/plugins/network/proxy/fetch-proxy.ts | 4 +- .../src/plugins/network/proxy/sse-proxy.ts | 6 +-- .../src/plugins/network/proxy/xhr-proxy.ts | 10 ++--- packages/page-spy-browser/src/plugins/page.ts | 2 +- .../page-spy-browser/src/plugins/storage.ts | 20 ++++----- .../src/plugins/system/index.ts | 2 +- .../library/src/main/ets/helpers/socket.ts | 4 +- .../library/src/main/ets/plugins/console.ts | 8 ++-- .../library/src/main/ets/plugins/error.ts | 2 +- .../src/main/ets/plugins/network/axios.ts | 6 +-- .../library/src/main/ets/plugins/storage.ts | 12 +++--- .../library/src/main/ets/utils/atom.ts | 10 ++--- .../src/main/ets/utils/network/base.ts | 6 +-- .../library/src/main/ets/utils/socket-base.ts | 42 +++++++++---------- .../page-spy-mp-base/src/helpers/socket.ts | 4 +- .../page-spy-mp-base/src/plugins/console.ts | 6 +-- .../page-spy-mp-base/src/plugins/error.ts | 8 ++-- .../src/plugins/network/proxy/request.ts | 4 +- .../page-spy-mp-base/src/plugins/storage.ts | 14 +++---- .../page-spy-mp-base/src/plugins/system.ts | 2 +- packages/page-spy-plugin-mp-eval/src/index.ts | 2 +- .../src/index.ts | 16 +++---- .../src/helpers/socket.ts | 4 +- .../src/plugins/console.ts | 6 +-- .../src/plugins/error.ts | 10 ++--- .../src/plugins/network/proxy/fetch-proxy.ts | 4 +- .../src/plugins/network/proxy/xhr-proxy.ts | 10 ++--- .../src/plugins/system.ts | 2 +- 37 files changed, 167 insertions(+), 167 deletions(-) diff --git a/packages/page-spy-base/src/atom.ts b/packages/page-spy-base/src/atom.ts index 0be240c4..409234a5 100644 --- a/packages/page-spy-base/src/atom.ts +++ b/packages/page-spy-base/src/atom.ts @@ -13,7 +13,7 @@ import { } from './utils'; export class Atom { - private store: Record = {}; + public store: Record = {}; public getStore() { return this.store; @@ -24,7 +24,7 @@ export class Atom { } // { __atomId: instanceId } - private instanceStore: Record = {}; + public instanceStore: Record = {}; public getInstanceStore() { return this.instanceStore; @@ -93,7 +93,7 @@ export class Atom { return Atom.getAtomOverview({ atomId: id, value: name, instanceId }); } - private static getAtomOverview({ + public static getAtomOverview({ instanceId = '', atomId, value, @@ -112,7 +112,7 @@ export class Atom { }; } - private static getSemanticValue(data: any) { + public static getSemanticValue(data: any) { if (isPlainObject(data)) { return 'Object {...}'; } @@ -123,7 +123,7 @@ export class Atom { return constructorName; } - private addExtraProperty(id: string) { + public addExtraProperty(id: string) { const data = this.store[id]; const instanceId = this.instanceStore[id]; const result: Record = {}; diff --git a/packages/page-spy-base/src/network/base.ts b/packages/page-spy-base/src/network/base.ts index 26e6c08f..468387cc 100644 --- a/packages/page-spy-base/src/network/base.ts +++ b/packages/page-spy-base/src/network/base.ts @@ -6,9 +6,9 @@ import { ReqReadyState } from './common'; type RequestStore = Record; export class NetworkProxyBase { - private reqMap: RequestStore = Object.create(null); + public reqMap: RequestStore = Object.create(null); - constructor(private socketStore: SocketStoreBase) {} + constructor(public socketStore: SocketStoreBase) {} public getRequestMap() { return this.reqMap; @@ -70,7 +70,7 @@ export class NetworkProxyBase { } } - private deferDeleteRequest(id: string) { + public deferDeleteRequest(id: string) { const req = this.getRequest(id); if (req && req.readyState === ReqReadyState.DONE) { setTimeout(() => { diff --git a/packages/page-spy-base/src/socket-base.ts b/packages/page-spy-base/src/socket-base.ts index 562c5572..2a1add72 100644 --- a/packages/page-spy-base/src/socket-base.ts +++ b/packages/page-spy-base/src/socket-base.ts @@ -99,20 +99,20 @@ export abstract class SocketStoreBase { protected abstract updateRoomInfo(): void; - private socketUrl: string = ''; + public socketUrl: string = ''; - private socketConnection: SpySocket.Connection | null = null; + public socketConnection: SpySocket.Connection | null = null; - private debuggerConnection: SpySocket.Connection | null = null; + public debuggerConnection: SpySocket.Connection | null = null; // ping timer used for send next ping. // a ping is sent after last msg (normal msg or pong) received. - private pingTimer: ReturnType | null = null; + public pingTimer: ReturnType | null = null; // pong timer used for waiting for pong, if pong not received, close the connection - private pongTimer: ReturnType | null = null; + public pongTimer: ReturnType | null = null; - private retryTimer: ReturnType | null = null; + public retryTimer: ReturnType | null = null; // Cache messages only in online mode public isOffline = false; @@ -122,10 +122,10 @@ export abstract class SocketStoreBase { public messageCapacity: number = 0; // messages store - private messages: SpySocket.BroadcastEvent[] = []; + public messages: SpySocket.BroadcastEvent[] = []; // events center - private events: Record< + public events: Record< InteractiveType | InternalMsgType, SpyBase.EventCallback[] > = { @@ -139,7 +139,7 @@ export abstract class SocketStoreBase { }; // initial retry interval. - private retryInterval = INIT_RETRY_INTERVAL; + public retryInterval = INIT_RETRY_INTERVAL; connectable = true; @@ -250,13 +250,13 @@ export abstract class SocketStoreBase { }); } - private connectOnline() { + public connectOnline() { this.retryInterval = INIT_RETRY_INTERVAL; this.updateRoomInfo(); this.ping(); } - private connectOffline() { + public connectOffline() { this.socketConnection = null; this.debuggerConnection = null; this.clearPing(); @@ -278,7 +278,7 @@ export abstract class SocketStoreBase { this.init(this.socketUrl); } - private ping() { + public ping() { if (this.pingTimer) { clearTimeout(this.pingTimer); } @@ -301,7 +301,7 @@ export abstract class SocketStoreBase { /* c8 ignore stop */ } - private clearPing() { + public clearPing() { if (this.pingTimer) { clearTimeout(this.pingTimer); this.pingTimer = null; @@ -312,7 +312,7 @@ export abstract class SocketStoreBase { } } - private handlePong() { + public handlePong() { clearTimeout(this.pongTimer!); this.pongTimer = null; this.ping(); @@ -408,7 +408,7 @@ export abstract class SocketStoreBase { }); } - private unicastMessage( + public unicastMessage( msg: SpyMessage.MessageItem, to: SpySocket.Connection, ) { @@ -416,7 +416,7 @@ export abstract class SocketStoreBase { this.send(message); } - private handleFlushBuffer( + public handleFlushBuffer( message: SpyBase.InteractiveEvent<{ latestId: string }>, ) { const { latestId } = message.source.data; @@ -440,7 +440,7 @@ export abstract class SocketStoreBase { /* c8 ignore stop */ } - private static handleResolveAtom( + public static handleResolveAtom( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { @@ -452,7 +452,7 @@ export abstract class SocketStoreBase { } } - private static handleAtomPropertyGetter( + public static handleAtomPropertyGetter( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { @@ -504,7 +504,7 @@ export abstract class SocketStoreBase { } } - private checkIfSend(msg: SpySocket.ClientEvent) { + public checkIfSend(msg: SpySocket.ClientEvent) { if (this.socketWrapper.getState() !== SocketState.OPEN) return false; if ( [SERVER_MESSAGE_TYPE.UPDATE_ROOM_INFO, SERVER_MESSAGE_TYPE.PING].includes( @@ -518,7 +518,7 @@ export abstract class SocketStoreBase { return true; } - private checkIfCache(msg: SpySocket.ClientEvent, noCache: boolean = false) { + public checkIfCache(msg: SpySocket.ClientEvent, noCache: boolean = false) { if (this.isOffline || noCache) return false; if ( [SERVER_MESSAGE_TYPE.MESSAGE, SERVER_MESSAGE_TYPE.PING].includes(msg.type) @@ -528,7 +528,7 @@ export abstract class SocketStoreBase { return true; } - private sendClientInfo() { + public sendClientInfo() { const clientInfo = Client.makeClientInfoMsg(); this.broadcastMessage( { diff --git a/packages/page-spy-browser/src/component/toast.ts b/packages/page-spy-browser/src/component/toast.ts index 76c69641..10c9f5b4 100644 --- a/packages/page-spy-browser/src/component/toast.ts +++ b/packages/page-spy-browser/src/component/toast.ts @@ -3,7 +3,7 @@ * Clear all notifications use `Toast.destroy()` */ export class Toast { - private static timer: ReturnType | null = null; + public static timer: ReturnType | null = null; static message(text: string) { const node = document.createElement('div'); diff --git a/packages/page-spy-browser/src/helpers/socket.ts b/packages/page-spy-browser/src/helpers/socket.ts index 416ad7fe..2f8f758e 100644 --- a/packages/page-spy-browser/src/helpers/socket.ts +++ b/packages/page-spy-browser/src/helpers/socket.ts @@ -10,7 +10,7 @@ import { import { InitConfig } from '../config'; export class WebSocketWrapper extends SocketWrapper { - private socketInstance: WebSocket | null = null; + public socketInstance: WebSocket | null = null; init(url: string) { this.socketInstance = new WebSocket(url); diff --git a/packages/page-spy-browser/src/plugins/console.ts b/packages/page-spy-browser/src/plugins/console.ts index 44ffa73b..b7651d53 100644 --- a/packages/page-spy-browser/src/plugins/console.ts +++ b/packages/page-spy-browser/src/plugins/console.ts @@ -11,7 +11,7 @@ export default class ConsolePlugin implements PageSpyPlugin { public static hasInitd = false; - private proxyTypes: SpyConsole.ProxyType[] = [ + public proxyTypes: SpyConsole.ProxyType[] = [ 'log', 'info', 'error', @@ -19,7 +19,7 @@ export default class ConsolePlugin implements PageSpyPlugin { 'debug', ]; - private console: Record = {}; + public console: Record = {}; // eslint-disable-next-line class-methods-use-this public async onInit() { @@ -49,7 +49,7 @@ export default class ConsolePlugin implements PageSpyPlugin { } // run executable code which received from remote and send back the result - private static handleDebugger( + public static handleDebugger( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { @@ -89,7 +89,7 @@ export default class ConsolePlugin implements PageSpyPlugin { } } - private printLog(data: SpyConsole.DataItem) { + public printLog(data: SpyConsole.DataItem) { if (data.logs && data.logs.length) { this.console[data.logType](...data.logs); // eslint-disable-next-line no-param-reassign diff --git a/packages/page-spy-browser/src/plugins/database.ts b/packages/page-spy-browser/src/plugins/database.ts index 01b02a18..d28606e3 100644 --- a/packages/page-spy-browser/src/plugins/database.ts +++ b/packages/page-spy-browser/src/plugins/database.ts @@ -19,15 +19,15 @@ export class DatabasePlugin implements PageSpyPlugin { public static hasInitd = false; - private originAdd: IDBObjectStore['add'] | null = null; + public originAdd: IDBObjectStore['add'] | null = null; - private originPut: IDBObjectStore['put'] | null = null; + public originPut: IDBObjectStore['put'] | null = null; - private originDelete: IDBObjectStore['delete'] | null = null; + public originDelete: IDBObjectStore['delete'] | null = null; - private originClear: IDBObjectStore['clear'] | null = null; + public originClear: IDBObjectStore['clear'] | null = null; - private originDrop: IDBFactory['deleteDatabase'] | null = null; + public originDrop: IDBFactory['deleteDatabase'] | null = null; public static get isSupport() { if ( @@ -71,7 +71,7 @@ export class DatabasePlugin implements PageSpyPlugin { DatabasePlugin.hasInitd = false; } - private static listenEvents() { + public static listenEvents() { socketStore.addListener('refresh', async ({ source }) => { if (source.data === 'indexedDB') { const result = await this.takeBasicInfo(); @@ -93,7 +93,7 @@ export class DatabasePlugin implements PageSpyPlugin { }); } - private initIndexedDBProxy() { + public initIndexedDBProxy() { const { put: originPut, add: originAdd, @@ -158,7 +158,7 @@ export class DatabasePlugin implements PageSpyPlugin { }; } - private static async takeBasicInfo() { + public static async takeBasicInfo() { const dbs = await window.indexedDB.databases(); if (!dbs.length) { return null; @@ -174,7 +174,7 @@ export class DatabasePlugin implements PageSpyPlugin { return data.filter(Boolean) as DBInfo[]; } - private static async getDBData(info: Required) { + public static async getDBData(info: Required) { try { const result: DBInfo = { name: info.name, @@ -206,7 +206,7 @@ export class DatabasePlugin implements PageSpyPlugin { } } - private static async getStoreDataWithPagination({ + public static async getStoreDataWithPagination({ db, store, page, @@ -266,7 +266,7 @@ export class DatabasePlugin implements PageSpyPlugin { }); } - private static sendData(info: Omit) { + public static sendData(info: Omit) { const data = makeMessage('database', info); // The user wouldn't want to get the stale data, so here we set the 2nd parameter to true. socketStore.broadcastMessage(data, true); diff --git a/packages/page-spy-browser/src/plugins/error.ts b/packages/page-spy-browser/src/plugins/error.ts index 318dfcd8..0bd21ce6 100644 --- a/packages/page-spy-browser/src/plugins/error.ts +++ b/packages/page-spy-browser/src/plugins/error.ts @@ -7,7 +7,7 @@ export default class ErrorPlugin implements PageSpyPlugin { public static hasInitd = false; - private uncaughtErrorListener = (e: ErrorEvent) => { + public uncaughtErrorListener = (e: ErrorEvent) => { if (e.error) { const { message, stack } = e.error; const errorDetail = formatErrorObj(e.error); @@ -20,7 +20,7 @@ export default class ErrorPlugin implements PageSpyPlugin { } }; - private resourceLoadErrorListener = (evt: Event) => { + public resourceLoadErrorListener = (evt: Event) => { if (!(evt instanceof ErrorEvent)) { const { target } = evt as any; ErrorPlugin.sendMessage( @@ -32,7 +32,7 @@ export default class ErrorPlugin implements PageSpyPlugin { } }; - private rejectionListener = (evt: PromiseRejectionEvent) => { + public rejectionListener = (evt: PromiseRejectionEvent) => { const errorDetail = formatErrorObj(evt.reason); ErrorPlugin.sendMessage(evt.reason, errorDetail); }; @@ -53,17 +53,17 @@ export default class ErrorPlugin implements PageSpyPlugin { ErrorPlugin.hasInitd = false; } - private onUncaughtError() { + public onUncaughtError() { window.addEventListener('error', this.uncaughtErrorListener); } - private onResourceLoadError() { + public onResourceLoadError() { // Resource load failed // Track the error on capture-phase window.addEventListener('error', this.resourceLoadErrorListener, true); } - private onUnhandledRejectionError() { + public onUnhandledRejectionError() { // Promise unhandledRejection Error window.addEventListener('unhandledrejection', this.rejectionListener); } diff --git a/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts index e8e32326..e49cfdd9 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/beacon-proxy.ts @@ -8,7 +8,7 @@ import { import WebNetworkProxyBase from './base'; export default class BeaconProxy extends WebNetworkProxyBase { - private sendBeacon: Navigator['sendBeacon'] | null = null; + public sendBeacon: Navigator['sendBeacon'] | null = null; public constructor() { super(); @@ -21,7 +21,7 @@ export default class BeaconProxy extends WebNetworkProxyBase { } } - private initProxyHandler() { + public initProxyHandler() { const originSendBeacon = window.navigator.sendBeacon; if (!originSendBeacon) { return; diff --git a/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts index 0f0cb5b9..0dfa0368 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/fetch-proxy.ts @@ -15,7 +15,7 @@ import { import WebNetworkProxyBase from './base'; export default class FetchProxy extends WebNetworkProxyBase { - private fetch: WindowOrWorkerGlobalScope['fetch'] | null = null; + public fetch: WindowOrWorkerGlobalScope['fetch'] | null = null; constructor() { super(); @@ -28,7 +28,7 @@ export default class FetchProxy extends WebNetworkProxyBase { } } - private initProxyHandler() { + public initProxyHandler() { const that = this; const originFetch = window.fetch; diff --git a/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts index 76f4ae46..758fb931 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/sse-proxy.ts @@ -25,17 +25,17 @@ export default class SSEProxy extends WebNetworkProxyBase { this.initProxyHandler(); } - private initProxyHandler() { + public initProxyHandler() { if (!window.EventSource) { return; } const _sseProxy = this; window.EventSource = class EventSourceProxy { - private content = + public content = 'The "window.EventSource" is being proxied by PageSpy\'s NetworkPlugin.'; - private es: EventSource; + public es: EventSource; constructor(url: string | URL, eventSourceInitDict?: EventSourceInit) { const id = getRandomId(); diff --git a/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts b/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts index 102ccc06..fc9c9295 100644 --- a/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts +++ b/packages/page-spy-browser/src/plugins/network/proxy/xhr-proxy.ts @@ -24,18 +24,18 @@ declare global { } } class XhrProxy extends WebNetworkProxyBase { - private xhrOpen: XMLHttpRequest['open'] | null = null; + public xhrOpen: XMLHttpRequest['open'] | null = null; - private xhrSend: XMLHttpRequest['send'] | null = null; + public xhrSend: XMLHttpRequest['send'] | null = null; - private xhrSetRequestHeader: XMLHttpRequest['setRequestHeader'] | null = null; + public xhrSetRequestHeader: XMLHttpRequest['setRequestHeader'] | null = null; public constructor() { super(); this.initProxyHandler(); } - private initProxyHandler() { + public initProxyHandler() { const that = this; if (!window.XMLHttpRequest) { return; @@ -182,7 +182,7 @@ class XhrProxy extends WebNetworkProxyBase { } // eslint-disable-next-line class-methods-use-this - private async formatResponse(XMLReq: XMLHttpRequest) { + public async formatResponse(XMLReq: XMLHttpRequest) { const result: { response: RequestItem['response']; responseReason: RequestItem['responseReason']; diff --git a/packages/page-spy-browser/src/plugins/page.ts b/packages/page-spy-browser/src/plugins/page.ts index 4ffbd3aa..04e57a08 100644 --- a/packages/page-spy-browser/src/plugins/page.ts +++ b/packages/page-spy-browser/src/plugins/page.ts @@ -25,7 +25,7 @@ export default class PagePlugin implements PageSpyPlugin { PagePlugin.hasInitd = false; } - private static collectHtml() { + public static collectHtml() { const originHtml = document.documentElement.outerHTML; const msg = makeMessage('page', { html: originHtml, diff --git a/packages/page-spy-browser/src/plugins/storage.ts b/packages/page-spy-browser/src/plugins/storage.ts index 9389020d..8fe1d68d 100644 --- a/packages/page-spy-browser/src/plugins/storage.ts +++ b/packages/page-spy-browser/src/plugins/storage.ts @@ -7,13 +7,13 @@ export class StoragePlugin implements PageSpyPlugin { public static hasInitd = false; - private originSetItem: Storage['setItem'] | null = null; + public originSetItem: Storage['setItem'] | null = null; - private originRemoveItem: Storage['removeItem'] | null = null; + public originRemoveItem: Storage['removeItem'] | null = null; - private originClear: Storage['clear'] | null = null; + public originClear: Storage['clear'] | null = null; - private cookieStoreChangeListener: ((evt: Event) => void) | null = null; + public cookieStoreChangeListener: ((evt: Event) => void) | null = null; // eslint-disable-next-line class-methods-use-this public onInit() { @@ -65,7 +65,7 @@ export class StoragePlugin implements PageSpyPlugin { } } - private static listenRefreshEvent() { + public static listenRefreshEvent() { /* c8 ignore next 5 */ socketStore.addListener('refresh', async ({ source }) => { /* c8 ignore next 3 */ @@ -74,7 +74,7 @@ export class StoragePlugin implements PageSpyPlugin { }); } - private static takeStorage(type: 'localStorage' | 'sessionStorage') { + public static takeStorage(type: 'localStorage' | 'sessionStorage') { const data: SpyStorage.GetTypeDataItem = { type, action: 'get', @@ -97,7 +97,7 @@ export class StoragePlugin implements PageSpyPlugin { return data; } - private static async takeCookie() { + public static async takeCookie() { const data: SpyStorage.GetTypeDataItem = { type: 'cookie', action: 'get', @@ -117,7 +117,7 @@ export class StoragePlugin implements PageSpyPlugin { return data; } - private initStorageProxy() { + public initStorageProxy() { const { getStorageType, sendStorageItem } = StoragePlugin; const { clear, removeItem, setItem } = Storage.prototype; this.originClear = clear; @@ -196,13 +196,13 @@ export class StoragePlugin implements PageSpyPlugin { }); } - private static getStorageType(ins: Storage): SpyStorage.DataType { + public static getStorageType(ins: Storage): SpyStorage.DataType { if (ins === localStorage) return 'localStorage'; if (ins === sessionStorage) return 'sessionStorage'; return ins.constructor.name as any; } - private static sendStorageItem(info: Omit) { + public static sendStorageItem(info: Omit) { const data = makeMessage('storage', info); socketStore.dispatchEvent('public-data', data); // The user wouldn't want to get the stale data, so here we set the 2nd parameter to true. diff --git a/packages/page-spy-browser/src/plugins/system/index.ts b/packages/page-spy-browser/src/plugins/system/index.ts index b2287c0b..527bdae4 100644 --- a/packages/page-spy-browser/src/plugins/system/index.ts +++ b/packages/page-spy-browser/src/plugins/system/index.ts @@ -52,7 +52,7 @@ export default class SystemPlugin implements PageSpyPlugin { SystemPlugin.hasInitd = false; } - private static async getSystemInfo() { + public static async getSystemInfo() { const features = await computeResult(); const msg = makeMessage('system', { system: { diff --git a/packages/page-spy-harmony/library/src/main/ets/helpers/socket.ts b/packages/page-spy-harmony/library/src/main/ets/helpers/socket.ts index f226ffe1..938f2515 100644 --- a/packages/page-spy-harmony/library/src/main/ets/helpers/socket.ts +++ b/packages/page-spy-harmony/library/src/main/ets/helpers/socket.ts @@ -10,9 +10,9 @@ import { } from '../utils/socket-base'; export class OHSocketWrapper extends SocketWrapper { - private state: SocketState = 0; + public state: SocketState = 0; - private socketInstance: webSocket.WebSocket | null = null; + public socketInstance: webSocket.WebSocket | null = null; init(url: string) { this.state = SocketState.CONNECTING; diff --git a/packages/page-spy-harmony/library/src/main/ets/plugins/console.ts b/packages/page-spy-harmony/library/src/main/ets/plugins/console.ts index 9e686cc3..aa56a032 100644 --- a/packages/page-spy-harmony/library/src/main/ets/plugins/console.ts +++ b/packages/page-spy-harmony/library/src/main/ets/plugins/console.ts @@ -10,7 +10,7 @@ export default class ConsolePlugin implements PageSpyPlugin { public static hasInitd = false; - private proxyTypes: SpyConsole.ProxyType[] = [ + public proxyTypes: SpyConsole.ProxyType[] = [ 'log', 'info', 'error', @@ -18,7 +18,7 @@ export default class ConsolePlugin implements PageSpyPlugin { 'debug', ]; - private console: Record = {}; + public console: Record = {}; public async onInit() { if (ConsolePlugin.hasInitd) return; @@ -52,7 +52,7 @@ export default class ConsolePlugin implements PageSpyPlugin { ConsolePlugin.hasInitd = false; } - private static handleDebugger( + public static handleDebugger( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { @@ -92,7 +92,7 @@ export default class ConsolePlugin implements PageSpyPlugin { } } - private printLog(data: SpyConsole.DataItem) { + public printLog(data: SpyConsole.DataItem) { if (data.logs && data.logs.length) { this.console[data.logType](...data.logs); data.logs = data.logs.map((log) => atom.transformToAtom(log)); diff --git a/packages/page-spy-harmony/library/src/main/ets/plugins/error.ts b/packages/page-spy-harmony/library/src/main/ets/plugins/error.ts index c535f71c..87859e65 100644 --- a/packages/page-spy-harmony/library/src/main/ets/plugins/error.ts +++ b/packages/page-spy-harmony/library/src/main/ets/plugins/error.ts @@ -9,7 +9,7 @@ export default class ErrorPlugin implements PageSpyPlugin { public static hasInitd = false; - private static observerId: number; + public static observerId: number; public onInit() { if (ErrorPlugin.hasInitd) return; diff --git a/packages/page-spy-harmony/library/src/main/ets/plugins/network/axios.ts b/packages/page-spy-harmony/library/src/main/ets/plugins/network/axios.ts index 9df8a021..7384dbf2 100644 --- a/packages/page-spy-harmony/library/src/main/ets/plugins/network/axios.ts +++ b/packages/page-spy-harmony/library/src/main/ets/plugins/network/axios.ts @@ -14,15 +14,15 @@ import { } from '@ohos/axios'; export default class AxiosProxy extends NetworkProxyBase { - private requestInterceptor: number | null = null; - private responseInterceptor: number | null = null; + public requestInterceptor: number | null = null; + public responseInterceptor: number | null = null; constructor(public axios: AxiosStatic | AxiosInstance) { super(socketStore); this.initProxyHandler(); } - private initProxyHandler() { + public initProxyHandler() { this.requestInterceptor = this.axios.interceptors.request.use((config) => { const id = getRandomId(); this.createRequest(id); diff --git a/packages/page-spy-harmony/library/src/main/ets/plugins/storage.ts b/packages/page-spy-harmony/library/src/main/ets/plugins/storage.ts index 29de5ba8..79030885 100644 --- a/packages/page-spy-harmony/library/src/main/ets/plugins/storage.ts +++ b/packages/page-spy-harmony/library/src/main/ets/plugins/storage.ts @@ -46,7 +46,7 @@ export default class StoragePlugin implements PageSpyPlugin { }); } - private static initStorageProxy() { + public static initStorageProxy() { const { sendSetItem, sendRemoveItem, sendClearItem } = StoragePlugin; ['setAndLink', 'setAndProp'].forEach((fnName) => { Object.defineProperties(AppStorage, { @@ -106,7 +106,7 @@ export default class StoragePlugin implements PageSpyPlugin { }); } - private static listenRefreshEvent() { + public static listenRefreshEvent() { socketStore.addListener('refresh', async ({ source }) => { const { data: storageType } = source; if (storageType === 'AppStorage') { @@ -137,7 +137,7 @@ export default class StoragePlugin implements PageSpyPlugin { } } - private static sendSetItem(key: string, value: any) { + public static sendSetItem(key: string, value: any) { StoragePlugin.sendStorageItem({ type: 'AppStorage', action: 'set', @@ -146,7 +146,7 @@ export default class StoragePlugin implements PageSpyPlugin { } as SpyStorage.SetTypeDataItem); } - private static sendRemoveItem(key: string) { + public static sendRemoveItem(key: string) { StoragePlugin.sendStorageItem({ type: 'AppStorage', action: 'remove', @@ -154,14 +154,14 @@ export default class StoragePlugin implements PageSpyPlugin { } as SpyStorage.RemoveTypeDataItem); } - private static sendClearItem() { + public static sendClearItem() { StoragePlugin.sendStorageItem({ type: 'AppStorage', action: 'clear', } as SpyStorage.ClearTypeDataItem); } - private static sendStorageItem(info: Omit) { + public static sendStorageItem(info: Omit) { const data = makeMessage('storage', info); socketStore.dispatchEvent('public-data', data); // The user wouldn't want to get the stale data, so here we set the 2nd parameter to true. diff --git a/packages/page-spy-harmony/library/src/main/ets/utils/atom.ts b/packages/page-spy-harmony/library/src/main/ets/utils/atom.ts index d84254b0..968d781f 100644 --- a/packages/page-spy-harmony/library/src/main/ets/utils/atom.ts +++ b/packages/page-spy-harmony/library/src/main/ets/utils/atom.ts @@ -11,7 +11,7 @@ import { } from './index'; class Atom { - private store: Record = {}; + public store: Record = {}; public getStore() { return this.store; @@ -22,7 +22,7 @@ class Atom { } // { __atomId: instanceId } - private instanceStore: Record = {}; + public instanceStore: Record = {}; public getInstanceStore() { return this.instanceStore; @@ -88,7 +88,7 @@ class Atom { return Atom.getAtomOverview({ atomId: id, value: name, instanceId }); } - private static getAtomOverview({ + public static getAtomOverview({ instanceId = '', atomId, value, @@ -107,7 +107,7 @@ class Atom { }; } - private static getSemanticValue(data: any) { + public static getSemanticValue(data: any) { if (isPlainObject(data)) { return 'Object {...}'; } @@ -118,7 +118,7 @@ class Atom { return constructorName; } - private addExtraProperty(id: string) { + public addExtraProperty(id: string) { const data = this.store[id]; const instanceId = this.instanceStore[id]; const result: Record = {}; diff --git a/packages/page-spy-harmony/library/src/main/ets/utils/network/base.ts b/packages/page-spy-harmony/library/src/main/ets/utils/network/base.ts index ca2d7c2e..d8af7467 100644 --- a/packages/page-spy-harmony/library/src/main/ets/utils/network/base.ts +++ b/packages/page-spy-harmony/library/src/main/ets/utils/network/base.ts @@ -7,9 +7,9 @@ import { PUBLIC_DATA } from '../message/debug-type'; type RequestStore = Record; export default class NetworkProxyBase { - private reqMap: RequestStore = Object.create(null); + public reqMap: RequestStore = Object.create(null); - constructor(private socketStore: SocketStoreBase) {} + constructor(public socketStore: SocketStoreBase) {} public getRequestMap() { return this.reqMap; @@ -63,7 +63,7 @@ export default class NetworkProxyBase { this.deferDeleteRequest(id); } - private deferDeleteRequest(id: string) { + public deferDeleteRequest(id: string) { const req = this.getRequest(id); if (req && req.readyState === ReqReadyState.DONE) { setTimeout(() => { diff --git a/packages/page-spy-harmony/library/src/main/ets/utils/socket-base.ts b/packages/page-spy-harmony/library/src/main/ets/utils/socket-base.ts index 3b81b082..6711eeb9 100644 --- a/packages/page-spy-harmony/library/src/main/ets/utils/socket-base.ts +++ b/packages/page-spy-harmony/library/src/main/ets/utils/socket-base.ts @@ -111,20 +111,20 @@ export abstract class SocketStoreBase { protected abstract updateRoomInfo(): void; - private socketUrl: string = ''; + public socketUrl: string = ''; - private socketConnection: SpySocket.Connection | null = null; + public socketConnection: SpySocket.Connection | null = null; - private debuggerConnection: SpySocket.Connection | null = null; + public debuggerConnection: SpySocket.Connection | null = null; // ping timer used for send next ping. // a ping is sent after last msg (normal msg or pong) received. - private pingTimer: ReturnType | null = null; + public pingTimer: ReturnType | null = null; // pong timer used for waiting for pong, if pong not received, close the connection - private pongTimer: ReturnType | null = null; + public pongTimer: ReturnType | null = null; - private retryTimer: ReturnType | null = null; + public retryTimer: ReturnType | null = null; // Cache messages only in online mode public isOffline = false; @@ -134,10 +134,10 @@ export abstract class SocketStoreBase { public messageCapacity: number = 0; // messages store - private messages: SpySocket.BroadcastEvent[] = []; + public messages: SpySocket.BroadcastEvent[] = []; // events center - private events: Record< + public events: Record< InteractiveType | InternalMsgType, SpyBase.EventCallback[] > = { @@ -151,7 +151,7 @@ export abstract class SocketStoreBase { }; // initial retry interval. - private retryInterval = INIT_RETRY_INTERVAL; + public retryInterval = INIT_RETRY_INTERVAL; connectable = true; @@ -249,13 +249,13 @@ export abstract class SocketStoreBase { }); } - private connectOnline() { + public connectOnline() { this.retryInterval = INIT_RETRY_INTERVAL; this.updateRoomInfo(); this.ping(); } - private connectOffline() { + public connectOffline() { this.socketConnection = null; this.debuggerConnection = null; this.clearPing(); @@ -277,7 +277,7 @@ export abstract class SocketStoreBase { this.init(this.socketUrl); } - private ping() { + public ping() { if (this.pingTimer) { clearTimeout(this.pingTimer); } @@ -298,7 +298,7 @@ export abstract class SocketStoreBase { }, HEARTBEAT_INTERVAL); } - private clearPing() { + public clearPing() { if (this.pingTimer) { clearTimeout(this.pingTimer); this.pingTimer = null; @@ -309,7 +309,7 @@ export abstract class SocketStoreBase { } } - private handlePong() { + public handlePong() { clearTimeout(this.pongTimer!); this.pongTimer = null; this.ping(); @@ -404,7 +404,7 @@ export abstract class SocketStoreBase { }); } - private unicastMessage( + public unicastMessage( msg: SpyMessage.MessageItem, to: SpySocket.Connection, ) { @@ -412,7 +412,7 @@ export abstract class SocketStoreBase { this.send(message); } - private handleFlushBuffer( + public handleFlushBuffer( message: SpyBase.InteractiveEvent<{ latestId: string }>, ) { const { latestId } = message.source.data; @@ -434,7 +434,7 @@ export abstract class SocketStoreBase { }); } - private static handleResolveAtom( + public static handleResolveAtom( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { @@ -446,7 +446,7 @@ export abstract class SocketStoreBase { } } - private static handleAtomPropertyGetter( + public static handleAtomPropertyGetter( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { @@ -494,7 +494,7 @@ export abstract class SocketStoreBase { } } - private checkIfSend(msg: SpySocket.ClientEvent) { + public checkIfSend(msg: SpySocket.ClientEvent) { if (this.socketWrapper.getState() !== SocketState.OPEN) return false; if ( [SERVER_MESSAGE_TYPE.UPDATE_ROOM_INFO, SERVER_MESSAGE_TYPE.PING].includes( @@ -508,7 +508,7 @@ export abstract class SocketStoreBase { return true; } - private checkIfCache(msg: SpySocket.ClientEvent, noCache: boolean = false) { + public checkIfCache(msg: SpySocket.ClientEvent, noCache: boolean = false) { if (this.isOffline || noCache) return false; if ( [SERVER_MESSAGE_TYPE.MESSAGE, SERVER_MESSAGE_TYPE.PING].includes(msg.type) @@ -518,7 +518,7 @@ export abstract class SocketStoreBase { return true; } - private sendClientInfo() { + public sendClientInfo() { const clientInfo = Client.makeClientInfoMsg(); this.broadcastMessage( { diff --git a/packages/page-spy-mp-base/src/helpers/socket.ts b/packages/page-spy-mp-base/src/helpers/socket.ts index bac525eb..6fc36a5c 100644 --- a/packages/page-spy-mp-base/src/helpers/socket.ts +++ b/packages/page-spy-mp-base/src/helpers/socket.ts @@ -11,9 +11,9 @@ import type { SpyMP } from '@huolala-tech/page-spy-types'; import { getMPSDK, utilAPI } from '../utils'; export class MPSocketWrapper extends SocketWrapper { - private socketInstance: MPSocket | null = null; + public socketInstance: MPSocket | null = null; - private state: SocketState = 0; + public state: SocketState = 0; // some ali-family app only support single socket connection... public static isSingleSocket = false; diff --git a/packages/page-spy-mp-base/src/plugins/console.ts b/packages/page-spy-mp-base/src/plugins/console.ts index 1806e16c..a20a2f1b 100644 --- a/packages/page-spy-mp-base/src/plugins/console.ts +++ b/packages/page-spy-mp-base/src/plugins/console.ts @@ -9,11 +9,11 @@ import { joinQuery } from '../utils'; export default class ConsolePlugin implements PageSpyPlugin { public name: string = 'ConsolePlugin'; - private console: Record = {}; + public console: Record = {}; public static hasInitd = false; - private proxyTypes: SpyConsole.ProxyType[] = [ + public proxyTypes: SpyConsole.ProxyType[] = [ 'log', 'info', 'error', @@ -64,7 +64,7 @@ export default class ConsolePlugin implements PageSpyPlugin { ConsolePlugin.hasInitd = false; } - private printLog(data: SpyConsole.DataItem) { + public printLog(data: SpyConsole.DataItem) { if (data.logs && data.logs.length) { this.console[data.logType](...data.logs); // eslint-disable-next-line no-param-reassign diff --git a/packages/page-spy-mp-base/src/plugins/error.ts b/packages/page-spy-mp-base/src/plugins/error.ts index 958a108f..1ce0683a 100644 --- a/packages/page-spy-mp-base/src/plugins/error.ts +++ b/packages/page-spy-mp-base/src/plugins/error.ts @@ -31,7 +31,7 @@ export default class ErrorPlugin implements PageSpyPlugin { ErrorPlugin.hasInitd = false; } - private errorHandler(error: { message: string; stack: string }) { + public errorHandler(error: { message: string; stack: string }) { if (!ErrorPlugin.hasInitd) { return; } @@ -48,7 +48,7 @@ export default class ErrorPlugin implements PageSpyPlugin { } } - private unhandledRejectionHandler(evt: { reason: string }) { + public unhandledRejectionHandler(evt: { reason: string }) { if (!ErrorPlugin.hasInitd) { return; } @@ -58,14 +58,14 @@ export default class ErrorPlugin implements PageSpyPlugin { }); } - private onUncaughtError() { + public onUncaughtError() { const mp = getMPSDK(); if (mp.canIUse('onError')) { mp.onError(this.errorHandler); } } - private onUnhandledRejectionError() { + public onUnhandledRejectionError() { const mp = getMPSDK(); // Promise unhandledRejection Error if (mp.canIUse('onUnhandledRejection')) { diff --git a/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts b/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts index 687f9b6b..ee6987f2 100644 --- a/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts +++ b/packages/page-spy-mp-base/src/plugins/network/proxy/request.ts @@ -10,7 +10,7 @@ import { getMPSDK } from '../../../utils'; import MPNetworkProxyBase from './base'; export default class MPWeixinRequestProxy extends MPNetworkProxyBase { - private request: MPNetworkAPI['request'] | null = null; + public request: MPNetworkAPI['request'] | null = null; constructor() { super(); @@ -26,7 +26,7 @@ export default class MPWeixinRequestProxy extends MPNetworkProxyBase { } } - private initProxyHandler() { + public initProxyHandler() { const that = this; const mp = getMPSDK(); const originRequest = mp.request; diff --git a/packages/page-spy-mp-base/src/plugins/storage.ts b/packages/page-spy-mp-base/src/plugins/storage.ts index af06146f..87c2b3d0 100644 --- a/packages/page-spy-mp-base/src/plugins/storage.ts +++ b/packages/page-spy-mp-base/src/plugins/storage.ts @@ -27,7 +27,7 @@ export default class StoragePlugin implements PageSpyPlugin { public static hasInitd = false; - private static originFunctions = {} as MPStorageAPI; + public static originFunctions = {} as MPStorageAPI; // eslint-disable-next-line class-methods-use-this public onInit() { @@ -72,7 +72,7 @@ export default class StoragePlugin implements PageSpyPlugin { } /* c8 ignore start */ - private static listenRefreshEvent() { + public static listenRefreshEvent() { socketStore.addListener('refresh', async ({ source }) => { const { data: storageType } = source; if (storageType === 'mpStorage') { @@ -82,7 +82,7 @@ export default class StoragePlugin implements PageSpyPlugin { } /* c8 ignore stop */ - private static initStorageProxy() { + public static initStorageProxy() { const mp = getMPSDK(); const { sendClearItem, sendRemoveItem, sendSetItem } = StoragePlugin; const proxyFunctions = [ @@ -237,7 +237,7 @@ export default class StoragePlugin implements PageSpyPlugin { } } - private static sendSetItem(key: string, value: any) { + public static sendSetItem(key: string, value: any) { StoragePlugin.sendStorageItem({ type: 'mpStorage', action: 'set', @@ -246,7 +246,7 @@ export default class StoragePlugin implements PageSpyPlugin { } as SpyStorage.SetTypeDataItem); } - private static sendRemoveItem(key: string) { + public static sendRemoveItem(key: string) { StoragePlugin.sendStorageItem({ type: 'mpStorage', action: 'remove', @@ -254,14 +254,14 @@ export default class StoragePlugin implements PageSpyPlugin { } as SpyStorage.RemoveTypeDataItem); } - private static sendClearItem() { + public static sendClearItem() { StoragePlugin.sendStorageItem({ type: 'mpStorage', action: 'clear', } as SpyStorage.ClearTypeDataItem); } - private static sendStorageItem(info: Omit) { + public static sendStorageItem(info: Omit) { const data = makeMessage('storage', info); socketStore.dispatchEvent('public-data', data); // The user wouldn't want to get the stale data, so here we set the 2nd parameter to true. diff --git a/packages/page-spy-mp-base/src/plugins/system.ts b/packages/page-spy-mp-base/src/plugins/system.ts index b61137ef..4b2996d2 100644 --- a/packages/page-spy-mp-base/src/plugins/system.ts +++ b/packages/page-spy-mp-base/src/plugins/system.ts @@ -26,7 +26,7 @@ export default class SystemPlugin implements PageSpyPlugin { SystemPlugin.hasInitd = false; } - private static getSystemInfo() { + public static getSystemInfo() { const deviceInfo = Client.info; const msg = makeMessage('system', { system: { diff --git a/packages/page-spy-plugin-mp-eval/src/index.ts b/packages/page-spy-plugin-mp-eval/src/index.ts index 2f52d781..961912a4 100644 --- a/packages/page-spy-plugin-mp-eval/src/index.ts +++ b/packages/page-spy-plugin-mp-eval/src/index.ts @@ -43,7 +43,7 @@ export default class MPEvalPlugin implements PageSpyPlugin { } // run executable code which received from remote and send back the result - private static handleDebugger( + public static handleDebugger( { source, }: SpyBase.InteractiveEvent<{ diff --git a/packages/page-spy-plugin-rn-async-storage/src/index.ts b/packages/page-spy-plugin-rn-async-storage/src/index.ts index e8c48d2a..914a4fc5 100644 --- a/packages/page-spy-plugin-rn-async-storage/src/index.ts +++ b/packages/page-spy-plugin-rn-async-storage/src/index.ts @@ -17,9 +17,9 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { public static hasInitd = false; - private static originFunctions = {} as typeof AsyncStorage; + public static originFunctions = {} as typeof AsyncStorage; - private static socketStore: SpyBase.SocketStoreType | null = null; + public static socketStore: SpyBase.SocketStoreType | null = null; // eslint-disable-next-line class-methods-use-this public onInit(params: OnInitParams) { @@ -68,7 +68,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { } /* c8 ignore start */ - private static listenRefreshEvent() { + public static listenRefreshEvent() { RNAsyncStoragePlugin.socketStore?.addListener( 'refresh', async ({ source }) => { @@ -81,7 +81,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { } /* c8 ignore stop */ - private static initStorageProxy() { + public static initStorageProxy() { const { sendClearItem, sendRemoveItem, sendSetItem } = RNAsyncStoragePlugin; const proxyFunctions = [ 'setItem', @@ -199,7 +199,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { }); } - private static sendSetItem(key: string, value: string) { + public static sendSetItem(key: string, value: string) { RNAsyncStoragePlugin.sendStorageItem({ type: 'asyncStorage', action: 'set', @@ -208,7 +208,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { } as SpyStorage.SetTypeDataItem); } - private static sendRemoveItem(key: string) { + public static sendRemoveItem(key: string) { RNAsyncStoragePlugin.sendStorageItem({ type: 'asyncStorage', action: 'remove', @@ -216,14 +216,14 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin { } as SpyStorage.RemoveTypeDataItem); } - private static sendClearItem() { + public static sendClearItem() { RNAsyncStoragePlugin.sendStorageItem({ type: 'asyncStorage', action: 'clear', } as SpyStorage.ClearTypeDataItem); } - private static sendStorageItem(info: Omit) { + public static sendStorageItem(info: Omit) { const data = makeMessage('storage', info); RNAsyncStoragePlugin.socketStore?.dispatchEvent('public-data', data); // The user wouldn't want to get the stale data, so here we set the 2nd parameter to true. diff --git a/packages/page-spy-react-native/src/helpers/socket.ts b/packages/page-spy-react-native/src/helpers/socket.ts index e7c9963a..80f9deb2 100644 --- a/packages/page-spy-react-native/src/helpers/socket.ts +++ b/packages/page-spy-react-native/src/helpers/socket.ts @@ -15,7 +15,7 @@ import { SpyBase } from '@huolala-tech/page-spy-types'; import { InitConfig } from '../config'; export class RNWebSocketWrapper extends SocketWrapper { - private socketInstance: WebSocket | null = null; + public socketInstance: WebSocket | null = null; init(url: string) { this.socketInstance = new WebSocket(url); @@ -88,7 +88,7 @@ export class RNWebSocketStore extends SocketStoreBase { } // run executable code which received from remote and send back the result - private static handleDebugger( + public static handleDebugger( { source }: SpyBase.InteractiveEvent, reply: (data: any) => void, ) { diff --git a/packages/page-spy-react-native/src/plugins/console.ts b/packages/page-spy-react-native/src/plugins/console.ts index 70b5c078..ba1ad1e5 100644 --- a/packages/page-spy-react-native/src/plugins/console.ts +++ b/packages/page-spy-react-native/src/plugins/console.ts @@ -5,11 +5,11 @@ import socketStore from '../helpers/socket'; export default class ConsolePlugin implements PageSpyPlugin { public name: string = 'ConsolePlugin'; - private console: Record = {}; + public console: Record = {}; public static hasInitd = false; - private proxyTypes: SpyConsole.ProxyType[] = [ + public proxyTypes: SpyConsole.ProxyType[] = [ 'log', 'info', 'error', @@ -49,7 +49,7 @@ export default class ConsolePlugin implements PageSpyPlugin { ConsolePlugin.hasInitd = false; } - private printLog(data: SpyConsole.DataItem) { + public printLog(data: SpyConsole.DataItem) { if (data.logs && data.logs.length) { this.console[data.logType](...data.logs); // eslint-disable-next-line no-param-reassign diff --git a/packages/page-spy-react-native/src/plugins/error.ts b/packages/page-spy-react-native/src/plugins/error.ts index 4d47f512..cc3f4959 100644 --- a/packages/page-spy-react-native/src/plugins/error.ts +++ b/packages/page-spy-react-native/src/plugins/error.ts @@ -16,9 +16,9 @@ export default class ErrorPlugin implements PageSpyPlugin { public static hasInitd = false; - private originHandler: ErrorHandlerCallback | null = null; + public originHandler: ErrorHandlerCallback | null = null; - private originPromise: Promise | null = null; + public originPromise: Promise | null = null; public onInit() { if (ErrorPlugin.hasInitd) return; @@ -27,7 +27,7 @@ export default class ErrorPlugin implements PageSpyPlugin { this.onUnhandledRejectionError(); } - private onUncaughtError() { + public onUncaughtError() { const originHandler = ErrorUtils.getGlobalHandler(); if (originHandler) { this.originHandler = originHandler; @@ -41,7 +41,7 @@ export default class ErrorPlugin implements PageSpyPlugin { }); } - private onUnhandledRejectionError() { + public onUnhandledRejectionError() { if (!ErrorPlugin.hasInitd) { return; } @@ -66,7 +66,7 @@ export default class ErrorPlugin implements PageSpyPlugin { // }); } - private errorHandler(error: Error) { + public errorHandler(error: Error) { if (!ErrorPlugin.hasInitd) { return; } diff --git a/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts b/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts index f5cd198f..ae716277 100644 --- a/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts +++ b/packages/page-spy-react-native/src/plugins/network/proxy/fetch-proxy.ts @@ -16,7 +16,7 @@ import RNNetworkProxyBase from './base'; import { IS_FETCH_HEADER } from './xhr-proxy'; export default class FetchProxy extends RNNetworkProxyBase { - private fetch: WindowOrWorkerGlobalScope['fetch'] | null = null; + public fetch: WindowOrWorkerGlobalScope['fetch'] | null = null; constructor() { super(); @@ -29,7 +29,7 @@ export default class FetchProxy extends RNNetworkProxyBase { } } - private initProxyHandler() { + public initProxyHandler() { const that = this; const originFetch = globalThis.fetch; diff --git a/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts b/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts index 1c601d89..d51730fd 100644 --- a/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts +++ b/packages/page-spy-react-native/src/plugins/network/proxy/xhr-proxy.ts @@ -38,18 +38,18 @@ declare global { } } class XhrProxy extends RNNetworkProxyBase { - private xhrOpen: XMLHttpRequest['open'] | null = null; + public xhrOpen: XMLHttpRequest['open'] | null = null; - private xhrSend: XMLHttpRequest['send'] | null = null; + public xhrSend: XMLHttpRequest['send'] | null = null; - private xhrSetRequestHeader: XMLHttpRequest['setRequestHeader'] | null = null; + public xhrSetRequestHeader: XMLHttpRequest['setRequestHeader'] | null = null; public constructor() { super(); this.initProxyHandler(); } - private initProxyHandler() { + public initProxyHandler() { const that = this; const { open, send, setRequestHeader } = XMLHttpRequest.prototype; this.xhrOpen = open; @@ -230,7 +230,7 @@ class XhrProxy extends RNNetworkProxyBase { } // eslint-disable-next-line class-methods-use-this - private async formatResponse( + public async formatResponse( XMLReq: XMLHttpRequest, type: XMLHttpRequestResponseType, ) { diff --git a/packages/page-spy-react-native/src/plugins/system.ts b/packages/page-spy-react-native/src/plugins/system.ts index a080bea5..df9978de 100644 --- a/packages/page-spy-react-native/src/plugins/system.ts +++ b/packages/page-spy-react-native/src/plugins/system.ts @@ -27,7 +27,7 @@ export default class SystemPlugin implements PageSpyPlugin { SystemPlugin.hasInitd = false; } - private static getSystemInfo() { + public static getSystemInfo() { const msg = makeMessage('system', { system: { ua: combineName(Client.info),