@tarojs/rn-runner 3.5.6-alpha.2 → 3.5.7

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/dist/index.js CHANGED
@@ -9,44 +9,106 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ const saveAssets_1 = require("@react-native-community/cli-plugin-metro/build/commands/bundle/saveAssets");
13
+ const cli_server_api_1 = require("@react-native-community/cli-server-api");
12
14
  const helper_1 = require("@tarojs/helper");
13
- const rn_supporter_1 = require("@tarojs/rn-supporter");
14
- const child_process_1 = require("child_process");
15
- const fs_1 = require("fs");
16
- const path_1 = require("path");
15
+ const fse = require("fs-extra");
16
+ const Metro = require("metro");
17
+ const transformHelpers_1 = require("metro/src/lib/transformHelpers");
18
+ const Server = require("metro/src/Server");
19
+ const outputBundle = require("metro/src/shared/output/bundle");
20
+ const path = require("path");
21
+ const qr = require("qrcode-terminal");
22
+ const readline = require("readline");
23
+ const url = require("url");
24
+ const config_1 = require("./config");
17
25
  const build_component_1 = require("./config/build-component");
18
- // 确认根目录下 metro.config.js index.js 是否存在
19
- const files = ['metro.config.js', 'index.js'];
20
- function confirmFiles() {
21
- files.forEach(file => {
22
- const filePath = (0, path_1.join)(process.cwd(), file);
23
- (0, fs_1.copyFile)((0, path_1.join)(__dirname, '..', 'templates', file), filePath, fs_1.constants.COPYFILE_EXCL, err => {
24
- if (err) {
25
- if (err.code !== 'EEXIST') {
26
- // 不重复生成配置文件
27
- console.log(err);
28
- }
29
- }
30
- else {
31
- console.log(`${file} created`);
26
+ const config_holder_1 = require("./config/config-holder");
27
+ const preview_1 = require("./config/preview");
28
+ const terminal_reporter_1 = require("./config/terminal-reporter");
29
+ const utils_1 = require("./utils");
30
+ function concatOutputFileName(config) {
31
+ // 优先级:--bundle-output > config.output > config.outputRoot
32
+ let output = path.join(config.outputRoot, 'index.bundle');
33
+ if (config.output) {
34
+ const outputType = typeof config.output;
35
+ if (outputType === 'string') {
36
+ output = config.output;
37
+ }
38
+ else if (outputType === 'object') {
39
+ output = config.output[config.deviceType];
40
+ if (!output) {
41
+ console.error(`lack value for 'rn.output' configuration with platform '${config.deviceType}': ${JSON.stringify(config.output)}`);
32
42
  }
33
- });
34
- });
43
+ }
44
+ else {
45
+ console.error(`invalid value for 'rn.output' configuration: ${JSON.stringify(config.output)}`);
46
+ }
47
+ }
48
+ if (config.bundleOutput) {
49
+ output = config.bundleOutput;
50
+ }
51
+ const res = path.isAbsolute(output) ? output : path.join('.', output);
52
+ fse.ensureDirSync(path.dirname(res));
53
+ return res;
35
54
  }
55
+ function concatOutputAssetsDest(config) {
56
+ // 优先级:--assets-dest > config.output > config.outputRoot
57
+ let assetDest;
58
+ if (!(config === null || config === void 0 ? void 0 : config.deviceType) || !(config === null || config === void 0 ? void 0 : config.output)) {
59
+ assetDest = config.outputRoot;
60
+ }
61
+ else {
62
+ assetDest = config.deviceType === 'ios' ? config.output.iosAssetsDest : config.output.androidAssetsDest;
63
+ }
64
+ if (config.assetsDest) {
65
+ assetDest = config.assetsDest;
66
+ }
67
+ if (!assetDest)
68
+ return undefined;
69
+ const res = path.isAbsolute(assetDest) ? assetDest : path.join('.', assetDest);
70
+ fse.ensureDirSync(path.dirname(res));
71
+ return res;
72
+ }
73
+ function getOutputSourceMapOption(config) {
74
+ var _a, _b, _c, _d, _e, _f;
75
+ if (!(config === null || config === void 0 ? void 0 : config.deviceType)) {
76
+ return {};
77
+ }
78
+ const isIos = config.deviceType === 'ios';
79
+ const sourceMapUrl = config.sourceMapUrl || (isIos ? (_a = config === null || config === void 0 ? void 0 : config.output) === null || _a === void 0 ? void 0 : _a.iosSourceMapUrl : (_b = config === null || config === void 0 ? void 0 : config.output) === null || _b === void 0 ? void 0 : _b.androidSourceMapUrl);
80
+ const sourcemapOutput = config.sourcemapOutput || (isIos ? (_c = config === null || config === void 0 ? void 0 : config.output) === null || _c === void 0 ? void 0 : _c.iosSourcemapOutput : (_d = config === null || config === void 0 ? void 0 : config.output) === null || _d === void 0 ? void 0 : _d.androidSourcemapOutput);
81
+ const sourcemapSourcesRoot = config.sourcemapSourcesRoot || (isIos ? (_e = config === null || config === void 0 ? void 0 : config.output) === null || _e === void 0 ? void 0 : _e.iosSourcemapSourcesRoot : (_f = config === null || config === void 0 ? void 0 : config.output) === null || _f === void 0 ? void 0 : _f.androidSourcemapSourcesRoot);
82
+ sourcemapOutput && fse.ensureDirSync(path.dirname(sourcemapOutput));
83
+ return {
84
+ sourceMapUrl,
85
+ sourcemapOutput,
86
+ sourcemapSourcesRoot
87
+ };
88
+ }
89
+ // TODO: 返回值
90
+ // HttpServer | {code: string, map: string}
91
+ // IBuildConfig
36
92
  function build(_appPath, config) {
37
93
  return __awaiter(this, void 0, void 0, function* () {
38
- confirmFiles();
39
94
  process.env.TARO_ENV = helper_1.PLATFORMS.RN;
40
- const isIos = config.deviceType === 'ios';
41
- const cliParams = [];
42
- config.output = config.output || {};
43
- // cli & config 参数透传
95
+ // TODO:新增环境变量是否可以在metro构建过程中可以访问到?
96
+ const entry = (0, config_holder_1.getRNConfigEntry)();
97
+ config.entry = entry;
98
+ const metroConfig = yield (0, config_1.default)(config);
99
+ const sourceRoot = config.sourceRoot || 'src';
100
+ const commonOptions = {
101
+ platform: config.deviceType,
102
+ minify: process.env.NODE_ENV === 'production' || !config.isWatch,
103
+ dev: config.isWatch
104
+ };
44
105
  if (config.resetCache) {
45
- cliParams.push('--reset-cache');
106
+ metroConfig.resetCache = config.resetCache;
46
107
  }
47
108
  if (config.publicPath) {
48
- cliParams.push('--public-path', config.publicPath);
109
+ metroConfig.transformer.publicPath = config.publicPath;
49
110
  }
111
+ metroConfig.reporter = new terminal_reporter_1.TerminalReporter(entry, sourceRoot, metroConfig.cacheStores[0]);
50
112
  const onFinish = function (error) {
51
113
  if (typeof config.onBuildFinish === 'function') {
52
114
  config.onBuildFinish({
@@ -61,67 +123,114 @@ function build(_appPath, config) {
61
123
  return (0, build_component_1.default)(_appPath, config);
62
124
  }
63
125
  else if (config.isWatch) {
126
+ if (!metroConfig.server || (metroConfig.server.useGlobalHotkey === undefined)) {
127
+ if (!metroConfig.server) {
128
+ metroConfig.server = {};
129
+ }
130
+ metroConfig.server.useGlobalHotkey = true;
131
+ }
64
132
  if (config.port) {
65
- cliParams.push('--port', config.port);
133
+ metroConfig.server.port = config.port;
66
134
  }
67
- try {
68
- (0, child_process_1.spawn)('react-native', ['start'].concat(cliParams), {
69
- stdio: 'inherit'
135
+ const { middleware, messageSocketEndpoint, websocketEndpoints } = (0, cli_server_api_1.createDevServerMiddleware)({
136
+ port: metroConfig.server.port,
137
+ watchFolders: metroConfig.watchFolders
138
+ });
139
+ metroConfig.server.enhanceMiddleware = (metroMiddleware, metroServer) => {
140
+ metroConfig.reporter.metroServerInstance = metroServer;
141
+ // bundle路由只识别/index.bundle
142
+ return middleware.use((req, res, next) => {
143
+ // eslint-disable-next-line node/no-deprecated-api
144
+ const urlObj = url.parse(req.url);
145
+ if (/\/[^]+.bundle/.test(urlObj.pathname || '') && (urlObj.pathname || '').toLowerCase() !== '/index.bundle') {
146
+ res.writeHead(400);
147
+ res.end('Please access /index.bundle for entry bundling.');
148
+ }
149
+ else if (/^\/debugger-ui\//.test(urlObj.pathname || '')) {
150
+ next();
151
+ }
152
+ else {
153
+ metroMiddleware(req, res, next);
154
+ }
155
+ });
156
+ };
157
+ // 支持host
158
+ return Metro.runServer(metroConfig, Object.assign(Object.assign({}, commonOptions), { hmrEnabled: true, websocketEndpoints })).then(server => {
159
+ console.log(`React-Native Dev server is running on port: ${metroConfig.server.port}`);
160
+ console.log('\n\nTo reload the app press "r"\nTo open developer menu press "d"\n');
161
+ readline.emitKeypressEvents(process.stdin);
162
+ process.stdin.setRawMode && process.stdin.setRawMode(true);
163
+ process.stdin.on('keypress', (_key, data) => {
164
+ const { ctrl, name } = data;
165
+ if (name === 'r') {
166
+ messageSocketEndpoint.broadcast('reload');
167
+ console.log('Reloading app...');
168
+ }
169
+ else if (name === 'd') {
170
+ messageSocketEndpoint.broadcast('devMenu');
171
+ console.log('Opening developer menu...');
172
+ }
173
+ else if (ctrl && (name === 'c')) {
174
+ process.exit();
175
+ }
70
176
  });
71
177
  if (config.qr) {
72
- (0, rn_supporter_1.previewDev)({
73
- port: parseInt(config.port) || 8081,
74
- });
178
+ const host = (0, utils_1.getOpenHost)();
179
+ if (host) {
180
+ const url = `taro://${host}:${metroConfig.server.port}`;
181
+ console.log(utils_1.PLAYGROUNDINFO);
182
+ console.log(`print qrcode of '${url}':`);
183
+ qr.generate(url, { small: !utils_1.isWin });
184
+ }
185
+ else {
186
+ console.log('print qrcode error: host not found.');
187
+ }
75
188
  }
76
189
  onFinish(null);
77
- }
78
- catch (e) {
190
+ return server;
191
+ }).catch(e => {
79
192
  onFinish(e);
80
- }
193
+ });
81
194
  }
82
195
  else {
83
- const bundleOutput = config.bundleOutput ? config.bundleOutput : (isIos ? config.output.ios : config.output.android);
84
- cliParams.push('--bundle-output', bundleOutput);
85
- const sourcemapOutput = config.sourcemapOutput ? config.sourcemapOutput : (isIos ? config.output.iosSourcemapOutput : config.output.androidSourcemapOutput);
86
- if (sourcemapOutput) {
87
- cliParams.push('--sourcemap-output', sourcemapOutput);
88
- }
89
- const sourceMapUrl = config.sourceMapUrl ? config.sourceMapUrl : (isIos ? config.output.iosSourceMapUrl : config.output.androidSourceMapUrl);
90
- if (sourceMapUrl) {
91
- cliParams.push('--sourcemap-use-absolute-path', sourceMapUrl);
92
- }
93
- const sourcemapSourcesRoot = config.sourcemapSourcesRoot ? config.sourcemapSourcesRoot : (isIos ? config.output.iosSourcemapSourcesRoot : config.output.androidSourcemapSourcesRoot);
94
- if (sourcemapSourcesRoot) {
95
- cliParams.push('--sourcemap-sources-root', sourcemapSourcesRoot);
96
- }
97
- const assetsDest = config.assetsDest ? config.assetsDest : (isIos ? config.output.iosAssetsDest : config.output.androidAssetsDest);
98
- cliParams.push('--assets-dest', assetsDest);
196
+ const options = Object.assign(Object.assign({}, commonOptions), { entry: './index', out: concatOutputFileName(config) });
197
+ const savedBuildFunc = outputBundle.build;
198
+ outputBundle.build = (packagerClient, requestOptions) => __awaiter(this, void 0, void 0, function* () {
199
+ const resolutionFn = yield (0, transformHelpers_1.getResolveDependencyFn)(packagerClient.getBundler().getBundler(), requestOptions.platform);
200
+ // try for test case build_noWatch
201
+ try {
202
+ requestOptions.entryFile = resolutionFn(metroConfig.projectRoot, requestOptions.entryFile);
203
+ }
204
+ catch (e) { } // eslint-disable-line no-empty
205
+ return savedBuildFunc(packagerClient, requestOptions);
206
+ });
207
+ const server = new Server(metroConfig);
208
+ const sourceMapOption = getOutputSourceMapOption(config);
99
209
  try {
100
- (0, child_process_1.spawn)('react-native', [
101
- 'bundle',
102
- '--platform',
103
- config.deviceType,
104
- '--dev',
105
- 'false',
106
- '--entry-file',
107
- 'index.js'
108
- ].concat(cliParams), {
109
- stdio: 'inherit'
110
- });
111
- if (config.qr) {
112
- process.on('beforeExit', () => {
113
- (0, rn_supporter_1.previewProd)({
114
- out: bundleOutput,
115
- platform: config.deviceType,
116
- assetsDest: assetsDest,
210
+ const requestOptions = Object.assign(Object.assign(Object.assign({}, commonOptions), sourceMapOption), { entryFile: options.entry, inlineSourceMap: false, createModuleIdFactory: metroConfig.serializer.createModuleIdFactory });
211
+ const bundle = yield outputBundle.build(server, requestOptions);
212
+ const outputOptions = Object.assign(Object.assign(Object.assign({}, commonOptions), sourceMapOption), { bundleOutput: options.out });
213
+ yield outputBundle.save(bundle, outputOptions, console.log);
214
+ // Save the assets of the bundle
215
+ const outputAssets = yield server.getAssets(Object.assign(Object.assign({}, Server.DEFAULT_BUNDLE_OPTIONS), requestOptions));
216
+ const assetsDest = concatOutputAssetsDest(config);
217
+ return yield (0, saveAssets_1.default)(outputAssets, options.platform, assetsDest).then(() => {
218
+ if (config.qr) {
219
+ (0, preview_1.default)({
220
+ out: options.out,
221
+ assetsDest,
222
+ platform: options.platform
117
223
  });
118
- });
119
- }
120
- onFinish(null);
224
+ }
225
+ onFinish(null);
226
+ });
121
227
  }
122
228
  catch (e) {
123
229
  onFinish(e);
124
230
  }
231
+ finally {
232
+ server.end();
233
+ }
125
234
  }
126
235
  });
127
236
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,2CAA0C;AAC1C,uDAA6D;AAC7D,iDAAqC;AACrC,2BAAuC;AACvC,+BAA2B;AAE3B,8DAAqD;AAErD,uCAAuC;AACvC,MAAM,KAAK,GAAG,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAA;AAC7C,SAAS,YAAY;IACnB,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,IAAI,CAAC,CAAA;QAC1C,IAAA,aAAQ,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,cAAS,CAAC,aAAa,EAAE,GAAG,CAAC,EAAE;YAC1F,IAAI,GAAG,EAAE;gBACP,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE;oBACzB,YAAY;oBACZ,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;iBACjB;aACF;iBAAM;gBACL,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,UAAU,CAAC,CAAA;aAC/B;QACH,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC;AAED,SAA8B,KAAK,CAAE,QAAgB,EAAE,MAAW;;QAChE,YAAY,EAAE,CAAA;QACd,OAAO,CAAC,GAAG,CAAC,QAAQ,GAAG,kBAAS,CAAC,EAAE,CAAA;QACnC,MAAM,KAAK,GAAG,MAAM,CAAC,UAAU,KAAK,KA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AE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;gBAE3D,gCAAgC;gBAChC,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,SAAS,iCACtC,MAAM,CAAC,sBAAsB,GAC7B,cAAc,EACjB,CAAA;gBACF,MAAM,UAAU,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAA;gBACjD,OAAO,MAAM,IAAA,oBAAU,EAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;oBAC5E,IAAI,MAAM,CAAC,EAAE,EAAE;wBACb,IAAA,iBAAO,EAAC;4BACN,GAAG,EAAE,OAAO,CAAC,GAAG;4BAChB,UAAU;4BACV,QAAQ,EAAE,OAAO,CAAC,QAAQ;yBAC3B,CAAC,CAAA;qBACH;oBACD,QAAQ,CAAC,IAAI,CAAC,CAAA;gBAChB,CAAC,CAAC,CAAA;aACH;YAAC,OAAO,CAAC,EAAE;gBACV,QAAQ,CAAC,CAAC,CAAC,CAAA;aACZ;oBAAS;gBACR,MAAM,CAAC,GAAG,EAAE,CAAA;aACb;SACF;IACH,CAAC;CAAA;AA3KD,wBA2KC"}
package/dist/utils.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWin = exports.PLAYGROUNDINFO = exports.PLAYGROUNDREPO = exports.getOpenHost = void 0;
4
+ const os_1 = require("os");
5
+ function getOpenHost() {
6
+ var _a;
7
+ let result;
8
+ const interfaces = (0, os_1.networkInterfaces)();
9
+ for (const devName in interfaces) {
10
+ const isEnd = (_a = interfaces[devName]) === null || _a === void 0 ? void 0 : _a.some(item => {
11
+ // 取IPv4, 不为127.0.0.1的内网ip
12
+ if (['IPv4', 4, '4'].includes(item.family) && item.address !== '127.0.0.1' && !item.internal) {
13
+ result = item.address;
14
+ return true;
15
+ }
16
+ return false;
17
+ });
18
+ // 若获取到ip, 结束遍历
19
+ if (isEnd) {
20
+ break;
21
+ }
22
+ }
23
+ return result;
24
+ }
25
+ exports.getOpenHost = getOpenHost;
26
+ exports.PLAYGROUNDREPO = 'https://github.com/wuba/taro-playground';
27
+ exports.PLAYGROUNDINFO = `use [Taro Playground App](${exports.PLAYGROUNDREPO}) to scan`;
28
+ exports.isWin = /^win/.test(process.platform);
29
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,2BAAsC;AAEtC,SAAgB,WAAW;;IACzB,IAAI,MAAM,CAAA;IACV,MAAM,UAAU,GAAG,IAAA,sBAAiB,GAAE,CAAA;IACtC,KAAK,MAAM,OAAO,IAAI,UAAU,EAAE;QAChC,MAAM,KAAK,GAAG,MAAA,UAAU,CAAC,OAAO,CAAC,0CAAE,IAAI,CAAC,IAAI,CAAC,EAAE;YAC7C,0BAA0B;YAC1B,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,KAAK,WAAW,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAC5F,MAAM,GAAG,IAAI,CAAC,OAAO,CAAA;gBACrB,OAAO,IAAI,CAAA;aACZ;YACD,OAAO,KAAK,CAAA;QACd,CAAC,CAAC,CAAA;QACF,eAAe;QACf,IAAI,KAAK,EAAE;YACT,MAAK;SACN;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC;AAlBD,kCAkBC;AAEY,QAAA,cAAc,GAAG,yCAAyC,CAAA;AAE1D,QAAA,cAAc,GAAG,6BAA6B,sBAAc,WAAW,CAAA;AAEvE,QAAA,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/rn-runner",
3
- "version": "3.5.6-alpha.2",
3
+ "version": "3.5.7",
4
4
  "description": "ReactNative build tool for taro",
5
5
  "main": "index.js",
6
6
  "repository": {
@@ -21,20 +21,35 @@
21
21
  "npm": ">=6.0.0"
22
22
  },
23
23
  "dependencies": {
24
+ "@react-native-community/cli": "^8.0.0",
25
+ "@react-native-community/cli-config": "^8.0.0",
26
+ "@react-native-community/cli-plugin-metro": "^8.0.0",
27
+ "@react-native-community/cli-tools": "^8.0.0",
28
+ "@react-native-community/cli-server-api": "^8.0.0",
24
29
  "@rollup/plugin-babel": "^5.3.1",
25
30
  "@rollup/plugin-commonjs": "^20.0.0",
26
31
  "@rollup/plugin-json": "^4.1.0",
27
32
  "@rollup/plugin-node-resolve": "^13.3.0",
28
33
  "@rollup/plugin-replace": "^4.0.0",
29
- "@tarojs/helper": "3.5.6-alpha.2",
30
- "@tarojs/rn-style-transformer": "3.5.6-alpha.2",
31
- "@tarojs/rn-supporter": "3.5.6-alpha.2",
32
- "@tarojs/rn-transformer": "3.5.6-alpha.2",
34
+ "@tarojs/helper": "3.5.7",
35
+ "@tarojs/rn-style-transformer": "3.5.7",
36
+ "@tarojs/rn-supporter": "3.5.7",
37
+ "@tarojs/rn-transformer": "3.5.7",
33
38
  "acorn-jsx": "^5.3.2",
39
+ "fs-extra": "^8.0.1",
34
40
  "lodash": "^4.17.21",
41
+ "metro": "^0.70.3",
42
+ "metro-cache": "^0.70.3",
43
+ "metro-config": "^0.70.3",
44
+ "metro-core": "^0.70.3",
45
+ "metro-react-native-babel-transformer": "^0.70.3",
46
+ "metro-resolver": "^0.70.3",
47
+ "mime-types": "^2.1.27",
48
+ "qrcode-terminal": "^0.12.0",
35
49
  "rollup-plugin-image-file": "^1.0.2"
36
50
  },
37
51
  "devDependencies": {
52
+ "expo-file-system": "~14.1.0",
38
53
  "react-is": "^16.13.0",
39
54
  "react-native-root-siblings": "^4.1.1"
40
55
  },
@@ -0,0 +1,47 @@
1
+ import * as FileStore from 'metro-cache/src/stores/FileStore'
2
+
3
+ export default class ConditionalFileStore<T> {
4
+ ignoreEntryFileCache = false
5
+ _fileStore: FileStore<T>
6
+ entryName: string
7
+
8
+ constructor (options: any, entryName?: string) {
9
+ this._fileStore = new FileStore<T>(options)
10
+ this.entryName = entryName || 'app'
11
+ }
12
+
13
+ isEntryCache (cacheItem): boolean {
14
+ if (!cacheItem) return false
15
+ const { dependencies } = cacheItem
16
+ if (!dependencies || !dependencies.length) {
17
+ return false
18
+ }
19
+
20
+ for (const d of dependencies) {
21
+ if (d.name.includes(`${this.entryName}.config`)) {
22
+ return true
23
+ }
24
+ }
25
+ return false
26
+ }
27
+
28
+ async get (key: Buffer): Promise<T | null> {
29
+ const result = await this._fileStore.get(key)
30
+ if (result && this.ignoreEntryFileCache && this.isEntryCache(result)) {
31
+ return null
32
+ }
33
+ return result
34
+ }
35
+
36
+ async set (key: Buffer, value: any): Promise<void> {
37
+ // fix: 样式文件不写缓存
38
+ if (value?.output?.[0]?.data?.functionMap?.names?.indexOf('ignoreStyleFileCache') > -1) {
39
+ return
40
+ }
41
+ return await this._fileStore.set(key, value)
42
+ }
43
+
44
+ clear (): void {
45
+ this._fileStore.clear()
46
+ }
47
+ }
@@ -0,0 +1,70 @@
1
+ import { merge } from 'lodash'
2
+
3
+ import { Config, RNConfig } from '../types'
4
+
5
+ const fs = require('fs')
6
+
7
+ let config: Config
8
+ let rnConfig: RNConfig
9
+
10
+ const getConfig = () => {
11
+ if (config) return config
12
+ const fileName = `${process.cwd()}/config/index.js`
13
+ if (fs.existsSync(fileName)) {
14
+ config = require(`${process.cwd()}/config/index`)(merge)
15
+ return config
16
+ } else {
17
+ console.warn('缺少项目基本配置')
18
+ config = {}
19
+ return config
20
+ }
21
+ }
22
+
23
+ const getRNConfig = () => {
24
+ getConfig()
25
+ if (rnConfig) return rnConfig
26
+ if (config.rn) {
27
+ rnConfig = config.rn
28
+ } else {
29
+ rnConfig = {}
30
+ }
31
+ return rnConfig
32
+ }
33
+
34
+ const getRNConfigEntry = () => {
35
+ getRNConfig()
36
+ return rnConfig.entry || 'app'
37
+ }
38
+
39
+ const getRNConfigOutput = (p) => {
40
+ getRNConfig()
41
+ if (rnConfig.output) {
42
+ if (p === 'ios') {
43
+ return rnConfig.output.ios
44
+ } else {
45
+ return rnConfig.output.android
46
+ }
47
+ } else {
48
+ return null
49
+ }
50
+ }
51
+
52
+ const getRNConfigTransformer = () => {
53
+ getRNConfig()
54
+ if (rnConfig.transformer) {
55
+ return rnConfig.transformer
56
+ } else {
57
+ return null
58
+ }
59
+ }
60
+
61
+ const getRNConfigBabelPlugin = () => {
62
+ getRNConfig()
63
+ if (rnConfig.babelPlugin) {
64
+ return rnConfig.babelPlugin
65
+ } else {
66
+ return null
67
+ }
68
+ }
69
+
70
+ export { getConfig, getRNConfig, getRNConfigBabelPlugin, getRNConfigEntry, getRNConfigOutput, getRNConfigTransformer }
@@ -0,0 +1,76 @@
1
+ import resolveReactNativePath from '@react-native-community/cli-config/build/resolveReactNativePath'
2
+ import { findProjectRoot } from '@react-native-community/cli-tools'
3
+ import { Supporter } from '@tarojs/rn-supporter'
4
+ import * as Metro from 'metro'
5
+ import * as os from 'os'
6
+ import * as path from 'path'
7
+
8
+ import ConditionalFileStore from './conditional-file-store'
9
+
10
+ const reactNativePath: string = resolveReactNativePath(findProjectRoot())
11
+
12
+ type ResolveRequestFunc = (context, moduleName, platform) => any
13
+ type GetModulesRunBeforeMainModuleFunc = () => any
14
+ type GetPolyfillsFunc = () => any
15
+ interface MetroConfig {
16
+ transformer: {
17
+ dynamicDepsInPackages: string
18
+ babelTransformerPath: string
19
+ assetRegistryPath: string
20
+ }
21
+ resolver: {
22
+ sourceExts: string[]
23
+ resolveRequest?: ResolveRequestFunc
24
+ }
25
+ serializer: {
26
+ getModulesRunBeforeMainModule: GetModulesRunBeforeMainModuleFunc
27
+ getPolyfills: GetPolyfillsFunc
28
+ }
29
+ cacheStores: ConditionalFileStore<any>[]
30
+ server: {
31
+ port: number
32
+ }
33
+ }
34
+
35
+ const defaultConfig: MetroConfig = getDefaultConfig()
36
+
37
+ function getDefaultConfig () {
38
+ const supporter = new Supporter({ fromRunner: true })
39
+ const taroMetroConfig = supporter.getMetroConfig()
40
+ const metroConfig: MetroConfig = {
41
+ transformer: taroMetroConfig.transformer,
42
+ resolver: taroMetroConfig.resolver,
43
+ serializer: {
44
+ // We can include multiple copies of InitializeCore here because metro will
45
+ // only add ones that are already part of the bundle
46
+ getModulesRunBeforeMainModule: () => [
47
+ require.resolve(
48
+ path.join(reactNativePath, 'Libraries/Core/InitializeCore')
49
+ )
50
+ ],
51
+ getPolyfills: () =>
52
+ require(path.join(reactNativePath, 'rn-get-polyfills'))()
53
+ },
54
+ cacheStores: [new ConditionalFileStore<any>({
55
+ root: path.join(os.tmpdir(), 'metro-cache')
56
+ })],
57
+ server: {
58
+ port: 8081
59
+ }
60
+ }
61
+ return metroConfig
62
+ }
63
+
64
+ export default async (config: any) => {
65
+ const metroConfig = getDefaultConfig()
66
+ const res = await Metro.loadConfig({}, metroConfig)
67
+ if (!res.cacheStores || (res.cacheStores.length !== 1) || !(res.cacheStores[0] instanceof ConditionalFileStore)) {
68
+ throw new Error("cacheStores shouldn't be overridden in metro config.")
69
+ }
70
+ if (config.entry) {
71
+ res.cacheStores[0].entryName = config.entry
72
+ }
73
+ return res
74
+ }
75
+
76
+ export { defaultConfig }