Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .boilerplate-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fbb58dd35ba36ecc8dad791268120463b53a6815
81018841961fa40b00651c15444d45d4ca1018ce
2 changes: 1 addition & 1 deletion .github/workflows/resolve-yarn-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
resolve-yarn-lock-on-comment:
name: '/'
name: 'Resolve yarn.lock'
if: contains(github.event.comment.body, '/resolve yarn.lock')
uses: technology-studio/github-workflows/.github/workflows/_resolve-yarn-lock.yml@main
secrets: inherit
Expand Down
3 changes: 1 addition & 2 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
yarn git-hook

yarn -s lint-staged
1 change: 0 additions & 1 deletion .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
yarn commitlint --edit || exec < /dev/tty && yarn txo-cz --hook > /dev/null 2>&1 || true

12 changes: 11 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "--coverage", "false"],
"runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "--coverage", "false", "${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"name": "Debug Jest Tests with yarn",
"type": "node",
"request": "launch",
"runtimeExecutable": "yarn",
"args": ["test", "--runInBand", "--coverage=false", "${file}"],
"runtimeArgs": ["--inspect-brk"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
Expand Down
2 changes: 1 addition & 1 deletion __tests__/Setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @Copyright: Technology Studio
**/

import './Config/LogConfig'
import 'Config/LogConfig'

// Mock your external modules here if needed
// jest
Expand Down
9 changes: 9 additions & 0 deletions __tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"extends": "../tsconfig-base.json",
"compilerOptions": {
"rootDir": "../",
"baseUrl": "../",
"paths": {
"Config/*": ["./__tests__/Config/*"],
"Data/*": ["./__tests__/Data/*"],
"Utils/*": ["./__tests__/Utils/*"],
"src": ["./src"],
"src/*": ["./src/*"]
}
},
"include": [
"./**/*.ts"
Expand Down
21 changes: 21 additions & 0 deletions eslint-ci-rules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
"@typescript-eslint/no-magic-numbers",
"@typescript-eslint/no-import-type-side-effects",
"max-lines",
"@typescript-eslint/no-unnecessary-condition",
"@typescript-eslint/prefer-destructuring",
"@typescript-eslint/no-unsafe-type-assertion",
"max-nested-callbacks",
"@stylistic/space-before-function-paren",
"@stylistic/max-statements-per-line",
"@stylistic/indent-binary-ops",
"complexity",
"logical-assignment-operators",
"@typescript-eslint/max-params",
"@typescript-eslint/init-declarations",
"@stylistic/operator-linebreak",
"@stylistic/arrow-parens",
"@typescript-eslint/no-unnecessary-type-parameters",
"@typescript-eslint/no-misused-spread",
"@typescript-eslint/switch-exhaustiveness-check"
]
13 changes: 13 additions & 0 deletions eslint-ci.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const ciRules = require('./eslint-ci-rules.json')

module.exports = (async function config() {
const { default: defaultConfigPromise } = await import('./eslint.config.js')
const defaultConfig = await defaultConfigPromise
return [
...defaultConfig,
{
files: ['**/*.ts', '**/*.tsx'],
rules: ciRules.reduce((acc, rule) => ({ ...acc, [rule]: 'warn' }), {}),
},
]
})()
12 changes: 4 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const txoConfig = require('eslint-config-txo-typescript-react')

/** @type {import('eslint').Linter.FlatConfig[]} */
const config = [
...txoConfig.default,
]

module.exports = config
module.exports = (async function config() {
const txoPackageConfigList = await import('eslint-config-txo-package-react')
return txoPackageConfigList.configList
})()
9 changes: 4 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,18 @@
**/

const { pathsToModuleNameMapper } = require('ts-jest')
const { compilerOptions } = require('./tsconfig.json');
const { compilerOptions } = require('./__tests__/tsconfig.json');

const { defaults } = require('jest-config');

module.exports = {
preset: 'ts-jest',
cache: true,
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
testEnvironment: 'node',
testMatch: [
'<rootDir>/__tests__/Tests/**/?(*.)(spec|test).ts'
],
transformIgnorePatterns: [
'/node_modules/(?!@txo).+\\.js$'
],
testPathIgnorePatterns: [
'/node_modules/'
],
Expand All @@ -29,7 +28,7 @@ module.exports = {
],
transform: {
'^.+\\.tsx?$': ['ts-jest', {
tsconfig: './tsconfig.json'
tsconfig: '<rootDir>/__tests__/tsconfig.json'
}]
},
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths , { prefix: '<rootDir>/' } ),
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,23 @@
"license": "UNLICENSED",
"private": false,
"scripts": {
"build": "yarn build:clean && yarn build:lib",
"build:clean": "yarn rimraf lib",
"build:lib": "yarn tsc",
"build:watch": "yarn tsc --watch",
"test": "jest",
"test:watch": "concurrently \"yarn build:watch\" \"jest --watch\"",
"coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
"build": "yarn build:clean && yarn build:lib",
"compare-boilerplate-version": "./scripts/compare-boilerplate-version.sh",
"coverage": "jest --coverage && open coverage/lcov-report/index.html || xdg-open coverage/lcov-report/index.html",
"lint:ci": "yarn eslint -c eslint-ci.config.js --cache . && yarn txo-eslint ccr --cache",
"lint:fix": "eslint . --fix",
"lint": "eslint --max-warnings 0 .",
"fixcode": "eslint . --fix",
"git-hook": "yarn -s lint-staged",
"prepare": "husky && yarn build",
"print-txo-packages": "yarn list 2> /dev/null|grep @txo|sed 's/.*\\(@txo[^@]*\\)@^*\\([^ ]*\\).*/\\1@\\2/g'|sort|uniq",
"sanity": "yarn lint:ci && yarn build && tsc --noEmit && yarn test --coverage && yarn compare-boilerplate-version && echo 'success'",
"semantic-release": "semantic-release",
"update-boilerplate-version": "./scripts/update-boilerplate-version.sh",
"lint:ci": "yarn lint",
"type-check": "tsc --noEmit"
"test:watch": "concurrently \"yarn build:watch\" \"yarn test --watch\"",
"test": "jest",
"type-check": "tsc --noEmit",
"update-boilerplate-version": "./scripts/update-boilerplate-version.sh"
},
"engines": {
"node": ">=18.0.0"
Expand Down Expand Up @@ -65,7 +64,7 @@
"@types/react-dom": "^18.3.5",
"@types/react-native": "^0.73.0",
"concurrently": "^9.1.2",
"eslint-config-txo-typescript-react": "^2.0.82",
"eslint-config-txo-package-react": "^1.0.26",
"husky": "^9.1.7",
"jest": "^29.7.0",
"lint-staged": "^15.4.3",
Expand Down
17 changes: 9 additions & 8 deletions src/Containers/ReactNavigationInjection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@ import type {
} from '../Model/Types'
import { screenConditionConfigMap } from '../Api/ConditionManager'

// eslint-disable-next-line @typescript-eslint/no-var-requires
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-type-assertion -- we need to import the module and cast it to the correct type
const useOnActionObject = require('@react-navigation/core/src/useOnAction') as {
default: (options: UseOnActionOptions) => OnAction<NavigationAction>,
}
const originalUseOnAction = useOnActionObject.default
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { default: originalUseOnAction } = useOnActionObject
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-type-assertion -- we need to import the module and cast it to the correct type
const NavigationContainerRefContextObject = require('@react-navigation/core/src/NavigationContainerRefContext') as {
default: typeof NavigationContainerRefContextType,
}
const NavigationContainerRefContext = NavigationContainerRefContextObject.default
const { default: NavigationContainerRefContext } = NavigationContainerRefContextObject

let onActionFactory: ((onAction: OnAction<NavigationAction>) => (attributes: OnActionFactoryAttributes, ...args: Parameters<OnAction<NavigationAction>>) => boolean) | null = null
// eslint-disable-next-line @typescript-eslint/init-declarations -- we are using in two different scopes, it's not possible
let getContext: () => ConditionContext

export const registerOnActionFactory = (_onActionFactory: typeof onActionFactory, _getContext: () => ConditionContext): void => {
onActionFactory = _onActionFactory
getContext = _getContext
}

useOnActionObject.default = function useOnAction (options: UseOnActionOptions): OnAction<NavigationAction> {
useOnActionObject.default = function useOnAction(options: UseOnActionOptions): OnAction<NavigationAction> {
const onAction = originalUseOnAction(options)
const { getState, setState, router, routerConfigOptions } = options ?? {}
const { getState, setState, router, routerConfigOptions } = options
const navigationContainerRefContext = useContext(NavigationContainerRefContext)
const navigation = useContext(NavigationContext)

Expand All @@ -52,10 +53,10 @@ useOnActionObject.default = function useOnAction (options: UseOnActionOptions):
return onActionFactory(onAction)({
getContext,
getState,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- navigationContainerRefContext must be available
getRootState: () => navigationContainerRefContext!.getRootState(),
nextOnAction,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- navigation must be available
navigation: navigation!,
screenConditionConfigMap,
setState,
Expand Down
21 changes: 11 additions & 10 deletions src/Model/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ declare module '@react-navigation/routers' {
}

export type NavigationAction = | RequireConditionsNavigationAction
| NavigateNavigationAction
| BackNavigationAction
| FinishFlowAndContinueNavigationAction
| CancelFlowNavigationAction
| ValidateConditionsNavigationAction
| CloseNavigationAction

| NavigateNavigationAction
| BackNavigationAction
| FinishFlowAndContinueNavigationAction
| CancelFlowNavigationAction
| ValidateConditionsNavigationAction
| CloseNavigationAction

// eslint-disable-next-line @typescript-eslint/no-magic-numbers -- get first parameter - options
export type UseOnActionOptions = Parameters<typeof UseOnActionType>[0] & {
router: Router<NavigationState, AbstractNavigationAction>,
}
Expand Down Expand Up @@ -137,7 +138,7 @@ type NavigatePayloadOptions = {

export type NavigatePayload<PARAMS_MAP, ROUTE_NAME extends keyof PARAMS_MAP = keyof PARAMS_MAP> = ROUTE_NAME extends keyof PARAMS_MAP
? RequiredKeys<PARAMS_MAP[ROUTE_NAME]> extends never
? {
? {
routeName: ROUTE_NAME,
params?: PARAMS_MAP[ROUTE_NAME],
options?: NavigatePayloadOptions,
Expand All @@ -153,7 +154,7 @@ export type NavigatePayload<PARAMS_MAP, ROUTE_NAME extends keyof PARAMS_MAP = ke
},
options?: NavigatePayloadOptions,
}
: {
: {
routeName: ROUTE_NAME,
params: PARAMS_MAP[ROUTE_NAME],
options?: NavigatePayloadOptions,
Expand Down Expand Up @@ -208,7 +209,7 @@ export type WithConditionalNavigationState<
: { params: PARAMS & { _conditionalNavigationState?: ConditionalNavigationState } }
)

// eslint-disable-next-line @typescript-eslint/no-empty-interface
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- this is extended in the dependants
export interface ConditionContext {}

export type CustomActionHandler = () => (NavigationAction & { navigatorId: string }) | undefined | null
Expand Down
Loading
Loading