Export Config/defaults on Metro's main module

Reviewed By: arcanis

Differential Revision: D6435529

fbshipit-source-id: a9549dc5900025fcc798ccb92b49e96c982c2e1e
This commit is contained in:
Christoph Nakazawa 2017-11-29 04:37:22 -08:00 committed by Facebook Github Bot
parent 0f7ad193c7
commit 66b381a5c7
2 changed files with 16 additions and 22 deletions

View File

@ -12,6 +12,7 @@
'use strict';
const Config = require('./Config');
const Http = require('http');
const Https = require('https');
const MetroBundler = require('./shared/output/bundle');
@ -20,29 +21,18 @@ const Terminal = require('./lib/Terminal');
const TerminalReporter = require('./lib/TerminalReporter');
const TransformCaching = require('./lib/TransformCaching');
const connect = require('connect');
const defaults = require('./defaults');
const {realpath} = require('fs');
const {readFile} = require('fs-extra');
const defaultAssetExts = require('./defaults').assetExts;
const defaultSourceExts = require('./defaults').sourceExts;
const defaultPlatforms = require('./defaults').platforms;
const defaultProvidesModuleNodeModules = require('./defaults')
.providesModuleNodeModules;
const DEFAULT_CONFIG = require('./Config').DEFAULT;
const normalizeConfig = require('./Config').normalize;
import type {ConfigT} from './Config';
import type {RequestOptions, OutputOptions} from './shared/types.flow.js';
import type {Options as ServerOptions} from './shared/types.flow';
import type {IncomingMessage, ServerResponse} from 'http';
import type {Server as HttpServer} from 'http';
import type {Server as HttpsServer} from 'https';
import type {ConfigT} from './Config';
import type {Options as ServerOptions} from './shared/types.flow';
import type {RequestOptions, OutputOptions} from './shared/types.flow.js';
export type {ConfigT} from './Config';
type PublicMetroOptions = {|
@ -80,12 +70,12 @@ async function runMetro({
projectRoots = [],
watch = false,
}: PrivateMetroOptions) {
const normalizedConfig = config ? normalizeConfig(config) : DEFAULT_CONFIG;
const normalizedConfig = config ? Config.normalize(config) : Config.DEFAULT;
const assetExts = defaultAssetExts.concat(
const assetExts = defaults.assetExts.concat(
(normalizedConfig.getAssetExts && normalizedConfig.getAssetExts()) || [],
);
const sourceExts = defaultSourceExts.concat(
const sourceExts = defaults.sourceExts.concat(
(normalizedConfig.getSourceExts && normalizedConfig.getSourceExts()) || [],
);
const platforms =
@ -98,7 +88,7 @@ async function runMetro({
const providesModuleNodeModules =
typeof normalizedConfig.getProvidesModuleNodeModules === 'function'
? normalizedConfig.getProvidesModuleNodeModules()
: defaultProvidesModuleNodeModules;
: defaults.providesModuleNodeModules;
const serverOptions: ServerOptions = {
assetExts: normalizedConfig.assetTransforms ? [] : assetExts,
@ -112,7 +102,7 @@ async function runMetro({
globalTransformCache: null,
hasteImpl: normalizedConfig.hasteImpl,
maxWorkers,
platforms: defaultPlatforms.concat(platforms),
platforms: defaults.platforms.concat(platforms),
postMinifyProcess: normalizedConfig.postMinifyProcess,
postProcessModules: normalizedConfig.postProcessModules,
postProcessBundleSourcemap: normalizedConfig.postProcessBundleSourcemap,
@ -174,6 +164,9 @@ type RunServerOptions = {|
|};
exports.runServer = async (options: RunServerOptions) => {
// Lazy require
const connect = require('connect');
const serverApp = connect();
const {middleware, end} = await exports.createConnectMiddleware({
@ -262,5 +255,8 @@ exports.runBuild = async (options: RunBuildOptions) => {
return {metroServer, metroBundle};
};
exports.Config = Config;
exports.defaults = defaults;
// The symbols below belong to the legacy API and should not be relied upon
Object.assign(exports, require('./legacy'));

View File

@ -12,7 +12,6 @@
'use strict';
const Config = require('./Config');
const Logger = require('./Logger');
const TransformCaching = require('./lib/TransformCaching');
@ -30,7 +29,6 @@ import type {Options as ServerOptions} from './shared/types.flow';
exports.createBlacklist = blacklist;
exports.sourceMaps = {fromRawMappings, compactMapping};
exports.createServer = createServer;
exports.Config = Config;
exports.Logger = Logger;
export type ConfigT = MetroConfig;