Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to TS 5 #8937

Merged
merged 4 commits into from
Jun 23, 2023
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
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@

{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"warnOnUnsupportedTypeScriptVersion": false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use version 5.1.3 when latest supported is 5.1.0. It will be supported soon but we're safe anyway

},
"extends": ["react-app", "plugin:prettier/recommended"],
"plugins": [
"@typescript-eslint",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMI, why did you disable this plugin?

Expand Down
2 changes: 1 addition & 1 deletion cypress/start.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const cypress = require('cypress');
const server = require('./server');

return server.start().then(listeningServer => {
server.start().then(listeningServer => {
// kick off a cypress run
return cypress
.run({
Expand Down
4 changes: 2 additions & 2 deletions examples/crm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"@types/faker": "^5.1.7",
"@types/jest": "^26.0.19",
"@types/jest": "^29.5.2",
"@types/lodash": "~4.14.168",
"@types/react": "^17.0.20",
"@types/react-beautiful-dnd": "^13.0.0",
"@types/react-dom": "^17.0.9",
"@vitejs/plugin-react": "^2.2.0",
"source-map-explorer": "^2.0.0",
"typescript": "^4.4.0",
"typescript": "^5.1.3",
"vite": "^3.2.0",
"web-vitals": "^1.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/data-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cross-env": "^5.2.0",
"ra-core": "^4.11.3",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"peerDependencies": {
"ra-core": "^4.0.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@
},
"devDependencies": {
"@types/fetch-mock": "^7.3.2",
"@types/jest": "^26.0.19",
"@types/jest": "^29.5.2",
"@types/node": "^12.12.14",
"@types/prop-types": "^15.6.0",
"@types/react": "^17.0.20",
"@types/react-dom": "^17.0.9",
"@vitejs/plugin-react": "^2.2.0",
"rewire": "^5.0.0",
"source-map-explorer": "^2.0.0",
"typescript": "^4.4.0",
"typescript": "^5.1.3",
"vite": "^3.2.0"
}
}
2 changes: 1 addition & 1 deletion examples/no-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"@vitejs/plugin-react": "^2.2.0",
"typescript": "^4.4.0",
"typescript": "^5.1.3",
"vite": "^3.2.0"
},
"gitHead": "6eb0f6fcbe3ba237b507f3506d230b3445c0a764"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@hookform/devtools": "^4.0.2",
"@vitejs/plugin-react": "^2.2.0",
"react-app-polyfill": "^1.0.4",
"typescript": "^4.4.0",
"typescript": "^5.1.3",
"vite": "^3.2.0"
}
}
2 changes: 1 addition & 1 deletion examples/tutorial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/react": "^18.0.22",
"@types/react-dom": "^18.0.7",
"@vitejs/plugin-react": "^2.2.0",
"typescript": "^4.6.4",
"typescript": "^5.1.3",
"vite": "^3.2.0"
}
}
21 changes: 13 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ const fs = require('fs');

const packages = fs.readdirSync(path.resolve(__dirname, './packages'));
const moduleNameMapper = packages.reduce((mapper, dirName) => {
const package = require(path.resolve(
const pkg = require(path.resolve(
__dirname,
'./packages',
dirName,
'package.json'
));
mapper[`^${package.name}(.*)$`] = path.join(
mapper[`^${pkg.name}(.*)$`] = path.join(
__dirname,
`./packages/${dirName}/src$1`
);
Expand All @@ -19,20 +19,25 @@ const moduleNameMapper = packages.reduce((mapper, dirName) => {
module.exports = {
globalSetup: './test-global-setup.js',
setupFilesAfterEnv: ['./test-setup.js'],
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'jsdom',
testPathIgnorePatterns: [
'/node_modules/',
'/lib/',
'/esm/',
'/examples/simple/',
],
transformIgnorePatterns: [
'[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|ts|tsx)$',
'[/\\\\]node_modules[/\\\\](?!(@hookform)/).+\\.(js|jsx|mjs|ts|tsx)$',
],
globals: {
'ts-jest': {
isolatedModules: true,
},
transform: {
// '^.+\\.[tj]sx?$' to process js/ts with `ts-jest`
'^.+\\.[tj]sx?$': [
'ts-jest',
{
isolatedModules: true,
useESM: true,
},
],
},
moduleNameMapper,
};
26 changes: 16 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,36 @@
"@storybook/react": "^7.0.12",
"@storybook/react-webpack5": "^7.0.12",
"@storybook/testing-react": "^2.0.0",
"@types/jest": "^26.0.19",
"@types/jest": "^29.5.2",
"@types/react": "^17.0.20",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"concurrently": "^5.1.0",
"cross-env": "^5.2.0",
"eslint": "^8.19.0",
"eslint-config-prettier": "^8.5.0",
"eslint-config-react-app": "^7.0.1",
"eslint-plugin-cypress": "^2.12.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-testing-library": "^5.11.0",
"full-icu": "~1.3.1",
"global-jsdom": "^9.0.1",
"husky": "^2.3.0",
"jest": "26.6.0",
"jest-circus": "26.6.0",
"jest-resolve": "26.6.0",
"jest-watch-typeahead": "0.6.1",
"lerna": "~5.5.2",
"jest": "^29.5.0",
"jest-circus": "29.5.0",
"jest-environment-jsdom": "^29.5.0",
"jest-resolve": "29.5.0",
"jest-watch-typeahead": "2.2.2",
"lerna": "~7.0.2",
"lint-staged": "^13.0.3",
"lolex": "~2.3.2",
"prettier": "~2.1.1",
"raf": "~3.4.1",
"react": "^17.0.0",
"react-dom": "^17.0.0",
"storybook": "^7.0.12",
"ts-jest": "^26.4.4",
"typescript": "^4.4.0",
"ts-jest": "^29.1.0",
"typescript": "^5.1.3",
"wait-on": "^3.2.0",
"whatwg-fetch": "^3.0.0"
},
Expand All @@ -75,6 +78,9 @@
}
},
"resolutions": {
"@typescript-eslint/typescript-estree": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"@typescript-eslint/eslint-plugin": "^5.60.0",
Comment on lines +81 to +83
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required because of eslint-config-react-app which has not been updated in 2 years. We would probably be better of with our own config

"minimist": "^1.2.6",
"ejs": "^3.1.7"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-react-admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"devDependencies": {
"@types/react": ">=17.0.0",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"gitHead": "e936ff2c3f887d2e98ef136cf3b3f3d254725fc4"
}
4 changes: 2 additions & 2 deletions packages/ra-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@hookform/resolvers": "^2.8.8",
"@testing-library/react": "^11.2.3",
"@testing-library/react-hooks": "^7.0.2",
"@types/jest": "^26.0.19",
"@types/jest": "^29.5.2",
"@types/node": "^17.0.8",
"@types/node-polyglot": "^0.4.31",
"@types/react": "^17.0.20",
Expand All @@ -45,7 +45,7 @@
"react-test-renderer": "^16.9.0 || ^17.0.0",
"recharts": "^2.1.15",
"rimraf": "^3.0.2",
"typescript": "^4.4.0",
"typescript": "^5.1.3",
"yup": "^0.32.11"
},
"peerDependencies": {
Expand Down
45 changes: 20 additions & 25 deletions packages/ra-core/src/core/Resource.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
import * as React from 'react';
import { isValidElement } from 'react';
import { ComponentType, ReactElement, isValidElement } from 'react';
import { Route, Routes } from 'react-router-dom';
import { isValidElementType } from 'react-is';

import { ResourceProps } from '../types';
import { ResourceContextProvider } from './ResourceContextProvider';

export const Resource = (props: ResourceProps) => {
const { create: Create, edit: Edit, list: List, name, show: Show } = props;
const { create, edit, list, name, show } = props;

return (
<ResourceContextProvider value={name}>
<Routes>
{Create && (
<Route
path="create/*"
element={isValidElement(Create) ? Create : <Create />}
/>
)}
{Show && (
<Route
path=":id/show/*"
element={isValidElement(Show) ? Show : <Show />}
/>
)}
{Edit && (
<Route
path=":id/*"
element={isValidElement(Edit) ? Edit : <Edit />}
/>
)}
{List && (
<Route
path="/*"
element={isValidElement(List) ? List : <List />}
/>
{create && (
<Route path="create/*" element={getElement(create)} />
)}
{show && <Route path=":id/show/*" element={getElement(show)} />}
{edit && <Route path=":id/*" element={getElement(edit)} />}
{list && <Route path="/*" element={getElement(list)} />}
{props.children}
</Routes>
</ResourceContextProvider>
);
};

const getElement = (ElementOrComponent: ComponentType<any> | ReactElement) => {
if (isValidElement(ElementOrComponent)) {
return ElementOrComponent;
}

if (isValidElementType(ElementOrComponent)) {
return <ElementOrComponent />;
}

return null;
};

Resource.raName = 'Resource';

Resource.registerResource = ({
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-data-fakerest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"cross-env": "^5.2.0",
"ra-core": "^4.11.3",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"peerDependencies": {
"ra-core": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-data-graphql-simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"cross-env": "^5.2.0",
"graphql": "^15.6.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"gitHead": "65189b7cea65cc57190f41f77b84fdb290b68e29"
}
2 changes: 1 addition & 1 deletion packages/ra-data-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"cross-env": "^5.2.0",
"graphql": "^15.6.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"gitHead": "65189b7cea65cc57190f41f77b84fdb290b68e29"
}
2 changes: 1 addition & 1 deletion packages/ra-data-json-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"cross-env": "^5.2.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"gitHead": "e936ff2c3f887d2e98ef136cf3b3f3d254725fc4"
}
2 changes: 1 addition & 1 deletion packages/ra-data-localforage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"devDependencies": {
"cross-env": "^5.2.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"peerDependencies": {
"ra-core": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-data-localstorage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"devDependencies": {
"cross-env": "^5.2.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"peerDependencies": {
"ra-core": "*"
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-data-simple-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"cross-env": "^5.2.0",
"ra-core": "^4.11.3",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"peerDependencies": {
"ra-core": "^4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-i18n-polyglot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"cross-env": "^5.2.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"gitHead": "e936ff2c3f887d2e98ef136cf3b3f3d254725fc4"
}
2 changes: 1 addition & 1 deletion packages/ra-input-rich-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"react-dom": "^17.0.0",
"react-hook-form": "^7.43.9",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"gitHead": "e936ff2c3f887d2e98ef136cf3b3f3d254725fc4"
}
2 changes: 1 addition & 1 deletion packages/ra-language-english/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"keywords": [
"react",
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-language-french/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"keywords": [
"react",
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-no-code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"react-router": "^6.1.0",
"react-router-dom": "^6.1.0",
"rimraf": "^3.0.2",
"typescript": "^4.4.0"
"typescript": "^5.1.3"
},
"peerDependencies": {
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
Expand Down
Loading