mirror of
https://github.com/status-im/metro.git
synced 2025-02-08 01:03:28 +00:00
Export Config/defaults on Metro's main module
Reviewed By: arcanis Differential Revision: D6435529 fbshipit-source-id: a9549dc5900025fcc798ccb92b49e96c982c2e1e
This commit is contained in:
parent
0f7ad193c7
commit
66b381a5c7
@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const Config = require('./Config');
|
||||||
const Http = require('http');
|
const Http = require('http');
|
||||||
const Https = require('https');
|
const Https = require('https');
|
||||||
const MetroBundler = require('./shared/output/bundle');
|
const MetroBundler = require('./shared/output/bundle');
|
||||||
@ -20,29 +21,18 @@ const Terminal = require('./lib/Terminal');
|
|||||||
const TerminalReporter = require('./lib/TerminalReporter');
|
const TerminalReporter = require('./lib/TerminalReporter');
|
||||||
const TransformCaching = require('./lib/TransformCaching');
|
const TransformCaching = require('./lib/TransformCaching');
|
||||||
|
|
||||||
const connect = require('connect');
|
const defaults = require('./defaults');
|
||||||
|
|
||||||
const {realpath} = require('fs');
|
const {realpath} = require('fs');
|
||||||
const {readFile} = require('fs-extra');
|
const {readFile} = require('fs-extra');
|
||||||
|
|
||||||
const defaultAssetExts = require('./defaults').assetExts;
|
import type {ConfigT} from './Config';
|
||||||
const defaultSourceExts = require('./defaults').sourceExts;
|
import type {RequestOptions, OutputOptions} from './shared/types.flow.js';
|
||||||
const defaultPlatforms = require('./defaults').platforms;
|
import type {Options as ServerOptions} from './shared/types.flow';
|
||||||
const defaultProvidesModuleNodeModules = require('./defaults')
|
|
||||||
.providesModuleNodeModules;
|
|
||||||
|
|
||||||
const DEFAULT_CONFIG = require('./Config').DEFAULT;
|
|
||||||
const normalizeConfig = require('./Config').normalize;
|
|
||||||
|
|
||||||
import type {IncomingMessage, ServerResponse} from 'http';
|
import type {IncomingMessage, ServerResponse} from 'http';
|
||||||
|
|
||||||
import type {Server as HttpServer} from 'http';
|
import type {Server as HttpServer} from 'http';
|
||||||
import type {Server as HttpsServer} from 'https';
|
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';
|
export type {ConfigT} from './Config';
|
||||||
|
|
||||||
type PublicMetroOptions = {|
|
type PublicMetroOptions = {|
|
||||||
@ -80,12 +70,12 @@ async function runMetro({
|
|||||||
projectRoots = [],
|
projectRoots = [],
|
||||||
watch = false,
|
watch = false,
|
||||||
}: PrivateMetroOptions) {
|
}: 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()) || [],
|
(normalizedConfig.getAssetExts && normalizedConfig.getAssetExts()) || [],
|
||||||
);
|
);
|
||||||
const sourceExts = defaultSourceExts.concat(
|
const sourceExts = defaults.sourceExts.concat(
|
||||||
(normalizedConfig.getSourceExts && normalizedConfig.getSourceExts()) || [],
|
(normalizedConfig.getSourceExts && normalizedConfig.getSourceExts()) || [],
|
||||||
);
|
);
|
||||||
const platforms =
|
const platforms =
|
||||||
@ -98,7 +88,7 @@ async function runMetro({
|
|||||||
const providesModuleNodeModules =
|
const providesModuleNodeModules =
|
||||||
typeof normalizedConfig.getProvidesModuleNodeModules === 'function'
|
typeof normalizedConfig.getProvidesModuleNodeModules === 'function'
|
||||||
? normalizedConfig.getProvidesModuleNodeModules()
|
? normalizedConfig.getProvidesModuleNodeModules()
|
||||||
: defaultProvidesModuleNodeModules;
|
: defaults.providesModuleNodeModules;
|
||||||
|
|
||||||
const serverOptions: ServerOptions = {
|
const serverOptions: ServerOptions = {
|
||||||
assetExts: normalizedConfig.assetTransforms ? [] : assetExts,
|
assetExts: normalizedConfig.assetTransforms ? [] : assetExts,
|
||||||
@ -112,7 +102,7 @@ async function runMetro({
|
|||||||
globalTransformCache: null,
|
globalTransformCache: null,
|
||||||
hasteImpl: normalizedConfig.hasteImpl,
|
hasteImpl: normalizedConfig.hasteImpl,
|
||||||
maxWorkers,
|
maxWorkers,
|
||||||
platforms: defaultPlatforms.concat(platforms),
|
platforms: defaults.platforms.concat(platforms),
|
||||||
postMinifyProcess: normalizedConfig.postMinifyProcess,
|
postMinifyProcess: normalizedConfig.postMinifyProcess,
|
||||||
postProcessModules: normalizedConfig.postProcessModules,
|
postProcessModules: normalizedConfig.postProcessModules,
|
||||||
postProcessBundleSourcemap: normalizedConfig.postProcessBundleSourcemap,
|
postProcessBundleSourcemap: normalizedConfig.postProcessBundleSourcemap,
|
||||||
@ -174,6 +164,9 @@ type RunServerOptions = {|
|
|||||||
|};
|
|};
|
||||||
|
|
||||||
exports.runServer = async (options: RunServerOptions) => {
|
exports.runServer = async (options: RunServerOptions) => {
|
||||||
|
// Lazy require
|
||||||
|
const connect = require('connect');
|
||||||
|
|
||||||
const serverApp = connect();
|
const serverApp = connect();
|
||||||
|
|
||||||
const {middleware, end} = await exports.createConnectMiddleware({
|
const {middleware, end} = await exports.createConnectMiddleware({
|
||||||
@ -262,5 +255,8 @@ exports.runBuild = async (options: RunBuildOptions) => {
|
|||||||
return {metroServer, metroBundle};
|
return {metroServer, metroBundle};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.Config = Config;
|
||||||
|
exports.defaults = defaults;
|
||||||
|
|
||||||
// The symbols below belong to the legacy API and should not be relied upon
|
// The symbols below belong to the legacy API and should not be relied upon
|
||||||
Object.assign(exports, require('./legacy'));
|
Object.assign(exports, require('./legacy'));
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const Config = require('./Config');
|
|
||||||
const Logger = require('./Logger');
|
const Logger = require('./Logger');
|
||||||
const TransformCaching = require('./lib/TransformCaching');
|
const TransformCaching = require('./lib/TransformCaching');
|
||||||
|
|
||||||
@ -30,7 +29,6 @@ import type {Options as ServerOptions} from './shared/types.flow';
|
|||||||
exports.createBlacklist = blacklist;
|
exports.createBlacklist = blacklist;
|
||||||
exports.sourceMaps = {fromRawMappings, compactMapping};
|
exports.sourceMaps = {fromRawMappings, compactMapping};
|
||||||
exports.createServer = createServer;
|
exports.createServer = createServer;
|
||||||
exports.Config = Config;
|
|
||||||
exports.Logger = Logger;
|
exports.Logger = Logger;
|
||||||
|
|
||||||
export type ConfigT = MetroConfig;
|
export type ConfigT = MetroConfig;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user