diff --git a/packages/cli/src/commands/link/__tests__/link.test.ts b/packages/cli/src/commands/link/__tests__/link.test.ts index bcb7021cc..69817b746 100644 --- a/packages/cli/src/commands/link/__tests__/link.test.ts +++ b/packages/cli/src/commands/link/__tests__/link.test.ts @@ -1,7 +1,11 @@ import {func as link} from '../link'; import loadConfig from '../../../tools/config'; import makeHook from '../makeHook'; -jest.mock('chalk', () => ({grey: str => str, bold: str => str})); +jest.mock('chalk', () => ({ + grey: jest.fn(), + bold: jest.fn(), + dim: {underline: jest.fn()}, +})); jest.mock('../../../tools/config'); jest.mock('../makeHook', () => { return jest.fn(() => { diff --git a/packages/cli/src/commands/link/link.ts b/packages/cli/src/commands/link/link.ts index d1cf9bba7..84aefcb1d 100644 --- a/packages/cli/src/commands/link/link.ts +++ b/packages/cli/src/commands/link/link.ts @@ -15,6 +15,7 @@ import linkDependency from './linkDependency'; import linkAssets from './linkAssets'; import linkAll from './linkAll'; import makeHook from './makeHook'; +import printDeprecationWarning from './printDeprecationWarning'; type FlagsType = { platforms?: Array; @@ -53,6 +54,8 @@ async function link( return linkAll(ctx, {linkDeps: opts.all, linkAssets: true}); } + printDeprecationWarning('react-native link [packageName]'); + // Trim the version / tag out of the package name (eg. package@latest) const packageName = rawPackageName.replace(/^(.+?)(@.+?)$/gi, '$1'); diff --git a/packages/cli/src/commands/link/linkAll.ts b/packages/cli/src/commands/link/linkAll.ts index 3ff6f37f5..184ae4fd4 100644 --- a/packages/cli/src/commands/link/linkAll.ts +++ b/packages/cli/src/commands/link/linkAll.ts @@ -6,6 +6,7 @@ import {Config} from '@react-native-community/cli-types'; import linkAssets from './linkAssets'; import linkDependency from './linkDependency'; import makeHook from './makeHook'; +import printDeprecationWarning from './printDeprecationWarning'; const dedupeAssets = (assets: Array): Array => uniqBy(assets, asset => path.basename(asset)); @@ -17,16 +18,8 @@ type Options = { async function linkAll(config: Config, options: Options) { if (options.linkDeps) { + printDeprecationWarning('react-native link --all'); logger.debug('Linking all dependencies'); - logger.info( - `Linking dependencies using "${chalk.bold( - 'link', - )}" command is now legacy and most likely unnecessary. We encourage you to try ${chalk.bold( - 'autolinking', - )} 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( - 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', - )}`, - ); for (let key in config.dependencies) { const dependency = config.dependencies[key]; diff --git a/packages/cli/src/commands/link/printDeprecationWarning.ts b/packages/cli/src/commands/link/printDeprecationWarning.ts new file mode 100644 index 000000000..74e980d2a --- /dev/null +++ b/packages/cli/src/commands/link/printDeprecationWarning.ts @@ -0,0 +1,12 @@ +import chalk from 'chalk'; +import {logger} from '@react-native-community/cli-tools'; + +export default function printDeprecationWarning(command: string) { + logger.warn( + `Calling ${chalk.bold( + command, + )} is deprecated in favor of autolinking. It will be removed in the next major release.\nAutolinking documentation: ${chalk.dim.underline( + 'https://github.com/react-native-community/cli/blob/master/docs/autolinking.md', + )}`, + ); +} diff --git a/packages/cli/src/commands/link/unlink.ts b/packages/cli/src/commands/link/unlink.ts index 59759d905..f6aef7252 100644 --- a/packages/cli/src/commands/link/unlink.ts +++ b/packages/cli/src/commands/link/unlink.ts @@ -17,6 +17,7 @@ import { } from '@react-native-community/cli-types'; import getPlatformName from './getPlatformName'; import makeHook from './makeHook'; +import printDeprecationWarning from './printDeprecationWarning'; type Flags = { platforms?: Array; @@ -29,6 +30,7 @@ const unlinkDependency = ( packageName: string, otherDependencies: Array, ) => { + printDeprecationWarning('react-native unlink [packageName]'); Object.keys(platforms || {}).forEach(platform => { const projectConfig: AndroidProjectConfig | IOSProjectConfig = project[platform];