Skip to content

Commit a90851a

Browse files
Esemesekthymikee
andauthored
chore: add deprecation messages for manual linking (#1037)
* imp: Add deprecation messages for linking * Correct messages * Wrong English * adjust wording Co-authored-by: Michał Pierzchała <thymikee@gmail.com>
1 parent 6cded84 commit a90851a

File tree

5 files changed

+24
-10
lines changed

5 files changed

+24
-10
lines changed

packages/cli/src/commands/link/__tests__/link.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import {func as link} from '../link';
22
import loadConfig from '../../../tools/config';
33
import makeHook from '../makeHook';
4-
jest.mock('chalk', () => ({grey: str => str, bold: str => str}));
4+
jest.mock('chalk', () => ({
5+
grey: jest.fn(),
6+
bold: jest.fn(),
7+
dim: {underline: jest.fn()},
8+
}));
59
jest.mock('../../../tools/config');
610
jest.mock('../makeHook', () => {
711
return jest.fn(() => {

packages/cli/src/commands/link/link.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import linkDependency from './linkDependency';
1515
import linkAssets from './linkAssets';
1616
import linkAll from './linkAll';
1717
import makeHook from './makeHook';
18+
import printDeprecationWarning from './printDeprecationWarning';
1819

1920
type FlagsType = {
2021
platforms?: Array<string>;
@@ -53,6 +54,8 @@ async function link(
5354
return linkAll(ctx, {linkDeps: opts.all, linkAssets: true});
5455
}
5556

57+
printDeprecationWarning('react-native link [packageName]');
58+
5659
// Trim the version / tag out of the package name (eg. package@latest)
5760
const packageName = rawPackageName.replace(/^(.+?)(@.+?)$/gi, '$1');
5861

packages/cli/src/commands/link/linkAll.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {Config} from '@react-native-community/cli-types';
66
import linkAssets from './linkAssets';
77
import linkDependency from './linkDependency';
88
import makeHook from './makeHook';
9+
import printDeprecationWarning from './printDeprecationWarning';
910

1011
const dedupeAssets = (assets: Array<string>): Array<string> =>
1112
uniqBy(assets, asset => path.basename(asset));
@@ -17,16 +18,8 @@ type Options = {
1718

1819
async function linkAll(config: Config, options: Options) {
1920
if (options.linkDeps) {
21+
printDeprecationWarning('react-native link --all');
2022
logger.debug('Linking all dependencies');
21-
logger.info(
22-
`Linking dependencies using "${chalk.bold(
23-
'link',
24-
)}" command is now legacy and most likely unnecessary. We encourage you to try ${chalk.bold(
25-
'autolinking',
26-
)} that comes with React Native v0.60 default template. Autolinking happens at build time – during CocoaPods install or Gradle install phase. More information: ${chalk.dim.underline(
27-
'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md',
28-
)}`,
29-
);
3023

3124
for (let key in config.dependencies) {
3225
const dependency = config.dependencies[key];
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import chalk from 'chalk';
2+
import {logger} from '@react-native-community/cli-tools';
3+
4+
export default function printDeprecationWarning(command: string) {
5+
logger.warn(
6+
`Calling ${chalk.bold(
7+
command,
8+
)} is deprecated in favor of autolinking. It will be removed in the next major release.\nAutolinking documentation: ${chalk.dim.underline(
9+
'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md',
10+
)}`,
11+
);
12+
}

packages/cli/src/commands/link/unlink.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from '@react-native-community/cli-types';
1818
import getPlatformName from './getPlatformName';
1919
import makeHook from './makeHook';
20+
import printDeprecationWarning from './printDeprecationWarning';
2021

2122
type Flags = {
2223
platforms?: Array<string>;
@@ -29,6 +30,7 @@ const unlinkDependency = (
2930
packageName: string,
3031
otherDependencies: Array<Dependency>,
3132
) => {
33+
printDeprecationWarning('react-native unlink [packageName]');
3234
Object.keys(platforms || {}).forEach(platform => {
3335
const projectConfig: AndroidProjectConfig | IOSProjectConfig =
3436
project[platform];

0 commit comments

Comments
 (0)