Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: group deprecated rnpm warnings, add migration guide #450

Merged
merged 3 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ This CLI is intended to be used with a certain version of React Native. You'll f

## Documentation

- [configuration](./docs/configuration.md)
- [commands](./docs/commands.md)
- [plugins](./docs/plugins.md)
- [init](./docs/init.md)
- [autolinking](./docs/autolinking.md)
- [plugins](./docs/plugins.md)

## About

Expand Down
104 changes: 104 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,107 @@ Check the documentation for
- [plugins](./plugins.md)

to learn more about different types of configuration and features available.

## Migration guide

`"rnpm"` is deprecated and support for it will be removed in next major version of the CLI.

> **Important**: Proceed further only if your project uses `"rnpm"` in `package.json`.

There are different kinds of React Native projects, including apps, libraries and platforms. For each we prepared a brief "before & after" of the configuration shape with legacy `"rnpm"` and current `react-native.config.js`. Please mind that all configuration entries are optional.

### Apps

`package.json` entry:

```json
{
"rnpm": {
"ios": {},
"android": {},
"assets": ["./path-to-assets"],
"plugin": "./path-to-commands.js"
}
}
```

becomes `react-native.config.js`

```js
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ['./path-to-assets'], // stays the same
commands: require('./path-to-commands.js'), // formerly "plugin", returns an array of commands
};
```

### Libraries

`package.json` entry:

```json
{
"rnpm": {
"ios": {},
"android": {},
"assets": ["./path-to-assets"],
"hooks": {
"prelink": "./path-to-a-prelink-hook"
}
}
}
```

becomes `react-native.config.js`:

```js
module.exports = {
// config for a library is scoped under "dependency" key
dependency: {
platforms: {
ios: {},
android: {}, // projects are grouped into "platforms"
},
assets: ['./path-to-assets'], // stays the same
// hooks are considered anti-pattern, please avoid them
hooks: {
prelink: './path-to-a-prelink-hook',
},
},
};
```

You'll find more details in [dependencies](./dependencies.md) docs.

### Out-of-tree platforms

`package.json` entry:

```json
{
"rnpm": {
"haste": {
"platforms": ["windows"],
"providesModuleNodeModules": ["react-native-windows"]
},
"platform": "./local-cli/platform.js"
}
}
```

becomes `react-native.config.js`

```js
module.exports = {
platforms: {
// grouped under "platforms" entry
windows: require('./local-cli/platform.js').windows,
},
// "haste" is no longer needed
};
```

You'll find more details in [platforms](./platforms.md) docs.
27 changes: 26 additions & 1 deletion packages/cli/src/tools/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,23 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {
},
};

let depsWithWarnings = [];

const finalConfig = findDependencies(projectRoot).reduce(
(acc: ConfigT, dependencyName) => {
let root;
let config;
try {
root = resolveNodeModuleDir(projectRoot, dependencyName);
config = readDependencyConfigFromDisk(root);
const output = readDependencyConfigFromDisk(root);
config = output.config;

if (output.legacy) {
const pkg = require(path.join(root, 'package.json'));
const link =
pkg.homepage || `https://npmjs.com/package/${dependencyName}`;
depsWithWarnings.push([dependencyName, link]);
}
} catch (error) {
logger.warn(
inlineString(`
Expand Down Expand Up @@ -172,6 +182,21 @@ function loadConfig(projectRoot: string = process.cwd()): ConfigT {
initialConfig,
);

if (depsWithWarnings.length) {
logger.warn(
`The following packages use deprecated "rnpm" config that will stop working from next release:\n${depsWithWarnings
.map(
([name, link]) =>
` - ${chalk.bold(name)}: ${chalk.dim(chalk.underline(link))}`,
)
.join(
'\n',
)}\nPlease notify their maintainers about it. You can find more details at ${chalk.dim.underline(
'https://react-native-community/cli/docs/configuration.md#migration-guide',
)}.`,
);
}

return finalConfig;
}

Expand Down
15 changes: 5 additions & 10 deletions packages/cli/src/tools/config/readConfigFromDisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ export function readConfigFromDisk(rootFolder: string): UserConfigT {
*/
export function readDependencyConfigFromDisk(
rootFolder: string,
): UserDependencyConfigT {
): {config: UserDependencyConfigT, legacy?: boolean} {
const explorer = cosmiconfig('react-native', {
stopDir: rootFolder,
searchPlaces,
});

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

const result = Joi.validate(config, schema.dependencyConfig);
Expand All @@ -109,7 +110,7 @@ export function readDependencyConfigFromDisk(
throw new JoiError(result.error);
}

return result.value;
return {config: result.value, legacy: legacy && config !== undefined};
}

/**
Expand Down Expand Up @@ -139,7 +140,7 @@ const loadProjectCommands = (
function readLegacyDependencyConfigFromDisk(
rootFolder: string,
): ?UserDependencyConfigT {
const {rnpm: config, name} = require(path.join(rootFolder, 'package.json'));
const {rnpm: config} = require(path.join(rootFolder, 'package.json'));

if (!config) {
return undefined;
Expand All @@ -162,11 +163,5 @@ function readLegacyDependencyConfigFromDisk(
: {},
};

logger.warn(
`Package "${chalk.bold(
path.basename(name),
)}" is using deprecated "rnpm" config that will stop working from next release. Please notify its maintainers about it.`,
);

return transformedConfig;
}