Skip to content

Commit e253cd3

Browse files
committed
Add TypeScript support, replace Babel with TypeScript compiler
1 parent 0c878a7 commit e253cd3

File tree

7 files changed

+353
-198
lines changed

7 files changed

+353
-198
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["@babel/env", "@babel/react"]
2+
"presets": ["@babel/typescript", "@babel/env", "@babel/react"]
33
}

.eslintrc.json

+7-1
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/**"],

index.d.ts

-35
This file was deleted.

package.json

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
"name": "react-date-picker",
33
"version": "9.2.0",
44
"description": "A date picker for your React app.",
5-
"main": "dist/index.js",
5+
"main": "dist/cjs/index.js",
6+
"module": "dist/esm/index.js",
67
"source": "src/index.js",
7-
"types": "./index.d.ts",
8+
"sideEffects": [
9+
"*.css"
10+
],
811
"scripts": {
912
"build": "yarn build-js && yarn copy-styles",
10-
"build-js": "babel src -d dist --ignore \"**/*.spec.js,**/*.spec.jsx\"",
13+
"build-js": "yarn build-js-esm && yarn build-js-cjs",
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",
1116
"clean": "rimraf dist",
1217
"copy-styles": "node ./copy-styles.mjs",
1318
"jest": "jest",
14-
"lint": "eslint . --ext .js,.jsx",
19+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
1520
"postinstall": "husky install",
1621
"prepack": "yarn clean && yarn build",
1722
"prettier": "prettier --check . --cache",
18-
"test": "yarn lint && yarn prettier && yarn jest"
23+
"test": "yarn lint && yarn tsc && yarn prettier && yarn jest",
24+
"tsc": "tsc --noEmit"
1925
},
2026
"keywords": [
2127
"calendar",
@@ -41,13 +47,16 @@
4147
"update-input-width": "^1.2.2"
4248
},
4349
"devDependencies": {
44-
"@babel/cli": "^7.15.0",
4550
"@babel/core": "^7.15.0",
4651
"@babel/preset-env": "^7.15.0",
4752
"@babel/preset-react": "^7.14.0",
53+
"@babel/preset-typescript": "^7.18.6",
4854
"@testing-library/jest-dom": "^5.15.0",
4955
"@testing-library/react": "^13.4.0",
5056
"@testing-library/user-event": "^14.4.0",
57+
"@types/jest": "^29.0.0",
58+
"@typescript-eslint/eslint-plugin": "^5.41.0",
59+
"@typescript-eslint/parser": "^5.44.0",
5160
"eslint": "^8.26.0",
5261
"eslint-config-wojtekmaj": "^0.7.1",
5362
"husky": "^8.0.0",
@@ -57,7 +66,8 @@
5766
"pretty-quick": "^3.1.0",
5867
"react": "^18.2.0",
5968
"react-dom": "^18.2.0",
60-
"rimraf": "^3.0.0"
69+
"rimraf": "^3.0.0",
70+
"typescript": "^4.9.5"
6171
},
6272
"peerDependencies": {
6373
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",

tsconfig.build.json

+4
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

+18
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)