@tarojs/rn-runner 3.5.0-beta.2 → 3.5.0-beta.5

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.
Files changed (46) hide show
  1. package/.eslintrc.js +2 -1
  2. package/__tests__/__snapshots__/components.spec.ts.snap +523 -0
  3. package/__tests__/build.spec.ts +3 -3
  4. package/__tests__/components.spec.ts +103 -0
  5. package/__tests__/config.spec.ts +1 -1
  6. package/__tests__/global.d.ts +11 -0
  7. package/__tests__/mock/build_testdata.ts +58 -0
  8. package/__tests__/mock/{build_testdata.js → components_testdata.ts} +4 -9
  9. package/__tests__/mock/config/index.js +1 -0
  10. package/__tests__/mock/src/app.config.ts +13 -0
  11. package/__tests__/mock/src/app.scss +0 -0
  12. package/__tests__/mock/src/app.tsx +15 -0
  13. package/__tests__/mock/src/components/cell/index.scss +25 -0
  14. package/__tests__/mock/src/components/cell/index.tsx +38 -0
  15. package/__tests__/mock/src/components/navbar/icon_back.webp +0 -0
  16. package/__tests__/mock/src/components/navbar/index.scss +29 -0
  17. package/__tests__/mock/src/components/navbar/index.tsx +36 -0
  18. package/__tests__/mock/src/components/navbar/resolver.rn.ts +1 -0
  19. package/__tests__/mock/src/components/navbar/resolver.ts +1 -0
  20. package/__tests__/mock/src/components/svg/index.tsx +6 -0
  21. package/__tests__/mock/src/components/svg/rollup-logo.svg +3 -0
  22. package/__tests__/mock/src/utils/dynamicImport/index.ts +3 -0
  23. package/__tests__/mock/src/utils/namedExport/index.js +2 -0
  24. package/__tests__/mock/src/utils/requireLodash/index.ts +5 -0
  25. package/__tests__/mock/src/utils/requireReactNative/index.js +2 -0
  26. package/__tests__/tsconfig.json +8 -0
  27. package/dist/config/build-component.js +162 -0
  28. package/dist/config/build-component.js.map +1 -0
  29. package/dist/config/config-holder.js +1 -1
  30. package/dist/config/config-holder.js.map +1 -1
  31. package/dist/config/index.js +4 -4
  32. package/dist/config/index.js.map +1 -1
  33. package/dist/config/terminal-reporter.js +3 -3
  34. package/dist/config/terminal-reporter.js.map +1 -1
  35. package/dist/index.js +26 -19
  36. package/dist/index.js.map +1 -1
  37. package/index.js +1 -0
  38. package/jest.config.js +3 -30
  39. package/package.json +38 -25
  40. package/src/config/build-component.ts +171 -0
  41. package/src/config/config-holder.ts +2 -1
  42. package/src/config/index.ts +15 -14
  43. package/src/config/terminal-reporter.ts +3 -3
  44. package/src/index.ts +33 -22
  45. package/src/types/index.ts +33 -33
  46. package/tsconfig.json +3 -5
package/src/index.ts CHANGED
@@ -1,22 +1,22 @@
1
- import * as Metro from 'metro'
2
- import getMetroConfig from './config'
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 url from 'url'
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.isWatch) {
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 { middleware, attachToServer } = createDevServerMiddleware({
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
- messageSocket.broadcast('reload')
168
+ messageSocketEndpoint.broadcast('reload')
161
169
  console.log('Reloading app...')
162
170
  } else if (name === 'd') {
163
- messageSocket.broadcast('devMenu')
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
- requestOptions.entryFile = resolutionFn(metroConfig.projectRoot, requestOptions.entryFile)
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
 
@@ -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/tsconfig.json CHANGED
@@ -1,12 +1,10 @@
1
1
  {
2
2
  "extends": "../../tsconfig.root.json",
3
3
  "compilerOptions": {
4
- "rootDir": "./src",
4
+ "jsx": "react",
5
5
  "outDir": "./dist",
6
6
  "sourceMap": true,
7
- "types": ["node"],
8
- "module": "commonjs",
9
- "typeRoots": ["./node_modules/@types"]
7
+ "module": "commonjs"
10
8
  },
11
- "include": ["./src"],
9
+ "include": ["./src"]
12
10
  }