mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix broken getProjectRoots default in local-cli
This commit is contained in:
committed by
Hector Ramos
parent
1668f90f8e
commit
39e0750223
+63
-2
@@ -10,9 +10,15 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const android = require('./android');
|
||||
const Config = require('../util/Config');
|
||||
const findPlugins = require('./findPlugins');
|
||||
const findAssets = require('./findAssets');
|
||||
const ios = require('./ios');
|
||||
const windows = require('./windows');
|
||||
const wrapCommands = require('./wrapCommands');
|
||||
|
||||
const defaultConfig = require('./default.config');
|
||||
const flatten = require('lodash').flatten;
|
||||
const minimist = require('minimist');
|
||||
const path = require('path');
|
||||
|
||||
@@ -35,6 +41,61 @@ export type RNConfig = {
|
||||
getDependencyConfig(pkgName: string): Object,
|
||||
};
|
||||
|
||||
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 };
|
||||
|
||||
const defaultRNConfig = {
|
||||
getProjectCommands(): Array<CommandT> {
|
||||
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(): Object {
|
||||
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: string) {
|
||||
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 || [],
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* Loads the CLI configuration
|
||||
*/
|
||||
@@ -44,7 +105,7 @@ function getCliConfig(): RNConfig {
|
||||
? Config.loadFile(path.resolve(__dirname, cliArgs.config))
|
||||
: Config.findOptional(__dirname);
|
||||
|
||||
return {...defaultConfig, ...config};
|
||||
return {...defaultRNConfig, ...config};
|
||||
}
|
||||
|
||||
module.exports = getCliConfig();
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const findSymlinksPaths = require('./findSymlinksPaths');
|
||||
|
||||
const blacklist = require('../../packager/blacklist');
|
||||
const fs = require('fs');
|
||||
const invariant = require('fbjs/lib/invariant');
|
||||
@@ -93,12 +95,38 @@ export type ConfigT = {
|
||||
transformVariants: () => TransformVariants,
|
||||
};
|
||||
|
||||
function getProjectPath() {
|
||||
if (__dirname.match(/node_modules[\/\\]react-native[\/\\]local-cli[\/\\]util$/)) {
|
||||
// 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, '../..');
|
||||
}
|
||||
|
||||
const resolveSymlink = (roots) =>
|
||||
roots.concat(
|
||||
findSymlinksPaths(
|
||||
path.join(getProjectPath(), 'node_modules'),
|
||||
roots
|
||||
)
|
||||
);
|
||||
|
||||
const defaultConfig: ConfigT = {
|
||||
extraNodeModules: Object.create(null),
|
||||
getAssetExts: () => [],
|
||||
getBlacklistRE: () => blacklist(),
|
||||
getPlatforms: () => [],
|
||||
getProjectRoots: () => [process.cwd()],
|
||||
getProjectRoots: () => {
|
||||
const root = process.env.REACT_NATIVE_APP_ROOT;
|
||||
if (root) {
|
||||
return resolveSymlink([path.resolve(root)]);
|
||||
}
|
||||
return resolveSymlink([getProjectPath()]);
|
||||
},
|
||||
getProvidesModuleNodeModules: () => providesModuleNodeModules.slice(),
|
||||
getSourceExts: () => [],
|
||||
getTransformModulePath: () => path.resolve(__dirname, '../../packager/transformer'),
|
||||
|
||||
Reference in New Issue
Block a user