gio-miniprogram-sdk 4.4.2 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +13 -11
  2. package/dist/alipay.js +1 -1
  3. package/dist/baidu.js +1 -1
  4. package/dist/bytedance.js +1 -1
  5. package/dist/jingdong.js +1 -1
  6. package/dist/kuaishou.js +1 -1
  7. package/dist/mpx.js +1 -0
  8. package/dist/plugins/gioABTest.js +1 -1
  9. package/dist/plugins/gioCompress.js +1 -1
  10. package/dist/plugins/gioEventAutoTracking.js +1 -1
  11. package/dist/plugins/gioImpressionTracking.js +1 -1
  12. package/dist/plugins/gioMultipleInstances.js +1 -1
  13. package/dist/plugins/gioPerformance.js +1 -1
  14. package/dist/qq.js +1 -1
  15. package/dist/quickapp.js +1 -1
  16. package/dist/taobao.js +1 -1
  17. package/dist/taro.js +1 -1
  18. package/dist/uniapp.js +1 -1
  19. package/dist/wechat.js +1 -1
  20. package/dist/xiaohongshu.js +1 -1
  21. package/package.json +13 -2
  22. package/.eslintignore +0 -11
  23. package/.eslintrc.js +0 -120
  24. package/.github/workflows/greetings.yml +0 -13
  25. package/.github/workflows/publish.yml +0 -45
  26. package/.prettierignore +0 -19
  27. package/.prettierrc.js +0 -9
  28. package/babel.config.js +0 -6
  29. package/rollup.config.js +0 -100
  30. package/rollup.plugins.config.js +0 -84
  31. package/src/adapters/gioTaobaoAdapter.ts +0 -202
  32. package/src/adapters/gioTaroAdapter.ts +0 -467
  33. package/src/adapters/gioUniAppAdapter.ts +0 -431
  34. package/src/constants/config.ts +0 -170
  35. package/src/constants/emitMsg.ts +0 -24
  36. package/src/constants/regex.ts +0 -18
  37. package/src/core/dataStore/eventContextBuilder.ts +0 -95
  38. package/src/core/dataStore/eventHooks/appEffects.ts +0 -218
  39. package/src/core/dataStore/eventHooks/index.ts +0 -468
  40. package/src/core/dataStore/eventHooks/minipPage.ts +0 -221
  41. package/src/core/dataStore/eventHooks/pageEffects.ts +0 -189
  42. package/src/core/dataStore/index.ts +0 -661
  43. package/src/core/growingIO.ts +0 -637
  44. package/src/core/pluginsInstance/base.ts +0 -157
  45. package/src/core/pluginsInstance/taro.ts +0 -15
  46. package/src/core/pluginsInstance/tb.ts +0 -15
  47. package/src/core/pluginsInstance/uniapp.ts +0 -15
  48. package/src/core/uploader.ts +0 -272
  49. package/src/core/userStore.ts +0 -267
  50. package/src/index.ts +0 -77
  51. package/src/minipInstance/base.ts +0 -352
  52. package/src/minipInstance/framework.ts +0 -24
  53. package/src/minipInstance/jd.ts +0 -11
  54. package/src/minipInstance/ks.ts +0 -12
  55. package/src/minipInstance/my.ts +0 -131
  56. package/src/minipInstance/qq.ts +0 -12
  57. package/src/minipInstance/quickapp.ts +0 -233
  58. package/src/minipInstance/swan.ts +0 -20
  59. package/src/minipInstance/tb.ts +0 -58
  60. package/src/minipInstance/tt.ts +0 -12
  61. package/src/minipInstance/wx.ts +0 -27
  62. package/src/minipInstance/xhs.ts +0 -20
  63. package/src/platformConfig/base.ts +0 -82
  64. package/src/platformConfig/framework.ts +0 -31
  65. package/src/platformConfig/jd.ts +0 -11
  66. package/src/platformConfig/ks.ts +0 -11
  67. package/src/platformConfig/my.ts +0 -16
  68. package/src/platformConfig/qq.ts +0 -13
  69. package/src/platformConfig/quickapp.ts +0 -48
  70. package/src/platformConfig/swan.ts +0 -11
  71. package/src/platformConfig/tb.ts +0 -29
  72. package/src/platformConfig/tt.ts +0 -11
  73. package/src/platformConfig/wx.ts +0 -20
  74. package/src/platformConfig/xhs.ts +0 -27
  75. package/src/plugins/gioABTest.ts +0 -348
  76. package/src/plugins/gioCompress.ts +0 -253
  77. package/src/plugins/gioEventAutoTracking.ts +0 -310
  78. package/src/plugins/gioImpressionTracking.ts +0 -386
  79. package/src/plugins/gioMultipleInstances.ts +0 -189
  80. package/src/plugins/gioPerformance/exception.ts +0 -152
  81. package/src/plugins/gioPerformance/monitor.ts +0 -284
  82. package/src/plugins/gioPerformance/network.ts +0 -197
  83. package/src/plugins/gioPerformance.ts +0 -131
  84. package/src/types/base.ts +0 -167
  85. package/src/types/dataStore.ts +0 -62
  86. package/src/types/eventHooks.ts +0 -146
  87. package/src/types/gioCustomTracking.ts +0 -9
  88. package/src/types/gioEventTracking.ts +0 -10
  89. package/src/types/gioPerformance.ts +0 -8
  90. package/src/types/growingIO.ts +0 -137
  91. package/src/types/minipInstance.ts +0 -133
  92. package/src/types/platforms.ts +0 -64
  93. package/src/types/plugins.ts +0 -24
  94. package/src/types/uploader.ts +0 -30
  95. package/src/types/userStore.ts +0 -28
  96. package/src/utils/glodash.ts +0 -430
  97. package/src/utils/tools.ts +0 -511
  98. package/src/utils/verifiers.ts +0 -52
  99. package/tsconfig.json +0 -32
  100. package/typings/global.d.ts +0 -105
@@ -1,467 +0,0 @@
1
- /**
2
- * 名称:Taro代理插件
3
- * 用途:用于重写Taro框架下的创建App/Page/Component方法实现代理Hook;并获取Taro框架下的自定义方法真实方法名获取。
4
- * 注意:测试taro3react时,微信要用react18测试,支付宝要用react17测试。
5
- */
6
- import {
7
- TARO_EVENT_PROPS_REG,
8
- TARO_EVENT_REACT_FUNC1_REG,
9
- TARO_EVENT_REACT_FUNC2_REG,
10
- TARO_EVENT_VUE_FUNC1_REG,
11
- TARO_EVENT_VUE_FUNC2_REG,
12
- TARO_EVENT_VUE_FUNC3_REG
13
- } from '@@/constants/regex';
14
- import { GrowingIOType } from '@@/types/growingIO';
15
- import EMIT_MSG from '@@/constants/emitMsg';
16
-
17
- let ut;
18
- const HANDLER = {
19
- tap: 'onClick',
20
- longpress: 'onLongPress'
21
- };
22
- const CUSTOM_HOOK_EVENTS = [
23
- 'onShareAppMessage',
24
- 'onShareTimeline',
25
- 'onAddToFavorites',
26
- 'onTabItemTap'
27
- ];
28
- class GioTaroAdapter {
29
- public pluginVersion: string;
30
- public taroVersion: string;
31
- private taro: any;
32
- private taroVue: any;
33
- private taroVueVersion: number;
34
- private exposedNames: any;
35
- private inAppLifecycle: boolean;
36
- constructor(public growingIO: GrowingIOType) {
37
- this.pluginVersion = '__PLUGIN_VERSION__';
38
- const { utils, emitter, minipInstance } = this.growingIO;
39
- ut = utils;
40
- this.exposedNames = {};
41
- this.inAppLifecycle = true;
42
- emitter.on(EMIT_MSG.MINIP_LIFECYCLE, ({ event }) => {
43
- if (['Page onShow', 'Page onReady'].includes(event)) {
44
- if (this.taro && this.taroVersion === '3') {
45
- // 提前存储页面节点信息用来获取dataset
46
- this.saveFullPage(document.body);
47
- // taro3开发时要等onready才能取到节点,所以补充做一次曝光监听
48
- setTimeout(
49
- () => minipInstance.initImpression(minipInstance.getCurrentPage()),
50
- 0
51
- );
52
- }
53
- }
54
- });
55
- }
56
-
57
- // 主入口,版本判断
58
- main = () => {
59
- const { taro, taroVue } = this.growingIO.vdsConfig;
60
- const { Current, createComponent } = taro;
61
- const isTaro2 = !Current && createComponent;
62
- const isTaro3 = Current && !createComponent;
63
- this.taro = taro;
64
- if (isTaro2) {
65
- // taro2
66
- this.taroVersion = '2';
67
- this.proxyTaro2(this.taro);
68
- ut.consoleText('Taro version 2', 'info');
69
- } else if (isTaro3) {
70
- // taro3
71
- this.taroVersion = '3';
72
- this.taroVue = taroVue;
73
- if (this.taroVue) {
74
- const mainVersion = Number(
75
- ut.head(ut.split(this.taroVue.version, '.'))
76
- );
77
- this.taroVueVersion = mainVersion;
78
- ut.consoleText(`Taro version 3, Vue version ${mainVersion}`, 'info');
79
- } else {
80
- ut.consoleText('Taro version 3', 'info');
81
- }
82
- this.proxyTaro3();
83
- } else {
84
- ut.consoleText('未获取到Taro实例或不支持的Taro版本,请检查!', 'error');
85
- }
86
- };
87
-
88
- // 代理taro2
89
- proxyTaro2 = (taro: any) => {
90
- const self = this;
91
- const originApp = taro.createApp;
92
- const originComponent = taro.createComponent;
93
- if (originApp) {
94
- taro.createApp = function (AppClass) {
95
- const AppRef = originApp(AppClass);
96
- self.growingIO.dataStore.eventHooks.appOverriding(AppRef);
97
- return AppRef;
98
- };
99
- }
100
- if (originComponent) {
101
- taro.createComponent = function (ComponentClass, isPage) {
102
- const ComponentRef = originComponent(ComponentClass, isPage);
103
- const targetType = isPage ? 'page' : 'component';
104
- // wx/qq的生命周期函数和自定义函数都在ComponentRef.methods中
105
- // my/tt/jd的生命周期函数和自定义函数都在ComponentRef中
106
- // swan的生命周期函数在ComponentRef.methods中,自定义函数在ComponentRef中
107
- switch (self.growingIO.gioPlatform) {
108
- case 'wx':
109
- case 'qq':
110
- self.growingIO.dataStore.eventHooks[`${targetType}Overriding`](
111
- ComponentRef.methods
112
- );
113
- break;
114
- case 'my':
115
- case 'tt':
116
- case 'jd':
117
- self.growingIO.dataStore.eventHooks[`${targetType}Overriding`](
118
- ComponentRef
119
- );
120
- break;
121
- case 'swan':
122
- self.growingIO.dataStore.eventHooks[`${targetType}Overriding`](
123
- ComponentRef
124
- );
125
- self.growingIO.dataStore.eventHooks[`${targetType}Overriding`](
126
- ComponentRef.methods
127
- );
128
- break;
129
- default:
130
- break;
131
- }
132
- return ComponentRef;
133
- };
134
- }
135
- };
136
-
137
- // 代理taro3
138
- proxyTaro3 = () => {
139
- const self = this;
140
- const {
141
- dataStore: { eventHooks },
142
- minipInstance
143
- } = this.growingIO;
144
- // hook app
145
- eventHooks.nativeGrowing(['App']);
146
- // taro3vue2走单独的hook逻辑
147
- if (this.taroVueVersion === 2) {
148
- eventHooks.nativeGrowing(['Page']);
149
- this.taro3Vue2Proxy();
150
- return;
151
- }
152
- if (this.taroVueVersion === 3) {
153
- this.proxyTaro3vue3();
154
- }
155
- // taro3react / taro3vue3走监听hook逻辑
156
- const originCall = self.taro?.hooks?.call;
157
- if (originCall) {
158
- self.defineProperty(self.taro.hooks, 'call', function (...args) {
159
- const argsArray = Array.from(args);
160
- // 根据taro消息直接触发页面生命周期
161
- if (argsArray[0] === 'getLifecycle') {
162
- const lifetime = argsArray[2];
163
- if (
164
- eventHooks.pageHandlers.includes(lifetime) &&
165
- !CUSTOM_HOOK_EVENTS.includes(lifetime)
166
- ) {
167
- // hook方法也会执行第一次进入小程序时的AppOnShow导致先出发第一个页面onShow的bug。这里用一个变量标记当前的生命周期是否在App中
168
- if (lifetime === 'onLoad' && self.inAppLifecycle) {
169
- self.inAppLifecycle = false;
170
- }
171
- // 有路由地址的才是页面的生命周期(支付宝在ApponShow时也会拿到,所以要再判标记)
172
- const page = minipInstance.getCurrentPage();
173
- if (page.route && !self.inAppLifecycle) {
174
- ut.niceTry(() =>
175
- eventHooks.pageEffects.main(page, lifetime, argsArray[1])
176
- );
177
- }
178
- }
179
- }
180
- let result = originCall.apply(this, argsArray);
181
- // 分享和添加收藏事件走hook逻辑
182
- if (argsArray[0] === 'modifyPageObject') {
183
- const pageObject = argsArray[1];
184
- CUSTOM_HOOK_EVENTS.forEach((k) => {
185
- if (pageObject[k]) {
186
- pageObject[k] = eventHooks.lifeFcEffects(
187
- k,
188
- ut.isFunction(pageObject[k]) ? pageObject[k] : () => {},
189
- 'Page'
190
- );
191
- }
192
- });
193
- }
194
- // 无埋点事件
195
- if (argsArray[0] === 'dispatchTaroEvent') {
196
- const taroEvent = argsArray[1];
197
- const taroElement = argsArray[2];
198
- const actionEffects =
199
- self.growingIO.plugins?.gioEventAutoTracking?.main;
200
- if (
201
- ut.isFunction(actionEffects) &&
202
- eventHooks.actionEventTypes.includes(taroEvent.type)
203
- ) {
204
- const { currentTarget, target, detail } = taroEvent.mpEvent;
205
- // taro本身会给所有节点添加id,id一致说明是触发事件的节点
206
- if (target.id === currentTarget.id) {
207
- // 尝试获取真实的方法名
208
- try {
209
- let originHandler = ut.head(
210
- taroElement.__handlers[taroEvent.type]
211
- );
212
- // 一定要有对应的事件
213
- if (originHandler) {
214
- if (originHandler.oldHandler) {
215
- originHandler = originHandler.oldHandler;
216
- }
217
- let funcName = '';
218
- if (self.taroVue) {
219
- // vue3
220
- funcName = self.taro3vue3GetFuncName(
221
- originHandler,
222
- taroElement
223
- );
224
- } else {
225
- // react --- @tarojs/runtime 3.6.x会有一个随机名的对象存储点击事件优先获取,其他版本直接取originHandler
226
- funcName = self.taro3reactGetFuncName(
227
- originHandler,
228
- taroEvent,
229
- taroElement
230
- );
231
- }
232
-
233
- // 构建无埋点事件
234
- actionEffects(
235
- {
236
- ...taroEvent.mpEvent,
237
- currentTarget: {
238
- ...currentTarget,
239
- detail,
240
- dataset: {
241
- ...currentTarget.dataset,
242
- ...taroElement.dataset
243
- }
244
- }
245
- },
246
- funcName
247
- );
248
- }
249
- } catch (error) {
250
- ut.consoleText('Error: ' + error, 'error');
251
- }
252
- }
253
- }
254
- }
255
- return result;
256
- });
257
- } else {
258
- ut.consoleText('Taro3实例获取失败,请检查初始化逻辑!', 'warn');
259
- eventHooks.nativeGrowing(['Page']);
260
- }
261
- };
262
-
263
- // 保存vue3下使用setup写法的function component的导出方法名
264
- proxyTaro3vue3 = () => {
265
- const self = this;
266
- this.taroVue.mixin({
267
- beforeMount: function () {
268
- // 存在tid说明是页面
269
- if (this._?.props?.tid && !ut.isEmpty(this._.exposed)) {
270
- const path = ut.head(ut.split(this._.props.tid, '?'));
271
- const kvs = {};
272
- ut.keys(this._.exposed).forEach((k) => {
273
- if (this._.exposed[k].name) {
274
- kvs[this._.exposed[k].name] = k;
275
- }
276
- });
277
- self.exposedNames[path] = { ...kvs };
278
- }
279
- }
280
- });
281
- };
282
-
283
- // taro3react获取方法名
284
- taro3reactGetFuncName = (
285
- originHandler: any,
286
- taroEvent: any,
287
- taroElement: any
288
- ) => {
289
- const propsKey = ut
290
- .keys(taroElement)
291
- .find((key) => TARO_EVENT_PROPS_REG.test(key));
292
- const propsHandler =
293
- ut.niceTry(() => taroElement[propsKey][HANDLER[taroEvent.type]]) ??
294
- originHandler.oldHandler ??
295
- originHandler;
296
- if (propsHandler?.value?.name) {
297
- return propsHandler?.value?.name;
298
- } else if (
299
- propsHandler.name &&
300
- !['handler', 'invoker'].includes(propsHandler.name)
301
- ) {
302
- // class component匿名引用方法
303
- let funcName = ut
304
- .head(`${propsHandler}`.match(TARO_EVENT_REACT_FUNC1_REG))
305
- ?.replace('return ', '')
306
- ?.replace('(', '');
307
- if (funcName) {
308
- return ut.head(ut.drop(ut.split(funcName, '.'))) ?? propsHandler.name;
309
- } else {
310
- // component匿名引用方法
311
- funcName = ut
312
- .head(`${propsHandler}`.match(TARO_EVENT_REACT_FUNC2_REG))
313
- ?.replace('return ', '')
314
- ?.replace('(', '');
315
- return funcName ?? propsHandler.name;
316
- }
317
- } else {
318
- return this.getAnonymousFunc(taroElement);
319
- }
320
- };
321
-
322
- // taro3vue3获取方法名
323
- taro3vue3GetFuncName = (originHandler: any, taroElement: any) => {
324
- if (ut.startsWith(`${originHandler.value}`.replace(' ', ''), 'function(')) {
325
- // 使用emit监听组件的方法
326
- let preFuncName = ut
327
- .head(`${originHandler.value}`.match(TARO_EVENT_VUE_FUNC1_REG))
328
- ?.replace('return ', '');
329
- try {
330
- // 使用emit监听组件的方法要优先判断
331
- if (preFuncName) {
332
- // dev状态时是单引号
333
- // eslint-disable-next-line
334
- if (preFuncName.indexOf("'") > -1) {
335
- // eslint-disable-next-line
336
- preFuncName = ut.head(ut.drop(ut.split(preFuncName, "'")));
337
- } else {
338
- // build状态时是双引号
339
- preFuncName = ut.head(ut.drop(ut.split(preFuncName, '"')));
340
- }
341
- } else {
342
- // 普通引用方法/匿名引用方法/普通setup定义的方法
343
- preFuncName = ut
344
- .head(`${originHandler.value}`.match(TARO_EVENT_VUE_FUNC2_REG))
345
- ?.replace('return ', '');
346
- // script setup定义且匿名引用的方法(需要配合defineExpose导出,否则是一个编译后的匿名单字母函数名)
347
- if (!preFuncName) {
348
- preFuncName = ut
349
- .head(`${originHandler.value}`.match(TARO_EVENT_VUE_FUNC3_REG))
350
- ?.replace('return ', '');
351
- }
352
- // script setup定义普通引用的方法(需要配合defineExpose导出,否则是一个编译后的匿名单字母函数名)
353
- if (!preFuncName) {
354
- preFuncName = originHandler.value?.name;
355
- }
356
- }
357
- } catch (error) {
358
- preFuncName = '';
359
- }
360
- // 能获取到方法名
361
- if (preFuncName) {
362
- let funcName =
363
- preFuncName.indexOf('.') > -1
364
- ? ut.head(ut.drop(ut.split(preFuncName, '.')))
365
- : preFuncName;
366
- let path = '';
367
- if (taroElement?._root?.uid) {
368
- path = ut.head(ut.split(taroElement._root.uid, '?'));
369
- } else {
370
- path = this.growingIO.dataStore.eventHooks.currentPage.getPagePath();
371
- }
372
- if (this.exposedNames[path]) {
373
- funcName =
374
- ut.niceTry(() => this.exposedNames[path][funcName]) ?? funcName;
375
- }
376
- return funcName;
377
- } else {
378
- // 不能获取方法名,直接构建一个匿名方法名
379
- return this.getAnonymousFunc(taroElement);
380
- }
381
- } else if (originHandler?.value?.name) {
382
- return originHandler.value.name;
383
- } else {
384
- return this.getAnonymousFunc(taroElement);
385
- }
386
- };
387
-
388
- // 无法获取的方法名
389
- getAnonymousFunc = (taroElement: any) => {
390
- const path = this.growingIO.dataStore.eventHooks.currentPage.getPagePath();
391
- const paths = path.split('/');
392
- const idx = paths.findIndex((v) => v.indexOf('page') > -1) + 1;
393
- const pageName = idx && paths[idx] ? paths[idx] : ut.last(paths);
394
- return `${pageName}_Func${
395
- ut.startsWith(taroElement.uid, '_')
396
- ? taroElement.uid
397
- : '_' + taroElement.uid
398
- }`;
399
- };
400
-
401
- // taro3使用vue2的代理
402
- taro3Vue2Proxy = () => {
403
- const self = this;
404
- this.taroVue.mixin({
405
- beforeMount: function () {
406
- // 对传统methods写法的普通事件hook
407
- const methods = this.$options.methods;
408
- ut.keys(methods).forEach((k: string) => {
409
- self.defineProperty(this, k, self.proxyMethods(k, this[k]));
410
- });
411
- // 对setup中定义的事件hook
412
- const setupState = this._setupState;
413
- if (!ut.isEmpty(setupState)) {
414
- ut.keys(setupState).forEach((k: string) => {
415
- self.defineProperty(
416
- setupState,
417
- k,
418
- self.proxyMethods(k, setupState[k])
419
- );
420
- });
421
- }
422
- }
423
- });
424
- };
425
-
426
- // 重写方法
427
- proxyMethods = (name: string, method: any) => {
428
- const { eventHooks } = this.growingIO.dataStore;
429
- if (ut.isFunction(method) && !eventHooks.pageHandlers.includes(name)) {
430
- return function (...args) {
431
- return eventHooks.customFcEffects(name, method).apply(this, args);
432
- };
433
- } else {
434
- return method;
435
- }
436
- };
437
-
438
- // 重新定义属性
439
- defineProperty = (target, key, value) => {
440
- Object.defineProperty(target, key, {
441
- writable: true,
442
- enumerable: true,
443
- configurable: true,
444
- value
445
- });
446
- };
447
-
448
- // taro3中存储当前页面完整的数据以获取曝光事件中的dataset
449
- // https://taro-docs.jd.com/taro/docs/react-overall#dataset
450
- saveFullPage = (body: any) => {
451
- const pageTraverse = (tEle: any) => {
452
- tEle.forEach((cEle: any) => {
453
- if (cEle?.ctx?.route) {
454
- if (!this.growingIO.taro3VMs) {
455
- this.growingIO.taro3VMs = {};
456
- }
457
- this.growingIO.taro3VMs[cEle.ctx.route] = cEle;
458
- } else if (ut.isArray(cEle.childNodes)) {
459
- pageTraverse(cEle.childNodes);
460
- }
461
- });
462
- };
463
- pageTraverse(body.childNodes);
464
- };
465
- }
466
-
467
- export default { name: 'gioTaroAdapter', method: GioTaroAdapter };