77 * @flow
88 */
99
10- import { flatMap , values , difference } from 'lodash' ;
10+ import { flatMap , values , difference , pick } from 'lodash' ;
1111import { logger , CLIError } from '@react-native-community/cli-tools' ;
1212import type { ConfigT } from 'types' ;
1313import getPlatformName from './getPlatformName' ;
1414import makeHook from './makeHook' ;
1515
16+ type Flags = {
17+ platforms ?: Array < string > ,
18+ } ;
19+
1620const 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