@tarojs/plugin-platform-alipay 3.5.0-alpha.14 → 3.5.0-alpha.17

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.
package/dist/index.js CHANGED
@@ -2,67 +2,205 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var service = require('@tarojs/service');
6
5
  var shared = require('@tarojs/shared');
6
+ var service = require('@tarojs/service');
7
7
  var template = require('@tarojs/shared/dist/template');
8
8
 
9
9
  /*! *****************************************************************************
10
- Copyright (c) Microsoft Corporation. All rights reserved.
11
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
12
- this file except in compliance with the License. You may obtain a copy of the
13
- License at http://www.apache.org/licenses/LICENSE-2.0
10
+ Copyright (c) Microsoft Corporation.
14
11
 
15
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
17
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
18
- MERCHANTABLITY OR NON-INFRINGEMENT.
12
+ Permission to use, copy, modify, and/or distribute this software for any
13
+ purpose with or without fee is hereby granted.
19
14
 
20
- See the Apache Version 2.0 License for specific language governing permissions
21
- and limitations under the License.
15
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
+ PERFORMANCE OF THIS SOFTWARE.
22
22
  ***************************************************************************** */
23
23
 
24
24
  function __awaiter(thisArg, _arguments, P, generator) {
25
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
25
26
  return new (P || (P = Promise))(function (resolve, reject) {
26
27
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
27
28
  function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
28
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
29
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
29
30
  step((generator = generator.apply(thisArg, _arguments || [])).next());
30
31
  });
31
32
  }
32
33
 
33
- class Template extends template.RecursiveTemplate {
34
- constructor() {
35
- super(...arguments);
36
- this.exportExpr = 'export default';
37
- this.supportXS = true;
38
- this.Adapter = {
39
- if: 'a:if',
40
- else: 'a:else',
41
- elseif: 'a:elif',
42
- for: 'a:for',
43
- forItem: 'a:for-item',
44
- forIndex: 'a:for-index',
45
- key: 'a:key',
46
- xs: 'sjs',
47
- type: 'alipay'
48
- };
49
- this.modifyLoopBody = (child, nodeName) => {
50
- if (nodeName === 'picker-view') {
51
- return `<picker-view-column>
34
+ const components = {
35
+ // ======== 调整属性 ========
36
+ View: {
37
+ 'disable-scroll': 'false',
38
+ hidden: 'false',
39
+ bindAppear: '',
40
+ bindDisappear: '',
41
+ bindFirstAppear: ''
42
+ },
43
+ Text: {
44
+ 'number-of-lines': ''
45
+ },
46
+ Map: {
47
+ skew: '0',
48
+ rotate: '0',
49
+ polygons: '[]',
50
+ 'include-padding': '',
51
+ 'ground-overlays': '',
52
+ 'tile-overlay': '',
53
+ 'custom-map-style': '',
54
+ setting: '{}',
55
+ optimize: '',
56
+ bindRegionChange: '',
57
+ bindPanelTap: ''
58
+ },
59
+ Button: {
60
+ scope: '',
61
+ 'public-id': '',
62
+ bindGetAuthorize: '',
63
+ bindError: ''
64
+ },
65
+ Checkbox: {
66
+ bindChange: ''
67
+ },
68
+ Input: {
69
+ 'random-number': 'false',
70
+ controlled: 'false',
71
+ enableNative: 'false'
72
+ },
73
+ Slider: {
74
+ 'track-size': '4',
75
+ 'handle-size': '22',
76
+ 'handle-color': shared.singleQuote('#ffffff')
77
+ },
78
+ Switch: {
79
+ controlled: 'false'
80
+ },
81
+ Textarea: {
82
+ 'show-count': 'true',
83
+ controlled: 'false',
84
+ enableNative: 'false'
85
+ },
86
+ MovableView: {
87
+ bindChangeEnd: ''
88
+ },
89
+ ScrollView: {
90
+ 'scroll-animation-duration': '',
91
+ 'trap-scroll': 'false'
92
+ },
93
+ Swiper: {
94
+ 'active-class': '',
95
+ 'changing-class': '',
96
+ acceleration: 'false',
97
+ 'disable-programmatic-animation': 'false',
98
+ 'disable-touch': 'false',
99
+ bindAnimationEnd: ''
100
+ },
101
+ Image: {
102
+ 'default-source': ''
103
+ },
104
+ Canvas: {
105
+ type: '',
106
+ width: shared.singleQuote('300px'),
107
+ height: shared.singleQuote('225px'),
108
+ bindReady: ''
109
+ },
110
+ Video: {
111
+ 'poster-size': shared.singleQuote('contain'),
112
+ 'mobilenet-hint-type': '1',
113
+ enableNative: 'false',
114
+ bindLoading: '',
115
+ bindUserAction: '',
116
+ bindStop: '',
117
+ bindRenderStart: ''
118
+ },
119
+ // ======== 额外组件 ========
120
+ Lottie: {
121
+ autoplay: 'false',
122
+ path: '',
123
+ speed: '1.0',
124
+ repeatCount: '0',
125
+ autoReverse: 'false',
126
+ assetsPath: '',
127
+ placeholder: '',
128
+ djangoId: '',
129
+ md5: '',
130
+ optimize: 'false',
131
+ bindDataReady: '',
132
+ bindDataFailed: '',
133
+ bindAnimationStart: '',
134
+ bindAnimationEnd: '',
135
+ bindAnimationRepeat: '',
136
+ bindAnimationCancel: '',
137
+ bindDataLoadReady: ''
138
+ },
139
+ Lifestyle: {
140
+ 'public-id': '',
141
+ memo: '',
142
+ bindFollow: ''
143
+ },
144
+ LifeFollow: {
145
+ sceneId: '',
146
+ checkFollow: '',
147
+ bindCheckFollow: '',
148
+ bindClose: ''
149
+ },
150
+ ContactButton: {
151
+ 'tnt-inst-id': '',
152
+ scene: '',
153
+ size: '25',
154
+ color: shared.singleQuote('#00A3FF'),
155
+ icon: '',
156
+ 'alipay-card-no': '',
157
+ 'ext-info': ''
158
+ },
159
+ ArCamera: {
160
+ devicePosition: shared.singleQuote('back'),
161
+ marker: '',
162
+ mode: shared.singleQuote('imageTracking'),
163
+ useCapturedImage: 'false',
164
+ bindInit: '',
165
+ bindStop: '',
166
+ bindError: '',
167
+ bindARFrame: ''
168
+ }
169
+ };
170
+
171
+ class Template extends template.RecursiveTemplate {
172
+ constructor() {
173
+ super(...arguments);
174
+ this.exportExpr = 'export default';
175
+ this.supportXS = true;
176
+ this.Adapter = {
177
+ if: 'a:if',
178
+ else: 'a:else',
179
+ elseif: 'a:elif',
180
+ for: 'a:for',
181
+ forItem: 'a:for-item',
182
+ forIndex: 'a:for-index',
183
+ key: 'a:key',
184
+ xs: 'sjs',
185
+ type: 'alipay'
186
+ };
187
+ this.modifyLoopBody = (child, nodeName) => {
188
+ if (nodeName === 'picker-view') {
189
+ return `<picker-view-column class="{{item.cl}}" style="{{item.st}}">
52
190
  <view a:for="{{item.cn}}" a:key="sid">
53
191
  ${child}
54
192
  </view>
55
- </picker-view-column>`;
56
- }
57
- return child;
58
- };
59
- this.modifyLoopContainer = (children, nodeName) => {
60
- if (nodeName === 'picker') {
193
+ </picker-view-column>`;
194
+ }
195
+ return child;
196
+ };
197
+ this.modifyLoopContainer = (children, nodeName) => {
198
+ if (nodeName === 'picker') {
61
199
  return `
62
200
  <view>${children}</view>
63
- `;
64
- }
65
- if (nodeName === 'swiper') {
201
+ `;
202
+ }
203
+ if (nodeName === 'swiper') {
66
204
  return `
67
205
  <block a:for="{{xs.f(i.cn)}}" a:key="sid">
68
206
  <swiper-item class="{{item.cl}}" style="{{item.st}}" id="{{item.uid||item.sid}}" data-sid="{{item.sid}}">
@@ -71,367 +209,272 @@ class Template extends template.RecursiveTemplate {
71
209
  </block>
72
210
  </swiper-item>
73
211
  </block>
74
- `;
75
- }
76
- return children;
77
- };
78
- this.modifyTemplateResult = (res, nodeName) => {
79
- if (nodeName === 'picker-view-column' || nodeName === 'swiper-item')
80
- return '';
81
- return res;
82
- };
83
- this.modifyThirdPartyLoopBody = () => {
84
- // 兼容支付宝 2.0 构建
85
- return `<view a:if="{{item.nn==='slot'}}" slot="{{item.name}}" id="{{item.uid||item.sid}}" data-sid="{{item.sid}}">
212
+ `;
213
+ }
214
+ return children;
215
+ };
216
+ this.modifyTemplateResult = (res, nodeName) => {
217
+ if (nodeName === 'picker-view-column' || nodeName === 'swiper-item')
218
+ return '';
219
+ return res;
220
+ };
221
+ this.modifyThirdPartyLoopBody = () => {
222
+ // 兼容支付宝 2.0 构建
223
+ const slot = this.componentsAlias.slot;
224
+ const slotAlias = slot._num;
225
+ const slotNamePropAlias = slot.name;
226
+ return `<view a:if="{{item.nn==='${slotAlias}'}}" slot="{{item.${slotNamePropAlias}}}" id="{{item.uid||item.sid}}" data-sid="{{item.sid}}">
86
227
  <block a:for="{{item.cn}}" a:key="sid">
87
228
  <template is="{{xs.e(0)}}" data="{{i:item}}" />
88
229
  </block>
89
230
  </view>
90
- <template a:else is="{{xs.e(0)}}" data="{{i:item}}" />`;
91
- };
92
- }
93
- buildXsTemplate() {
94
- return '<import-sjs name="xs" from="./utils.sjs" />';
95
- }
96
- replacePropName(name, value, compName) {
97
- if (value === 'eh')
98
- return name.replace('bind', 'on');
99
- if (compName === 'map' && value.includes('polygons')) {
100
- name = 'polygon';
101
- }
102
- return name;
103
- }
104
- getEvents() {
105
- return {
106
- onTap: 'eh',
107
- onTouchMove: 'eh',
108
- onTouchEnd: 'eh',
109
- onTouchCancel: 'eh',
110
- onLongTap: 'eh'
111
- };
112
- }
113
- buildThirdPartyAttr(attrs) {
114
- return [...attrs].reduce((str, attr) => {
115
- if (attr.startsWith('@')) {
116
- return str + `on${shared.capitalize(attr.slice(1))}="eh" `;
117
- }
118
- else if (attr.startsWith('bind')) {
119
- return str + `${attr}="eh" `;
120
- }
121
- else if (attr.startsWith('on')) {
122
- return str + `${attr}="eh" `;
123
- }
124
- return str + `${attr}="{{ i.${shared.toCamelCase(attr)} }}" `;
125
- }, '');
126
- }
127
- createMiniComponents(components) {
128
- const result = super.createMiniComponents(components);
129
- // 兼容支付宝 2.0 构建
130
- delete result.slot;
131
- delete result['slot-view'];
132
- return result;
133
- }
134
- buildXSTmpExtra() {
231
+ <template a:else is="{{xs.e(0)}}" data="{{i:item}}" />`;
232
+ };
233
+ }
234
+ buildXsTemplate() {
235
+ return '<import-sjs name="xs" from="./utils.sjs" />';
236
+ }
237
+ replacePropName(name, value, compName, componentAlias) {
238
+ if (value === 'eh')
239
+ return name.replace('bind', 'on');
240
+ if (compName === 'map') {
241
+ const polygonsAlias = componentAlias.polygons;
242
+ if (value.includes(polygonsAlias)) {
243
+ name = 'polygon';
244
+ }
245
+ }
246
+ return name;
247
+ }
248
+ getEvents() {
249
+ return {
250
+ onTap: 'eh',
251
+ onTouchMove: 'eh',
252
+ onTouchEnd: 'eh',
253
+ onTouchCancel: 'eh',
254
+ onLongTap: 'eh'
255
+ };
256
+ }
257
+ buildThirdPartyAttr(attrs) {
258
+ return [...attrs].reduce((str, attr) => {
259
+ if (attr.startsWith('@')) {
260
+ return str + `on${shared.capitalize(attr.slice(1))}="eh" `;
261
+ }
262
+ else if (attr.startsWith('bind')) {
263
+ return str + `${attr}="eh" `;
264
+ }
265
+ else if (attr.startsWith('on')) {
266
+ return str + `${attr}="eh" `;
267
+ }
268
+ return str + `${attr}="{{ i.${shared.toCamelCase(attr)} }}" `;
269
+ }, '');
270
+ }
271
+ createMiniComponents(components) {
272
+ const result = super.createMiniComponents(components);
273
+ // 兼容支付宝 2.0 构建
274
+ delete result.slot;
275
+ delete result['slot-view'];
276
+ return result;
277
+ }
278
+ buildXSTmpExtra() {
279
+ const swiperItemAlias = this.componentsAlias['swiper-item']._num;
135
280
  return `f: function (l) {
136
- return l.filter(function (i) {return i.nn === 'swiper-item'})
137
- }`;
138
- }
281
+ return l.filter(function (i) {return i.nn === '${swiperItemAlias}'})
282
+ }`;
283
+ }
139
284
  }
140
285
 
141
- const components = {
142
- // ======== 调整属性 ========
143
- View: {
144
- 'disable-scroll': 'false',
145
- hidden: 'false',
146
- bindAppear: '',
147
- bindDisappear: '',
148
- bindFirstAppear: ''
149
- },
150
- Text: {
151
- 'number-of-lines': ''
152
- },
153
- Map: {
154
- skew: '0',
155
- rotate: '0',
156
- polygons: '[]',
157
- 'include-padding': '',
158
- 'ground-overlays': '',
159
- 'tile-overlay': '',
160
- 'custom-map-style': '',
161
- setting: '{}',
162
- optimize: '',
163
- bindRegionChange: '',
164
- bindPanelTap: ''
165
- },
166
- Button: {
167
- scope: '',
168
- 'public-id': '',
169
- bindGetAuthorize: '',
170
- bindError: ''
171
- },
172
- Checkbox: {
173
- bindChange: ''
174
- },
175
- Input: {
176
- 'random-number': 'false',
177
- controlled: 'false',
178
- enableNative: 'false'
179
- },
180
- Slider: {
181
- 'track-size': '4',
182
- 'handle-size': '22',
183
- 'handle-color': shared.singleQuote('#ffffff')
184
- },
185
- Switch: {
186
- controlled: 'false'
187
- },
188
- Textarea: {
189
- 'show-count': 'true',
190
- controlled: 'false',
191
- enableNative: 'false'
192
- },
193
- MovableView: {
194
- bindChangeEnd: ''
195
- },
196
- ScrollView: {
197
- 'scroll-animation-duration': '',
198
- 'trap-scroll': 'false'
199
- },
200
- Swiper: {
201
- 'active-class': '',
202
- 'changing-class': '',
203
- acceleration: 'false',
204
- 'disable-programmatic-animation': 'false',
205
- 'disable-touch': 'false',
206
- bindAnimationEnd: ''
207
- },
208
- Image: {
209
- 'default-source': ''
210
- },
211
- Canvas: {
212
- type: '',
213
- width: shared.singleQuote('300px'),
214
- height: shared.singleQuote('225px'),
215
- bindReady: ''
216
- },
217
- Video: {
218
- 'poster-size': shared.singleQuote('contain'),
219
- 'mobilenet-hint-type': '1',
220
- enableNative: 'false',
221
- bindLoading: '',
222
- bindUserAction: '',
223
- bindStop: '',
224
- bindRenderStart: ''
225
- },
226
- // ======== 额外组件 ========
227
- Lottie: {
228
- autoplay: 'false',
229
- path: '',
230
- speed: '1.0',
231
- repeatCount: '0',
232
- autoReverse: 'false',
233
- assetsPath: '',
234
- placeholder: '',
235
- djangoId: '',
236
- md5: '',
237
- optimize: 'false',
238
- bindDataReady: '',
239
- bindDataFailed: '',
240
- bindAnimationStart: '',
241
- bindAnimationEnd: '',
242
- bindAnimationRepeat: '',
243
- bindAnimationCancel: '',
244
- bindDataLoadReady: ''
245
- },
246
- Lifestyle: {
247
- 'public-id': '',
248
- memo: '',
249
- bindFollow: ''
250
- },
251
- LifeFollow: {
252
- sceneId: '',
253
- checkFollow: '',
254
- bindCheckFollow: '',
255
- bindClose: ''
256
- },
257
- ContactButton: {
258
- 'tnt-inst-id': '',
259
- scene: '',
260
- size: '25',
261
- color: shared.singleQuote('#00A3FF'),
262
- icon: '',
263
- 'alipay-card-no': '',
264
- 'ext-info': ''
265
- }
266
- };
267
-
268
- const PACKAGE_NAME = '@tarojs/plugin-platform-alipay';
269
- class Alipay extends service.TaroPlatformBase {
270
- /**
271
- * 1. setupTransaction - init
272
- * 2. setup
273
- * 3. setupTransaction - close
274
- * 4. buildTransaction - init
275
- * 5. build
276
- * 6. buildTransaction - close
277
- */
278
- constructor(ctx, config) {
279
- super(ctx, config);
280
- this.platform = 'alipay';
281
- this.globalObject = 'my';
282
- this.runtimePath = `${PACKAGE_NAME}/dist/runtime`;
283
- this.taroComponentsPath = `${PACKAGE_NAME}/dist/components-react`;
284
- this.fileType = {
285
- templ: '.axml',
286
- style: '.acss',
287
- config: '.json',
288
- script: '.js',
289
- xs: '.sjs'
290
- };
291
- this.template = new Template();
292
- this.setupTransaction.addWrapper({
293
- close() {
294
- this.modifyMiniConfigs();
295
- this.modifyComponents();
296
- this.modifyWebpackConfig();
297
- this.generateProjectConfig('project.alipay.json', 'mini.project.json');
298
- }
299
- });
300
- }
301
- /**
302
- * 转换用户编写的配置(微信小程序标准)为支付宝小程序标准
303
- */
304
- modifyMiniConfigs() {
305
- this.ctx.modifyMiniConfigs(({ configMap }) => {
306
- const replaceKeyMap = {
307
- navigationBarTitleText: 'defaultTitle',
308
- navigationBarBackgroundColor: 'titleBarColor',
309
- enablePullDownRefresh: 'pullRefresh',
310
- list: 'items',
311
- text: 'name',
312
- iconPath: 'icon',
313
- selectedIconPath: 'activeIcon',
314
- color: 'textColor'
315
- };
316
- Object.keys(configMap).forEach(key => {
317
- const item = configMap[key];
318
- if (item.content) {
319
- this.recursiveReplaceObjectKeys(item.content, replaceKeyMap);
320
- }
321
- });
322
- });
323
- }
324
- /**
325
- * 增加组件或修改组件属性
326
- */
327
- modifyComponents() {
328
- const { internalComponents } = this.template;
329
- this.template.mergeComponents(this.ctx, components);
330
- this.modifySlider(internalComponents.Slider);
331
- this.modifySwiper(internalComponents.Swiper);
332
- }
333
- /**
334
- * 修改 Slider 组件属性
335
- */
336
- modifySlider(slider) {
337
- delete slider['block-size'];
338
- delete slider['block-color'];
339
- }
340
- /**
341
- * 修改 Swiper 组件属性
342
- */
343
- modifySwiper(swiper) {
344
- delete swiper.bindAnimationFinish;
345
- }
346
- /**
347
- * 修改 Webpack 配置
348
- */
349
- modifyWebpackConfig() {
350
- this.ctx.modifyWebpackChain(({ chain }) => {
351
- // 支付宝系小程序全局就有 navigator 对象,不需要模拟
352
- chain.plugin('providerPlugin')
353
- .tap(args => {
354
- const newArgs = Object.assign({}, args[0]);
355
- delete newArgs.navigator;
356
- return [newArgs];
357
- });
358
- });
359
- }
286
+ const PACKAGE_NAME = '@tarojs/plugin-platform-alipay';
287
+ class Alipay extends service.TaroPlatformBase {
288
+ /**
289
+ * 1. setupTransaction - init
290
+ * 2. setup
291
+ * 3. setupTransaction - close
292
+ * 4. buildTransaction - init
293
+ * 5. build
294
+ * 6. buildTransaction - close
295
+ */
296
+ constructor(ctx, config) {
297
+ super(ctx, config);
298
+ this.platform = 'alipay';
299
+ this.globalObject = 'my';
300
+ this.runtimePath = `${PACKAGE_NAME}/dist/runtime`;
301
+ this.taroComponentsPath = `${PACKAGE_NAME}/dist/components-react`;
302
+ this.fileType = {
303
+ templ: '.axml',
304
+ style: '.acss',
305
+ config: '.json',
306
+ script: '.js',
307
+ xs: '.sjs'
308
+ };
309
+ this.template = new Template();
310
+ this.setupTransaction.addWrapper({
311
+ close() {
312
+ this.modifyMiniConfigs();
313
+ this.modifyComponents();
314
+ this.modifyWebpackConfig();
315
+ this.generateProjectConfig('project.alipay.json', 'mini.project.json');
316
+ }
317
+ });
318
+ }
319
+ /**
320
+ * 转换用户编写的配置(微信小程序标准)为支付宝小程序标准
321
+ */
322
+ modifyMiniConfigs() {
323
+ this.ctx.modifyMiniConfigs(({ configMap }) => {
324
+ const replaceKeyMap = {
325
+ navigationBarTitleText: 'defaultTitle',
326
+ navigationBarBackgroundColor: 'titleBarColor',
327
+ enablePullDownRefresh: 'pullRefresh',
328
+ list: 'items',
329
+ text: 'name',
330
+ iconPath: 'icon',
331
+ selectedIconPath: 'activeIcon',
332
+ color: 'textColor'
333
+ };
334
+ Object.keys(configMap).forEach(key => {
335
+ const item = configMap[key];
336
+ if (item.content) {
337
+ this.recursiveReplaceObjectKeys(item.content, replaceKeyMap);
338
+ }
339
+ });
340
+ });
341
+ }
342
+ /**
343
+ * 增加组件或修改组件属性
344
+ */
345
+ modifyComponents() {
346
+ const { internalComponents } = this.template;
347
+ this.template.mergeComponents(this.ctx, components);
348
+ this.modifySlider(internalComponents.Slider);
349
+ this.modifySwiper(internalComponents.Swiper);
350
+ }
351
+ /**
352
+ * 修改 Slider 组件属性
353
+ */
354
+ modifySlider(slider) {
355
+ delete slider['block-size'];
356
+ delete slider['block-color'];
357
+ }
358
+ /**
359
+ * 修改 Swiper 组件属性
360
+ */
361
+ modifySwiper(swiper) {
362
+ delete swiper.bindAnimationFinish;
363
+ }
364
+ /**
365
+ * 修改 Webpack 配置
366
+ */
367
+ modifyWebpackConfig() {
368
+ this.ctx.modifyWebpackChain(({ chain }) => {
369
+ // 支付宝系小程序全局就有 navigator 对象,不需要模拟
370
+ chain.plugin('providerPlugin')
371
+ .tap(args => {
372
+ const newArgs = Object.assign({}, args[0]);
373
+ delete newArgs.navigator;
374
+ return [newArgs];
375
+ });
376
+ });
377
+ }
360
378
  }
361
379
 
362
- let registedModifyPageTemplate = false;
363
- var index = (ctx) => {
364
- ctx.registerPlatform({
365
- name: 'alipay',
366
- useConfigName: 'mini',
367
- fn({ config }) {
368
- return __awaiter(this, void 0, void 0, function* () {
369
- !registedModifyPageTemplate && modifyPageTemplate(ctx);
370
- const program = new Alipay(ctx, config);
371
- yield program.start();
372
- });
373
- }
374
- });
375
- };
376
- function getIsBuildPluginPath(filePath, isBuildPlugin) {
377
- return isBuildPlugin ? `plugin/${filePath}` : filePath;
378
- }
379
- // 支付宝小程序中,如果某个页面依赖了原生小程序组件,
380
- // 那么这个页面不能使用公共模板 base.axml,
381
- // 而需要把公共模板的内容在此页面的模板中复制一份, 。
382
- function modifyPageTemplate(ctx) {
383
- registedModifyPageTemplate = true;
384
- ctx.modifyBuildAssets(({ assets, miniPlugin }) => {
385
- const pages = [];
386
- // 筛选出使用了自定义组件的页面
387
- miniPlugin.pages.forEach(page => {
388
- const config = miniPlugin.filesConfig[miniPlugin.getConfigFilePath(page.name)].content;
389
- if (!page.isNative && (config === null || config === void 0 ? void 0 : config.hasOwnProperty('usingComponents')) && Object.keys(config.usingComponents).length) {
390
- pages.push(page.name);
391
- }
392
- });
393
- if (!pages.length)
394
- return;
395
- const baseXml = assets[getIsBuildPluginPath('base.axml', miniPlugin.options.isBuildPlugin)].source();
396
- pages.forEach(page => {
397
- const templateName = `${page}.axml`;
398
- const assetsItem = assets[templateName];
399
- const src = assetsItem._value ? assetsItem._value.toString() : assetsItem.source();
400
- let relativePath;
401
- const templateCaller = src.replace(/<import src="(.*)base\.axml"\/>/, function (_, $1) {
402
- relativePath = $1;
403
- return '';
404
- });
405
- const main = baseXml.replace(/<import-sjs name="xs" from="(.*)utils.sjs" \/>/, function () {
406
- return `<import-sjs name="xs" from="${relativePath}utils.sjs" />`;
407
- });
380
+ let registeredModifyPageTemplate = false;
381
+ var index = (ctx) => {
382
+ ctx.registerPlatform({
383
+ name: 'alipay',
384
+ useConfigName: 'mini',
385
+ fn({ config }) {
386
+ return __awaiter(this, void 0, void 0, function* () {
387
+ !registeredModifyPageTemplate && modifyPageTemplate(ctx);
388
+ const program = new Alipay(ctx, config);
389
+ yield program.start();
390
+ });
391
+ }
392
+ });
393
+ ctx.modifyRunnerOpts(({ opts }) => {
394
+ if (!(opts === null || opts === void 0 ? void 0 : opts.compiler))
395
+ return;
396
+ if (shared.isString(opts.compiler)) {
397
+ opts.compiler = {
398
+ type: opts.compiler
399
+ };
400
+ }
401
+ const { compiler } = opts;
402
+ if (compiler.type === 'webpack5') {
403
+ compiler.prebundle || (compiler.prebundle = {});
404
+ const prebundleOptions = compiler.prebundle;
405
+ if (prebundleOptions.enable === false)
406
+ return;
407
+ prebundleOptions.swc || (prebundleOptions.swc = {
408
+ jsc: {
409
+ target: 'es5'
410
+ }
411
+ });
412
+ prebundleOptions.exclude || (prebundleOptions.exclude = []);
413
+ prebundleOptions.exclude.push('@tarojs/plugin-platform-alipay/dist/runtime');
414
+ prebundleOptions.include || (prebundleOptions.include = []);
415
+ prebundleOptions.include.push('@tarojs/shared');
416
+ }
417
+ });
418
+ };
419
+ function getIsBuildPluginPath(filePath, isBuildPlugin) {
420
+ return isBuildPlugin ? `plugin/${filePath}` : filePath;
421
+ }
422
+ // 支付宝小程序中,如果某个页面依赖了原生小程序组件,
423
+ // 那么这个页面不能使用公共模板 base.axml,
424
+ // 而需要把公共模板的内容在此页面的模板中复制一份,
425
+ function modifyPageTemplate(ctx) {
426
+ registeredModifyPageTemplate = true;
427
+ ctx.modifyBuildAssets(({ assets, miniPlugin }) => {
428
+ const pages = [];
429
+ // 筛选出使用了自定义组件的页面
430
+ miniPlugin.pages.forEach(page => {
431
+ const config = miniPlugin.filesConfig[miniPlugin.getConfigFilePath(page.name)].content;
432
+ if (!page.isNative && (config === null || config === void 0 ? void 0 : config.hasOwnProperty('usingComponents')) && Object.keys(config.usingComponents).length) {
433
+ pages.push(page.name);
434
+ }
435
+ });
436
+ if (!pages.length)
437
+ return;
438
+ const baseXml = assets[getIsBuildPluginPath('base.axml', miniPlugin.options.isBuildPlugin)].source();
439
+ pages.forEach(page => {
440
+ const templateName = `${page}.axml`;
441
+ const assetsItem = assets[templateName];
442
+ const src = assetsItem._value ? assetsItem._value.toString() : assetsItem.source();
443
+ let relativePath;
444
+ const templateCaller = src.replace(/<import src="(.*)base\.axml"\/>/, function (_, $1) {
445
+ relativePath = $1;
446
+ return '';
447
+ });
448
+ const main = baseXml.replace(/<import-sjs name="xs" from="(.*)utils.sjs" \/>/, function () {
449
+ return `<import-sjs name="xs" from="${relativePath}utils.sjs" />`;
450
+ });
408
451
  const res = `${templateCaller}
409
- ${main}`;
410
- assets[templateName] = {
411
- size: () => res.length,
412
- source: () => res
413
- };
414
- });
415
- if (miniPlugin.options.isBuildPlugin) {
416
- const miniProjectJSONStr = JSON.stringify({
417
- miniprogramRoot: 'miniprogram',
418
- pluginRoot: 'plugin',
419
- compileType: 'plugin'
420
- }, null, 2);
421
- assets['mini.project.json'] = {
422
- size: () => miniProjectJSONStr.length,
423
- source: () => miniProjectJSONStr
424
- };
425
- const pluginJSON = JSON.parse(assets['/plugin/plugin.json'].source());
426
- pluginJSON.publicPages = pluginJSON.pages;
427
- pluginJSON.pages = Object.values(pluginJSON.publicPages);
428
- const pluginJSONStr = JSON.stringify(pluginJSON, null, 2);
429
- assets['/plugin/plugin.json'] = {
430
- size: () => pluginJSONStr.length,
431
- source: () => pluginJSONStr
432
- };
433
- }
434
- });
452
+ ${main}`;
453
+ assets[templateName] = {
454
+ size: () => res.length,
455
+ source: () => res
456
+ };
457
+ });
458
+ if (miniPlugin.options.isBuildPlugin) {
459
+ const miniProjectJSONStr = JSON.stringify({
460
+ miniprogramRoot: 'miniprogram',
461
+ pluginRoot: 'plugin',
462
+ compileType: 'plugin'
463
+ }, null, 2);
464
+ assets['mini.project.json'] = {
465
+ size: () => miniProjectJSONStr.length,
466
+ source: () => miniProjectJSONStr
467
+ };
468
+ const pluginJSON = JSON.parse(assets['/plugin/plugin.json'].source());
469
+ pluginJSON.publicPages = pluginJSON.pages;
470
+ pluginJSON.pages = Object.values(pluginJSON.publicPages);
471
+ const pluginJSONStr = JSON.stringify(pluginJSON, null, 2);
472
+ assets['/plugin/plugin.json'] = {
473
+ size: () => pluginJSONStr.length,
474
+ source: () => pluginJSONStr
475
+ };
476
+ }
477
+ });
435
478
  }
436
479
 
437
480
  exports.Alipay = Alipay;