babel-preset-taro 4.0.1 → 4.0.2

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 CHANGED
@@ -154,15 +154,8 @@ See `/LICENSE` for details of the license.
154
154
 
155
155
  ==================
156
156
 
157
- MIT (stencil-vue2-output-target):
158
- The following files embed [stencil-vue2-output-target](https://github.com/diondree/stencil-vue2-output-target) MIT:
159
- `/packages/taro-components-library-vue2/src/vue-component-lib/utils.ts`
160
- See `/LICENSE` for details of the license.
161
-
162
- ==================
163
-
164
157
  MIT (weui):
165
- The following files embed [stencil-vue2-output-target](https://github.com/Tencent/weui) MIT:
158
+ The following files embed [weui](https://github.com/Tencent/weui) MIT:
166
159
  `/packages/taro-components/src/components/*.scss`
167
160
  See `/LICENSE.txt` for details of the license.
168
161
 
@@ -172,3 +165,10 @@ Apache-2.0 (intersection-observer):
172
165
  The following files embed [intersection-observer](https://github.com/GoogleChromeLabs/intersection-observer) Apache-2.0:
173
166
  `/packages/taro-api/src/polyfill/intersection-observer.ts`
174
167
  See `/LICENSE.txt` for details of the license.
168
+
169
+ ==================
170
+
171
+ MIT (babel-plugin-jsx-dom-expressions):
172
+ The following files embed [babel-plugin-jsx-dom-expressions](https://github.com/ryansolid/dom-expressions/blob/main/packages/babel-plugin-jsx-dom-expressions) MIT:
173
+ `/packages/babel-plugin-transform-solid-jsx/src/*`
174
+ See `/LICENSE` for details of the license.
package/README.md CHANGED
@@ -43,13 +43,7 @@ module.exports = {
43
43
 
44
44
  - `react-refresh/babel`
45
45
 
46
- #### 3. Vue
47
-
48
- ##### presetes
49
-
50
- - `@vue/babel-preset-jsx`
51
-
52
- #### 4. Vue3
46
+ #### 3. Vue3
53
47
 
54
48
  ##### plugins
55
49
 
@@ -80,16 +74,16 @@ module.exports = {
80
74
  ### vueJsx
81
75
 
82
76
  :::note
83
- 只在使用 **Vue/Vue3** 时生效。
77
+ 只在使用 **Vue3** 时生效。
84
78
  :::
85
79
 
86
80
  **默认值**:`true`
87
81
 
88
82
  **类型**:`true` | `false` | `object`
89
83
 
90
- 是否使用 `@vue/babel-preset-jsx`(Vue)或 `@vue/babel-plugin-jsx`(Vue3)来支持使用 `jsx`。
84
+ 是否使用 `@vue/babel-plugin-jsx` 来支持使用 `jsx`。
91
85
 
92
- 当传入一个 `object` 时,等同于设置为 `true`,且该 `object` 将会作为 `@vue/babel-preset-jsx`(Vue)或 `@vue/babel-plugin-jsx`(Vue3)的参数。
86
+ 当传入一个 `object` 时,等同于设置为 `true`,且该 `object` 将会作为 `@vue/babel-plugin-jsx` 的参数。
93
87
 
94
88
  ### targets
95
89
 
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const path = require('path')
2
2
 
3
- function hasBrowserslist () {
3
+ function hasBrowserslist() {
4
4
  const fs = require('@tarojs/helper').fs
5
5
  const root = process.cwd()
6
6
  try {
@@ -28,64 +28,76 @@ module.exports = (_, options = {}) => {
28
28
  const presets = []
29
29
  const plugins = []
30
30
  const overrides = []
31
- const isReact = options.framework === 'react' || options.framework === 'preact'
32
- const isNerv = options.framework === 'nerv'
33
- const isVue = options.framework === 'vue'
34
- const isVue3 = options.framework === 'vue3'
31
+ const isVite = options.compiler === 'vite'
32
+ // vite 不需要 react preset,在内部已经处理了
33
+ const isReact = options.framework === 'react' || options.framework === 'preact' && !isVite
34
+ // vite 不需要 solid preset,在内部已经处理了
35
+ const isSolid = options.framework === 'solid' && !isVite
36
+ // vite 不需要 vue 的 preset,在内部已经处理了
37
+ const isVue3 = options.framework === 'vue3' && !isVite
38
+ // vite 不需要使用 babel 处理 ts,在 esbuild 中处理了
39
+ const isTs = options.ts && !isVite
35
40
  const moduleName = options.framework.charAt(0).toUpperCase() + options.framework.slice(1)
36
41
  const presetReactConfig = options.react || {}
37
42
 
38
- if (isNerv) {
39
- presets.push([require('@babel/preset-react'), {
40
- pragma: `${moduleName}.createElement`,
41
- pragmaFrag: `${moduleName}.Fragment`,
42
- ...presetReactConfig
43
- }])
44
- }
45
-
46
43
  if (isReact) {
47
- presets.push([require('@babel/preset-react'), {
48
- runtime: options.reactJsxRuntime || 'automatic',
49
- ...presetReactConfig
50
- }])
44
+ presets.push([
45
+ require('@babel/preset-react'),
46
+ {
47
+ runtime: options.reactJsxRuntime || 'automatic',
48
+ ...presetReactConfig,
49
+ },
50
+ ])
51
51
  if (process.env.TARO_PLATFORM === 'web' && process.env.NODE_ENV !== 'production' && options.hot !== false) {
52
52
  if (options.framework === 'react') {
53
53
  plugins.push([require('react-refresh/babel'), { skipEnvCheck: true }])
54
54
  } else if (options.framework === 'preact') {
55
55
  overrides.push({
56
56
  include: /\.[jt]sx$/,
57
- plugins: [require('@prefresh/babel-plugin')]
57
+ plugins: [require('@prefresh/babel-plugin')],
58
58
  })
59
59
  }
60
60
  }
61
+ } else if (isSolid) {
62
+ const solidOptions = {}
63
+ if (process.env.TARO_PLATFORM !== 'web') {
64
+ Object.assign(solidOptions, {
65
+ moduleName: '@tarojs/plugin-framework-solid/dist/reconciler',
66
+ generate: 'universal',
67
+ uniqueTransform: true,
68
+ })
69
+ }
70
+ presets.push([
71
+ require('babel-plugin-transform-solid-jsx'),
72
+ solidOptions,
73
+ ])
61
74
  }
62
75
 
63
- if (isVue || isVue3) {
76
+ if (isVue3) {
64
77
  if (options.vueJsx !== false) {
65
78
  const jsxOptions = typeof options.vueJsx === 'object' ? options.vueJsx : {}
66
- if (isVue) {
67
- presets.push([require('@vue/babel-preset-jsx'), jsxOptions])
68
- } else {
69
- plugins.push([require('@vue/babel-plugin-jsx'), jsxOptions])
70
- }
79
+ plugins.push([require('@vue/babel-plugin-jsx'), jsxOptions])
71
80
  }
72
81
  }
73
82
 
74
- if (options.ts) {
83
+ if (isTs) {
75
84
  const config = typeof options.ts === 'object' ? options.ts : {}
76
- if (isNerv || isReact) {
85
+ if (isReact) {
77
86
  config.jsxPragma = moduleName
78
87
  }
79
- if (isVue || isVue3) {
88
+ if (isVue3) {
80
89
  overrides.push({
81
90
  include: /\.vue$/,
82
- presets: [[require('@babel/preset-typescript'), { allExtensions: true, isTSX: true }]]
91
+ presets: [[require('@babel/preset-typescript'), { allExtensions: true, isTSX: true }]],
83
92
  })
84
93
  }
85
94
  presets.push([require('@babel/preset-typescript'), config])
86
95
  }
87
96
 
88
- const runtimePath = process.env.NODE_ENV === 'jest' || process.env.NODE_ENV === 'test' ? false : path.dirname(require.resolve('@babel/runtime/package.json'))
97
+ const runtimePath =
98
+ process.env.NODE_ENV === 'jest' || process.env.NODE_ENV === 'test'
99
+ ? false
100
+ : path.dirname(require.resolve('@babel/runtime/package.json'))
89
101
  const runtimeVersion = require('@babel/runtime/package.json').version
90
102
  const {
91
103
  loose = false,
@@ -115,7 +127,7 @@ module.exports = (_, options = {}) => {
115
127
  // By default transform-runtime assumes that @babel/runtime@7.0.0-beta.0 is installed, which means helpers introduced later than 7.0.0-beta.0 will be inlined instead of imported.
116
128
  // See https://github.com/babel/babel/issues/10261
117
129
  // And https://github.com/facebook/docusaurus/pull/2111
118
- version = runtimeVersion
130
+ version = runtimeVersion,
119
131
  } = options
120
132
 
121
133
  // resolve targets
@@ -127,7 +139,7 @@ module.exports = (_, options = {}) => {
127
139
  } else if (!hasBrowserslist()) {
128
140
  targets = {
129
141
  ios: '9',
130
- android: '5'
142
+ android: '5',
131
143
  }
132
144
  }
133
145
 
@@ -142,7 +154,7 @@ module.exports = (_, options = {}) => {
142
154
  include,
143
155
  exclude,
144
156
  shippedProposals,
145
- forceAllTransforms
157
+ forceAllTransforms,
146
158
  }
147
159
 
148
160
  let transformRuntimeCorejs = false
@@ -162,23 +174,33 @@ module.exports = (_, options = {}) => {
162
174
  presets.unshift([require('@babel/preset-env'), envOptions])
163
175
 
164
176
  plugins.push(
165
- [require('@babel/plugin-proposal-decorators'), {
166
- decoratorsBeforeExport,
167
- legacy: decoratorsLegacy !== false
168
- }],
177
+ [
178
+ require('@babel/plugin-proposal-decorators'),
179
+ {
180
+ decoratorsBeforeExport,
181
+ legacy: decoratorsLegacy !== false,
182
+ },
183
+ ],
169
184
  [require('@babel/plugin-proposal-class-properties'), { loose }]
170
185
  )
171
186
 
172
- plugins.push([require('@babel/plugin-transform-runtime'), {
173
- regenerator: true,
174
- corejs: transformRuntimeCorejs,
175
- helpers: true,
176
- useESModules: process.env.NODE_ENV !== 'test',
177
- absoluteRuntime,
178
- version
179
- }])
180
-
181
- if (typeof options['dynamic-import-node'] === 'boolean' ? options['dynamic-import-node'] : process.env.TARO_PLATFORM !== 'web') {
187
+ plugins.push([
188
+ require('@babel/plugin-transform-runtime'),
189
+ {
190
+ regenerator: true,
191
+ corejs: transformRuntimeCorejs,
192
+ helpers: true,
193
+ useESModules: process.env.NODE_ENV !== 'test',
194
+ absoluteRuntime,
195
+ version,
196
+ },
197
+ ])
198
+
199
+ if (
200
+ typeof options['dynamic-import-node'] === 'boolean'
201
+ ? options['dynamic-import-node']
202
+ : process.env.TARO_PLATFORM !== 'web'
203
+ ) {
182
204
  plugins.push([require('babel-plugin-dynamic-import-node')])
183
205
  }
184
206
 
@@ -186,10 +208,13 @@ module.exports = (_, options = {}) => {
186
208
 
187
209
  return {
188
210
  sourceType: 'unambiguous',
189
- overrides: [{
190
- exclude: [/@babel[/|\\\\]runtime/, /core-js/, /\bwebpack\/buildin\b/],
191
- presets,
192
- plugins
193
- }, ...overrides]
211
+ overrides: [
212
+ {
213
+ exclude: [/@babel[/|\\\\]runtime/, /core-js/, /\bwebpack\/buildin\b/],
214
+ presets,
215
+ plugins,
216
+ },
217
+ ...overrides,
218
+ ],
194
219
  }
195
220
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "babel-preset-taro",
3
- "version": "4.0.1",
3
+ "version": "4.0.2",
4
4
  "description": "Taro babel preset",
5
- "author": "yuche <i@yuche.me>",
6
- "homepage": "https://github.com/nervjs/taro/tree/master/packages/babel-preset-taro#readme",
5
+ "author": "O2Team",
7
6
  "license": "MIT",
7
+ "homepage": "https://github.com/nervjs/taro/tree/main/packages/babel-preset-taro#readme",
8
8
  "main": "index.js",
9
9
  "files": [
10
10
  "rn/",
@@ -18,42 +18,65 @@
18
18
  "bugs": {
19
19
  "url": "https://github.com/NervJS/taro/issues"
20
20
  },
21
+ "engines": {
22
+ "node": ">= 18"
23
+ },
21
24
  "dependencies": {
22
- "@babel/plugin-proposal-class-properties": "^7.14.5",
23
- "@babel/plugin-proposal-decorators": "^7.14.5",
24
- "@babel/plugin-syntax-jsx": "^7.14.5",
25
- "@babel/plugin-transform-runtime": "^7.14.5",
26
- "@babel/preset-env": "^7.14.5",
27
- "@babel/preset-react": "^7.14.5",
28
- "@babel/preset-typescript": "^7.14.5",
29
- "@babel/runtime": "^7.14.5",
30
- "@babel/runtime-corejs3": "^7.14.5",
31
- "babel-plugin-dynamic-import-node": "2.3.3",
25
+ "@babel/plugin-proposal-decorators": "^7.24.1",
26
+ "@babel/plugin-transform-class-properties": "^7.24.1",
27
+ "@babel/plugin-transform-runtime": "^7.24.3",
28
+ "@babel/preset-env": "^7.24.4",
29
+ "@babel/preset-typescript": "^7.24.1",
30
+ "@babel/runtime": "^7.24.4",
31
+ "@babel/runtime-corejs3": "^7.24.4",
32
+ "@rnx-kit/babel-preset-metro-react-native": "^1.1.8",
33
+ "babel-plugin-dynamic-import-node": "^2.3.3",
32
34
  "babel-plugin-minify-dead-code-elimination": "^0.5.2",
33
35
  "babel-plugin-transform-imports-api": "1.0.0",
34
- "core-js": "^3.6.5",
35
- "lodash": "^4.17.21",
36
- "metro-react-native-babel-preset": "^0.72.1",
37
- "react-refresh": "^0.11.0",
38
- "@tarojs/helper": "4.0.1"
36
+ "core-js": "^3.36.1",
37
+ "@tarojs/helper": "4.0.2",
38
+ "babel-plugin-transform-solid-jsx": "4.0.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@babel/core": "^7.14.5",
42
- "@prefresh/babel-plugin": "^0.4.1",
43
- "@vue/babel-plugin-jsx": "^1.0.6",
44
- "@vue/babel-preset-jsx": "^1.2.4",
45
- "jest": "^29.3.1",
46
- "jest-cli": "^29.3.1",
47
- "jest-environment-node": "^29.5.0",
48
- "ts-jest": "^29.0.5",
49
- "typescript": "^4.7.4",
50
- "@tarojs/shared": "4.0.1"
41
+ "@babel/core": "^7.24.4",
42
+ "@babel/preset-react": "^7.24.1",
43
+ "@prefresh/babel-plugin": "^0.5.1",
44
+ "@vue/babel-plugin-jsx": "^1.2.2",
45
+ "babel-preset-solid": "^1.8.16",
46
+ "react-refresh": "^0.14.0",
47
+ "@tarojs/taro-rn": "4.0.2"
51
48
  },
52
49
  "peerDependencies": {
53
- "@babel/core": "*"
50
+ "@babel/core": "^7.0.0",
51
+ "@babel/preset-react": "^7.24.1",
52
+ "@prefresh/babel-plugin": "^0.5.1",
53
+ "@vue/babel-plugin-jsx": "^1.2.2",
54
+ "babel-preset-solid": "^1.8.16",
55
+ "react-refresh": "^0.14.0",
56
+ "@tarojs/taro-rn": "4.0.2"
57
+ },
58
+ "peerDependenciesMeta": {
59
+ "@babel/preset-react": {
60
+ "optional": true
61
+ },
62
+ "react-refresh": {
63
+ "optional": true
64
+ },
65
+ "@prefresh/babel-plugin": {
66
+ "optional": true
67
+ },
68
+ "babel-preset-solid": {
69
+ "optional": true
70
+ },
71
+ "@vue/babel-plugin-jsx": {
72
+ "optional": true
73
+ },
74
+ "@tarojs/taro-rn": {
75
+ "optional": true
76
+ }
54
77
  },
55
78
  "scripts": {
56
- "test": "jest --collectCoverage",
79
+ "test": "jest",
57
80
  "test:ci": "jest --ci -i --coverage --silent"
58
81
  }
59
82
  }
package/rn/index.js CHANGED
@@ -1,6 +1,9 @@
1
- const reactNativeBabelPreset = require('metro-react-native-babel-preset')
1
+ const reactNativeBabelPreset = require('@rnx-kit/babel-preset-metro-react-native')
2
2
 
3
3
  module.exports = (_, options = {}) => {
4
+ if (!process.env.NODE_ENV) {
5
+ process.env.NODE_ENV = 'development'
6
+ }
4
7
  const {
5
8
  decoratorsBeforeExport,
6
9
  decoratorsLegacy