@tarojs/rn-runner 3.5.0-beta.4 → 3.5.0-theta.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/.eslintrc.js +1 -2
- package/__tests__/mock/config/index.js +0 -1
- package/dist/index.js +3 -7
- package/dist/index.js.map +1 -1
- package/package.json +8 -16
- package/src/config/index.ts +11 -11
- package/src/index.ts +3 -14
- package/tsconfig.json +1 -1
- package/LICENSE +0 -21
- package/__tests__/__snapshots__/components.spec.ts.snap +0 -523
- package/__tests__/components.spec.ts +0 -103
- package/__tests__/global.d.ts +0 -11
- package/__tests__/mock/components_testdata.ts +0 -58
- package/__tests__/mock/src/app.config.ts +0 -13
- package/__tests__/mock/src/app.scss +0 -0
- package/__tests__/mock/src/app.tsx +0 -15
- package/__tests__/mock/src/components/cell/index.scss +0 -25
- package/__tests__/mock/src/components/cell/index.tsx +0 -38
- package/__tests__/mock/src/components/navbar/icon_back.webp +0 -0
- package/__tests__/mock/src/components/navbar/index.scss +0 -29
- package/__tests__/mock/src/components/navbar/index.tsx +0 -36
- package/__tests__/mock/src/components/navbar/resolver.rn.ts +0 -1
- package/__tests__/mock/src/components/navbar/resolver.ts +0 -1
- package/__tests__/mock/src/components/svg/index.tsx +0 -6
- package/__tests__/mock/src/components/svg/rollup-logo.svg +0 -3
- package/__tests__/mock/src/utils/dynamicImport/index.ts +0 -3
- package/__tests__/mock/src/utils/namedExport/index.js +0 -3
- package/__tests__/mock/src/utils/requireLodash/index.ts +0 -5
- package/__tests__/mock/src/utils/requireReactNative/index.js +0 -3
- package/__tests__/tsconfig.json +0 -8
- package/dist/config/build-component.js +0 -162
- package/dist/config/build-component.js.map +0 -1
- package/src/config/build-component.ts +0 -171
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
import babel from '@rollup/plugin-babel'
|
|
2
|
-
import * as commonjs from '@rollup/plugin-commonjs'
|
|
3
|
-
import * as json from '@rollup/plugin-json'
|
|
4
|
-
import nodeResolve from '@rollup/plugin-node-resolve'
|
|
5
|
-
import * as pluginReplace from '@rollup/plugin-replace'
|
|
6
|
-
import { recursiveMerge } from '@tarojs/helper'
|
|
7
|
-
import { rollupTransform as styleTransformer } from '@tarojs/rn-style-transformer'
|
|
8
|
-
import { resolveExtFile, rollupResolver as taroResolver } from '@tarojs/rn-supporter'
|
|
9
|
-
import { getAppConfig } from '@tarojs/rn-transformer'
|
|
10
|
-
import * as jsx from 'acorn-jsx'
|
|
11
|
-
import * as path from 'path'
|
|
12
|
-
import { rollup, RollupOptions } from 'rollup'
|
|
13
|
-
import * as clear from 'rollup-plugin-clear'
|
|
14
|
-
import image from 'rollup-plugin-image-file'
|
|
15
|
-
|
|
16
|
-
type ExternalFn = (arr: Array<string | RegExp>) => Array<string | RegExp>
|
|
17
|
-
|
|
18
|
-
interface IComponentConfig {
|
|
19
|
-
input: string[] | string
|
|
20
|
-
output?: string
|
|
21
|
-
sourceRootPath?: string
|
|
22
|
-
external?: Array<string | RegExp> | ExternalFn
|
|
23
|
-
externalResolve?: (importee, importer) => string | null | void
|
|
24
|
-
modifyRollupConfig?: (
|
|
25
|
-
config: RollupOptions,
|
|
26
|
-
innerplugins?: [typeof taroResolver, typeof styleTransformer]
|
|
27
|
-
) => RollupOptions
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const DEFAULT_CONFIG: Pick<
|
|
31
|
-
IComponentConfig,
|
|
32
|
-
'external' | 'output' | 'externalResolve' | 'sourceRootPath' | 'modifyRollupConfig'
|
|
33
|
-
> = {
|
|
34
|
-
external: [/^react(\/.*)?$/, /^react-native(\/.*)?$/, /^@react-native/],
|
|
35
|
-
output: 'dist',
|
|
36
|
-
externalResolve: importee => (likeDependent(importee) ? importee : null),
|
|
37
|
-
sourceRootPath: process.cwd(),
|
|
38
|
-
modifyRollupConfig: config => config
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export const build = async (projectConfig, componentConfig: IComponentConfig) => {
|
|
42
|
-
const mergedConfig = recursiveMerge({ ...DEFAULT_CONFIG }, componentConfig)
|
|
43
|
-
const { input, external, output, externalResolve, sourceRootPath, modifyRollupConfig } = mergedConfig
|
|
44
|
-
|
|
45
|
-
const getInputOption = () => {
|
|
46
|
-
const components: string[] = Array.isArray(input) ? input : [input]
|
|
47
|
-
|
|
48
|
-
const inputOptions = components.reduce((pre, cur) => {
|
|
49
|
-
let absolutePath = cur
|
|
50
|
-
if (!path.isAbsolute(cur)) {
|
|
51
|
-
absolutePath = path.resolve(sourceRootPath, cur)
|
|
52
|
-
}
|
|
53
|
-
const realPath = resolveExtFile({ originModulePath: absolutePath }, absolutePath)
|
|
54
|
-
const relativePath = path
|
|
55
|
-
.relative(sourceRootPath, realPath)
|
|
56
|
-
.replace(/\.(js|ts|jsx|tsx)$/, '')
|
|
57
|
-
.replace(/\.{1,}\//g, '')
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
...pre,
|
|
61
|
-
[relativePath]: realPath
|
|
62
|
-
}
|
|
63
|
-
}, {})
|
|
64
|
-
if (components.length === 1) {
|
|
65
|
-
return {
|
|
66
|
-
index: Object.values(inputOptions)[0]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return inputOptions
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const getExternal = () => {
|
|
73
|
-
if (typeof external === 'function') {
|
|
74
|
-
return external(DEFAULT_CONFIG.external)
|
|
75
|
-
}
|
|
76
|
-
const _external = Array.isArray(external) ? external : [external]
|
|
77
|
-
return _external.filter(Boolean).map(item => {
|
|
78
|
-
if (((item as unknown) as RegExp).test) return item
|
|
79
|
-
const match = (item as string).match(/^\/(.+)\/$/)
|
|
80
|
-
return match ? new RegExp(match[1]) : item
|
|
81
|
-
})
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const rollupOptions: RollupOptions = {
|
|
85
|
-
input: getInputOption(),
|
|
86
|
-
output: {
|
|
87
|
-
format: 'es',
|
|
88
|
-
dir: output
|
|
89
|
-
},
|
|
90
|
-
external: getExternal(),
|
|
91
|
-
// @ts-ignore react native 相关的一些库中可能包含 jsx 语法
|
|
92
|
-
acornInjectPlugins: [jsx()],
|
|
93
|
-
plugins: [
|
|
94
|
-
clear({ targets: [output] }),
|
|
95
|
-
// TODO: 使用 react-native-svg-transformer 处理
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
image({
|
|
98
|
-
extensions: ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.svg', '.svgx']
|
|
99
|
-
}),
|
|
100
|
-
// @ts-ignore
|
|
101
|
-
json(),
|
|
102
|
-
taroResolver({
|
|
103
|
-
externalResolve
|
|
104
|
-
}),
|
|
105
|
-
nodeResolve({
|
|
106
|
-
extensions: ['.mjs', '.js', '.json', '.node', '.ts', '.tsx']
|
|
107
|
-
}),
|
|
108
|
-
// @ts-ignore
|
|
109
|
-
pluginReplace({
|
|
110
|
-
'process.env.NODE_ENV': JSON.stringify('production')
|
|
111
|
-
}),
|
|
112
|
-
// @ts-ignore
|
|
113
|
-
commonjs(),
|
|
114
|
-
babel({
|
|
115
|
-
babelHelpers: 'runtime',
|
|
116
|
-
presets: [
|
|
117
|
-
[
|
|
118
|
-
'babel-preset-taro',
|
|
119
|
-
{
|
|
120
|
-
framework: 'react',
|
|
121
|
-
ts: true,
|
|
122
|
-
reactJsxRuntime: projectConfig.reactJsxRuntime || 'automatic',
|
|
123
|
-
disableImportExportTransform: true
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
],
|
|
127
|
-
extensions: ['js', 'ts', 'jsx', 'tsx']
|
|
128
|
-
}),
|
|
129
|
-
styleTransformer({ config: projectConfig })
|
|
130
|
-
]
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const newRollupOptions = modifyRollupConfig(rollupOptions, {
|
|
134
|
-
taroResolver,
|
|
135
|
-
styleTransformer
|
|
136
|
-
})
|
|
137
|
-
const { output: outputOptions, ...inputOptions } = newRollupOptions
|
|
138
|
-
|
|
139
|
-
let bundle
|
|
140
|
-
try {
|
|
141
|
-
bundle = await rollup(inputOptions)
|
|
142
|
-
|
|
143
|
-
const result = await bundle.write(outputOptions)
|
|
144
|
-
return result
|
|
145
|
-
} catch (error) {
|
|
146
|
-
console.error(error)
|
|
147
|
-
}
|
|
148
|
-
if (bundle) {
|
|
149
|
-
await bundle.close()
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function likeDependent (str: string) {
|
|
154
|
-
return !str.match(/^\.?\.\//) && !path.isAbsolute(str)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export default async function (projectPath: string, config: any) {
|
|
158
|
-
const { sourceRoot, entry, nativeComponents } = config
|
|
159
|
-
const appPath = path.join(projectPath, sourceRoot, entry)
|
|
160
|
-
const appConfig = getAppConfig(appPath)
|
|
161
|
-
const { output = DEFAULT_CONFIG.output } = nativeComponents || {}
|
|
162
|
-
|
|
163
|
-
const componentConfig = {
|
|
164
|
-
...nativeComponents,
|
|
165
|
-
input: appConfig?.components,
|
|
166
|
-
output: path.join(projectPath, output),
|
|
167
|
-
sourceRootPath: path.join(projectPath, sourceRoot)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return build(config, componentConfig)
|
|
171
|
-
}
|