Skip to content

Commit f60bb00

Browse files
fix(lint): use top-level codegenNativeComponent import
Replaces the deprecated deep import `react-native/Libraries/Utilities/codegenNativeComponent` with the top-level named import now exported from `react-native`. The `react-native/Libraries/Types/CodegenTypes` import is preserved because codegen's AST parser matches those type names statically — it can't follow namespace or alias indirection. Suppressed the lint warning on that one line with a note explaining why. Also simplifies the jest setup: `codegenNativeComponent` is now mocked alongside the rest of `react-native` in `__mocks__/react-native.ts`, so the separate `__mocks__/codegenNativeComponent.ts` file and its `moduleNameMapper` entry in `jest.config.js` are no longer needed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 584f9e0 commit f60bb00

5 files changed

Lines changed: 6 additions & 19 deletions

File tree

__mocks__/codegenNativeComponent.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

__mocks__/react-native.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const requireNativeComponent = (..._args: any[]) => {
3939
});
4040
};
4141

42+
const codegenNativeComponent = requireNativeComponent;
43+
4244
const StyleSheet = {
4345
flatten: jest.fn(style => style),
4446
};
@@ -71,6 +73,7 @@ module.exports = {
7173
},
7274
NativeEventEmitter: jest.fn(() => createMockEmitter()),
7375
requireNativeComponent,
76+
codegenNativeComponent,
7477
TurboModuleRegistry: {
7578
getEnforcing: jest.fn((name: string) => {
7679
if (name === 'ShopifyCheckoutSheetKit') {

jest.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ module.exports = {
33
modulePathIgnorePatterns: ['modules/@shopify/checkout-sheet-kit/lib'],
44
modulePaths: ['<rootDir>/sample/node_modules'],
55
setupFiles: ['<rootDir>/jest.setup.ts'],
6-
moduleNameMapper: {
7-
'react-native/Libraries/Utilities/codegenNativeComponent':
8-
'<rootDir>/__mocks__/codegenNativeComponent.ts',
9-
},
106
transform: {
117
'\\.[jt]sx?$': 'babel-jest',
128
},

modules/@shopify/checkout-sheet-kit/src/components/AcceleratedCheckoutButtons.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SO
2222
*/
2323

2424
import React, {useCallback, useMemo, useState} from 'react';
25-
import {Platform} from 'react-native';
25+
import {codegenNativeComponent, Platform} from 'react-native';
2626
import type {ViewStyle} from 'react-native';
27-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2827
import type {
2928
AcceleratedCheckoutWallet,
3029
CheckoutCompletedEvent,

modules/@shopify/checkout-sheet-kit/src/specs/RCTAcceleratedCheckoutButtonsNativeComponent.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2121
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

24-
import type {ViewProps} from 'react-native';
25-
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
24+
import {codegenNativeComponent, type ViewProps} from 'react-native';
2625
import type {
2726
BubblingEventHandler,
2827
DirectEventHandler,
2928
Double,
3029
Float,
30+
// eslint-disable-next-line @react-native/no-deep-imports -- codegen parser requires these type names to be imported directly (not via aliases) so it can match them statically during AST traversal
3131
} from 'react-native/Libraries/Types/CodegenTypes';
3232

3333
type FailEvent = Readonly<{

0 commit comments

Comments
 (0)