Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const ModuleCache = require("./ModuleCache");
const defaults = require("metro-config/src/defaults/defaults");
const parsePlatformFilePath = require("../../node-haste/lib/parsePlatformFilePath");
const path = require("path");
const _require = require("../../node-haste/DependencyGraph/ModuleResolution"),
ModuleResolver = _require.ModuleResolver;
const _require2 = require("jest-haste-map"),
ModuleMap = _require2.ModuleMap;
const platforms = new Set(defaults.platforms);
const GENERIC_PLATFORM = "g";
const PACKAGE_JSON = path.sep + "package.json";
const NULL_MODULE = {
path: "/",
getPackage() {},
isHaste() {
throw new Error("not implemented");
},
getName() {
throw new Error("not implemented");
}
}; // This function maps the ModuleGraph data structure to jest-haste-map's ModuleMap
async function restart(): Promise {
if (restarting) {
return;
} else {
restarting = true;
}
if (server) {
// eslint-disable-next-line no-console
console.log('Configuration changed. Restarting the server...');
await promisify(server.close).call(server);
}
const config = await loadConfig(argv);
server = await MetroApi.runServer(config, argv);
restarting = false;
}
async function restart(): Promise {
if (restarting) {
return;
} else {
restarting = true;
}
if (server) {
// eslint-disable-next-line no-console
console.log('Configuration changed. Restarting the server...');
await promisify(server.close).call(server);
}
const config = await loadConfig(argv);
server = await MetroApi.runServer(config, argv);
restarting = false;
}
}
if (server) {
// eslint-disable-next-line no-console
console.log('Configuration changed. Restarting the server...');
await promisify(server.close).call(server);
}
const config = await loadConfig(argv);
server = await MetroApi.runServer(config, argv);
restarting = false;
}
const foundConfig = await resolveConfig(argv.config, argv.cwd);
if (foundConfig) {
await watchFile(foundConfig.filepath, restart);
} else {
await restart();
}
}),
});
}
if (server) {
// eslint-disable-next-line no-console
console.log('Configuration changed. Restarting the server...');
await promisify(server.close).call(server);
}
const config = await loadConfig(argv);
server = await MetroApi.runServer(config, argv);
restarting = false;
}
const foundConfig = await resolveConfig(argv.config, argv.cwd);
if (foundConfig) {
await watchFile(foundConfig.filepath, restart);
} else {
await restart();
}
}),
});
async function configure(flags) {
const reactNativePath = path.dirname(require.resolve('react-native/package.json'));
const config = await loadConfig();
const custom = {
resolver: {},
serializer: {},
transformer: {},
cacheStores: [
new FileStore({
root: flags['cache-location']
})
]
};
//
// We need to create a fake package name that we will point to the root
// of the users directory so we can resolve their requires and test files
// without having to rely on `package.json` based resolve due to poor
// handling of absolute and relative paths.
function mergeConfig(...args) {
const mergedConfig = metroMergeConfig(...args);
// We need to remove the invalid `symbolicator` config key if it's present and empty.
if (
mergedConfig.symbolicator &&
Object.values(mergedConfig.symbolicator).length === 0
) {
delete mergedConfig.symbolicator;
}
return mergedConfig;
}
// - And point to the correct AssetRegistry, also hidden in the React-Native
// module.
//
// The `providesModuleNodeModules` and `hasteImplModulePath` are currently
// not needed to correctly configure metro for Ekke as we're replacing
// `react-native` with polyfill, but if we for some reason turn this off,
// we don't want to research the undocumented codebase of Metro, cli, and
// React-Native again to figure out how to correctly resolve and bundle
// React-Native.
//
custom.resolver.providesModuleNodeModules = ['react-native'];
custom.resolver.hasteImplModulePath = path.join(reactNativePath, 'jest/hasteImpl');
custom.resolver.resolverMainFields = ['react-native', 'browser', 'main'];
custom.transformer.assetRegistryPath = path.join(reactNativePath, 'Libraries/Image/AssetRegistry');
const merged = mergeConfig(config, custom);
debug('metro config', merged);
return merged;
}
deltaBundler
) {
// Get all the polyfills from the relevant option params (the
// `getPolyfills()` method and the `polyfillModuleNames` variable).
const polyfillModuleNames = config.serializer
.getPolyfills({
platform: options.platform
})
.concat(config.serializer.polyfillModuleNames);
const transformOptions = _objectSpread({}, options, {
type: "script"
});
const graph = yield deltaBundler.buildGraph(
[defaults.moduleSystem].concat(_toConsumableArray(polyfillModuleNames)),
{
resolve: yield transformHelpers.getResolveDependencyFn(
bundler,
options.platform
),
transform: yield transformHelpers.getTransformFn(
[defaults.moduleSystem].concat(
_toConsumableArray(polyfillModuleNames)
),
bundler,
deltaBundler,
config,
transformOptions
),
onProgress: null
}
): Promise<$ReadOnlyArray>> {
// Get all the polyfills from the relevant option params (the
// `getPolyfills()` method and the `polyfillModuleNames` variable).
const polyfillModuleNames = config.serializer
.getPolyfills({
platform: options.platform,
})
.concat(config.serializer.polyfillModuleNames);
const transformOptions: TransformInputOptions = {
...options,
type: 'script',
};
const graph = await deltaBundler.buildGraph(
[defaults.moduleSystem, ...polyfillModuleNames],
{
resolve: await transformHelpers.getResolveDependencyFn(
bundler,
options.platform,
),
transform: await transformHelpers.getTransformFn(
[defaults.moduleSystem, ...polyfillModuleNames],
bundler,
deltaBundler,
config,
transformOptions,
),
onProgress: null,
experimentalImportBundleSupport:
config.transformer.experimentalImportBundleSupport,
shallow: false,