Permalink
Browse files

Allow project-specific config for RN CLI using providesModuleNodeModules

Reviewed By: davidaurelio

Differential Revision: D4409046

fbshipit-source-id: 5af0d08542935a784f4737653ccac49fd7517aff
  • Loading branch information...
andrewimm authored and facebook-github-bot committed Jan 13, 2017
1 parent 09801aa commit 09a83f976e75671c2ea4abd02b8c88e73417e169
@@ -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
@@ -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.
@@ -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
@@ -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') {

This comment has been minimized.

Show comment
Hide comment
@grabbou

grabbou Jan 13, 2017

Collaborator

When this cannot be a function? Shouldn't default value be used here:

 const providesModuleNodeModules =
 +    args.providesModuleNodeModules || defaultProvidesModuleNodeModules;

instead of passing null?

@grabbou

grabbou Jan 13, 2017

Collaborator

When this cannot be a function? Shouldn't default value be used here:

 const providesModuleNodeModules =
 +    args.providesModuleNodeModules || defaultProvidesModuleNodeModules;

instead of passing null?

This comment has been minimized.

Show comment
Hide comment
@andrewimm

andrewimm Jan 14, 2017

Contributor

The fallback is provided at a deeper level, every other config option provides an "empty" default here. I guess the alternative would have been to provide [] here, and then later on the check would have been a little more complex than args.providesModuleNodeModules || defaultProvidesModuleNodeModules

There was an upgrade case I encountered where config.getProvidesModuleNodeModules was undefined, so this is to ensure people can smoothly upgrade. In the longer term, hopefully this functionality is no longer needed.

@andrewimm

andrewimm Jan 14, 2017

Contributor

The fallback is provided at a deeper level, every other config option provides an "empty" default here. I guess the alternative would have been to provide [] here, and then later on the check would have been a little more complex than args.providesModuleNodeModules || defaultProvidesModuleNodeModules

There was an upgrade case I encountered where config.getProvidesModuleNodeModules was undefined, so this is to ensure people can smoothly upgrade. In the longer term, hopefully this functionality is no longer needed.

return config.getProvidesModuleNodeModules();
}
return null;
},
}, {
command: '--skipflow',
description: 'Disable flow checks'
@@ -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,
@@ -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,
@@ -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,

0 comments on commit 09a83f9

Please sign in to comment.