@rnv/engine-rn-tvos
Version:
ReNative Engine to build react-native tvos platform.
118 lines • 6.76 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");
var path = require('path');
var os = require('os');
var doResolve = require('@rnv/core').doResolve;
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, _e;
var projectPath = env.RNV_PROJECT_ROOT || process.cwd();
var defaultConfig = (0, sdk_react_native_1.withMetroConfig)(projectPath);
var watchFolders = [path.resolve(projectPath, 'node_modules')];
var metroCache = require(require.resolve('metro-cache', { paths: [projectPath] }));
var FileStore = metroCache.FileStore;
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 = {
cacheStores: function (metroCache) {
var _a;
var cacheStores = [];
if (typeof (config === null || config === void 0 ? void 0 : config.cacheStores) === 'function') {
cacheStores = config.cacheStores(metroCache);
}
else if ((_a = config === null || config === void 0 ? void 0 : config.cacheStores) === null || _a === void 0 ? void 0 : _a.length) {
// eslint-disable-next-line prefer-destructuring
cacheStores = config.cacheStores;
}
cacheStores = tslib_1.__spreadArray(tslib_1.__spreadArray([], cacheStores, true), [
new FileStore({
root: path.join(os.tmpdir(), 'metro-cache-tvos'),
}),
], false);
return cacheStores;
},
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) || {})) })];
}
});
}); },
assetRegistryPath: ((_b = config === null || config === void 0 ? void 0 : config.transformer) === null || _b === void 0 ? void 0 : _b.assetRegistryPath) ||
path.resolve("".concat(doResolve('react-native-tvos'), "/Libraries/Image/AssetRegistry.js")),
},
resolver: {
resolveRequest: function (context, moduleName, platform) {
var _a;
if (moduleName.startsWith('react-native/')) {
return context.resolveRequest(context, moduleName.replace('react-native/', 'react-native-tvos/'), platform);
}
// Chain to the custom config resolver if provided.
if (typeof ((_a = config === null || config === void 0 ? void 0 : config.resolver) === null || _a === void 0 ? void 0 : _a.resolveRequest) === 'function') {
return config.resolver.resolveRequest(context, moduleName, platform);
}
// Optionally, chain to the standard Metro resolver.
return context.resolveRequest(context, moduleName, platform);
},
blockList: exclusionList([
/platformBuilds\/.*/,
/buildHooks\/.*/,
/projectConfig\/.*/,
/website\/.*/,
/appConfigs\/.*/,
/renative.local.*/,
/metro.config.local.*/,
/.expo\/.*/,
/.rollup.cache\/.*/,
]
.concat(((_c = config === null || config === void 0 ? void 0 : config.resolver) === null || _c === void 0 ? void 0 : _c.blockList) || [])
.concat(((_d = config === null || config === void 0 ? void 0 : config.resolver) === null || _d === void 0 ? void 0 : _d.blacklistRE) || [])),
blacklistRE: undefined,
sourceExts: tslib_1.__spreadArray(tslib_1.__spreadArray([], (((_e = config === null || config === void 0 ? void 0 : config.resolver) === null || _e === void 0 ? void 0 : _e.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
;