Skip to content

Commit deefacd

Browse files
authored
Merge pull request #349 from netease-lcap/merge/test_2026_03_23
Merge/test
2 parents 52017d3 + 6e92c5b commit deefacd

42 files changed

Lines changed: 2320 additions & 432 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

packages/basic/build/rollup.config.mjs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import resolve from '@rollup/plugin-node-resolve';
22
import typescript from '@rollup/plugin-typescript';
33
import json from '@rollup/plugin-json';
44
import commonjs from '@rollup/plugin-commonjs';
5-
import nodePolyfills from 'rollup-plugin-polyfill-node';
5+
import { visualizer } from 'rollup-plugin-visualizer';
6+
import terser from '@rollup/plugin-terser';
7+
import isCI from 'is-ci';
68

79
export default {
810
input: 'src/index.ts',
@@ -22,10 +24,27 @@ export default {
2224
plugins: [
2325
resolve({
2426
extensions: ['.ts', '.js', '.json'],
27+
browser: true,
28+
preferBuiltins: false,
2529
}),
2630
json(),
2731
commonjs(),
2832
typescript(),
29-
nodePolyfills(),
30-
],
33+
terser({
34+
compress: {
35+
drop_console: false,
36+
pure_funcs: [],
37+
},
38+
mangle: false, // 禁用变量名混淆,避免对已压缩代码的二次混淆问题
39+
format: {
40+
comments: false,
41+
},
42+
}),
43+
!isCI && visualizer({
44+
filename: 'dist/stats.html',
45+
open: false,
46+
gzipSize: true,
47+
brotliSize: true,
48+
}),
49+
].filter(Boolean),
3150
};

packages/basic/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,22 @@
4747
"@rollup/plugin-commonjs": "^26.0.1",
4848
"@rollup/plugin-json": "^6.1.0",
4949
"@rollup/plugin-node-resolve": "^15.2.3",
50+
"@rollup/plugin-terser": "^0.4.4",
5051
"@rollup/plugin-typescript": "^11.1.6",
5152
"@types/jest": "^29.5.12",
5253
"@types/lodash": "^4.17.13",
5354
"@types/node": "^20.11.16",
5455
"@types/safe-json-stringify": "^1.1.5",
5556
"fast-check": "^3.14.0",
57+
"is-ci": "^4.1.0",
5658
"jest": "^29.7.0",
5759
"jest-environment-jsdom": "^29.7.0",
5860
"jest-watch-typeahead": "^2.2.2",
5961
"minimist": "^1.2.8",
6062
"nodemon": "^3.0.3",
6163
"rollup": "^4.19.1",
6264
"rollup-plugin-polyfill-node": "^0.13.0",
65+
"rollup-plugin-visualizer": "^6.0.5",
6366
"ts-jest": "^29.1.1",
6467
"typedoc": "^0.26.11",
6568
"typescript": "^5.3.3",

packages/basic/src/global.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import _set from 'lodash/set';
2-
31
// 用来mock Vue的构造函数
42
// @ts-ignore
53
const GlobalFn = typeof window.Vue === 'function' ? window.Vue : function MockVue() {};

packages/basic/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as _ from 'lodash';
12
import Config, { setConfig } from './config';
23

34
export * from './apis';
@@ -8,6 +9,6 @@ export * from './router';
89

910
import Global, { global } from './global';
1011

11-
export { Config, setConfig, Global, global };
12+
export { Config, setConfig, Global, global, _ };
1213

1314
export * from './utils';
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { sortBy } from "lodash";
2-
import { genSortedTypeKey, getTypeDefinition } from "./tools";
1+
import { sortBy } from 'lodash';
2+
import { genSortedTypeKey, getTypeDefinition } from './tools';
33

44
/**
55
* 根据如下优先级排序类型:Enum Reference > Primitives > Tagged References > Entity > Structure > AnonymousStructure > Map > List
@@ -9,17 +9,17 @@ import { genSortedTypeKey, getTypeDefinition } from "./tools";
99
export function sortTypeArgumentsBasedOnTypePriority(typeArguments: TypeAnnotation[]): TypeAnnotation[] {
1010
const firstPass = sortBy(typeArguments, (arg) => {
1111
// 应用优先级排序规则 Primitives > Tagged References > Entity > Structure > AnonymousStructure > Map > List
12-
const typeKindListOrderedByPriority = ["primitive", "reference", "anonymousStructure", "generic"] as const;
13-
if (arg.typeKind === "union") {
14-
throw new Error("Union类型的typeArguments不能再为union");
12+
const typeKindListOrderedByPriority = ['primitive', 'reference', 'anonymousStructure', 'generic'] as const;
13+
if (arg.typeKind === 'union') {
14+
throw new Error('Union类型的typeArguments不能再为union');
1515
}
1616
const priority = typeKindListOrderedByPriority.indexOf(arg.typeKind);
1717
return [priority, isTaggedReferenceType(arg) ? 0 : 1, isEntityReferenceType(arg) ? 0 : 1];
1818
});
1919
const secondPass = sortBy(firstPass, (arg) => {
2020
// 应用优先级排序规则:Enum Reference > Others
2121
const argTypeDef = getTypeDefinition(genSortedTypeKey(arg));
22-
if (argTypeDef?.concept === "Enum") {
22+
if (argTypeDef?.concept === 'Enum') {
2323
return 0;
2424
}
2525
return 1;
@@ -30,16 +30,16 @@ export function sortTypeArgumentsBasedOnTypePriority(typeArguments: TypeAnnotati
3030
// @ts-expect-error FIXME
3131
const properties = getTypeDefinition(genSortedTypeKey(typeAnnotation))?.properties;
3232
return (
33-
typeAnnotation.typeKind === "reference" &&
34-
properties?.filter((prop) => prop.name === "errorType" && prop.expression?.concept === "StringLiteral")
33+
typeAnnotation.typeKind === 'reference' &&
34+
properties?.filter((prop) => prop.name === 'errorType' && prop.expression?.concept === 'StringLiteral')
3535
);
3636
}
3737

3838
function isEntityReferenceType(typeAnnotation: TypeAnnotation): boolean {
3939
return (
40-
typeAnnotation.typeKind === "reference" &&
40+
typeAnnotation.typeKind === 'reference' &&
4141
// @ts-expect-error FIXME
42-
getTypeDefinition(genSortedTypeKey(typeAnnotation))?.concept === "Entity"
42+
getTypeDefinition(genSortedTypeKey(typeAnnotation))?.concept === 'Entity'
4343
);
4444
}
4545
}

packages/basic/src/init/service/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import isPlainObject from "lodash/isPlainObject";
1+
import { isPlainObject } from 'lodash';
22

3-
import { createService } from "../../utils";
4-
import Global from "../../global";
5-
import Config from "../../config";
3+
import { createService } from '../../utils';
4+
import Global from '../../global';
5+
import Config from '../../config';
66

77
let $services;
88

@@ -16,7 +16,7 @@ function initService(
1616

1717
keys.forEach((key) => {
1818
if ($services && $services[key]) {
19-
throw new Error("services repeat:" + key);
19+
throw new Error('services repeat:' + key);
2020
}
2121

2222
const service = services[key];
@@ -27,9 +27,9 @@ function initService(
2727
});
2828

2929
if (keys.length) {
30-
$services = Object.assign({}, Config.globalProperties.get("$services"), services);
30+
$services = Object.assign({}, Config.globalProperties.get('$services'), services);
3131

32-
Config.globalProperties.set("$services", $services);
32+
Config.globalProperties.set('$services', $services);
3333
}
3434

3535
return {

packages/basic/src/sdk/modules/utils.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
isSunday,
4040
} from 'date-fns';
4141
import { formatInTimeZone } from 'date-fns-tz';
42-
import { isObject, isEqual, set, cloneDeep } from 'lodash';
42+
import { isObject, set, isEqual, cloneDeep } from 'lodash';
4343
import Decimal from 'decimal.js';
4444
import {
4545
isInputValidNaslDateTime,
@@ -71,7 +71,14 @@ export class Utils {
7171
this.helpers = optinos;
7272
}
7373

74-
private isArrayInBounds<T>(arr: T[], index: number): boolean {
74+
/**
75+
* 判断数组访问是否越界
76+
* @param arr
77+
* @param index
78+
* @param boundaryChecker
79+
* @returns
80+
*/
81+
private isArrayInBounds<T>(arr: T[], index: number, boundaryChecker?: (index: number, arr: T[]) => boolean): boolean {
7582
if (!Array.isArray(arr)) {
7683
this.helpers.throwError('传入内容不是数组');
7784
return false;
@@ -82,7 +89,10 @@ export class Utils {
8289
return false;
8390
}
8491

85-
if (index < 0 || index >= arr.length) {
92+
const defaultBoundaryChecker = (idx: number, array: T[]) => idx >= 0 && idx < array.length;
93+
const checker = boundaryChecker ?? defaultBoundaryChecker;
94+
95+
if (!checker(index, arr)) {
8696
this.helpers.throwError(`列表访问越界,访问下标 ${index},列表长度 ${arr.length}`);
8797
return false;
8898
}
@@ -316,7 +326,8 @@ export class Utils {
316326
}
317327

318328
Insert<T>(arr: T[], index: number, item: T) {
319-
if (this.isArrayInBounds(arr, index)) {
329+
const boundaryChecker = (idx: number, array: T[]) => idx >= 0 && idx <= array.length;
330+
if (this.isArrayInBounds(arr, index, boundaryChecker)) {
320331
arr.splice(index, 0, item);
321332
}
322333
}
@@ -889,16 +900,16 @@ export class Utils {
889900
}
890901

891902
AddDays(date = new Date(), amount = 1, converter = 'json') {
892-
return toValue(addDays(safeNewDate(date), amount), converter);
903+
return toValue.call(this, addDays(safeNewDate(date), amount), converter);
893904
}
894905

895906
AddMonths(date = new Date(), amount = 1, converter = 'json') {
896907
/** 传入的值为标准的时间格式 */
897-
return toValue(addMonths(safeNewDate(date), amount), converter);
908+
return toValue.call(this, addMonths(safeNewDate(date), amount), converter);
898909
}
899910

900911
SubDays(date = new Date(), amount = 1, converter = 'json') {
901-
return toValue(subDays(safeNewDate(date), amount), converter);
912+
return toValue.call(this, subDays(safeNewDate(date), amount), converter);
902913
}
903914

904915
// 兼容性策略:老应用升级到 3.10,保持老行为不变

packages/basic/src/utils/create/add.configs.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import camelCase from 'lodash/camelCase';
2-
import upperFirst from 'lodash/upperFirst';
3-
import lowerFirst from 'lodash/lowerFirst';
1+
import { camelCase, upperFirst, lowerFirst } from 'lodash';
2+
43
import errHandles from './errHandles';
54

65
export const isPromise = function (func) {

packages/basic/src/utils/create/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios';
22
import type { AxiosRequestConfig, Method } from 'axios';
3-
import pick from 'lodash/pick';
3+
import { pick } from 'lodash';
44

55
import Service from '../request-pre';
66
import { formatMicroFrontUrl } from '../../init/router/microFrontUrl'; // 微前端路由方法

packages/basic/src/utils/create/interceptors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import isPlainObject from "lodash/isPlainObject";
2-
import { stringifyWithLoopProtection } from "./utils";
1+
import { isPlainObject } from 'lodash';
2+
import { stringifyWithLoopProtection } from './utils';
33

44
const interceptors: Array<{
55
request?: {
@@ -21,7 +21,7 @@ const loopProtection = (config) => {
2121
}
2222
}
2323
} catch (e) {
24-
console.warn("loopProtection json control error");
24+
console.warn('loopProtection json control error');
2525
}
2626

2727
return config;

0 commit comments

Comments
 (0)