@@ -21,6 +21,8 @@ module.exports = {
2121 messages : {
2222 deepImport :
2323 "'{{importPath}}' React Native deep imports are deprecated. Please use the top level import instead." ,
24+ useReplacementSource :
25+ "'{{importPath}}' is deprecated. Please import '{{replacementSource}}' instead." ,
2426 } ,
2527 schema : [ ] ,
2628 fixable : 'code' ,
@@ -31,12 +33,14 @@ module.exports = {
3133 ImportDeclaration ( node ) {
3234 if (
3335 ! isDeepReactNativeImport ( node . source ) ||
34- isInitializeCoreImport ( node . source ) ||
3536 isSecondaryEntryPoint ( node . source ) ||
3637 isFbInternalImport ( node . source )
3738 ) {
3839 return ;
3940 }
41+ if ( reportReplacementSource ( node . source ) ) {
42+ return ;
43+ }
4044 if ( isDefaultImport ( node ) ) {
4145 const reactNativeSource = node . source . value . slice (
4246 'react-native/' . length ,
@@ -88,13 +92,16 @@ module.exports = {
8892 CallExpression ( node ) {
8993 if (
9094 ! isDeepRequire ( node ) ||
91- isInitializeCoreImport ( node . arguments [ 0 ] ) ||
9295 isSecondaryEntryPoint ( node . arguments [ 0 ] ) ||
9396 isFbInternalImport ( node . arguments [ 0 ] )
9497 ) {
9598 return ;
9699 }
97100
101+ if ( reportReplacementSource ( node . arguments [ 0 ] ) ) {
102+ return ;
103+ }
104+
98105 const parent = node . parent ;
99106 const importPath = node . arguments [ 0 ] . value ;
100107
@@ -123,6 +130,26 @@ module.exports = {
123130 } ,
124131 } ;
125132
133+ function reportReplacementSource ( source ) {
134+ const reactNativeSource = source . value . slice ( 'react-native/' . length ) ;
135+ const mapping = publicAPIMapping [ reactNativeSource ] ;
136+ if ( ! mapping || ! mapping . replacementSource ) {
137+ return false ;
138+ }
139+ context . report ( {
140+ node : source ,
141+ messageId : 'useReplacementSource' ,
142+ data : {
143+ importPath : source . value ,
144+ replacementSource : mapping . replacementSource ,
145+ } ,
146+ fix ( fixer ) {
147+ return fixer . replaceText ( source , `'${ mapping . replacementSource } '` ) ;
148+ } ,
149+ } ) ;
150+ return true ;
151+ }
152+
126153 function getStandardReport ( source ) {
127154 return {
128155 node : source ,
@@ -167,20 +194,15 @@ module.exports = {
167194 return parts . length > 1 && parts [ 0 ] === 'react-native' ;
168195 }
169196
170- function isInitializeCoreImport ( source ) {
171- if ( source . type !== 'Literal' || typeof source . value !== 'string' ) {
172- return false ;
173- }
174-
175- return source . value === 'react-native/Libraries/Core/InitializeCore' ;
176- }
177-
178197 function isSecondaryEntryPoint ( source ) {
179198 if ( source . type !== 'Literal' || typeof source . value !== 'string' ) {
180199 return false ;
181200 }
182201
183- return source . value === 'react-native/asset-registry' ;
202+ return (
203+ source . value === 'react-native/asset-registry' ||
204+ source . value === 'react-native/setup-env'
205+ ) ;
184206 }
185207
186208 function isFbInternalImport ( source ) {
0 commit comments