2015-09-22 16:00:04 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-10-22 13:07:01 +00:00
|
|
|
*
|
2017-09-26 19:54:44 +00:00
|
|
|
* @format
|
2016-10-22 13:07:01 +00:00
|
|
|
* @flow
|
2015-09-22 16:00:04 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2017-09-14 11:20:26 +00:00
|
|
|
const findSymlinkedModules = require('./findSymlinkedModules');
|
2017-07-13 10:30:06 +00:00
|
|
|
const getPolyfills = require('../../rn-get-polyfills');
|
2015-09-22 16:00:04 +00:00
|
|
|
const path = require('path');
|
|
|
|
|
2018-07-25 12:44:40 +00:00
|
|
|
const {createBlacklist} = require('metro');
|
2018-08-02 12:22:57 +00:00
|
|
|
const {loadConfig} = require('metro-config');
|
2017-05-03 13:38:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configuration file of the CLI.
|
|
|
|
*/
|
2018-07-25 12:44:40 +00:00
|
|
|
import type {ConfigT} from 'metro-config/src/configTypes.flow';
|
2017-05-03 13:38:40 +00:00
|
|
|
|
Fix broken default getProjectRoots
Summary:
In <= 0.44, the default implementation of getProjectRoots() came from `local-cli/core/default.config.js`. With changes happening in the CLI and the packager over the course of the last two months, various pieces of this logic (specifically `local-cli/utils/Config.js`) were rewritten, and though default.config.js was still being imported and used in `local-cli/core/index.js`, the default `getProjectRoots()` was being overriden by the defaults specified in `local-cli/utils/Config.js`.
This PR moves the logic from default.config.js into Config.js and index.js, as appropriate. Specifically:
- The `getProjectCommands()`, `getProjectConfig()`, and `getDependencyConfig()` methods, which have traditionally not been part of the rn-cli.config.js spec, are now defined in `local-cli/core/index.js`.
- The `getProjectRoots()` method, which contained logic for properly resolving the _actual_ project root as well as resolving symlinks within that root, has been moved to `local-cli/utils/Config.js`, to match the fact that other default rn-cli.config.js definitions live there.
Closes https://github.com/facebook/react-native/pull/14412
Differential Revision: D5216887
Pulled By: hramos
fbshipit-source-id: 7a3840ecf0ad8ea3f6d7bbd3d54e4f02950c6a32
2017-06-09 08:14:37 +00:00
|
|
|
function getProjectPath() {
|
2017-09-26 19:54:44 +00:00
|
|
|
if (
|
|
|
|
__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/)
|
|
|
|
) {
|
Fix broken default getProjectRoots
Summary:
In <= 0.44, the default implementation of getProjectRoots() came from `local-cli/core/default.config.js`. With changes happening in the CLI and the packager over the course of the last two months, various pieces of this logic (specifically `local-cli/utils/Config.js`) were rewritten, and though default.config.js was still being imported and used in `local-cli/core/index.js`, the default `getProjectRoots()` was being overriden by the defaults specified in `local-cli/utils/Config.js`.
This PR moves the logic from default.config.js into Config.js and index.js, as appropriate. Specifically:
- The `getProjectCommands()`, `getProjectConfig()`, and `getDependencyConfig()` methods, which have traditionally not been part of the rn-cli.config.js spec, are now defined in `local-cli/core/index.js`.
- The `getProjectRoots()` method, which contained logic for properly resolving the _actual_ project root as well as resolving symlinks within that root, has been moved to `local-cli/utils/Config.js`, to match the fact that other default rn-cli.config.js definitions live there.
Closes https://github.com/facebook/react-native/pull/14412
Differential Revision: D5216887
Pulled By: hramos
fbshipit-source-id: 7a3840ecf0ad8ea3f6d7bbd3d54e4f02950c6a32
2017-06-09 08:14:37 +00:00
|
|
|
// 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, '../../../..');
|
|
|
|
}
|
|
|
|
return path.resolve(__dirname, '../..');
|
|
|
|
}
|
|
|
|
|
2017-09-14 11:20:26 +00:00
|
|
|
const resolveSymlinksForRoots = roots =>
|
|
|
|
roots.reduce(
|
2018-04-17 12:37:02 +00:00
|
|
|
/* $FlowFixMe(>=0.70.0 site=react_native_fb) This comment suppresses an
|
|
|
|
* error found when Flow v0.70 was deployed. To see the error delete this
|
|
|
|
* comment and run Flow. */
|
2017-09-26 19:54:44 +00:00
|
|
|
(arr, rootPath) => arr.concat(findSymlinkedModules(rootPath, roots)),
|
|
|
|
[...roots],
|
Fix broken default getProjectRoots
Summary:
In <= 0.44, the default implementation of getProjectRoots() came from `local-cli/core/default.config.js`. With changes happening in the CLI and the packager over the course of the last two months, various pieces of this logic (specifically `local-cli/utils/Config.js`) were rewritten, and though default.config.js was still being imported and used in `local-cli/core/index.js`, the default `getProjectRoots()` was being overriden by the defaults specified in `local-cli/utils/Config.js`.
This PR moves the logic from default.config.js into Config.js and index.js, as appropriate. Specifically:
- The `getProjectCommands()`, `getProjectConfig()`, and `getDependencyConfig()` methods, which have traditionally not been part of the rn-cli.config.js spec, are now defined in `local-cli/core/index.js`.
- The `getProjectRoots()` method, which contained logic for properly resolving the _actual_ project root as well as resolving symlinks within that root, has been moved to `local-cli/utils/Config.js`, to match the fact that other default rn-cli.config.js definitions live there.
Closes https://github.com/facebook/react-native/pull/14412
Differential Revision: D5216887
Pulled By: hramos
fbshipit-source-id: 7a3840ecf0ad8ea3f6d7bbd3d54e4f02950c6a32
2017-06-09 08:14:37 +00:00
|
|
|
);
|
|
|
|
|
2017-09-15 11:55:29 +00:00
|
|
|
const getProjectRoots = () => {
|
|
|
|
const root = process.env.REACT_NATIVE_APP_ROOT;
|
|
|
|
if (root) {
|
|
|
|
return resolveSymlinksForRoots([path.resolve(root)]);
|
|
|
|
}
|
|
|
|
return resolveSymlinksForRoots([getProjectPath()]);
|
|
|
|
};
|
2017-09-14 11:20:26 +00:00
|
|
|
|
2018-02-17 04:39:27 +00:00
|
|
|
const getBlacklistRE = () => {
|
|
|
|
return createBlacklist([/.*\/__fixtures__\/.*/]);
|
|
|
|
};
|
|
|
|
|
2015-09-22 16:00:04 +00:00
|
|
|
/**
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
* Module capable of getting the configuration out of a given file.
|
2015-10-20 23:58:13 +00:00
|
|
|
*
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
* The function will return all the default configuration, as specified by the
|
2017-09-15 11:55:29 +00:00
|
|
|
* `DEFAULT` param overriden by those found on `rn-cli.config.js` files, if any. If no
|
Merge `rnpm config` with the `cli config`, step 1
Summary:
This is step one on merging the `rnpm` config with the `cli config`. The plan is to remove two sources of truth (rnpm package.json config and rn-cli Javascript config)
Rationale:
As of now, we have `rnpm` config, that used to live in the `local-cli/core/config/index.js` and the `rn-cli` config, living in `default.config.js` and `utils/Config.js`.
This PR moves all the things into one file, called `local-cli/core', simplifies things, enhances types (Config now has better types, added missing properties and fixed descriptions).
One notable addition is that users can now opt-in to override the commands that are loaded at the package level. Previously it was only possible to add a command by writing a plugin. Now, you can just tweak the `rn-cli.config.js`.
This is one of the several improvements I have on my roadmap, with better documentation for the CLI as well.
Closes https://github.com/facebook/react-native/pull/11564
Differential Revision: D4360095
fbshipit-source-id: feaec7c88df63e51cef1f9620c7eedeb738d3d00
2017-01-09 15:49:29 +00:00
|
|
|
* default config is provided and no configuration can be found in the directory
|
|
|
|
* hierarchy, an error will be thrown.
|
2015-09-22 16:00:04 +00:00
|
|
|
*/
|
|
|
|
const Config = {
|
2018-07-25 12:44:40 +00:00
|
|
|
DEFAULT: {
|
|
|
|
resolver: {
|
|
|
|
resolverMainFields: ['react-native', 'browser', 'main'],
|
|
|
|
blacklistRE: getBlacklistRE(),
|
|
|
|
},
|
|
|
|
serializer: {
|
|
|
|
getModulesRunBeforeMainModule: () => [
|
|
|
|
require.resolve('../../Libraries/Core/InitializeCore'),
|
|
|
|
],
|
|
|
|
getPolyfills,
|
|
|
|
},
|
|
|
|
|
|
|
|
watchFolders: [getProjectPath(), ...getProjectRoots()],
|
|
|
|
transformModulePath: require.resolve('metro/src/reactNativeTransformer'),
|
2016-08-12 18:46:04 +00:00
|
|
|
},
|
2015-10-20 23:58:13 +00:00
|
|
|
|
2018-02-02 12:35:11 +00:00
|
|
|
getProjectPath,
|
|
|
|
getProjectRoots,
|
|
|
|
|
2018-07-28 03:31:20 +00:00
|
|
|
async load(configFile: ?string): Promise<ConfigT> {
|
2018-08-02 12:22:57 +00:00
|
|
|
return await loadConfig(
|
2018-07-28 03:31:20 +00:00
|
|
|
configFile ? {config: configFile} : {},
|
2018-08-02 12:22:57 +00:00
|
|
|
this.DEFAULT,
|
2018-07-28 03:31:20 +00:00
|
|
|
);
|
2016-08-12 18:46:04 +00:00
|
|
|
},
|
2015-09-22 16:00:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Config;
|