From 82d8be11f01976623ca06599af687a025f0ffe13 Mon Sep 17 00:00:00 2001 From: Mirus Date: Thu, 18 Apr 2024 16:31:14 +0300 Subject: [PATCH 1/4] feat: initial ts config and the first tsx module --- package.json | 12 ++++++--- rollup.config.mjs | 8 +++++- ...r_container.jsx => calendar_container.tsx} | 17 ++++++------ tsconfig.json | 26 +++++++++++++++++++ yarn.lock | 20 +++++++++++++- 5 files changed, 69 insertions(+), 14 deletions(-) rename src/{calendar_container.jsx => calendar_container.tsx} (67%) create mode 100644 tsconfig.json diff --git a/package.json b/package.json index 580aa30c3..10a9509fd 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", "@testing-library/react": "^15.0.0", "@types/jest": "^29.5.4", "@types/node": "20", @@ -74,7 +75,9 @@ "stylelint-config-standard": "^36.0.0", "stylelint-config-standard-scss": "^13.0.0", "stylelint-scss": "^6.2.1", - "ts-jest": "^29.1.1" + "ts-jest": "^29.1.1", + "tslib": "^2.6.2", + "typescript": "^5.4.5" }, "peerDependencies": { "react": "^16.9.0 || ^17 || ^18", @@ -98,12 +101,15 @@ "test": "NODE_ENV=test jest", "test:ci": "NODE_ENV=test jest --ci --coverage", "test:watch": "NODE_OPTIONS=--openssl-legacy-provider NODE_ENV=test jest --watch", - "build": "NODE_ENV=production yarn run build:js && NODE_ENV=production yarn run css:prod && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run css:dev && NODE_ENV=production yarn run css:modules:dev", - "build-dev": "NODE_ENV=development yarn run js:dev && NODE_ENV=development yarn run css:dev && NODE_ENV=development yarn run css:modules:dev", + "build": "NODE_ENV=production yarn run build:js && NODE_ENV=production yarn run css:prod && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run css:dev && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run build:types", + "build-dev": "NODE_ENV=development yarn run js:dev && NODE_ENV=development yarn run css:dev && NODE_ENV=development yarn run css:modules:dev && NODE_ENV=production yarn run build:types", "css:prod": "sass --style compressed src/stylesheets/datepicker.scss > dist/react-datepicker.min.css", "css:modules:prod": "sass --style compressed src/stylesheets/datepicker-cssmodules.scss | tee dist/react-datepicker-cssmodules.min.css dist/react-datepicker-min.module.css", "css:dev": "sass --style expanded src/stylesheets/datepicker.scss > dist/react-datepicker.css", "css:modules:dev": "sass --style expanded src/stylesheets/datepicker-cssmodules.scss | tee dist/react-datepicker-cssmodules.css dist/react-datepicker.module.css", + "type-check": "tsc --noEmit", + "type-check:watch": "npm run type-check -- --watch", + "build:types": "tsc --emitDeclarationOnly", "build:js": "rollup -c", "js:dev": "rollup -cw", "prepare": "husky install" diff --git a/rollup.config.mjs b/rollup.config.mjs index 8797faab2..3b8035cc4 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -8,6 +8,7 @@ import resolve from "@rollup/plugin-node-resolve"; import commonjs from "@rollup/plugin-commonjs"; import filesize from "rollup-plugin-filesize"; import terser from "@rollup/plugin-terser"; +import typescript from "@rollup/plugin-typescript"; const pkg = JSON.parse( fs @@ -95,10 +96,15 @@ const config = { plugins: [ resolve({ mainFields: ["module"], - extensions: [".js", ".jsx"], + extensions: [".js", ".jsx", ".ts", ".tsx"], }), babel(), commonjs(), + typescript({ + tsconfig: "./tsconfig.json", + declaration: true, + declarationDir: "dist", + }), filesize(), ], external: [ diff --git a/src/calendar_container.jsx b/src/calendar_container.tsx similarity index 67% rename from src/calendar_container.jsx rename to src/calendar_container.tsx index 10ea8071c..493161f55 100644 --- a/src/calendar_container.jsx +++ b/src/calendar_container.tsx @@ -1,12 +1,18 @@ -import PropTypes from "prop-types"; import React from "react"; +interface CalendarContainerProps { + showTimeSelectOnly?: boolean; + showTime?: boolean; + className?: string; + children?: React.ReactNode; +} + export default function CalendarContainer({ showTimeSelectOnly = false, showTime = false, className, children, -}) { +}: Readonly) { let ariaLabel = showTimeSelectOnly ? "Choose Time" : `Choose Date${showTime ? " and Time" : ""}`; @@ -22,10 +28,3 @@ export default function CalendarContainer({ ); } - -CalendarContainer.propTypes = { - showTimeSelectOnly: PropTypes.bool, - showTime: PropTypes.bool, - className: PropTypes.string, - children: PropTypes.node, -}; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..2cefec010 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,26 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "noFallthroughCasesInSwitch": true, + "noUnusedParameters": true, + "noUnusedLocals": true, + "declarationDir": "dist/types", + "declaration": true, + "strict": true, + "module": "esnext", + "target": "es5", + "lib": ["es6", "dom"], + "sourceMap": true, + "jsx": "react", + "moduleResolution": "node", + "rootDir": "src", + "noImplicitReturns": true, + "noImplicitThis": true, + "noImplicitAny": true, + "strictNullChecks": true, + "esModuleInterop": true, + "baseUrl": "src/" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist"] +} diff --git a/yarn.lock b/yarn.lock index 24959ad79..015302a93 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1691,7 +1691,15 @@ smob "^1.0.0" terser "^5.17.4" -"@rollup/pluginutils@^5.0.1": +"@rollup/plugin-typescript@^11.1.6": + version "11.1.6" + resolved "https://registry.yarnpkg.com/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz#724237d5ec12609ec01429f619d2a3e7d4d1b22b" + integrity sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA== + dependencies: + "@rollup/pluginutils" "^5.1.0" + resolve "^1.22.1" + +"@rollup/pluginutils@^5.0.1", "@rollup/pluginutils@^5.1.0": version "5.1.0" resolved "https://registry.yarnpkg.com/@rollup/pluginutils/-/pluginutils-5.1.0.tgz#7e53eddc8c7f483a4ad0b94afb1f7f5fd3c771e0" integrity sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g== @@ -7017,6 +7025,11 @@ ts-jest@^29.1.1: semver "^7.5.3" yargs-parser "^21.0.1" +tslib@^2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.6.2.tgz#703ac29425e7b37cd6fd456e92404d46d1f3e4ae" + integrity sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q== + tuf-js@^1.1.7: version "1.1.7" resolved "https://registry.yarnpkg.com/tuf-js/-/tuf-js-1.1.7.tgz#21b7ae92a9373015be77dfe0cb282a80ec3bbe43" @@ -7136,6 +7149,11 @@ typed-array-length@^1.0.5: is-typed-array "^1.1.13" possible-typed-array-names "^1.0.0" +typescript@^5.4.5: + version "5.4.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.4.5.tgz#42ccef2c571fdbd0f6718b1d1f5e6e5ef006f611" + integrity sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ== + unbox-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/unbox-primitive/-/unbox-primitive-1.0.2.tgz#29032021057d5e6cdbd08c5129c226dff8ed6f9e" From 45ba3c7617c0ac0475b38c70c60bc054471bc792 Mon Sep 17 00:00:00 2001 From: Mirus Date: Thu, 18 Apr 2024 16:46:20 +0300 Subject: [PATCH 2/4] feat: add lost test configs --- babel.config.js | 6 +++++- jest.config.js | 4 ++-- package.json | 3 ++- yarn.lock | 32 ++++++++++++++++++++++++++++++-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/babel.config.js b/babel.config.js index f272ad85b..aad6cd9b3 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,6 +1,10 @@ const { NODE_ENV } = process.env; -const presets = ["@babel/preset-env", "@babel/preset-react"]; +const presets = [ + "@babel/preset-typescript", + "@babel/preset-env", + "@babel/preset-react", +]; const plugins = [ "@babel/plugin-transform-react-jsx", "@babel/plugin-proposal-class-properties", diff --git a/jest.config.js b/jest.config.js index acf5eebf7..93cada21c 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,13 +4,13 @@ module.exports = { setupFilesAfterEnv: ["/test/index.js"], testEnvironment: "jest-environment-jsdom", collectCoverageFrom: [ - "**/*.{js,jsx}", + "**/*.{js,jsx, ts, tsx}", "!**/node_modules/**", "!**/vendor/**", ], transformIgnorePatterns: ["/node_modules/(?!date-fns)"], transform: { - "^.+\\.(js|jsx)$": "babel-jest", + "^.+\\.(js|jsx|ts|tsx)$": "babel-jest", "^.+\\.ts?$": "ts-jest", "node_modules/(?!date-fns/.*)": "ts-jest", }, diff --git a/package.json b/package.json index 10a9509fd..62e0a8ba3 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "@babel/plugin-proposal-class-properties": "^7.18.6", "@babel/preset-env": "^7.22.10", "@babel/preset-react": "^7.22.5", + "@babel/preset-typescript": "^7.24.1", "@react-docgen/cli": "^2.0.3", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^25.0.7", @@ -49,7 +50,7 @@ "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^11.1.6", "@testing-library/react": "^15.0.0", - "@types/jest": "^29.5.4", + "@types/jest": "^29.5.12", "@types/node": "20", "axe-core": "^4.4.1", "babel-jest": "^29.6.4", diff --git a/yarn.lock b/yarn.lock index 015302a93..6a8deb86b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -472,7 +472,7 @@ dependencies: "@babel/helper-plugin-utils" "^7.8.0" -"@babel/plugin-syntax-jsx@^7.23.3": +"@babel/plugin-syntax-jsx@^7.23.3", "@babel/plugin-syntax-jsx@^7.24.1": version "7.24.1" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz#3f6ca04b8c841811dbc3c5c5f837934e0d626c10" integrity sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA== @@ -542,6 +542,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.14.5" +"@babel/plugin-syntax-typescript@^7.24.1": + version "7.24.1" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz#b3bcc51f396d15f3591683f90239de143c076844" + integrity sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw== + dependencies: + "@babel/helper-plugin-utils" "^7.24.0" + "@babel/plugin-syntax-typescript@^7.7.2": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.22.5.tgz#aac8d383b062c5072c647a31ef990c1d0af90272" @@ -946,6 +953,16 @@ dependencies: "@babel/helper-plugin-utils" "^7.24.0" +"@babel/plugin-transform-typescript@^7.24.1": + version "7.24.4" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.24.4.tgz#03e0492537a4b953e491f53f2bc88245574ebd15" + integrity sha512-79t3CQ8+oBGk/80SQ8MN3Bs3obf83zJ0YZjDmDaEZN8MqhMI760apl5z6a20kFeMXBwJX99VpKT8CKxEBp5H1g== + dependencies: + "@babel/helper-annotate-as-pure" "^7.22.5" + "@babel/helper-create-class-features-plugin" "^7.24.4" + "@babel/helper-plugin-utils" "^7.24.0" + "@babel/plugin-syntax-typescript" "^7.24.1" + "@babel/plugin-transform-unicode-escapes@^7.24.1": version "7.24.1" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.24.1.tgz#fb3fa16676549ac7c7449db9b342614985c2a3a4" @@ -1085,6 +1102,17 @@ "@babel/plugin-transform-react-jsx-development" "^7.22.5" "@babel/plugin-transform-react-pure-annotations" "^7.24.1" +"@babel/preset-typescript@^7.24.1": + version "7.24.1" + resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.24.1.tgz#89bdf13a3149a17b3b2a2c9c62547f06db8845ec" + integrity sha512-1DBaMmRDpuYQBPWD8Pf/WEwCrtgRHxsZnP4mIy9G/X+hFfbI47Q2G4t1Paakld84+qsk2fSsUPMKg71jkoOOaQ== + dependencies: + "@babel/helper-plugin-utils" "^7.24.0" + "@babel/helper-validator-option" "^7.23.5" + "@babel/plugin-syntax-jsx" "^7.24.1" + "@babel/plugin-transform-modules-commonjs" "^7.24.1" + "@babel/plugin-transform-typescript" "^7.24.1" + "@babel/regjsgen@^0.8.0": version "0.8.0" resolved "https://registry.yarnpkg.com/@babel/regjsgen/-/regjsgen-0.8.0.tgz#f0ba69b075e1f05fb2825b7fad991e7adbb18310" @@ -1935,7 +1963,7 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jest@^29.5.4": +"@types/jest@^29.5.12": version "29.5.12" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.5.12.tgz#7f7dc6eb4cf246d2474ed78744b05d06ce025544" integrity sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw== From ac85514b703b6fc071b4658f70ab7bd55cfe87e7 Mon Sep 17 00:00:00 2001 From: Mirus Date: Thu, 18 Apr 2024 17:17:04 +0300 Subject: [PATCH 3/4] chore: add additional strict rule --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index 2cefec010..1a69dd831 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,6 +7,7 @@ "declarationDir": "dist/types", "declaration": true, "strict": true, + "noUncheckedIndexedAccess": true, "module": "esnext", "target": "es5", "lib": ["es6", "dom"], From 7a2fd9329d7fce33d51b328be9d8df73c1288566 Mon Sep 17 00:00:00 2001 From: Mirus Date: Thu, 18 Apr 2024 18:10:17 +0300 Subject: [PATCH 4/4] chore: better naming --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 62e0a8ba3..91b930e1e 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "test": "NODE_ENV=test jest", "test:ci": "NODE_ENV=test jest --ci --coverage", "test:watch": "NODE_OPTIONS=--openssl-legacy-provider NODE_ENV=test jest --watch", - "build": "NODE_ENV=production yarn run build:js && NODE_ENV=production yarn run css:prod && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run css:dev && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run build:types", + "build": "NODE_ENV=production yarn run build:src && NODE_ENV=production yarn run css:prod && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run css:dev && NODE_ENV=production yarn run css:modules:dev && NODE_ENV=production yarn run build:types", "build-dev": "NODE_ENV=development yarn run js:dev && NODE_ENV=development yarn run css:dev && NODE_ENV=development yarn run css:modules:dev && NODE_ENV=production yarn run build:types", "css:prod": "sass --style compressed src/stylesheets/datepicker.scss > dist/react-datepicker.min.css", "css:modules:prod": "sass --style compressed src/stylesheets/datepicker-cssmodules.scss | tee dist/react-datepicker-cssmodules.min.css dist/react-datepicker-min.module.css", @@ -111,7 +111,7 @@ "type-check": "tsc --noEmit", "type-check:watch": "npm run type-check -- --watch", "build:types": "tsc --emitDeclarationOnly", - "build:js": "rollup -c", + "build:src": "rollup -c", "js:dev": "rollup -cw", "prepare": "husky install" },