From 1346d01051c711a517b348665c38ec7674db7c31 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Tue, 17 Dec 2024 13:53:05 -0500 Subject: [PATCH 1/7] install @comapeo/core-react --- package-lock.json | 14 ++++++++++++++ package.json | 1 + 2 files changed, 15 insertions(+) diff --git a/package-lock.json b/package-lock.json index 47c2b3602..94e8626a9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "hasInstallScript": true, "dependencies": { "@bam.tech/react-native-image-resizer": "3.0.11", + "@comapeo/core-react": "1.0.0", "@comapeo/ipc": "2.1.0", "@expo-google-fonts/rubik": "0.2.3", "@formatjs/intl-getcanonicallocales": "2.5.4", @@ -2459,6 +2460,19 @@ "yauzl-promise": "^4.0.0" } }, + "node_modules/@comapeo/core-react": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@comapeo/core-react/-/core-react-1.0.0.tgz", + "integrity": "sha512-q705wyEQRT+7+De2tbP7VbZZkyPaT/PJByrIIoec+DFwk0IhpqSvfu+KuCEbNyHVKjlD1hJYO0xECrhLYWnm6g==", + "license": "MIT", + "peerDependencies": { + "@comapeo/core": "*", + "@comapeo/ipc": "*", + "@comapeo/schema": "*", + "@tanstack/react-query": "^5", + "react": "^18 || ^19" + } + }, "node_modules/@comapeo/core/node_modules/@sinclair/typebox": { "version": "0.29.6", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.29.6.tgz", diff --git a/package.json b/package.json index 2f49a8d7f..d383a5f1f 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ }, "dependencies": { "@bam.tech/react-native-image-resizer": "3.0.11", + "@comapeo/core-react": "1.0.0", "@comapeo/ipc": "2.1.0", "@expo-google-fonts/rubik": "0.2.3", "@formatjs/intl-getcanonicallocales": "2.5.4", From 68fd9a6fa9f862b1df095cb365eccfac7f836216 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Tue, 17 Dec 2024 13:58:52 -0500 Subject: [PATCH 2/7] chore: initial @comapeo/core-react integration This PR introduce usage of the `ClientApiProvider` and `useClientApi()` provided by the module. These are 1-to-1 replacements for the pre-existing `ApiProvider` and `useApi()`, respectively. --- package-lock.json | 8 +++---- package.json | 2 +- src/frontend/Navigation/Stack/index.tsx | 4 ++-- .../contexts/ActiveProjectContext.tsx | 4 ++-- src/frontend/contexts/ApiContext.tsx | 22 ------------------- src/frontend/contexts/AppProviders.tsx | 6 ++--- src/frontend/hooks/server/deviceInfo.ts | 7 +++--- src/frontend/hooks/server/invites.ts | 8 +++---- src/frontend/hooks/server/maps.ts | 9 ++++---- src/frontend/hooks/server/mediaSync.ts | 6 ++--- src/frontend/hooks/server/projects.ts | 10 ++++----- src/frontend/hooks/useLocalPeers.ts | 6 ++--- .../hooks/useProjectInvitesListener.ts | 4 ++-- .../screens/Settings/CreateTestData.tsx | 4 ++-- .../ProjectInviteBottomSheet/index.tsx | 4 ++-- 15 files changed, 41 insertions(+), 63 deletions(-) delete mode 100644 src/frontend/contexts/ApiContext.tsx diff --git a/package-lock.json b/package-lock.json index 94e8626a9..ff9c280d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "dependencies": { "@bam.tech/react-native-image-resizer": "3.0.11", - "@comapeo/core-react": "1.0.0", + "@comapeo/core-react": "1.0.1", "@comapeo/ipc": "2.1.0", "@expo-google-fonts/rubik": "0.2.3", "@formatjs/intl-getcanonicallocales": "2.5.4", @@ -2461,9 +2461,9 @@ } }, "node_modules/@comapeo/core-react": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@comapeo/core-react/-/core-react-1.0.0.tgz", - "integrity": "sha512-q705wyEQRT+7+De2tbP7VbZZkyPaT/PJByrIIoec+DFwk0IhpqSvfu+KuCEbNyHVKjlD1hJYO0xECrhLYWnm6g==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@comapeo/core-react/-/core-react-1.0.1.tgz", + "integrity": "sha512-rU3r/Kd7z3Y8yK7vVXvWQrzewdDxlJ9dTBZROIPuB4mWL41wCx7OCDBONaPn++tE+KJUk9E28Btgdf9EJfwlPA==", "license": "MIT", "peerDependencies": { "@comapeo/core": "*", diff --git a/package.json b/package.json index d383a5f1f..cb41f4afa 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@bam.tech/react-native-image-resizer": "3.0.11", - "@comapeo/core-react": "1.0.0", + "@comapeo/core-react": "1.0.1", "@comapeo/ipc": "2.1.0", "@expo-google-fonts/rubik": "0.2.3", "@formatjs/intl-getcanonicallocales": "2.5.4", diff --git a/src/frontend/Navigation/Stack/index.tsx b/src/frontend/Navigation/Stack/index.tsx index 90157d3ea..b2daf1b78 100644 --- a/src/frontend/Navigation/Stack/index.tsx +++ b/src/frontend/Navigation/Stack/index.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import {useClientApi} from '@comapeo/core-react'; import {createNativeStackNavigator} from '@react-navigation/native-stack'; import {NativeStackNavigationOptions} from '@react-navigation/native-stack/lib/typescript/src/types'; import {WHITE} from '../../lib/styles'; @@ -17,7 +18,6 @@ import {getInitialRouteName} from '../../utils/navigation'; import {createDefaultScreenGroup} from './AppScreens'; import {createOnboardingScreens} from './OnboardingScreens'; import {useSuspenseQuery} from '@tanstack/react-query'; -import {useApi} from '../../contexts/ApiContext'; import {Loading} from '../../sharedComponents/Loading'; import {useSecurityContext} from '../../contexts/SecurityContext'; import {useNavigationFromRoot} from '../../hooks/useNavigationWithTypes'; @@ -63,7 +63,7 @@ function RootStackNavigatorChild() { store => store.value, ); const {data: presets} = usePresetsQuery(); - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const deviceInfo = useSuspenseQuery({ queryKey: [DEVICE_INFO_KEY], diff --git a/src/frontend/contexts/ActiveProjectContext.tsx b/src/frontend/contexts/ActiveProjectContext.tsx index 6f49a7515..185825979 100644 --- a/src/frontend/contexts/ActiveProjectContext.tsx +++ b/src/frontend/contexts/ActiveProjectContext.tsx @@ -1,10 +1,10 @@ import * as React from 'react'; +import {useClientApi} from '@comapeo/core-react'; import {type MapeoProjectApi} from '@comapeo/ipc'; import {usePersistedProjectId} from '../hooks/persistedState/usePersistedProjectId'; import {useProject, useCreateProject} from '../hooks/server/projects'; import {Loading} from '../sharedComponents/Loading'; -import {useApi} from './ApiContext'; const ActiveProjectContext = React.createContext< {projectId: string; projectApi: MapeoProjectApi} | undefined @@ -13,7 +13,7 @@ const ActiveProjectContext = React.createContext< export const ActiveProjectProvider = ({ children, }: React.PropsWithChildren<{}>) => { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const activeProjectId = usePersistedProjectId(store => store.projectId); const setActiveProjectId = usePersistedProjectId(store => store.setProjectId); diff --git a/src/frontend/contexts/ApiContext.tsx b/src/frontend/contexts/ApiContext.tsx deleted file mode 100644 index 0a1dbb672..000000000 --- a/src/frontend/contexts/ApiContext.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import * as React from 'react'; -import {type MapeoClientApi} from '@comapeo/ipc'; - -// TODO: support passing api mock for unit tests -const ApiContext = React.createContext(undefined); - -export type ApiProviderProps = { - api: MapeoClientApi; - children?: React.ReactNode; -}; - -export const ApiProvider = ({api, children}: ApiProviderProps): JSX.Element => { - return {children}; -}; - -export function useApi() { - const api = React.useContext(ApiContext); - if (!api) { - throw new Error('No Api set, use ApiProvider to set one'); - } - return api; -} diff --git a/src/frontend/contexts/AppProviders.tsx b/src/frontend/contexts/AppProviders.tsx index 903ddfe1e..7fffea7a2 100644 --- a/src/frontend/contexts/AppProviders.tsx +++ b/src/frontend/contexts/AppProviders.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import {ClientApiProvider} from '@comapeo/core-react'; import {GestureHandlerRootView} from 'react-native-gesture-handler'; import {QueryClient, QueryClientProvider} from '@tanstack/react-query'; import {StyleSheet} from 'react-native'; @@ -19,7 +20,6 @@ import { } from './LocalDiscoveryContext'; import {type MapeoClientApi} from '@comapeo/ipc'; import {ServerLoading} from '../ServerLoading'; -import {ApiProvider} from './ApiContext'; import {MessagePortLike} from '../lib/MessagePortLike'; import {IntlProvider} from './IntlContext'; import {BottomSheetModalProvider} from '@gorhom/bottom-sheet'; @@ -55,7 +55,7 @@ export const AppProviders = ({ - + @@ -67,7 +67,7 @@ export const AppProviders = ({ - + diff --git a/src/frontend/hooks/server/deviceInfo.ts b/src/frontend/hooks/server/deviceInfo.ts index db6ca1c55..6c1ac7e59 100644 --- a/src/frontend/hooks/server/deviceInfo.ts +++ b/src/frontend/hooks/server/deviceInfo.ts @@ -1,12 +1,11 @@ +import {useClientApi} from '@comapeo/core-react'; import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'; import {deviceType, DeviceType} from 'expo-device'; -import {useApi} from '../../contexts/ApiContext'; - export const DEVICE_INFO_KEY = 'deviceInfo'; export const useDeviceInfo = () => { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); return useQuery({ queryKey: [DEVICE_INFO_KEY], @@ -17,7 +16,7 @@ export const useDeviceInfo = () => { }; export const useEditDeviceInfo = () => { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const queryClient = useQueryClient(); return useMutation({ diff --git a/src/frontend/hooks/server/invites.ts b/src/frontend/hooks/server/invites.ts index 066c4122d..a7a253641 100644 --- a/src/frontend/hooks/server/invites.ts +++ b/src/frontend/hooks/server/invites.ts @@ -1,10 +1,10 @@ +import {useClientApi} from '@comapeo/core-react'; import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query'; -import {useApi} from '../../contexts/ApiContext'; import {useActiveProject} from '../../contexts/ActiveProjectContext'; import {usePersistedProjectId} from '../persistedState/usePersistedProjectId'; import {ALL_PROJECTS_KEY, PROJECT_MEMBERS_KEY} from './projects'; @@ -12,7 +12,7 @@ import {ALL_PROJECTS_KEY, PROJECT_MEMBERS_KEY} from './projects'; export const INVITE_KEY = 'pending_invites'; export function usePendingInvites() { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); return useSuspenseQuery({ queryKey: [INVITE_KEY], queryFn: async () => { @@ -22,7 +22,7 @@ export function usePendingInvites() { } export function useAcceptInvite() { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const queryClient = useQueryClient(); const switchActiveProject = usePersistedProjectId( state => state.setProjectId, @@ -46,7 +46,7 @@ export function useAcceptInvite() { } export function useRejectInvite() { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const queryClient = useQueryClient(); return useMutation({ mutationFn: async ({inviteId}: {inviteId: string}) => { diff --git a/src/frontend/hooks/server/maps.ts b/src/frontend/hooks/server/maps.ts index 040c9bedb..fc4fcdeee 100644 --- a/src/frontend/hooks/server/maps.ts +++ b/src/frontend/hooks/server/maps.ts @@ -1,8 +1,8 @@ +import {useClientApi} from '@comapeo/core-react'; import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'; import * as FileSystem from 'expo-file-system'; import * as v from 'valibot'; -import {useApi} from '../../contexts/ApiContext'; import {DOCUMENT_DIRECTORY} from '../../lib/file-system'; import {createRefreshTokenStore} from '../refreshTokenStore'; @@ -28,7 +28,7 @@ export type CustomMapInfo = v.InferOutput; const {useRefreshToken, useRefreshTokenActions} = createRefreshTokenStore(); export function useMapStyleJsonUrl() { - const api = useApi(); + const api = useClientApi(); const refreshToken = useRefreshToken(); return useQuery({ @@ -42,7 +42,8 @@ export function useMapStyleJsonUrl() { export function useImportCustomMapFile() { const queryClient = useQueryClient(); - const api = useApi(); + // const api = useApi(); + const api = useClientApi(); const {refresh} = useRefreshTokenActions(); return useMutation({ @@ -96,7 +97,7 @@ export function useRemoveCustomMapFile() { * Returns `null` if no viable map is found. Throws an error if a detected map is invalid. */ export function useGetCustomMapInfo() { - const api = useApi(); + const api = useClientApi(); return useQuery({ queryKey: [MAPS_QUERY_KEY, 'custom', 'info'], diff --git a/src/frontend/hooks/server/mediaSync.ts b/src/frontend/hooks/server/mediaSync.ts index e665e07bd..1c7ec2531 100644 --- a/src/frontend/hooks/server/mediaSync.ts +++ b/src/frontend/hooks/server/mediaSync.ts @@ -1,9 +1,9 @@ +import {useClientApi} from '@comapeo/core-react'; import { useMutation, useQueryClient, useSuspenseQuery, } from '@tanstack/react-query'; -import {useApi} from '../../contexts/ApiContext'; import {MediaSyncSetting} from '../../sharedTypes'; export const MEDIA_SYNC_SETTING_KEY = 'media_sync_setting'; @@ -17,7 +17,7 @@ export function isArchiveDevice(value: MediaSyncSetting): boolean { } export function useGetMediaSyncSetting() { - const api = useApi(); + const api = useClientApi(); return useSuspenseQuery({ queryKey: [MEDIA_SYNC_SETTING_KEY], @@ -29,7 +29,7 @@ export function useGetMediaSyncSetting() { } export function useSetMediaSyncSetting() { - const api = useApi(); + const api = useClientApi(); const queryClient = useQueryClient(); return useMutation({ diff --git a/src/frontend/hooks/server/projects.ts b/src/frontend/hooks/server/projects.ts index e5e6d20f3..29e630e5f 100644 --- a/src/frontend/hooks/server/projects.ts +++ b/src/frontend/hooks/server/projects.ts @@ -1,6 +1,6 @@ +import {useClientApi} from '@comapeo/core-react'; import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'; -import {useApi} from '../../contexts/ApiContext'; import {useActiveProject} from '../../contexts/ActiveProjectContext'; import {PRESETS_KEY} from './presets'; import {ICONS_KEY} from './icons'; @@ -17,7 +17,7 @@ export const THIS_USERS_ROLE_KEY = 'my_role'; export const REMOTE_ARCHIVE = 'remote_archive'; export function useProject(projectId?: string) { - const api = useApi(); + const api = useClientApi(); return useQuery({ queryKey: [PROJECT_KEY, projectId], @@ -33,7 +33,7 @@ export function useProject(projectId?: string) { } export function useAllProjects() { - const api = useApi(); + const api = useClientApi(); return useQuery({ queryKey: [ALL_PROJECTS_KEY], @@ -44,7 +44,7 @@ export function useAllProjects() { } export function useCreateProject() { - const api = useApi(); + const api = useClientApi(); const queryClient = useQueryClient(); return useMutation({ @@ -107,7 +107,7 @@ export const useOriginalVersionIdToDeviceId = (originalVersionId: string) => { }; export function useLeaveProject() { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const queryClient = useQueryClient(); diff --git a/src/frontend/hooks/useLocalPeers.ts b/src/frontend/hooks/useLocalPeers.ts index abd1bce9d..72838ad0c 100644 --- a/src/frontend/hooks/useLocalPeers.ts +++ b/src/frontend/hooks/useLocalPeers.ts @@ -1,6 +1,6 @@ -import {type MapeoClientApi} from '@comapeo/ipc'; import {useSyncExternalStore} from 'react'; -import {useApi} from '../contexts/ApiContext'; +import {useClientApi} from '@comapeo/core-react'; +import {type MapeoClientApi} from '@comapeo/ipc'; type LocalPeer = Awaited>[number]; @@ -10,7 +10,7 @@ let localPeerState: ReturnType | undefined; * @returns An array of local peers (includes peers that were previously connected but are no longer connected) */ export function useLocalPeers(): LocalPeer[] { - const api = useApi(); + const api = useClientApi(); if (!localPeerState) { localPeerState = createLocalPeerState(api); } diff --git a/src/frontend/hooks/useProjectInvitesListener.ts b/src/frontend/hooks/useProjectInvitesListener.ts index 8a8facf71..d795279a2 100644 --- a/src/frontend/hooks/useProjectInvitesListener.ts +++ b/src/frontend/hooks/useProjectInvitesListener.ts @@ -1,8 +1,8 @@ import {useCallback, useEffect, useState} from 'react'; -import {useApi} from '../contexts/ApiContext'; import {useQueryClient} from '@tanstack/react-query'; import {INVITE_KEY} from './server/invites'; import {Invite, InviteRemovalReason} from '@comapeo/core/dist/invite-api'; +import {useClientApi} from '@comapeo/core-react'; export const useProjectInvitesListener = ({ inviteId, @@ -11,7 +11,7 @@ export const useProjectInvitesListener = ({ inviteId?: string; bottomSheetIsOpen: boolean; }) => { - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const queryClient = useQueryClient(); const [currentInviteCanceled, setCurrentInviteCancelled] = useState(false); diff --git a/src/frontend/screens/Settings/CreateTestData.tsx b/src/frontend/screens/Settings/CreateTestData.tsx index fe53f369b..1f9b7c983 100644 --- a/src/frontend/screens/Settings/CreateTestData.tsx +++ b/src/frontend/screens/Settings/CreateTestData.tsx @@ -1,3 +1,4 @@ +import {useClientApi} from '@comapeo/core-react'; import {useMutation, useQueryClient} from '@tanstack/react-query'; import {lengthToDegrees} from '@turf/helpers'; import {randomPosition} from '@turf/random'; @@ -9,7 +10,6 @@ import {StyleSheet, TextInput, ToastAndroid, View} from 'react-native'; import {UIActivityIndicator} from 'react-native-indicators'; import {useActiveProject} from '../../contexts/ActiveProjectContext'; -import {useApi} from '../../contexts/ApiContext'; import {OBSERVATION_KEY} from '../../hooks/server/observations'; import {useLocation} from '../../hooks/useLocation'; import {LIGHT_GREY, RED, WHITE} from '../../lib/styles'; @@ -225,7 +225,7 @@ const styles = StyleSheet.create({ function useCreateFakeObservationsMutation() { const queryClient = useQueryClient(); - const mapeoApi = useApi(); + const mapeoApi = useClientApi(); const {projectApi, projectId} = useActiveProject(); return useMutation({ diff --git a/src/frontend/sharedComponents/ProjectInviteBottomSheet/index.tsx b/src/frontend/sharedComponents/ProjectInviteBottomSheet/index.tsx index e4cbf1791..1af750bf7 100644 --- a/src/frontend/sharedComponents/ProjectInviteBottomSheet/index.tsx +++ b/src/frontend/sharedComponents/ProjectInviteBottomSheet/index.tsx @@ -1,5 +1,6 @@ import * as React from 'react'; import {Invite, InviteRemovalReason} from '@comapeo/core/dist/invite-api'; +import {useClientApi} from '@comapeo/core-react'; import {BottomSheetModal, useBottomSheetModal} from '../BottomSheetModal'; import { @@ -13,7 +14,6 @@ import {InviteSuccessBottomSheetContent} from './InviteSuccessBottomSheetContent import {InviteCanceledBottomSheetContent} from './InviteCanceledBottomSheetContent'; import {useAllProjects} from '../../hooks/server/projects'; import {LeaveProjectModalContent} from '../LeaveProjectModalContent'; -import {useApi} from '../../contexts/ApiContext'; export type LeaveProjectModalState = 'AlreadyOnProj' | 'LeaveProj'; @@ -169,7 +169,7 @@ export const ProjectInviteBottomSheet = ({ }; function useAcceptedInvite() { - const api = useApi(); + const api = useClientApi(); const [acceptedInvite, setAcceptedInvite] = React.useState( null, ); From 8c8b52bcce1fc60ded748b5df8ae847b1421cb2b Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Tue, 17 Dec 2024 15:41:34 -0500 Subject: [PATCH 3/7] remove comment --- src/frontend/hooks/server/maps.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/frontend/hooks/server/maps.ts b/src/frontend/hooks/server/maps.ts index fc4fcdeee..d08574dd7 100644 --- a/src/frontend/hooks/server/maps.ts +++ b/src/frontend/hooks/server/maps.ts @@ -42,7 +42,6 @@ export function useMapStyleJsonUrl() { export function useImportCustomMapFile() { const queryClient = useQueryClient(); - // const api = useApi(); const api = useClientApi(); const {refresh} = useRefreshTokenActions(); From df4b90ab2b032750e3b0d191199fe135c1093267 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Tue, 17 Dec 2024 16:49:42 -0500 Subject: [PATCH 4/7] add workaround for getting module to work with jest --- jest.config.js | 16 ++++++++++++++++ package.json | 17 ----------------- tsconfig.json | 7 +------ 3 files changed, 17 insertions(+), 23 deletions(-) create mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..78d23a9dd --- /dev/null +++ b/jest.config.js @@ -0,0 +1,16 @@ +/** @type {import("jest").Config} */ +const config = { + preset: 'jest-expo', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + setupFilesAfterEnv: ['@rnmapbox/maps/setup-jest'], + transformIgnorePatterns: [ + 'node_modules/(?!(...|@rnmapbox|(jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)', + ], + moduleNameMapper: { + // Jest seems to have issues with resolving '@comapeo/core-react' due to being a pure ESM module, + // but Metro doesn't when running the app + '^@comapeo/core-react': '/node_modules/@comapeo/core-react/dist', + }, +}; + +module.exports = config; diff --git a/package.json b/package.json index cb41f4afa..33f3512f5 100644 --- a/package.json +++ b/package.json @@ -167,23 +167,6 @@ "type-fest": "4.26.0", "typescript": "5.3.3" }, - "jest": { - "preset": "jest-expo", - "moduleFileExtensions": [ - "ts", - "tsx", - "js", - "jsx", - "json", - "node" - ], - "setupFilesAfterEnv": [ - "@rnmapbox/maps/setup-jest" - ], - "transformIgnorePatterns": [ - "node_modules/(?!(...|@rnmapbox|(jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)" - ] - }, "lint-staged": { "*.{js,ts,jsx,tsx}": "prettier --write", "src/frontend/**/*.{ts,tsx}": "npm run extract-messages" diff --git a/tsconfig.json b/tsconfig.json index c8c89cc09..884bc15fe 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,10 +5,5 @@ "noUncheckedIndexedAccess": true }, "include": ["src/frontend/**/*"], - "exclude": [ - "node_modules", - "metro.config.js", - "babel.config.js", - "jest.config.js" - ] + "exclude": ["node_modules"] } From 6a78610110d0b6af0ff09ef1d4e7ca5776c8984f Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Tue, 17 Dec 2024 16:53:08 -0500 Subject: [PATCH 5/7] revert change to tsconfig and instead use ts-check in jest config file --- jest.config.js | 2 ++ tsconfig.json | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 78d23a9dd..e24dffb38 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,3 +1,5 @@ +// @ts-check + /** @type {import("jest").Config} */ const config = { preset: 'jest-expo', diff --git a/tsconfig.json b/tsconfig.json index 884bc15fe..c8c89cc09 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,5 +5,10 @@ "noUncheckedIndexedAccess": true }, "include": ["src/frontend/**/*"], - "exclude": ["node_modules"] + "exclude": [ + "node_modules", + "metro.config.js", + "babel.config.js", + "jest.config.js" + ] } From 047aab78827673b9d7af00a6e43bba9abf083ad9 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Wed, 18 Dec 2024 13:36:58 -0500 Subject: [PATCH 6/7] upgrade to @comapeo/core-react@1.1.0 --- jest.config.js | 5 -- package-lock.json | 143 ++++++++++++++++++++-------------------------- package.json | 2 +- 3 files changed, 63 insertions(+), 87 deletions(-) diff --git a/jest.config.js b/jest.config.js index e24dffb38..27c6e4355 100644 --- a/jest.config.js +++ b/jest.config.js @@ -8,11 +8,6 @@ const config = { transformIgnorePatterns: [ 'node_modules/(?!(...|@rnmapbox|(jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)', ], - moduleNameMapper: { - // Jest seems to have issues with resolving '@comapeo/core-react' due to being a pure ESM module, - // but Metro doesn't when running the app - '^@comapeo/core-react': '/node_modules/@comapeo/core-react/dist', - }, }; module.exports = config; diff --git a/package-lock.json b/package-lock.json index ff9c280d1..5aa8e13d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "dependencies": { "@bam.tech/react-native-image-resizer": "3.0.11", - "@comapeo/core-react": "1.0.1", + "@comapeo/core-react": "1.1.0", "@comapeo/ipc": "2.1.0", "@expo-google-fonts/rubik": "0.2.3", "@formatjs/intl-getcanonicallocales": "2.5.4", @@ -167,12 +167,13 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.25.7.tgz", - "integrity": "sha512-0xZJFNE5XMpENsgfHYTw8FbX4kv53mFLn2i3XPoq69LyhYSCBJtitaHx9QnsVTrsogI4Z3+HtEfZ2/GFPOtf5g==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", "license": "MIT", "dependencies": { - "@babel/highlight": "^7.25.7", + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", "picocolors": "^1.0.0" }, "engines": { @@ -255,12 +256,13 @@ } }, "node_modules/@babel/generator": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.25.7.tgz", - "integrity": "sha512-5Dqpl5fyV9pIAD62yK9P7fcA768uVPUyrQmqpqstHWgMma4feF1x/oFysBCVZLY5wJ2GkMUCdsNDnGZrPoR6rA==", + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.3.tgz", + "integrity": "sha512-6FF/urZvD0sTeO7k6/B15pMLC4CHUv1426lzr3N01aHJTl046uCAh9LXW/fzeXXjPNCJ6iABW5XaWOsIZB93aQ==", "license": "MIT", "dependencies": { - "@babel/types": "^7.25.7", + "@babel/parser": "^7.26.3", + "@babel/types": "^7.26.3", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", "jsesc": "^3.0.2" @@ -466,28 +468,27 @@ } }, "node_modules/@babel/helper-module-imports": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.25.7.tgz", - "integrity": "sha512-o0xCgpNmRohmnoWKQ0Ij8IdddjyBFE4T2kagL/x6M3+4zUgc+4qTOUBoNe4XxDskt1HPKO007ZPiMgLDq2s7Kw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.25.9.tgz", + "integrity": "sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==", "license": "MIT", "dependencies": { - "@babel/traverse": "^7.25.7", - "@babel/types": "^7.25.7" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.25.7.tgz", - "integrity": "sha512-k/6f8dKG3yDz/qCwSM+RKovjMix563SLxQFo0UhRNo239SP6n9u5/eLtKD6EAjwta2JHJ49CsD8pms2HdNiMMQ==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.26.0.tgz", + "integrity": "sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw==", "license": "MIT", "dependencies": { - "@babel/helper-module-imports": "^7.25.7", - "@babel/helper-simple-access": "^7.25.7", - "@babel/helper-validator-identifier": "^7.25.7", - "@babel/traverse": "^7.25.7" + "@babel/helper-module-imports": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -509,7 +510,9 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.0", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.25.9.tgz", + "integrity": "sha512-kSMlyUVdWe25rEsRGviIgOWnoT/nfABVWlqt9N19/dIPWViAOW2s9wznP5tURbs/IDuNk4gPy3YdYRgH3uxhBw==", "license": "MIT", "engines": { "node": ">=6.9.0" @@ -547,19 +550,6 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/helper-simple-access": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.25.7.tgz", - "integrity": "sha512-FPGAkJmyoChQeM+ruBGIDyrT2tKfZJO8NcxdC+CWNJi7N8/rZpSxK7yvBJ5O/nF1gfu5KzN7VKG3YVSLFfRSxQ==", - "license": "MIT", - "dependencies": { - "@babel/traverse": "^7.25.7", - "@babel/types": "^7.25.7" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@babel/helper-skip-transparent-expression-wrappers": { "version": "7.22.5", "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.22.5.tgz", @@ -583,18 +573,18 @@ } }, "node_modules/@babel/helper-string-parser": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.7.tgz", - "integrity": "sha512-CbkjYdsJNHFk8uqpEkpCvRs3YRp9tY6FmFY7wLMSYuGYkrdUi7r2lc4/wqsvlHoMznX3WJ9IP8giGPq68T/Y6g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz", + "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==", "license": "MIT", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.7.tgz", - "integrity": "sha512-AM6TzwYqGChO45oiuPqwL2t20/HdMC1rTPAesnBCgPCSF1x3oN9MVUwQV2iyz4xqWrctwK5RNC8LV22kaQCNYg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", "license": "MIT", "engines": { "node": ">=6.9.0" @@ -712,12 +702,12 @@ } }, "node_modules/@babel/parser": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.25.7.tgz", - "integrity": "sha512-aZn7ETtQsjjGG5HruveUK06cU3Hljuhd9Iojm4M8WWv3wLE6OkE5PWbDUkItmMgegmccaITudyuW5RPYrYlgWw==", + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.3.tgz", + "integrity": "sha512-WJ/CvmY8Mea8iDXo6a7RK2wbmJITT5fN3BEkRuFlxVyNx8jOKIIhmC4fSkTcPcf8JyavbBwIe6OpiCOBXt/IcA==", "license": "MIT", "dependencies": { - "@babel/types": "^7.25.7" + "@babel/types": "^7.26.3" }, "bin": { "parser": "bin/babel-parser.js" @@ -1551,12 +1541,13 @@ } }, "node_modules/@babel/plugin-transform-modules-commonjs": { - "version": "7.22.11", + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.26.3.tgz", + "integrity": "sha512-MgR55l4q9KddUDITEzEFYn5ZsGDXMSsU9E+kh7fjRXTIC3RHqfCo8RPRbyReYJh44HQ/yomFkqbOFohXvDCiIQ==", "license": "MIT", "dependencies": { - "@babel/helper-module-transforms": "^7.22.9", - "@babel/helper-plugin-utils": "^7.22.5", - "@babel/helper-simple-access": "^7.22.5" + "@babel/helper-module-transforms": "^7.26.0", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2336,30 +2327,30 @@ "license": "MIT" }, "node_modules/@babel/template": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.7.tgz", - "integrity": "sha512-wRwtAgI3bAS+JGU2upWNL9lSlDcRCqD05BZ1n3X2ONLH1WilFP6O1otQjeMK/1g0pvYcXC7b/qVUB1keofjtZA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.9.tgz", + "integrity": "sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==", "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.25.7", - "@babel/parser": "^7.25.7", - "@babel/types": "^7.25.7" + "@babel/code-frame": "^7.25.9", + "@babel/parser": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.7.tgz", - "integrity": "sha512-jatJPT1Zjqvh/1FyJs6qAHL+Dzb7sTb+xr7Q+gM1b+1oBsMsQQ4FkVKb6dFlJvLlVssqkRzV05Jzervt9yhnzg==", + "version": "7.26.4", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.26.4.tgz", + "integrity": "sha512-fH+b7Y4p3yqvApJALCPJcwb0/XaOSgtK4pzV6WVjPR5GLFQBRI7pfoX2V2iM48NXvX07NUxxm1Vw98YjqTcU5w==", "license": "MIT", "dependencies": { - "@babel/code-frame": "^7.25.7", - "@babel/generator": "^7.25.7", - "@babel/parser": "^7.25.7", - "@babel/template": "^7.25.7", - "@babel/types": "^7.25.7", + "@babel/code-frame": "^7.26.2", + "@babel/generator": "^7.26.3", + "@babel/parser": "^7.26.3", + "@babel/template": "^7.25.9", + "@babel/types": "^7.26.3", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -2368,14 +2359,13 @@ } }, "node_modules/@babel/types": { - "version": "7.25.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.25.7.tgz", - "integrity": "sha512-vwIVdXG+j+FOpkwqHRcBgHLYNL7XMkufrlaFvL9o6Ai9sJn9+PdyIL5qa0XzTZw084c+u9LOls53eoZWP/W5WQ==", + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.3.tgz", + "integrity": "sha512-vN5p+1kl59GVKMvTHt55NzzmYVxprfJD+ql7U9NFIfKCBkYE55LYtS+WtPlaYOyzydrKI8Nezd+aZextrd+FMA==", "license": "MIT", "dependencies": { - "@babel/helper-string-parser": "^7.25.7", - "@babel/helper-validator-identifier": "^7.25.7", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2461,9 +2451,9 @@ } }, "node_modules/@comapeo/core-react": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@comapeo/core-react/-/core-react-1.0.1.tgz", - "integrity": "sha512-rU3r/Kd7z3Y8yK7vVXvWQrzewdDxlJ9dTBZROIPuB4mWL41wCx7OCDBONaPn++tE+KJUk9E28Btgdf9EJfwlPA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@comapeo/core-react/-/core-react-1.1.0.tgz", + "integrity": "sha512-sukKrSoXNqo5Mq4qbSkzFdtse1uXKjaEUf1p3PFhzGZ2JAfXQwBE2ad0SAfprAjLgv2NslxbMYccWXu2WPzFLw==", "license": "MIT", "peerDependencies": { "@comapeo/core": "*", @@ -27666,15 +27656,6 @@ "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", "license": "BSD-3-Clause" }, - "node_modules/to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", - "license": "MIT", - "engines": { - "node": ">=4" - } - }, "node_modules/to-readable-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/to-readable-stream/-/to-readable-stream-1.0.0.tgz", diff --git a/package.json b/package.json index 33f3512f5..67224f36f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ }, "dependencies": { "@bam.tech/react-native-image-resizer": "3.0.11", - "@comapeo/core-react": "1.0.1", + "@comapeo/core-react": "1.1.0", "@comapeo/ipc": "2.1.0", "@expo-google-fonts/rubik": "0.2.3", "@formatjs/intl-getcanonicallocales": "2.5.4", From 77a0f29f115de24f72ac2c15d6085026b4947f01 Mon Sep 17 00:00:00 2001 From: Andrew Chou Date: Wed, 18 Dec 2024 13:38:50 -0500 Subject: [PATCH 7/7] move jest config back into package.json will extract to separate file in a separate PR as it's out of scope for this PR (since I resolved the jest issue I was having) --- jest.config.js | 13 ------------- package.json | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) delete mode 100644 jest.config.js diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 27c6e4355..000000000 --- a/jest.config.js +++ /dev/null @@ -1,13 +0,0 @@ -// @ts-check - -/** @type {import("jest").Config} */ -const config = { - preset: 'jest-expo', - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], - setupFilesAfterEnv: ['@rnmapbox/maps/setup-jest'], - transformIgnorePatterns: [ - 'node_modules/(?!(...|@rnmapbox|(jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)', - ], -}; - -module.exports = config; diff --git a/package.json b/package.json index 67224f36f..cf7ce39b8 100644 --- a/package.json +++ b/package.json @@ -167,6 +167,23 @@ "type-fest": "4.26.0", "typescript": "5.3.3" }, + "jest": { + "preset": "jest-expo", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json", + "node" + ], + "setupFilesAfterEnv": [ + "@rnmapbox/maps/setup-jest" + ], + "transformIgnorePatterns": [ + "node_modules/(?!(...|@rnmapbox|(jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@sentry/react-native|native-base|react-native-svg)" + ] + }, "lint-staged": { "*.{js,ts,jsx,tsx}": "prettier --write", "src/frontend/**/*.{ts,tsx}": "npm run extract-messages"