Allow project-specific config for RN CLI using providesModuleNodeModules

Reviewed By: davidaurelio

Differential Revision: D4409046

fbshipit-source-id: 5af0d08542935a784f4737653ccac49fd7517aff
This commit is contained in:
Andrew Imm 2017-01-12 21:03:57 -08:00 committed by Facebook Github Bot
parent 09801aac30
commit 09a83f976e
7 changed files with 38 additions and 5 deletions

View File

@ -19,6 +19,7 @@ const outputBundle = require('./output/bundle');
const path = require('path');
const saveAssets = require('./saveAssets');
const defaultAssetExts = require('../../packager/defaults').assetExts;
const defaultProvidesModuleNodeModules = require('../../packager/defaults').providesModuleNodeModules;
import type {RequestOptions, OutputOptions} from './types.flow';
import type {ConfigT} from '../core';
@ -63,16 +64,21 @@ function buildBundle(
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
undefined;
const providesModuleNodeModules =
typeof config.getProvidesModuleNodeModules === 'function' ? config.getProvidesModuleNodeModules() :
defaultProvidesModuleNodeModules;
const options = {
projectRoots: config.getProjectRoots(),
assetExts: defaultAssetExts.concat(assetExts),
blacklistRE: config.getBlacklistRE(),
getTransformOptions: config.getTransformOptions,
transformModulePath: transformModulePath,
extraNodeModules: config.extraNodeModules,
getTransformOptions: config.getTransformOptions,
projectRoots: config.getProjectRoots(),
providesModuleNodeModules: providesModuleNodeModules,
resetCache: args.resetCache,
watch: false,
reporter: new TerminalReporter(),
transformModulePath: transformModulePath,
watch: false,
};
packagerInstance = new Server(options);

View File

@ -11,6 +11,7 @@
'use strict';
const Config = require('../util/Config');
const defaultConfig = require('./default.config');
const minimist = require('minimist');
@ -34,6 +35,11 @@ export type ConfigT = {
* ending in .custom.js, you would return ['custom'] here.
*/
getPlatforms: () => Array<string>,
/**
* Specify any additional node modules that should be processed for
* providesModule declarations.
*/
getProvidesModuleNodeModules?: () => Array<string>,
/**
* Returns the path to a custom transformer. This can also be overridden
* with the --transformer commandline argument.

View File

@ -18,6 +18,7 @@ const copyToClipBoardMiddleware = require('./middleware/copyToClipBoardMiddlewar
const cpuProfilerMiddleware = require('./middleware/cpuProfilerMiddleware');
const defaultAssetExts = require('../../packager/defaults').assetExts;
const defaultPlatforms = require('../../packager/defaults').platforms;
const defaultProvidesModuleNodeModules = require('../../packager/defaults').providesModuleNodeModules;
const getDevToolsMiddleware = require('./middleware/getDevToolsMiddleware');
const heapCaptureMiddleware = require('./middleware/heapCaptureMiddleware.js');
const http = require('http');
@ -87,6 +88,9 @@ function getPackagerServer(args, config) {
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
undefined;
const providesModuleNodeModules =
args.providesModuleNodeModules || defaultProvidesModuleNodeModules;
return ReactPackager.createServer({
assetExts: defaultAssetExts.concat(args.assetExts),
blacklistRE: config.getBlacklistRE(),
@ -95,6 +99,7 @@ function getPackagerServer(args, config) {
getTransformOptions: config.getTransformOptions,
platforms: defaultPlatforms.concat(args.platforms),
projectRoots: args.projectRoots,
providesModuleNodeModules: providesModuleNodeModules,
reporter: new TerminalReporter(),
resetCache: args.resetCache,
transformModulePath: transformModulePath,

View File

@ -101,6 +101,16 @@ module.exports = {
description: 'Specify any additional platforms to be used by the packager',
parse: (val) => val.split(','),
default: (config) => config.getPlatforms(),
}, {
command: '--providesModuleNodeModules [list]',
description: 'Specify any npm packages that import dependencies with providesModule',
parse: (val) => val.split(','),
default: (config) => {
if (typeof config.getProvidesModuleNodeModules === 'function') {
return config.getProvidesModuleNodeModules();
}
return null;
},
}, {
command: '--skipflow',
description: 'Disable flow checks'

View File

@ -74,6 +74,7 @@ type Options = {
platforms: Array<string>,
polyfillModuleNames: Array<string>,
projectRoots: Array<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
resetCache: boolean,
transformModulePath?: string,
@ -154,6 +155,7 @@ class Bundler {
platforms: opts.platforms,
polyfillModuleNames: opts.polyfillModuleNames,
projectRoots: opts.projectRoots,
providesModuleNodeModules: opts.providesModuleNodeModules,
reporter: opts.reporter,
resetCache: opts.resetCache,
transformCacheKey,

View File

@ -36,6 +36,7 @@ type Options = {
platforms: Array<string>,
polyfillModuleNames?: Array<string>,
projectRoots: Array<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
resetCache: boolean,
transformCacheKey: string,
@ -65,7 +66,7 @@ class Resolver {
},
platforms: opts.platforms,
preferNativePlatform: true,
providesModuleNodeModules: defaults.providesModuleNodeModules,
providesModuleNodeModules: opts.providesModuleNodeModules || defaults.providesModuleNodeModules,
reporter: opts.reporter,
resetCache: opts.resetCache,
roots: opts.projectRoots,

View File

@ -63,6 +63,7 @@ type Options = {
platforms?: Array<string>,
polyfillModuleNames?: Array<string>,
projectRoots: Array<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
resetCache?: boolean,
silent?: boolean,
@ -178,6 +179,7 @@ class Server {
platforms: Array<string>,
polyfillModuleNames: Array<string>,
projectRoots: Array<string>,
providesModuleNodeModules?: Array<string>,
reporter: Reporter,
resetCache: boolean,
silent: boolean,
@ -209,6 +211,7 @@ class Server {
platforms: options.platforms || defaults.platforms,
polyfillModuleNames: options.polyfillModuleNames || [],
projectRoots: options.projectRoots,
providesModuleNodeModules: options.providesModuleNodeModules,
reporter: options.reporter,
resetCache: options.resetCache || false,
silent: options.silent || false,