Skip to content
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
6 changes: 5 additions & 1 deletion packages/cli/src/commands/link/__tests__/link.test.ts
Original file line number Diff line number Diff line change
@@ -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(() => {
Expand Down
3 changes: 3 additions & 0 deletions packages/cli/src/commands/link/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
Expand Down Expand Up @@ -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');

Expand Down
11 changes: 2 additions & 9 deletions packages/cli/src/commands/link/linkAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>): Array<string> =>
uniqBy(assets, asset => path.basename(asset));
Expand All @@ -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];
Expand Down
12 changes: 12 additions & 0 deletions packages/cli/src/commands/link/printDeprecationWarning.ts
Original file line number Diff line number Diff line change
@@ -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',
)}`,
);
}
2 changes: 2 additions & 0 deletions packages/cli/src/commands/link/unlink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
Expand All @@ -29,6 +30,7 @@ const unlinkDependency = (
packageName: string,
otherDependencies: Array<Dependency>,
) => {
printDeprecationWarning('react-native unlink [packageName]');
Object.keys(platforms || {}).forEach(platform => {
const projectConfig: AndroidProjectConfig | IOSProjectConfig =
project[platform];
Expand Down