@tarojs/rn-runner 3.5.0-canary.1 → 3.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.
- package/.eslintrc.js +2 -1
- package/__tests__/__snapshots__/components.spec.ts.snap +523 -0
- package/__tests__/build.spec.ts +4 -3
- package/__tests__/components.spec.ts +103 -0
- package/__tests__/config.spec.ts +2 -1
- package/__tests__/global.d.ts +11 -0
- package/__tests__/mock/build_testdata.ts +58 -0
- package/__tests__/mock/{build_testdata.js → components_testdata.ts} +3 -8
- package/__tests__/mock/config/index.js +1 -0
- package/__tests__/mock/src/app.config.ts +13 -0
- package/__tests__/mock/src/app.scss +0 -0
- package/__tests__/mock/src/app.tsx +15 -0
- package/__tests__/mock/src/components/cell/index.scss +25 -0
- package/__tests__/mock/src/components/cell/index.tsx +38 -0
- package/__tests__/mock/src/components/navbar/icon_back.webp +0 -0
- package/__tests__/mock/src/components/navbar/index.scss +29 -0
- package/__tests__/mock/src/components/navbar/index.tsx +36 -0
- package/__tests__/mock/src/components/navbar/resolver.rn.ts +1 -0
- package/__tests__/mock/src/components/navbar/resolver.ts +1 -0
- package/__tests__/mock/src/components/svg/index.tsx +6 -0
- package/__tests__/mock/src/components/svg/rollup-logo.svg +3 -0
- package/__tests__/mock/src/utils/dynamicImport/index.ts +3 -0
- package/__tests__/mock/src/utils/namedExport/index.js +2 -0
- package/__tests__/mock/src/utils/requireLodash/index.ts +5 -0
- package/__tests__/mock/src/utils/requireReactNative/index.js +2 -0
- package/__tests__/tsconfig.json +8 -0
- package/dist/config/build-component.js +162 -0
- package/dist/config/build-component.js.map +1 -0
- package/dist/config/conditional-file-store.js +28 -91
- package/dist/config/conditional-file-store.js.map +1 -1
- package/dist/config/config-holder.js +13 -13
- package/dist/config/config-holder.js.map +1 -1
- package/dist/config/index.js +26 -63
- package/dist/config/index.js.map +1 -1
- package/dist/config/preview.js +28 -28
- package/dist/config/preview.js.map +1 -1
- package/dist/config/terminal-reporter.js +57 -125
- package/dist/config/terminal-reporter.js.map +1 -1
- package/dist/index.js +169 -224
- package/dist/index.js.map +1 -1
- package/dist/utils.js +7 -7
- package/dist/utils.js.map +1 -1
- package/index.js +1 -0
- package/jest.config.js +3 -30
- package/package.json +39 -25
- package/src/config/build-component.ts +171 -0
- package/src/config/config-holder.ts +2 -1
- package/src/config/index.ts +15 -14
- package/src/config/preview.ts +7 -6
- package/src/config/terminal-reporter.ts +3 -3
- package/src/index.ts +36 -25
- package/src/types/index.ts +33 -33
- package/src/utils.ts +1 -1
- package/tsconfig.json +9 -27
package/package.json
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/rn-runner",
|
|
3
|
-
"version": "3.5.0
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "ReactNative build tool for taro",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/NervJS/taro.git"
|
|
9
9
|
},
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"dev": "tsc --watch",
|
|
13
|
-
"lint": "eslint .",
|
|
14
|
-
"test": "jest --silent",
|
|
15
|
-
"test:dev": "jest --watch",
|
|
16
|
-
"test:ci": "jest --silent --coverage false",
|
|
17
|
-
"test:coverage": "jest --coverage"
|
|
18
|
-
},
|
|
19
10
|
"keywords": [
|
|
20
11
|
"taro"
|
|
21
12
|
],
|
|
@@ -30,21 +21,44 @@
|
|
|
30
21
|
"npm": ">=6.0.0"
|
|
31
22
|
},
|
|
32
23
|
"dependencies": {
|
|
33
|
-
"@react-native-community/cli": "^
|
|
34
|
-
"@react-native-community/cli-
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
24
|
+
"@react-native-community/cli": "^7.0.3",
|
|
25
|
+
"@react-native-community/cli-plugin-metro": "^7.0.0",
|
|
26
|
+
"@react-native-community/cli-server-api": "^7.0.0",
|
|
27
|
+
"@rollup/plugin-babel": "^5.3.1",
|
|
28
|
+
"@rollup/plugin-commonjs": "^20.0.0",
|
|
29
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
30
|
+
"@rollup/plugin-node-resolve": "^13.3.0",
|
|
31
|
+
"@rollup/plugin-replace": "^4.0.0",
|
|
32
|
+
"@tarojs/helper": "3.5.0",
|
|
33
|
+
"@tarojs/rn-style-transformer": "3.5.0",
|
|
34
|
+
"@tarojs/rn-supporter": "3.5.0",
|
|
35
|
+
"@tarojs/rn-transformer": "3.5.0",
|
|
36
|
+
"acorn-jsx": "^5.3.2",
|
|
39
37
|
"fs-extra": "^8.0.1",
|
|
40
38
|
"lodash": "^4.17.21",
|
|
41
|
-
"metro": "^0.
|
|
42
|
-
"metro-cache": "^0.
|
|
43
|
-
"metro-config": "^0.
|
|
44
|
-
"metro-core": "^0.
|
|
45
|
-
"metro-react-native-babel-transformer": "^0.
|
|
46
|
-
"metro-resolver": "^0.
|
|
47
|
-
"
|
|
39
|
+
"metro": "^0.67.0",
|
|
40
|
+
"metro-cache": "^0.67.0",
|
|
41
|
+
"metro-config": "^0.67.0",
|
|
42
|
+
"metro-core": "^0.67.0",
|
|
43
|
+
"metro-react-native-babel-transformer": "^0.67.0",
|
|
44
|
+
"metro-resolver": "^0.67.0",
|
|
45
|
+
"mime-types": "^2.1.27",
|
|
46
|
+
"qrcode-terminal": "^0.12.0",
|
|
47
|
+
"rollup-plugin-clear": "^2.0.7",
|
|
48
|
+
"rollup-plugin-image-file": "^1.0.2"
|
|
48
49
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"expo-file-system": "~14.0.0",
|
|
52
|
+
"react-is": "^16.13.0",
|
|
53
|
+
"react-native-root-siblings": "^4.1.1"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsc",
|
|
57
|
+
"dev": "tsc --watch",
|
|
58
|
+
"lint": "eslint .",
|
|
59
|
+
"test": "jest --silent",
|
|
60
|
+
"test:dev": "jest --watch",
|
|
61
|
+
"test:ci": "jest --silent --coverage false",
|
|
62
|
+
"test:coverage": "jest --coverage"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { merge } from 'lodash'
|
|
2
|
+
|
|
2
3
|
import { Config, RNConfig } from '../types'
|
|
3
4
|
|
|
4
5
|
const fs = require('fs')
|
|
@@ -66,4 +67,4 @@ const getRNConfigBabelPlugin = () => {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
export { getConfig, getRNConfig, getRNConfigEntry, getRNConfigOutput, getRNConfigTransformer
|
|
70
|
+
export { getConfig, getRNConfig, getRNConfigBabelPlugin, getRNConfigEntry, getRNConfigOutput, getRNConfigTransformer }
|
package/src/config/index.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import findProjectRoot from '@react-native-community/cli/build/tools/config/findProjectRoot'
|
|
2
|
+
import resolveReactNativePath from '@react-native-community/cli/build/tools/config/resolveReactNativePath'
|
|
3
|
+
import { Supporter } from '@tarojs/rn-supporter'
|
|
1
4
|
import * as Metro from 'metro'
|
|
2
5
|
import * as os from 'os'
|
|
3
6
|
import * as path from 'path'
|
|
4
|
-
|
|
5
|
-
import findProjectRoot from '@react-native-community/cli/build/tools/config/findProjectRoot'
|
|
6
|
-
import * as Supporter from '@tarojs/rn-supporter'
|
|
7
|
+
|
|
7
8
|
import ConditionalFileStore from './conditional-file-store'
|
|
8
9
|
|
|
9
10
|
const reactNativePath: string = resolveReactNativePath(findProjectRoot())
|
|
@@ -13,21 +14,21 @@ type GetModulesRunBeforeMainModuleFunc = () => any
|
|
|
13
14
|
type GetPolyfillsFunc = () => any
|
|
14
15
|
interface MetroConfig {
|
|
15
16
|
transformer: {
|
|
16
|
-
dynamicDepsInPackages: string
|
|
17
|
-
babelTransformerPath: string
|
|
18
|
-
assetRegistryPath: string
|
|
19
|
-
}
|
|
17
|
+
dynamicDepsInPackages: string
|
|
18
|
+
babelTransformerPath: string
|
|
19
|
+
assetRegistryPath: string
|
|
20
|
+
}
|
|
20
21
|
resolver: {
|
|
21
|
-
sourceExts: string[]
|
|
22
|
-
resolveRequest?: ResolveRequestFunc
|
|
23
|
-
}
|
|
22
|
+
sourceExts: string[]
|
|
23
|
+
resolveRequest?: ResolveRequestFunc
|
|
24
|
+
}
|
|
24
25
|
serializer: {
|
|
25
|
-
getModulesRunBeforeMainModule: GetModulesRunBeforeMainModuleFunc
|
|
26
|
+
getModulesRunBeforeMainModule: GetModulesRunBeforeMainModuleFunc
|
|
26
27
|
getPolyfills: GetPolyfillsFunc
|
|
27
|
-
}
|
|
28
|
-
cacheStores: ConditionalFileStore<any>[]
|
|
28
|
+
}
|
|
29
|
+
cacheStores: ConditionalFileStore<any>[]
|
|
29
30
|
server: {
|
|
30
|
-
port: number
|
|
31
|
+
port: number
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
package/src/config/preview.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import * as mime from 'mime-types'
|
|
2
|
-
import { createServer } from 'http'
|
|
3
1
|
import { readFile } from 'fs'
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
2
|
+
import { createServer } from 'http'
|
|
3
|
+
import * as mime from 'mime-types'
|
|
4
|
+
import { extname, join } from 'path'
|
|
5
|
+
import * as qr from 'qrcode-terminal'
|
|
6
6
|
import { URL } from 'url'
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
import { getOpenHost, PLAYGROUNDINFO } from '../utils'
|
|
8
9
|
|
|
9
10
|
interface PreviewOption {
|
|
10
11
|
out: string
|
|
@@ -109,5 +110,5 @@ export default (opt: PreviewOption):void => {
|
|
|
109
110
|
const url = `${host}/index.js`
|
|
110
111
|
console.log(PLAYGROUNDINFO)
|
|
111
112
|
console.log(`print qrcode of ${opt.platform} bundle '${url}':`)
|
|
112
|
-
generate(url, { small: true })
|
|
113
|
+
qr.generate(url, { small: true })
|
|
113
114
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { emptyModulePath } from '@tarojs/rn-supporter'
|
|
2
2
|
import * as MetroTerminalReporter from 'metro/src/lib/TerminalReporter'
|
|
3
|
-
import
|
|
3
|
+
import { Terminal } from 'metro-core'
|
|
4
4
|
|
|
5
5
|
export class TerminalReporter {
|
|
6
6
|
_reporter: any
|
|
@@ -38,7 +38,7 @@ export class TerminalReporter {
|
|
|
38
38
|
break
|
|
39
39
|
case 'bundle_build_done': {
|
|
40
40
|
this._reporter.update(args)
|
|
41
|
-
const realEntryPath =
|
|
41
|
+
const realEntryPath = require.resolve(emptyModulePath)
|
|
42
42
|
if (this._initialized) {
|
|
43
43
|
// 恢复入口页面的缓存
|
|
44
44
|
this._reporter.ignoreEntryFileCache = false
|
package/src/index.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { getRNConfigEntry } from './config/config-holder'
|
|
4
|
-
import { getOpenHost, PLAYGROUNDINFO } from './utils'
|
|
5
|
-
import preview from './config/preview'
|
|
6
|
-
|
|
1
|
+
import saveAssets from '@react-native-community/cli-plugin-metro/build/commands/bundle/saveAssets'
|
|
2
|
+
import { createDevServerMiddleware } from '@react-native-community/cli-server-api'
|
|
7
3
|
import { PLATFORMS } from '@tarojs/helper'
|
|
8
|
-
import * as path from 'path'
|
|
9
4
|
import * as fse from 'fs-extra'
|
|
10
|
-
import * as
|
|
11
|
-
import { generate } from 'qrcode-terminal'
|
|
12
|
-
|
|
13
|
-
import * as readline from 'readline'
|
|
14
|
-
import { createDevServerMiddleware } from '@react-native-community/cli-server-api'
|
|
15
|
-
import { TerminalReporter } from './config/terminal-reporter'
|
|
5
|
+
import * as Metro from 'metro'
|
|
16
6
|
import { getResolveDependencyFn } from 'metro/src/lib/transformHelpers'
|
|
17
7
|
import * as Server from 'metro/src/Server'
|
|
18
|
-
import saveAssets from '@react-native-community/cli/build/commands/bundle/saveAssets'
|
|
19
8
|
import * as outputBundle from 'metro/src/shared/output/bundle'
|
|
9
|
+
import * as path from 'path'
|
|
10
|
+
import * as qr from 'qrcode-terminal'
|
|
11
|
+
import * as readline from 'readline'
|
|
12
|
+
import * as url from 'url'
|
|
13
|
+
|
|
14
|
+
import getMetroConfig from './config'
|
|
15
|
+
import buildComponent from './config/build-component'
|
|
16
|
+
import { getRNConfigEntry } from './config/config-holder'
|
|
17
|
+
import preview from './config/preview'
|
|
18
|
+
import { TerminalReporter } from './config/terminal-reporter'
|
|
19
|
+
import { getOpenHost, PLAYGROUNDINFO } from './utils'
|
|
20
20
|
|
|
21
21
|
function concatOutputFileName (config: any): string {
|
|
22
22
|
// 优先级:--bundle-output > config.output > config.outputRoot
|
|
@@ -78,7 +78,7 @@ function getOutputSourceMapOption (config: any): Record<string, any> {
|
|
|
78
78
|
// TODO: 返回值
|
|
79
79
|
// HttpServer | {code: string, map: string}
|
|
80
80
|
// IBuildConfig
|
|
81
|
-
export default async function build (
|
|
81
|
+
export default async function build (_appPath: string, config: any): Promise<any> {
|
|
82
82
|
process.env.TARO_ENV = PLATFORMS.RN
|
|
83
83
|
// TODO:新增环境变量是否可以在metro构建过程中可以访问到?
|
|
84
84
|
const entry = getRNConfigEntry()
|
|
@@ -109,7 +109,12 @@ export default async function build (appPath: string, config: any): Promise<any>
|
|
|
109
109
|
if (error instanceof Error) throw error
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
if (config.
|
|
112
|
+
if (config.isBuildNativeComp) {
|
|
113
|
+
return buildComponent(
|
|
114
|
+
_appPath,
|
|
115
|
+
config
|
|
116
|
+
)
|
|
117
|
+
} else if (config.isWatch) {
|
|
113
118
|
if (!metroConfig.server || (metroConfig.server.useGlobalHotkey === undefined)) {
|
|
114
119
|
if (!metroConfig.server) {
|
|
115
120
|
metroConfig.server = {}
|
|
@@ -120,7 +125,11 @@ export default async function build (appPath: string, config: any): Promise<any>
|
|
|
120
125
|
metroConfig.server.port = config.port
|
|
121
126
|
}
|
|
122
127
|
|
|
123
|
-
const {
|
|
128
|
+
const {
|
|
129
|
+
middleware,
|
|
130
|
+
messageSocketEndpoint,
|
|
131
|
+
websocketEndpoints
|
|
132
|
+
} = createDevServerMiddleware({
|
|
124
133
|
port: metroConfig.server.port,
|
|
125
134
|
watchFolders: metroConfig.watchFolders
|
|
126
135
|
})
|
|
@@ -145,22 +154,21 @@ export default async function build (appPath: string, config: any): Promise<any>
|
|
|
145
154
|
// 支持host
|
|
146
155
|
return Metro.runServer(metroConfig, {
|
|
147
156
|
...commonOptions,
|
|
148
|
-
hmrEnabled: true
|
|
157
|
+
hmrEnabled: true,
|
|
158
|
+
websocketEndpoints
|
|
149
159
|
}).then(server => {
|
|
150
160
|
console.log(`React-Native Dev server is running on port: ${metroConfig.server.port}`)
|
|
151
161
|
console.log('\n\nTo reload the app press "r"\nTo open developer menu press "d"\n')
|
|
152
162
|
|
|
153
|
-
const { messageSocket } = attachToServer(server)
|
|
154
|
-
|
|
155
163
|
readline.emitKeypressEvents(process.stdin)
|
|
156
164
|
process.stdin.setRawMode && process.stdin.setRawMode(true)
|
|
157
|
-
process.stdin.on('keypress', (
|
|
165
|
+
process.stdin.on('keypress', (_key, data) => {
|
|
158
166
|
const { ctrl, name } = data
|
|
159
167
|
if (name === 'r') {
|
|
160
|
-
|
|
168
|
+
messageSocketEndpoint.broadcast('reload')
|
|
161
169
|
console.log('Reloading app...')
|
|
162
170
|
} else if (name === 'd') {
|
|
163
|
-
|
|
171
|
+
messageSocketEndpoint.broadcast('devMenu')
|
|
164
172
|
console.log('Opening developer menu...')
|
|
165
173
|
} else if (ctrl && (name === 'c')) {
|
|
166
174
|
process.exit()
|
|
@@ -173,7 +181,7 @@ export default async function build (appPath: string, config: any): Promise<any>
|
|
|
173
181
|
const url = `taro://${host}:${metroConfig.server.port}`
|
|
174
182
|
console.log(PLAYGROUNDINFO)
|
|
175
183
|
console.log(`print qrcode of '${url}':`)
|
|
176
|
-
generate(url, { small: true })
|
|
184
|
+
qr.generate(url, { small: true })
|
|
177
185
|
} else {
|
|
178
186
|
console.log('print qrcode error: host not found.')
|
|
179
187
|
}
|
|
@@ -192,7 +200,10 @@ export default async function build (appPath: string, config: any): Promise<any>
|
|
|
192
200
|
const savedBuildFunc = outputBundle.build
|
|
193
201
|
outputBundle.build = async (packagerClient, requestOptions) => {
|
|
194
202
|
const resolutionFn = await getResolveDependencyFn(packagerClient.getBundler().getBundler(), requestOptions.platform)
|
|
195
|
-
|
|
203
|
+
// try for test case build_noWatch
|
|
204
|
+
try {
|
|
205
|
+
requestOptions.entryFile = resolutionFn(metroConfig.projectRoot, requestOptions.entryFile)
|
|
206
|
+
} catch (e) {}
|
|
196
207
|
return savedBuildFunc(packagerClient, requestOptions)
|
|
197
208
|
}
|
|
198
209
|
|
package/src/types/index.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
1
|
// https://taro-docs.jd.com/taro/docs/config-detail/
|
|
2
2
|
interface Output {
|
|
3
|
-
android: string
|
|
3
|
+
android: string
|
|
4
4
|
ios: string
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
interface Copy {
|
|
8
|
-
patterns: []
|
|
8
|
+
patterns: []
|
|
9
9
|
options: Record<string, any>
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
interface Csso {
|
|
13
|
-
enable: boolean
|
|
13
|
+
enable: boolean
|
|
14
14
|
config: Record<string, any>
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
interface Sass {
|
|
18
|
-
resource: []
|
|
19
|
-
projectDirectory: string
|
|
18
|
+
resource: []
|
|
19
|
+
projectDirectory: string
|
|
20
20
|
data: string
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface Config {
|
|
24
|
-
projectName?: string
|
|
25
|
-
date?: string
|
|
26
|
-
designWidth?: number
|
|
27
|
-
deviceRatio?: Record<string, any
|
|
28
|
-
sourceRoot?: string
|
|
29
|
-
outputRoot?: string
|
|
30
|
-
defineConstants?: Record<string, any
|
|
31
|
-
alias?: Record<string, any
|
|
32
|
-
env?: Record<string, any
|
|
33
|
-
sass?: Sass
|
|
34
|
-
copy?: Copy
|
|
35
|
-
plugins?: []
|
|
36
|
-
presets?: []
|
|
37
|
-
terser?: Record<string, any
|
|
38
|
-
csso?: Csso
|
|
39
|
-
framework?: Record<string, any
|
|
40
|
-
mini?: Record<string, any
|
|
41
|
-
h5?: Record<string, any
|
|
42
|
-
rn?: Record<string, any
|
|
24
|
+
projectName?: string
|
|
25
|
+
date?: string
|
|
26
|
+
designWidth?: number
|
|
27
|
+
deviceRatio?: Record<string, any>
|
|
28
|
+
sourceRoot?: string
|
|
29
|
+
outputRoot?: string
|
|
30
|
+
defineConstants?: Record<string, any>
|
|
31
|
+
alias?: Record<string, any>
|
|
32
|
+
env?: Record<string, any>
|
|
33
|
+
sass?: Sass
|
|
34
|
+
copy?: Copy
|
|
35
|
+
plugins?: []
|
|
36
|
+
presets?: []
|
|
37
|
+
terser?: Record<string, any>
|
|
38
|
+
csso?: Csso
|
|
39
|
+
framework?: Record<string, any>
|
|
40
|
+
mini?: Record<string, any>
|
|
41
|
+
h5?: Record<string, any>
|
|
42
|
+
rn?: Record<string, any>
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export interface RNConfig extends Config {
|
|
46
|
-
appName?: boolean
|
|
47
|
-
entry?: string
|
|
48
|
-
output?: Output
|
|
49
|
-
sourceDir?: string
|
|
50
|
-
postcss?: Record<string, any
|
|
51
|
-
less?: Record<string, any
|
|
52
|
-
stylus?: Record<string, any
|
|
53
|
-
transformer?: any
|
|
54
|
-
babelPlugin?: any
|
|
46
|
+
appName?: boolean
|
|
47
|
+
entry?: string
|
|
48
|
+
output?: Output
|
|
49
|
+
sourceDir?: string
|
|
50
|
+
postcss?: Record<string, any>
|
|
51
|
+
less?: Record<string, any>
|
|
52
|
+
stylus?: Record<string, any>
|
|
53
|
+
transformer?: any
|
|
54
|
+
babelPlugin?: any
|
|
55
55
|
}
|
package/src/utils.ts
CHANGED
|
@@ -6,7 +6,7 @@ export function getOpenHost () {
|
|
|
6
6
|
for (const devName in interfaces) {
|
|
7
7
|
const isEnd = interfaces[devName]?.some(item => {
|
|
8
8
|
// 取IPv4, 不为127.0.0.1的内网ip
|
|
9
|
-
if (
|
|
9
|
+
if (['IPv4', 4, '4'].includes(item.family) && item.address !== '127.0.0.1' && !item.internal) {
|
|
10
10
|
result = item.address
|
|
11
11
|
return true
|
|
12
12
|
}
|
package/tsconfig.json
CHANGED
|
@@ -1,28 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"noImplicitAny": false,
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"downlevelIteration": true,
|
|
14
|
-
"moduleResolution": "node",
|
|
15
|
-
"target": "es5",
|
|
16
|
-
"skipLibCheck": true,
|
|
17
|
-
"lib": [
|
|
18
|
-
"ES2015",
|
|
19
|
-
],
|
|
20
|
-
"types": [
|
|
21
|
-
"node"
|
|
22
|
-
],
|
|
23
|
-
"typeRoots": [
|
|
24
|
-
"./node_modules",
|
|
25
|
-
"./src/types"
|
|
26
|
-
]
|
|
27
|
-
}
|
|
28
|
-
}
|
|
2
|
+
"extends": "../../tsconfig.root.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"jsx": "react",
|
|
5
|
+
"outDir": "./dist",
|
|
6
|
+
"sourceMap": true,
|
|
7
|
+
"module": "commonjs"
|
|
8
|
+
},
|
|
9
|
+
"include": ["./src"]
|
|
10
|
+
}
|