Skip to content

Commit

Permalink
chore: improve RNPM warnings (react-native-community#395)
Browse files Browse the repository at this point in the history
* Improve RNPM warnings

* Update packages/cli/src/tools/config/readConfigFromDisk.js

Co-Authored-By: Michał Pierzchała <[email protected]>

* Fix lint error
  • Loading branch information
grabbou authored May 20, 2019
1 parent b03f741 commit 1d2f254
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
5 changes: 1 addition & 4 deletions packages/cli/src/tools/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import makeHook from './makeHook';
import {
readConfigFromDisk,
readDependencyConfigFromDisk,
readLegacyDependencyConfigFromDisk,
} from './readConfigFromDisk';

import {type ConfigT} from 'types';
Expand All @@ -39,9 +38,7 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {
let config;
try {
root = resolveNodeModuleDir(projectRoot, dependencyName);
config =
readLegacyDependencyConfigFromDisk(root) ||
readDependencyConfigFromDisk(root);
config = readDependencyConfigFromDisk(root);
} catch (error) {
logger.warn(
inlineString(`
Expand Down
18 changes: 7 additions & 11 deletions packages/cli/src/tools/config/readConfigFromDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export function readDependencyConfigFromDisk(
searchPlaces,
});

const {config} = explorer.searchSync(rootFolder) || {config: undefined};
const {config} = explorer.searchSync(rootFolder) || {
config: readLegacyDependencyConfigFromDisk(rootFolder),
};

const result = Joi.validate(config, schema.dependencyConfig);

Expand Down Expand Up @@ -90,7 +92,7 @@ const loadProjectCommands = (
/**
* Reads a legacy configuration from a `package.json` "rnpm" key.
*/
export function readLegacyDependencyConfigFromDisk(
function readLegacyDependencyConfigFromDisk(
rootFolder: string,
): ?UserDependencyConfigT {
const {rnpm: config, name} = require(path.join(rootFolder, 'package.json'));
Expand All @@ -113,21 +115,15 @@ export function readLegacyDependencyConfigFromDisk(
commands: loadProjectCommands(rootFolder, config.plugin),
platforms: config.platform
? require(path.join(rootFolder, config.platform))
: undefined,
: {},
};

// @todo: paste a link to documentation that explains the migration steps
logger.warn(
`Package ${chalk.bold(
path.basename(name),
)} is using deprecated "rnpm" config that will stop working from next release. Consider upgrading to the new config format.`,
)} is using deprecated "rnpm" config that will stop working from next release. Please notify its maintainers about it.`,
);

const result = Joi.validate(transformedConfig, schema.dependencyConfig);

if (result.error) {
throw new JoiError(result.error);
}

return result.value;
return transformedConfig;
}

0 comments on commit 1d2f254

Please sign in to comment.