@tarojs/plugin-inject 1.0.1 → 3.6.1-alpha.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.
- package/LICENSE +139 -0
- package/README.md +62 -0
- package/dist/index.js +44 -16
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +10 -11
- package/dist/runtime.js.map +1 -1
- package/index.js +1 -0
- package/package.json +19 -28
- package/dist/apis-list.js +0 -6
- package/dist/apis-list.js.map +0 -1
- package/dist/components.js +0 -5
- package/dist/components.js.map +0 -1
- package/src/apis-list.ts +0 -2
- package/src/components.ts +0 -1
- package/src/index.ts +0 -95
- package/src/runtime.ts +0 -18
package/LICENSE
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 O2Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
========================================================================
|
|
24
|
+
|
|
25
|
+
MIT (react-devtools):
|
|
26
|
+
The following files embed [react-devtools](https://github.com/facebook/react) MIT:
|
|
27
|
+
`/packages/taro-plugin-react-devtools/src/backend/index.js`
|
|
28
|
+
See `/LICENSE` for details of the license.
|
|
29
|
+
|
|
30
|
+
==================
|
|
31
|
+
|
|
32
|
+
MIT (vue-devtools):
|
|
33
|
+
The following files embed [vue-devtools](https://github.com/vuejs/devtools) MIT:
|
|
34
|
+
`/packages/taro-plugin-vue-devtools/src/backend/*`
|
|
35
|
+
See `/LICENSE` for details of the license.
|
|
36
|
+
|
|
37
|
+
==================
|
|
38
|
+
|
|
39
|
+
MIT (vite):
|
|
40
|
+
The following files embed [vite](https://github.com/vitejs/vite) MIT:
|
|
41
|
+
`/packages/taro-webpack5-prebundle/src/prebundle/scanImport.ts`,
|
|
42
|
+
`/packages/taro-webpack5-prebundle/src/prebundle/bundle.ts`,
|
|
43
|
+
`/packages/taro-webpack5-prebundle/src/h5.ts`,
|
|
44
|
+
`/packages/taro-webpack5-prebundle/src/min.ts`
|
|
45
|
+
See `/LICENSE` for details of the license.
|
|
46
|
+
|
|
47
|
+
==================
|
|
48
|
+
|
|
49
|
+
MIT (webpack):
|
|
50
|
+
The following files embed [webpack](https://github.com/webpack/webpack) MIT:
|
|
51
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerEntryModule.ts`,
|
|
52
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerPlugin.ts`,
|
|
53
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroContainerReferencePlugin.ts`,
|
|
54
|
+
`/packages/taro-webpack5-prebundle/src/webpack/TaroModuleFederationPlugin.ts`
|
|
55
|
+
See `/LICENSE` for details of the license.
|
|
56
|
+
|
|
57
|
+
==================
|
|
58
|
+
|
|
59
|
+
MIT (sizzle):
|
|
60
|
+
The following files embed [sizzle](https://github.com/jquery/sizzle) MIT:
|
|
61
|
+
`/packages/taro-extends/src/jquery/sizzle.js`
|
|
62
|
+
See `/LICENSE.txt` for details of the license.
|
|
63
|
+
|
|
64
|
+
==================
|
|
65
|
+
|
|
66
|
+
MIT (zepto):
|
|
67
|
+
The following files embed [zepto](https://github.com/madrobby/zepto) MIT:
|
|
68
|
+
`/packages/taro-extends/src/jquery/zepto.js`,
|
|
69
|
+
`/packages/taro-extends/src/jquery/event.js`
|
|
70
|
+
See `/MIT-LICENSE` for details of the license.
|
|
71
|
+
|
|
72
|
+
==================
|
|
73
|
+
|
|
74
|
+
MIT (css-to-react-native):
|
|
75
|
+
The following files embed [css-to-react-native](https://github.com/styled-components/css-to-react-native) MIT:
|
|
76
|
+
`/packages/css-to-react-native/src/css-to-react-native/*`
|
|
77
|
+
See `/LICENSE.md` for details of the license.
|
|
78
|
+
|
|
79
|
+
==================
|
|
80
|
+
|
|
81
|
+
MIT (reactify-wc):
|
|
82
|
+
The following files embed [reactify-wc](https://github.com/BBKolton/reactify-wc) MIT:
|
|
83
|
+
`/packages/taro-components-library-react/src/component-lib/reactify-wc.ts`
|
|
84
|
+
See `/LICENSE` for details of the license.
|
|
85
|
+
|
|
86
|
+
==================
|
|
87
|
+
|
|
88
|
+
MIT (ant-design-mobile-rn):
|
|
89
|
+
The following files embed [ant-design-mobile-rn](https://github.com/ant-design/ant-design-mobile-rn) MIT:
|
|
90
|
+
`/packages/taro-components-rn/src/components/Swiper/carousel.tsx`
|
|
91
|
+
See `/LICENSE` for details of the license.
|
|
92
|
+
|
|
93
|
+
==================
|
|
94
|
+
|
|
95
|
+
MIT (react-wx-images-viewer):
|
|
96
|
+
The following files embed [react-wx-images-viewer](https://github.com/react-ld/react-wx-images-viewer) MIT:
|
|
97
|
+
`/packages/taro-h5/src/api/media/image/previewImage.ts`
|
|
98
|
+
See `/LICENSE` for details of the license.
|
|
99
|
+
|
|
100
|
+
==================
|
|
101
|
+
|
|
102
|
+
MIT (webpack-contrib/css-loader):
|
|
103
|
+
The following files embed [webpack-contrib/css-loader](https://github.com/webpack-contrib/css-loader) MIT:
|
|
104
|
+
`/packages/taro-rn-style-transformer/src/utils/index.ts`
|
|
105
|
+
See `/LICENSE` for details of the license.
|
|
106
|
+
|
|
107
|
+
==================
|
|
108
|
+
|
|
109
|
+
MIT (react-native):
|
|
110
|
+
The following files embed [react-native](https://github.com/facebook/react-native) MIT:
|
|
111
|
+
`/packages/taro-rn-style-transformer/src/transforms/StyleSheet/*`
|
|
112
|
+
See `/LICENSE` for details of the license.
|
|
113
|
+
|
|
114
|
+
==================
|
|
115
|
+
|
|
116
|
+
MIT (myrne/performance-now):
|
|
117
|
+
The following files embed [myrne/performance-now](https://github.com/myrne/performance-now) MIT:
|
|
118
|
+
`/packages/taro-runtime/src/bom/raf.ts`
|
|
119
|
+
See `/LICENSE` for details of the license.
|
|
120
|
+
|
|
121
|
+
==================
|
|
122
|
+
|
|
123
|
+
Apache (chameleon-api):
|
|
124
|
+
The following files embed [chameleon-api](https://github.com/chameleon-team/chameleon-api) Apache:
|
|
125
|
+
`/packages/taro-h5/src/api/device/clipboard.ts`
|
|
126
|
+
|
|
127
|
+
==================
|
|
128
|
+
|
|
129
|
+
MIT (uni-app):
|
|
130
|
+
The following files embed [uni-app](https://github.com/dcloudio/uni-app) MIT:
|
|
131
|
+
`/packages/taro-components-rn/src/components/Video/index.tsx`
|
|
132
|
+
See `/LICENSE` for details of the license.
|
|
133
|
+
|
|
134
|
+
==================
|
|
135
|
+
|
|
136
|
+
MIT (miniprogram-render):
|
|
137
|
+
The following files embed [miniprogram-render](https://github.com/Tencent/kbone) MIT:
|
|
138
|
+
`/packages/taro-plugin-http/src/runtime/Cookie.ts`
|
|
139
|
+
See `/LICENSE` for details of the license.
|
package/README.md
CHANGED
|
@@ -52,6 +52,7 @@ const config = {
|
|
|
52
52
|
| componentsMap | object | 新增组件时的名称映射 |
|
|
53
53
|
| voidComponents | array, function | 设置组件是否可以渲染子元素 |
|
|
54
54
|
| nestElements | object, function | 设置组件模版的循环次数 |
|
|
55
|
+
| thirdPartyComponents | object | 设置第三方自定义组件的属性的默认值 |
|
|
55
56
|
|
|
56
57
|
#### 1. syncApis
|
|
57
58
|
|
|
@@ -139,6 +140,29 @@ const config = {
|
|
|
139
140
|
}
|
|
140
141
|
```
|
|
141
142
|
|
|
143
|
+
新增事件属性:
|
|
144
|
+
> 新增一个事件属性有两种方式,一种是像上面例子那样属性以`bind`开头,一种是像下面例子这样将属性值设为`eh` [查看详细PR](https://github.com/NervJS/taro/pull/11478)
|
|
145
|
+
```js
|
|
146
|
+
const config = {
|
|
147
|
+
plugins: [
|
|
148
|
+
[
|
|
149
|
+
'@tarojs/plugin-inject',
|
|
150
|
+
{
|
|
151
|
+
components: {
|
|
152
|
+
// 新增一个 'CustomComponent' 组件并支持 'catchtouchend' 事件
|
|
153
|
+
CustomComponent: {
|
|
154
|
+
catchtouchend: 'eh',
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
componentsMap: {
|
|
158
|
+
CustomComponent: 'custom-component',
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
],
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
142
166
|
#### 4. voidComponents
|
|
143
167
|
|
|
144
168
|
在 `voidComponents` 里的组件**不可以渲染子组件**。
|
|
@@ -231,6 +255,44 @@ const config = {
|
|
|
231
255
|
}
|
|
232
256
|
```
|
|
233
257
|
|
|
258
|
+
#### 6. thirdPartyComponents
|
|
259
|
+
|
|
260
|
+
> v1.0.2+ 开始支持,且需要 Taro v3.4.10+
|
|
261
|
+
|
|
262
|
+
在默认情况下,第三方自定义组件的属性会被编译为形如:`<van-empty image="{{i.image}}" />`。
|
|
263
|
+
|
|
264
|
+
这时自定义组件声明的默认值会失效(详情请浏览 [#11575](https://github.com/NervJS/taro/issues/11575))。
|
|
265
|
+
|
|
266
|
+
```js
|
|
267
|
+
Component({
|
|
268
|
+
props: {
|
|
269
|
+
image: {
|
|
270
|
+
type: String,
|
|
271
|
+
value: 'default'
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
所以我们需要为此属性增加默认值,把它编译为形如:`<van-empty image="{{i.image===undefined?'default':i.image}}" />`。
|
|
278
|
+
|
|
279
|
+
用法:
|
|
280
|
+
|
|
281
|
+
```js
|
|
282
|
+
const config = {
|
|
283
|
+
plugins: [
|
|
284
|
+
['@tarojs/plugin-inject', {
|
|
285
|
+
thirdPartyComponents: {
|
|
286
|
+
// 为 `van-empty` 组件的 image 属性设置默认值 'default'
|
|
287
|
+
'van-empty': {
|
|
288
|
+
'image': "'default'"
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}]
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
234
296
|
### 模块补充
|
|
235
297
|
|
|
236
298
|
在前面的 components 示例中,给Text组件添加了新属性x-props后,@tarojs/components的类型文件中没有新定义的属性,typescript无法识别Text组件的x-props属性,导致vscode提示属性不存在,可以通过[模块补充](https://docs.taro.zone/docs/platform-plugin-how#%E7%B1%BB%E5%9E%8B)的方式来修正
|
package/dist/index.js
CHANGED
|
@@ -1,26 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var shared = require('@tarojs/shared');
|
|
6
|
+
var path = require('path');
|
|
7
|
+
|
|
8
|
+
function _interopNamespace(e) {
|
|
9
|
+
if (e && e.__esModule) return e;
|
|
10
|
+
var n = Object.create(null);
|
|
11
|
+
if (e) {
|
|
12
|
+
Object.keys(e).forEach(function (k) {
|
|
13
|
+
if (k !== 'default') {
|
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return e[k]; }
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
n["default"] = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
27
|
+
|
|
28
|
+
var index = (ctx, options) => {
|
|
6
29
|
const fs = ctx.helper.fs;
|
|
7
30
|
ctx.registerMethod({
|
|
8
31
|
name: 'onSetupClose',
|
|
9
32
|
fn(platform) {
|
|
10
|
-
const { voidComponents, nestElements, components, syncApis, asyncApis, componentsMap } = options;
|
|
33
|
+
const { voidComponents, nestElements, components, syncApis, asyncApis, componentsMap, thirdPartyComponents } = options;
|
|
11
34
|
const template = platform.template;
|
|
12
|
-
if (
|
|
35
|
+
if (shared.isArray(voidComponents)) {
|
|
13
36
|
voidComponents.forEach(el => template.voidElements.add(el));
|
|
14
37
|
}
|
|
15
|
-
else if (
|
|
38
|
+
else if (shared.isFunction(voidComponents)) {
|
|
16
39
|
template.voidElements = voidComponents(template.voidElements);
|
|
17
40
|
}
|
|
18
|
-
if (
|
|
41
|
+
if (shared.isObject(nestElements)) {
|
|
19
42
|
for (const key in nestElements) {
|
|
20
43
|
template.nestElements.set(key, nestElements[key]);
|
|
21
44
|
}
|
|
22
45
|
}
|
|
23
|
-
else if (
|
|
46
|
+
else if (shared.isFunction(nestElements)) {
|
|
24
47
|
template.nestElements = nestElements(template.nestElements);
|
|
25
48
|
}
|
|
26
49
|
if (components || syncApis || asyncApis || componentsMap) {
|
|
@@ -35,33 +58,38 @@ exports.default = (ctx, options) => {
|
|
|
35
58
|
injectComponents(fs, components);
|
|
36
59
|
injectApis(fs, syncApis, asyncApis);
|
|
37
60
|
}
|
|
61
|
+
if (thirdPartyComponents) {
|
|
62
|
+
template.mergeThirdPartyComponents(thirdPartyComponents);
|
|
63
|
+
}
|
|
38
64
|
}
|
|
39
65
|
});
|
|
40
66
|
};
|
|
41
67
|
function injectRuntimePath(platform) {
|
|
42
68
|
const injectedPath = `@tarojs/plugin-inject/dist/runtime`;
|
|
43
|
-
if (
|
|
69
|
+
if (shared.isArray(platform.runtimePath)) {
|
|
44
70
|
platform.runtimePath.push(injectedPath);
|
|
45
71
|
}
|
|
46
|
-
else if (
|
|
72
|
+
else if (shared.isString(platform.runtimePath)) {
|
|
47
73
|
platform.runtimePath = [platform.runtimePath, injectedPath];
|
|
48
74
|
}
|
|
49
75
|
}
|
|
50
76
|
function injectComponentsReact(fs, taroComponentsPath, componentsMap) {
|
|
51
|
-
fs.writeFileSync(
|
|
77
|
+
fs.writeFileSync(path__namespace.resolve(__dirname, '../dist/components-react.js'), `
|
|
52
78
|
export * from '${taroComponentsPath}'
|
|
53
79
|
${Object.keys(componentsMap).map((key) => `export const ${key} = '${componentsMap[key]}'`).join('\n')}
|
|
54
80
|
`);
|
|
55
81
|
}
|
|
56
82
|
function injectComponents(fs, components) {
|
|
57
|
-
fs.writeFileSync(
|
|
83
|
+
fs.writeFileSync(path__namespace.resolve(__dirname, '../dist/components.js'), `
|
|
58
84
|
export const components = ${components ? JSON.stringify(components) : JSON.stringify({})};
|
|
59
85
|
`);
|
|
60
86
|
}
|
|
61
87
|
function injectApis(fs, syncApis, asyncApis) {
|
|
62
|
-
fs.writeFileSync(
|
|
88
|
+
fs.writeFileSync(path__namespace.resolve(__dirname, '../dist/apis-list.js'), `
|
|
63
89
|
export const noPromiseApis = new Set(${syncApis ? JSON.stringify(syncApis) : JSON.stringify([])});
|
|
64
90
|
export const needPromiseApis = new Set(${asyncApis ? JSON.stringify(asyncApis) : JSON.stringify([])});
|
|
65
91
|
`);
|
|
66
92
|
}
|
|
67
|
-
|
|
93
|
+
|
|
94
|
+
exports["default"] = index;
|
|
95
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["\nimport { isArray, isFunction, isObject, isString } from '@tarojs/shared'\nimport * as path from 'path'\n\nimport type { IPluginContext, TaroPlatformBase } from '@tarojs/service'\n\ntype VoidComponents = Set<string>\ntype NestElements = Map<string, number>\n\ninterface IOptions {\n voidComponents: string[] | ((list: VoidComponents) => VoidComponents)\n nestElements: Record<string, number> | ((elem: NestElements) => NestElements)\n components: Record<string, Record<string, any>>\n componentsMap: Record<string, string>\n syncApis: string[]\n asyncApis: string[]\n thirdPartyComponents: Record<string, Record<string, any>>\n}\n\nexport default (ctx: IPluginContext, options: IOptions) => {\n const fs = ctx.helper.fs\n\n ctx.registerMethod({\n name: 'onSetupClose',\n fn (platform: TaroPlatformBase) {\n const {\n voidComponents,\n nestElements,\n components,\n syncApis,\n asyncApis,\n componentsMap,\n thirdPartyComponents\n } = options\n\n const template = platform.template\n\n if (isArray(voidComponents)) {\n voidComponents.forEach(el => template.voidElements.add(el))\n } else if (isFunction(voidComponents)) {\n template.voidElements = voidComponents(template.voidElements)\n }\n\n if (isObject<NestElements>(nestElements)) {\n for (const key in nestElements) {\n template.nestElements.set(key, nestElements[key])\n }\n } else if (isFunction(nestElements)) {\n template.nestElements = nestElements(template.nestElements)\n }\n\n if (components || syncApis || asyncApis || componentsMap) {\n injectRuntimePath(platform)\n\n if (components) {\n template.mergeComponents(ctx, components)\n }\n\n if (componentsMap) {\n injectComponentsReact(fs, platform.taroComponentsPath, componentsMap)\n platform.taroComponentsPath = `@tarojs/plugin-inject/dist/components-react`\n }\n\n injectComponents(fs, components)\n injectApis(fs, syncApis, asyncApis)\n }\n\n if (thirdPartyComponents) {\n template.mergeThirdPartyComponents(thirdPartyComponents)\n }\n }\n })\n}\n\nfunction injectRuntimePath (platform: TaroPlatformBase) {\n const injectedPath = `@tarojs/plugin-inject/dist/runtime`\n if (isArray(platform.runtimePath)) {\n platform.runtimePath.push(injectedPath)\n } else if (isString(platform.runtimePath)) {\n platform.runtimePath = [platform.runtimePath, injectedPath]\n }\n}\n\nfunction injectComponentsReact (fs, taroComponentsPath, componentsMap) {\n fs.writeFileSync(path.resolve(__dirname, '../dist/components-react.js'), `\nexport * from '${taroComponentsPath}'\n${Object.keys(componentsMap).map((key) => `export const ${key} = '${componentsMap[key]}'`).join('\\n')}\n`)\n}\n\nfunction injectComponents (fs, components) {\n fs.writeFileSync(path.resolve(__dirname, '../dist/components.js'), `\nexport const components = ${components ? JSON.stringify(components) : JSON.stringify({})};\n`)\n}\n\nfunction injectApis (fs, syncApis, asyncApis) {\n fs.writeFileSync(path.resolve(__dirname, '../dist/apis-list.js'), `\nexport const noPromiseApis = new Set(${syncApis ? JSON.stringify(syncApis) : JSON.stringify([])});\nexport const needPromiseApis = new Set(${asyncApis ? JSON.stringify(asyncApis) : JSON.stringify([])});\n`)\n}\n"],"names":["isArray","isFunction","isObject","isString","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,YAAe,CAAC,GAAmB,EAAE,OAAiB,KAAI;AACxD,IAAA,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;IAExB,GAAG,CAAC,cAAc,CAAC;AACjB,QAAA,IAAI,EAAE,cAAc;AACpB,QAAA,EAAE,CAAE,QAA0B,EAAA;AAC5B,YAAA,MAAM,EACJ,cAAc,EACd,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,SAAS,EACT,aAAa,EACb,oBAAoB,EACrB,GAAG,OAAO,CAAA;AAEX,YAAA,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAA;AAElC,YAAA,IAAIA,cAAO,CAAC,cAAc,CAAC,EAAE;AAC3B,gBAAA,cAAc,CAAC,OAAO,CAAC,EAAE,IAAI,QAAQ,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC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,EAAE,CAAA;AAC7B,qCAAA,EAAA,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;AACtD,uCAAA,EAAA,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;AAClG,CAAA,CAAC,CAAA;AACF;;;;"}
|
package/dist/runtime.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const apis_list_1 = require("./apis-list");
|
|
1
|
+
import { mergeReconciler, mergeInternalComponents, processApis } from '@tarojs/shared';
|
|
2
|
+
import { noPromiseApis, needPromiseApis } from './apis-list';
|
|
3
|
+
import { components } from './components';
|
|
4
|
+
|
|
6
5
|
const hostConfig = {
|
|
7
6
|
initNativeApi(taro) {
|
|
8
7
|
const global = taro.miniGlobal;
|
|
9
|
-
|
|
10
|
-
noPromiseApis
|
|
11
|
-
needPromiseApis
|
|
8
|
+
processApis(taro, global, {
|
|
9
|
+
noPromiseApis,
|
|
10
|
+
needPromiseApis,
|
|
12
11
|
isOnlyPromisify: true
|
|
13
12
|
});
|
|
14
13
|
}
|
|
15
14
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=runtime.js.map
|
|
15
|
+
mergeReconciler(hostConfig);
|
|
16
|
+
mergeInternalComponents(components);
|
|
17
|
+
//# sourceMappingURL=runtime.js.map
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","
|
|
1
|
+
{"version":3,"file":"runtime.js","sources":["../src/runtime.ts"],"sourcesContent":["import { mergeInternalComponents, mergeReconciler, processApis } from '@tarojs/shared'\n\nimport { needPromiseApis,noPromiseApis } from './apis-list'\nimport { components } from './components'\n\nconst hostConfig = {\n initNativeApi (taro) {\n const global = taro.miniGlobal\n processApis(taro, global, {\n noPromiseApis,\n needPromiseApis,\n isOnlyPromisify: true\n })\n }\n}\n\n\nmergeReconciler(hostConfig)\nmergeInternalComponents(components)\n"],"names":[],"mappings":";;;;AAKA,MAAM,UAAU,GAAG;AACjB,IAAA,aAAa,CAAE,IAAI,EAAA;AACjB,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAA;AAC9B,QAAA,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE;YACxB,aAAa;YACb,eAAe;AACf,YAAA,eAAe,EAAE,IAAI;AACtB,SAAA,CAAC,CAAA;KACH;CACF,CAAA;AAGD,eAAe,CAAC,UAAU,CAAC,CAAA;AAC3B,uBAAuB,CAAC,UAAU,CAAC"}
|
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,43 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/plugin-inject",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "3.6.1-alpha.0",
|
|
4
4
|
"description": "Taro 小程序端平台中间层插件",
|
|
5
|
+
"author": "luckyadam",
|
|
6
|
+
"homepage": "https://github.com/nervjs/taro",
|
|
7
|
+
"license": "MIT",
|
|
5
8
|
"main": "index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"prod": "tsc",
|
|
10
|
-
"clean": "rimraf dist",
|
|
11
|
-
"test": "jest",
|
|
12
|
-
"test:dev": "jest --watch"
|
|
13
|
-
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"taro"
|
|
11
|
+
],
|
|
14
12
|
"files": [
|
|
15
|
-
"src",
|
|
16
|
-
"dist",
|
|
17
13
|
"index.js",
|
|
18
|
-
"
|
|
14
|
+
"dist"
|
|
19
15
|
],
|
|
20
16
|
"repository": {
|
|
21
17
|
"type": "git",
|
|
22
|
-
"url": "git+https://github.com/NervJS/taro
|
|
18
|
+
"url": "git+https://github.com/NervJS/taro.git"
|
|
23
19
|
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"Taro"
|
|
26
|
-
],
|
|
27
|
-
"author": "luckyadam",
|
|
28
|
-
"license": "MIT",
|
|
29
20
|
"bugs": {
|
|
30
|
-
"url": "https://github.com/NervJS/
|
|
21
|
+
"url": "https://github.com/NervJS/taro/issues"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@tarojs/service": "3.6.1-alpha.0",
|
|
25
|
+
"@tarojs/shared": "3.6.1-alpha.0"
|
|
31
26
|
},
|
|
32
|
-
"homepage": "https://github.com/NervJS/tarojs-plugin-inject#readme",
|
|
33
27
|
"peerDependencies": {
|
|
34
|
-
"
|
|
28
|
+
"react": ">=17"
|
|
35
29
|
},
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"typescript": "^3.8.3",
|
|
40
|
-
"webpack": "^4.41.0",
|
|
41
|
-
"webpack-dev-server": "^3.8.2"
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "rollup -c",
|
|
32
|
+
"dev": "rollup -c -w"
|
|
42
33
|
}
|
|
43
|
-
}
|
|
34
|
+
}
|
package/dist/apis-list.js
DELETED
package/dist/apis-list.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"apis-list.js","sourceRoot":"","sources":["../src/apis-list.ts"],"names":[],"mappings":";;;AAAa,QAAA,aAAa,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAA;AAC3B,QAAA,eAAe,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,CAAA"}
|
package/dist/components.js
DELETED
package/dist/components.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG,EAAE,CAAA"}
|
package/src/apis-list.ts
DELETED
package/src/components.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const components = {}
|
package/src/index.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import type { IPluginContext, TaroPlatformBase } from '@tarojs/service'
|
|
3
|
-
import { isObject, isArray, isFunction, isString } from '@tarojs/shared'
|
|
4
|
-
import * as path from 'path'
|
|
5
|
-
|
|
6
|
-
type VoidComponents = Set<string>
|
|
7
|
-
type NestElements = Map<string, number>
|
|
8
|
-
|
|
9
|
-
interface IOptions {
|
|
10
|
-
voidComponents: string[] | ((list: VoidComponents) => VoidComponents)
|
|
11
|
-
nestElements: Record<string, number> | ((elem: NestElements) => NestElements)
|
|
12
|
-
components: Record<string, Record<string, any>>
|
|
13
|
-
componentsMap: Record<string, string>
|
|
14
|
-
syncApis: string[]
|
|
15
|
-
asyncApis: string[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default (ctx: IPluginContext, options: IOptions) => {
|
|
19
|
-
const fs = ctx.helper.fs
|
|
20
|
-
|
|
21
|
-
ctx.registerMethod({
|
|
22
|
-
name: 'onSetupClose',
|
|
23
|
-
fn(platform: TaroPlatformBase) {
|
|
24
|
-
const {
|
|
25
|
-
voidComponents,
|
|
26
|
-
nestElements,
|
|
27
|
-
components,
|
|
28
|
-
syncApis,
|
|
29
|
-
asyncApis,
|
|
30
|
-
componentsMap
|
|
31
|
-
} = options
|
|
32
|
-
|
|
33
|
-
const template = platform.template
|
|
34
|
-
|
|
35
|
-
if (isArray(voidComponents)) {
|
|
36
|
-
voidComponents.forEach(el => template.voidElements.add(el))
|
|
37
|
-
} else if (isFunction(voidComponents)) {
|
|
38
|
-
template.voidElements = voidComponents(template.voidElements)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (isObject<NestElements>(nestElements)) {
|
|
42
|
-
for (const key in nestElements) {
|
|
43
|
-
template.nestElements.set(key, nestElements[key])
|
|
44
|
-
}
|
|
45
|
-
} else if (isFunction(nestElements)) {
|
|
46
|
-
template.nestElements = nestElements(template.nestElements)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (components || syncApis || asyncApis || componentsMap) {
|
|
50
|
-
injectRuntimePath(platform)
|
|
51
|
-
|
|
52
|
-
if (components) {
|
|
53
|
-
template.mergeComponents(ctx, components)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (componentsMap) {
|
|
57
|
-
injectComponentsReact(fs, platform.taroComponentsPath, componentsMap)
|
|
58
|
-
platform.taroComponentsPath = `@tarojs/plugin-inject/dist/components-react`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
injectComponents(fs, components)
|
|
62
|
-
injectApis(fs, syncApis, asyncApis)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function injectRuntimePath(platform: TaroPlatformBase) {
|
|
69
|
-
const injectedPath = `@tarojs/plugin-inject/dist/runtime`
|
|
70
|
-
if (isArray(platform.runtimePath)) {
|
|
71
|
-
platform.runtimePath.push(injectedPath)
|
|
72
|
-
} else if (isString(platform.runtimePath)) {
|
|
73
|
-
platform.runtimePath = [platform.runtimePath, injectedPath]
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function injectComponentsReact(fs, taroComponentsPath, componentsMap) {
|
|
78
|
-
fs.writeFileSync(path.resolve(__dirname, '../dist/components-react.js'), `
|
|
79
|
-
export * from '${taroComponentsPath}'
|
|
80
|
-
${Object.keys(componentsMap).map((key) => `export const ${key} = '${componentsMap[key]}'`).join('\n')}
|
|
81
|
-
`)
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function injectComponents(fs, components) {
|
|
85
|
-
fs.writeFileSync(path.resolve(__dirname, '../dist/components.js'), `
|
|
86
|
-
export const components = ${components ? JSON.stringify(components) : JSON.stringify({})};
|
|
87
|
-
`)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function injectApis(fs, syncApis, asyncApis) {
|
|
91
|
-
fs.writeFileSync(path.resolve(__dirname, '../dist/apis-list.js'), `
|
|
92
|
-
export const noPromiseApis = new Set(${syncApis ? JSON.stringify(syncApis) : JSON.stringify([])});
|
|
93
|
-
export const needPromiseApis = new Set(${asyncApis ? JSON.stringify(asyncApis) : JSON.stringify([])});
|
|
94
|
-
`)
|
|
95
|
-
}
|
package/src/runtime.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { mergeReconciler, mergeInternalComponents, processApis } from '@tarojs/shared'
|
|
2
|
-
import { components } from './components'
|
|
3
|
-
import { noPromiseApis, needPromiseApis } from './apis-list'
|
|
4
|
-
|
|
5
|
-
const hostConfig = {
|
|
6
|
-
initNativeApi (taro) {
|
|
7
|
-
const global = taro.miniGlobal
|
|
8
|
-
processApis(taro, global, {
|
|
9
|
-
noPromiseApis,
|
|
10
|
-
needPromiseApis,
|
|
11
|
-
isOnlyPromisify: true
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
mergeReconciler(hostConfig)
|
|
18
|
-
mergeInternalComponents(components)
|