diff --git a/local-cli/bundle/buildBundle.js b/local-cli/bundle/buildBundle.js index df2c19d3a..f2d8e6088 100644 --- a/local-cli/bundle/buildBundle.js +++ b/local-cli/bundle/buildBundle.js @@ -21,7 +21,7 @@ const saveAssets = require('./saveAssets'); const defaultAssetExts = require('../../packager/defaults').assetExts; import type {RequestOptions, OutputOptions} from './types.flow'; -import type {ConfigT} from '../util/Config'; +import type {ConfigT} from '../core'; function saveBundle(output, bundle, args) { return Promise.resolve( diff --git a/local-cli/cliEntry.js b/local-cli/cliEntry.js index 6933741ab..1e74b9233 100644 --- a/local-cli/cliEntry.js +++ b/local-cli/cliEntry.js @@ -10,21 +10,19 @@ */ 'use strict'; -const Config = require('./util/Config'); +const config = require('./core'); const assertRequiredOptions = require('./util/assertRequiredOptions'); const chalk = require('chalk'); const childProcess = require('child_process'); const commander = require('commander'); const commands = require('./commands'); -const defaultConfig = require('./default.config'); const init = require('./init/init'); -const minimist = require('minimist'); const path = require('path'); const pkg = require('../package.json'); -import type {Command} from './commands'; -import type {ConfigT} from './util/Config'; +import type {CommandT} from './commands'; +import type {ConfigT} from './core'; commander.version(pkg.version); @@ -93,7 +91,7 @@ function printUnknownCommand(cmdName) { ].join('\n')); } -const addCommand = (command: Command, config: ConfigT) => { +const addCommand = (command: CommandT, cfg: ConfigT) => { const options = command.options || []; const cmd = commander @@ -108,7 +106,7 @@ const addCommand = (command: Command, config: ConfigT) => { Promise.resolve() .then(() => { assertRequiredOptions(options, passedOptions); - return command.func(argv, config, passedOptions); + return command.func(argv, cfg, passedOptions); }) .catch(handleError); }); @@ -122,7 +120,7 @@ const addCommand = (command: Command, config: ConfigT) => { opt.command, opt.description, opt.parse || defaultOptParser, - typeof opt.default === 'function' ? opt.default(config) : opt.default, + typeof opt.default === 'function' ? opt.default(cfg) : opt.default, )); // Placeholder option for --config, which is parsed before any other option, @@ -130,24 +128,6 @@ const addCommand = (command: Command, config: ConfigT) => { cmd.option('--config [string]', 'Path to the CLI configuration file'); }; -function getCliConfig() { - // Use a lightweight option parser to look up the CLI configuration file, - // which we need to set up the parser for the other args and options - const cliArgs = minimist(process.argv.slice(2)); - - let cwd; - let configPath; - if (cliArgs.config != null) { - cwd = process.cwd(); - configPath = cliArgs.config; - } else { - cwd = __dirname; - configPath = Config.findConfigPath(cwd); - } - - return Config.get(cwd, defaultConfig, configPath); -} - function run() { const setupEnvScript = /^win/.test(process.platform) ? 'setup_env.bat' @@ -155,7 +135,6 @@ function run() { childProcess.execFileSync(path.join(__dirname, setupEnvScript)); - const config = getCliConfig(); commands.forEach(cmd => addCommand(cmd, config)); commander.parse(process.argv); diff --git a/local-cli/commands.js b/local-cli/commands.js index 5f2fe27bb..7e7612aed 100644 --- a/local-cli/commands.js +++ b/local-cli/commands.js @@ -10,11 +10,11 @@ */ 'use strict'; -const getUserCommands = require('./core/getCommands'); +const { getProjectCommands } = require('./core'); -import type {ConfigT} from './util/Config'; +import type { ConfigT } from './core'; -export type Command = { +export type CommandT = { name: string, description?: string, usage?: string, @@ -66,10 +66,10 @@ const undocumentedCommands = [ }, ]; -const commands: Array = [ +const commands: Array = [ ...documentedCommands, ...undocumentedCommands, - ...getUserCommands(), + ...getProjectCommands(), ]; module.exports = commands; diff --git a/local-cli/core/__tests__/android/findAndroidAppFolder.spec.js b/local-cli/core/__tests__/android/findAndroidAppFolder.spec.js index 753ffbf6b..716d6f593 100644 --- a/local-cli/core/__tests__/android/findAndroidAppFolder.spec.js +++ b/local-cli/core/__tests__/android/findAndroidAppFolder.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const findAndroidAppFolder = require('../../config/android/findAndroidAppFolder'); +const findAndroidAppFolder = require('../../android/findAndroidAppFolder'); const mockFs = require('mock-fs'); const mocks = require('../../__fixtures__/android'); diff --git a/local-cli/core/__tests__/android/findManifest.spec.js b/local-cli/core/__tests__/android/findManifest.spec.js index 45c2b996a..2377c39da 100644 --- a/local-cli/core/__tests__/android/findManifest.spec.js +++ b/local-cli/core/__tests__/android/findManifest.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const findManifest = require('../../config/android/findManifest'); +const findManifest = require('../../android/findManifest'); const mockFs = require('mock-fs'); const mocks = require('../../__fixtures__/android'); diff --git a/local-cli/core/__tests__/android/findPackageClassName.spec.js b/local-cli/core/__tests__/android/findPackageClassName.spec.js index f1d4ae08a..ac2a9528a 100644 --- a/local-cli/core/__tests__/android/findPackageClassName.spec.js +++ b/local-cli/core/__tests__/android/findPackageClassName.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const findPackageClassName = require('../../config/android/findPackageClassName'); +const findPackageClassName = require('../../android/findPackageClassName'); const mockFs = require('mock-fs'); const mocks = require('../../__fixtures__/android'); diff --git a/local-cli/core/__tests__/android/getDependencyConfig.spec.js b/local-cli/core/__tests__/android/getDependencyConfig.spec.js index 82c51281b..c706662fe 100644 --- a/local-cli/core/__tests__/android/getDependencyConfig.spec.js +++ b/local-cli/core/__tests__/android/getDependencyConfig.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const getDependencyConfig = require('../../config/android').dependencyConfig; +const getDependencyConfig = require('../../android').dependencyConfig; const mockFs = require('mock-fs'); const mocks = require('../../__fixtures__/android'); const userConfig = {}; diff --git a/local-cli/core/__tests__/android/getProjectConfig.spec.js b/local-cli/core/__tests__/android/getProjectConfig.spec.js index f5d54382c..3c0b2f79d 100644 --- a/local-cli/core/__tests__/android/getProjectConfig.spec.js +++ b/local-cli/core/__tests__/android/getProjectConfig.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const getProjectConfig = require('../../config/android').projectConfig; +const getProjectConfig = require('../../android').projectConfig; const mockFs = require('mock-fs'); const mocks = require('../../__fixtures__/android'); diff --git a/local-cli/core/__tests__/android/readManifest.spec.js b/local-cli/core/__tests__/android/readManifest.spec.js index cf18f8c14..481b9f3cc 100644 --- a/local-cli/core/__tests__/android/readManifest.spec.js +++ b/local-cli/core/__tests__/android/readManifest.spec.js @@ -1,7 +1,7 @@ jest.autoMockOff(); -const findManifest = require('../../config/android/findManifest'); -const readManifest = require('../../config/android/readManifest'); +const findManifest = require('../../android/findManifest'); +const readManifest = require('../../android/readManifest'); const mockFs = require('mock-fs'); const mocks = require('../../__fixtures__/android'); diff --git a/local-cli/core/__tests__/findAssets.spec.js b/local-cli/core/__tests__/findAssets.spec.js index 7bbe89867..a3758e1b2 100644 --- a/local-cli/core/__tests__/findAssets.spec.js +++ b/local-cli/core/__tests__/findAssets.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const findAssets = require('../config/findAssets'); +const findAssets = require('../findAssets'); const mockFs = require('mock-fs'); const dependencies = require('../__fixtures__/dependencies'); const isArray = (arg) => diff --git a/local-cli/core/__tests__/ios/findProject.spec.js b/local-cli/core/__tests__/ios/findProject.spec.js index 08a931e01..141b28c2d 100644 --- a/local-cli/core/__tests__/ios/findProject.spec.js +++ b/local-cli/core/__tests__/ios/findProject.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const findProject = require('../../config/ios/findProject'); +const findProject = require('../../ios/findProject'); const mockFs = require('mock-fs'); const projects = require('../../__fixtures__/projects'); const ios = require('../../__fixtures__/ios'); diff --git a/local-cli/core/__tests__/ios/getProjectConfig.spec.js b/local-cli/core/__tests__/ios/getProjectConfig.spec.js index 9b1a88e75..bb27c22a1 100644 --- a/local-cli/core/__tests__/ios/getProjectConfig.spec.js +++ b/local-cli/core/__tests__/ios/getProjectConfig.spec.js @@ -1,6 +1,6 @@ jest.autoMockOff(); -const getProjectConfig = require('../../config/ios').projectConfig; +const getProjectConfig = require('../../ios').projectConfig; const mockFs = require('mock-fs'); const projects = require('../../__fixtures__/projects'); diff --git a/local-cli/core/config/android/findAndroidAppFolder.js b/local-cli/core/android/findAndroidAppFolder.js similarity index 100% rename from local-cli/core/config/android/findAndroidAppFolder.js rename to local-cli/core/android/findAndroidAppFolder.js diff --git a/local-cli/core/config/android/findManifest.js b/local-cli/core/android/findManifest.js similarity index 100% rename from local-cli/core/config/android/findManifest.js rename to local-cli/core/android/findManifest.js diff --git a/local-cli/core/config/android/findPackageClassName.js b/local-cli/core/android/findPackageClassName.js similarity index 100% rename from local-cli/core/config/android/findPackageClassName.js rename to local-cli/core/android/findPackageClassName.js diff --git a/local-cli/core/config/android/index.js b/local-cli/core/android/index.js similarity index 100% rename from local-cli/core/config/android/index.js rename to local-cli/core/android/index.js diff --git a/local-cli/core/config/android/readManifest.js b/local-cli/core/android/readManifest.js similarity index 100% rename from local-cli/core/config/android/readManifest.js rename to local-cli/core/android/readManifest.js diff --git a/local-cli/core/config/index.js b/local-cli/core/config/index.js deleted file mode 100644 index ccc521c94..000000000 --- a/local-cli/core/config/index.js +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -'use strict'; - -const android = require('./android'); -const findAssets = require('./findAssets'); -const ios = require('./ios'); -const windows = require('./windows'); -const path = require('path'); -const wrapCommands = require('./wrapCommands'); - -const getRNPMConfig = (folder) => - require(path.join(folder, './package.json')).rnpm || {}; - -/** - * Returns project config from the current working directory - * @return {Object} - */ -exports.getProjectConfig = function getProjectConfig() { - const folder = process.cwd(); - const rnpm = getRNPMConfig(folder); - - return Object.assign({}, rnpm, { - ios: ios.projectConfig(folder, rnpm.ios || {}), - android: android.projectConfig(folder, rnpm.android || {}), - windows: windows.projectConfig(folder, rnpm.windows || {}), - assets: findAssets(folder, rnpm.assets), - }); -}; - -/** - * Returns a dependency config from node_modules/ - * @param {String} packageName Dependency name - * @return {Object} - */ -exports.getDependencyConfig = function getDependencyConfig(packageName) { - const folder = path.join(process.cwd(), 'node_modules', packageName); - const rnpm = getRNPMConfig( - path.join(process.cwd(), 'node_modules', packageName) - ); - - return Object.assign({}, rnpm, { - ios: ios.dependencyConfig(folder, rnpm.ios || {}), - android: android.dependencyConfig(folder, rnpm.android || {}), - windows: windows.dependencyConfig(folder, rnpm.windows || {}), - assets: findAssets(folder, rnpm.assets), - commands: wrapCommands(rnpm.commands), - params: rnpm.params || [], - }); -}; diff --git a/local-cli/core/default.config.js b/local-cli/core/default.config.js new file mode 100644 index 000000000..1c4d01a69 --- /dev/null +++ b/local-cli/core/default.config.js @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ +'use strict'; + +const path = require('path'); +const flatten = require('lodash').flatten; + +const blacklist = require('../../packager/blacklist'); + +const android = require('./android'); +const findAssets = require('./findAssets'); +const ios = require('./ios'); +const windows = require('./windows'); +const wrapCommands = require('./wrapCommands'); +const findPlugins = require('./findPlugins'); + +import type {ConfigT} from './index'; + +const getRNPMConfig = (folder) => + // $FlowFixMe non-literal require + require(path.join(folder, './package.json')).rnpm || {}; + +const attachPackage = (command, pkg) => Array.isArray(command) + ? command.map(cmd => attachPackage(cmd, pkg)) + : { ...command, pkg }; + +/** + * Default configuration for the CLI. + * + * If you need to override any of this functions do so by defining the file + * `rn-cli.config.js` on the root of your project with the functions you need + * to tweak. + */ +const config: ConfigT = { + getProjectCommands() { + const appRoot = process.cwd(); + const plugins = findPlugins([appRoot]) + .map(pathToCommands => { + const name = pathToCommands.split(path.sep)[0]; + + return attachPackage( + // $FlowFixMe non-literal require + require(path.join(appRoot, 'node_modules', pathToCommands)), + // $FlowFixMe non-literal require + require(path.join(appRoot, 'node_modules', name, 'package.json')) + ); + }); + + return flatten(plugins); + }, + getProjectConfig() { + const folder = process.cwd(); + const rnpm = getRNPMConfig(folder); + + return Object.assign({}, rnpm, { + ios: ios.projectConfig(folder, rnpm.ios || {}), + android: android.projectConfig(folder, rnpm.android || {}), + windows: windows.projectConfig(folder, rnpm.windows || {}), + assets: findAssets(folder, rnpm.assets), + }); + }, + getDependencyConfig(packageName) { + const folder = path.join(process.cwd(), 'node_modules', packageName); + const rnpm = getRNPMConfig( + path.join(process.cwd(), 'node_modules', packageName) + ); + + return Object.assign({}, rnpm, { + ios: ios.dependencyConfig(folder, rnpm.ios || {}), + android: android.dependencyConfig(folder, rnpm.android || {}), + windows: windows.dependencyConfig(folder, rnpm.windows || {}), + assets: findAssets(folder, rnpm.assets), + commands: wrapCommands(rnpm.commands), + params: rnpm.params || [], + }); + }, + getAssetExts() { + return []; + }, + getPlatforms() { + return []; + }, + getBlacklistRE() { + return blacklist(); + }, + getTransformModulePath() { + return require.resolve('../../packager/transformer'); + }, + getProjectRoots() { + const root = process.env.REACT_NATIVE_APP_ROOT; + if (root) { + return [path.resolve(root)]; + } + if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]core$/)) { + // Packager is running from node_modules. + // This is the default case for all projects created using 'react-native init'. + return [path.resolve(__dirname, '../../../..')]; + } else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) { + // React Native was installed using CocoaPods. + return [path.resolve(__dirname, '../../../..')]; + } else { + return [path.resolve(__dirname, '../..')]; + } + }, +}; + +module.exports = config; diff --git a/local-cli/core/config/findAssets.js b/local-cli/core/findAssets.js similarity index 100% rename from local-cli/core/config/findAssets.js rename to local-cli/core/findAssets.js diff --git a/local-cli/core/getCommands.js b/local-cli/core/getCommands.js deleted file mode 100644 index 5a1988f50..000000000 --- a/local-cli/core/getCommands.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -'use strict'; - -const findPlugins = require('./findPlugins'); -const path = require('path'); -const flatten = require('lodash').flatten; - -const attachPackage = (command, pkg) => Array.isArray(command) - ? command.map(cmd => attachPackage(cmd, pkg)) - : { ...command, pkg }; - -/** - * @return {Array} Array of commands - */ -module.exports = function getCommands() { - const appRoot = process.cwd(); - const plugins = findPlugins([appRoot]) - .map(pathToCommands => { - const name = pathToCommands.split(path.sep)[0]; - - return attachPackage( - require(path.join(appRoot, 'node_modules', pathToCommands)), - require(path.join(appRoot, 'node_modules', name, 'package.json')) - ); - }); - - return flatten(plugins); -}; diff --git a/local-cli/core/index.js b/local-cli/core/index.js new file mode 100644 index 000000000..b7927b4d8 --- /dev/null +++ b/local-cli/core/index.js @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + * + * @flow + */ +'use strict'; + +const Config = require('../util/Config'); +const defaultConfig = require('./default.config'); +const minimist = require('minimist'); + +import type {GetTransformOptions} from '../../packager/react-packager/src/Bundler'; +import type {CommandT} from '../commands'; + +/** + * Configuration file of the CLI. + */ +export type ConfigT = { + extraNodeModules?: { [id: string]: string }, + /** + * Specify any additional asset extentions to be used by the packager. + * For example, if you want to include a .ttf file, you would return ['ttf'] + * from here and use `require('./fonts/example.ttf')` inside your app. + */ + getAssetExts?: () => Array, + /** + * Specify any additional platforms to be used by the packager. + * For example, if you want to add a "custom" platform, and use modules + * ending in .custom.js, you would return ['custom'] here. + */ + getPlatforms: () => Array, + /** + * Returns the path to a custom transformer. This can also be overridden + * with the --transformer commandline argument. + */ + getTransformModulePath?: () => string, + getTransformOptions?: GetTransformOptions, + transformVariants?: () => {[name: string]: Object}, + /** + * Returns a regular expression for modules that should be ignored by the + * packager on a given platform. + */ + getBlacklistRE(): RegExp, + getProjectRoots(): Array, + getAssetExts(): Array, + /** + * Returns an array of project commands used by the CLI to load + */ + getProjectCommands(): Array, + /** + * Returns project config from the current working directory + */ + getProjectConfig(): Object, + /** + * Returns dependency config from /packageName + */ + getDependencyConfig(pkgName: string): Object, +}; + +/** + * Loads the CLI configuration + */ +function getCliConfig(): ConfigT { + const cliArgs = minimist(process.argv.slice(2)); + + let cwd; + let configPath; + + if (cliArgs.config != null) { + cwd = process.cwd(); + configPath = cliArgs.config; + } else { + cwd = __dirname; + configPath = Config.findConfigPath(cwd); + } + + return Config.get(cwd, defaultConfig, configPath); +} + +module.exports = getCliConfig(); diff --git a/local-cli/core/config/ios/findProject.js b/local-cli/core/ios/findProject.js similarity index 100% rename from local-cli/core/config/ios/findProject.js rename to local-cli/core/ios/findProject.js diff --git a/local-cli/core/config/ios/index.js b/local-cli/core/ios/index.js similarity index 100% rename from local-cli/core/config/ios/index.js rename to local-cli/core/ios/index.js diff --git a/local-cli/core/config/windows/findNamespace.js b/local-cli/core/windows/findNamespace.js similarity index 100% rename from local-cli/core/config/windows/findNamespace.js rename to local-cli/core/windows/findNamespace.js diff --git a/local-cli/core/config/windows/findPackageClassName.js b/local-cli/core/windows/findPackageClassName.js similarity index 100% rename from local-cli/core/config/windows/findPackageClassName.js rename to local-cli/core/windows/findPackageClassName.js diff --git a/local-cli/core/config/windows/findProject.js b/local-cli/core/windows/findProject.js similarity index 100% rename from local-cli/core/config/windows/findProject.js rename to local-cli/core/windows/findProject.js diff --git a/local-cli/core/config/windows/findWindowsSolution.js b/local-cli/core/windows/findWindowsSolution.js similarity index 100% rename from local-cli/core/config/windows/findWindowsSolution.js rename to local-cli/core/windows/findWindowsSolution.js diff --git a/local-cli/core/config/windows/generateGUID.js b/local-cli/core/windows/generateGUID.js similarity index 100% rename from local-cli/core/config/windows/generateGUID.js rename to local-cli/core/windows/generateGUID.js diff --git a/local-cli/core/config/windows/index.js b/local-cli/core/windows/index.js similarity index 100% rename from local-cli/core/config/windows/index.js rename to local-cli/core/windows/index.js diff --git a/local-cli/core/config/wrapCommands.js b/local-cli/core/wrapCommands.js similarity index 91% rename from local-cli/core/config/wrapCommands.js rename to local-cli/core/wrapCommands.js index a0f0fbc75..c7a7fe1e5 100644 --- a/local-cli/core/config/wrapCommands.js +++ b/local-cli/core/wrapCommands.js @@ -8,7 +8,7 @@ */ 'use strict'; -const makeCommand = require('../makeCommand'); +const makeCommand = require('./makeCommand'); module.exports = function wrapCommands(commands) { const mappedCommands = {}; diff --git a/local-cli/default.config.js b/local-cli/default.config.js deleted file mode 100644 index 25091edbe..000000000 --- a/local-cli/default.config.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ - 'use strict'; - -var blacklist = require('../packager/blacklist'); -var path = require('path'); -var rnpmConfig = require('./core/config'); - -/** - * Default configuration for the CLI. - * - * If you need to override any of this functions do so by defining the file - * `rn-cli.config.js` on the root of your project with the functions you need - * to tweak. - */ -var config = { - getProjectRoots, - - getProjectConfig: rnpmConfig.getProjectConfig, - getDependencyConfig: rnpmConfig.getDependencyConfig, - - /** - * Specify any additional asset extentions to be used by the packager. - * For example, if you want to include a .ttf file, you would return ['ttf'] - * from here and use `require('./fonts/example.ttf')` inside your app. - */ - getAssetExts() { - return []; - }, - - /** - * Specify any additional platforms to be used by the packager. - * For example, if you want to add a "custom" platform, and use modules - * ending in .custom.js, you would return ['custom'] here. - */ - getPlatforms() { - return []; - }, - - /** - * Returns a regular expression for modules that should be ignored by the - * packager on a given platform. - */ - getBlacklistRE() { - return blacklist(); - }, - - /** - * Returns the path to a custom transformer. This can also be overridden - * with the --transformer commandline argument. - */ - getTransformModulePath() { - return require.resolve('../packager/transformer'); - }, -}; - -function getProjectRoots() { - var root = process.env.REACT_NATIVE_APP_ROOT; - if (root) { - return [path.resolve(root)]; - } - if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli$/)) { - // Packager is running from node_modules. - // This is the default case for all projects created using 'react-native init'. - return [path.resolve(__dirname, '../../..')]; - } else if (__dirname.match(/Pods[\/\\]React[\/\\]packager$/)) { - // React Native was installed using CocoaPods. - return [path.resolve(__dirname, '../../..')]; - } else { - return [path.resolve(__dirname, '..')]; - } -} - -module.exports = config; diff --git a/local-cli/util/Config.js b/local-cli/util/Config.js index aa90e87bd..7032878e1 100644 --- a/local-cli/util/Config.js +++ b/local-cli/util/Config.js @@ -14,37 +14,25 @@ const assert = require('assert'); const fs = require('fs'); const path = require('path'); -import type {GetTransformOptions} from '../../packager/react-packager/src/Bundler/index.js'; - const RN_CLI_CONFIG = 'rn-cli.config.js'; -export type ConfigT = { - extraNodeModules?: {[id: string]: string}, - getAssetExts?: () => Array, - getTransformModulePath?: () => string, - getTransformOptions?: GetTransformOptions, - transformVariants?: () => {[name: string]: Object}, - - getBlacklistRE(): RegExp, - getProjectRoots(): Array, -}; +// TODO: @bestander & @grabbou - get rid when internal tests are fixed +export type { ConfigT } from '../core'; /** - * Module capable of getting the configuration that should be used for - * the `rn-cli`. The configuration file is a JS file named `rn-cli.config.js`. - * It has to be on any parent directory of the cli. + * Module capable of getting the configuration out of a given file. * - * The function will return all the default configuration functions overriden - * by those found on `rn-cli.config.js`, if any. If no default config is - * provided and no configuration can be found in the directory hierarchy an - * error will be thrown. + * The function will return all the default configuration, as specified by the + * `defaultConfig` param overriden by those found on `rn-cli.config.js` files, if any. If no + * default config is provided and no configuration can be found in the directory + * hierarchy, an error will be thrown. */ const Config = { - get( + get( cwd: string, - defaultConfig?: ConfigT | null, + defaultConfig?: T | null, pathToConfig?: string | null, - ): ConfigT { + ): T { let baseConfig; // Handle the legacy code path where pathToConfig is unspecified @@ -67,6 +55,7 @@ const Config = { require(path.join(cwd, pathToConfig)); } + // $FlowFixMe we return `at least` T + extras return { ...defaultConfig, ...baseConfig,