Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade the build process #100

Merged
merged 13 commits into from
Jul 10, 2024
43 changes: 31 additions & 12 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import type { Config } from 'jest';
import { pathsToModuleNameMapper } from 'ts-jest';
import tsConfig from './tsconfig.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: '<rootDir>/',
}),
'\\.(css|less|svg|png|jpg)$':
Expand All @@ -16,9 +32,10 @@ const moduleNameMapper = {
* - moduleNameMapper
* - testMatch
* - preset
* - transform
*/

const config: Config = {
const config: JestConfigWithTsJest = {
collectCoverageFrom: [
'packages/**/*.ts',
'!packages/**/*.d.ts',
Expand All @@ -34,34 +51,36 @@ const config: Config = {
name: 'Base',
color: 'cyanBright',
},
preset: 'ts-jest',
testEnvironment: 'jsdom',
testMatch: ['**/packages/base/tests/**/*.test.ts'],
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: [
'<rootDir>/packages/page-spy-browser/tests/setup.ts',
'jest-canvas-mock',
],
moduleNameMapper,
transform,
},
{
displayName: {
name: 'MPBase',
color: 'green',
},
preset: 'ts-jest',
testMatch: ['**/packages/mp-base/tests/**/*.test.ts'],
testMatch: ['**/packages/page-spy-mp-base/tests/**/*.test.ts'],
setupFilesAfterEnv: [
'<rootDir>/packages/page-spy-mp-base/tests/setup.ts',
],
moduleNameMapper,
setupFilesAfterEnv: ['<rootDir>/packages/mp-base/tests/setup.ts'],
transform,
},
],
};
Expand Down
8 changes: 0 additions & 8 deletions packages/base/package.json

This file was deleted.

6 changes: 0 additions & 6 deletions packages/mp-base/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions packages/mp-base/yarn.lock

This file was deleted.

17 changes: 6 additions & 11 deletions packages/page-spy-alipay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
"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": {
"type": "git",
"url": "https://github.com/HuolalaTech/page-spy"
"url": "git+https://github.com/HuolalaTech/page-spy.git"
},
"keywords": [
"pagespy",
Expand All @@ -31,28 +30,24 @@
},
"dependencies": {
"@babel/runtime": "^7.13.0",
"@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",
"@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",
"@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": {
Expand Down
20 changes: 1 addition & 19 deletions packages/page-spy-alipay/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -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/**/*.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(),
];

Expand Down
8 changes: 3 additions & 5 deletions packages/page-spy-alipay/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
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 { SpyClient } from 'packages/page-spy-types';
import PageSpy, { setMPSDK, utilAPI } from '@huolala-tech/page-spy-mp-base';
import { Client, SocketStoreBase } from '@huolala-tech/page-spy-base';
import { SpyClient } from '@huolala-tech/page-spy-types';

// reassign the global.mp to uni

Expand Down
9 changes: 9 additions & 0 deletions packages/page-spy-alipay/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "dist",
"declarationDir": "dist/types"
},
"include": ["src"]
}
15 changes: 0 additions & 15 deletions packages/page-spy-alipay/types/index.d.ts

This file was deleted.

38 changes: 38 additions & 0 deletions packages/page-spy-base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@huolala-tech/page-spy-base",
"version": "1.0.0",
"description": "The common utils of PageSpy.",
"dependencies": {
"@huolala-tech/page-spy-types": "^1.9.0"
},
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"build": "yarn clean && tsc",
"clean": "rm -rf ./dist"
},
"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"
],
"keywords": [
"pagespy",
"debug",
"remote",
"inspect",
"devtools",
"reactnative"
]
}
14 changes: 7 additions & 7 deletions packages/base/src/atom.ts → packages/page-spy-base/src/atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import {
isPlainObject,
isPrototype,
makePrimitiveValue,
} from './index';
} from './utils';

export class Atom {
private store: Record<string, any> = {};
public store: Record<string, any> = {};

public getStore() {
return this.store;
Expand All @@ -24,7 +24,7 @@ export class Atom {
}

// { __atomId: instanceId }
private instanceStore: Record<string, string> = {};
public instanceStore: Record<string, string> = {};

public getInstanceStore() {
return this.instanceStore;
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Atom {
return Atom.getAtomOverview({ atomId: id, value: name, instanceId });
}

private static getAtomOverview({
public static getAtomOverview({
instanceId = '',
atomId,
value,
Expand All @@ -112,7 +112,7 @@ export class Atom {
};
}

private static getSemanticValue(data: any) {
public static getSemanticValue(data: any) {
if (isPlainObject(data)) {
return 'Object {...}';
}
Expand All @@ -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<string, any> = {};
Expand Down Expand Up @@ -172,4 +172,4 @@ export class Atom {
}
}

export default new Atom();
export const atom = new Atom();
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions packages/page-spy-base/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
@@ -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<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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<string, RequestItem | null>;
export default class NetworkProxyBase {
private reqMap: RequestStore = Object.create(null);
export class NetworkProxyBase {
public reqMap: RequestStore = Object.create(null);

constructor(private socketStore: SocketStoreBase) {}
constructor(public socketStore: SocketStoreBase) {}

public getRequestMap() {
return this.reqMap;
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class NetworkProxyBase {
}
}

private deferDeleteRequest(id: string) {
public deferDeleteRequest(id: string) {
const req = this.getRequest(id);
if (req && req.readyState === ReqReadyState.DONE) {
setTimeout(() => {
Expand Down
Loading
Loading