Skip to content

Commit f5d64fb

Browse files
authored
feat: support unlink --platforms (#511)
1 parent a3d468e commit f5d64fb

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed

packages/cli/src/commands/install/uninstall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
import type {ConfigT} from 'types';
1111
import {logger} from '@react-native-community/cli-tools';
1212
import * as PackageManager from '../../tools/packageManager';
13-
import link from '../link/unlink';
13+
import unlink from '../link/unlink';
1414

1515
async function uninstall(args: Array<string>, ctx: ConfigT) {
1616
const name = args[0];
1717

1818
logger.info(`Unlinking "${name}"...`);
19-
await link.func([name], ctx);
19+
await unlink.func([name], ctx, {});
2020

2121
logger.info(`Uninstalling "${name}"...`);
2222
await PackageManager.uninstall([name]);

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
* @flow
88
*/
99

10-
import {flatMap, values, difference} from 'lodash';
10+
import {flatMap, values, difference, pick} from 'lodash';
1111
import {logger, CLIError} from '@react-native-community/cli-tools';
1212
import type {ConfigT} from 'types';
1313
import getPlatformName from './getPlatformName';
1414
import makeHook from './makeHook';
1515

16+
type Flags = {
17+
platforms?: Array<string>,
18+
};
19+
1620
const unlinkDependency = (
1721
platforms,
1822
project,
@@ -78,8 +82,20 @@ const unlinkDependency = (
7882
* If optional argument [packageName] is provided, it's the only one
7983
* that's checked
8084
*/
81-
async function unlink(args: Array<string>, ctx: ConfigT) {
85+
async function unlink(args: Array<string>, ctx: ConfigT, opts: Flags) {
8286
const packageName = args[0];
87+
let platforms = ctx.platforms;
88+
89+
if (opts.platforms) {
90+
platforms = pick(platforms, opts.platforms);
91+
logger.debug('Skipping selected platforms');
92+
}
93+
94+
logger.debug(
95+
`Available platforms: ${Object.keys(platforms)
96+
.map(getPlatformName)
97+
.join(', ')}`,
98+
);
8399

84100
const {[packageName]: dependency, ...otherDependencies} = ctx.dependencies;
85101

@@ -95,7 +111,7 @@ async function unlink(args: Array<string>, ctx: ConfigT) {
95111
await makeHook(dependency.hooks.preulink)();
96112
}
97113
unlinkDependency(
98-
ctx.platforms,
114+
platforms,
99115
ctx.project,
100116
dependency,
101117
packageName,
@@ -122,12 +138,12 @@ async function unlink(args: Array<string>, ctx: ConfigT) {
122138
return;
123139
}
124140

125-
Object.keys(ctx.platforms || {}).forEach(platform => {
141+
Object.keys(platforms || {}).forEach(platform => {
126142
const projectConfig = ctx.project[platform];
127143
const linkConfig =
128-
ctx.platforms[platform] &&
129-
ctx.platforms[platform].linkConfig &&
130-
ctx.platforms[platform].linkConfig();
144+
platforms[platform] &&
145+
platforms[platform].linkConfig &&
146+
platforms[platform].linkConfig();
131147
if (!linkConfig || !linkConfig.unlinkAssets || !projectConfig) {
132148
return;
133149
}
@@ -146,4 +162,11 @@ export default {
146162
func: unlink,
147163
description: 'unlink native dependency',
148164
name: 'unlink <packageName>',
165+
options: [
166+
{
167+
name: '--platforms [list]',
168+
description: 'Scope unlinking to specified platforms',
169+
parse: (val: string) => val.toLowerCase().split(','),
170+
},
171+
],
149172
};

0 commit comments

Comments
 (0)