Skip to content

Commit 8a024fe

Browse files
committed
Add TypeScript support, replace Babel with TypeScript compiler (#790)
1 parent efb10fc commit 8a024fe

File tree

7 files changed

+379
-172
lines changed

7 files changed

+379
-172
lines changed

.babelrc

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,3 @@
11
{
2-
"presets": ["@babel/env", "@babel/react"],
3-
"env": {
4-
"production-esm": {
5-
"presets": [
6-
[
7-
"@babel/env",
8-
{
9-
"modules": false
10-
}
11-
],
12-
"@babel/react"
13-
]
14-
}
15-
}
2+
"presets": ["@babel/typescript", "@babel/env", "@babel/react"]
163
}

.eslintrc.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
2-
"extends": "wojtekmaj/react-no-automatic-runtime",
2+
"extends": [
3+
"wojtekmaj/react-no-automatic-runtime",
4+
"plugin:@typescript-eslint/eslint-recommended",
5+
"plugin:@typescript-eslint/recommended"
6+
],
7+
"parser": "@typescript-eslint/parser",
8+
"plugins": ["@typescript-eslint"],
39
"overrides": [
410
{
511
"files": ["sample/**", "test/**"],

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@
1111
"scripts": {
1212
"build": "yarn build-js && yarn copy-styles",
1313
"build-js": "yarn build-js-esm && yarn build-js-cjs",
14-
"build-js-esm": "BABEL_ENV=production-esm babel src -d dist/esm --ignore \"**/*.spec.js,**/*.spec.jsx\"",
15-
"build-js-cjs": "BABEL_ENV=production-cjs babel src -d dist/cjs --ignore \"**/*.spec.js,**/*.spec.jsx\"",
14+
"build-js-esm": "tsc --project tsconfig.build.json --outDir dist/esm --module esnext",
15+
"build-js-cjs": "tsc --project tsconfig.build.json --outDir dist/cjs --module commonjs",
1616
"clean": "rimraf dist",
1717
"copy-styles": "node ./copy-styles.mjs",
1818
"jest": "jest",
19-
"lint": "eslint . --ext .js,.jsx",
19+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
2020
"postinstall": "husky install",
2121
"prepack": "yarn clean && yarn build",
2222
"prettier": "prettier --check . --cache",
23-
"test": "yarn lint && yarn prettier && yarn jest"
23+
"test": "yarn lint && yarn tsc && yarn prettier && yarn jest",
24+
"tsc": "tsc --noEmit"
2425
},
2526
"keywords": [
2627
"calendar",
@@ -35,18 +36,22 @@
3536
},
3637
"license": "MIT",
3738
"dependencies": {
39+
"@types/react": "*",
3840
"@wojtekmaj/date-utils": "^1.1.3",
3941
"clsx": "^1.2.1",
4042
"get-user-locale": "^2.1.3",
4143
"prop-types": "^15.6.0"
4244
},
4345
"devDependencies": {
44-
"@babel/cli": "^7.15.0",
4546
"@babel/core": "^7.15.0",
4647
"@babel/preset-env": "^7.15.0",
4748
"@babel/preset-react": "^7.14.0",
49+
"@babel/preset-typescript": "^7.18.6",
4850
"@testing-library/jest-dom": "^5.15.0",
4951
"@testing-library/react": "^13.4.0",
52+
"@types/jest": "^29.0.0",
53+
"@typescript-eslint/eslint-plugin": "^5.41.0",
54+
"@typescript-eslint/parser": "^5.44.0",
5055
"eslint": "^8.26.0",
5156
"eslint-config-wojtekmaj": "^0.7.1",
5257
"husky": "^8.0.0",
@@ -56,7 +61,8 @@
5661
"pretty-quick": "^3.1.0",
5762
"react": "^18.2.0",
5863
"react-dom": "^18.2.0",
59-
"rimraf": "^3.0.0"
64+
"rimraf": "^3.0.0",
65+
"typescript": "^4.9.5"
6066
},
6167
"peerDependencies": {
6268
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",

test/yarn.lock

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,31 @@ __metadata:
526526
languageName: node
527527
linkType: hard
528528

529+
"@types/prop-types@npm:*":
530+
version: 15.7.5
531+
resolution: "@types/prop-types@npm:15.7.5"
532+
checksum: 5b43b8b15415e1f298243165f1d44390403bb2bd42e662bca3b5b5633fdd39c938e91b7fce3a9483699db0f7a715d08cef220c121f723a634972fdf596aec980
533+
languageName: node
534+
linkType: hard
535+
536+
"@types/react@npm:*":
537+
version: 18.0.28
538+
resolution: "@types/react@npm:18.0.28"
539+
dependencies:
540+
"@types/prop-types": "*"
541+
"@types/scheduler": "*"
542+
csstype: ^3.0.2
543+
checksum: e752df961105e5127652460504785897ca6e77259e0da8f233f694f9e8f451cde7fa0709d4456ade0ff600c8ce909cfe29f9b08b9c247fa9b734e126ec53edd7
544+
languageName: node
545+
linkType: hard
546+
547+
"@types/scheduler@npm:*":
548+
version: 0.16.2
549+
resolution: "@types/scheduler@npm:0.16.2"
550+
checksum: b6b4dcfeae6deba2e06a70941860fb1435730576d3689225a421280b7742318d1548b3d22c1f66ab68e414f346a9542f29240bc955b6332c5b11e561077583bc
551+
languageName: node
552+
linkType: hard
553+
529554
"@vitejs/plugin-react@npm:^3.0.0":
530555
version: 3.1.0
531556
resolution: "@vitejs/plugin-react@npm:3.1.0"
@@ -769,6 +794,13 @@ __metadata:
769794
languageName: node
770795
linkType: hard
771796

797+
"csstype@npm:^3.0.2":
798+
version: 3.1.1
799+
resolution: "csstype@npm:3.1.1"
800+
checksum: 1f7b4f5fdd955b7444b18ebdddf3f5c699159f13e9cf8ac9027ae4a60ae226aef9bbb14a6e12ca7dba3358b007cee6354b116e720262867c398de6c955ea451d
801+
languageName: node
802+
linkType: hard
803+
772804
"debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.3.3":
773805
version: 4.3.4
774806
resolution: "debug@npm:4.3.4"
@@ -1572,6 +1604,7 @@ __metadata:
15721604
version: 0.0.0-use.local
15731605
resolution: "react-calendar@portal:../::locator=react-calendar-test-page%40workspace%3A."
15741606
dependencies:
1607+
"@types/react": "*"
15751608
"@wojtekmaj/date-utils": ^1.1.3
15761609
clsx: ^1.2.1
15771610
get-user-locale: ^2.1.3

tsconfig.build.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"exclude": ["src/**/*.spec.js", "src/**/*.spec.jsx", "src/**/*.spec.ts", "src/**/*.spec.tsx"]
4+
}

tsconfig.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"compilerOptions": {
3+
"allowJs": true,
4+
"declaration": false,
5+
"downlevelIteration": true,
6+
"esModuleInterop": true,
7+
"importsNotUsedAsValues": "error",
8+
"isolatedModules": true,
9+
"jsx": "react",
10+
"moduleResolution": "node",
11+
"noUncheckedIndexedAccess": true,
12+
"outDir": "dist",
13+
"strict": true,
14+
"strictNullChecks": true,
15+
"target": "es5"
16+
},
17+
"include": ["src"]
18+
}

0 commit comments

Comments
 (0)