@tarojs/rn-runner 3.5.0-alpha.13 → 3.5.0-alpha.16
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 +3 -3
- package/__tests__/components.spec.ts +103 -0
- package/__tests__/config.spec.ts +1 -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} +4 -9
- 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/config-holder.js +1 -1
- package/dist/config/config-holder.js.map +1 -1
- package/dist/config/index.js +4 -4
- package/dist/config/index.js.map +1 -1
- package/dist/config/preview.js +6 -6
- package/dist/config/preview.js.map +1 -1
- package/dist/config/terminal-reporter.js +3 -3
- package/dist/config/terminal-reporter.js.map +1 -1
- package/dist/index.js +26 -19
- package/dist/index.js.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +1 -1
- package/index.js +1 -0
- package/jest.config.js +3 -30
- package/package.json +38 -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 +33 -22
- package/src/types/index.ts +33 -33
- package/src/utils.ts +1 -1
- package/tsconfig.json +3 -5
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 * as qr 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-plugin-metro/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
|
|
@@ -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
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()
|
|
@@ -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,12 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../tsconfig.root.json",
|
|
3
3
|
"compilerOptions": {
|
|
4
|
-
"
|
|
4
|
+
"jsx": "react",
|
|
5
5
|
"outDir": "./dist",
|
|
6
6
|
"sourceMap": true,
|
|
7
|
-
"
|
|
8
|
-
"module": "commonjs",
|
|
9
|
-
"typeRoots": ["./node_modules/@types"]
|
|
7
|
+
"module": "commonjs"
|
|
10
8
|
},
|
|
11
|
-
"include": ["./src"]
|
|
9
|
+
"include": ["./src"]
|
|
12
10
|
}
|