@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/dist/config/preview.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs_1 = require("fs");
|
|
4
|
-
const http_1 = require("http");
|
|
5
|
-
const mime = require("mime-types");
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const qr = require("qrcode-terminal");
|
|
8
|
-
const url_1 = require("url");
|
|
9
|
-
const utils_1 = require("../utils");
|
|
10
|
-
const drawableFileTypes = new Set([
|
|
11
|
-
'gif',
|
|
12
|
-
'jpeg',
|
|
13
|
-
'jpg',
|
|
14
|
-
'png',
|
|
15
|
-
'webp',
|
|
16
|
-
'xml'
|
|
17
|
-
]);
|
|
18
|
-
function getAndroidAssetSuffix(scale) {
|
|
19
|
-
switch (scale) {
|
|
20
|
-
case 0.75:
|
|
21
|
-
return 'ldpi';
|
|
22
|
-
case 1:
|
|
23
|
-
return 'mdpi';
|
|
24
|
-
case 1.5:
|
|
25
|
-
return 'hdpi';
|
|
26
|
-
case 2:
|
|
27
|
-
return 'xhdpi';
|
|
28
|
-
case 3:
|
|
29
|
-
return 'xxhdpi';
|
|
30
|
-
case 4:
|
|
31
|
-
return 'xxxhdpi';
|
|
32
|
-
default:
|
|
33
|
-
return '';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
function getAndroidResourceFolderName(pathname) {
|
|
37
|
-
const ext = (0, path_1.extname)(pathname).replace(/^./, '').toLowerCase();
|
|
38
|
-
if (!drawableFileTypes.has(ext)) {
|
|
39
|
-
return 'raw';
|
|
40
|
-
}
|
|
41
|
-
const suffix = getAndroidAssetSuffix(1); // TODO: auto scale
|
|
42
|
-
const androidFolder = `drawable-${suffix}`;
|
|
43
|
-
return androidFolder;
|
|
44
|
-
}
|
|
45
|
-
function getAndroidResourceIdentifier(pathname) {
|
|
46
|
-
if (pathname[0] === '/') {
|
|
47
|
-
pathname = pathname.substr(1);
|
|
48
|
-
}
|
|
49
|
-
const ext = (0, path_1.extname)(pathname).toLowerCase();
|
|
50
|
-
const extReg = new RegExp(ext + '$');
|
|
51
|
-
return pathname
|
|
52
|
-
.replace(extReg, '')
|
|
53
|
-
.toLowerCase()
|
|
54
|
-
.replace(/\//g, '_')
|
|
55
|
-
.replace(/([^a-z0-9_])/g, '')
|
|
56
|
-
.replace(/^assets_/, '') + ext;
|
|
57
|
-
}
|
|
58
|
-
exports.default = (opt) => {
|
|
59
|
-
const port = process.env.PORT || 8079;
|
|
60
|
-
const host = `http://${(0, utils_1.getOpenHost)()}:${port}`;
|
|
61
|
-
(0, http_1.createServer)(function (request, response) {
|
|
62
|
-
const url = new url_1.URL(request.url || '', host);
|
|
63
|
-
console.log(`${request.method} ${request.url}`);
|
|
64
|
-
if (url.pathname === '/inspector/device') {
|
|
65
|
-
response.writeHead(404);
|
|
66
|
-
response.end('404', 'utf-8');
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
let filePath;
|
|
70
|
-
const contentType = mime.lookup(url.pathname);
|
|
71
|
-
if (url.pathname === '/index.js') {
|
|
72
|
-
filePath = opt.out;
|
|
73
|
-
}
|
|
74
|
-
else if (opt.platform === 'ios') {
|
|
75
|
-
filePath = (0, path_1.join)(opt.assetsDest || '', url.pathname);
|
|
76
|
-
}
|
|
77
|
-
else if (opt.platform === 'android') {
|
|
78
|
-
filePath = (0, path_1.join)(opt.assetsDest || '', getAndroidResourceFolderName(url.pathname), getAndroidResourceIdentifier(url.pathname));
|
|
79
|
-
}
|
|
80
|
-
(0, fs_1.readFile)(filePath, function (error, content) {
|
|
81
|
-
if (error) {
|
|
82
|
-
if (error.code === 'ENOENT') {
|
|
83
|
-
response.writeHead(404);
|
|
84
|
-
response.end('404', 'utf-8');
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
response.writeHead(500);
|
|
88
|
-
response.end('500', 'utf-8');
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
response.writeHead(200, { 'Content-Type': contentType });
|
|
93
|
-
response.end(content, 'utf-8');
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}).listen(port);
|
|
97
|
-
const url = `${host}/index.js`;
|
|
98
|
-
console.log(utils_1.PLAYGROUNDINFO);
|
|
99
|
-
console.log(`print qrcode of ${opt.platform} bundle '${url}':`);
|
|
100
|
-
qr.generate(url, { small: !utils_1.isWin });
|
|
101
|
-
};
|
|
102
|
-
//# sourceMappingURL=preview.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"preview.js","sourceRoot":"","sources":["../../src/config/preview.ts"],"names":[],"mappings":";;AAAA,2BAA6B;AAC7B,+BAAmC;AACnC,mCAAkC;AAClC,+BAAoC;AACpC,sCAAqC;AACrC,6B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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.TerminalReporter = void 0;
|
|
13
|
-
const rn_supporter_1 = require("@tarojs/rn-supporter");
|
|
14
|
-
const MetroTerminalReporter = require("metro/src/lib/TerminalReporter");
|
|
15
|
-
const metro_core_1 = require("metro-core");
|
|
16
|
-
class TerminalReporter {
|
|
17
|
-
constructor(entry, sourceRoot, conditionalFileStore, metroServerInstance) {
|
|
18
|
-
this._reporter = new MetroTerminalReporter(new metro_core_1.Terminal(process.stdout));
|
|
19
|
-
this._conditionalFileStore = conditionalFileStore;
|
|
20
|
-
this.metroServerInstance = metroServerInstance;
|
|
21
|
-
this._initialized = false;
|
|
22
|
-
this._entry = entry;
|
|
23
|
-
this._sourceRoot = sourceRoot;
|
|
24
|
-
}
|
|
25
|
-
update(args) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
// 当依赖图加载之后,检测app和页面配置文件的变化
|
|
28
|
-
switch (args.type) {
|
|
29
|
-
case 'initialize_started':
|
|
30
|
-
this._reporter.terminal.log(`
|
|
31
|
-
##### ## ##### #### ##### ###### ## #### ##### # # ## ##### # # # ######
|
|
32
|
-
# # # # # # # # # # # # # # # ## # # # # # # # #
|
|
33
|
-
# # # # # # # # # ##### # # # # # # # # # # # # # #####
|
|
34
|
-
# ###### ##### # # ##### # ###### # # # # # ###### # # # # #
|
|
35
|
-
# # # # # # # # # # # # # # # # ## # # # # # # #
|
|
36
|
-
# # # # # #### # # ###### # # #### # # # # # # # ## ######
|
|
37
|
-
`);
|
|
38
|
-
break;
|
|
39
|
-
case 'bundle_build_started':
|
|
40
|
-
args.bundleDetails.entryFile = './index';
|
|
41
|
-
this._reporter.update(args);
|
|
42
|
-
break;
|
|
43
|
-
case 'bundle_build_done':
|
|
44
|
-
{
|
|
45
|
-
this._reporter.update(args);
|
|
46
|
-
const realEntryPath = require.resolve(rn_supporter_1.emptyModulePath);
|
|
47
|
-
if (this._initialized) {
|
|
48
|
-
// 恢复入口页面的缓存
|
|
49
|
-
this._reporter.ignoreEntryFileCache = false;
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
this._initialized = true;
|
|
53
|
-
if (!this.metroServerInstance) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const incrementalBundler = this.metroServerInstance.getBundler();
|
|
57
|
-
const deltaBundler = incrementalBundler.getDeltaBundler();
|
|
58
|
-
const bundler = incrementalBundler.getBundler();
|
|
59
|
-
const findEntryGraphId = keys => {
|
|
60
|
-
for (const k of keys) {
|
|
61
|
-
if (JSON.parse(k).entryFile === realEntryPath) {
|
|
62
|
-
return k;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return null;
|
|
66
|
-
};
|
|
67
|
-
// 获取入口文件的graph
|
|
68
|
-
const entryGraphId = findEntryGraphId(incrementalBundler._revisionsByGraphId.keys());
|
|
69
|
-
const entryGraphVersion = yield incrementalBundler.getRevisionByGraphId(entryGraphId);
|
|
70
|
-
// 监听DeltaCalculator的change事件,把入口文件也加入到_modifiedFiles集合中
|
|
71
|
-
bundler.getDependencyGraph().then(dependencyGraph => {
|
|
72
|
-
dependencyGraph.getWatcher().on('change', ({ eventsQueue }) => {
|
|
73
|
-
const changedFiles = eventsQueue.map(item => item.filePath);
|
|
74
|
-
// 如果配置文件修改之后,把入口文件添加到修改列表中
|
|
75
|
-
const deltaCalculator = deltaBundler._deltaCalculators.get(entryGraphVersion.graph);
|
|
76
|
-
const isConfigurationModified = keys => {
|
|
77
|
-
for (const k of keys) {
|
|
78
|
-
if (k.includes('.config') && k.includes(this._sourceRoot)) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
};
|
|
84
|
-
if (isConfigurationModified(changedFiles)) {
|
|
85
|
-
// 忽略入口文件的转译结果缓存
|
|
86
|
-
this._conditionalFileStore.ignoreEntryFileCache = true;
|
|
87
|
-
deltaCalculator._modifiedFiles.add(realEntryPath);
|
|
88
|
-
this._reporter.terminal.flush();
|
|
89
|
-
console.log('\nConfiguration(s) are changed.');
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
this._reporter.update(args);
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.TerminalReporter = TerminalReporter;
|
|
103
|
-
//# sourceMappingURL=terminal-reporter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"terminal-reporter.js","sourceRoot":"","sources":["../../src/config/terminal-reporter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uDAAsD;AACtD,wEAAuE;AACvE,2CAAqC;AAErC,MAAa,gBAAgB;IAQ3B,YAAa,KAAa,EAAE,UAAkB,EAAE,oBAAyB,EAAE,mBAAyB;QAClG,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAqB,CAAC,IAAI,qBAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;QACxE,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAA;QACjD,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAA;QAC9C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAA;QACzB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,WA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oBACE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;oBAC3B,MAAK;aACR;QACH,CAAC;KAAA;CACF;AA3FD,4CA2FC"}
|
package/dist/utils.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
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
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,47 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
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 }
|
package/src/config/index.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
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 }
|
package/src/config/preview.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { readFile } from 'fs'
|
|
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
|
-
import { URL } from 'url'
|
|
7
|
-
|
|
8
|
-
import { getOpenHost, isWin, PLAYGROUNDINFO } from '../utils'
|
|
9
|
-
|
|
10
|
-
interface PreviewOption {
|
|
11
|
-
out: string
|
|
12
|
-
platform: string
|
|
13
|
-
assetsDest?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const drawableFileTypes = new Set<string>([
|
|
17
|
-
'gif',
|
|
18
|
-
'jpeg',
|
|
19
|
-
'jpg',
|
|
20
|
-
'png',
|
|
21
|
-
'webp',
|
|
22
|
-
'xml'
|
|
23
|
-
])
|
|
24
|
-
|
|
25
|
-
function getAndroidAssetSuffix (scale: number): string {
|
|
26
|
-
switch (scale) {
|
|
27
|
-
case 0.75:
|
|
28
|
-
return 'ldpi'
|
|
29
|
-
case 1:
|
|
30
|
-
return 'mdpi'
|
|
31
|
-
case 1.5:
|
|
32
|
-
return 'hdpi'
|
|
33
|
-
case 2:
|
|
34
|
-
return 'xhdpi'
|
|
35
|
-
case 3:
|
|
36
|
-
return 'xxhdpi'
|
|
37
|
-
case 4:
|
|
38
|
-
return 'xxxhdpi'
|
|
39
|
-
default:
|
|
40
|
-
return ''
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getAndroidResourceFolderName (pathname:string): string {
|
|
45
|
-
const ext = extname(pathname).replace(/^./, '').toLowerCase()
|
|
46
|
-
if (!drawableFileTypes.has(ext)) {
|
|
47
|
-
return 'raw'
|
|
48
|
-
}
|
|
49
|
-
const suffix = getAndroidAssetSuffix(1) // TODO: auto scale
|
|
50
|
-
const androidFolder = `drawable-${suffix}`
|
|
51
|
-
return androidFolder
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function getAndroidResourceIdentifier (pathname:string): string {
|
|
55
|
-
if (pathname[0] === '/') {
|
|
56
|
-
pathname = pathname.substr(1)
|
|
57
|
-
}
|
|
58
|
-
const ext = extname(pathname).toLowerCase()
|
|
59
|
-
const extReg = new RegExp(ext + '$')
|
|
60
|
-
return pathname
|
|
61
|
-
.replace(extReg, '')
|
|
62
|
-
.toLowerCase()
|
|
63
|
-
.replace(/\//g, '_')
|
|
64
|
-
.replace(/([^a-z0-9_])/g, '')
|
|
65
|
-
.replace(/^assets_/, '') + ext
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default (opt: PreviewOption):void => {
|
|
69
|
-
const port = process.env.PORT || 8079
|
|
70
|
-
const host = `http://${getOpenHost()}:${port}`
|
|
71
|
-
|
|
72
|
-
createServer(function (request, response) {
|
|
73
|
-
const url = new URL(request.url || '', host)
|
|
74
|
-
|
|
75
|
-
console.log(`${request.method} ${request.url}`)
|
|
76
|
-
|
|
77
|
-
if (url.pathname === '/inspector/device') {
|
|
78
|
-
response.writeHead(404)
|
|
79
|
-
response.end('404', 'utf-8')
|
|
80
|
-
return
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let filePath
|
|
84
|
-
const contentType = mime.lookup(url.pathname)
|
|
85
|
-
|
|
86
|
-
if (url.pathname === '/index.js') {
|
|
87
|
-
filePath = opt.out
|
|
88
|
-
} else if (opt.platform === 'ios') {
|
|
89
|
-
filePath = join(opt.assetsDest || '', url.pathname)
|
|
90
|
-
} else if (opt.platform === 'android') {
|
|
91
|
-
filePath = join(opt.assetsDest || '', getAndroidResourceFolderName(url.pathname), getAndroidResourceIdentifier(url.pathname))
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
readFile(filePath, function (error, content) {
|
|
95
|
-
if (error) {
|
|
96
|
-
if (error.code === 'ENOENT') {
|
|
97
|
-
response.writeHead(404)
|
|
98
|
-
response.end('404', 'utf-8')
|
|
99
|
-
} else {
|
|
100
|
-
response.writeHead(500)
|
|
101
|
-
response.end('500', 'utf-8')
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
response.writeHead(200, { 'Content-Type': contentType })
|
|
105
|
-
response.end(content, 'utf-8')
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
}).listen(port)
|
|
109
|
-
|
|
110
|
-
const url = `${host}/index.js`
|
|
111
|
-
console.log(PLAYGROUNDINFO)
|
|
112
|
-
console.log(`print qrcode of ${opt.platform} bundle '${url}':`)
|
|
113
|
-
qr.generate(url, { small: !isWin })
|
|
114
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { emptyModulePath } from '@tarojs/rn-supporter'
|
|
2
|
-
import * as MetroTerminalReporter from 'metro/src/lib/TerminalReporter'
|
|
3
|
-
import { Terminal } from 'metro-core'
|
|
4
|
-
|
|
5
|
-
export class TerminalReporter {
|
|
6
|
-
_reporter: any
|
|
7
|
-
_conditionalFileStore: any
|
|
8
|
-
metroServerInstance: any
|
|
9
|
-
_initialized: boolean
|
|
10
|
-
_entry: string
|
|
11
|
-
_sourceRoot: string
|
|
12
|
-
|
|
13
|
-
constructor (entry: string, sourceRoot: string, conditionalFileStore: any, metroServerInstance?: any) {
|
|
14
|
-
this._reporter = new MetroTerminalReporter(new Terminal(process.stdout))
|
|
15
|
-
this._conditionalFileStore = conditionalFileStore
|
|
16
|
-
this.metroServerInstance = metroServerInstance
|
|
17
|
-
this._initialized = false
|
|
18
|
-
this._entry = entry
|
|
19
|
-
this._sourceRoot = sourceRoot
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async update (args) {
|
|
23
|
-
// 当依赖图加载之后,检测app和页面配置文件的变化
|
|
24
|
-
switch (args.type) {
|
|
25
|
-
case 'initialize_started':
|
|
26
|
-
this._reporter.terminal.log(`
|
|
27
|
-
##### ## ##### #### ##### ###### ## #### ##### # # ## ##### # # # ######
|
|
28
|
-
# # # # # # # # # # # # # # # ## # # # # # # # #
|
|
29
|
-
# # # # # # # # # ##### # # # # # # # # # # # # # #####
|
|
30
|
-
# ###### ##### # # ##### # ###### # # # # # ###### # # # # #
|
|
31
|
-
# # # # # # # # # # # # # # # # ## # # # # # # #
|
|
32
|
-
# # # # # #### # # ###### # # #### # # # # # # # ## ######
|
|
33
|
-
`)
|
|
34
|
-
break
|
|
35
|
-
case 'bundle_build_started':
|
|
36
|
-
args.bundleDetails.entryFile = './index'
|
|
37
|
-
this._reporter.update(args)
|
|
38
|
-
break
|
|
39
|
-
case 'bundle_build_done': {
|
|
40
|
-
this._reporter.update(args)
|
|
41
|
-
const realEntryPath = require.resolve(emptyModulePath)
|
|
42
|
-
if (this._initialized) {
|
|
43
|
-
// 恢复入口页面的缓存
|
|
44
|
-
this._reporter.ignoreEntryFileCache = false
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
this._initialized = true
|
|
48
|
-
if (!this.metroServerInstance) {
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
const incrementalBundler = this.metroServerInstance.getBundler()
|
|
52
|
-
const deltaBundler = incrementalBundler.getDeltaBundler()
|
|
53
|
-
const bundler = incrementalBundler.getBundler()
|
|
54
|
-
const findEntryGraphId = keys => {
|
|
55
|
-
for (const k of keys) {
|
|
56
|
-
if (JSON.parse(k).entryFile === realEntryPath) {
|
|
57
|
-
return k
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return null
|
|
61
|
-
}
|
|
62
|
-
// 获取入口文件的graph
|
|
63
|
-
const entryGraphId = findEntryGraphId(incrementalBundler._revisionsByGraphId.keys())
|
|
64
|
-
const entryGraphVersion = await incrementalBundler.getRevisionByGraphId(entryGraphId)
|
|
65
|
-
|
|
66
|
-
// 监听DeltaCalculator的change事件,把入口文件也加入到_modifiedFiles集合中
|
|
67
|
-
bundler.getDependencyGraph().then(dependencyGraph => {
|
|
68
|
-
dependencyGraph.getWatcher().on('change', ({ eventsQueue }) => {
|
|
69
|
-
const changedFiles = eventsQueue.map(item => item.filePath)
|
|
70
|
-
// 如果配置文件修改之后,把入口文件添加到修改列表中
|
|
71
|
-
const deltaCalculator = deltaBundler._deltaCalculators.get(entryGraphVersion.graph)
|
|
72
|
-
const isConfigurationModified = keys => {
|
|
73
|
-
for (const k of keys) {
|
|
74
|
-
if (k.includes('.config') && k.includes(this._sourceRoot)) {
|
|
75
|
-
return true
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return false
|
|
79
|
-
}
|
|
80
|
-
if (isConfigurationModified(changedFiles)) {
|
|
81
|
-
// 忽略入口文件的转译结果缓存
|
|
82
|
-
this._conditionalFileStore.ignoreEntryFileCache = true
|
|
83
|
-
deltaCalculator._modifiedFiles.add(realEntryPath)
|
|
84
|
-
this._reporter.terminal.flush()
|
|
85
|
-
console.log('\nConfiguration(s) are changed.')
|
|
86
|
-
}
|
|
87
|
-
})
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
break
|
|
91
|
-
default:
|
|
92
|
-
this._reporter.update(args)
|
|
93
|
-
break
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|