@rnv/engine-rn
Version:
ReNative Engine to build react-native based platforms.
84 lines • 4.73 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.withRNVMetro = void 0;
var tslib_1 = require("tslib");
var sdk_react_native_1 = require("@rnv/sdk-react-native");
// TODO merge with packages/engine-rn-macos/src/adapters/metroAdapter.ts and place in @rnv/sdk-react-native
var path = require('path');
var sharedExclusions = [
/node_modules\/react\/dist\/.*/,
/website\/node_modules\/.*/,
/heapCapture\/bundle\.js/,
/.*\/__tests__\/.*/,
];
var env = process === null || process === void 0 ? void 0 : process.env;
function escapeRegExp(pattern) {
if (typeof pattern === 'string') {
// eslint-disable-next-line
var escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator
return escaped.replace(/\//g, "\\".concat(path.sep));
}
else if (Object.prototype.toString.call(pattern) === '[object RegExp]') {
return pattern.source.replace(/\//g, path.sep);
}
throw new Error("Unexpected exclusion pattern: ".concat(pattern));
}
function exclusionList(additionalExclusions) {
return tslib_1.__spreadArray(tslib_1.__spreadArray([], additionalExclusions, true), sharedExclusions, true).map(function (regexp) { return new RegExp(escapeRegExp(regexp)); });
}
var withRNVMetro = function (config) {
var _a, _b, _c, _d;
var projectPath = env.RNV_PROJECT_ROOT || process.cwd();
var defaultConfig = (0, sdk_react_native_1.withMetroConfig)(projectPath);
var watchFolders = [path.resolve(projectPath, 'node_modules')];
if (env.RNV_IS_MONOREPO === 'true' || env.RNV_IS_MONOREPO === true) {
var monoRootPath = env.RNV_MONO_ROOT || projectPath;
watchFolders.push(path.resolve(monoRootPath, 'node_modules'));
watchFolders.push(path.resolve(monoRootPath, 'packages'));
}
if ((_a = config === null || config === void 0 ? void 0 : config.watchFolders) === null || _a === void 0 ? void 0 : _a.length) {
watchFolders.push.apply(watchFolders, config.watchFolders);
}
var exts = env.RNV_EXTENSIONS || '';
var cnfRnv = {
transformer: {
getTransformOptions: function (entryPoints, options, getDependenciesOf) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var transformOptions;
var _a, _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, ((_b = (_a = config === null || config === void 0 ? void 0 : config.transformer) === null || _a === void 0 ? void 0 : _a.getTransformOptions) === null || _b === void 0 ? void 0 : _b.call(_a, entryPoints, options, getDependenciesOf))];
case 1:
transformOptions = (_c.sent()) || {};
return [2 /*return*/, tslib_1.__assign(tslib_1.__assign({}, transformOptions), { transform: tslib_1.__assign({ experimentalImportSupport: false,
// this defeats the RCTDeviceEventEmitter is not a registered callable module
inlineRequires: true }, ((transformOptions === null || transformOptions === void 0 ? void 0 : transformOptions.transform) || {})) })];
}
});
}); },
},
resolver: {
blockList: exclusionList([
/platformBuilds\/.*/,
/buildHooks\/.*/,
/projectConfig\/.*/,
/website\/.*/,
/appConfigs\/.*/,
/renative.local.*/,
/metro.config.local.*/,
/.expo\/.*/,
/.rollup.cache\/.*/,
]
.concat(((_b = config === null || config === void 0 ? void 0 : config.resolver) === null || _b === void 0 ? void 0 : _b.blockList) || [])
.concat(((_c = config === null || config === void 0 ? void 0 : config.resolver) === null || _c === void 0 ? void 0 : _c.blacklistRE) || [])),
blacklistRE: undefined,
sourceExts: tslib_1.__spreadArray(tslib_1.__spreadArray([], (((_d = config === null || config === void 0 ? void 0 : config.resolver) === null || _d === void 0 ? void 0 : _d.sourceExts) || []), true), exts.split(','), true),
},
watchFolders: watchFolders,
projectRoot: (config === null || config === void 0 ? void 0 : config.projectRoot) || path.resolve(projectPath),
};
var cnf = (0, sdk_react_native_1.mergeConfig)(defaultConfig, config, cnfRnv);
return cnf;
};
exports.withRNVMetro = withRNVMetro;
//# sourceMappingURL=metroAdapter.js.map
;