Skip to content

Commit

Permalink
FRON-9073 Update dependencies (#69)
Browse files Browse the repository at this point in the history
* FRON-9073 Update dependencies

* FRON-9073 Update dependencies

* FRON-9073 Update dependencies

* Enabled strict mode again, fixed types to pull from zen-push

* Updated CI scripts

* Removed set-env in favour of new patterns by Gh

---------

Co-authored-by: Priyank Purohit <[email protected]>
  • Loading branch information
Uladzislau-Ustsinovich and priyank-purohit authored Jun 21, 2024
1 parent c724dfb commit e6b76dd
Show file tree
Hide file tree
Showing 14 changed files with 3,682 additions and 3,290 deletions.
45 changes: 39 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"eslint:recommended",
"airbnb",
"plugin:react/recommended",
"plugin:prettier/recommended",
"prettier/react",
"prettier/@typescript-eslint"
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -37,16 +36,50 @@

"plugins": ["@typescript-eslint", "react", "prettier", "react-hooks"],
"rules": {
"prettier/prettier": 1,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/interface-name-prefix": [1, {"prefixWithI": "never"}],
"@typescript-eslint/no-empty-interface": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/no-use-before-define": 0,
"prettier/prettier": 1,

"react/destructuring-assignment": 0,
"react/display-name": 0,
"react/jsx-filename-extension": 0, // does not like JSX in .tsx files
"react/prop-types": 0,
"no-unused-vars": 0,
"react/require-default-props": 0,

"import/extensions": 0,
"import/no-unresolved": 0,
"import/no-useless-path-segments": 0,
"import/order": 0, // wants specific import order
"import/prefer-default-export": 0,
"import/no-extraneous-dependencies": [
0,
{
"devDependencies": false,
"optionalDependencies": false,
"peerDependencies": false,
"packageDir": "./"
}
],

"arrow-body-style": 0,
"class-methods-use-this": 0,
"consistent-return": 0, // conflicts with React lifecycle methods
"max-classes-per-file": 0,
"symbol-description": 0,

"no-await-in-loop": 0,
"no-lonely-if": 0,
"no-param-reassign": 0, // immutability
"no-restricted-syntax": 0,
"no-shadow": 0,
"no-undef": 0,
"no-underscore-dangle": 0,
"no-unused-vars": 0,
"no-use-before-define": 0,
"no-console": [
"error",
{"allow": ["table", "warn", "error", "info", "group", "groupEnd"]}
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ jobs:
steps:
- name: Checkout (pull_request)
if: github.event_name == 'pull_request'
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Checkout (push)
if: github.event_name == 'push'
uses: actions/checkout@v2
- uses: actions/setup-node@v1
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm test -- --ci --coverage
- run: npm run lint
- run: yarn install
- run: yarn test -- --ci --coverage
- run: yarn run lint
- name: Set ENV for codeclimate (pull_request)
run: |
echo "::set-env name=GIT_BRANCH::${{ github.head_ref }}"
echo "::set-env name=GIT_COMMIT_SHA::$(git rev-parse HEAD)"
echo "GIT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$(git rev-parse HEAD)" >> $GITHUB_ENV
if: github.event_name == 'pull_request'
- name: Set ENV for codeclimate (push)
run: |
echo "::set-env name=GIT_BRANCH::${GITHUB_REF##*/}"
echo "::set-env name=GIT_COMMIT_SHA::$GITHUB_SHA"
echo "GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
echo "GIT_COMMIT_SHA=$GITHUB_SHA" >> $GITHUB_ENV
if: github.event_name == 'push'
- name: Code Climate Test Reporter
uses: aktions/codeclimate-test-reporter@v1
Expand All @@ -42,10 +42,10 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm run build
- run: yarn install
- run: yarn run build
14 changes: 7 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 12
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm install
- run: npm run test
- run: npm run build
- run: npm publish ./dist
- run: yarn install
- run: yarn run test
- run: yarn run build
- run: yarn publish ./dist
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 33 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"cache",
"fetch"
],
"version": "0.9.0",
"version": "1.0.0",
"main": "./dist/index.cjs.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -30,7 +30,7 @@
"test": "jest",
"lint": "eslint 'src/**/*.tsx'",
"typecheck": "tsc --noEmit",
"clean": "rimraf -r dist",
"clean": "rm -rf dist",
"prebuild": "npm run clean",
"build": "tsc",
"postbuild": "npm run bundle && npm run prepdist",
Expand All @@ -39,39 +39,43 @@
},
"dependencies": {
"typesafe-actions": "^5.1.0",
"zen-observable": "^0.8.15",
"zen-push": "^0.2.1"
"zen-observable": "^0.10.0",
"zen-push": "^0.3.1"
},
"peerDependencies": {
"react": "^16.8.0"
"react": "18.3.1"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^7.1.1",
"@testing-library/jest-dom": "^5.1.1",
"@testing-library/react": "^9.4.0",
"@testing-library/react-hooks": "^3.2.1",
"@types/hoist-non-react-statics": "^3.3.1",
"@types/jest": "^25.1.3",
"@types/zen-observable": "^0.8.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "12.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@types/hoist-non-react-statics": "^3.3.5",
"@types/jest": "^26.0.23",
"@types/zen-observable": "^0.8.7",
"@types/zen-push": "^0.1.1",
"@typescript-eslint/eslint-plugin": "^2.20.0",
"@typescript-eslint/parser": "^2.20.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^2.4.0",
"jest": "^25.1.0",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"eslint": "^7.32.0",
"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.29.4",
"eslint-plugin-react-hooks": "^4.5.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"jest-fetch-mock": "^3.0.1",
"prettier": "^1.19.1",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-test-renderer": "^16.12.0",
"rimraf": "^3.0.2",
"rollup": "^1.31.1",
"prettier": "2.6.2",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-test-renderer": "18.3.1",
"rollup": "^1.31.0",
"rollup-plugin-terser": "^5.2.0",
"rollup-plugin-typescript2": "^0.26.0",
"ts-jest": "^25.2.1",
"typescript": "^3.7.5"
}
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "29.1.4",
"typescript": "^5.1.3"
},
"packageManager": "[email protected]+sha1.ac34549e6aa8e7ead463a7407e1c7390f61a6610"
}
2 changes: 1 addition & 1 deletion src/api/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe('errors', () => {
})

api = new Api({
parseResponseJson: (response) => ({parsedError: response['test_error']})
parseResponseJson: (response) => ({parsedError: response.test_error})
})

await expect(api.request({url: '/endpoint'})).rejects.toEqual(
Expand Down
2 changes: 1 addition & 1 deletion src/api/request-fetcher/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class ApiRequestFetcher implements RequestFetcher {
}
})()

return {body: body, bodyType: responseType, status}
return {body, bodyType: responseType, status}
}

/**
Expand Down
16 changes: 8 additions & 8 deletions src/api/request-manager/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Observable from 'zen-observable'
import PushStream from 'zen-push'

import {DEFAULT_FETCH_POLICY, DEFAULT_REQUEST_METHOD} from '../constants'
Expand Down Expand Up @@ -132,14 +131,14 @@ export class ApiRequestManager {
/**
* Configuring an error handler to be called on error
*/
get onReceivedResponseBody(): Observable<[ApiRequestParams, ResponseBody]> {
get onReceivedResponseBody(): typeof this.responseBodyStream.observable {
return this.responseBodyStream.observable
}

/**
* Configuring an error handler to be called on error
*/
get onError(): Observable<Error> {
get onError(): typeof this.errorStream.observable {
return this.errorStream.observable
}

Expand Down Expand Up @@ -196,7 +195,7 @@ export class ApiRequestManager {

return responseBody
} catch (error) {
this.errorStream.next(error)
this.errorStream.next(error as Error)
throw error
}
}
Expand All @@ -207,9 +206,10 @@ export class ApiRequestManager {
* - For JSON request bodies, it is serialized to a string and
* sets the appropriate 'Content-Type' header.
*/
private getRequestHeadersAndBody(
params: ApiRequestParams
): {headers: ApiHeaders; body: BodyInit | undefined} {
private getRequestHeadersAndBody(params: ApiRequestParams): {
headers: ApiHeaders
body: BodyInit | undefined
} {
let headers: ApiHeaders = cloneHeaders(this.defaultHeaders)

if (params.headers) {
Expand Down Expand Up @@ -275,5 +275,5 @@ export class ApiRequestManager {
}

function defaultDeduplicate(params: ApiRequestParams) {
return params.method === 'GET' ? true : false
return params.method === 'GET'
}
26 changes: 14 additions & 12 deletions src/react/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ const DEFAULT_QUERY_FETCH_POLICY = 'cache-and-fetch'
const DEFAULT_QUERY_USE_ERROR_BOUNDARY = false
const DEFAULT_MUTATION_FETCH_POLICY = 'no-cache'

interface ApiContext {
api: Api
defaults: ApiProviderDefaults
}

interface ApiProviderDefaults {
useApiQuery: UseApiQueryDefaults
useApiMutation: UseApiMutationDefaults
}

interface UseApiQueryDefaults {
fetchPolicy: ApiRequestFetchPolicy
useErrorBoundary: boolean
Expand All @@ -26,9 +16,19 @@ interface UseApiMutationDefaults {
fetchPolicy: ApiRequestFetchPolicy
}

interface ApiProviderDefaults {
useApiQuery: UseApiQueryDefaults
useApiMutation: UseApiMutationDefaults
}

interface ApiContextProps {
api: Api
defaults: ApiProviderDefaults
}

const defaultApi = new Api()

const DEFAULT_API_CONTEXT: ApiContext = {
const DEFAULT_API_CONTEXT: ApiContextProps = {
api: defaultApi,
defaults: {
useApiQuery: {
Expand All @@ -41,14 +41,16 @@ const DEFAULT_API_CONTEXT: ApiContext = {
}
}

export const ApiContext = createContext<ApiContext>(DEFAULT_API_CONTEXT)
export const ApiContext = createContext<ApiContextProps>(DEFAULT_API_CONTEXT)

export interface ApiProviderProps {
/**
* The API instance to use
*/
api?: Api

children: React.ReactNode

/**
* Sets the default `fetchPolicy` which is used by `useApiQuery`
* if no `fetchPolicy` is provided to the hook.
Expand Down
2 changes: 1 addition & 1 deletion src/react/use-api-mutation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function useApiMutation<
returnValue = await mutator(mutationApiHelpers)
} catch (error) {
if (params.onError) {
return params.onError(error, {mutationArgs})
return params.onError(error as Error, {mutationArgs})
}
throw error
} finally {
Expand Down
Loading

0 comments on commit e6b76dd

Please sign in to comment.