Skip to content

Commit d3bc80c

Browse files
committed
perf:module path regex check
1 parent 0457275 commit d3bc80c

File tree

1 file changed

+6
-4
lines changed
  • react-native/packager/react-packager/src/Resolver

1 file changed

+6
-4
lines changed

react-native/packager/react-packager/src/Resolver/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ const declareOpts = require('../lib/declareOpts');
1616
const Promise = require('promise');
1717
// @Denis 获取模块名单
1818
const fs = require('fs');
19+
const cwd = process.cwd();
1920
let rnBlackList = [];
2021
let rnSimpleBL = [];
2122
let rnRegExpBL = [];
2223

2324
if(process.env.RN_BLACKLIST_PATH){
2425
rnBlackList = require(process.env.RN_BLACKLIST_PATH);
25-
} else if (fs.existsSync(path.join(process.cwd(), 'rn-blacklist.js'))) {
26+
} else if (fs.existsSync(path.join(cwd, 'rn-blacklist.js'))) {
2627
rnBlackList = require(process.cwd() + '/rn-blacklist.js');
2728
}
2829

@@ -187,7 +188,7 @@ class Resolver {
187188
} else {
188189
let dependencies = [];
189190
resolutionResponse.dependencies.forEach(mp => {
190-
if (rnSimpleBL.indexOf(mp.moduleName) > -1 || this._regexpBLTest(mp.moduleName)) {
191+
if (rnSimpleBL.indexOf(mp.moduleName) > -1 || this._regexpBLTest(mp.path)) {
191192
resolutionResponse._mappings[mp.hash()] && delete resolutionResponse._mappings[mp.hash()];
192193
} else {
193194
console.log("> ", mp.moduleName);
@@ -202,9 +203,10 @@ class Resolver {
202203
}
203204

204205
// @Denis
205-
_regexpBLTest(moduleName) {
206+
// 正则对path的匹配
207+
_regexpBLTest(modulePath) {
206208
for (const i in rnRegExpBL) {
207-
if (rnRegExpBL[i].test(moduleName)) {
209+
if (rnRegExpBL[i].test(modulePath.replace(cwd, ''))) {
208210
return true;
209211
}
210212
}

0 commit comments

Comments
 (0)