@tarojs/rn-runner 3.5.11 → 3.6.0-alpha.1
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/__tests__/__snapshots__/components.spec.ts.snap +3 -3
- package/dist/index.js +82 -184
- package/dist/index.js.map +1 -1
- package/package.json +10 -23
- package/src/index.ts +81 -206
- package/templates/index.js +1 -0
- package/templates/metro.config.js +8 -0
- package/__tests__/build.spec.ts +0 -17
- package/__tests__/config.spec.ts +0 -35
- package/dist/config/conditional-file-store.js +0 -57
- package/dist/config/conditional-file-store.js.map +0 -1
- package/dist/config/config-holder.js +0 -76
- package/dist/config/config-holder.js.map +0 -1
- package/dist/config/index.js +0 -57
- package/dist/config/index.js.map +0 -1
- package/dist/config/preview.js +0 -102
- package/dist/config/preview.js.map +0 -1
- package/dist/config/terminal-reporter.js +0 -103
- package/dist/config/terminal-reporter.js.map +0 -1
- package/dist/utils.js +0 -29
- package/dist/utils.js.map +0 -1
- package/src/config/conditional-file-store.ts +0 -47
- package/src/config/config-holder.ts +0 -70
- package/src/config/index.ts +0 -76
- package/src/config/preview.ts +0 -114
- package/src/config/terminal-reporter.ts +0 -96
- package/src/utils.ts +0 -27
package/src/index.ts
CHANGED
|
@@ -1,104 +1,44 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { previewDev, previewProd } from '@tarojs/rn-supporter'
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
import { constants, copyFile } from 'fs'
|
|
4
4
|
import * as fse from 'fs-extra'
|
|
5
|
-
import
|
|
6
|
-
import { getResolveDependencyFn } from 'metro/src/lib/transformHelpers'
|
|
7
|
-
import * as Server from 'metro/src/Server'
|
|
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'
|
|
5
|
+
import { dirname, join } from 'path'
|
|
13
6
|
|
|
14
|
-
import getMetroConfig from './config'
|
|
15
7
|
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, isWin, PLAYGROUNDINFO } from './utils'
|
|
20
8
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
9
|
+
// 确认根目录下 metro.config.js index.js 是否存在
|
|
10
|
+
const files = ['metro.config.js', 'index.js']
|
|
11
|
+
function confirmFiles () {
|
|
12
|
+
files.forEach(file => {
|
|
13
|
+
const filePath = join(process.cwd(), file)
|
|
14
|
+
copyFile(join(__dirname, '..', 'templates', file), filePath, constants.COPYFILE_EXCL, err => {
|
|
15
|
+
if (err) {
|
|
16
|
+
if (err.code !== 'EEXIST') {
|
|
17
|
+
// 不重复生成配置文件
|
|
18
|
+
console.log(err)
|
|
19
|
+
}
|
|
20
|
+
} else {
|
|
21
|
+
console.log(`${file} created`)
|
|
32
22
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
if (config.bundleOutput) {
|
|
38
|
-
output = config.bundleOutput
|
|
39
|
-
}
|
|
40
|
-
const res = path.isAbsolute(output) ? output : path.join('.', output)
|
|
41
|
-
fse.ensureDirSync(path.dirname(res))
|
|
42
|
-
return res
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function concatOutputAssetsDest (config: any): string | undefined {
|
|
46
|
-
// 优先级:--assets-dest > config.output > config.outputRoot
|
|
47
|
-
let assetDest
|
|
48
|
-
if (!config?.deviceType || !config?.output) {
|
|
49
|
-
assetDest = config.outputRoot
|
|
50
|
-
} else {
|
|
51
|
-
assetDest = config.deviceType === 'ios' ? config.output.iosAssetsDest : config.output.androidAssetsDest
|
|
52
|
-
}
|
|
53
|
-
if (config.assetsDest) {
|
|
54
|
-
assetDest = config.assetsDest
|
|
55
|
-
}
|
|
56
|
-
if (!assetDest) return undefined
|
|
57
|
-
const res = path.isAbsolute(assetDest) ? assetDest : path.join('.', assetDest)
|
|
58
|
-
fse.ensureDirSync(path.dirname(res))
|
|
59
|
-
return res
|
|
23
|
+
})
|
|
24
|
+
})
|
|
60
25
|
}
|
|
61
26
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return {}
|
|
65
|
-
}
|
|
66
|
-
const isIos = config.deviceType === 'ios'
|
|
67
|
-
const sourceMapUrl = config.sourceMapUrl || (isIos ? config?.output?.iosSourceMapUrl : config?.output?.androidSourceMapUrl)
|
|
68
|
-
const sourcemapOutput = config.sourcemapOutput || (isIos ? config?.output?.iosSourcemapOutput : config?.output?.androidSourcemapOutput)
|
|
69
|
-
const sourcemapSourcesRoot = config.sourcemapSourcesRoot || (isIos ? config?.output?.iosSourcemapSourcesRoot : config?.output?.androidSourcemapSourcesRoot)
|
|
70
|
-
sourcemapOutput && fse.ensureDirSync(path.dirname(sourcemapOutput))
|
|
71
|
-
return {
|
|
72
|
-
sourceMapUrl,
|
|
73
|
-
sourcemapOutput,
|
|
74
|
-
sourcemapSourcesRoot
|
|
75
|
-
}
|
|
76
|
-
}
|
|
27
|
+
const isWin = /^win/.test(process.platform)
|
|
28
|
+
const npxCmd = isWin ? 'npx.cmd' : 'npx'
|
|
77
29
|
|
|
78
|
-
// TODO: 返回值
|
|
79
|
-
// HttpServer | {code: string, map: string}
|
|
80
|
-
// IBuildConfig
|
|
81
30
|
export default async function build (_appPath: string, config: any): Promise<any> {
|
|
82
|
-
process.env.TARO_ENV =
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
config.
|
|
86
|
-
|
|
87
|
-
const sourceRoot = config.sourceRoot || 'src'
|
|
88
|
-
|
|
89
|
-
const commonOptions = {
|
|
90
|
-
platform: config.deviceType,
|
|
91
|
-
minify: process.env.NODE_ENV === 'production' || !config.isWatch,
|
|
92
|
-
dev: config.isWatch
|
|
93
|
-
}
|
|
31
|
+
process.env.TARO_ENV = 'rn'
|
|
32
|
+
const isIos = config.deviceType === 'ios'
|
|
33
|
+
const cliParams:string[] = []
|
|
34
|
+
config.output = config.output || {}
|
|
35
|
+
// cli & config 参数透传
|
|
94
36
|
if (config.resetCache) {
|
|
95
|
-
|
|
37
|
+
cliParams.push('--reset-cache')
|
|
96
38
|
}
|
|
97
39
|
if (config.publicPath) {
|
|
98
|
-
|
|
40
|
+
process.env.PUBLIC_PATH = config.publicPath
|
|
99
41
|
}
|
|
100
|
-
metroConfig.reporter = new TerminalReporter(entry, sourceRoot, metroConfig.cacheStores[0])
|
|
101
|
-
|
|
102
42
|
const onFinish = function (error?) {
|
|
103
43
|
if (typeof config.onBuildFinish === 'function') {
|
|
104
44
|
config.onBuildFinish({
|
|
@@ -108,145 +48,80 @@ export default async function build (_appPath: string, config: any): Promise<any
|
|
|
108
48
|
}
|
|
109
49
|
if (error instanceof Error) throw error
|
|
110
50
|
}
|
|
111
|
-
|
|
112
51
|
if (config.isBuildNativeComp) {
|
|
113
52
|
return buildComponent(
|
|
114
53
|
_appPath,
|
|
115
54
|
config
|
|
116
55
|
)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
metroConfig.server = {}
|
|
121
|
-
}
|
|
122
|
-
metroConfig.server.useGlobalHotkey = true
|
|
123
|
-
}
|
|
56
|
+
}
|
|
57
|
+
confirmFiles()
|
|
58
|
+
if (config.isWatch) {
|
|
124
59
|
if (config.port) {
|
|
125
|
-
|
|
60
|
+
cliParams.push('--port', config.port)
|
|
126
61
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
messageSocketEndpoint,
|
|
131
|
-
websocketEndpoints
|
|
132
|
-
} = createDevServerMiddleware({
|
|
133
|
-
port: metroConfig.server.port,
|
|
134
|
-
watchFolders: metroConfig.watchFolders
|
|
135
|
-
})
|
|
136
|
-
metroConfig.server.enhanceMiddleware = (metroMiddleware, metroServer) => {
|
|
137
|
-
metroConfig.reporter.metroServerInstance = metroServer
|
|
138
|
-
|
|
139
|
-
// bundle路由只识别/index.bundle
|
|
140
|
-
return middleware.use((req, res, next) => {
|
|
141
|
-
// eslint-disable-next-line node/no-deprecated-api
|
|
142
|
-
const urlObj = url.parse(req.url)
|
|
143
|
-
if (/\/[^]+.bundle/.test(urlObj.pathname || '') && (urlObj.pathname || '').toLowerCase() !== '/index.bundle') {
|
|
144
|
-
res.writeHead(400)
|
|
145
|
-
res.end('Please access /index.bundle for entry bundling.')
|
|
146
|
-
} else if (/^\/debugger-ui\//.test(urlObj.pathname || '')) {
|
|
147
|
-
next()
|
|
148
|
-
} else {
|
|
149
|
-
metroMiddleware(req, res, next)
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// 支持host
|
|
155
|
-
return Metro.runServer(metroConfig, {
|
|
156
|
-
...commonOptions,
|
|
157
|
-
hmrEnabled: true,
|
|
158
|
-
websocketEndpoints
|
|
159
|
-
}).then(server => {
|
|
160
|
-
console.log(`React-Native Dev server is running on port: ${metroConfig.server.port}`)
|
|
161
|
-
console.log('\n\nTo reload the app press "r"\nTo open developer menu press "d"\n')
|
|
162
|
-
|
|
163
|
-
readline.emitKeypressEvents(process.stdin)
|
|
164
|
-
process.stdin.setRawMode && process.stdin.setRawMode(true)
|
|
165
|
-
process.stdin.on('keypress', (_key, data) => {
|
|
166
|
-
const { ctrl, name } = data
|
|
167
|
-
if (name === 'r') {
|
|
168
|
-
messageSocketEndpoint.broadcast('reload')
|
|
169
|
-
console.log('Reloading app...')
|
|
170
|
-
} else if (name === 'd') {
|
|
171
|
-
messageSocketEndpoint.broadcast('devMenu')
|
|
172
|
-
console.log('Opening developer menu...')
|
|
173
|
-
} else if (ctrl && (name === 'c')) {
|
|
174
|
-
process.exit()
|
|
175
|
-
}
|
|
62
|
+
try {
|
|
63
|
+
spawn(npxCmd, ['react-native', 'start'].concat(cliParams), {
|
|
64
|
+
stdio: 'inherit'
|
|
176
65
|
})
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const url = `taro://${host}:${metroConfig.server.port}`
|
|
182
|
-
console.log(PLAYGROUNDINFO)
|
|
183
|
-
console.log(`print qrcode of '${url}':`)
|
|
184
|
-
qr.generate(url, { small: !isWin })
|
|
185
|
-
} else {
|
|
186
|
-
console.log('print qrcode error: host not found.')
|
|
187
|
-
}
|
|
66
|
+
if(config.qr) {
|
|
67
|
+
previewDev({
|
|
68
|
+
port: parseInt(config.port) || 8081,
|
|
69
|
+
})
|
|
188
70
|
}
|
|
189
71
|
onFinish(null)
|
|
190
|
-
|
|
191
|
-
}).catch(e => {
|
|
72
|
+
} catch(e) {
|
|
192
73
|
onFinish(e)
|
|
193
|
-
}
|
|
74
|
+
}
|
|
194
75
|
} else {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
76
|
+
const defaultOutputDir = join(process.cwd(), config.outputRoot || 'dist')
|
|
77
|
+
const defaultBundleOutput = join(defaultOutputDir, 'index.bundle')
|
|
78
|
+
const bundleOutput = (config.bundleOutput ? config.bundleOutput : (isIos ? config.output.ios : config.output.android)) || defaultBundleOutput
|
|
79
|
+
fse.ensureDirSync(dirname(bundleOutput))
|
|
80
|
+
cliParams.push('--bundle-output', bundleOutput)
|
|
81
|
+
|
|
82
|
+
const sourcemapOutput = config.sourcemapOutput ? config.sourcemapOutput : (isIos ? config.output.iosSourcemapOutput : config.output.androidSourcemapOutput)
|
|
83
|
+
if (sourcemapOutput) {
|
|
84
|
+
cliParams.push('--sourcemap-output', sourcemapOutput)
|
|
199
85
|
}
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// try for test case build_noWatch
|
|
204
|
-
try {
|
|
205
|
-
requestOptions.entryFile = resolutionFn(metroConfig.projectRoot, requestOptions.entryFile)
|
|
206
|
-
} catch (e) {} // eslint-disable-line no-empty
|
|
207
|
-
return savedBuildFunc(packagerClient, requestOptions)
|
|
86
|
+
const sourceMapUrl = config.sourceMapUrl ? config.sourceMapUrl : (isIos ? config.output.iosSourceMapUrl : config.output.androidSourceMapUrl)
|
|
87
|
+
if (sourceMapUrl) {
|
|
88
|
+
cliParams.push('--sourcemap-use-absolute-path', sourceMapUrl)
|
|
208
89
|
}
|
|
209
90
|
|
|
210
|
-
const
|
|
91
|
+
const sourcemapSourcesRoot = config.sourcemapSourcesRoot ? config.sourcemapSourcesRoot : (isIos ? config.output.iosSourcemapSourcesRoot : config.output.androidSourcemapSourcesRoot)
|
|
92
|
+
if (sourcemapSourcesRoot) {
|
|
93
|
+
cliParams.push('--sourcemap-sources-root', sourcemapSourcesRoot)
|
|
94
|
+
}
|
|
211
95
|
|
|
212
|
-
const
|
|
96
|
+
const assetsDest = (config.assetsDest ? config.assetsDest : (isIos ? config.output.iosAssetsDest : config.output.androidAssetsDest)) || defaultOutputDir
|
|
97
|
+
cliParams.push('--assets-dest', assetsDest)
|
|
98
|
+
fse.ensureDirSync(assetsDest)
|
|
213
99
|
|
|
214
100
|
try {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
bundleOutput: options.out
|
|
227
|
-
}
|
|
228
|
-
await outputBundle.save(bundle, outputOptions, console.log)
|
|
229
|
-
|
|
230
|
-
// Save the assets of the bundle
|
|
231
|
-
const outputAssets = await server.getAssets({
|
|
232
|
-
...Server.DEFAULT_BUNDLE_OPTIONS,
|
|
233
|
-
...requestOptions
|
|
101
|
+
spawn(npxCmd, [
|
|
102
|
+
'react-native',
|
|
103
|
+
'bundle',
|
|
104
|
+
'--platform',
|
|
105
|
+
config.deviceType,
|
|
106
|
+
'--dev',
|
|
107
|
+
'false',
|
|
108
|
+
'--entry-file',
|
|
109
|
+
'index.js'
|
|
110
|
+
].concat(cliParams), {
|
|
111
|
+
stdio: 'inherit'
|
|
234
112
|
})
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
assetsDest,
|
|
241
|
-
platform: options.platform
|
|
113
|
+
if(config.qr) {
|
|
114
|
+
process.on('beforeExit', () => {
|
|
115
|
+
previewProd({
|
|
116
|
+
out: bundleOutput,
|
|
117
|
+
platform: config.deviceType,
|
|
118
|
+
assetsDest: assetsDest,
|
|
242
119
|
})
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
} catch
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
onFinish(null)
|
|
123
|
+
} catch(e) {
|
|
247
124
|
onFinish(e)
|
|
248
|
-
} finally {
|
|
249
|
-
server.end()
|
|
250
125
|
}
|
|
251
126
|
}
|
|
252
127
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@tarojs/rn-supporter/entry-file.js'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const { mergeConfig } = require('metro-config')
|
|
2
|
+
const { getMetroConfig } = require('@tarojs/rn-supporter')
|
|
3
|
+
|
|
4
|
+
module.exports = mergeConfig({
|
|
5
|
+
// custom your metro config here
|
|
6
|
+
// https://facebook.github.io/metro/docs/configuration
|
|
7
|
+
resolver: {}
|
|
8
|
+
}, getMetroConfig())
|
package/__tests__/build.spec.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import build from '../src/index'
|
|
2
|
-
import { appPath, config, configNoWatch } from './mock/build_testdata'
|
|
3
|
-
|
|
4
|
-
const outputBundle = require('metro/src/shared/output/bundle')
|
|
5
|
-
|
|
6
|
-
describe('init', () => {
|
|
7
|
-
jest.spyOn(outputBundle, 'build').mockImplementation(() => {
|
|
8
|
-
return 'ok'
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('build', async () => {
|
|
12
|
-
await build(appPath, config)
|
|
13
|
-
})
|
|
14
|
-
it('build_noWatch', async () => {
|
|
15
|
-
await build(appPath, configNoWatch)
|
|
16
|
-
})
|
|
17
|
-
})
|
package/__tests__/config.spec.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { getRNConfigBabelPlugin, getRNConfigEntry, getRNConfigOutput, getRNConfigTransformer } from '../src/config/config-holder'
|
|
2
|
-
|
|
3
|
-
const path = require('path')
|
|
4
|
-
|
|
5
|
-
describe('init', () => {
|
|
6
|
-
const spy = jest.spyOn(process, 'cwd')
|
|
7
|
-
spy.mockReturnValue(path.resolve(__dirname, '', 'mock'))
|
|
8
|
-
process.env = {
|
|
9
|
-
NODE_ENV: 'development'
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
it('getRNConfigOutput', () => {
|
|
13
|
-
expect(getRNConfigOutput('ios')).toEqual('iosbundle/main.bundle')
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('getRNConfigEntry', () => {
|
|
17
|
-
expect(getRNConfigEntry()).toEqual('app')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('getRNConfigTransformer', () => {
|
|
21
|
-
expect(getRNConfigTransformer()).toEqual([
|
|
22
|
-
'metro/transformer'
|
|
23
|
-
])
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('getRNConfigBabelPlugin', () => {
|
|
27
|
-
const babelPlugin = [
|
|
28
|
-
'/absulute/path/plugin/filename',
|
|
29
|
-
'@tarojs/plugin-mock',
|
|
30
|
-
['@tarojs/plugin-mock'],
|
|
31
|
-
['@tarojs/plugin-mock', {}]
|
|
32
|
-
]
|
|
33
|
-
expect(getRNConfigBabelPlugin()).toEqual(babelPlugin)
|
|
34
|
-
})
|
|
35
|
-
})
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const FileStore = require("metro-cache/src/stores/FileStore");
|
|
13
|
-
class ConditionalFileStore {
|
|
14
|
-
constructor(options, entryName) {
|
|
15
|
-
this.ignoreEntryFileCache = false;
|
|
16
|
-
this._fileStore = new FileStore(options);
|
|
17
|
-
this.entryName = entryName || 'app';
|
|
18
|
-
}
|
|
19
|
-
isEntryCache(cacheItem) {
|
|
20
|
-
if (!cacheItem)
|
|
21
|
-
return false;
|
|
22
|
-
const { dependencies } = cacheItem;
|
|
23
|
-
if (!dependencies || !dependencies.length) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
for (const d of dependencies) {
|
|
27
|
-
if (d.name.includes(`${this.entryName}.config`)) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
get(key) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
const result = yield this._fileStore.get(key);
|
|
36
|
-
if (result && this.ignoreEntryFileCache && this.isEntryCache(result)) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
set(key, value) {
|
|
43
|
-
var _a, _b, _c, _d, _e;
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
// fix: 样式文件不写缓存
|
|
46
|
-
if (((_e = (_d = (_c = (_b = (_a = value === null || value === void 0 ? void 0 : value.output) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.functionMap) === null || _d === void 0 ? void 0 : _d.names) === null || _e === void 0 ? void 0 : _e.indexOf('ignoreStyleFileCache')) > -1) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
return yield this._fileStore.set(key, value);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
clear() {
|
|
53
|
-
this._fileStore.clear();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.default = ConditionalFileStore;
|
|
57
|
-
//# sourceMappingURL=conditional-file-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-file-store.js","sourceRoot":"","sources":["../../src/config/conditional-file-store.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,8DAA6D;AAE7D,MAAqB,oBAAoB;IAKvC,YAAa,OAAY,EAAE,SAAkB;QAJ7C,yBAAoB,GAAG,KAAK,CAAA;QAK1B,IAAI,CAAC,UAAU,GAAG,IAAI,SAAS,CAAI,OAAO,CAAC,CAAA;QAC3C,IAAI,CAAC,SAAS,GAAG,SAAS,IAAI,KAAK,CAAA;IACrC,CAAC;IAED,YAAY,CAAE,SAAS;QACrB,IAAI,CAAC,SAAS;YAAE,OAAO,KAAK,CAAA;QAC5B,MAAM,EAAE,YAAY,EAAE,GAAG,SAAS,CAAA;QAClC,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE;YACzC,OAAO,KAAK,CAAA;SACb;QAED,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE;YAC5B,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,SAAS,SAAS,CAAC,EAAE;gBAC/C,OAAO,IAAI,CAAA;aACZ;SACF;QACD,OAAO,KAAK,CAAA;IACd,CAAC;IAEK,GAAG,CAAE,GAAW;;YACpB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC7C,IAAI,MAAM,IAAI,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;gBACpE,OAAO,IAAI,CAAA;aACZ;YACD,OAAO,MAAM,CAAA;QACf,CAAC;KAAA;IAEK,GAAG,CAAE,GAAW,EAAE,KAAU;;;YAChC,gBAAgB;YAChB,IAAI,CAAA,MAAA,MAAA,MAAA,MAAA,MAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,MAAM,0CAAG,CAAC,CAAC,0CAAE,IAAI,0CAAE,WAAW,0CAAE,KAAK,0CAAE,OAAO,CAAC,sBAAsB,CAAC,IAAG,CAAC,CAAC,EAAE;gBACtF,OAAM;aACP;YACD,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;;KAC7C;IAED,KAAK;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA;IACzB,CAAC;CACF;AA5CD,uCA4CC"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRNConfigTransformer = exports.getRNConfigOutput = exports.getRNConfigEntry = exports.getRNConfigBabelPlugin = exports.getRNConfig = exports.getConfig = void 0;
|
|
4
|
-
const lodash_1 = require("lodash");
|
|
5
|
-
const fs = require('fs');
|
|
6
|
-
let config;
|
|
7
|
-
let rnConfig;
|
|
8
|
-
const getConfig = () => {
|
|
9
|
-
if (config)
|
|
10
|
-
return config;
|
|
11
|
-
const fileName = `${process.cwd()}/config/index.js`;
|
|
12
|
-
if (fs.existsSync(fileName)) {
|
|
13
|
-
config = require(`${process.cwd()}/config/index`)(lodash_1.merge);
|
|
14
|
-
return config;
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
console.warn('缺少项目基本配置');
|
|
18
|
-
config = {};
|
|
19
|
-
return config;
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
exports.getConfig = getConfig;
|
|
23
|
-
const getRNConfig = () => {
|
|
24
|
-
getConfig();
|
|
25
|
-
if (rnConfig)
|
|
26
|
-
return rnConfig;
|
|
27
|
-
if (config.rn) {
|
|
28
|
-
rnConfig = config.rn;
|
|
29
|
-
}
|
|
30
|
-
else {
|
|
31
|
-
rnConfig = {};
|
|
32
|
-
}
|
|
33
|
-
return rnConfig;
|
|
34
|
-
};
|
|
35
|
-
exports.getRNConfig = getRNConfig;
|
|
36
|
-
const getRNConfigEntry = () => {
|
|
37
|
-
getRNConfig();
|
|
38
|
-
return rnConfig.entry || 'app';
|
|
39
|
-
};
|
|
40
|
-
exports.getRNConfigEntry = getRNConfigEntry;
|
|
41
|
-
const getRNConfigOutput = (p) => {
|
|
42
|
-
getRNConfig();
|
|
43
|
-
if (rnConfig.output) {
|
|
44
|
-
if (p === 'ios') {
|
|
45
|
-
return rnConfig.output.ios;
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return rnConfig.output.android;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
exports.getRNConfigOutput = getRNConfigOutput;
|
|
56
|
-
const getRNConfigTransformer = () => {
|
|
57
|
-
getRNConfig();
|
|
58
|
-
if (rnConfig.transformer) {
|
|
59
|
-
return rnConfig.transformer;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
exports.getRNConfigTransformer = getRNConfigTransformer;
|
|
66
|
-
const getRNConfigBabelPlugin = () => {
|
|
67
|
-
getRNConfig();
|
|
68
|
-
if (rnConfig.babelPlugin) {
|
|
69
|
-
return rnConfig.babelPlugin;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
exports.getRNConfigBabelPlugin = getRNConfigBabelPlugin;
|
|
76
|
-
//# sourceMappingURL=config-holder.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-holder.js","sourceRoot":"","sources":["../../src/config/config-holder.ts"],"names":[],"mappings":";;;AAAA,mCAA8B;AAI9B,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAExB,IAAI,MAAc,CAAA;AAClB,IAAI,QAAkB,CAAA;AAEtB,MAAM,SAAS,GAAG,GAAG,EAAE;IACrB,IAAI,MAAM;QAAE,OAAO,MAAM,CAAA;IACzB,MAAM,QAAQ,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAA;IACnD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC3B,MAAM,GAAG,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,cAAK,CAAC,CAAA;QACxD,OAAO,MAAM,CAAA;KACd;SAAM;QACL,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;QACxB,MAAM,GAAG,EAAE,CAAA;QACX,OAAO,MAAM,CAAA;KACd;AACH,CAAC,CAAA;AAiDQ,8BAAS;AA/ClB,MAAM,WAAW,GAAG,GAAG,EAAE;IACvB,SAAS,EAAE,CAAA;IACX,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAA;IAC7B,IAAI,MAAM,CAAC,EAAE,EAAE;QACb,QAAQ,GAAG,MAAM,CAAC,EAAE,CAAA;KACrB;SAAM;QACL,QAAQ,GAAG,EAAE,CAAA;KACd;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAsCmB,kCAAW;AApC/B,MAAM,gBAAgB,GAAG,GAAG,EAAE;IAC5B,WAAW,EAAE,CAAA;IACb,OAAO,QAAQ,CAAC,KAAK,IAAI,KAAK,CAAA;AAChC,CAAC,CAAA;AAiCwD,4CAAgB;AA/BzE,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,EAAE;IAC9B,WAAW,EAAE,CAAA;IACb,IAAI,QAAQ,CAAC,MAAM,EAAE;QACnB,IAAI,CAAC,KAAK,KAAK,EAAE;YACf,OAAO,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAA;SAC3B;aAAM;YACL,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAA;SAC/B;KACF;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAoB0E,8CAAiB;AAlB5F,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,WAAW,EAAE,CAAA;IACb,IAAI,QAAQ,CAAC,WAAW,EAAE;QACxB,OAAO,QAAQ,CAAC,WAAW,CAAA;KAC5B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAW6F,wDAAsB;AATpH,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,WAAW,EAAE,CAAA;IACb,IAAI,QAAQ,CAAC,WAAW,EAAE;QACxB,OAAO,QAAQ,CAAC,WAAW,CAAA;KAC5B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAEgC,wDAAsB"}
|
package/dist/config/index.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.defaultConfig = void 0;
|
|
13
|
-
const resolveReactNativePath_1 = require("@react-native-community/cli-config/build/resolveReactNativePath");
|
|
14
|
-
const cli_tools_1 = require("@react-native-community/cli-tools");
|
|
15
|
-
const rn_supporter_1 = require("@tarojs/rn-supporter");
|
|
16
|
-
const Metro = require("metro");
|
|
17
|
-
const os = require("os");
|
|
18
|
-
const path = require("path");
|
|
19
|
-
const conditional_file_store_1 = require("./conditional-file-store");
|
|
20
|
-
const reactNativePath = (0, resolveReactNativePath_1.default)((0, cli_tools_1.findProjectRoot)());
|
|
21
|
-
const defaultConfig = getDefaultConfig();
|
|
22
|
-
exports.defaultConfig = defaultConfig;
|
|
23
|
-
function getDefaultConfig() {
|
|
24
|
-
const supporter = new rn_supporter_1.Supporter({ fromRunner: true });
|
|
25
|
-
const taroMetroConfig = supporter.getMetroConfig();
|
|
26
|
-
const metroConfig = {
|
|
27
|
-
transformer: taroMetroConfig.transformer,
|
|
28
|
-
resolver: taroMetroConfig.resolver,
|
|
29
|
-
serializer: {
|
|
30
|
-
// We can include multiple copies of InitializeCore here because metro will
|
|
31
|
-
// only add ones that are already part of the bundle
|
|
32
|
-
getModulesRunBeforeMainModule: () => [
|
|
33
|
-
require.resolve(path.join(reactNativePath, 'Libraries/Core/InitializeCore'))
|
|
34
|
-
],
|
|
35
|
-
getPolyfills: () => require(path.join(reactNativePath, 'rn-get-polyfills'))()
|
|
36
|
-
},
|
|
37
|
-
cacheStores: [new conditional_file_store_1.default({
|
|
38
|
-
root: path.join(os.tmpdir(), 'metro-cache')
|
|
39
|
-
})],
|
|
40
|
-
server: {
|
|
41
|
-
port: 8081
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
return metroConfig;
|
|
45
|
-
}
|
|
46
|
-
exports.default = (config) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
const metroConfig = getDefaultConfig();
|
|
48
|
-
const res = yield Metro.loadConfig({}, metroConfig);
|
|
49
|
-
if (!res.cacheStores || (res.cacheStores.length !== 1) || !(res.cacheStores[0] instanceof conditional_file_store_1.default)) {
|
|
50
|
-
throw new Error("cacheStores shouldn't be overridden in metro config.");
|
|
51
|
-
}
|
|
52
|
-
if (config.entry) {
|
|
53
|
-
res.cacheStores[0].entryName = config.entry;
|
|
54
|
-
}
|
|
55
|
-
return res;
|
|
56
|
-
});
|
|
57
|
-
//# sourceMappingURL=index.js.map
|
package/dist/config/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4GAAoG;AACpG,iEAAmE;AACnE,uDAAgD;AAChD,+BAA8B;AAC9B,yBAAwB;AACxB,6BAA4B;AAE5B,qEAA2D;AAE3D,MAAM,eAAe,GAAW,IAAA,gCAAsB,EAAC,IAAA,2BAAe,GAAE,CAAC,CAAA;AAyBzE,MAAM,aAAa,GAAgB,gBAAgB,EAAE,CAAA;AAyC5C,sCAAa;AAvCtB,SAAS,gBAAgB;IACvB,MAAM,SAAS,GAAG,IAAI,wBAAS,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAA;IACrD,MAAM,eAAe,GAAG,SAAS,CAAC,cAAc,EAAE,CAAA;IAClD,MAAM,WAAW,GAAgB;QAC/B,WAAW,EAAE,eAAe,CAAC,WAAW;QACxC,QAAQ,EAAE,eAAe,CAAC,QAAQ;QAClC,UAAU,EAAE;YACV,2EAA2E;YAC3E,oDAAoD;YACpD,6BAA6B,EAAE,GAAG,EAAE,CAAC;gBACnC,OAAO,CAAC,OAAO,CACb,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,+BAA+B,CAAC,CAC5D;aACF;YACD,YAAY,EAAE,GAAG,EAAE,CACjB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC,EAAE;SAC5D;QACD,WAAW,EAAE,CAAC,IAAI,gCAAoB,CAAM;gBAC1C,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,aAAa,CAAC;aAC5C,CAAC,CAAC;QACH,MAAM,EAAE;YACN,IAAI,EAAE,IAAI;SACX;KACF,CAAA;IACD,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,kBAAe,CAAO,MAAW,EAAE,EAAE;IACnC,MAAM,WAAW,GAAG,gBAAgB,EAAE,CAAA;IACtC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,UAAU,CAAC,EAAE,EAAE,WAAW,CAAC,CAAA;IACnD,IAAI,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,gCAAoB,CAAC,EAAE;QAC/G,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAA;KACxE;IACD,IAAI,MAAM,CAAC,KAAK,EAAE;QAChB,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,KAAK,CAAA;KAC5C;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA,CAAA"}
|