From b4646323ac0f6430f424e11207fc4a92037cc43f Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 9 Oct 2023 13:55:44 -0400 Subject: [PATCH 01/19] [webpack-build-scripts] feat: migrate to swc --- packages/eslint-plugin/package.json | 4 +- packages/node-build-scripts/package.json | 2 +- packages/webpack-build-scripts/package.json | 9 +- .../webpack.config.base.mjs | 36 ++-- .../webpack.config.karma.mjs | 21 +- yarn.lock | 192 +++++++++--------- 6 files changed, 145 insertions(+), 119 deletions(-) diff --git a/packages/eslint-plugin/package.json b/packages/eslint-plugin/package.json index 2a91354a99..efe8fccb1e 100644 --- a/packages/eslint-plugin/package.json +++ b/packages/eslint-plugin/package.json @@ -17,8 +17,8 @@ }, "devDependencies": { "@blueprintjs/node-build-scripts": "^8.0.3", - "@swc-node/register": "^1.6.7", - "@swc/core": "^1.3.80", + "@swc-node/register": "^1.6.8", + "@swc/core": "^1.3.92", "@types/dedent": "~0.7.0", "@typescript-eslint/rule-tester": "^6.7.4", "dedent": "^1.5.1", diff --git a/packages/node-build-scripts/package.json b/packages/node-build-scripts/package.json index 104926b69e..b1b45bf599 100644 --- a/packages/node-build-scripts/package.json +++ b/packages/node-build-scripts/package.json @@ -47,7 +47,7 @@ }, "devDependencies": { "@jest/globals": "^29.7.0", - "@swc/core": "^1.3.80", + "@swc/core": "^1.3.92", "@swc/jest": "^0.2.29", "@types/fs-extra": "~11.0.2", "@types/pkg-up": "^3.1.0", diff --git a/packages/webpack-build-scripts/package.json b/packages/webpack-build-scripts/package.json index 14e7d13100..d99509085b 100644 --- a/packages/webpack-build-scripts/package.json +++ b/packages/webpack-build-scripts/package.json @@ -12,7 +12,8 @@ }, "dependencies": { "@blueprintjs/node-build-scripts": "^8.0.3", - "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", + "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11", + "@swc/core": "^1.3.92", "assert": "^2.0.0", "autoprefixer": "^10.4.14", "css-loader": "^6.8.1", @@ -32,10 +33,10 @@ "source-map-loader": "^4.0.1", "stream-browserify": "^3.0.0", "style-loader": "^3.3.3", + "swc-loader": "^0.2.3", "terser-webpack-plugin": "^5.3.9", - "ts-loader": "^9.4.3", - "webpack": "^5.88.0", - "webpack-bundle-analyzer": "^4.9.0", + "webpack": "^5.88.2", + "webpack-bundle-analyzer": "^4.9.1", "webpack-dev-server": "^4.15.1", "webpack-notifier": "^1.15.0" }, diff --git a/packages/webpack-build-scripts/webpack.config.base.mjs b/packages/webpack-build-scripts/webpack.config.base.mjs index fc6ab91177..49e8d73fc8 100644 --- a/packages/webpack-build-scripts/webpack.config.base.mjs +++ b/packages/webpack-build-scripts/webpack.config.base.mjs @@ -24,7 +24,6 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin"; import { createRequire } from "node:module"; import { resolve } from "node:path"; import { cwd, env } from "node:process"; -import ReactRefreshTypeScript from "react-refresh-typescript"; import TerserPlugin from "terser-webpack-plugin"; import webpack from "webpack"; import WebpackNotifierPlugin from "webpack-notifier"; @@ -33,6 +32,10 @@ import { sassNodeModulesLoadPaths } from "@blueprintjs/node-build-scripts"; import { getPackageName } from "./utils.mjs"; +// import.meta.resolve is still experimental under a CLI flag, so we create a require fn instead +// see https://nodejs.org/docs/latest-v18.x/api/esm.html#importmetaresolvespecifier-parent +const require = createRequire(import.meta.url); + // globals const IS_PRODUCTION = env.NODE_ENV === "production"; const DEV_PORT = env.PORT || 9001; @@ -80,10 +83,6 @@ if (!IS_PRODUCTION) { ); } -// import.meta.resolve is still experimental under a CLI flag, so we create a require fn instead -// see https://nodejs.org/docs/latest-v16.x/api/esm.html#importmetaresolvespecifier-parent -const require = createRequire(import.meta.url); - // Module loaders for CSS files, used in reverse order: apply PostCSS, then interpret CSS as ES modules const cssLoaders = [ // Only extract CSS to separate file in production mode. @@ -148,7 +147,8 @@ export default { open: false, port: DEV_PORT, static: { - directory: resolve(cwd(), "src"), + // N.B. it is important to exclude TS sources from this directory allow hot module replacement to work + directory: resolve(cwd(), "src", "assets"), }, }, @@ -162,13 +162,25 @@ export default { }, { test: /\.tsx?$/, - loader: require.resolve("ts-loader"), + loader: require.resolve("swc-loader"), + exclude: /(node_modules)/, options: { - configFile: "src/tsconfig.json", - getCustomTransformers: () => ({ - before: IS_PRODUCTION ? [] : [ReactRefreshTypeScript()], - }), - transpileOnly: !IS_PRODUCTION, + jsc: { + parser: { + decorators: true, + dynamicImport: true, + syntax: "typescript", + tsx: true, + }, + transform: { + legacyDecorator: true, + react: { + refresh: !IS_PRODUCTION, + runtime: "classic", + useBuiltins: true, + }, + }, + }, }, }, { diff --git a/packages/webpack-build-scripts/webpack.config.karma.mjs b/packages/webpack-build-scripts/webpack.config.karma.mjs index c3873a67b9..80793c2468 100644 --- a/packages/webpack-build-scripts/webpack.config.karma.mjs +++ b/packages/webpack-build-scripts/webpack.config.karma.mjs @@ -12,7 +12,7 @@ import webpack from "webpack"; import { sassNodeModulesLoadPaths } from "@blueprintjs/node-build-scripts"; // import.meta.resolve is still experimental under a CLI flag, so we create a require fn instead -// see https://nodejs.org/docs/latest-v16.x/api/esm.html#importmetaresolvespecifier-parent +// see https://nodejs.org/docs/latest-v18.x/api/esm.html#importmetaresolvespecifier-parent const require = createRequire(import.meta.url); /** @@ -41,10 +41,23 @@ export default { }, { test: /\.tsx?$/, - loader: require.resolve("ts-loader"), + loader: require.resolve("swc-loader"), options: { - configFile: "test/tsconfig.json", - transpileOnly: true, + jsc: { + parser: { + decorators: true, + dynamicImport: true, + syntax: "typescript", + tsx: true, + }, + transform: { + legacyDecorator: true, + react: { + refresh: false, + useBuiltins: true, + }, + }, + }, }, }, { diff --git a/yarn.lock b/yarn.lock index 7e6279d409..8441ce570e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1347,7 +1347,7 @@ picocolors "^1.0.0" tslib "^2.6.0" -"@pmmmwh/react-refresh-webpack-plugin@^0.5.10": +"@pmmmwh/react-refresh-webpack-plugin@^0.5.11": version "0.5.11" resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.11.tgz#7c2268cedaa0644d677e8c4f377bc8fb304f714a" integrity sha512-7j/6vdTym0+qZ6u4XbSAxrWBGYSdCfTzySkj7WAFgDLmSyWlOrWvpyzxlFh5jtw9dn0oL/jtW+06XfFiisN3JQ== @@ -1446,17 +1446,17 @@ resolved "https://registry.yarnpkg.com/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz#96116f2a912e0c02817345b3c10751069920d553" integrity sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg== -"@swc-node/core@^1.10.5": - version "1.10.5" - resolved "https://registry.yarnpkg.com/@swc-node/core/-/core-1.10.5.tgz#eb9678c020ee128db08506147eb7794d83315609" - integrity sha512-G+Me0sTApMy6WY9mT0TluFxdO633P1GWMllbT3LWeJlknqQxJo8dAQcV0Uc0+rvBVXt7rRo/BMUZNJp88qarzg== +"@swc-node/core@^1.10.6": + version "1.10.6" + resolved "https://registry.yarnpkg.com/@swc-node/core/-/core-1.10.6.tgz#5c2af68bd4c9c8f5d91178a724af341a4402f5b6" + integrity sha512-lDIi/rPosmKIknWzvs2/Fi9zWRtbkx8OJ9pQaevhsoGzJSal8Pd315k1W5AIrnknfdAB4HqRN12fk6AhqnrEEw== -"@swc-node/register@^1.6.7": - version "1.6.7" - resolved "https://registry.yarnpkg.com/@swc-node/register/-/register-1.6.7.tgz#e67690d37ffa7d7d9a935fc6bedc909d56031794" - integrity sha512-+Tccbb4+fN8vYx88fdEGFbsCSnF0zBxbVhZkYkFAbVI7h6zVIgA3Jmlok4ZM+q+1KxzPN7AOfhQVuFOYBzZBeA== +"@swc-node/register@^1.6.8": + version "1.6.8" + resolved "https://registry.yarnpkg.com/@swc-node/register/-/register-1.6.8.tgz#4e2402b42ae5b538d5041e0c4d86d9c3c8d5b323" + integrity sha512-74ijy7J9CWr1Z88yO+ykXphV29giCrSpANQPQRooE0bObpkTO1g4RzQovIfbIaniBiGDDVsYwDoQ3FIrCE8HcQ== dependencies: - "@swc-node/core" "^1.10.5" + "@swc-node/core" "^1.10.6" "@swc-node/sourcemap-support" "^0.3.0" colorette "^2.0.19" debug "^4.3.4" @@ -1471,73 +1471,79 @@ source-map-support "^0.5.21" tslib "^2.5.0" -"@swc/core-darwin-arm64@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.80.tgz#18be1879ffc0a871a7397ccccf8a80278a794d60" - integrity sha512-rhoFTcQMUGfO7IkfOnopPSF6O0/aVJ58B7KueIKbvrMe6YvSfFj9QfObELFjYCcrJZTvUWBhig0QrsfPIiUphA== - -"@swc/core-darwin-x64@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.80.tgz#83413aed20751e836139be0aa2f6f419850bad41" - integrity sha512-0dOLedFpVXe+ugkKHXsqSxMKqvQYfFtibWbrZ7j8wOaErzSGPr0VpyWvepNVb9s046725kPXSw+fsGhqZR8wrw== - -"@swc/core-linux-arm-gnueabihf@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.80.tgz#caa6608103dfce820d071ca59cd52617e0c96804" - integrity sha512-QIjwP3PtDeHBDkwF6+ZZqdUsqAhORbMpxrw2jq3mHe4lQrxBttSFTq018vlMRo2mFEorOvXdadzaD9m+NymPrw== - -"@swc/core-linux-arm64-gnu@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.80.tgz#0ec3962eb196cc5f99b8540f89fafb75366092ce" - integrity sha512-cg8WriIueab58ZwkzXmIACnjSzFLzOBwxlC9k65gPXMNgCjab2YbqEYvAbjBqneuqaao02gW6tad2uhjgYaExw== - -"@swc/core-linux-arm64-musl@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.80.tgz#4c2f58fb10b6d163bf22ab517a3afacd7016d670" - integrity sha512-AhdCQ7QKx5mWrtpaOA1mFRiWWvuiiUtspvo0QSpspDetRKTND1rlf/3UB5+gp0kCeCNUTsVmJWU7fIA9ICZtXA== - -"@swc/core-linux-x64-gnu@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.80.tgz#de94d37953d46ac2321b96c35849beffaed60beb" - integrity sha512-+2e5oni1vOrLIjM5Q2/GIzK/uS2YEtuJqnjPvCK8SciRJsSl8OgVsRvyCDbmKeZNtJ2Q+o/O2AQ2w1qpAJG6jg== - -"@swc/core-linux-x64-musl@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.80.tgz#30e7dd46f30a8027bc6864c10666a98003f715ab" - integrity sha512-8OK9IlI1zpWOm7vIp1iXmZSEzLAwFpqhsGSEhxPavpOx2m54kLFdPcw/Uv3n461f6TCtszIxkGq1kSqBUdfUBA== - -"@swc/core-win32-arm64-msvc@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.80.tgz#cab6e1140c19b3576204da995f6dd719d6bb7417" - integrity sha512-RKhatwiAGlffnF6z2Mm3Ddid0v3KB+uf5m/Gc7N9zO/EUAV0PnHRuYuZSGyqodHmGFC+mK8YrCooFCEmHL9n+w== - -"@swc/core-win32-ia32-msvc@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.80.tgz#3da4715e77c6f1559a3a76cca80fddee9aa100fc" - integrity sha512-3jiiZzU/kaw7k4zUp1yMq1QiUe4wJVtCEXIhf+fKuBsIwm7rdvyK/+PIx5KHnZy4TGQnYczKBRhJA5nuBcrUCQ== - -"@swc/core-win32-x64-msvc@1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.80.tgz#2693dd16176b181f440127c822f7006ffba8d3ad" - integrity sha512-2eZtIoIWQBWqykfms92Zd37lveYOBWQTZjdooBGlsLHtcoQLkNpf1NXmR6TKY0yy8q6Yl3OhPvY+izjmO08MSg== - -"@swc/core@^1.3.80": - version "1.3.80" - resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.80.tgz#364570b0cd5bba7ff686888558bbfd6423317310" - integrity sha512-yX2xV5I/lYswHHR+44TPvzBgq3/Y8N1YWpTQADYuvSiX3Jxyvemk5Jpx3rRtigYb8WBkWAAf2i5d5ZJ2M7hhgw== - dependencies: - "@swc/types" "^0.1.3" +"@swc/core-darwin-arm64@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-darwin-arm64/-/core-darwin-arm64-1.3.92.tgz#0498d3584cf877e39107c94705c38fa4a8c04789" + integrity sha512-v7PqZUBtIF6Q5Cp48gqUiG8zQQnEICpnfNdoiY3xjQAglCGIQCjJIDjreZBoeZQZspB27lQN4eZ43CX18+2SnA== + +"@swc/core-darwin-x64@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-darwin-x64/-/core-darwin-x64-1.3.92.tgz#1728e7ebbfe37b56c07d99e29dde78bfa90cf8d1" + integrity sha512-Q3XIgQfXyxxxms3bPN+xGgvwk0TtG9l89IomApu+yTKzaIIlf051mS+lGngjnh9L0aUiCp6ICyjDLtutWP54fw== + +"@swc/core-linux-arm-gnueabihf@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm-gnueabihf/-/core-linux-arm-gnueabihf-1.3.92.tgz#6f7c20833b739f8911c936c9783976ded2c449dc" + integrity sha512-tnOCoCpNVXC+0FCfG84PBZJyLlz0Vfj9MQhyhCvlJz9hQmvpf8nTdKH7RHrOn8VfxtUBLdVi80dXgIFgbvl7qA== + +"@swc/core-linux-arm64-gnu@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-gnu/-/core-linux-arm64-gnu-1.3.92.tgz#bb01dd9b922b0c076c38924013bd10036ce39c7c" + integrity sha512-lFfGhX32w8h1j74Iyz0Wv7JByXIwX11OE9UxG+oT7lG0RyXkF4zKyxP8EoxfLrDXse4Oop434p95e3UNC3IfCw== + +"@swc/core-linux-arm64-musl@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-arm64-musl/-/core-linux-arm64-musl-1.3.92.tgz#0070165eed2805475c98eb732bab8bdca955932e" + integrity sha512-rOZtRcLj57MSAbiecMsqjzBcZDuaCZ8F6l6JDwGkQ7u1NYR57cqF0QDyU7RKS1Jq27Z/Vg21z5cwqoH5fLN+Sg== + +"@swc/core-linux-x64-gnu@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-gnu/-/core-linux-x64-gnu-1.3.92.tgz#d9785f93b9121eeef0f54e8d845dd216698e0115" + integrity sha512-qptoMGnBL6v89x/Qpn+l1TH1Y0ed+v0qhNfAEVzZvCvzEMTFXphhlhYbDdpxbzRmCjH6GOGq7Y+xrWt9T1/ARg== + +"@swc/core-linux-x64-musl@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-linux-x64-musl/-/core-linux-x64-musl-1.3.92.tgz#8fe5cf244695bf4f0bc7dc7df450a9bd1bfccc2b" + integrity sha512-g2KrJ43bZkCZHH4zsIV5ErojuV1OIpUHaEyW1gf7JWKaFBpWYVyubzFPvPkjcxHGLbMsEzO7w/NVfxtGMlFH/Q== + +"@swc/core-win32-arm64-msvc@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-win32-arm64-msvc/-/core-win32-arm64-msvc-1.3.92.tgz#d6150785455c813a8e62f4e4b0a22773baf398eb" + integrity sha512-3MCRGPAYDoQ8Yyd3WsCMc8eFSyKXY5kQLyg/R5zEqA0uthomo0m0F5/fxAJMZGaSdYkU1DgF73ctOWOf+Z/EzQ== + +"@swc/core-win32-ia32-msvc@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-win32-ia32-msvc/-/core-win32-ia32-msvc-1.3.92.tgz#8142166bceafbaa209d440b36fdc8cd4b4f82768" + integrity sha512-zqTBKQhgfWm73SVGS8FKhFYDovyRl1f5dTX1IwSKynO0qHkRCqJwauFJv/yevkpJWsI2pFh03xsRs9HncTQKSA== + +"@swc/core-win32-x64-msvc@1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core-win32-x64-msvc/-/core-win32-x64-msvc-1.3.92.tgz#4ba542875fc690b579232721ccec7873e139646a" + integrity sha512-41bE66ddr9o/Fi1FBh0sHdaKdENPTuDpv1IFHxSg0dJyM/jX8LbkjnpdInYXHBxhcLVAPraVRrNsC4SaoPw2Pg== + +"@swc/core@^1.3.92": + version "1.3.92" + resolved "https://registry.yarnpkg.com/@swc/core/-/core-1.3.92.tgz#f51808cdb6cbb90b0877b9a51806eea9a70eafca" + integrity sha512-vx0vUrf4YTEw59njOJ46Ha5i0cZTMYdRHQ7KXU29efN1MxcmJH2RajWLPlvQarOP1ab9iv9cApD7SMchDyx2vA== + dependencies: + "@swc/counter" "^0.1.1" + "@swc/types" "^0.1.5" optionalDependencies: - "@swc/core-darwin-arm64" "1.3.80" - "@swc/core-darwin-x64" "1.3.80" - "@swc/core-linux-arm-gnueabihf" "1.3.80" - "@swc/core-linux-arm64-gnu" "1.3.80" - "@swc/core-linux-arm64-musl" "1.3.80" - "@swc/core-linux-x64-gnu" "1.3.80" - "@swc/core-linux-x64-musl" "1.3.80" - "@swc/core-win32-arm64-msvc" "1.3.80" - "@swc/core-win32-ia32-msvc" "1.3.80" - "@swc/core-win32-x64-msvc" "1.3.80" + "@swc/core-darwin-arm64" "1.3.92" + "@swc/core-darwin-x64" "1.3.92" + "@swc/core-linux-arm-gnueabihf" "1.3.92" + "@swc/core-linux-arm64-gnu" "1.3.92" + "@swc/core-linux-arm64-musl" "1.3.92" + "@swc/core-linux-x64-gnu" "1.3.92" + "@swc/core-linux-x64-musl" "1.3.92" + "@swc/core-win32-arm64-msvc" "1.3.92" + "@swc/core-win32-ia32-msvc" "1.3.92" + "@swc/core-win32-x64-msvc" "1.3.92" + +"@swc/counter@^0.1.1": + version "0.1.2" + resolved "https://registry.yarnpkg.com/@swc/counter/-/counter-0.1.2.tgz#bf06d0770e47c6f1102270b744e17b934586985e" + integrity sha512-9F4ys4C74eSTEUNndnER3VJ15oru2NumfQxS8geE+f3eB5xvfxpWyqE5XlVnxb/R14uoXi6SLbBwwiDSkv+XEw== "@swc/jest@^0.2.29": version "0.2.29" @@ -1547,10 +1553,10 @@ "@jest/create-cache-key-function" "^27.4.2" jsonc-parser "^3.2.0" -"@swc/types@^0.1.3": - version "0.1.4" - resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.4.tgz#8d647e111dc97a8e2881bf71c2ee2d011698ff10" - integrity sha512-z/G02d+59gyyUb7KYhKi9jOhicek6QD2oMaotUyG+lUkybpXoV49dY9bj7Ah5Q+y7knK2jU67UTX9FyfGzaxQg== +"@swc/types@^0.1.5": + version "0.1.5" + resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.5.tgz#043b731d4f56a79b4897a3de1af35e75d56bc63a" + integrity sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw== "@testing-library/dom@^8.0.0": version "8.19.0" @@ -4620,7 +4626,7 @@ engine.io@~6.2.0: engine.io-parser "~5.0.3" ws "~8.2.3" -enhanced-resolve@^5.0.0, enhanced-resolve@^5.15.0: +enhanced-resolve@^5.15.0: version "5.15.0" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.15.0.tgz#1af946c7d93603eb88e9896cee4904dc012e9c35" integrity sha512-LXYT42KJ7lpIKECr2mAXIaMldcNCh/7E0KBKOu4KSfkHmP+mZmSs+8V5gBAqisWBy0OO4W5Oyys0GO1Y8KtdKg== @@ -8279,7 +8285,7 @@ microbuffer@^1.0.0: resolved "https://registry.yarnpkg.com/microbuffer/-/microbuffer-1.0.0.tgz#8b3832ed40c87d51f47bb234913a698a756d19d2" integrity sha1-izgy7UDIfVH0e7I0kTppinVtGdI= -micromatch@^4.0.0, micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5: +micromatch@^4.0.2, micromatch@^4.0.4, micromatch@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" integrity sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA== @@ -11044,7 +11050,7 @@ source-map@^0.6.0, source-map@^0.6.1: resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== -source-map@^0.7.3, source-map@^0.7.4: +source-map@^0.7.3: version "0.7.4" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656" integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA== @@ -11589,6 +11595,11 @@ svgpath@^2.1.5: resolved "https://registry.yarnpkg.com/svgpath/-/svgpath-2.5.0.tgz#d57434641d9aa9abae02a4038ebf281fa3005b10" integrity sha512-o/vohwqjUO9nDAh4rcjE3KaW/v//At8UJu2LJMybXidf5QLQLVA4bxH0//4YCsr+1H4Gw1Wi/Jc62ynzSBYidw== +swc-loader@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/swc-loader/-/swc-loader-0.2.3.tgz#6792f1c2e4c9ae9bf9b933b3e010210e270c186d" + integrity sha512-D1p6XXURfSPleZZA/Lipb3A8pZ17fP4NObZvFCDjK/OKljroqDpPmsBdTraWhVBqUNpcWBQY1imWdoPScRlQ7A== + synckit@^0.8.5: version "0.8.5" resolved "https://registry.yarnpkg.com/synckit/-/synckit-0.8.5.tgz#b7f4358f9bb559437f9f167eb6bc46b3c9818fa3" @@ -11785,17 +11796,6 @@ ts-api-utils@^1.0.1: resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.2.tgz#7c094f753b6705ee4faee25c3c684ade52d66d99" integrity sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ== -ts-loader@^9.4.3: - version "9.5.0" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.5.0.tgz#f0a51dda37cc4d8e43e6cb14edebbc599b0c3aa2" - integrity sha512-LLlB/pkB4q9mW2yLdFMnK3dEHbrBjeZTYguaaIfusyojBgAGf5kF+O6KcWqiGzWqHk0LBsoolrp4VftEURhybg== - dependencies: - chalk "^4.1.0" - enhanced-resolve "^5.0.0" - micromatch "^4.0.0" - semver "^7.3.4" - source-map "^0.7.4" - tsconfig-paths@^3.14.1: version "3.14.2" resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088" @@ -12336,7 +12336,7 @@ webidl-conversions@^3.0.0: resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE= -webpack-bundle-analyzer@^4.9.0: +webpack-bundle-analyzer@^4.9.1: version "4.9.1" resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.9.1.tgz#d00bbf3f17500c10985084f22f1a2bf45cb2f09d" integrity sha512-jnd6EoYrf9yMxCyYDPj8eutJvtjQNp8PHmni/e/ulydHBWhT5J3menXt3HEkScsu9YqMAcG4CfFjs3rj5pVU1w== @@ -12453,7 +12453,7 @@ webpack-sources@^3.2.3: resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde" integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w== -webpack@^5.76.2, webpack@^5.88.0: +webpack@^5.76.2, webpack@^5.88.2: version "5.88.2" resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.88.2.tgz#f62b4b842f1c6ff580f3fcb2ed4f0b579f4c210e" integrity sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ== From f11edbdeba5d4d75f63b857ca5f9627763d861e0 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 9 Oct 2023 14:01:15 -0400 Subject: [PATCH 02/19] Remove extraneous dep --- packages/webpack-build-scripts/package.json | 1 - yarn.lock | 5 ----- 2 files changed, 6 deletions(-) diff --git a/packages/webpack-build-scripts/package.json b/packages/webpack-build-scripts/package.json index d99509085b..012e27ca84 100644 --- a/packages/webpack-build-scripts/package.json +++ b/packages/webpack-build-scripts/package.json @@ -27,7 +27,6 @@ "postcss-loader": "^7.3.3", "process": "^0.11.10", "react-refresh": "^0.14.0", - "react-refresh-typescript": "^2.0.9", "sass": "^1.63.6", "sass-loader": "^13.3.2", "source-map-loader": "^4.0.1", diff --git a/yarn.lock b/yarn.lock index 8441ce570e..e92e06a11e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10221,11 +10221,6 @@ react-popper@^2.3.0: react-fast-compare "^3.0.1" warning "^4.0.2" -react-refresh-typescript@^2.0.9: - version "2.0.9" - resolved "https://registry.yarnpkg.com/react-refresh-typescript/-/react-refresh-typescript-2.0.9.tgz#f8a86efcb34f8d717100230564b9b57477d74b10" - integrity sha512-chAnOO4vpxm/3WkgOVmti+eN8yUtkJzeGkOigV6UA9eDFz12W34e/SsYe2H5+RwYJ3+sfSZkVbiXcG1chEBxlg== - react-refresh@^0.14.0: version "0.14.0" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e" From b6ad7442b08060b189ecf6af2505dbbbade0590c Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 9 Oct 2023 14:16:54 -0400 Subject: [PATCH 03/19] Enable 'importsNotUsedAsValues' tsc option --- packages/core/test/tsconfig.json | 7 ++++--- packages/datetime/test/tsconfig.json | 1 + packages/datetime2/test/tsconfig.json | 1 + packages/icons/test/tsconfig.json | 1 + packages/select/test/tsconfig.json | 1 + packages/table/test/tsconfig.json | 1 + 6 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/core/test/tsconfig.json b/packages/core/test/tsconfig.json index f50dbd7a0d..09bc5d917c 100644 --- a/packages/core/test/tsconfig.json +++ b/packages/core/test/tsconfig.json @@ -2,9 +2,10 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, - "module": "commonjs", - "noEmit": true, + "downlevelIteration": true, + "importsNotUsedAsValues": "error", "lib": ["dom", "dom.iterable", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"], - "downlevelIteration": true + "module": "commonjs", + "noEmit": true } } diff --git a/packages/datetime/test/tsconfig.json b/packages/datetime/test/tsconfig.json index b32f37bea5..e0e223db0e 100644 --- a/packages/datetime/test/tsconfig.json +++ b/packages/datetime/test/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, + "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/datetime2/test/tsconfig.json b/packages/datetime2/test/tsconfig.json index b32f37bea5..e0e223db0e 100644 --- a/packages/datetime2/test/tsconfig.json +++ b/packages/datetime2/test/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, + "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/icons/test/tsconfig.json b/packages/icons/test/tsconfig.json index b32f37bea5..e0e223db0e 100644 --- a/packages/icons/test/tsconfig.json +++ b/packages/icons/test/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, + "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/select/test/tsconfig.json b/packages/select/test/tsconfig.json index b32f37bea5..e0e223db0e 100644 --- a/packages/select/test/tsconfig.json +++ b/packages/select/test/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, + "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/table/test/tsconfig.json b/packages/table/test/tsconfig.json index b32f37bea5..e0e223db0e 100644 --- a/packages/table/test/tsconfig.json +++ b/packages/table/test/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, + "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } From 08246a63ddf593ef6b2cd0ce15c7493f5742363b Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 9 Oct 2023 14:24:48 -0400 Subject: [PATCH 04/19] [core] annotate type-only imports --- packages/core/src/common/props.ts | 4 ++-- packages/core/src/common/refs.ts | 2 +- packages/core/src/components/alert/alert.tsx | 2 +- .../core/src/components/button/buttonProps.ts | 2 +- packages/core/src/components/button/buttons.tsx | 2 +- .../src/components/context-menu/contextMenu.tsx | 2 +- .../context-menu/contextMenuPopover.tsx | 4 ++-- .../core/src/components/dialog/dialogBody.tsx | 2 +- .../core/src/components/dialog/dialogFooter.tsx | 2 +- .../src/components/dialog/dialogStepButton.tsx | 2 +- packages/core/src/components/hotkeys/hotkey.tsx | 2 +- .../src/components/hotkeys/hotkeysDialog2.tsx | 2 +- .../src/components/html-select/htmlSelect.tsx | 2 +- .../src/components/panel-stack/panelProps.ts | 2 +- .../src/components/panel-stack/panelStack.tsx | 4 ++-- .../src/components/panel-stack/panelView.tsx | 2 +- .../src/components/panel-stack2/panelStack2.tsx | 2 +- .../src/components/panel-stack2/panelView2.tsx | 2 +- .../src/components/popover/customModifiers.ts | 2 +- packages/core/src/components/popover/popover.tsx | 6 +++--- .../core/src/components/popover/popoverArrow.tsx | 4 ++-- .../components/popover/popoverPlacementUtils.ts | 2 +- .../src/components/popover/popoverSharedProps.ts | 6 +++--- .../core/src/components/popover/popperUtils.ts | 2 +- packages/core/src/components/portal/portal.tsx | 2 +- packages/core/src/components/slider/handle.tsx | 2 +- .../core/src/components/slider/rangeSlider.tsx | 2 +- packages/core/src/components/slider/slider.tsx | 2 +- packages/core/src/components/tabs/tab.tsx | 4 ++-- packages/core/src/components/tabs/tabTitle.tsx | 2 +- packages/core/src/components/tooltip/tooltip.tsx | 2 +- packages/core/src/components/tree/tree.tsx | 2 +- packages/core/src/components/tree/treeNode.tsx | 2 +- .../core/src/context/hotkeys/hotkeysProvider.tsx | 2 +- packages/core/src/hooks/hotkeys/useHotkeys.ts | 2 +- packages/core/src/legacy/contextMenuLegacy.tsx | 2 +- packages/core/src/legacy/hotkeysTargetLegacy.tsx | 2 +- .../core/test/common/utils/compareUtilsTests.ts | 2 +- packages/core/test/popover/popperUtilTests.ts | 16 +--------------- packages/core/test/slider/sliderTestUtils.ts | 2 +- 40 files changed, 49 insertions(+), 63 deletions(-) diff --git a/packages/core/src/common/props.ts b/packages/core/src/common/props.ts index 27763b234e..4fe12c4f21 100644 --- a/packages/core/src/common/props.ts +++ b/packages/core/src/common/props.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -import * as React from "react"; +import type * as React from "react"; import type { IconName } from "@blueprintjs/icons"; -import { Intent } from "./intent"; +import type { Intent } from "./intent"; export const DISPLAYNAME_PREFIX = "Blueprint5"; diff --git a/packages/core/src/common/refs.ts b/packages/core/src/common/refs.ts index 4faece6f6b..88ba9c460a 100644 --- a/packages/core/src/common/refs.ts +++ b/packages/core/src/common/refs.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as React from "react"; +import type * as React from "react"; export function isRefObject(value: React.Ref | undefined): value is React.RefObject { return value != null && typeof value !== "function"; diff --git a/packages/core/src/components/alert/alert.tsx b/packages/core/src/components/alert/alert.tsx index e0e59de18e..ff74da4dfb 100644 --- a/packages/core/src/components/alert/alert.tsx +++ b/packages/core/src/components/alert/alert.tsx @@ -26,7 +26,7 @@ import { import { Button } from "../button/buttons"; import { Dialog } from "../dialog/dialog"; import { Icon, IconName } from "../icon/icon"; -import { OverlayLifecycleProps } from "../overlay/overlay"; +import type { OverlayLifecycleProps } from "../overlay/overlay"; export interface AlertProps extends OverlayLifecycleProps, Props { /** diff --git a/packages/core/src/components/button/buttonProps.ts b/packages/core/src/components/button/buttonProps.ts index 85db92a33c..abdc868555 100644 --- a/packages/core/src/components/button/buttonProps.ts +++ b/packages/core/src/components/button/buttonProps.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as React from "react"; +import type * as React from "react"; import type { ActionProps, Alignment, MaybeElement } from "../../common"; import type { IconName } from "../icon/icon"; diff --git a/packages/core/src/components/button/buttons.tsx b/packages/core/src/components/button/buttons.tsx index e96a89dfef..2819f545bc 100644 --- a/packages/core/src/components/button/buttons.tsx +++ b/packages/core/src/components/button/buttons.tsx @@ -22,7 +22,7 @@ import { DISPLAYNAME_PREFIX, removeNonHTMLProps } from "../../common/props"; import { mergeRefs } from "../../common/refs"; import { Icon } from "../icon/icon"; import { Spinner, SpinnerSize } from "../spinner/spinner"; -import { AnchorButtonProps, ButtonProps } from "./buttonProps"; +import type { AnchorButtonProps, ButtonProps } from "./buttonProps"; /** * Button component. diff --git a/packages/core/src/components/context-menu/contextMenu.tsx b/packages/core/src/components/context-menu/contextMenu.tsx index 7059dd62a6..0c08e67fe2 100644 --- a/packages/core/src/components/context-menu/contextMenu.tsx +++ b/packages/core/src/components/context-menu/contextMenu.tsx @@ -20,7 +20,7 @@ import * as React from "react"; import { Classes, DISPLAYNAME_PREFIX, mergeRefs, Props, Utils } from "../../common"; import { TooltipContext, TooltipProvider } from "../popover/tooltipContext"; import { ContextMenuPopover } from "./contextMenuPopover"; -import { ContextMenuPopoverOptions, Offset } from "./contextMenuShared"; +import type { ContextMenuPopoverOptions, Offset } from "./contextMenuShared"; /** * Render props relevant to the _content_ of a context menu (rendered as the underlying Popover's content). diff --git a/packages/core/src/components/context-menu/contextMenuPopover.tsx b/packages/core/src/components/context-menu/contextMenuPopover.tsx index 926d0b7b52..e1a14eb5f9 100644 --- a/packages/core/src/components/context-menu/contextMenuPopover.tsx +++ b/packages/core/src/components/context-menu/contextMenuPopover.tsx @@ -19,9 +19,9 @@ import * as React from "react"; import { Classes, DISPLAYNAME_PREFIX } from "../../common"; import { Popover } from "../popover/popover"; -import { PopoverTargetProps } from "../popover/popoverSharedProps"; +import type { PopoverTargetProps } from "../popover/popoverSharedProps"; import { Portal } from "../portal/portal"; -import { ContextMenuPopoverOptions, Offset } from "./contextMenuShared"; +import type { ContextMenuPopoverOptions, Offset } from "./contextMenuShared"; export interface ContextMenuPopoverProps extends ContextMenuPopoverOptions { isOpen: boolean; diff --git a/packages/core/src/components/dialog/dialogBody.tsx b/packages/core/src/components/dialog/dialogBody.tsx index 763b1171e6..e3681c4f97 100644 --- a/packages/core/src/components/dialog/dialogBody.tsx +++ b/packages/core/src/components/dialog/dialogBody.tsx @@ -18,7 +18,7 @@ import classNames from "classnames"; import * as React from "react"; import { AbstractPureComponent, Classes } from "../../common"; -import { Props } from "../../common/props"; +import type { Props } from "../../common/props"; export interface DialogBodyProps extends Props { /** Dialog body contents. */ diff --git a/packages/core/src/components/dialog/dialogFooter.tsx b/packages/core/src/components/dialog/dialogFooter.tsx index 5a7a65255a..f68ac34374 100644 --- a/packages/core/src/components/dialog/dialogFooter.tsx +++ b/packages/core/src/components/dialog/dialogFooter.tsx @@ -18,7 +18,7 @@ import classNames from "classnames"; import * as React from "react"; import { AbstractPureComponent, Classes } from "../../common"; -import { Props } from "../../common/props"; +import type { Props } from "../../common/props"; export interface DialogFooterProps extends Props { /** Child contents are rendered on the left side of the footer. */ diff --git a/packages/core/src/components/dialog/dialogStepButton.tsx b/packages/core/src/components/dialog/dialogStepButton.tsx index dca10ab8c0..d5651c23a2 100644 --- a/packages/core/src/components/dialog/dialogStepButton.tsx +++ b/packages/core/src/components/dialog/dialogStepButton.tsx @@ -16,7 +16,7 @@ import * as React from "react"; -import { ButtonSharedPropsAndAttributes } from "../button/buttonProps"; +import type { ButtonSharedPropsAndAttributes } from "../button/buttonProps"; import { AnchorButton } from "../button/buttons"; import { Tooltip, TooltipProps } from "../tooltip/tooltip"; diff --git a/packages/core/src/components/hotkeys/hotkey.tsx b/packages/core/src/components/hotkeys/hotkey.tsx index d8d10fa176..501fc1dc72 100644 --- a/packages/core/src/components/hotkeys/hotkey.tsx +++ b/packages/core/src/components/hotkeys/hotkey.tsx @@ -18,7 +18,7 @@ import classNames from "classnames"; import * as React from "react"; import { AbstractPureComponent, Classes, DISPLAYNAME_PREFIX, Props } from "../../common"; -import { HotkeyConfig } from "../../hooks"; +import type { HotkeyConfig } from "../../hooks"; import { KeyComboTag } from "./keyComboTag"; export type HotkeyProps = Props & HotkeyConfig; diff --git a/packages/core/src/components/hotkeys/hotkeysDialog2.tsx b/packages/core/src/components/hotkeys/hotkeysDialog2.tsx index 6fdd3fa20c..8a1bfd02d6 100644 --- a/packages/core/src/components/hotkeys/hotkeysDialog2.tsx +++ b/packages/core/src/components/hotkeys/hotkeysDialog2.tsx @@ -18,7 +18,7 @@ import classNames from "classnames"; import * as React from "react"; import { Classes } from "../../common"; -import { HotkeyConfig } from "../../hooks"; +import type { HotkeyConfig } from "../../hooks"; import { Dialog, DialogProps } from "../dialog/dialog"; import { DialogBody } from "../dialog/dialogBody"; import { Hotkey } from "./hotkey"; diff --git a/packages/core/src/components/html-select/htmlSelect.tsx b/packages/core/src/components/html-select/htmlSelect.tsx index 6558918898..b85ae7ee56 100644 --- a/packages/core/src/components/html-select/htmlSelect.tsx +++ b/packages/core/src/components/html-select/htmlSelect.tsx @@ -21,7 +21,7 @@ import { CaretDown, DoubleCaretVertical, IconName, SVGIconProps } from "@bluepri import { DISABLED, FILL, HTML_SELECT, LARGE, MINIMAL } from "../../common/classes"; import { DISPLAYNAME_PREFIX, OptionProps } from "../../common/props"; -import { Extends } from "../../common/utils"; +import type { Extends } from "../../common/utils"; export type HTMLSelectIconName = Extends; diff --git a/packages/core/src/components/panel-stack/panelProps.ts b/packages/core/src/components/panel-stack/panelProps.ts index d93cbb5f1f..de9b30ce43 100644 --- a/packages/core/src/components/panel-stack/panelProps.ts +++ b/packages/core/src/components/panel-stack/panelProps.ts @@ -21,7 +21,7 @@ /* eslint-disable deprecation/deprecation */ -import * as React from "react"; +import type * as React from "react"; /** * An object describing a panel in a `PanelStack`. diff --git a/packages/core/src/components/panel-stack/panelStack.tsx b/packages/core/src/components/panel-stack/panelStack.tsx index b559db601c..e4f30c5344 100644 --- a/packages/core/src/components/panel-stack/panelStack.tsx +++ b/packages/core/src/components/panel-stack/panelStack.tsx @@ -20,8 +20,8 @@ import { CSSTransition, TransitionGroup } from "react-transition-group"; import { AbstractPureComponent, Classes } from "../../common"; import * as Errors from "../../common/errors"; -import { Props } from "../../common/props"; -import { IPanel } from "./panelProps"; +import type { Props } from "../../common/props"; +import type { IPanel } from "./panelProps"; import { PanelView } from "./panelView"; /* eslint-disable deprecation/deprecation */ diff --git a/packages/core/src/components/panel-stack/panelView.tsx b/packages/core/src/components/panel-stack/panelView.tsx index b112cb3ddf..5b30413f6b 100644 --- a/packages/core/src/components/panel-stack/panelView.tsx +++ b/packages/core/src/components/panel-stack/panelView.tsx @@ -26,7 +26,7 @@ import * as React from "react"; import { AbstractPureComponent, Classes } from "../../common"; import { Button } from "../button/buttons"; import { Text } from "../text/text"; -import { IPanel } from "./panelProps"; +import type { IPanel } from "./panelProps"; export interface IPanelViewProps { /** diff --git a/packages/core/src/components/panel-stack2/panelStack2.tsx b/packages/core/src/components/panel-stack2/panelStack2.tsx index 0698a3a1d6..0094d99e56 100644 --- a/packages/core/src/components/panel-stack2/panelStack2.tsx +++ b/packages/core/src/components/panel-stack2/panelStack2.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { CSSTransition, TransitionGroup } from "react-transition-group"; import { Classes, DISPLAYNAME_PREFIX, Props } from "../../common"; -import { Panel } from "./panelTypes"; +import type { Panel } from "./panelTypes"; import { PanelView2 } from "./panelView2"; /** diff --git a/packages/core/src/components/panel-stack2/panelView2.tsx b/packages/core/src/components/panel-stack2/panelView2.tsx index e1abd95746..3c41a2847c 100644 --- a/packages/core/src/components/panel-stack2/panelView2.tsx +++ b/packages/core/src/components/panel-stack2/panelView2.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { Classes, DISPLAYNAME_PREFIX } from "../../common"; import { Button } from "../button/buttons"; import { Text } from "../text/text"; -import { Panel, PanelProps } from "./panelTypes"; +import type { Panel, PanelProps } from "./panelTypes"; // eslint-disable-next-line @typescript-eslint/ban-types export interface PanelView2Props> { diff --git a/packages/core/src/components/popover/customModifiers.ts b/packages/core/src/components/popover/customModifiers.ts index 25b7f2e8e2..6defa5bc5e 100644 --- a/packages/core/src/components/popover/customModifiers.ts +++ b/packages/core/src/components/popover/customModifiers.ts @@ -19,7 +19,7 @@ * @see https://popper.js.org/docs/v2/modifiers/#custom-modifiers */ -import { Modifier } from "@popperjs/core"; +import type { Modifier } from "@popperjs/core"; // tslint:disable object-literal-sort-keys diff --git a/packages/core/src/components/popover/popover.tsx b/packages/core/src/components/popover/popover.tsx index 1e031dee45..bb15723242 100644 --- a/packages/core/src/components/popover/popover.tsx +++ b/packages/core/src/components/popover/popover.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { State as PopperState, PositioningStrategy } from "@popperjs/core"; +import type { State as PopperState, PositioningStrategy } from "@popperjs/core"; import classNames from "classnames"; import * as React from "react"; import { Manager, Modifier, Popper, PopperChildrenProps, Reference, ReferenceChildrenProps } from "react-popper"; @@ -28,14 +28,14 @@ import { Tooltip } from "../tooltip/tooltip"; import { matchReferenceWidthModifier } from "./customModifiers"; import { POPOVER_ARROW_SVG_SIZE, PopoverArrow } from "./popoverArrow"; import { positionToPlacement } from "./popoverPlacementUtils"; -import { +import type { DefaultPopoverTargetHTMLProps, PopoverClickTargetHandlers, PopoverHoverTargetHandlers, PopoverSharedProps, } from "./popoverSharedProps"; import { getBasePlacement, getTransformOrigin } from "./popperUtils"; -import { PopupKind } from "./popupKind"; +import type { PopupKind } from "./popupKind"; export const PopoverInteractionKind = { CLICK: "click" as "click", diff --git a/packages/core/src/components/popover/popoverArrow.tsx b/packages/core/src/components/popover/popoverArrow.tsx index 259da62fc7..658eeca68a 100644 --- a/packages/core/src/components/popover/popoverArrow.tsx +++ b/packages/core/src/components/popover/popoverArrow.tsx @@ -14,9 +14,9 @@ * limitations under the License. */ -import { Placement } from "@popperjs/core"; +import type { Placement } from "@popperjs/core"; import * as React from "react"; -import { PopperArrowProps } from "react-popper"; +import type { PopperArrowProps } from "react-popper"; import { Classes, DISPLAYNAME_PREFIX } from "../../common"; import { getBasePlacement } from "./popperUtils"; diff --git a/packages/core/src/components/popover/popoverPlacementUtils.ts b/packages/core/src/components/popover/popoverPlacementUtils.ts index 0843b7d03c..07b5668058 100644 --- a/packages/core/src/components/popover/popoverPlacementUtils.ts +++ b/packages/core/src/components/popover/popoverPlacementUtils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Placement } from "@popperjs/core"; +import type { Placement } from "@popperjs/core"; import { PopoverPosition } from "./popoverSharedProps"; diff --git a/packages/core/src/components/popover/popoverSharedProps.ts b/packages/core/src/components/popover/popoverSharedProps.ts index 8730d685d7..cee512109c 100644 --- a/packages/core/src/components/popover/popoverSharedProps.ts +++ b/packages/core/src/components/popover/popoverSharedProps.ts @@ -15,11 +15,11 @@ */ import { Boundary, Modifier, Placement, placements, RootBoundary, StrictModifiers } from "@popperjs/core"; -import * as React from "react"; -import { StrictModifier } from "react-popper"; +import type * as React from "react"; +import type { StrictModifier } from "react-popper"; import { Position, Props } from "../../common"; -import { OverlayableProps } from "../overlay/overlay"; +import type { OverlayableProps } from "../overlay/overlay"; export const PopoverPosition = { ...Position, diff --git a/packages/core/src/components/popover/popperUtils.ts b/packages/core/src/components/popover/popperUtils.ts index 307ec958c5..5131d4d73d 100644 --- a/packages/core/src/components/popover/popperUtils.ts +++ b/packages/core/src/components/popover/popperUtils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { BasePlacement, Placement } from "@popperjs/core"; +import type { BasePlacement, Placement } from "@popperjs/core"; // Popper placement utils // ====================== diff --git a/packages/core/src/components/portal/portal.tsx b/packages/core/src/components/portal/portal.tsx index 2ee0bb0fe9..9b042f6a87 100644 --- a/packages/core/src/components/portal/portal.tsx +++ b/packages/core/src/components/portal/portal.tsx @@ -18,7 +18,7 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; import { Classes, DISPLAYNAME_PREFIX, Props } from "../../common"; -import { ValidationMap } from "../../common/context"; +import type { ValidationMap } from "../../common/context"; import * as Errors from "../../common/errors"; import { PortalContext } from "../../context/portal/portalProvider"; diff --git a/packages/core/src/components/slider/handle.tsx b/packages/core/src/components/slider/handle.tsx index cf9a12151f..014053ee68 100644 --- a/packages/core/src/components/slider/handle.tsx +++ b/packages/core/src/components/slider/handle.tsx @@ -20,7 +20,7 @@ import * as React from "react"; import { AbstractPureComponent, Classes, Utils } from "../../common"; import { DISPLAYNAME_PREFIX } from "../../common/props"; import { clamp } from "../../common/utils"; -import { HandleProps } from "./handleProps"; +import type { HandleProps } from "./handleProps"; import { formatPercentage } from "./sliderUtils"; /** diff --git a/packages/core/src/components/slider/rangeSlider.tsx b/packages/core/src/components/slider/rangeSlider.tsx index 42c7edee73..1475bba50b 100644 --- a/packages/core/src/components/slider/rangeSlider.tsx +++ b/packages/core/src/components/slider/rangeSlider.tsx @@ -18,7 +18,7 @@ import * as React from "react"; import { AbstractPureComponent, DISPLAYNAME_PREFIX, Intent } from "../../common"; import * as Errors from "../../common/errors"; -import { HandleHtmlProps } from "./handleProps"; +import type { HandleHtmlProps } from "./handleProps"; import { MultiSlider, SliderBaseProps } from "./multiSlider"; export type NumberRange = [number, number]; diff --git a/packages/core/src/components/slider/slider.tsx b/packages/core/src/components/slider/slider.tsx index e82ccdcb99..394b4db46f 100644 --- a/packages/core/src/components/slider/slider.tsx +++ b/packages/core/src/components/slider/slider.tsx @@ -18,7 +18,7 @@ import * as React from "react"; import { AbstractPureComponent, Intent } from "../../common"; import { DISPLAYNAME_PREFIX } from "../../common/props"; -import { HandleHtmlProps } from "./handleProps"; +import type { HandleHtmlProps } from "./handleProps"; import { MultiSlider, SliderBaseProps } from "./multiSlider"; export interface SliderProps extends SliderBaseProps { diff --git a/packages/core/src/components/tabs/tab.tsx b/packages/core/src/components/tabs/tab.tsx index 83be6a4f90..fbe6cbd863 100644 --- a/packages/core/src/components/tabs/tab.tsx +++ b/packages/core/src/components/tabs/tab.tsx @@ -17,11 +17,11 @@ import classNames from "classnames"; import * as React from "react"; -import { IconName } from "@blueprintjs/icons"; +import type { IconName } from "@blueprintjs/icons"; import { AbstractPureComponent, Classes } from "../../common"; import { DISPLAYNAME_PREFIX, HTMLDivProps, MaybeElement, Props } from "../../common/props"; -import { TagProps } from "../tag/tag"; +import type { TagProps } from "../tag/tag"; export type TabId = string | number; diff --git a/packages/core/src/components/tabs/tabTitle.tsx b/packages/core/src/components/tabs/tabTitle.tsx index a8b4c04acd..1b6edfc2a6 100644 --- a/packages/core/src/components/tabs/tabTitle.tsx +++ b/packages/core/src/components/tabs/tabTitle.tsx @@ -21,7 +21,7 @@ import { AbstractPureComponent, Classes, Intent } from "../../common"; import { DISPLAYNAME_PREFIX, removeNonHTMLProps } from "../../common/props"; import { Icon } from "../icon/icon"; import { Tag } from "../tag/tag"; -import { TabId, TabProps } from "./tab"; +import type { TabId, TabProps } from "./tab"; export interface TabTitleProps extends TabProps { /** Optional contents. */ diff --git a/packages/core/src/components/tooltip/tooltip.tsx b/packages/core/src/components/tooltip/tooltip.tsx index f702a913c4..a1a8ed858a 100644 --- a/packages/core/src/components/tooltip/tooltip.tsx +++ b/packages/core/src/components/tooltip/tooltip.tsx @@ -22,7 +22,7 @@ import * as Classes from "../../common/classes"; // eslint-disable-next-line import/no-cycle import { Popover, PopoverInteractionKind } from "../popover/popover"; import { TOOLTIP_ARROW_SVG_SIZE } from "../popover/popoverArrow"; -import { DefaultPopoverTargetHTMLProps, PopoverSharedProps } from "../popover/popoverSharedProps"; +import type { DefaultPopoverTargetHTMLProps, PopoverSharedProps } from "../popover/popoverSharedProps"; import { TooltipContext, TooltipContextState, TooltipProvider } from "../popover/tooltipContext"; export interface TooltipProps diff --git a/packages/core/src/components/tree/tree.tsx b/packages/core/src/components/tree/tree.tsx index ba0632548c..5c456fabed 100644 --- a/packages/core/src/components/tree/tree.tsx +++ b/packages/core/src/components/tree/tree.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { Classes, DISPLAYNAME_PREFIX, Props } from "../../common"; import { TreeNode } from "./treeNode"; -import { TreeEventHandler, TreeNodeInfo } from "./treeTypes"; +import type { TreeEventHandler, TreeNodeInfo } from "./treeTypes"; // eslint-disable-next-line @typescript-eslint/ban-types export interface TreeProps extends Props { diff --git a/packages/core/src/components/tree/treeNode.tsx b/packages/core/src/components/tree/treeNode.tsx index 177a7db54d..1bce6134e8 100644 --- a/packages/core/src/components/tree/treeNode.tsx +++ b/packages/core/src/components/tree/treeNode.tsx @@ -22,7 +22,7 @@ import { ChevronRight } from "@blueprintjs/icons"; import { Classes, DISPLAYNAME_PREFIX } from "../../common"; import { Collapse } from "../collapse/collapse"; import { Icon } from "../icon/icon"; -import { TreeEventHandler, TreeNodeInfo } from "./treeTypes"; +import type { TreeEventHandler, TreeNodeInfo } from "./treeTypes"; // eslint-disable-next-line @typescript-eslint/ban-types export interface TreeNodeProps extends TreeNodeInfo { diff --git a/packages/core/src/context/hotkeys/hotkeysProvider.tsx b/packages/core/src/context/hotkeys/hotkeysProvider.tsx index 0552dc0e65..1a4a252a26 100644 --- a/packages/core/src/context/hotkeys/hotkeysProvider.tsx +++ b/packages/core/src/context/hotkeys/hotkeysProvider.tsx @@ -18,7 +18,7 @@ import * as React from "react"; import { shallowCompareKeys } from "../../common/utils"; import { HotkeysDialog2, HotkeysDialogProps } from "../../components/hotkeys/hotkeysDialog2"; -import { HotkeyConfig } from "../../hooks"; +import type { HotkeyConfig } from "../../hooks"; interface HotkeysContextState { /** diff --git a/packages/core/src/hooks/hotkeys/useHotkeys.ts b/packages/core/src/hooks/hotkeys/useHotkeys.ts index c44eabeccf..d569b95268 100644 --- a/packages/core/src/hooks/hotkeys/useHotkeys.ts +++ b/packages/core/src/hooks/hotkeys/useHotkeys.ts @@ -20,7 +20,7 @@ import { HOTKEYS_PROVIDER_NOT_FOUND } from "../../common/errors"; import { elementIsTextInput } from "../../common/utils/domUtils"; import { comboMatches, getKeyCombo, KeyCombo, parseKeyCombo } from "../../components/hotkeys/hotkeyParser"; import { HotkeysContext } from "../../context"; -import { HotkeyConfig } from "./hotkeyConfig"; +import type { HotkeyConfig } from "./hotkeyConfig"; export interface UseHotkeysOptions { /** diff --git a/packages/core/src/legacy/contextMenuLegacy.tsx b/packages/core/src/legacy/contextMenuLegacy.tsx index 0226543e92..ca29c72702 100644 --- a/packages/core/src/legacy/contextMenuLegacy.tsx +++ b/packages/core/src/legacy/contextMenuLegacy.tsx @@ -26,7 +26,7 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; import { AbstractPureComponent, Classes } from "../common"; -import { OverlayLifecycleProps } from "../components/overlay/overlay"; +import type { OverlayLifecycleProps } from "../components/overlay/overlay"; import { Popover } from "../components/popover/popover"; export interface Offset { diff --git a/packages/core/src/legacy/hotkeysTargetLegacy.tsx b/packages/core/src/legacy/hotkeysTargetLegacy.tsx index 46701d49e4..c4d601f0c9 100644 --- a/packages/core/src/legacy/hotkeysTargetLegacy.tsx +++ b/packages/core/src/legacy/hotkeysTargetLegacy.tsx @@ -24,7 +24,7 @@ import * as React from "react"; import { isFunction } from "../common/utils"; -import { HotkeysProps } from "../components/hotkeys"; +import type { HotkeysProps } from "../components/hotkeys"; import { HotkeyScope, HotkeysEvents } from "./hotkeysEvents"; import { Constructor, getDisplayName } from "./legacyCommon"; diff --git a/packages/core/test/common/utils/compareUtilsTests.ts b/packages/core/test/common/utils/compareUtilsTests.ts index bb721266fc..523bd22fde 100644 --- a/packages/core/test/common/utils/compareUtilsTests.ts +++ b/packages/core/test/common/utils/compareUtilsTests.ts @@ -18,7 +18,7 @@ import { expect } from "chai"; -import { KeyAllowlist, KeyDenylist } from "../../../src/common/utils"; +import type { KeyAllowlist, KeyDenylist } from "../../../src/common/utils"; import * as CompareUtils from "../../../src/common/utils/compareUtils"; describe("CompareUtils", () => { diff --git a/packages/core/test/popover/popperUtilTests.ts b/packages/core/test/popover/popperUtilTests.ts index 714d710432..77e1dd2845 100644 --- a/packages/core/test/popover/popperUtilTests.ts +++ b/packages/core/test/popover/popperUtilTests.ts @@ -14,21 +14,7 @@ * limitations under the License. */ -/* Copyright 2020 Palantir Technologies, Inc. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License.*/ - -import { BasePlacement } from "@popperjs/core"; +import type { BasePlacement } from "@popperjs/core"; import { expect } from "chai"; import { getAlignment, getOppositePlacement } from "../../src/components/popover/popperUtils"; diff --git a/packages/core/test/slider/sliderTestUtils.ts b/packages/core/test/slider/sliderTestUtils.ts index d4b06f5b10..215ec92050 100644 --- a/packages/core/test/slider/sliderTestUtils.ts +++ b/packages/core/test/slider/sliderTestUtils.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ReactWrapper } from "enzyme"; +import type { ReactWrapper } from "enzyme"; import { dispatchMouseEvent, dispatchTouchEvent } from "@blueprintjs/test-commons"; From d33d14a0f94054a85a78f9e21fcba3b36f7ee9e4 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 9 Oct 2023 14:25:45 -0400 Subject: [PATCH 05/19] Move 'importsNotUsedAsValues' option to base config --- config/tsconfig.base.json | 1 + packages/core/test/tsconfig.json | 1 - packages/datetime/test/tsconfig.json | 1 - packages/datetime2/test/tsconfig.json | 1 - packages/icons/test/tsconfig.json | 1 - packages/select/test/tsconfig.json | 1 - packages/table/test/tsconfig.json | 1 - 7 files changed, 1 insertion(+), 6 deletions(-) diff --git a/config/tsconfig.base.json b/config/tsconfig.base.json index ac6b9efb17..ab7426baba 100644 --- a/config/tsconfig.base.json +++ b/config/tsconfig.base.json @@ -6,6 +6,7 @@ "esModuleInterop": true, "experimentalDecorators": true, "importHelpers": true, + "importsNotUsedAsValues": "error", "jsx": "react", "lib": ["dom", "dom.iterable", "es5", "es2015.collection", "es2015.iterable"], "module": "es2020", diff --git a/packages/core/test/tsconfig.json b/packages/core/test/tsconfig.json index 09bc5d917c..f6f49bdeaf 100644 --- a/packages/core/test/tsconfig.json +++ b/packages/core/test/tsconfig.json @@ -3,7 +3,6 @@ "compilerOptions": { "declaration": false, "downlevelIteration": true, - "importsNotUsedAsValues": "error", "lib": ["dom", "dom.iterable", "es5", "es2015.collection", "es2015.iterable", "es2015.promise"], "module": "commonjs", "noEmit": true diff --git a/packages/datetime/test/tsconfig.json b/packages/datetime/test/tsconfig.json index e0e223db0e..b32f37bea5 100644 --- a/packages/datetime/test/tsconfig.json +++ b/packages/datetime/test/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, - "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/datetime2/test/tsconfig.json b/packages/datetime2/test/tsconfig.json index e0e223db0e..b32f37bea5 100644 --- a/packages/datetime2/test/tsconfig.json +++ b/packages/datetime2/test/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, - "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/icons/test/tsconfig.json b/packages/icons/test/tsconfig.json index e0e223db0e..b32f37bea5 100644 --- a/packages/icons/test/tsconfig.json +++ b/packages/icons/test/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, - "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/select/test/tsconfig.json b/packages/select/test/tsconfig.json index e0e223db0e..b32f37bea5 100644 --- a/packages/select/test/tsconfig.json +++ b/packages/select/test/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, - "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } diff --git a/packages/table/test/tsconfig.json b/packages/table/test/tsconfig.json index e0e223db0e..b32f37bea5 100644 --- a/packages/table/test/tsconfig.json +++ b/packages/table/test/tsconfig.json @@ -2,7 +2,6 @@ "extends": "../src/tsconfig", "compilerOptions": { "declaration": false, - "importsNotUsedAsValues": "error", "module": "commonjs", "noEmit": true } From 93b589bab06de01dc78b1e63da91895b70cb3b41 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Mon, 9 Oct 2023 14:35:19 -0400 Subject: [PATCH 06/19] [core] annotate more type-only exports --- packages/core/src/common/index.ts | 18 +- packages/core/src/common/utils/index.ts | 2 +- packages/core/src/components/hotkeys/index.ts | 10 +- packages/core/src/components/icon/icon.tsx | 2 +- packages/core/src/components/index.ts | 157 ++++++++++-------- .../components/popover/popoverSharedProps.ts | 4 +- .../src/components/popover/popperUtils.ts | 2 + packages/core/src/context/index.ts | 6 +- packages/core/src/hooks/index.ts | 4 +- packages/core/src/index.ts | 2 +- 10 files changed, 112 insertions(+), 95 deletions(-) diff --git a/packages/core/src/common/index.ts b/packages/core/src/common/index.ts index d7326740c0..6be6243bca 100644 --- a/packages/core/src/common/index.ts +++ b/packages/core/src/common/index.ts @@ -26,17 +26,17 @@ export { Intent } from "./intent"; export { KeyCodes as Keys } from "./keyCodes"; export { Position } from "./position"; export { - ActionProps, - ControlledProps, - IntentProps, - LinkProps, - OptionProps, - Props, + type ActionProps, + type ControlledProps, + type IntentProps, + type LinkProps, + type OptionProps, + type Props, removeNonHTMLProps, DISPLAYNAME_PREFIX, - HTMLDivProps, - HTMLInputProps, - MaybeElement, + type HTMLDivProps, + type HTMLInputProps, + type MaybeElement, } from "./props"; export { getRef, isRefCallback, isRefObject, mergeRefs, refHandler, setRef } from "./refs"; diff --git a/packages/core/src/common/utils/index.ts b/packages/core/src/common/utils/index.ts index 95f1ec40ee..d995544468 100644 --- a/packages/core/src/common/utils/index.ts +++ b/packages/core/src/common/utils/index.ts @@ -28,7 +28,7 @@ export { isFunction } from "./functionUtils"; export * from "./jsUtils"; export * from "./reactUtils"; export { isArrowKey, isKeyboardClick } from "./keyboardUtils"; -export { Extends } from "./typeUtils"; +export type { Extends } from "./typeUtils"; export { isDarkTheme } from "./isDarkTheme"; // ref utils used to live in this folder, but got refactored and moved elsewhere. diff --git a/packages/core/src/components/hotkeys/index.ts b/packages/core/src/components/hotkeys/index.ts index 3d36360ed1..da9cd174aa 100644 --- a/packages/core/src/components/hotkeys/index.ts +++ b/packages/core/src/components/hotkeys/index.ts @@ -14,11 +14,11 @@ * limitations under the License. */ -export { Hotkey, HotkeyProps } from "./hotkey"; -export { Hotkeys, HotkeysProps } from "./hotkeys"; -export { KeyComboTag, KeyComboTagProps } from "./keyComboTag"; -export { KeyCombo, comboMatches, getKeyCombo, getKeyComboString, parseKeyCombo } from "./hotkeyParser"; +export { Hotkey, type HotkeyProps } from "./hotkey"; +export { Hotkeys, type HotkeysProps } from "./hotkeys"; +export { KeyComboTag, type KeyComboTagProps } from "./keyComboTag"; +export { type KeyCombo, comboMatches, getKeyCombo, getKeyComboString, parseKeyCombo } from "./hotkeyParser"; // N.B. "V1" variants of these APIs are exported from src/legacy/ export { HotkeysDialog2 } from "./hotkeysDialog2"; -export { HotkeysTarget2, HotkeysTarget2Props, HotkeysTarget2RenderProps } from "./hotkeysTarget2"; +export { HotkeysTarget2, type HotkeysTarget2Props, type HotkeysTarget2RenderProps } from "./hotkeysTarget2"; diff --git a/packages/core/src/components/icon/icon.tsx b/packages/core/src/components/icon/icon.tsx index d7ecbf45e6..ec73def59e 100644 --- a/packages/core/src/components/icon/icon.tsx +++ b/packages/core/src/components/icon/icon.tsx @@ -30,7 +30,7 @@ import { import { Classes, DISPLAYNAME_PREFIX, IntentProps, MaybeElement, Props, removeNonHTMLProps } from "../../common"; // re-export for convenience, since some users won't be importing from or have a direct dependency on the icons package -export { IconName, IconSize }; +export { type IconName, IconSize }; export interface IconOwnProps { /** diff --git a/packages/core/src/components/index.ts b/packages/core/src/components/index.ts index 798790ef2d..888c88cfaa 100644 --- a/packages/core/src/components/index.ts +++ b/packages/core/src/components/index.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -export { Alert, AlertProps } from "./alert/alert"; -export { Breadcrumb, BreadcrumbProps } from "./breadcrumbs/breadcrumb"; -export { Breadcrumbs, BreadcrumbsProps } from "./breadcrumbs/breadcrumbs"; +export { Alert, type AlertProps } from "./alert/alert"; +export { Breadcrumb, type BreadcrumbProps } from "./breadcrumbs/breadcrumb"; +export { Breadcrumbs, type BreadcrumbsProps } from "./breadcrumbs/breadcrumbs"; export { AnchorButton, Button } from "./button/buttons"; export type { AnchorButtonProps, @@ -24,60 +24,75 @@ export type { ButtonSharedProps, ButtonSharedPropsAndAttributes, } from "./button/buttonProps"; -export { ButtonGroup, ButtonGroupProps } from "./button/buttonGroup"; -export { Callout, CalloutProps } from "./callout/callout"; -export { Card, CardProps } from "./card/card"; -export { CardList, CardListProps } from "./card-list/cardList"; -export { Collapse, CollapseProps } from "./collapse/collapse"; +export { ButtonGroup, type ButtonGroupProps } from "./button/buttonGroup"; +export { Callout, type CalloutProps } from "./callout/callout"; +export { Card, type CardProps } from "./card/card"; +export { CardList, type CardListProps } from "./card-list/cardList"; +export { Collapse, type CollapseProps } from "./collapse/collapse"; export { ContextMenu, - ContextMenuProps, - ContextMenuChildrenProps, - ContextMenuContentProps, + type ContextMenuProps, + type ContextMenuChildrenProps, + type ContextMenuContentProps, } from "./context-menu/contextMenu"; -export { ContextMenuPopover, ContextMenuPopoverProps } from "./context-menu/contextMenuPopover"; +export { ContextMenuPopover, type ContextMenuPopoverProps } from "./context-menu/contextMenuPopover"; export { showContextMenu, hideContextMenu } from "./context-menu/contextMenuSingleton"; -export { Dialog, DialogProps } from "./dialog/dialog"; -export { DialogBody, DialogBodyProps } from "./dialog/dialogBody"; -export { DialogFooter, DialogFooterProps } from "./dialog/dialogFooter"; +export { Dialog, type DialogProps } from "./dialog/dialog"; +export { DialogBody, type DialogBodyProps } from "./dialog/dialogBody"; +export { DialogFooter, type DialogFooterProps } from "./dialog/dialogFooter"; export type { DialogStepButtonProps } from "./dialog/dialogStepButton"; -export { DialogStep, DialogStepId, DialogStepProps } from "./dialog/dialogStep"; -export { MultistepDialog, MultistepDialogNavPosition, MultistepDialogProps } from "./dialog/multistepDialog"; -export { Divider, DividerProps } from "./divider/divider"; -export { Drawer, DrawerProps, DrawerSize } from "./drawer/drawer"; -export { EditableText, EditableTextProps } from "./editable-text/editableText"; -export { ControlGroup, ControlGroupProps } from "./forms/controlGroup"; -export { Checkbox, CheckboxProps, ControlProps, Radio, RadioProps, Switch, SwitchProps } from "./forms/controls"; -export { FileInput, FileInputProps } from "./forms/fileInput"; -export { FormGroup, FormGroupProps } from "./forms/formGroup"; -export { InputGroup, InputGroupProps } from "./forms/inputGroup"; -export { NumericInput, NumericInputProps } from "./forms/numericInput"; -export { RadioGroup, RadioGroupProps } from "./forms/radioGroup"; -export { TextArea, TextAreaProps } from "./forms/textArea"; +export { DialogStep, type DialogStepId, type DialogStepProps } from "./dialog/dialogStep"; +export { MultistepDialog, type MultistepDialogNavPosition, type MultistepDialogProps } from "./dialog/multistepDialog"; +export { Divider, type DividerProps } from "./divider/divider"; +export { Drawer, type DrawerProps, DrawerSize } from "./drawer/drawer"; +export { EditableText, type EditableTextProps } from "./editable-text/editableText"; +export { ControlGroup, type ControlGroupProps } from "./forms/controlGroup"; +export { + Checkbox, + type CheckboxProps, + type ControlProps, + Radio, + type RadioProps, + Switch, + type SwitchProps, +} from "./forms/controls"; +export { FileInput, type FileInputProps } from "./forms/fileInput"; +export { FormGroup, type FormGroupProps } from "./forms/formGroup"; +export { InputGroup, type InputGroupProps } from "./forms/inputGroup"; +export { NumericInput, type NumericInputProps } from "./forms/numericInput"; +export { RadioGroup, type RadioGroupProps } from "./forms/radioGroup"; +export { TextArea, type TextAreaProps } from "./forms/textArea"; export { Blockquote, Code, H1, H2, H3, H4, H5, H6, Label, OL, Pre, UL } from "./html/html"; -export { HTMLSelect, HTMLSelectIconName, HTMLSelectProps } from "./html-select/htmlSelect"; -export { HTMLTable, HTMLTableProps } from "./html-table/htmlTable"; +export { HTMLSelect, type HTMLSelectIconName, type HTMLSelectProps } from "./html-select/htmlSelect"; +export { HTMLTable, type HTMLTableProps } from "./html-table/htmlTable"; export * from "./hotkeys"; -export { DefaultIconProps, Icon, IconComponent, IconName, IconProps, IconSize } from "./icon/icon"; -export { Menu, MenuProps } from "./menu/menu"; -export { MenuDivider, MenuDividerProps } from "./menu/menuDivider"; -export { MenuItem, MenuItemProps } from "./menu/menuItem"; -export { Navbar, NavbarProps } from "./navbar/navbar"; -export { NavbarDivider, NavbarDividerProps } from "./navbar/navbarDivider"; -export { NavbarGroup, NavbarGroupProps } from "./navbar/navbarGroup"; -export { NavbarHeading, NavbarHeadingProps } from "./navbar/navbarHeading"; -export { NonIdealState, NonIdealStateProps, NonIdealStateIconSize } from "./non-ideal-state/nonIdealState"; -export { OverflowList, OverflowListProps } from "./overflow-list/overflowList"; -export { Overlay, OverlayLifecycleProps, OverlayProps, OverlayableProps } from "./overlay/overlay"; -export { Text, TextProps } from "./text/text"; +export { + type DefaultIconProps, + Icon, + type IconComponent, + type IconName, + type IconProps, + type IconSize, +} from "./icon/icon"; +export { Menu, type MenuProps } from "./menu/menu"; +export { MenuDivider, type MenuDividerProps } from "./menu/menuDivider"; +export { MenuItem, type MenuItemProps } from "./menu/menuItem"; +export { Navbar, type NavbarProps } from "./navbar/navbar"; +export { NavbarDivider, type NavbarDividerProps } from "./navbar/navbarDivider"; +export { NavbarGroup, type NavbarGroupProps } from "./navbar/navbarGroup"; +export { NavbarHeading, type NavbarHeadingProps } from "./navbar/navbarHeading"; +export { NonIdealState, type NonIdealStateProps, type NonIdealStateIconSize } from "./non-ideal-state/nonIdealState"; +export { OverflowList, type OverflowListProps } from "./overflow-list/overflowList"; +export { Overlay, type OverlayLifecycleProps, type OverlayProps, type OverlayableProps } from "./overlay/overlay"; +export { Text, type TextProps } from "./text/text"; // eslint-disable-next-line deprecation/deprecation -export { PanelStack, PanelStackProps } from "./panel-stack/panelStack"; +export { PanelStack, type PanelStackProps } from "./panel-stack/panelStack"; // eslint-disable-next-line deprecation/deprecation -export { IPanel, IPanelProps } from "./panel-stack/panelProps"; -export { PanelStack2, PanelStack2Props } from "./panel-stack2/panelStack2"; -export { Panel, PanelProps } from "./panel-stack2/panelTypes"; -export { PopoverProps, Popover, PopoverInteractionKind } from "./popover/popover"; -export { +export type { IPanel, IPanelProps } from "./panel-stack/panelProps"; +export { PanelStack2, type PanelStack2Props } from "./panel-stack2/panelStack2"; +export type { Panel, PanelProps } from "./panel-stack2/panelTypes"; +export { type PopoverProps, Popover, PopoverInteractionKind } from "./popover/popover"; +export type { DefaultPopoverTargetHTMLProps, PopoverPosition, PopoverSharedProps, @@ -88,31 +103,31 @@ export { PopperCustomModifier, PopperModifierOverrides, Placement, - PopperPlacements, StrictModifierNames, } from "./popover/popoverSharedProps"; -export { PopupKind } from "./popover/popupKind"; -export { Portal, PortalProps, PortalLegacyContext } from "./portal/portal"; -export { ProgressBar, ProgressBarProps } from "./progress-bar/progressBar"; -export { ResizeEntry, ResizeSensor, ResizeSensorProps } from "./resize-sensor/resizeSensor"; -export { HandleHtmlProps, HandleInteractionKind, HandleProps, HandleType } from "./slider/handleProps"; -export { MultiSlider, MultiSliderProps, SliderBaseProps } from "./slider/multiSlider"; -export { NumberRange, RangeSlider, RangeSliderProps } from "./slider/rangeSlider"; -export { Section, SectionElevation, SectionProps } from "./section/section"; -export { SectionCard, SectionCardProps } from "./section/sectionCard"; -export { Slider, SliderProps } from "./slider/slider"; -export { Spinner, SpinnerProps, SpinnerSize } from "./spinner/spinner"; -export { SwitchCard, SwitchCardProps } from "./control-card/switchCard"; -export { Tab, TabId, TabProps } from "./tabs/tab"; +export { PopperPlacements } from "./popover/popperUtils"; +export type { PopupKind } from "./popover/popupKind"; +export { Portal, type PortalProps, type PortalLegacyContext } from "./portal/portal"; +export { ProgressBar, type ProgressBarProps } from "./progress-bar/progressBar"; +export { type ResizeEntry, ResizeSensor, type ResizeSensorProps } from "./resize-sensor/resizeSensor"; +export type { HandleHtmlProps, HandleInteractionKind, HandleProps, HandleType } from "./slider/handleProps"; +export { MultiSlider, type MultiSliderProps, type SliderBaseProps } from "./slider/multiSlider"; +export { type NumberRange, RangeSlider, type RangeSliderProps } from "./slider/rangeSlider"; +export { Section, type SectionElevation, type SectionProps } from "./section/section"; +export { SectionCard, type SectionCardProps } from "./section/sectionCard"; +export { Slider, type SliderProps } from "./slider/slider"; +export { Spinner, type SpinnerProps, SpinnerSize } from "./spinner/spinner"; +export { SwitchCard, type SwitchCardProps } from "./control-card/switchCard"; +export { Tab, type TabId, type TabProps } from "./tabs/tab"; // eslint-disable-next-line deprecation/deprecation -export { Tabs, TabsProps, TabsExpander, Expander } from "./tabs/tabs"; -export { Tag, TagProps } from "./tag/tag"; -export { TagInput, TagInputProps, TagInputAddMethod } from "./tag-input/tagInput"; +export { Tabs, type TabsProps, TabsExpander, Expander } from "./tabs/tabs"; +export { Tag, type TagProps } from "./tag/tag"; +export { TagInput, type TagInputProps, type TagInputAddMethod } from "./tag-input/tagInput"; export { OverlayToaster } from "./toast/overlayToaster"; export type { OverlayToasterProps, ToasterPosition } from "./toast/overlayToasterProps"; -export { Toast, ToastProps } from "./toast/toast"; -export { Toaster, ToastOptions } from "./toast/toaster"; -export { TooltipProps, Tooltip } from "./tooltip/tooltip"; -export { Tree, TreeProps } from "./tree/tree"; -export { TreeNodeInfo, TreeEventHandler } from "./tree/treeTypes"; -export { TreeNode, TreeNodeProps } from "./tree/treeNode"; +export { Toast, type ToastProps } from "./toast/toast"; +export { Toaster, type ToastOptions } from "./toast/toaster"; +export { type TooltipProps, Tooltip } from "./tooltip/tooltip"; +export { Tree, type TreeProps } from "./tree/tree"; +export type { TreeNodeInfo, TreeEventHandler } from "./tree/treeTypes"; +export { TreeNode, type TreeNodeProps } from "./tree/treeNode"; diff --git a/packages/core/src/components/popover/popoverSharedProps.ts b/packages/core/src/components/popover/popoverSharedProps.ts index cee512109c..86c778f70e 100644 --- a/packages/core/src/components/popover/popoverSharedProps.ts +++ b/packages/core/src/components/popover/popoverSharedProps.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Boundary, Modifier, Placement, placements, RootBoundary, StrictModifiers } from "@popperjs/core"; +import type { Boundary, Modifier, Placement, RootBoundary, StrictModifiers } from "@popperjs/core"; import type * as React from "react"; import type { StrictModifier } from "react-popper"; @@ -30,7 +30,7 @@ export const PopoverPosition = { // eslint-disable-next-line @typescript-eslint/no-redeclare export type PopoverPosition = (typeof PopoverPosition)[keyof typeof PopoverPosition]; -export { Boundary as PopperBoundary, Placement, placements as PopperPlacements }; +export { Boundary as PopperBoundary, Placement }; // copied from @popperjs/core, where it is not exported as public export type StrictModifierNames = NonNullable; diff --git a/packages/core/src/components/popover/popperUtils.ts b/packages/core/src/components/popover/popperUtils.ts index 5131d4d73d..eebf953505 100644 --- a/packages/core/src/components/popover/popperUtils.ts +++ b/packages/core/src/components/popover/popperUtils.ts @@ -16,6 +16,8 @@ import type { BasePlacement, Placement } from "@popperjs/core"; +export { placements as PopperPlacements } from "@popperjs/core"; + // Popper placement utils // ====================== diff --git a/packages/core/src/context/index.ts b/packages/core/src/context/index.ts index 3982f21ae1..7533dd66e1 100644 --- a/packages/core/src/context/index.ts +++ b/packages/core/src/context/index.ts @@ -16,8 +16,8 @@ export { HotkeysContext, - HotkeysContextInstance, + type HotkeysContextInstance, HotkeysProvider, - HotkeysProviderProps, + type HotkeysProviderProps, } from "./hotkeys/hotkeysProvider"; -export { PortalContext, PortalContextOptions, PortalProvider } from "./portal/portalProvider"; +export { PortalContext, type PortalContextOptions, PortalProvider } from "./portal/portalProvider"; diff --git a/packages/core/src/hooks/index.ts b/packages/core/src/hooks/index.ts index 62c1045df2..feb3afba0f 100644 --- a/packages/core/src/hooks/index.ts +++ b/packages/core/src/hooks/index.ts @@ -14,6 +14,6 @@ * limitations under the License. */ -export { HotkeyConfig } from "./hotkeys/hotkeyConfig"; -export { useHotkeys, UseHotkeysOptions, UseHotkeysReturnValue } from "./hotkeys/useHotkeys"; +export type { HotkeyConfig } from "./hotkeys/hotkeyConfig"; +export { useHotkeys, type UseHotkeysOptions, type UseHotkeysReturnValue } from "./hotkeys/useHotkeys"; export { useAsyncControllableValue } from "./useAsyncControllableValue"; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 568eb8d6df..4312ef82a6 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -34,4 +34,4 @@ export { hideHotkeysDialog, hideHotkeysDialogAfterDelay, } from "./legacy/hotkeysDialogLegacy"; -export { ContextMenuTargetLegacy, ContextMenuTargetLegacyComponent } from "./legacy/contextMenuTargetLegacy"; +export { ContextMenuTargetLegacy, type ContextMenuTargetLegacyComponent } from "./legacy/contextMenuTargetLegacy"; From 98f88c1d47355733da0a96e24daec8435fd822ae Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 09:58:17 -0400 Subject: [PATCH 07/19] [eslint-plugin, tslint-config] annotate type-only imports --- .../rules/no-deprecated-components/no-deprecated-components.ts | 2 +- .../no-deprecated-components/no-deprecated-core-components.ts | 2 +- .../no-deprecated-datetime-components.ts | 2 +- .../no-deprecated-datetime2-components.ts | 2 +- .../no-deprecated-select-components.ts | 2 +- .../no-deprecated-components/no-deprecated-table-components.ts | 2 +- .../eslint-plugin/src/rules/no-deprecated-type-references.ts | 2 +- packages/eslint-plugin/src/rules/utils/fixList.ts | 2 +- packages/tslint-config/package.json | 3 ++- packages/tslint-config/src/rules/utils/addImportToFile.ts | 2 +- packages/tslint-config/src/rules/utils/replaceTagName.ts | 2 +- 11 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-components.ts b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-components.ts index f2f3842269..d22acb619e 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-components.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-components.ts @@ -2,7 +2,7 @@ * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; import { createNoDeprecatedComponentsRule } from "./createNoDeprecatedComponentsRule"; import { coreComponentsMigrationMapping } from "./no-deprecated-core-components"; diff --git a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-core-components.ts b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-core-components.ts index 4faef29ed1..14b777ec14 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-core-components.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-core-components.ts @@ -2,7 +2,7 @@ * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; import { createNoDeprecatedComponentsRule } from "./createNoDeprecatedComponentsRule"; diff --git a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime-components.ts b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime-components.ts index 592b8f548f..d22517abac 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime-components.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime-components.ts @@ -2,7 +2,7 @@ * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; import { createNoDeprecatedComponentsRule } from "./createNoDeprecatedComponentsRule"; diff --git a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime2-components.ts b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime2-components.ts index 27aac4f78b..2d5b3ff7d8 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime2-components.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-datetime2-components.ts @@ -2,7 +2,7 @@ * (c) Copyright 2023 Palantir Technologies Inc. All rights reserved. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; import { createNoDeprecatedComponentsRule } from "./createNoDeprecatedComponentsRule"; diff --git a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-select-components.ts b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-select-components.ts index b60fad0ee1..5b008d86fa 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-select-components.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-select-components.ts @@ -2,7 +2,7 @@ * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; import { createNoDeprecatedComponentsRule } from "./createNoDeprecatedComponentsRule"; diff --git a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-table-components.ts b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-table-components.ts index dacf529bfc..80dc627bcd 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-table-components.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-components/no-deprecated-table-components.ts @@ -2,7 +2,7 @@ * (c) Copyright 2022 Palantir Technologies Inc. All rights reserved. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; import { createNoDeprecatedComponentsRule } from "./createNoDeprecatedComponentsRule"; diff --git a/packages/eslint-plugin/src/rules/no-deprecated-type-references.ts b/packages/eslint-plugin/src/rules/no-deprecated-type-references.ts index b5a10357d6..c06c4ca6a8 100644 --- a/packages/eslint-plugin/src/rules/no-deprecated-type-references.ts +++ b/packages/eslint-plugin/src/rules/no-deprecated-type-references.ts @@ -4,7 +4,7 @@ // tslint:disable object-literal-sort-keys -import { TSESLint, TSESTree } from "@typescript-eslint/utils"; +import { type TSESLint, TSESTree } from "@typescript-eslint/utils"; import { createRule } from "./utils/createRule"; import { FixList } from "./utils/fixList"; diff --git a/packages/eslint-plugin/src/rules/utils/fixList.ts b/packages/eslint-plugin/src/rules/utils/fixList.ts index 698daaa813..830283b00a 100644 --- a/packages/eslint-plugin/src/rules/utils/fixList.ts +++ b/packages/eslint-plugin/src/rules/utils/fixList.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { TSESLint } from "@typescript-eslint/utils"; +import type { TSESLint } from "@typescript-eslint/utils"; type RuleFix = TSESLint.RuleFix; diff --git a/packages/tslint-config/package.json b/packages/tslint-config/package.json index 901adbd75d..9943f40f00 100644 --- a/packages/tslint-config/package.json +++ b/packages/tslint-config/package.json @@ -8,7 +8,8 @@ }, "dependencies": { "tslib": "~2.5.0", - "tslint-react": "^5.0.0" + "tslint-react": "^5.0.0", + "tsutils": "^3.21.0" }, "peerDependencies": { "tslint": "^6.0.0" diff --git a/packages/tslint-config/src/rules/utils/addImportToFile.ts b/packages/tslint-config/src/rules/utils/addImportToFile.ts index 0a44c26a6e..f21173ca0c 100644 --- a/packages/tslint-config/src/rules/utils/addImportToFile.ts +++ b/packages/tslint-config/src/rules/utils/addImportToFile.ts @@ -16,7 +16,7 @@ import { Replacement } from "tslint"; import { isImportDeclaration, isNamedImports } from "tsutils/typeguard/2.8"; -import * as ts from "typescript"; +import type * as ts from "typescript"; export function addImportToFile(file: ts.SourceFile, imports: string[], packageName: string) { const packageToModify = file.statements.find( diff --git a/packages/tslint-config/src/rules/utils/replaceTagName.ts b/packages/tslint-config/src/rules/utils/replaceTagName.ts index 8c0abf81e4..a76d2cf1a7 100644 --- a/packages/tslint-config/src/rules/utils/replaceTagName.ts +++ b/packages/tslint-config/src/rules/utils/replaceTagName.ts @@ -15,7 +15,7 @@ */ import { Replacement } from "tslint"; -import { JsxTagNameExpression } from "typescript"; +import type { JsxTagNameExpression } from "typescript"; /** Replace the name of a JSX tag. */ export function replaceTagName(tagName: JsxTagNameExpression, newTagName: string) { From 024df9be1b238fc250e257308d07d7920a53480a Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 09:59:30 -0400 Subject: [PATCH 08/19] [test-commons] annotate type-only imports --- packages/test-commons/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/test-commons/src/utils.ts b/packages/test-commons/src/utils.ts index 6822b33698..5060d3cc95 100644 --- a/packages/test-commons/src/utils.ts +++ b/packages/test-commons/src/utils.ts @@ -15,7 +15,7 @@ */ import { expect } from "chai"; -import * as React from "react"; +import type * as React from "react"; /** * Dispatch a native KeyBoardEvent on the target element with the given type From ec6db9a0bf308c09d5ff8af897cae06dbca8ad11 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 10:52:28 -0400 Subject: [PATCH 09/19] [docs-theme,icons,select,table] annotate type imports --- packages/core/src/components/index.ts | 11 ++--------- .../src/components/popover/popoverMigrationUtils.ts | 4 ++-- packages/datetime/src/common/timePickerProps.ts | 2 +- packages/docs-theme/src/common/context.ts | 2 +- packages/docs-theme/src/components/block.tsx | 4 ++-- packages/docs-theme/src/components/documentation.tsx | 2 +- packages/docs-theme/src/components/example.tsx | 2 +- packages/docs-theme/src/components/navButton.tsx | 2 +- packages/docs-theme/src/components/navMenuItem.tsx | 2 +- packages/docs-theme/src/components/navigator.tsx | 2 +- packages/docs-theme/src/components/page.tsx | 4 ++-- .../docs-theme/src/components/typescript/apiLink.tsx | 2 +- .../src/components/typescript/enumTable.tsx | 4 ++-- .../src/components/typescript/typeAliasTable.tsx | 4 ++-- packages/docs-theme/src/tags/css.tsx | 2 +- packages/docs-theme/src/tags/defaults.ts | 4 ++-- packages/docs-theme/src/tags/heading.tsx | 2 +- packages/docs-theme/src/tags/index.ts | 2 +- packages/docs-theme/src/tags/method.tsx | 2 +- packages/docs-theme/src/tags/reactDocs.tsx | 2 +- packages/docs-theme/src/tags/reactExample.tsx | 4 ++-- packages/docs-theme/src/tags/see.tsx | 2 +- packages/docs-theme/src/tags/typescript.tsx | 2 +- .../test/no-deprecated-type-references.test.ts | 2 +- packages/icons/src/allPaths.ts | 2 +- .../icons/src/paths-loaders/splitPathsBySizeLoader.ts | 2 +- packages/icons/src/svgIconProps.ts | 2 +- packages/icons/src/type-utils/camel-case.ts | 4 ++-- packages/icons/src/type-utils/delimiter-case.ts | 2 +- packages/icons/src/type-utils/index.ts | 9 ++++++--- packages/icons/src/type-utils/pascal-case.ts | 2 +- packages/icons/src/type-utils/screaming-snake-case.ts | 6 +++--- packages/icons/src/type-utils/snake-case.ts | 2 +- packages/select/src/common/itemRenderer.ts | 2 +- packages/select/src/common/listItemsProps.ts | 8 ++++---- packages/table/src/column.tsx | 6 +++--- packages/table/src/common/grid.ts | 2 +- packages/table/src/common/internal/directionUtils.ts | 2 +- packages/table/src/common/rect.ts | 2 +- packages/table/src/headers/columnHeader.tsx | 6 +++--- packages/table/src/headers/header.tsx | 10 +++++----- packages/table/src/headers/rowHeader.tsx | 6 +++--- packages/table/src/interactions/dragEvents.ts | 2 +- packages/table/src/interactions/draggable.tsx | 2 +- .../src/interactions/menus/copyCellsMenuItem.tsx | 2 +- packages/table/src/interactions/reorderable.tsx | 2 +- packages/table/src/interactions/resizeHandle.tsx | 4 ++-- packages/table/src/interactions/selectable.tsx | 2 +- packages/table/src/layers/regions.tsx | 2 +- packages/table/src/quadrants/tableQuadrant.tsx | 2 +- packages/table/src/quadrants/tableQuadrantStack.tsx | 2 +- packages/table/src/table.tsx | 2 +- packages/table/src/table2.tsx | 2 +- packages/table/src/table2Utils.ts | 2 +- packages/table/src/tableBody.tsx | 4 ++-- packages/table/src/tableBodyCells.tsx | 2 +- packages/table/src/tableHotkeys.ts | 2 +- packages/table/src/tableState.ts | 2 +- 58 files changed, 89 insertions(+), 93 deletions(-) diff --git a/packages/core/src/components/index.ts b/packages/core/src/components/index.ts index 888c88cfaa..621c8e9fdb 100644 --- a/packages/core/src/components/index.ts +++ b/packages/core/src/components/index.ts @@ -66,14 +66,7 @@ export { Blockquote, Code, H1, H2, H3, H4, H5, H6, Label, OL, Pre, UL } from "./ export { HTMLSelect, type HTMLSelectIconName, type HTMLSelectProps } from "./html-select/htmlSelect"; export { HTMLTable, type HTMLTableProps } from "./html-table/htmlTable"; export * from "./hotkeys"; -export { - type DefaultIconProps, - Icon, - type IconComponent, - type IconName, - type IconProps, - type IconSize, -} from "./icon/icon"; +export { type DefaultIconProps, Icon, type IconComponent, type IconName, type IconProps, IconSize } from "./icon/icon"; export { Menu, type MenuProps } from "./menu/menu"; export { MenuDivider, type MenuDividerProps } from "./menu/menuDivider"; export { MenuItem, type MenuItemProps } from "./menu/menuItem"; @@ -106,7 +99,7 @@ export type { StrictModifierNames, } from "./popover/popoverSharedProps"; export { PopperPlacements } from "./popover/popperUtils"; -export type { PopupKind } from "./popover/popupKind"; +export { PopupKind } from "./popover/popupKind"; export { Portal, type PortalProps, type PortalLegacyContext } from "./portal/portal"; export { ProgressBar, type ProgressBarProps } from "./progress-bar/progressBar"; export { type ResizeEntry, ResizeSensor, type ResizeSensorProps } from "./resize-sensor/resizeSensor"; diff --git a/packages/core/src/components/popover/popoverMigrationUtils.ts b/packages/core/src/components/popover/popoverMigrationUtils.ts index 45d1731871..bdd2b28c9a 100644 --- a/packages/core/src/components/popover/popoverMigrationUtils.ts +++ b/packages/core/src/components/popover/popoverMigrationUtils.ts @@ -14,10 +14,10 @@ * limitations under the License. */ -import { Placement } from "@popperjs/core"; +import type { Placement } from "@popperjs/core"; import { Position } from "../../common/position"; -import { PopoverPosition } from "./popoverSharedProps"; +import type { PopoverPosition } from "./popoverSharedProps"; /** * Convert a position to a placement. diff --git a/packages/datetime/src/common/timePickerProps.ts b/packages/datetime/src/common/timePickerProps.ts index 273860db81..6d3ec6e97f 100644 --- a/packages/datetime/src/common/timePickerProps.ts +++ b/packages/datetime/src/common/timePickerProps.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import { TimePrecision } from "./timePrecision"; import { TimeUnit } from "./timeUnit"; diff --git a/packages/docs-theme/src/common/context.ts b/packages/docs-theme/src/common/context.ts index 5ceb3fcc44..fc57c01fea 100644 --- a/packages/docs-theme/src/common/context.ts +++ b/packages/docs-theme/src/common/context.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { +import type { IBlock, IKssPluginData, IMarkdownPluginData, diff --git a/packages/docs-theme/src/components/block.tsx b/packages/docs-theme/src/components/block.tsx index 3e891af4e7..0cdea65657 100644 --- a/packages/docs-theme/src/components/block.tsx +++ b/packages/docs-theme/src/components/block.tsx @@ -14,13 +14,13 @@ * limitations under the License. */ -import { IBlock } from "@documentalist/client"; +import type { IBlock } from "@documentalist/client"; import classNames from "classnames"; import * as React from "react"; import { Classes, Code, H3 } from "@blueprintjs/core"; -import { TagRendererMap } from "../tags"; +import type { TagRendererMap } from "../tags"; export function renderBlock( /** the block to render */ diff --git a/packages/docs-theme/src/components/documentation.tsx b/packages/docs-theme/src/components/documentation.tsx index 5bd27e2b85..70db5da629 100644 --- a/packages/docs-theme/src/components/documentation.tsx +++ b/packages/docs-theme/src/components/documentation.tsx @@ -28,7 +28,7 @@ import { renderBlock } from "./block"; import { NavButton } from "./navButton"; import { Navigator } from "./navigator"; import { NavMenu } from "./navMenu"; -import { NavMenuItemProps } from "./navMenuItem"; +import type { NavMenuItemProps } from "./navMenuItem"; import { Page } from "./page"; import { addScrollbarStyle } from "./scrollbar"; import { ApiLink } from "./typescript/apiLink"; diff --git a/packages/docs-theme/src/components/example.tsx b/packages/docs-theme/src/components/example.tsx index e40bf6cb69..18f3fbcfa5 100644 --- a/packages/docs-theme/src/components/example.tsx +++ b/packages/docs-theme/src/components/example.tsx @@ -17,7 +17,7 @@ import classNames from "classnames"; import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; export interface ExampleProps extends Props { /** diff --git a/packages/docs-theme/src/components/navButton.tsx b/packages/docs-theme/src/components/navButton.tsx index 3fcc4deeb1..52202e65c4 100644 --- a/packages/docs-theme/src/components/navButton.tsx +++ b/packages/docs-theme/src/components/navButton.tsx @@ -18,7 +18,7 @@ import classNames from "classnames"; import * as React from "react"; import { Classes, Icon, KeyComboTag } from "@blueprintjs/core"; -import { IconName } from "@blueprintjs/icons"; +import type { IconName } from "@blueprintjs/icons"; export interface NavButtonProps { icon: IconName | JSX.Element; diff --git a/packages/docs-theme/src/components/navMenuItem.tsx b/packages/docs-theme/src/components/navMenuItem.tsx index a91c7cab62..b4a4371e13 100644 --- a/packages/docs-theme/src/components/navMenuItem.tsx +++ b/packages/docs-theme/src/components/navMenuItem.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IHeadingNode, IPageNode } from "@documentalist/client"; +import type { IHeadingNode, IPageNode } from "@documentalist/client"; import classNames from "classnames"; import * as React from "react"; diff --git a/packages/docs-theme/src/components/navigator.tsx b/packages/docs-theme/src/components/navigator.tsx index e86f84c1b4..6ce6242c20 100644 --- a/packages/docs-theme/src/components/navigator.tsx +++ b/packages/docs-theme/src/components/navigator.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IHeadingNode, IPageNode } from "@documentalist/client"; +import type { IHeadingNode, IPageNode } from "@documentalist/client"; import { filter } from "fuzzaldrin-plus"; import * as React from "react"; diff --git a/packages/docs-theme/src/components/page.tsx b/packages/docs-theme/src/components/page.tsx index 58fbf1eee5..2d196ad423 100644 --- a/packages/docs-theme/src/components/page.tsx +++ b/packages/docs-theme/src/components/page.tsx @@ -14,12 +14,12 @@ * limitations under the License. */ -import { IPageData } from "@documentalist/client"; +import type { IPageData } from "@documentalist/client"; import * as React from "react"; import { Classes } from "@blueprintjs/core"; -import { TagRendererMap } from "../tags"; +import type { TagRendererMap } from "../tags"; import { renderBlock } from "./block"; export interface PageProps { diff --git a/packages/docs-theme/src/components/typescript/apiLink.tsx b/packages/docs-theme/src/components/typescript/apiLink.tsx index 30ff041f0b..afd13e1570 100644 --- a/packages/docs-theme/src/components/typescript/apiLink.tsx +++ b/packages/docs-theme/src/components/typescript/apiLink.tsx @@ -16,7 +16,7 @@ import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import { COMPONENT_DISPLAY_NAMESPACE } from "../../common"; import { DocumentationContext } from "../../common/context"; diff --git a/packages/docs-theme/src/components/typescript/enumTable.tsx b/packages/docs-theme/src/components/typescript/enumTable.tsx index a3b5576638..ad50dc735a 100644 --- a/packages/docs-theme/src/components/typescript/enumTable.tsx +++ b/packages/docs-theme/src/components/typescript/enumTable.tsx @@ -14,11 +14,11 @@ * limitations under the License. */ -import { ITsEnum, ITsEnumMember } from "@documentalist/client"; +import type { ITsEnum, ITsEnumMember } from "@documentalist/client"; import classNames from "classnames"; import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import { COMPONENT_DISPLAY_NAMESPACE } from "../../common"; import { DocumentationContext } from "../../common/context"; diff --git a/packages/docs-theme/src/components/typescript/typeAliasTable.tsx b/packages/docs-theme/src/components/typescript/typeAliasTable.tsx index f4400f10a2..17e34a3ea8 100644 --- a/packages/docs-theme/src/components/typescript/typeAliasTable.tsx +++ b/packages/docs-theme/src/components/typescript/typeAliasTable.tsx @@ -14,11 +14,11 @@ * limitations under the License. */ -import { ITsTypeAlias } from "@documentalist/client"; +import type { ITsTypeAlias } from "@documentalist/client"; import classNames from "classnames"; import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import { COMPONENT_DISPLAY_NAMESPACE } from "../../common"; import { DocumentationContext } from "../../common/context"; diff --git a/packages/docs-theme/src/tags/css.tsx b/packages/docs-theme/src/tags/css.tsx index 2edbf41237..4c7c25ceeb 100644 --- a/packages/docs-theme/src/tags/css.tsx +++ b/packages/docs-theme/src/tags/css.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IKssPluginData, ITag } from "@documentalist/client"; +import type { IKssPluginData, ITag } from "@documentalist/client"; import classNames from "classnames"; import * as React from "react"; diff --git a/packages/docs-theme/src/tags/defaults.ts b/packages/docs-theme/src/tags/defaults.ts index 5be8b990c1..1a006e53af 100644 --- a/packages/docs-theme/src/tags/defaults.ts +++ b/packages/docs-theme/src/tags/defaults.ts @@ -14,8 +14,8 @@ * limitations under the License. */ -import { ITag } from "@documentalist/client"; -import * as React from "react"; +import type { ITag } from "@documentalist/client"; +import type * as React from "react"; import { CssExample } from "./css"; import { Heading } from "./heading"; diff --git a/packages/docs-theme/src/tags/heading.tsx b/packages/docs-theme/src/tags/heading.tsx index 1d763b6ef9..e1ed021802 100644 --- a/packages/docs-theme/src/tags/heading.tsx +++ b/packages/docs-theme/src/tags/heading.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { IHeadingTag } from "@documentalist/client"; +import type { IHeadingTag } from "@documentalist/client"; import classNames from "classnames"; import * as React from "react"; diff --git a/packages/docs-theme/src/tags/index.ts b/packages/docs-theme/src/tags/index.ts index a2716b595b..68383fe001 100644 --- a/packages/docs-theme/src/tags/index.ts +++ b/packages/docs-theme/src/tags/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ITag } from "@documentalist/client"; +import type { ITag } from "@documentalist/client"; export interface TagRendererMap { [tagName: string]: React.ComponentType | undefined; diff --git a/packages/docs-theme/src/tags/method.tsx b/packages/docs-theme/src/tags/method.tsx index 4301a58f02..325017abbb 100644 --- a/packages/docs-theme/src/tags/method.tsx +++ b/packages/docs-theme/src/tags/method.tsx @@ -17,7 +17,7 @@ import { isTsClass, isTsMethod, ITag, ITsClass, ITypescriptPluginData } from "@documentalist/client"; import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import { COMPONENT_DISPLAY_NAMESPACE } from "../common"; import { DocumentationContext } from "../common/context"; diff --git a/packages/docs-theme/src/tags/reactDocs.tsx b/packages/docs-theme/src/tags/reactDocs.tsx index b06e06723b..7604ea85c0 100644 --- a/packages/docs-theme/src/tags/reactDocs.tsx +++ b/packages/docs-theme/src/tags/reactDocs.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ITag } from "@documentalist/client"; +import type { ITag } from "@documentalist/client"; import * as React from "react"; export interface DocsMap { diff --git a/packages/docs-theme/src/tags/reactExample.tsx b/packages/docs-theme/src/tags/reactExample.tsx index 179a5c87e9..812bed93c7 100644 --- a/packages/docs-theme/src/tags/reactExample.tsx +++ b/packages/docs-theme/src/tags/reactExample.tsx @@ -14,13 +14,13 @@ * limitations under the License. */ -import { ITag } from "@documentalist/client"; +import type { ITag } from "@documentalist/client"; import * as React from "react"; import { AnchorButton, Intent } from "@blueprintjs/core"; import { Code } from "@blueprintjs/icons"; -import { ExampleProps } from "../components/example"; +import type { ExampleProps } from "../components/example"; export interface ExampleRenderInfo { sourceUrl: string; diff --git a/packages/docs-theme/src/tags/see.tsx b/packages/docs-theme/src/tags/see.tsx index 118cee05d8..08c26ed8c0 100644 --- a/packages/docs-theme/src/tags/see.tsx +++ b/packages/docs-theme/src/tags/see.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ITag } from "@documentalist/client"; +import type { ITag } from "@documentalist/client"; import * as React from "react"; import { COMPONENT_DISPLAY_NAMESPACE } from "../common"; diff --git a/packages/docs-theme/src/tags/typescript.tsx b/packages/docs-theme/src/tags/typescript.tsx index 1c0fe61f17..c43cb41c82 100644 --- a/packages/docs-theme/src/tags/typescript.tsx +++ b/packages/docs-theme/src/tags/typescript.tsx @@ -17,7 +17,7 @@ import { isTsClass, isTsEnum, isTsInterface, isTsTypeAlias, ITag, ITypescriptPluginData } from "@documentalist/client"; import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import { COMPONENT_DISPLAY_NAMESPACE } from "../common"; import { DocumentationContext } from "../common/context"; diff --git a/packages/eslint-plugin/test/no-deprecated-type-references.test.ts b/packages/eslint-plugin/test/no-deprecated-type-references.test.ts index d1c4c8e0e0..fc4a7ed4b6 100644 --- a/packages/eslint-plugin/test/no-deprecated-type-references.test.ts +++ b/packages/eslint-plugin/test/no-deprecated-type-references.test.ts @@ -49,7 +49,7 @@ ruleTester.run("no-deprecated-type-references", noDeprecatedTypeReferencesRule, }, ], output: dedent` - import { Props } from "@blueprintjs/core"; + import type { Props } from "@blueprintjs/core"; export interface MyInterface extends Props { foo: string; diff --git a/packages/icons/src/allPaths.ts b/packages/icons/src/allPaths.ts index dca3f17af4..145a337425 100644 --- a/packages/icons/src/allPaths.ts +++ b/packages/icons/src/allPaths.ts @@ -18,7 +18,7 @@ import { pascalCase } from "change-case"; import * as IconSvgPaths16 from "./generated/16px/paths"; import * as IconSvgPaths20 from "./generated/20px/paths"; -import { IconName } from "./iconNames"; +import type { IconName } from "./iconNames"; import { IconPaths, IconSize } from "./iconTypes"; import type { PascalCase } from "./type-utils"; export { IconSvgPaths16, IconSvgPaths20 }; diff --git a/packages/icons/src/paths-loaders/splitPathsBySizeLoader.ts b/packages/icons/src/paths-loaders/splitPathsBySizeLoader.ts index daa774fa0e..d8f156aa9b 100644 --- a/packages/icons/src/paths-loaders/splitPathsBySizeLoader.ts +++ b/packages/icons/src/paths-loaders/splitPathsBySizeLoader.ts @@ -17,7 +17,7 @@ import { pascalCase } from "change-case"; import type { IconPathsLoader } from "../iconLoader"; -import { IconName } from "../iconNames"; +import type { IconName } from "../iconNames"; import { IconPaths, IconSize } from "../iconTypes"; import type { PascalCase } from "../type-utils"; diff --git a/packages/icons/src/svgIconProps.ts b/packages/icons/src/svgIconProps.ts index 50a8a275da..616f998281 100644 --- a/packages/icons/src/svgIconProps.ts +++ b/packages/icons/src/svgIconProps.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import * as React from "react"; +import type * as React from "react"; type OmittedDOMAttributes = "children" | "dangerouslySetInnerHTML"; diff --git a/packages/icons/src/type-utils/camel-case.ts b/packages/icons/src/type-utils/camel-case.ts index f9275cebb1..fd2469dd3a 100644 --- a/packages/icons/src/type-utils/camel-case.ts +++ b/packages/icons/src/type-utils/camel-case.ts @@ -1,5 +1,5 @@ -import { WordSeparators } from "./sourceUtilities"; -import { Split } from "./utilities"; +import type { WordSeparators } from "./sourceUtilities"; +import type { Split } from "./utilities"; /** Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder. diff --git a/packages/icons/src/type-utils/delimiter-case.ts b/packages/icons/src/type-utils/delimiter-case.ts index c5f3d4112c..4d2d116f21 100644 --- a/packages/icons/src/type-utils/delimiter-case.ts +++ b/packages/icons/src/type-utils/delimiter-case.ts @@ -1,4 +1,4 @@ -import { UpperCaseCharacters, WordSeparators } from "./sourceUtilities"; +import type { UpperCaseCharacters, WordSeparators } from "./sourceUtilities"; /** Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters. diff --git a/packages/icons/src/type-utils/index.ts b/packages/icons/src/type-utils/index.ts index f8fb3b7f85..e2d8feb8f9 100644 --- a/packages/icons/src/type-utils/index.ts +++ b/packages/icons/src/type-utils/index.ts @@ -14,7 +14,10 @@ * limitations under the License. */ -/** @fileoverview Mapped type utils copied from the "type-fest" package */ +/** + * @fileoverview Mapped type utils copied from the "type-fest" package to avoid a dependency on that package + * (it caused surprising compilation errors downstream). + */ -export { PascalCase } from "./pascal-case"; -export { ScreamingSnakeCase } from "./screaming-snake-case"; +export type { PascalCase } from "./pascal-case"; +export type { ScreamingSnakeCase } from "./screaming-snake-case"; diff --git a/packages/icons/src/type-utils/pascal-case.ts b/packages/icons/src/type-utils/pascal-case.ts index 456e1d0915..67c9658352 100644 --- a/packages/icons/src/type-utils/pascal-case.ts +++ b/packages/icons/src/type-utils/pascal-case.ts @@ -1,4 +1,4 @@ -import { CamelCase } from "./camel-case"; +import type { CamelCase } from "./camel-case"; /** Converts a string literal to pascal-case. diff --git a/packages/icons/src/type-utils/screaming-snake-case.ts b/packages/icons/src/type-utils/screaming-snake-case.ts index 8843e7d06f..8986a86e90 100644 --- a/packages/icons/src/type-utils/screaming-snake-case.ts +++ b/packages/icons/src/type-utils/screaming-snake-case.ts @@ -1,6 +1,6 @@ -import { SplitIncludingDelimiters } from "./delimiter-case"; -import { SnakeCase } from "./snake-case"; -import { Includes } from "./includes"; +import type { SplitIncludingDelimiters } from "./delimiter-case"; +import type { SnakeCase } from "./snake-case"; +import type { Includes } from "./includes"; /** Returns a boolean for whether the string is screaming snake case. diff --git a/packages/icons/src/type-utils/snake-case.ts b/packages/icons/src/type-utils/snake-case.ts index a86f3dbedd..72d7104da6 100644 --- a/packages/icons/src/type-utils/snake-case.ts +++ b/packages/icons/src/type-utils/snake-case.ts @@ -1,4 +1,4 @@ -import { DelimiterCase } from "./delimiter-case"; +import type { DelimiterCase } from "./delimiter-case"; /** Convert a string literal to snake-case. diff --git a/packages/select/src/common/itemRenderer.ts b/packages/select/src/common/itemRenderer.ts index 5d9db0638e..037c8c1739 100644 --- a/packages/select/src/common/itemRenderer.ts +++ b/packages/select/src/common/itemRenderer.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as React from "react"; +import type * as React from "react"; export interface ItemModifiers { /** Whether this is the "active" (focused) item, meaning keyboard interactions will act upon it. */ diff --git a/packages/select/src/common/listItemsProps.ts b/packages/select/src/common/listItemsProps.ts index 3f4ed7fe77..ccfa7986ee 100644 --- a/packages/select/src/common/listItemsProps.ts +++ b/packages/select/src/common/listItemsProps.ts @@ -16,10 +16,10 @@ import { Props, Utils } from "@blueprintjs/core"; -import { ItemListRenderer } from "./itemListRenderer"; -import { ItemRenderer } from "./itemRenderer"; -import { CreateNewItem } from "./listItemsUtils"; -import { ItemListPredicate, ItemPredicate } from "./predicate"; +import type { ItemListRenderer } from "./itemListRenderer"; +import type { ItemRenderer } from "./itemRenderer"; +import type { CreateNewItem } from "./listItemsUtils"; +import type { ItemListPredicate, ItemPredicate } from "./predicate"; /** * Equality test comparator to determine if two {@link ListItemsProps} items are equivalent. diff --git a/packages/table/src/column.tsx b/packages/table/src/column.tsx index 8258898fa1..a4a4118272 100644 --- a/packages/table/src/column.tsx +++ b/packages/table/src/column.tsx @@ -19,9 +19,9 @@ import * as React from "react"; import { DISPLAYNAME_PREFIX, Props } from "@blueprintjs/core"; import { CellRenderer, emptyCellRenderer } from "./cell/cell"; -import { ColumnHeaderRenderer } from "./headers/columnHeader"; -import { ColumnNameProps } from "./headers/columnHeaderCell"; -import { ColumnLoadingOption } from "./regions"; +import type { ColumnHeaderRenderer } from "./headers/columnHeader"; +import type { ColumnNameProps } from "./headers/columnHeaderCell"; +import type { ColumnLoadingOption } from "./regions"; export interface ColumnProps extends ColumnNameProps, Props { /** diff --git a/packages/table/src/common/grid.ts b/packages/table/src/common/grid.ts index 75cd68f96f..98491037bf 100644 --- a/packages/table/src/common/grid.ts +++ b/packages/table/src/common/grid.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { CSSProperties } from "react"; +import type { CSSProperties } from "react"; import { Region, RegionCardinality, Regions } from "../regions"; import * as Classes from "./classes"; diff --git a/packages/table/src/common/internal/directionUtils.ts b/packages/table/src/common/internal/directionUtils.ts index ce4ef244cf..631441b12c 100644 --- a/packages/table/src/common/internal/directionUtils.ts +++ b/packages/table/src/common/internal/directionUtils.ts @@ -15,7 +15,7 @@ */ import { Direction } from "../direction"; -import { MovementDelta } from "../movementDelta"; +import type { MovementDelta } from "../movementDelta"; export function directionToDelta(direction: Direction): MovementDelta { switch (direction) { diff --git a/packages/table/src/common/rect.ts b/packages/table/src/common/rect.ts index 4724f6a8b7..19a0d37653 100644 --- a/packages/table/src/common/rect.ts +++ b/packages/table/src/common/rect.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import * as React from "react"; +import type * as React from "react"; export type AnyRect = Rect | DOMRect; diff --git a/packages/table/src/headers/columnHeader.tsx b/packages/table/src/headers/columnHeader.tsx index f0d7ff0789..f16e0196bb 100644 --- a/packages/table/src/headers/columnHeader.tsx +++ b/packages/table/src/headers/columnHeader.tsx @@ -18,10 +18,10 @@ import classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; -import { ColumnIndices } from "../common/grid"; +import type { ColumnIndices } from "../common/grid"; import { Utils } from "../common/index"; -import { ClientCoordinates } from "../interactions/dragTypes"; -import { IndexedResizeCallback } from "../interactions/resizable"; +import type { ClientCoordinates } from "../interactions/dragTypes"; +import type { IndexedResizeCallback } from "../interactions/resizable"; import { Orientation } from "../interactions/resizeHandle"; import { RegionCardinality, Regions } from "../regions"; import { ColumnHeaderCell, ColumnHeaderCellProps } from "./columnHeaderCell"; diff --git a/packages/table/src/headers/header.tsx b/packages/table/src/headers/header.tsx index fef7514689..477354afcf 100644 --- a/packages/table/src/headers/header.tsx +++ b/packages/table/src/headers/header.tsx @@ -20,19 +20,19 @@ import * as React from "react"; import { Utils as CoreUtils } from "@blueprintjs/core"; import { DragHandleVertical } from "@blueprintjs/icons"; -import { Grid } from "../common"; +import type { Grid } from "../common"; import type { FocusedCellCoordinates } from "../common/cellTypes"; import * as Classes from "../common/classes"; import { CLASSNAME_EXCLUDED_FROM_TEXT_MEASUREMENT } from "../common/utils"; import { DragEvents } from "../interactions/dragEvents"; -import { ClientCoordinates, CoordinateData } from "../interactions/dragTypes"; +import type { ClientCoordinates, CoordinateData } from "../interactions/dragTypes"; import { DragReorderable, ReorderableProps } from "../interactions/reorderable"; import { Resizable } from "../interactions/resizable"; -import { LockableLayout, Orientation } from "../interactions/resizeHandle"; +import type { LockableLayout, Orientation } from "../interactions/resizeHandle"; import { DragSelectable, SelectableProps } from "../interactions/selectable"; -import { Locator } from "../locator"; +import type { Locator } from "../locator"; import { Region, RegionCardinality, Regions } from "../regions"; -import { HeaderCellProps } from "./headerCell"; +import type { HeaderCellProps } from "./headerCell"; export type HeaderCellRenderer = (index: number) => React.ReactElement; diff --git a/packages/table/src/headers/rowHeader.tsx b/packages/table/src/headers/rowHeader.tsx index 4ec34602fb..ebd76051f2 100644 --- a/packages/table/src/headers/rowHeader.tsx +++ b/packages/table/src/headers/rowHeader.tsx @@ -18,9 +18,9 @@ import classNames from "classnames"; import * as React from "react"; import * as Classes from "../common/classes"; -import { RowIndices } from "../common/grid"; -import { ClientCoordinates } from "../interactions/dragTypes"; -import { IndexedResizeCallback } from "../interactions/resizable"; +import type { RowIndices } from "../common/grid"; +import type { ClientCoordinates } from "../interactions/dragTypes"; +import type { IndexedResizeCallback } from "../interactions/resizable"; import { Orientation } from "../interactions/resizeHandle"; import { RegionCardinality, Regions } from "../regions"; import { Header, HeaderProps } from "./header"; diff --git a/packages/table/src/interactions/dragEvents.ts b/packages/table/src/interactions/dragEvents.ts index c860bed550..9367f17695 100644 --- a/packages/table/src/interactions/dragEvents.ts +++ b/packages/table/src/interactions/dragEvents.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { ClientCoordinates, CoordinateData, DragHandler } from "./dragTypes"; +import type { ClientCoordinates, CoordinateData, DragHandler } from "./dragTypes"; export class DragEvents { public static DOUBLE_CLICK_TIMEOUT_MSEC = 500; diff --git a/packages/table/src/interactions/draggable.tsx b/packages/table/src/interactions/draggable.tsx index aac5a1e841..aa380c444c 100644 --- a/packages/table/src/interactions/draggable.tsx +++ b/packages/table/src/interactions/draggable.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { Utils as CoreUtils, Props } from "@blueprintjs/core"; import { DragEvents } from "./dragEvents"; -import { DraggableChildrenProps, DragHandler } from "./dragTypes"; +import type { DraggableChildrenProps, DragHandler } from "./dragTypes"; export type DraggableProps = Props & DragHandler & DraggableChildrenProps; diff --git a/packages/table/src/interactions/menus/copyCellsMenuItem.tsx b/packages/table/src/interactions/menus/copyCellsMenuItem.tsx index 15c57a1c1e..e6467e60b5 100644 --- a/packages/table/src/interactions/menus/copyCellsMenuItem.tsx +++ b/packages/table/src/interactions/menus/copyCellsMenuItem.tsx @@ -21,7 +21,7 @@ import { MenuItem, MenuItemProps } from "@blueprintjs/core"; import { Clipboard } from "../../common/clipboard"; import { TABLE_COPY_FAILED } from "../../common/errors"; import { Regions } from "../../regions"; -import { MenuContext } from "./menuContext"; +import type { MenuContext } from "./menuContext"; export interface CopyCellsMenuItemProps extends Omit { /** diff --git a/packages/table/src/interactions/reorderable.tsx b/packages/table/src/interactions/reorderable.tsx index 52ef4c6827..92a8a5a799 100644 --- a/packages/table/src/interactions/reorderable.tsx +++ b/packages/table/src/interactions/reorderable.tsx @@ -22,7 +22,7 @@ import type { FocusedCellCoordinates } from "../common/cellTypes"; import { Utils } from "../common/utils"; import { Region, RegionCardinality, Regions } from "../regions"; import { Draggable } from "./draggable"; -import { CoordinateData, DraggableChildrenProps, DragHandler } from "./dragTypes"; +import type { CoordinateData, DraggableChildrenProps, DragHandler } from "./dragTypes"; export interface ReorderableProps { /** diff --git a/packages/table/src/interactions/resizeHandle.tsx b/packages/table/src/interactions/resizeHandle.tsx index 57f81d0253..3fadee691c 100644 --- a/packages/table/src/interactions/resizeHandle.tsx +++ b/packages/table/src/interactions/resizeHandle.tsx @@ -17,11 +17,11 @@ import classNames from "classnames"; import * as React from "react"; -import { Props } from "@blueprintjs/core"; +import type { Props } from "@blueprintjs/core"; import * as Classes from "../common/classes"; import { Draggable } from "./draggable"; -import { CoordinateData } from "./dragTypes"; +import type { CoordinateData } from "./dragTypes"; export enum Orientation { HORIZONTAL = 1, diff --git a/packages/table/src/interactions/selectable.tsx b/packages/table/src/interactions/selectable.tsx index 112dffcfd2..797d6f2053 100644 --- a/packages/table/src/interactions/selectable.tsx +++ b/packages/table/src/interactions/selectable.tsx @@ -25,7 +25,7 @@ import { Utils } from "../common/utils"; import { Region, Regions } from "../regions"; import { DragEvents } from "./dragEvents"; import { Draggable } from "./draggable"; -import { CoordinateData, DraggableChildrenProps, DragHandler } from "./dragTypes"; +import type { CoordinateData, DraggableChildrenProps, DragHandler } from "./dragTypes"; export type SelectedRegionTransform = ( region: Region, diff --git a/packages/table/src/layers/regions.tsx b/packages/table/src/layers/regions.tsx index b79ad915c9..6e15ca002a 100644 --- a/packages/table/src/layers/regions.tsx +++ b/packages/table/src/layers/regions.tsx @@ -20,7 +20,7 @@ import * as React from "react"; import { Utils as CoreUtils, Props } from "@blueprintjs/core"; import * as Classes from "../common/classes"; -import { QuadrantType } from "../quadrants/tableQuadrant"; +import type { QuadrantType } from "../quadrants/tableQuadrant"; import { Region, Regions } from "../regions"; export type RegionStyler = (region: Region, quadrantType?: QuadrantType) => React.CSSProperties; diff --git a/packages/table/src/quadrants/tableQuadrant.tsx b/packages/table/src/quadrants/tableQuadrant.tsx index d43b4d0303..da78e95317 100644 --- a/packages/table/src/quadrants/tableQuadrant.tsx +++ b/packages/table/src/quadrants/tableQuadrant.tsx @@ -21,7 +21,7 @@ import { AbstractComponent, Props } from "@blueprintjs/core"; import * as Classes from "../common/classes"; import * as Errors from "../common/errors"; -import { Grid } from "../common/grid"; +import type { Grid } from "../common/grid"; export enum QuadrantType { /** diff --git a/packages/table/src/quadrants/tableQuadrantStack.tsx b/packages/table/src/quadrants/tableQuadrantStack.tsx index 5c33f41884..a72b45ad59 100644 --- a/packages/table/src/quadrants/tableQuadrantStack.tsx +++ b/packages/table/src/quadrants/tableQuadrantStack.tsx @@ -22,7 +22,7 @@ import * as Classes from "../common/classes"; import { Grid } from "../common/grid"; import * as ScrollUtils from "../common/internal/scrollUtils"; import { Utils } from "../common/utils"; -import { TableLoadingOption } from "../regions"; +import type { TableLoadingOption } from "../regions"; import { QuadrantType, TableQuadrant } from "./tableQuadrant"; import { TableQuadrantStackCache } from "./tableQuadrantStackCache"; diff --git a/packages/table/src/table.tsx b/packages/table/src/table.tsx index 0dc341ab2f..c7c303dbc0 100644 --- a/packages/table/src/table.tsx +++ b/packages/table/src/table.tsx @@ -34,7 +34,7 @@ import { HotkeysTarget, } from "@blueprintjs/core"; -import { CellRenderer } from "./cell/cell"; +import type { CellRenderer } from "./cell/cell"; import { Column, ColumnProps } from "./column"; import type { FocusedCellCoordinates } from "./common/cellTypes"; import * as Classes from "./common/classes"; diff --git a/packages/table/src/table2.tsx b/packages/table/src/table2.tsx index 1473c816f6..62c0095cd3 100644 --- a/packages/table/src/table2.tsx +++ b/packages/table/src/table2.tsx @@ -26,7 +26,7 @@ import { UseHotkeysReturnValue, } from "@blueprintjs/core"; -import { CellRenderer } from "./cell/cell"; +import type { CellRenderer } from "./cell/cell"; import { Column, ColumnProps } from "./column"; import type { FocusedCellCoordinates } from "./common/cellTypes"; import * as Classes from "./common/classes"; diff --git a/packages/table/src/table2Utils.ts b/packages/table/src/table2Utils.ts index a54cbb9381..c68cad51e2 100644 --- a/packages/table/src/table2Utils.ts +++ b/packages/table/src/table2Utils.ts @@ -15,7 +15,7 @@ import * as React from "react"; -import { HotkeyConfig } from "@blueprintjs/core"; +import type { HotkeyConfig } from "@blueprintjs/core"; import type { ColumnProps } from "./column"; import { RegionCardinality } from "./regions"; diff --git a/packages/table/src/tableBody.tsx b/packages/table/src/tableBody.tsx index 2110c40187..4d959b2985 100644 --- a/packages/table/src/tableBody.tsx +++ b/packages/table/src/tableBody.tsx @@ -23,10 +23,10 @@ import type { CellCoordinates } from "./common/cellTypes"; import * as Classes from "./common/classes"; import { ContextMenuTargetWrapper } from "./common/contextMenuTargetWrapper"; import { RenderMode } from "./common/renderMode"; -import { CoordinateData } from "./interactions/dragTypes"; +import type { CoordinateData } from "./interactions/dragTypes"; import { ContextMenuRenderer, MenuContextImpl } from "./interactions/menus"; import { DragSelectable, SelectableProps } from "./interactions/selectable"; -import { Locator } from "./locator"; +import type { Locator } from "./locator"; import { Region, Regions } from "./regions"; import { TableBodyCells, TableBodyCellsProps } from "./tableBodyCells"; diff --git a/packages/table/src/tableBodyCells.tsx b/packages/table/src/tableBodyCells.tsx index 81b6593b7b..2bb001d219 100644 --- a/packages/table/src/tableBodyCells.tsx +++ b/packages/table/src/tableBodyCells.tsx @@ -23,7 +23,7 @@ import { CellRenderer, emptyCellRenderer } from "./cell/cell"; import { Batcher } from "./common/batcher"; import type { FocusedCellCoordinates } from "./common/cellTypes"; import * as Classes from "./common/classes"; -import { ColumnIndices, Grid, RowIndices } from "./common/grid"; +import type { ColumnIndices, Grid, RowIndices } from "./common/grid"; import { Rect } from "./common/rect"; import { RenderMode } from "./common/renderMode"; diff --git a/packages/table/src/tableHotkeys.ts b/packages/table/src/tableHotkeys.ts index f2c37903bc..4102f984de 100644 --- a/packages/table/src/tableHotkeys.ts +++ b/packages/table/src/tableHotkeys.ts @@ -19,7 +19,7 @@ import type { FocusedCellCoordinates } from "./common/cellTypes"; import { Clipboard } from "./common/clipboard"; import { Direction } from "./common/direction"; import { TABLE_COPY_FAILED } from "./common/errors"; -import { Grid } from "./common/grid"; +import type { Grid } from "./common/grid"; import * as FocusedCellUtils from "./common/internal/focusedCellUtils"; import * as SelectionUtils from "./common/internal/selectionUtils"; import { NonNullRegion, Region, RegionCardinality, Regions } from "./regions"; diff --git a/packages/table/src/tableState.ts b/packages/table/src/tableState.ts index 0492a747b3..f3788d4f20 100644 --- a/packages/table/src/tableState.ts +++ b/packages/table/src/tableState.ts @@ -16,7 +16,7 @@ import type { ColumnProps } from "./column"; import type { Rect } from "./common"; import type { FocusedCellCoordinates } from "./common/cellTypes"; -import { ScrollDirection } from "./common/scrollDirection"; +import type { ScrollDirection } from "./common/scrollDirection"; import type { Region } from "./regions"; export interface TableState { From 109d87b2127e8016420a0d496da80dd6d515529d Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:01:08 -0400 Subject: [PATCH 10/19] [datetime,datetime2] annotate type-only imports --- packages/datetime/src/common/datePickerBaseProps.ts | 2 +- packages/datetime/src/common/dateRangeSelectionStrategy.ts | 2 +- packages/datetime/src/common/timePickerProps.ts | 4 ++-- packages/datetime/src/common/timezoneItems.ts | 2 +- packages/datetime/src/common/timezoneMetadata.ts | 2 +- packages/datetime/src/common/timezoneNameUtils.ts | 2 +- packages/datetime/src/common/timezoneOffsetUtils.ts | 2 +- packages/datetime/src/components/date-input/dateInput.tsx | 2 +- .../src/components/date-picker/datePickerCaption.tsx | 2 +- .../src/components/date-picker/datePickerNavbar.tsx | 2 +- .../src/components/date-range-input/dateRangeInput.tsx | 4 ++-- packages/datetime/src/index.ts | 2 +- packages/datetime2/src/common/dayPickerModifiers.ts | 2 +- .../datetime2/src/components/date-input3/dateInput3.tsx | 2 +- .../datetime2/src/components/date-input3/dateInput3Props.ts | 4 ++-- .../src/components/date-input3/useDateFormatter.ts | 4 ++-- .../datetime2/src/components/date-input3/useDateParser.ts | 4 ++-- .../datetime2/src/components/date-picker3/datePicker3.tsx | 4 ++-- .../src/components/date-picker3/datePicker3Props.ts | 4 ++-- .../src/components/date-range-input3/dateRangeInput3.tsx | 2 +- .../components/date-range-input3/dateRangeInput3Props.ts | 4 ++-- .../date-range-picker3/contiguousDayRangePicker.tsx | 2 +- .../src/components/date-range-picker3/dateRangePicker3.tsx | 6 +++--- .../components/date-range-picker3/dayRangePickerProps.ts | 2 +- .../date-range-picker3/nonContiguousDayRangePicker.tsx | 2 +- .../src/components/react-day-picker/datePicker3Dropdown.tsx | 2 +- .../src/components/react-day-picker/datePickerNavIcons.tsx | 2 +- 27 files changed, 37 insertions(+), 37 deletions(-) diff --git a/packages/datetime/src/common/datePickerBaseProps.ts b/packages/datetime/src/common/datePickerBaseProps.ts index 7e5253eacb..3854c3cecf 100644 --- a/packages/datetime/src/common/datePickerBaseProps.ts +++ b/packages/datetime/src/common/datePickerBaseProps.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { DayPickerProps, LocaleUtils } from "react-day-picker"; +import type { DayPickerProps, LocaleUtils } from "react-day-picker"; import type { TimePickerProps } from "./timePickerProps"; import type { TimePrecision } from "./timePrecision"; diff --git a/packages/datetime/src/common/dateRangeSelectionStrategy.ts b/packages/datetime/src/common/dateRangeSelectionStrategy.ts index e74f1aa2fd..101647b965 100644 --- a/packages/datetime/src/common/dateRangeSelectionStrategy.ts +++ b/packages/datetime/src/common/dateRangeSelectionStrategy.ts @@ -16,7 +16,7 @@ import { Boundary } from "@blueprintjs/core"; -import { DateRange } from "./dateRange"; +import type { DateRange } from "./dateRange"; import { isSameDay } from "./dateUtils"; export interface DateRangeSelectionState { diff --git a/packages/datetime/src/common/timePickerProps.ts b/packages/datetime/src/common/timePickerProps.ts index 6d3ec6e97f..db5cdb4184 100644 --- a/packages/datetime/src/common/timePickerProps.ts +++ b/packages/datetime/src/common/timePickerProps.ts @@ -16,8 +16,8 @@ import type { Props } from "@blueprintjs/core"; -import { TimePrecision } from "./timePrecision"; -import { TimeUnit } from "./timeUnit"; +import type { TimePrecision } from "./timePrecision"; +import type { TimeUnit } from "./timeUnit"; export interface TimePickerProps extends Props { /** diff --git a/packages/datetime/src/common/timezoneItems.ts b/packages/datetime/src/common/timezoneItems.ts index cb83f56f67..53d615f635 100644 --- a/packages/datetime/src/common/timezoneItems.ts +++ b/packages/datetime/src/common/timezoneItems.ts @@ -15,7 +15,7 @@ */ import { lookupTimezoneOffset } from "./timezoneOffsetUtils"; -import { Timezone, TimezoneWithoutOffset } from "./timezoneTypes"; +import type { Timezone, TimezoneWithoutOffset } from "./timezoneTypes"; const utcWithoutOffset: TimezoneWithoutOffset = { label: "UTC", ianaCode: "Etc/UTC" }; diff --git a/packages/datetime/src/common/timezoneMetadata.ts b/packages/datetime/src/common/timezoneMetadata.ts index 4eaf7041a6..1f37f39dca 100644 --- a/packages/datetime/src/common/timezoneMetadata.ts +++ b/packages/datetime/src/common/timezoneMetadata.ts @@ -16,7 +16,7 @@ import { TIMEZONE_ITEMS } from "./timezoneItems"; import { getTimezoneNames } from "./timezoneNameUtils"; -import { Timezone, TimezoneWithNames } from "./timezoneTypes"; +import type { Timezone, TimezoneWithNames } from "./timezoneTypes"; /** * Given a timezone IANA code and an optional date object, retrieve additional metadata like its common name, offset, diff --git a/packages/datetime/src/common/timezoneNameUtils.ts b/packages/datetime/src/common/timezoneNameUtils.ts index f2afb1e3ba..1db86cdcd5 100644 --- a/packages/datetime/src/common/timezoneNameUtils.ts +++ b/packages/datetime/src/common/timezoneNameUtils.ts @@ -18,7 +18,7 @@ import { formatInTimeZone } from "date-fns-tz"; import { getCurrentTimezone } from "./getTimezone"; import { MINIMAL_TIMEZONE_ITEMS, TIMEZONE_ITEMS } from "./timezoneItems"; -import { Timezone, TimezoneWithNames } from "./timezoneTypes"; +import type { Timezone, TimezoneWithNames } from "./timezoneTypes"; const CURRENT_DATE = Date.now(); const LONG_NAME_FORMAT_STR = "zzzz"; diff --git a/packages/datetime/src/common/timezoneOffsetUtils.ts b/packages/datetime/src/common/timezoneOffsetUtils.ts index 0b22290cd7..d6fd730b7d 100644 --- a/packages/datetime/src/common/timezoneOffsetUtils.ts +++ b/packages/datetime/src/common/timezoneOffsetUtils.ts @@ -16,7 +16,7 @@ import { getTimezoneOffset } from "date-fns-tz"; -import { Timezone, TimezoneWithoutOffset } from "./timezoneTypes"; +import type { Timezone, TimezoneWithoutOffset } from "./timezoneTypes"; /** * Augment hard-coded timezone information stored in this package with its current offset relative to UTC, diff --git a/packages/datetime/src/components/date-input/dateInput.tsx b/packages/datetime/src/components/date-input/dateInput.tsx index ad5df43d98..e4eba51c6a 100644 --- a/packages/datetime/src/components/date-input/dateInput.tsx +++ b/packages/datetime/src/components/date-input/dateInput.tsx @@ -55,7 +55,7 @@ import { } from "../../common/timezoneUtils"; import { DatePicker } from "../date-picker/datePicker"; import { DatePickerUtils } from "../date-picker/datePickerUtils"; -import { DatePickerShortcut } from "../shortcuts/shortcuts"; +import type { DatePickerShortcut } from "../shortcuts/shortcuts"; import { TimezoneSelect } from "../timezone-select/timezoneSelect"; export interface DateInputProps extends DatePickerBaseProps, DateFormatProps, DatetimePopoverProps, Props { diff --git a/packages/datetime/src/components/date-picker/datePickerCaption.tsx b/packages/datetime/src/components/date-picker/datePickerCaption.tsx index 28e16cf31b..3337a576e6 100644 --- a/packages/datetime/src/components/date-picker/datePickerCaption.tsx +++ b/packages/datetime/src/components/date-picker/datePickerCaption.tsx @@ -15,7 +15,7 @@ */ import * as React from "react"; -import { CaptionElementProps } from "react-day-picker"; +import type { CaptionElementProps } from "react-day-picker"; import { AbstractPureComponent, Divider, HTMLSelect, OptionProps } from "@blueprintjs/core"; import { IconSize } from "@blueprintjs/icons"; diff --git a/packages/datetime/src/components/date-picker/datePickerNavbar.tsx b/packages/datetime/src/components/date-picker/datePickerNavbar.tsx index b55abef5bb..b8e5386f30 100644 --- a/packages/datetime/src/components/date-picker/datePickerNavbar.tsx +++ b/packages/datetime/src/components/date-picker/datePickerNavbar.tsx @@ -16,7 +16,7 @@ import classNames from "classnames"; import * as React from "react"; -import { NavbarElementProps } from "react-day-picker"; +import type { NavbarElementProps } from "react-day-picker"; import { Button } from "@blueprintjs/core"; import { ChevronLeft, ChevronRight } from "@blueprintjs/icons"; diff --git a/packages/datetime/src/components/date-range-input/dateRangeInput.tsx b/packages/datetime/src/components/date-range-input/dateRangeInput.tsx index 06ba2178e9..7649f540c2 100644 --- a/packages/datetime/src/components/date-range-input/dateRangeInput.tsx +++ b/packages/datetime/src/components/date-range-input/dateRangeInput.tsx @@ -45,12 +45,12 @@ import { import { Classes, DateFormatProps, DatePickerBaseProps, DateRange, NonNullDateRange } from "../../common"; import { getFormattedDateString } from "../../common/dateFormatProps"; -import { DatetimePopoverProps } from "../../common/datetimePopoverProps"; +import type { DatetimePopoverProps } from "../../common/datetimePopoverProps"; import { isDayInRange, isSameTime } from "../../common/dateUtils"; import * as Errors from "../../common/errors"; import { DatePickerUtils } from "../date-picker/datePickerUtils"; import { DateRangePicker } from "../date-range-picker/dateRangePicker"; -import { DateRangeShortcut } from "../shortcuts/shortcuts"; +import type { DateRangeShortcut } from "../shortcuts/shortcuts"; // We handle events in a kind of generic way in this component, so here // we enumerate all the different kinds of events for which we have handlers. diff --git a/packages/datetime/src/index.ts b/packages/datetime/src/index.ts index 7f8713aa2f..474a57a635 100644 --- a/packages/datetime/src/index.ts +++ b/packages/datetime/src/index.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { DayModifiers as DatePickerDayModifiers, LocaleUtils } from "react-day-picker"; +import type { DayModifiers as DatePickerDayModifiers, LocaleUtils } from "react-day-picker"; export * from "./common"; diff --git a/packages/datetime2/src/common/dayPickerModifiers.ts b/packages/datetime2/src/common/dayPickerModifiers.ts index 9ba53d7427..d591986005 100644 --- a/packages/datetime2/src/common/dayPickerModifiers.ts +++ b/packages/datetime2/src/common/dayPickerModifiers.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { DayModifiers } from "react-day-picker"; +import type { DayModifiers } from "react-day-picker"; export const DISABLED_MODIFIER = "disabled"; export const HOVERED_RANGE_MODIFIER = "hovered-range"; diff --git a/packages/datetime2/src/components/date-input3/dateInput3.tsx b/packages/datetime2/src/components/date-input3/dateInput3.tsx index 6e1e88e70b..c1d6241023 100644 --- a/packages/datetime2/src/components/date-input3/dateInput3.tsx +++ b/packages/datetime2/src/components/date-input3/dateInput3.tsx @@ -42,7 +42,7 @@ import { Classes } from "../../classes"; import { getDefaultDateFnsFormat } from "../../common/dateFnsFormatUtils"; import { useDateFnsLocale } from "../../common/dateFnsLocaleUtils"; import { DatePicker3, DatePicker3Props } from "../date-picker3/datePicker3"; -import { DateInput3DefaultProps, DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; +import type { DateInput3DefaultProps, DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; import { useDateFormatter } from "./useDateFormatter"; import { useDateParser } from "./useDateParser"; diff --git a/packages/datetime2/src/components/date-input3/dateInput3Props.ts b/packages/datetime2/src/components/date-input3/dateInput3Props.ts index da39753001..b48b2a78ee 100644 --- a/packages/datetime2/src/components/date-input3/dateInput3Props.ts +++ b/packages/datetime2/src/components/date-input3/dateInput3Props.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { DateFormatProps, DateInputProps } from "@blueprintjs/datetime"; +import type { DateFormatProps, DateInputProps } from "@blueprintjs/datetime"; -import { DatePicker3Props } from "../date-picker3/datePicker3Props"; +import type { DatePicker3Props } from "../date-picker3/datePicker3Props"; /** * Props shared between DateInput v1 and v3. diff --git a/packages/datetime2/src/components/date-input3/useDateFormatter.ts b/packages/datetime2/src/components/date-input3/useDateFormatter.ts index b441a1461e..ac3ccecfb8 100644 --- a/packages/datetime2/src/components/date-input3/useDateFormatter.ts +++ b/packages/datetime2/src/components/date-input3/useDateFormatter.ts @@ -14,14 +14,14 @@ * limitations under the License. */ -import { Locale } from "date-fns"; +import type { Locale } from "date-fns"; import * as React from "react"; import { DateUtils } from "@blueprintjs/datetime"; import { getDateFnsFormatter, getDefaultDateFnsFormat } from "../../common/dateFnsFormatUtils"; import { getLocaleCodeFromProps } from "../../common/dateFnsLocaleProps"; -import { DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; +import type { DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; /** * Create a date string parser function based on a given locale. diff --git a/packages/datetime2/src/components/date-input3/useDateParser.ts b/packages/datetime2/src/components/date-input3/useDateParser.ts index a2376459f4..3f913faa62 100644 --- a/packages/datetime2/src/components/date-input3/useDateParser.ts +++ b/packages/datetime2/src/components/date-input3/useDateParser.ts @@ -14,12 +14,12 @@ * limitations under the License. */ -import { Locale } from "date-fns"; +import type { Locale } from "date-fns"; import * as React from "react"; import { getDateFnsParser, getDefaultDateFnsFormat } from "../../common/dateFnsFormatUtils"; import { getLocaleCodeFromProps } from "../../common/dateFnsLocaleProps"; -import { DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; +import type { DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; const INVALID_DATE = new Date(undefined!); diff --git a/packages/datetime2/src/components/date-picker3/datePicker3.tsx b/packages/datetime2/src/components/date-picker3/datePicker3.tsx index e1866d8fe8..9ce9e1af2a 100644 --- a/packages/datetime2/src/components/date-picker3/datePicker3.tsx +++ b/packages/datetime2/src/components/date-picker3/datePicker3.tsx @@ -35,8 +35,8 @@ import { loadDateFnsLocale } from "../../common/dateFnsLocaleUtils"; import { DatePicker3Dropdown } from "../react-day-picker/datePicker3Dropdown"; import { IconLeft, IconRight } from "../react-day-picker/datePickerNavIcons"; import { DatePicker3Provider } from "./datePicker3Context"; -import { DatePicker3Props } from "./datePicker3Props"; -import { DatePicker3State } from "./datePicker3State"; +import type { DatePicker3Props } from "./datePicker3Props"; +import type { DatePicker3State } from "./datePicker3State"; export { DatePicker3Props }; diff --git a/packages/datetime2/src/components/date-picker3/datePicker3Props.ts b/packages/datetime2/src/components/date-picker3/datePicker3Props.ts index 3c59149f7b..550b391d49 100644 --- a/packages/datetime2/src/components/date-picker3/datePicker3Props.ts +++ b/packages/datetime2/src/components/date-picker3/datePicker3Props.ts @@ -16,8 +16,8 @@ import type { DatePickerProps } from "@blueprintjs/datetime"; -import { DateFnsLocaleProps } from "../../common/dateFnsLocaleProps"; -import { ReactDayPickerSingleProps } from "../../common/reactDayPickerProps"; +import type { DateFnsLocaleProps } from "../../common/dateFnsLocaleProps"; +import type { ReactDayPickerSingleProps } from "../../common/reactDayPickerProps"; /** Props shared between DatePicker v1 and v3 */ type DatePickerSharedProps = Omit< diff --git a/packages/datetime2/src/components/date-range-input3/dateRangeInput3.tsx b/packages/datetime2/src/components/date-range-input3/dateRangeInput3.tsx index 34ed8561fd..03194453a5 100644 --- a/packages/datetime2/src/components/date-range-input3/dateRangeInput3.tsx +++ b/packages/datetime2/src/components/date-range-input3/dateRangeInput3.tsx @@ -44,7 +44,7 @@ import { import { Classes } from "../../classes"; import { getLocaleCodeFromProps } from "../../common/dateFnsLocaleProps"; import { DateRangePicker3 } from "../date-range-picker3/dateRangePicker3"; -import { +import type { DateRangeInput3DefaultProps, DateRangeInput3Props, DateRangeInput3PropsWithDefaults, diff --git a/packages/datetime2/src/components/date-range-input3/dateRangeInput3Props.ts b/packages/datetime2/src/components/date-range-input3/dateRangeInput3Props.ts index d0de16f33b..6dfaf98521 100644 --- a/packages/datetime2/src/components/date-range-input3/dateRangeInput3Props.ts +++ b/packages/datetime2/src/components/date-range-input3/dateRangeInput3Props.ts @@ -14,9 +14,9 @@ * limitations under the License. */ -import { DateRangeInputProps } from "@blueprintjs/datetime"; +import type { DateRangeInputProps } from "@blueprintjs/datetime"; -import { DateRangePicker3Props } from "../date-range-picker3/dateRangePicker3Props"; +import type { DateRangePicker3Props } from "../date-range-picker3/dateRangePicker3Props"; /** Props shared between DateRangeInput v1 and v3 */ type DateRangeInputSharedProps = Omit; diff --git a/packages/datetime2/src/components/date-range-picker3/contiguousDayRangePicker.tsx b/packages/datetime2/src/components/date-range-picker3/contiguousDayRangePicker.tsx index d2434acbf5..d2b2017c70 100644 --- a/packages/datetime2/src/components/date-range-picker3/contiguousDayRangePicker.tsx +++ b/packages/datetime2/src/components/date-range-picker3/contiguousDayRangePicker.tsx @@ -23,7 +23,7 @@ import { DateRange, DateRangeSelectionStrategy, MonthAndYear } from "@blueprintj import { dateRangeToDayPickerRange } from "../../common/reactDayPickerUtils"; import { DatePicker3Dropdown } from "../react-day-picker/datePicker3Dropdown"; import { IconLeft, IconRight } from "../react-day-picker/datePickerNavIcons"; -import { DayRangePickerProps } from "./dayRangePickerProps"; +import type { DayRangePickerProps } from "./dayRangePickerProps"; /** * Render a standard day range picker where props.contiguousCalendarMonths is expected to be `true`. diff --git a/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx b/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx index 3af62dbac4..82e8c51c38 100644 --- a/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx +++ b/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx @@ -17,7 +17,7 @@ import classNames from "classnames"; import { format } from "date-fns"; import * as React from "react"; -import { DateFormatter, DayModifiers, DayMouseEventHandler, ModifiersClassNames } from "react-day-picker"; +import type { DateFormatter, DayModifiers, DayMouseEventHandler, ModifiersClassNames } from "react-day-picker"; import { AbstractPureComponent, Boundary, DISPLAYNAME_PREFIX, Divider } from "@blueprintjs/core"; import { @@ -37,8 +37,8 @@ import { loadDateFnsLocale } from "../../common/dateFnsLocaleUtils"; import { combineModifiers, HOVERED_RANGE_MODIFIER } from "../../common/dayPickerModifiers"; import { DatePicker3Provider } from "../date-picker3/datePicker3Context"; import { ContiguousDayRangePicker } from "./contiguousDayRangePicker"; -import { DateRangePicker3Props } from "./dateRangePicker3Props"; -import { DateRangePicker3State } from "./dateRangePicker3State"; +import type { DateRangePicker3Props } from "./dateRangePicker3Props"; +import type { DateRangePicker3State } from "./dateRangePicker3State"; import { NonContiguousDayRangePicker } from "./nonContiguousDayRangePicker"; export { DateRangePicker3Props }; diff --git a/packages/datetime2/src/components/date-range-picker3/dayRangePickerProps.ts b/packages/datetime2/src/components/date-range-picker3/dayRangePickerProps.ts index c8c0f7153e..3f1ae7e17c 100644 --- a/packages/datetime2/src/components/date-range-picker3/dayRangePickerProps.ts +++ b/packages/datetime2/src/components/date-range-picker3/dayRangePickerProps.ts @@ -16,7 +16,7 @@ import type { DayPickerRangeProps } from "react-day-picker"; -import { Boundary } from "@blueprintjs/core"; +import type { Boundary } from "@blueprintjs/core"; import type { DateRange, MonthAndYear } from "@blueprintjs/datetime"; import type { DateRangePicker3Props } from "./dateRangePicker3Props"; diff --git a/packages/datetime2/src/components/date-range-picker3/nonContiguousDayRangePicker.tsx b/packages/datetime2/src/components/date-range-picker3/nonContiguousDayRangePicker.tsx index 3d4f251c40..5c544e3cc9 100644 --- a/packages/datetime2/src/components/date-range-picker3/nonContiguousDayRangePicker.tsx +++ b/packages/datetime2/src/components/date-range-picker3/nonContiguousDayRangePicker.tsx @@ -23,7 +23,7 @@ import { DateRange, DateRangeSelectionStrategy, DateUtils, MonthAndYear } from " import { Classes } from "../../classes"; import { dateRangeToDayPickerRange } from "../../common/reactDayPickerUtils"; import { DatePicker3Caption } from "../react-day-picker/datePicker3Caption"; -import { DayRangePickerProps } from "./dayRangePickerProps"; +import type { DayRangePickerProps } from "./dayRangePickerProps"; /** * Date range picker with two calendars which can move independently of each other. diff --git a/packages/datetime2/src/components/react-day-picker/datePicker3Dropdown.tsx b/packages/datetime2/src/components/react-day-picker/datePicker3Dropdown.tsx index 6f45657697..aee721512a 100644 --- a/packages/datetime2/src/components/react-day-picker/datePicker3Dropdown.tsx +++ b/packages/datetime2/src/components/react-day-picker/datePicker3Dropdown.tsx @@ -15,7 +15,7 @@ */ import * as React from "react"; -import { DropdownProps } from "react-day-picker"; +import type { DropdownProps } from "react-day-picker"; import { HTMLSelect } from "@blueprintjs/core"; diff --git a/packages/datetime2/src/components/react-day-picker/datePickerNavIcons.tsx b/packages/datetime2/src/components/react-day-picker/datePickerNavIcons.tsx index a63f4abfe6..0bd1813298 100644 --- a/packages/datetime2/src/components/react-day-picker/datePickerNavIcons.tsx +++ b/packages/datetime2/src/components/react-day-picker/datePickerNavIcons.tsx @@ -15,7 +15,7 @@ */ import * as React from "react"; -import { StyledComponent } from "react-day-picker"; +import type { StyledComponent } from "react-day-picker"; import { ChevronLeft, ChevronRight } from "@blueprintjs/icons"; From 83a6960a29d3f7e3b10b2a8e2313722909b75c64 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:19:05 -0400 Subject: [PATCH 11/19] Fix SWC config to load test modules correctly --- packages/webpack-build-scripts/webpack.config.karma.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/webpack-build-scripts/webpack.config.karma.mjs b/packages/webpack-build-scripts/webpack.config.karma.mjs index 80793c2468..be0c19ee02 100644 --- a/packages/webpack-build-scripts/webpack.config.karma.mjs +++ b/packages/webpack-build-scripts/webpack.config.karma.mjs @@ -54,10 +54,12 @@ export default { legacyDecorator: true, react: { refresh: false, - useBuiltins: true, }, }, }, + module: { + type: "commonjs", + }, }, }, { From c5a20bb85bbf49a58e4394ef6799661bf5be7227 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:27:50 -0400 Subject: [PATCH 12/19] fix coverage --- packages/core/karma.conf.js | 6 ++++++ packages/core/src/accessibility/focusStyleManager.ts | 1 - packages/core/src/common/utils/domUtils.ts | 1 + packages/webpack-build-scripts/webpack.config.karma.mjs | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/core/karma.conf.js b/packages/core/karma.conf.js index c8a3531a7f..7321e4a3ac 100644 --- a/packages/core/karma.conf.js +++ b/packages/core/karma.conf.js @@ -8,13 +8,19 @@ module.exports = async function (config) { createKarmaConfig({ dirname: __dirname, coverageExcludes: [ + // don't check barrel files + "src/**/index.ts", + // no need to test legacy APIs "src/legacy/*", + "src/common/keyCodes.ts", + "src/deprecatedTypeAliases.ts", // not worth full coverage "src/accessibility/*", "src/common/abstractComponent*", "src/common/abstractPureComponent*", + "src/components/html/html.tsx", // HACKHACK: for karma upgrade only "src/common/refs.ts", diff --git a/packages/core/src/accessibility/focusStyleManager.ts b/packages/core/src/accessibility/focusStyleManager.ts index b36a156a13..49c421c001 100644 --- a/packages/core/src/accessibility/focusStyleManager.ts +++ b/packages/core/src/accessibility/focusStyleManager.ts @@ -17,7 +17,6 @@ import { FOCUS_DISABLED } from "../common/classes"; import { InteractionModeEngine } from "../common/interactionMode"; -/* istanbul ignore next */ const fakeFocusEngine = { isActive: () => true, start: () => true, diff --git a/packages/core/src/common/utils/domUtils.ts b/packages/core/src/common/utils/domUtils.ts index 387c4665c7..bb78d568f3 100644 --- a/packages/core/src/common/utils/domUtils.ts +++ b/packages/core/src/common/utils/domUtils.ts @@ -113,6 +113,7 @@ export function throttleReactEventCallback(method: T): T { return throttleImpl(method); diff --git a/packages/webpack-build-scripts/webpack.config.karma.mjs b/packages/webpack-build-scripts/webpack.config.karma.mjs index be0c19ee02..8c3e61819b 100644 --- a/packages/webpack-build-scripts/webpack.config.karma.mjs +++ b/packages/webpack-build-scripts/webpack.config.karma.mjs @@ -50,6 +50,8 @@ export default { syntax: "typescript", tsx: true, }, + // this is important for istanbul comment flags to work correctly + preserveAllComments: true, transform: { legacyDecorator: true, react: { From 0f2966e6d171039881d4df7cbc8591489c43633e Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:35:19 -0400 Subject: [PATCH 13/19] fix more coverage & type imports --- packages/datetime/karma.conf.js | 2 ++ packages/datetime/test/common/dateFormat.ts | 2 +- packages/datetime/test/common/dateUtilsTests.tsx | 2 +- packages/datetime/test/common/dayPickerTestUtils.ts | 2 +- packages/datetime/test/common/timezoneMetadataTests.ts | 2 +- packages/datetime/test/components/datePickerTests.tsx | 2 +- .../datetime/test/components/dateRangePickerTests.tsx | 2 +- .../datetime/test/components/timezoneSelectTests.tsx | 2 +- packages/select/karma.conf.js | 7 ++++++- packages/select/test/itemRendererTests.tsx | 2 +- packages/select/test/selectComponentSuite.tsx | 4 ++-- packages/select/test/selectPopoverTestSuite.tsx | 2 +- packages/table/karma.conf.js | 9 +++++---- packages/table/test/harness.ts | 2 +- packages/table/test/table2Tests.tsx | 2 +- packages/table/test/tableBody2Tests.tsx | 4 ++-- packages/table/test/tableBodyTests.tsx | 2 +- packages/table/test/tableTests.tsx | 2 +- 18 files changed, 30 insertions(+), 22 deletions(-) diff --git a/packages/datetime/karma.conf.js b/packages/datetime/karma.conf.js index de16a984e3..a0cedd1ce3 100644 --- a/packages/datetime/karma.conf.js +++ b/packages/datetime/karma.conf.js @@ -8,6 +8,8 @@ module.exports = async function (config) { createKarmaConfig({ dirname: __dirname, coverageExcludes: [ + // don't check barrel files + "src/**/index.ts", // not worth coverage, fairly simple implementation "src/common/timezoneDisplayFormat.ts", ], diff --git a/packages/datetime/test/common/dateFormat.ts b/packages/datetime/test/common/dateFormat.ts index 35007a6ecb..eb8dd366a7 100644 --- a/packages/datetime/test/common/dateFormat.ts +++ b/packages/datetime/test/common/dateFormat.ts @@ -16,7 +16,7 @@ import { format, Locale, parse } from "date-fns"; -import { DateFormatProps } from "../../src/common"; +import type { DateFormatProps } from "../../src/common"; // eslint-disable-next-line @typescript-eslint/no-var-requires const locales: { [localeCode: string]: Locale } = require("date-fns/locale"); diff --git a/packages/datetime/test/common/dateUtilsTests.tsx b/packages/datetime/test/common/dateUtilsTests.tsx index b3ed380584..5465d1b13a 100644 --- a/packages/datetime/test/common/dateUtilsTests.tsx +++ b/packages/datetime/test/common/dateUtilsTests.tsx @@ -18,7 +18,7 @@ import { expect } from "chai"; import { assertTimeIs, createTimeObject } from "@blueprintjs/test-commons"; -import { DateRange } from "../../src/"; +import type { DateRange } from "../../src/"; import * as DateUtils from "../../src/common/dateUtils"; import { Months } from "../../src/common/months"; diff --git a/packages/datetime/test/common/dayPickerTestUtils.ts b/packages/datetime/test/common/dayPickerTestUtils.ts index c7f0ddac2b..eb113be4c7 100644 --- a/packages/datetime/test/common/dayPickerTestUtils.ts +++ b/packages/datetime/test/common/dayPickerTestUtils.ts @@ -17,7 +17,7 @@ /** @fileoverview test utils for react-day-picker v7 */ import { assert } from "chai"; -import { ReactWrapper } from "enzyme"; +import type { ReactWrapper } from "enzyme"; import { Classes } from "../../src/common"; diff --git a/packages/datetime/test/common/timezoneMetadataTests.ts b/packages/datetime/test/common/timezoneMetadataTests.ts index e5800964ba..ebea7fdc20 100644 --- a/packages/datetime/test/common/timezoneMetadataTests.ts +++ b/packages/datetime/test/common/timezoneMetadataTests.ts @@ -19,7 +19,7 @@ import { expect } from "chai"; import { UTC_TIME } from "../../src/common/timezoneItems"; import { getTimezoneMetadata } from "../../src/common/timezoneMetadata"; import { lookupTimezoneOffset } from "../../src/common/timezoneOffsetUtils"; -import { TimezoneWithoutOffset } from "../../src/common/timezoneTypes"; +import type { TimezoneWithoutOffset } from "../../src/common/timezoneTypes"; const LONDON_TZ_IANA = "Europe/London"; const NEW_YORK_TZ_IANA = "America/New_York"; diff --git a/packages/datetime/test/components/datePickerTests.tsx b/packages/datetime/test/components/datePickerTests.tsx index eaa75080a9..d4f8db5429 100644 --- a/packages/datetime/test/components/datePickerTests.tsx +++ b/packages/datetime/test/components/datePickerTests.tsx @@ -34,7 +34,7 @@ import { assertDatesEqual } from "@blueprintjs/test-commons"; import { Classes, DatePicker, DatePickerModifiers, DatePickerProps, TimePicker, TimePrecision } from "../../src"; import { DateUtils, Months } from "../../src/common"; import * as Errors from "../../src/common/errors"; -import { DatePickerState } from "../../src/components/date-picker/datePicker"; +import type { DatePickerState } from "../../src/components/date-picker/datePicker"; import { DatePickerShortcut, DatePickerShortcutMenu } from "../../src/components/shortcuts/shortcuts"; import { assertDayDisabled, assertDayHidden } from "../common/dayPickerTestUtils"; diff --git a/packages/datetime/test/components/dateRangePickerTests.tsx b/packages/datetime/test/components/dateRangePickerTests.tsx index 681976334e..2c53c6343f 100644 --- a/packages/datetime/test/components/dateRangePickerTests.tsx +++ b/packages/datetime/test/components/dateRangePickerTests.tsx @@ -43,7 +43,7 @@ import * as DateUtils from "../../src/common/dateUtils"; import * as Errors from "../../src/common/errors"; import { Months } from "../../src/common/months"; import { DatePickerNavbar } from "../../src/components/date-picker/datePickerNavbar"; -import { DateRangePickerState } from "../../src/components/date-range-picker/dateRangePicker"; +import type { DateRangePickerState } from "../../src/components/date-range-picker/dateRangePicker"; import { DatePickerShortcutMenu, DateRangeShortcut } from "../../src/components/shortcuts/shortcuts"; import { assertDayDisabled } from "../common/dayPickerTestUtils"; diff --git a/packages/datetime/test/components/timezoneSelectTests.tsx b/packages/datetime/test/components/timezoneSelectTests.tsx index 68ab468805..3b1d82d7af 100644 --- a/packages/datetime/test/components/timezoneSelectTests.tsx +++ b/packages/datetime/test/components/timezoneSelectTests.tsx @@ -26,7 +26,7 @@ import { TimezoneSelect, TimezoneSelectProps } from "../../src"; import { getCurrentTimezone } from "../../src/common/getTimezone"; import { TIMEZONE_ITEMS } from "../../src/common/timezoneItems"; import { getInitialTimezoneItems, mapTimezonesWithNames } from "../../src/common/timezoneNameUtils"; -import { TimezoneWithNames } from "../../src/common/timezoneTypes"; +import type { TimezoneWithNames } from "../../src/common/timezoneTypes"; const LOS_ANGELES_TZ = "America/Los_Angeles"; let CURRENT_TZ = getCurrentTimezone(); diff --git a/packages/select/karma.conf.js b/packages/select/karma.conf.js index 6f08d9fda4..8cf9ee61fc 100644 --- a/packages/select/karma.conf.js +++ b/packages/select/karma.conf.js @@ -7,7 +7,12 @@ module.exports = async function (config) { config.set( createKarmaConfig({ dirname: __dirname, - coverageExcludes: ["src/__examples__/*"], + coverageExcludes: [ + // don't check barrel files or example fixtures + "src/**/index.ts", + "src/__examples__/*", + "src/components/deprecatedAliases.ts", + ], }), ); }; diff --git a/packages/select/test/itemRendererTests.tsx b/packages/select/test/itemRendererTests.tsx index 03b51fa229..5906b80b5a 100644 --- a/packages/select/test/itemRendererTests.tsx +++ b/packages/select/test/itemRendererTests.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { Menu, MenuItem } from "@blueprintjs/core"; -import { ItemRenderer, ItemRendererProps } from "../src"; +import type { ItemRenderer, ItemRendererProps } from "../src"; import { Film, TOP_100_FILMS } from "../src/__examples__"; describe("ItemRenderer", () => { diff --git a/packages/select/test/selectComponentSuite.tsx b/packages/select/test/selectComponentSuite.tsx index 56c139462f..19a2b78166 100644 --- a/packages/select/test/selectComponentSuite.tsx +++ b/packages/select/test/selectComponentSuite.tsx @@ -15,13 +15,13 @@ */ import { assert } from "chai"; -import { ReactWrapper } from "enzyme"; +import type { ReactWrapper } from "enzyme"; import * as React from "react"; import sinon from "sinon"; import { Classes, HTMLInputProps } from "@blueprintjs/core"; -import { ListItemsProps } from "../src"; +import type { ListItemsProps } from "../src"; import { areFilmsEqual, createFilm, diff --git a/packages/select/test/selectPopoverTestSuite.tsx b/packages/select/test/selectPopoverTestSuite.tsx index 9dc4f93a4b..105257548c 100644 --- a/packages/select/test/selectPopoverTestSuite.tsx +++ b/packages/select/test/selectPopoverTestSuite.tsx @@ -20,7 +20,7 @@ import * as sinon from "sinon"; import { Classes } from "@blueprintjs/core"; -import { ListItemsProps, SelectPopoverProps } from "../src"; +import type { ListItemsProps, SelectPopoverProps } from "../src"; import { areFilmsEqual, Film, filterFilm, renderFilm, TOP_100_FILMS } from "../src/__examples__"; type EnzymeLocator = (wrapper: ReactWrapper) => ReactWrapper; diff --git a/packages/table/karma.conf.js b/packages/table/karma.conf.js index a91a66ab59..c6def8cdb0 100644 --- a/packages/table/karma.conf.js +++ b/packages/table/karma.conf.js @@ -2,13 +2,16 @@ * Copyright 2017 Palantir Technologies, Inc. All rights reserved. */ -const REACT = process.env.REACT || "16"; - module.exports = async function (config) { const { createKarmaConfig } = await import("@blueprintjs/karma-build-scripts"); config.set( createKarmaConfig({ dirname: __dirname, + coverageExcludes: [ + // don't check barrel files or deprecated APIs + "src/**/index.ts", + "src/deprecatedAliases.ts", + ], coverageOverrides: { "src/cell/cell*": { lines: 70, @@ -26,8 +29,6 @@ module.exports = async function (config) { statements: 70, }, }, - coverageExcludes: - REACT === "15" ? ["src/table2.tsx", "src/table2Utils.ts", "src/cell/editableCell2.tsx"] : [], }), ); }; diff --git a/packages/table/test/harness.ts b/packages/table/test/harness.ts index d207e8d29a..085889163c 100644 --- a/packages/table/test/harness.ts +++ b/packages/table/test/harness.ts @@ -16,7 +16,7 @@ /* eslint-disable max-classes-per-file */ -import * as React from "react"; +import type * as React from "react"; import * as ReactDOM from "react-dom"; export type MouseEventType = "click" | "mousedown" | "mouseup" | "mousemove" | "mouseenter" | "mouseleave"; diff --git a/packages/table/test/table2Tests.tsx b/packages/table/test/table2Tests.tsx index e80aee7c45..714de4eac7 100644 --- a/packages/table/test/table2Tests.tsx +++ b/packages/table/test/table2Tests.tsx @@ -34,7 +34,7 @@ import { RenderMode } from "../src/common/renderMode"; import { TableQuadrant } from "../src/quadrants/tableQuadrant"; import { TableQuadrantStack } from "../src/quadrants/tableQuadrantStack"; import { Region, Regions } from "../src/regions"; -import { TableState } from "../src/tableState"; +import type { TableState } from "../src/tableState"; import { CellType, expectCellLoading } from "./cellTestUtils"; import { ElementHarness, ReactHarness } from "./harness"; import { createStringOfLength, createTableOfSize } from "./mocks/table"; diff --git a/packages/table/test/tableBody2Tests.tsx b/packages/table/test/tableBody2Tests.tsx index 8e5f3cb156..56a98edfad 100644 --- a/packages/table/test/tableBody2Tests.tsx +++ b/packages/table/test/tableBody2Tests.tsx @@ -25,9 +25,9 @@ import * as Classes from "../src/common/classes"; import { Grid } from "../src/common/grid"; import { Rect } from "../src/common/rect"; import { RenderMode } from "../src/common/renderMode"; -import { MenuContext } from "../src/interactions/menus/menuContext"; +import type { MenuContext } from "../src/interactions/menus/menuContext"; import { Region, Regions } from "../src/regions"; -import { TableBodyProps } from "../src/tableBody"; +import type { TableBodyProps } from "../src/tableBody"; import { TableBody2 } from "../src/tableBody2"; import { cellClassNames } from "../src/tableBodyCells"; diff --git a/packages/table/test/tableBodyTests.tsx b/packages/table/test/tableBodyTests.tsx index 5dab5dcf40..ac39a92de4 100644 --- a/packages/table/test/tableBodyTests.tsx +++ b/packages/table/test/tableBodyTests.tsx @@ -32,7 +32,7 @@ import * as Classes from "../src/common/classes"; import { Grid } from "../src/common/grid"; import { Rect } from "../src/common/rect"; import { RenderMode } from "../src/common/renderMode"; -import { MenuContext } from "../src/interactions/menus/menuContext"; +import type { MenuContext } from "../src/interactions/menus/menuContext"; import { Region, Regions } from "../src/regions"; import { TableBody, TableBodyProps } from "../src/tableBody"; import { cellClassNames } from "../src/tableBodyCells"; diff --git a/packages/table/test/tableTests.tsx b/packages/table/test/tableTests.tsx index 7b625b3139..3880ef86d6 100644 --- a/packages/table/test/tableTests.tsx +++ b/packages/table/test/tableTests.tsx @@ -39,7 +39,7 @@ import { Rect } from "../src/common/rect"; import { RenderMode } from "../src/common/renderMode"; import { TableQuadrant } from "../src/quadrants/tableQuadrant"; import { Region, Regions } from "../src/regions"; -import { TableState } from "../src/tableState"; +import type { TableState } from "../src/tableState"; import { CellType, expectCellLoading } from "./cellTestUtils"; import { ElementHarness, ReactHarness } from "./harness"; import { createStringOfLength, createTableOfSize } from "./mocks/table"; From 5d48c8ff27884342d6407a6c792b4e9adf069412 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:47:32 -0400 Subject: [PATCH 14/19] [docs-app] fix bundling type errors --- packages/core/src/components/index.ts | 4 ++-- packages/docs-app/src/common/dateFormatSelector.tsx | 2 +- packages/docs-app/src/common/formattedDateRange.tsx | 2 +- packages/docs-app/src/components/blueprintDocs.tsx | 2 +- packages/docs-app/src/components/navHeader.tsx | 2 +- packages/docs-app/src/examples/core-examples/alertExample.tsx | 2 +- .../docs-app/src/examples/core-examples/calloutExample.tsx | 2 +- .../docs-app/src/examples/core-examples/common/iconSelect.tsx | 2 +- .../docs-app/src/examples/core-examples/dialogExample.tsx | 2 +- .../docs-app/src/examples/core-examples/drawerExample.tsx | 2 +- .../src/examples/core-examples/multistepDialogExample.tsx | 2 +- .../src/examples/core-examples/nonIdealStateExample.tsx | 2 +- .../docs-app/src/examples/core-examples/overlayExample.tsx | 2 +- packages/docs-app/src/examples/core-examples/toastExample.tsx | 2 +- .../src/examples/datetime-examples/common/dateFnsDate.tsx | 2 +- .../datetime-examples/common/dateFnsDateFormatPropsSelect.tsx | 2 +- .../src/examples/datetime-examples/common/momentDate.tsx | 2 +- .../src/examples/datetime-examples/common/momentFormats.tsx | 2 +- .../examples/datetime2-examples/dateRangePicker3Example.tsx | 2 +- .../docs-app/src/examples/select-examples/selectExample.tsx | 2 +- packages/docs-app/src/tags/reactExamples.ts | 4 ++-- 21 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/core/src/components/index.ts b/packages/core/src/components/index.ts index 621c8e9fdb..314289b757 100644 --- a/packages/core/src/components/index.ts +++ b/packages/core/src/components/index.ts @@ -74,7 +74,7 @@ export { Navbar, type NavbarProps } from "./navbar/navbar"; export { NavbarDivider, type NavbarDividerProps } from "./navbar/navbarDivider"; export { NavbarGroup, type NavbarGroupProps } from "./navbar/navbarGroup"; export { NavbarHeading, type NavbarHeadingProps } from "./navbar/navbarHeading"; -export { NonIdealState, type NonIdealStateProps, type NonIdealStateIconSize } from "./non-ideal-state/nonIdealState"; +export { NonIdealState, type NonIdealStateProps, NonIdealStateIconSize } from "./non-ideal-state/nonIdealState"; export { OverflowList, type OverflowListProps } from "./overflow-list/overflowList"; export { Overlay, type OverlayLifecycleProps, type OverlayProps, type OverlayableProps } from "./overlay/overlay"; export { Text, type TextProps } from "./text/text"; @@ -103,7 +103,7 @@ export { PopupKind } from "./popover/popupKind"; export { Portal, type PortalProps, type PortalLegacyContext } from "./portal/portal"; export { ProgressBar, type ProgressBarProps } from "./progress-bar/progressBar"; export { type ResizeEntry, ResizeSensor, type ResizeSensorProps } from "./resize-sensor/resizeSensor"; -export type { HandleHtmlProps, HandleInteractionKind, HandleProps, HandleType } from "./slider/handleProps"; +export { type HandleHtmlProps, HandleInteractionKind, type HandleProps, HandleType } from "./slider/handleProps"; export { MultiSlider, type MultiSliderProps, type SliderBaseProps } from "./slider/multiSlider"; export { type NumberRange, RangeSlider, type RangeSliderProps } from "./slider/rangeSlider"; export { Section, type SectionElevation, type SectionProps } from "./section/section"; diff --git a/packages/docs-app/src/common/dateFormatSelector.tsx b/packages/docs-app/src/common/dateFormatSelector.tsx index 45000c22b2..12e2db3ba9 100644 --- a/packages/docs-app/src/common/dateFormatSelector.tsx +++ b/packages/docs-app/src/common/dateFormatSelector.tsx @@ -17,7 +17,7 @@ import * as React from "react"; import { Radio, RadioGroup } from "@blueprintjs/core"; -import { DateFormatProps } from "@blueprintjs/datetime"; +import type { DateFormatProps } from "@blueprintjs/datetime"; import { handleNumberChange } from "@blueprintjs/docs-theme"; export interface DateFormatSelectorProps { diff --git a/packages/docs-app/src/common/formattedDateRange.tsx b/packages/docs-app/src/common/formattedDateRange.tsx index a95b336192..dfec5c2f2e 100644 --- a/packages/docs-app/src/common/formattedDateRange.tsx +++ b/packages/docs-app/src/common/formattedDateRange.tsx @@ -17,7 +17,7 @@ import * as React from "react"; import { Tag } from "@blueprintjs/core"; -import { DateRange } from "@blueprintjs/datetime"; +import type { DateRange } from "@blueprintjs/datetime"; import { ArrowRight } from "@blueprintjs/icons"; import { FormattedDateTag } from "./formattedDateTag"; diff --git a/packages/docs-app/src/components/blueprintDocs.tsx b/packages/docs-app/src/components/blueprintDocs.tsx index 2b3906d751..0040ea8c90 100644 --- a/packages/docs-app/src/components/blueprintDocs.tsx +++ b/packages/docs-app/src/components/blueprintDocs.tsx @@ -19,7 +19,7 @@ import classNames from "classnames"; import * as React from "react"; import { AnchorButton, Classes, HotkeysProvider, Tag } from "@blueprintjs/core"; -import { DocsCompleteData } from "@blueprintjs/docs-data"; +import type { DocsCompleteData } from "@blueprintjs/docs-data"; import { Banner, Documentation, DocumentationProps, NavMenuItem, NavMenuItemProps } from "@blueprintjs/docs-theme"; import { highlightCodeBlocks } from "../styles/syntaxHighlighting"; diff --git a/packages/docs-app/src/components/navHeader.tsx b/packages/docs-app/src/components/navHeader.tsx index 159763ede1..a7e941c612 100644 --- a/packages/docs-app/src/components/navHeader.tsx +++ b/packages/docs-app/src/components/navHeader.tsx @@ -14,7 +14,7 @@ * limitations under the License. */ -import { INpmPackage } from "@documentalist/client"; +import type { INpmPackage } from "@documentalist/client"; import * as React from "react"; import { Classes, HotkeysTarget2, Intent, Menu, MenuItem, NavbarHeading, Popover, Tag } from "@blueprintjs/core"; diff --git a/packages/docs-app/src/examples/core-examples/alertExample.tsx b/packages/docs-app/src/examples/core-examples/alertExample.tsx index 37b5e9c538..f88ad30025 100644 --- a/packages/docs-app/src/examples/core-examples/alertExample.tsx +++ b/packages/docs-app/src/examples/core-examples/alertExample.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { Alert, Button, H5, Intent, OverlayToaster, Switch, Toaster } from "@blueprintjs/core"; import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme"; -import { BlueprintExampleData } from "../../tags/types"; +import type { BlueprintExampleData } from "../../tags/types"; export interface AlertExampleState { canEscapeKeyCancel: boolean; diff --git a/packages/docs-app/src/examples/core-examples/calloutExample.tsx b/packages/docs-app/src/examples/core-examples/calloutExample.tsx index cbd88fb6eb..11dd3a488b 100644 --- a/packages/docs-app/src/examples/core-examples/calloutExample.tsx +++ b/packages/docs-app/src/examples/core-examples/calloutExample.tsx @@ -18,7 +18,7 @@ import * as React from "react"; import { Button, Callout, Code, H5, HTMLSelect, Intent, Label, Switch } from "@blueprintjs/core"; import { DocsExampleProps, Example, handleBooleanChange, handleNumberChange } from "@blueprintjs/docs-theme"; -import { IconName } from "@blueprintjs/icons"; +import type { IconName } from "@blueprintjs/icons"; import { IconSelect } from "./common/iconSelect"; import { IntentSelect } from "./common/intentSelect"; diff --git a/packages/docs-app/src/examples/core-examples/common/iconSelect.tsx b/packages/docs-app/src/examples/core-examples/common/iconSelect.tsx index ac9b533987..225fbe0260 100644 --- a/packages/docs-app/src/examples/core-examples/common/iconSelect.tsx +++ b/packages/docs-app/src/examples/core-examples/common/iconSelect.tsx @@ -18,7 +18,7 @@ import classNames from "classnames"; import * as React from "react"; import { Alignment, Button, Classes, MenuItem } from "@blueprintjs/core"; -import { IconName } from "@blueprintjs/icons"; +import type { IconName } from "@blueprintjs/icons"; import { ItemRenderer, Select } from "@blueprintjs/select"; import { getIconNames, IconNameOrNone, NONE } from "./iconNames"; diff --git a/packages/docs-app/src/examples/core-examples/dialogExample.tsx b/packages/docs-app/src/examples/core-examples/dialogExample.tsx index 747024cb4d..32023b1301 100644 --- a/packages/docs-app/src/examples/core-examples/dialogExample.tsx +++ b/packages/docs-app/src/examples/core-examples/dialogExample.tsx @@ -30,7 +30,7 @@ import { } from "@blueprintjs/core"; import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme"; -import { BlueprintExampleData } from "../../tags/types"; +import type { BlueprintExampleData } from "../../tags/types"; export interface DialogExampleState { autoFocus: boolean; diff --git a/packages/docs-app/src/examples/core-examples/drawerExample.tsx b/packages/docs-app/src/examples/core-examples/drawerExample.tsx index 7fe6e4bb9f..89f2146d04 100644 --- a/packages/docs-app/src/examples/core-examples/drawerExample.tsx +++ b/packages/docs-app/src/examples/core-examples/drawerExample.tsx @@ -41,7 +41,7 @@ import { handleValueChange, } from "@blueprintjs/docs-theme"; -import { BlueprintExampleData } from "../../tags/types"; +import type { BlueprintExampleData } from "../../tags/types"; export interface DrawerExampleState { autoFocus: boolean; diff --git a/packages/docs-app/src/examples/core-examples/multistepDialogExample.tsx b/packages/docs-app/src/examples/core-examples/multistepDialogExample.tsx index 6148947b12..6148edc142 100644 --- a/packages/docs-app/src/examples/core-examples/multistepDialogExample.tsx +++ b/packages/docs-app/src/examples/core-examples/multistepDialogExample.tsx @@ -40,7 +40,7 @@ import { handleValueChange, } from "@blueprintjs/docs-theme"; -import { BlueprintExampleData } from "../../tags/types"; +import type { BlueprintExampleData } from "../../tags/types"; export interface MultistepDialogExampleState { autoFocus: boolean; diff --git a/packages/docs-app/src/examples/core-examples/nonIdealStateExample.tsx b/packages/docs-app/src/examples/core-examples/nonIdealStateExample.tsx index 259517d738..dc4cbebb99 100644 --- a/packages/docs-app/src/examples/core-examples/nonIdealStateExample.tsx +++ b/packages/docs-app/src/examples/core-examples/nonIdealStateExample.tsx @@ -27,7 +27,7 @@ import { Switch, } from "@blueprintjs/core"; import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme"; -import { IconName } from "@blueprintjs/icons"; +import type { IconName } from "@blueprintjs/icons"; import { IconSelect } from "./common/iconSelect"; import { Layout, LayoutSelect } from "./common/layoutSelect"; diff --git a/packages/docs-app/src/examples/core-examples/overlayExample.tsx b/packages/docs-app/src/examples/core-examples/overlayExample.tsx index 0bbf7791cf..c947a2e744 100644 --- a/packages/docs-app/src/examples/core-examples/overlayExample.tsx +++ b/packages/docs-app/src/examples/core-examples/overlayExample.tsx @@ -19,7 +19,7 @@ import * as React from "react"; import { Button, Classes, Code, H3, H5, Intent, Overlay, Switch } from "@blueprintjs/core"; import { Example, ExampleProps, handleBooleanChange } from "@blueprintjs/docs-theme"; -import { BlueprintExampleData } from "../../tags/types"; +import type { BlueprintExampleData } from "../../tags/types"; const OVERLAY_EXAMPLE_CLASS = "docs-overlay-example-transition"; const OVERLAY_TALL_CLASS = "docs-overlay-example-tall"; diff --git a/packages/docs-app/src/examples/core-examples/toastExample.tsx b/packages/docs-app/src/examples/core-examples/toastExample.tsx index cfa0083e3a..3c1bf48c16 100644 --- a/packages/docs-app/src/examples/core-examples/toastExample.tsx +++ b/packages/docs-app/src/examples/core-examples/toastExample.tsx @@ -36,7 +36,7 @@ import { } from "@blueprintjs/core"; import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme"; -import { BlueprintExampleData } from "../../tags/types"; +import type { BlueprintExampleData } from "../../tags/types"; type ToastDemo = ToastProps & { button: string }; diff --git a/packages/docs-app/src/examples/datetime-examples/common/dateFnsDate.tsx b/packages/docs-app/src/examples/datetime-examples/common/dateFnsDate.tsx index 9589255af4..04a972312c 100644 --- a/packages/docs-app/src/examples/datetime-examples/common/dateFnsDate.tsx +++ b/packages/docs-app/src/examples/datetime-examples/common/dateFnsDate.tsx @@ -19,7 +19,7 @@ import { format, isValid } from "date-fns"; import * as React from "react"; import { Icon, Intent, Props, Tag } from "@blueprintjs/core"; -import { DateRange } from "@blueprintjs/datetime"; +import type { DateRange } from "@blueprintjs/datetime"; const FORMAT = "EEEE, MMMM d, yyyy"; const FORMAT_WITH_TIME = "MMMM d, yyyy 'at' K:mm a"; diff --git a/packages/docs-app/src/examples/datetime-examples/common/dateFnsDateFormatPropsSelect.tsx b/packages/docs-app/src/examples/datetime-examples/common/dateFnsDateFormatPropsSelect.tsx index 04c07a26aa..dc2a841323 100644 --- a/packages/docs-app/src/examples/datetime-examples/common/dateFnsDateFormatPropsSelect.tsx +++ b/packages/docs-app/src/examples/datetime-examples/common/dateFnsDateFormatPropsSelect.tsx @@ -17,7 +17,7 @@ import { format, Locale, parse } from "date-fns"; import * as React from "react"; -import { DateFormatProps } from "@blueprintjs/datetime"; +import type { DateFormatProps } from "@blueprintjs/datetime"; import { DateFormatSelector, DateFormatSelectorProps } from "../../../common/dateFormatSelector"; diff --git a/packages/docs-app/src/examples/datetime-examples/common/momentDate.tsx b/packages/docs-app/src/examples/datetime-examples/common/momentDate.tsx index 917309808a..56baad6933 100644 --- a/packages/docs-app/src/examples/datetime-examples/common/momentDate.tsx +++ b/packages/docs-app/src/examples/datetime-examples/common/momentDate.tsx @@ -19,7 +19,7 @@ import moment from "moment"; import * as React from "react"; import { Icon, Intent, Props, Tag } from "@blueprintjs/core"; -import { DateRange } from "@blueprintjs/datetime"; +import type { DateRange } from "@blueprintjs/datetime"; const FORMAT = "dddd, LL"; const FORMAT_TIME = "dddd, LL LT"; diff --git a/packages/docs-app/src/examples/datetime-examples/common/momentFormats.tsx b/packages/docs-app/src/examples/datetime-examples/common/momentFormats.tsx index 2f2b626f7c..3ad6d73638 100644 --- a/packages/docs-app/src/examples/datetime-examples/common/momentFormats.tsx +++ b/packages/docs-app/src/examples/datetime-examples/common/momentFormats.tsx @@ -17,7 +17,7 @@ import moment from "moment"; import * as React from "react"; -import { DateFormatProps } from "@blueprintjs/datetime"; +import type { DateFormatProps } from "@blueprintjs/datetime"; import { DateFormatSelector, DateFormatSelectorProps } from "../../../common/dateFormatSelector"; diff --git a/packages/docs-app/src/examples/datetime2-examples/dateRangePicker3Example.tsx b/packages/docs-app/src/examples/datetime2-examples/dateRangePicker3Example.tsx index db76c0032f..5ad85a977a 100644 --- a/packages/docs-app/src/examples/datetime2-examples/dateRangePicker3Example.tsx +++ b/packages/docs-app/src/examples/datetime2-examples/dateRangePicker3Example.tsx @@ -17,7 +17,7 @@ import * as React from "react"; import { Classes, FormGroup, H5, Switch } from "@blueprintjs/core"; -import { DateRange, TimePrecision } from "@blueprintjs/datetime"; +import type { DateRange, TimePrecision } from "@blueprintjs/datetime"; import { DateRangePicker3 } from "@blueprintjs/datetime2"; import { Example, ExampleProps, handleBooleanChange, handleValueChange } from "@blueprintjs/docs-theme"; diff --git a/packages/docs-app/src/examples/select-examples/selectExample.tsx b/packages/docs-app/src/examples/select-examples/selectExample.tsx index b34b31e5df..12fe3112a4 100644 --- a/packages/docs-app/src/examples/select-examples/selectExample.tsx +++ b/packages/docs-app/src/examples/select-examples/selectExample.tsx @@ -18,7 +18,7 @@ import * as React from "react"; import { H5, Menu, MenuDivider, MenuItem, Switch } from "@blueprintjs/core"; import { Example, ExampleProps } from "@blueprintjs/docs-theme"; -import { ItemListRendererProps } from "@blueprintjs/select"; +import type { ItemListRendererProps } from "@blueprintjs/select"; import { Film, FilmSelect, filterFilm, TOP_100_FILMS } from "@blueprintjs/select/examples"; export interface SelectExampleState { diff --git a/packages/docs-app/src/tags/reactExamples.ts b/packages/docs-app/src/tags/reactExamples.ts index 937eb5c072..61d886b2fd 100644 --- a/packages/docs-app/src/tags/reactExamples.ts +++ b/packages/docs-app/src/tags/reactExamples.ts @@ -16,7 +16,7 @@ import * as React from "react"; -import { ExampleMap, ExampleProps } from "@blueprintjs/docs-theme"; +import type { ExampleMap, ExampleProps } from "@blueprintjs/docs-theme"; import { getTheme } from "../components/blueprintDocs"; import * as CoreExamples from "../examples/core-examples"; @@ -24,7 +24,7 @@ import * as DatetimeExamples from "../examples/datetime-examples"; import * as Datetime2Examples from "../examples/datetime2-examples"; import * as SelectExamples from "../examples/select-examples"; import * as TableExamples from "../examples/table-examples"; -import { BlueprintExampleData } from "./types"; +import type { BlueprintExampleData } from "./types"; const SRC_HREF_BASE = "https://github.com/palantir/blueprint/blob/develop/packages/docs-app/src/examples"; From 74951975db788964a2b4972c5fe9d3c1ffcaa02a Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:49:10 -0400 Subject: [PATCH 15/19] [eslint-plugin] revert inadvertent change --- .../eslint-plugin/test/no-deprecated-type-references.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/test/no-deprecated-type-references.test.ts b/packages/eslint-plugin/test/no-deprecated-type-references.test.ts index fc4a7ed4b6..d1c4c8e0e0 100644 --- a/packages/eslint-plugin/test/no-deprecated-type-references.test.ts +++ b/packages/eslint-plugin/test/no-deprecated-type-references.test.ts @@ -49,7 +49,7 @@ ruleTester.run("no-deprecated-type-references", noDeprecatedTypeReferencesRule, }, ], output: dedent` - import type { Props } from "@blueprintjs/core"; + import { Props } from "@blueprintjs/core"; export interface MyInterface extends Props { foo: string; From 8708de933bb2df1be110ff080d1274dfa40893bd Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 11:50:31 -0400 Subject: [PATCH 16/19] [datetime2] fix test typecheck --- packages/datetime2/test/common/dayPickerTestUtils.ts | 2 +- packages/datetime2/test/components/datePicker3Tests.tsx | 2 +- packages/datetime2/test/components/dateRangePicker3Tests.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/datetime2/test/common/dayPickerTestUtils.ts b/packages/datetime2/test/common/dayPickerTestUtils.ts index 7e23aff782..539b754173 100644 --- a/packages/datetime2/test/common/dayPickerTestUtils.ts +++ b/packages/datetime2/test/common/dayPickerTestUtils.ts @@ -17,7 +17,7 @@ /** @fileoverview test utils for react-day-picker v8 */ import { assert } from "chai"; -import { ReactWrapper } from "enzyme"; +import type { ReactWrapper } from "enzyme"; import { Classes } from "../../src/classes"; diff --git a/packages/datetime2/test/components/datePicker3Tests.tsx b/packages/datetime2/test/components/datePicker3Tests.tsx index b1b524c373..2abfca36d5 100644 --- a/packages/datetime2/test/components/datePicker3Tests.tsx +++ b/packages/datetime2/test/components/datePicker3Tests.tsx @@ -36,7 +36,7 @@ import { assertDatesEqual } from "@blueprintjs/test-commons"; import { Classes } from "../../src/classes"; import * as DateFnsLocaleUtils from "../../src/common/dateFnsLocaleUtils"; import { DatePicker3, DatePicker3Props } from "../../src/components/date-picker3/datePicker3"; -import { DatePicker3State } from "../../src/components/date-picker3/datePicker3State"; +import type { DatePicker3State } from "../../src/components/date-picker3/datePicker3State"; import { assertDayDisabled, assertDayHidden } from "../common/dayPickerTestUtils"; import { loadDateFnsLocaleFake } from "../common/loadDateFnsLocaleFake"; diff --git a/packages/datetime2/test/components/dateRangePicker3Tests.tsx b/packages/datetime2/test/components/dateRangePicker3Tests.tsx index cec9775d73..d2cb0bd923 100644 --- a/packages/datetime2/test/components/dateRangePicker3Tests.tsx +++ b/packages/datetime2/test/components/dateRangePicker3Tests.tsx @@ -38,7 +38,7 @@ import { import { DateRangePicker3, DateRangePicker3Props, Datetime2Classes, ReactDayPickerClasses } from "../../src"; import * as DateFnsLocaleUtils from "../../src/common/dateFnsLocaleUtils"; -import { DateRangePicker3State } from "../../src/components/date-range-picker3/dateRangePicker3State"; +import type { DateRangePicker3State } from "../../src/components/date-range-picker3/dateRangePicker3State"; import { assertDayDisabled } from "../common/dayPickerTestUtils"; import { loadDateFnsLocaleFake } from "../common/loadDateFnsLocaleFake"; From 11495e8293a8e99861a1e122e650d4187193488f Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 12:25:56 -0400 Subject: [PATCH 17/19] [datetime2] make date-fns locale loader configurable, adjust test stubs --- .../src/common/dateFnsLocaleProps.ts | 14 ++ .../src/common/dateFnsLocaleUtils.ts | 41 ++-- .../src/components/date-input3/dateInput3.tsx | 8 +- .../components/date-input3/dateInput3Props.ts | 6 +- .../components/date-picker3/datePicker3.tsx | 9 +- .../date-range-input3/dateRangeInput3Props.ts | 5 +- .../date-range-picker3/dateRangePicker3.tsx | 9 +- .../test/components/dateInput3Tests.tsx | 19 +- .../test/components/datePicker3Tests.tsx | 223 ++++++++++++------ .../test/components/dateRangeInput3Tests.tsx | 19 +- 10 files changed, 226 insertions(+), 127 deletions(-) diff --git a/packages/datetime2/src/common/dateFnsLocaleProps.ts b/packages/datetime2/src/common/dateFnsLocaleProps.ts index 2ab25d83a5..41d90a2cf0 100644 --- a/packages/datetime2/src/common/dateFnsLocaleProps.ts +++ b/packages/datetime2/src/common/dateFnsLocaleProps.ts @@ -16,7 +16,21 @@ import type { Locale } from "date-fns"; +/** + * @param localeCode - ISO 639-1 + optional country code + * @returns date-fns `Locale` object + */ +export type DateFnsLocaleLoader = (localeCode: string) => Promise; + export interface DateFnsLocaleProps { + /** + * Optional custom loader function for the date-fns `Locale` which will be used to localize the date picker. + * This is useful in test environments or in build systems where you wish to customize module loading behavior. + * If not provided, a default loader will be used which uses dynamic imports to load `date-fns/locale/${localeCode}` + * modules. + */ + dateFnsLocaleLoader?: DateFnsLocaleLoader; + /** * date-fns `Locale` object or locale code string ((ISO 639-1 + optional country code) which will be used * to localize the date picker. diff --git a/packages/datetime2/src/common/dateFnsLocaleUtils.ts b/packages/datetime2/src/common/dateFnsLocaleUtils.ts index 0adf739714..0216a6b23c 100644 --- a/packages/datetime2/src/common/dateFnsLocaleUtils.ts +++ b/packages/datetime2/src/common/dateFnsLocaleUtils.ts @@ -19,36 +19,35 @@ import * as React from "react"; import { Utils } from "@blueprintjs/core"; +import type { DateFnsLocaleLoader } from "./dateFnsLocaleProps"; + /** * Lazy-loads a date-fns locale for use in a datetime class component. */ -export async function loadDateFnsLocale(localeOrCode: Locale | string | undefined): Promise { - if (localeOrCode === undefined) { - return; - } else if (typeof localeOrCode === "string") { - try { - const localeModule = await import( - /* webpackChunkName: "date-fns-locale-[request]" */ - `date-fns/locale/${localeOrCode}/index.js` +export async function loadDateFnsLocale(localeCode: string): Promise { + try { + const localeModule = await import( + /* webpackChunkName: "date-fns-locale-[request]" */ + `date-fns/locale/${localeCode}/index.js` + ); + return localeModule.default; + } catch { + if (!Utils.isNodeEnv("production")) { + console.error( + `[Blueprint] Could not load "${localeCode}" date-fns locale, please check that this locale code is supported: https://github.com/date-fns/date-fns/tree/main/src/locale`, ); - return localeModule.default; - } catch { - if (!Utils.isNodeEnv("production")) { - console.error( - `[Blueprint] Could not load "${localeOrCode}" date-fns locale, please check that this locale code is supported: https://github.com/date-fns/date-fns/tree/main/src/locale`, - ); - } - return undefined; } + return undefined; } - - return localeOrCode; } /** * Lazy-loads a date-fns locale for use in a datetime function component. */ -export function useDateFnsLocale(localeOrCode: Locale | string | undefined) { +export function useDateFnsLocale( + localeOrCode: Locale | string | undefined, + dateFnsLocaleLoader: DateFnsLocaleLoader = loadDateFnsLocale, +) { // make sure to set the locale correctly on first render if it is available const [locale, setLocale] = React.useState( typeof localeOrCode === "object" ? localeOrCode : undefined, @@ -57,13 +56,13 @@ export function useDateFnsLocale(localeOrCode: Locale | string | undefined) { React.useEffect(() => { setLocale(prevLocale => { if (typeof localeOrCode === "string") { - loadDateFnsLocale(localeOrCode).then(setLocale); + dateFnsLocaleLoader(localeOrCode).then(setLocale); // keep the current locale for now, it will be updated async return prevLocale; } else { return localeOrCode; } }); - }, [localeOrCode]); + }, [dateFnsLocaleLoader, localeOrCode]); return locale; } diff --git a/packages/datetime2/src/components/date-input3/dateInput3.tsx b/packages/datetime2/src/components/date-input3/dateInput3.tsx index c1d6241023..e918e2dcf3 100644 --- a/packages/datetime2/src/components/date-input3/dateInput3.tsx +++ b/packages/datetime2/src/components/date-input3/dateInput3.tsx @@ -41,7 +41,8 @@ import { import { Classes } from "../../classes"; import { getDefaultDateFnsFormat } from "../../common/dateFnsFormatUtils"; import { useDateFnsLocale } from "../../common/dateFnsLocaleUtils"; -import { DatePicker3, DatePicker3Props } from "../date-picker3/datePicker3"; +import type { ReactDayPickerSingleProps } from "../../common/reactDayPickerProps"; +import { DatePicker3 } from "../date-picker3/datePicker3"; import type { DateInput3DefaultProps, DateInput3Props, DateInput3PropsWithDefaults } from "./dateInput3Props"; import { useDateFormatter } from "./useDateFormatter"; import { useDateParser } from "./useDateParser"; @@ -73,6 +74,7 @@ export const DateInput3: React.FC = React.memo(function _DateIn const { closeOnSelection, dateFnsFormat, + dateFnsLocaleLoader, defaultTimezone, defaultValue, disabled, @@ -97,7 +99,7 @@ export const DateInput3: React.FC = React.memo(function _DateIn ...datePickerProps } = props as DateInput3PropsWithDefaults; - const locale = useDateFnsLocale(localeOrCode); + const locale = useDateFnsLocale(localeOrCode, dateFnsLocaleLoader); const placeholder = getPlaceholder(props); const formatDateString = useDateFormatter(props, locale); const parseDateString = useDateParser(props, locale); @@ -231,7 +233,7 @@ export const DateInput3: React.FC = React.memo(function _DateIn [closeOnSelection, isControlled, formatDateString, onChange, timezoneValue, timePrecision, valueAsDate], ); - const dayPickerProps: DatePicker3Props["dayPickerProps"] = { + const dayPickerProps: ReactDayPickerSingleProps["dayPickerProps"] = { ...props.dayPickerProps, onDayKeyDown: (day, modifiers, e) => { props.dayPickerProps?.onDayKeyDown?.(day, modifiers, e); diff --git a/packages/datetime2/src/components/date-input3/dateInput3Props.ts b/packages/datetime2/src/components/date-input3/dateInput3Props.ts index b48b2a78ee..ba1c49a5a5 100644 --- a/packages/datetime2/src/components/date-input3/dateInput3Props.ts +++ b/packages/datetime2/src/components/date-input3/dateInput3Props.ts @@ -16,7 +16,8 @@ import type { DateFormatProps, DateInputProps } from "@blueprintjs/datetime"; -import type { DatePicker3Props } from "../date-picker3/datePicker3Props"; +import type { DateFnsLocaleProps } from "../../common/dateFnsLocaleProps"; +import type { ReactDayPickerSingleProps } from "../../common/reactDayPickerProps"; /** * Props shared between DateInput v1 and v3. @@ -31,7 +32,8 @@ type DateInputSharedProps = Omit< export interface DateInput3Props extends DateInputSharedProps, - Pick, + ReactDayPickerSingleProps, + DateFnsLocaleProps, Partial> { /** * [date-fns format](https://date-fns.org/docs/format) string used to format & parse date strings. diff --git a/packages/datetime2/src/components/date-picker3/datePicker3.tsx b/packages/datetime2/src/components/date-picker3/datePicker3.tsx index 9ce9e1af2a..f4edc1061f 100644 --- a/packages/datetime2/src/components/date-picker3/datePicker3.tsx +++ b/packages/datetime2/src/components/date-picker3/datePicker3.tsx @@ -184,8 +184,13 @@ export class DatePicker3 extends AbstractPureComponent; -export type DateRangeInput3Props = DateRangeInputSharedProps & Pick; +export type DateRangeInput3Props = DateRangeInputSharedProps & ReactDayPickerRangeProps & DateFnsLocaleProps; export type DateRangeInput3DefaultProps = Required< Pick< diff --git a/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx b/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx index 82e8c51c38..12fd259028 100644 --- a/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx +++ b/packages/datetime2/src/components/date-range-picker3/dateRangePicker3.tsx @@ -227,8 +227,13 @@ export class DateRangePicker3 extends AbstractPureComponent item.label === "New York")!; @@ -45,7 +45,8 @@ const TOKYO_TIMEZONE = TIMEZONE_ITEMS.find(item => item.label === "Tokyo")!; const VALUE = "2021-11-29T10:30:00z"; -const DEFAULT_PROPS = { +const DEFAULT_PROPS: DateInput3Props & DateFormatProps = { + dateFnsLocaleLoader: loadDateFnsLocaleFake, defaultTimezone: TimezoneUtils.UTC_TIME.ianaCode, formatDate: (date: Date | null | undefined, localeCode?: string) => { if (date == null) { @@ -75,11 +76,6 @@ const DEFAULT_PROPS = { describe("", () => { const onChange = sinon.spy(); let testsContainerElement: HTMLElement | undefined; - let loadDateFnsLocaleStub: sinon.SinonStub; - - before(() => { - loadDateFnsLocaleStub = sinon.stub(DateFnsLocaleUtils, "loadDateFnsLocale").callsFake(loadDateFnsLocaleFake); - }); beforeEach(() => { testsContainerElement = document.createElement("div"); @@ -91,10 +87,6 @@ describe("", () => { onChange.resetHistory(); }); - after(() => { - loadDateFnsLocaleStub.restore(); - }); - describe("basic rendering", () => { it("passes custom classNames to popover target", () => { const CLASS_1 = "foo"; @@ -451,7 +443,10 @@ describe("", () => { assert.strictEqual(wrapper.find(InputGroup).prop("value"), rangeMessage); assert.isTrue(onError.calledOnce); - assert.strictEqual(DEFAULT_PROPS.formatDate(onError.args[0][0]), DEFAULT_PROPS.formatDate(new Date(value))); + assert.strictEqual( + DEFAULT_PROPS.formatDate!(onError.args[0][0]), + DEFAULT_PROPS.formatDate!(new Date(value)), + ); }); it("typing in an invalid date displays the error message and calls onError with Date(undefined)", () => { diff --git a/packages/datetime2/test/components/datePicker3Tests.tsx b/packages/datetime2/test/components/datePicker3Tests.tsx index 2abfca36d5..c7fc274b62 100644 --- a/packages/datetime2/test/components/datePicker3Tests.tsx +++ b/packages/datetime2/test/components/datePicker3Tests.tsx @@ -34,29 +34,22 @@ import { import { assertDatesEqual } from "@blueprintjs/test-commons"; import { Classes } from "../../src/classes"; -import * as DateFnsLocaleUtils from "../../src/common/dateFnsLocaleUtils"; import { DatePicker3, DatePicker3Props } from "../../src/components/date-picker3/datePicker3"; import type { DatePicker3State } from "../../src/components/date-picker3/datePicker3State"; import { assertDayDisabled, assertDayHidden } from "../common/dayPickerTestUtils"; import { loadDateFnsLocaleFake } from "../common/loadDateFnsLocaleFake"; +const DEFAULT_PROPS: DatePicker3Props = { + dateFnsLocaleLoader: loadDateFnsLocaleFake, +}; + describe("", () => { let testsContainerElement: HTMLElement; let datePicker3Wrapper: ReactWrapper; - let loadDateFnsLocaleStub: sinon.SinonStub; - - before(() => { - loadDateFnsLocaleStub = sinon.stub(DateFnsLocaleUtils, "loadDateFnsLocale").callsFake(loadDateFnsLocaleFake); - }); beforeEach(() => { testsContainerElement = document.createElement("div"); document.body.appendChild(testsContainerElement); - loadDateFnsLocaleStub.resetHistory(); - }); - - after(() => { - loadDateFnsLocaleStub.restore(); }); afterEach(() => { @@ -66,22 +59,22 @@ describe("", () => { }); it(`renders .${Classes.DATEPICKER}`, () => { - assert.lengthOf(wrap().root.find(`.${Classes.DATEPICKER}`), 1); + assert.lengthOf(wrap().root.find(`.${Classes.DATEPICKER}`), 1); }); it("no day is selected by default", () => { - const { assertSelectedDays, root } = wrap(); + const { assertSelectedDays, root } = wrap(); assertSelectedDays(); assert.isNull(root.state("selectedDay")); }); it("current day is not highlighted by default", () => { - const { root } = wrap(); + const { root } = wrap(); assert.lengthOf(root.find(`.${Classes.DATEPICKER3_HIGHLIGHT_CURRENT_DAY}`), 0); }); it("current day should be highlighted when highlightCurrentDay={true}", () => { - const { root } = wrap(); + const { root } = wrap(); assert.lengthOf(root.find(`.${Classes.DATEPICKER3_HIGHLIGHT_CURRENT_DAY}`), 1); }); @@ -89,7 +82,7 @@ describe("", () => { it("shows outside days by default", () => { const defaultValue = new Date(2017, Months.SEPTEMBER, 1); const firstDayInView = new Date(2017, Months.AUGUST, 27, 12, 0); - const { root } = wrap(); + const { root } = wrap(); // TODO: refactor this to avoid knowing about react-day-picker's internal component names const firstDay = root.find(Day).first(); assertDatesEqual(new Date(firstDay.prop("date")), firstDayInView); @@ -98,7 +91,11 @@ describe("", () => { it("doesn't show outside days if enableOutsideDays=false", () => { const defaultValue = new Date(2017, Months.SEPTEMBER, 1, 12); const { root } = wrap( - , + , ); const days = root.find(Day); @@ -128,7 +125,11 @@ describe("", () => { it("disables out-of-range max dates", () => { const defaultValue = new Date(2017, Months.SEPTEMBER, 1); const { getDay } = wrap( - , + , ); assertDayDisabled(getDay(21)); assertDayDisabled(getDay(10), false); @@ -137,7 +138,11 @@ describe("", () => { it("disables out-of-range min dates", () => { const defaultValue = new Date(2017, Months.SEPTEMBER, 1); const { getDay, clickPreviousMonth } = wrap( - , + , ); clickPreviousMonth(); assertDayDisabled(getDay(10)); @@ -150,35 +155,45 @@ describe("", () => { it("calls onMonthChange on button next click", () => { const onMonthChange = sinon.spy(); - const { root } = wrap(); + const { root } = wrap( + , + ); root.find(`.${Classes.DATEPICKER3_NAV_BUTTON_NEXT}`).first().simulate("click"); assert.isTrue(onMonthChange.called); }); it("calls onMonthChange on button prev click", () => { const onMonthChange = sinon.spy(); - const { root } = wrap(); + const { root } = wrap( + , + ); root.find(`.${Classes.DATEPICKER3_NAV_BUTTON_PREVIOUS}`).first().simulate("click"); assert.isTrue(onMonthChange.called); }); it("calls onMonthChange on month select change", () => { const onMonthChange = sinon.spy(); - const { root } = wrap(); + const { root } = wrap( + , + ); root.find(`.${Classes.DATEPICKER_MONTH_SELECT}`).first().find("select").simulate("change"); assert.isTrue(onMonthChange.called); }); it("calls onMonthChange on year select change", () => { const onMonthChange = sinon.spy(); - const { root } = wrap(); + const { root } = wrap( + , + ); root.find(`.${Classes.DATEPICKER_YEAR_SELECT}`).first().find("select").simulate("change"); assert.isTrue(onMonthChange.called); }); it("calls onDayClick", () => { const onDayClick = sinon.spy(); - const { getDay } = wrap(); + const { getDay } = wrap( + , + ); getDay().simulate("click"); assert.isTrue(onDayClick.called); }); @@ -189,7 +204,10 @@ describe("", () => { const ODD_CLASS = "test-odd"; const oddifier = (d: Date) => d.getDate() % 2 === 1; const { getDay } = wrap( - , + , ); assert.isFalse(getDay(4).hasClass(ODD_CLASS)); @@ -197,14 +215,14 @@ describe("", () => { }); it("renders the actions bar when showActionsBar=true", () => { - const { root } = wrap(); + const { root } = wrap(); assert.lengthOf(root.find({ className: Classes.DATEPICKER_FOOTER }), 1); }); describe("initially displayed month", () => { it("is defaultValue", () => { const defaultValue = new Date(2007, Months.APRIL, 4); - const { root } = wrap(); + const { root } = wrap(); assert.equal(root.state("displayYear"), 2007); assert.equal(root.state("displayMonth"), Months.APRIL); }); @@ -212,21 +230,23 @@ describe("", () => { it("is initialMonth if set (overrides defaultValue)", () => { const defaultValue = new Date(2007, Months.APRIL, 4); const initialMonth = new Date(2002, Months.MARCH, 1); - const { root } = wrap(); + const { root } = wrap( + , + ); assert.equal(root.state("displayYear"), 2002); assert.equal(root.state("displayMonth"), Months.MARCH); }); it("is value if set and initialMonth not set", () => { const value = new Date(2007, Months.APRIL, 4); - const { root } = wrap(); + const { root } = wrap(); assert.equal(root.state("displayYear"), 2007); assert.equal(root.state("displayMonth"), Months.APRIL); }); it("is today if today is within date range", () => { const today = new Date(); - const { root } = wrap(); + const { root } = wrap(); assert.equal(root.state("displayYear"), today.getFullYear()); assert.equal(root.state("displayMonth"), today.getMonth()); }); @@ -234,7 +254,7 @@ describe("", () => { it("is a day between minDate and maxDate if today is not in range", () => { const maxDate = new Date(2005, Months.JANUARY); const minDate = new Date(2000, Months.JANUARY); - const { root } = wrap(); + const { root } = wrap(); assert.isTrue( DateUtils.isDayInRange(new Date(root.state("displayYear"), root.state("displayMonth")), [ minDate, @@ -245,13 +265,13 @@ describe("", () => { it("selectedDay is set to the day of the value", () => { const value = new Date(2007, Months.APRIL, 4); - const { root } = wrap(); + const { root } = wrap(); assert.strictEqual(root.state("selectedDay"), value.getDate()); }); it("selectedDay is set to the day of the defaultValue", () => { const defaultValue = new Date(2007, Months.APRIL, 4); - const { root } = wrap(); + const { root } = wrap(); assert.strictEqual(root.state("selectedDay"), defaultValue.getDate()); }); }); @@ -268,7 +288,7 @@ describe("", () => { after(() => consoleError.restore()); it("maxDate must be later than minDate", () => { - wrap(); + wrap(); assert.isTrue(consoleError.calledWith(Errors.DATEPICKER_MAX_DATE_INVALID)); }); @@ -284,7 +304,14 @@ describe("", () => { }); it("an error is logged if value is outside bounds", () => { - wrap(); + wrap( + , + ); assert.isTrue(consoleError.calledWith(Errors.DATEPICKER_VALUE_INVALID)); }); @@ -333,7 +360,12 @@ describe("", () => { it("min/max after today has disabled button", () => { const { getTodayButton } = wrap( - , + , ); assert.isTrue(getTodayButton().props().disabled); @@ -354,7 +386,7 @@ describe("", () => { it("only days outside bounds have disabled class", () => { const minDate = new Date(2000, Months.JANUARY, 10); - const { getDay } = wrap(); + const { getDay } = wrap(); // 8 is before min date, 12 is after assert.isTrue(getDay(8).hasClass(Classes.DATEPICKER3_DAY_DISABLED)); assert.isFalse(getDay(12).hasClass(Classes.DATEPICKER3_DAY_DISABLED)); @@ -362,7 +394,9 @@ describe("", () => { it("onChange not fired when a day outside of bounds is clicked", () => { const onChange = sinon.spy(); - const { getDay } = wrap(); + const { getDay } = wrap( + , + ); assert.isTrue(onChange.notCalled); getDay(4).simulate("click"); getDay(16).simulate("click"); @@ -402,13 +436,13 @@ describe("", () => { it("value initially selects a day", () => { const value = new Date(2010, Months.JANUARY, 1); const { assertSelectedDays } = wrap( - , + , ); assertSelectedDays(value.getDate()); }); it("selection does not update automatically", () => { - const { getDay, assertSelectedDays } = wrap(); + const { getDay, assertSelectedDays } = wrap(); assertSelectedDays(); getDay().simulate("click"); assertSelectedDays(); @@ -416,7 +450,9 @@ describe("", () => { it("selected day doesn't update on current month view change", () => { const value = new Date(2010, Months.JANUARY, 2); - const { assertSelectedDays, clickPreviousMonth, months, years } = wrap(); + const { assertSelectedDays, clickPreviousMonth, months, years } = wrap( + , + ); clickPreviousMonth(); assertSelectedDays(2); @@ -430,7 +466,7 @@ describe("", () => { it("onChange fired when a day is clicked", () => { const onChange = sinon.spy(); - const { getDay } = wrap(); + const { getDay } = wrap(); getDay().simulate("click"); assert.isTrue(onChange.calledOnce); assert.isTrue(onChange.args[0][1]); @@ -439,7 +475,9 @@ describe("", () => { it("onChange fired when month is changed", () => { const value = new Date(2010, Months.JANUARY, 2); const onChange = sinon.spy(); - const { months, clickPreviousMonth } = wrap(); + const { months, clickPreviousMonth } = wrap( + , + ); clickPreviousMonth(); assert.isTrue(onChange.calledOnce, "expected onChange called"); @@ -452,7 +490,7 @@ describe("", () => { it("can change displayed date with the dropdowns in the caption", () => { const { months, root, years } = wrap( - , + , ); assert.equal(root.state("displayMonth"), Months.MARCH); assert.equal(root.state("displayYear"), 2015); @@ -468,7 +506,9 @@ describe("", () => { const aWeekAgo = DateUtils.clone(today); aWeekAgo.setDate(today.getDate() - 6); const onChange = sinon.spy(); - const { clickShortcut } = wrap(); + const { clickShortcut } = wrap( + , + ); clickShortcut(2); assert.isTrue(onChange.calledOnce, "called"); @@ -477,7 +517,7 @@ describe("", () => { }); it("all shortcuts are displayed as inactive when none are selected", () => { - const { root } = wrap(); + const { root } = wrap(); assert.isFalse( root.find(DatePickerShortcutMenu).find(Menu).find(MenuItem).find(`.${CoreClasses.ACTIVE}`).exists(), @@ -486,7 +526,9 @@ describe("", () => { it("corresponding shortcut is displayed as active when selected", () => { const selectedShortcut = 0; - const { root } = wrap(); + const { root } = wrap( + , + ); assert.isTrue( root.find(DatePickerShortcutMenu).find(Menu).find(MenuItem).find(`.${CoreClasses.ACTIVE}`).exists(), @@ -505,7 +547,12 @@ describe("", () => { const onShortcutChangeSpy = sinon.spy(); const onChangeSpy = sinon.spy(); const { clickShortcut } = wrap( - , + , ); clickShortcut(selectedShortcut); @@ -520,7 +567,11 @@ describe("", () => { const date = new Date(2015, Months.JANUARY, 1); const onChangeSpy = sinon.spy(); const { clickShortcut, assertSelectedDays } = wrap( - , + , ); clickShortcut(); assert.isTrue(onChangeSpy.calledOnce); @@ -533,13 +584,13 @@ describe("", () => { describe("when uncontrolled", () => { it("defaultValue initially selects a day", () => { const today = new Date(); - const { assertSelectedDays } = wrap(); + const { assertSelectedDays } = wrap(); assertSelectedDays(today.getDate()); }); it("onChange fired when a day is clicked", () => { const onChange = sinon.spy(); - const { getDay } = wrap(); + const { getDay } = wrap(); assert.isTrue(onChange.notCalled); getDay().simulate("click"); assert.isTrue(onChange.calledOnce); @@ -549,7 +600,11 @@ describe("", () => { const onChange = sinon.spy(); // must use an initial month otherwise clicking next month in december will fail const { getDay, clickNextMonth } = wrap( - , + , ); assert.isTrue(onChange.notCalled); getDay().simulate("click"); @@ -559,7 +614,7 @@ describe("", () => { }); it("selected day updates are automatic", () => { - const { assertSelectedDays, getDay } = wrap(); + const { assertSelectedDays, getDay } = wrap(); assertSelectedDays(); getDay(3).simulate("click"); assertSelectedDays(3); @@ -567,7 +622,9 @@ describe("", () => { it("selected day is preserved when selections are changed", () => { const initialMonth = new Date(2015, Months.JULY, 1); - const { assertSelectedDays, getDay, months } = wrap(); + const { assertSelectedDays, getDay, months } = wrap( + , + ); getDay(31).simulate("click"); months.simulate("change", { target: { value: Months.AUGUST } }); assertSelectedDays(31); @@ -576,7 +633,7 @@ describe("", () => { it("selected day is changed if necessary when selections are changed", () => { const initialMonth = new Date(2015, Months.JULY, 1); const { assertSelectedDays, getDay, clickPreviousMonth } = wrap( - , + , ); getDay(31).simulate("click"); clickPreviousMonth(); @@ -591,7 +648,7 @@ describe("", () => { const minDate = new Date(2015, Months.MARCH, 13); const maxDate = new Date(2015, Months.NOVEMBER, 21); const { assertSelectedDays, getDay, months } = wrap( - , + , ); getDay(1).simulate("click"); @@ -604,7 +661,9 @@ describe("", () => { }); it("can change displayed date with the dropdowns in the caption", () => { - const { months, root, years } = wrap(); + const { months, root, years } = wrap( + , + ); assert.equal(root.state("displayMonth"), Months.MARCH); assert.equal(root.state("displayYear"), 2015); @@ -615,7 +674,7 @@ describe("", () => { }); it("shortcuts select values", () => { - const { root, clickShortcut } = wrap(); + const { root, clickShortcut } = wrap(); clickShortcut(2); const today = new Date(); @@ -629,7 +688,7 @@ describe("", () => { it("custom shortcuts select the correct values", () => { const date = new Date(2010, Months.JANUARY, 10); const { clickShortcut, assertSelectedDays } = wrap( - , + , ); clickShortcut(); assertSelectedDays(date.getDate()); @@ -640,14 +699,14 @@ describe("", () => { const defaultValue = new Date(2012, 2, 5, 6, 5, 40); it("setting timePrecision shows a TimePicker", () => { - const { root } = wrap(); + const { root } = wrap(); assert.isFalse(root.find(TimePicker).exists()); root.setProps({ timePrecision: "minute" }); assert.isTrue(root.find(TimePicker).exists()); }); it("setting timePickerProps shows a TimePicker", () => { - const { root } = wrap(); + const { root } = wrap(); assert.isTrue(root.find(TimePicker).exists()); }); @@ -669,7 +728,14 @@ describe("", () => { it("changing date does not change time", () => { const onChangeSpy = sinon.spy(); - wrap() + wrap( + , + ) .getDay(16) .simulate("click"); assert.isTrue(DateUtils.isSameTime(onChangeSpy.firstCall.args[0] as Date, defaultValue)); @@ -678,7 +744,12 @@ describe("", () => { it("changing time does not change date", () => { const onChangeSpy = sinon.spy(); const { setTimeInput } = wrap( - , + , ); setTimeInput("minute", 45); assert.isTrue(DateUtils.isSameDay(onChangeSpy.firstCall.args[0] as Date, defaultValue)); @@ -687,7 +758,9 @@ describe("", () => { it("changing time without date uses today", () => { const onChangeSpy = sinon.spy(); // no date set via props - const { setTimeInput } = wrap(); + const { setTimeInput } = wrap( + , + ); setTimeInput("minute", 45); assert.isTrue(DateUtils.isSameDay(onChangeSpy.firstCall.args[0] as Date, new Date())); }); @@ -720,7 +793,7 @@ describe("", () => { describe("clearing a selection", () => { it("onChange correctly passes a Date and never null when canClearSelection is false", () => { const onChange = sinon.spy(); - const { getDay } = wrap(); + const { getDay } = wrap(); getDay().simulate("click"); assert.isNotNull(onChange.firstCall.args[0]); getDay().simulate("click"); @@ -729,7 +802,7 @@ describe("", () => { it("onChange correctly passes a Date or null when canClearSelection is true", () => { const onChange = sinon.spy(); - const { getDay } = wrap(); + const { getDay } = wrap(); getDay().simulate("click"); assert.isNotNull(onChange.firstCall.args[0]); getDay().simulate("click"); @@ -737,17 +810,21 @@ describe("", () => { }); it("Clear button disabled when canClearSelection is false", () => { - const { getClearButton } = wrap(); + const { getClearButton } = wrap( + , + ); assert.isTrue(getClearButton().props().disabled); }); it("Clear button enabled when canClearSelection is true", () => { - const { getClearButton } = wrap(); + const { getClearButton } = wrap( + , + ); assert.isFalse(getClearButton().props().disabled); }); it("selects the current day when Today is clicked", () => { - const { root } = wrap(); + const { root } = wrap(); root.find({ className: Classes.DATEPICKER_FOOTER }).find(Button).first().simulate("click"); const today = new Date(); @@ -759,7 +836,7 @@ describe("", () => { }); it("clears the value when Clear is clicked", () => { - const { getDay, root } = wrap(); + const { getDay, root } = wrap(); getDay().simulate("click"); root.find({ className: Classes.DATEPICKER_FOOTER }).find(Button).last().simulate("click"); assert.isNull(root.state("value")); @@ -768,8 +845,10 @@ describe("", () => { describe("localization", () => { it("accept a statically-loaded date-fns locale and doesn't try to load it again", () => { - wrap(); - assert.isTrue(loadDateFnsLocaleStub.calledOnceWithExactly(enUSLocale)); + const stub = sinon.stub(); + stub.callsFake(loadDateFnsLocaleFake); + wrap(); + assert.isTrue(stub.notCalled, "Expected locale loader not to be called"); }); }); diff --git a/packages/datetime2/test/components/dateRangeInput3Tests.tsx b/packages/datetime2/test/components/dateRangeInput3Tests.tsx index 1dbdcf02a9..845e803f85 100644 --- a/packages/datetime2/test/components/dateRangeInput3Tests.tsx +++ b/packages/datetime2/test/components/dateRangeInput3Tests.tsx @@ -36,8 +36,13 @@ import { import { DateFormatProps, DateRange, Classes as DatetimeClasses, Months, TimePrecision } from "@blueprintjs/datetime"; import { expectPropValidationError } from "@blueprintjs/test-commons"; -import { DateRangeInput3, DateRangePicker3, Datetime2Classes, ReactDayPickerClasses } from "../../src"; -import * as DateFnsLocaleUtils from "../../src/common/dateFnsLocaleUtils"; +import { + DateRangeInput3, + DateRangeInput3Props, + DateRangePicker3, + Datetime2Classes, + ReactDayPickerClasses, +} from "../../src"; import { loadDateFnsLocaleFake } from "../common/loadDateFnsLocaleFake"; type NullableRange = [T | null, T | null]; @@ -61,17 +66,13 @@ type InvalidDateTestFunction = ( // Change the default for testability DateRangeInput3.defaultProps.popoverProps = { usePortal: false }; +(DateRangeInput3.defaultProps as DateRangeInput3Props).dateFnsLocaleLoader = loadDateFnsLocaleFake; const DATE_FORMAT = getDateFnsFormatter("M/d/yyyy"); const DATETIME_FORMAT = getDateFnsFormatter("M/d/yyyy HH:mm:ss"); describe("", () => { let containerElement: HTMLElement | undefined; - let loadDateFnsLocaleStub: sinon.SinonStub; - - before(() => { - loadDateFnsLocaleStub = sinon.stub(DateFnsLocaleUtils, "loadDateFnsLocale").callsFake(loadDateFnsLocaleFake); - }); beforeEach(() => { containerElement = document.createElement("div"); @@ -85,10 +86,6 @@ describe("", () => { } }); - after(() => { - loadDateFnsLocaleStub.restore(); - }); - const START_DAY = 22; const START_DATE = new Date(2022, Months.JANUARY, START_DAY); const START_STR = DATE_FORMAT.formatDate(START_DATE); From 0b82e421f3e74bd283edea0079d547ae44ec0629 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 12:36:04 -0400 Subject: [PATCH 18/19] [datetime2] fix coverage --- packages/datetime2/karma.conf.js | 24 ++++++++++++++----- .../test/components/dateRangePicker3Tests.tsx | 15 ++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/packages/datetime2/karma.conf.js b/packages/datetime2/karma.conf.js index 03dc94a2f0..9b15ccb7e8 100644 --- a/packages/datetime2/karma.conf.js +++ b/packages/datetime2/karma.conf.js @@ -2,20 +2,32 @@ * Copyright 2022 Palantir Technologies, Inc. All rights reserved. */ +const MODERATE_COVERAGE_THRESHOLD = { + lines: 75, + statements: 75, +}; +const LOW_COVERAGE_THRESHOLD = { + lines: 50, + statements: 50, +}; + module.exports = async function (config) { const { createKarmaConfig } = await import("@blueprintjs/karma-build-scripts"); config.set( createKarmaConfig({ dirname: __dirname, coverageExcludes: [ - // we stub this out in tests because it relies on dynamic imports - "src/common/dateFnsLocaleUtils.ts", + // don't check barrel files + "src/**/index.ts", ], coverageOverrides: { - "src/*": { - lines: 75, - statements: 75, - }, + // these tests are "good enough" + "src/components/react-day-picker/datePicker3Caption.tsx": MODERATE_COVERAGE_THRESHOLD, + "src/dateInput2MigrationUtils.ts": MODERATE_COVERAGE_THRESHOLD, + + // HACKHACK(@adidahiya): need to add more tests here + "src/components/date-range-picker3/nonContiguousDayRangePicker.tsx": LOW_COVERAGE_THRESHOLD, + "src/common/dayPickerModifiers.ts": LOW_COVERAGE_THRESHOLD, }, }), ); diff --git a/packages/datetime2/test/components/dateRangePicker3Tests.tsx b/packages/datetime2/test/components/dateRangePicker3Tests.tsx index d2cb0bd923..cc360cc530 100644 --- a/packages/datetime2/test/components/dateRangePicker3Tests.tsx +++ b/packages/datetime2/test/components/dateRangePicker3Tests.tsx @@ -37,22 +37,19 @@ import { } from "@blueprintjs/datetime"; import { DateRangePicker3, DateRangePicker3Props, Datetime2Classes, ReactDayPickerClasses } from "../../src"; -import * as DateFnsLocaleUtils from "../../src/common/dateFnsLocaleUtils"; import type { DateRangePicker3State } from "../../src/components/date-range-picker3/dateRangePicker3State"; import { assertDayDisabled } from "../common/dayPickerTestUtils"; import { loadDateFnsLocaleFake } from "../common/loadDateFnsLocaleFake"; -describe("", () => { +// Change the default for testability +(DateRangePicker3.defaultProps as DateRangePicker3Props).dateFnsLocaleLoader = loadDateFnsLocaleFake; + +describe("", () => { let testsContainerElement: HTMLElement; let drpWrapper: ReactWrapper; let onChangeSpy: sinon.SinonSpy; let onHoverChangeSpy: sinon.SinonSpy; - let loadDateFnsLocaleStub: sinon.SinonStub; - - before(() => { - loadDateFnsLocaleStub = sinon.stub(DateFnsLocaleUtils, "loadDateFnsLocale").callsFake(loadDateFnsLocaleFake); - }); beforeEach(() => { testsContainerElement = document.createElement("div"); @@ -65,10 +62,6 @@ describe("", () => { testsContainerElement.remove(); }); - after(() => { - loadDateFnsLocaleStub.restore(); - }); - it("renders its template", () => { const { wrapper } = render(); assert.isTrue(wrapper.find(`.${Datetime2Classes.DATERANGEPICKER}`).exists()); From ff9a170ace2cff8808891d6fc0b5c57cb6346c54 Mon Sep 17 00:00:00 2001 From: Adi Dahiya Date: Tue, 10 Oct 2023 13:30:58 -0400 Subject: [PATCH 19/19] [table] fix DragSelectable tests --- packages/table/src/index.ts | 2 +- .../table/src/interactions/selectable.tsx | 25 ++++++- packages/table/test/selectableTests.tsx | 75 +++++++------------ 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/table/src/index.ts b/packages/table/src/index.ts index a5134857ed..f99dfa9a1c 100644 --- a/packages/table/src/index.ts +++ b/packages/table/src/index.ts @@ -45,7 +45,7 @@ export { CopyCellsMenuItem, type ContextMenuRenderer, type MenuContext } from ". export { type LockableLayout, type ResizeHandleProps, Orientation, ResizeHandle } from "./interactions/resizeHandle"; -export { type SelectableProps, type DragSelectableProps, type DragSelectable } from "./interactions/selectable"; +export { type SelectableProps, type DragSelectableProps, DragSelectable } from "./interactions/selectable"; export type { ColumnHeaderRenderer } from "./headers/columnHeader"; diff --git a/packages/table/src/interactions/selectable.tsx b/packages/table/src/interactions/selectable.tsx index 797d6f2053..69cec92b42 100644 --- a/packages/table/src/interactions/selectable.tsx +++ b/packages/table/src/interactions/selectable.tsx @@ -16,10 +16,10 @@ import * as React from "react"; -import { Utils as CoreUtils } from "@blueprintjs/core"; +import { Utils as CoreUtils, DISPLAYNAME_PREFIX } from "@blueprintjs/core"; import type { FocusedCellCoordinates } from "../common/cellTypes"; -import * as FocusedCellUtils from "../common/internal/focusedCellUtils"; +import * as DefaultFocusedCellUtils from "../common/internal/focusedCellUtils"; import * as PlatformUtils from "../common/internal/platformUtils"; import { Utils } from "../common/utils"; import { Region, Regions } from "../regions"; @@ -48,6 +48,14 @@ export interface SelectableProps { */ focusedCell?: FocusedCellCoordinates; + /** + * Focused cell coordinate & region utility functions. Exposed as a prop for testing purposes. + * These custom properties will be merged with the default util implementations. + * + * @internal + */ + focusedCellUtils?: Partial; + /** * When the user focuses something, this callback is called with new * focused cell coordinates. This should be considered the new focused cell @@ -121,6 +129,15 @@ export class DragSelectable extends React.PureComponent { selectedRegions: [], }; + public static displayName = `${DISPLAYNAME_PREFIX}.DragSelectable`; + + private get focusedCellUtils() { + return { + ...DefaultFocusedCellUtils, + ...this.props.focusedCellUtils, + }; + } + private didExpandSelectionOnActivate = false; private lastEmittedSelectedRegions: Region[] | null = null; @@ -339,7 +356,7 @@ export class DragSelectable extends React.PureComponent { private invokeOnFocusCallbackForRegion = (focusRegion: Region, focusSelectionIndex = 0) => { const { onFocusedCell } = this.props; const focusedCellCoords = Regions.getFocusCellCoordinatesFromRegion(focusRegion); - onFocusedCell(FocusedCellUtils.toFullCoordinates(focusedCellCoords, focusSelectionIndex)); + onFocusedCell(this.focusedCellUtils.toFullCoordinates(focusedCellCoords, focusSelectionIndex)); }; // Other @@ -360,7 +377,7 @@ export class DragSelectable extends React.PureComponent { if (regions.length === 0) { return [region]; } else if (focusedCell != null) { - const expandedRegion = FocusedCellUtils.expandFocusedRegion(focusedCell, region); + const expandedRegion = this.focusedCellUtils.expandFocusedRegion(focusedCell, region); return Regions.update(regions, expandedRegion); } else { const expandedRegion = Regions.expandRegion(regions[regions.length - 1], region); diff --git a/packages/table/test/selectableTests.tsx b/packages/table/test/selectableTests.tsx index 9226fc4f4c..94d52b182e 100644 --- a/packages/table/test/selectableTests.tsx +++ b/packages/table/test/selectableTests.tsx @@ -20,7 +20,7 @@ import sinon from "sinon"; import type { FocusedCellCoordinates } from "../src/common/cellTypes"; import * as FocusedCellUtils from "../src/common/internal/focusedCellUtils"; -import { DragSelectable, DragSelectableProps } from "../src/interactions/selectable"; +import { DragSelectable, type DragSelectableProps } from "../src/interactions/selectable"; import { Region, Regions } from "../src/regions"; import { ElementHarness, ReactHarness } from "./harness"; @@ -38,6 +38,13 @@ describe("DragSelectable", () => { const locateClick = sinon.stub(); const locateDrag = sinon.stub(); + const expandFocusedRegion = sinon.spy(FocusedCellUtils.expandFocusedRegion); + const expandRegion = sinon.spy(Regions, "expandRegion"); + + DragSelectable.defaultProps.focusedCellUtils = { + expandFocusedRegion, + }; + const children = (
Zero
@@ -57,6 +64,9 @@ describe("DragSelectable", () => { locateClick.resetHistory(); locateDrag.resetHistory(); + + expandFocusedRegion.resetHistory(); + expandRegion.resetHistory(); }); after(() => { @@ -195,8 +205,6 @@ describe("DragSelectable", () => { expectSingleCellRegion(REGION); expectSingleCellRegion(REGION_2); - const expandFocusedSpy = sinon.spy(FocusedCellUtils, "expandFocusedRegion"); - const expandSpy = sinon.spy(Regions, "expandRegion"); const component = mountDragSelectable({ focusedCell: toFocusedCell(REGION), selectedRegions: [REGION], @@ -204,34 +212,24 @@ describe("DragSelectable", () => { getItem(component).mouse("mousedown", { shiftKey: true }); - expect(expandFocusedSpy.calledOnce).to.be.true; - expect(expandSpy.called).to.be.false; - expectOnSelectionCalledWith([expandFocusedSpy.firstCall.returnValue]); - - // unwrap the sinon spies - (FocusedCellUtils.expandFocusedRegion as any).restore(); - (Regions.expandRegion as any).restore(); + expect(expandFocusedRegion.calledOnce).to.be.true; + expect(expandRegion.called).to.be.false; + expectOnSelectionCalledWith([expandFocusedRegion.firstCall.returnValue]); }); it("otherwise, expands the most recent one to the clicked region", () => { - const expandFocusedSpy = sinon.spy(FocusedCellUtils, "expandFocusedRegion"); - const expandSpy = sinon.spy(Regions, "expandRegion"); const component = mountDragSelectable({ selectedRegions: [REGION], }); getItem(component).mouse("mousedown", { shiftKey: true }); - expect(expandFocusedSpy.calledOnce).to.be.false; - expect(expandSpy.called).to.be.true; - expectOnSelectionCalledWith([expandSpy.firstCall.returnValue]); - - (FocusedCellUtils.expandFocusedRegion as any).restore(); - (Regions.expandRegion as any).restore(); + expect(expandFocusedRegion.calledOnce).to.be.false; + expect(expandRegion.called).to.be.true; + expectOnSelectionCalledWith([expandRegion.firstCall.returnValue]); }); it("expands selection even if CMD key was pressed", () => { - const expandFocusedSpy = sinon.spy(FocusedCellUtils, "expandFocusedRegion"); const component = mountDragSelectable({ focusedCell: toFocusedCell(REGION), selectedRegions: [REGION], @@ -239,14 +237,11 @@ describe("DragSelectable", () => { getItem(component).mouse("mousedown", { shiftKey: true, metaKey: true }); - expect(expandFocusedSpy.calledOnce).to.be.true; - expectOnSelectionCalledWith([expandFocusedSpy.firstCall.returnValue]); - - (FocusedCellUtils.expandFocusedRegion as any).restore(); + expect(expandFocusedRegion.calledOnce).to.be.true; + expectOnSelectionCalledWith([expandFocusedRegion.firstCall.returnValue]); }); it("works with a selectedRegionTransform too", () => { - const expandFocusedSpy = sinon.spy(FocusedCellUtils, "expandFocusedRegion"); const focusedCell = toFocusedCell(REGION); const component = mountDragSelectable({ focusedCell, @@ -256,10 +251,8 @@ describe("DragSelectable", () => { getItem(component).mouse("mousedown", { shiftKey: true, metaKey: true }); - expect(expandFocusedSpy.calledOnce).to.be.true; - expect(expandFocusedSpy.firstCall.calledWith(focusedCell, TRANSFORMED_REGION_2)).to.be.true; - - (FocusedCellUtils.expandFocusedRegion as any).restore(); + expect(expandFocusedRegion.calledOnce).to.be.true; + expect(expandFocusedRegion.firstCall.calledWith(focusedCell, TRANSFORMED_REGION_2)).to.be.true; }); }); @@ -361,20 +354,10 @@ describe("DragSelectable", () => { }); describe("if SHIFT depressed", () => { - let expandFocusedSpy: sinon.SinonSpy; - let expandSpy: sinon.SinonSpy; - beforeEach(() => { - expandFocusedSpy = sinon.spy(FocusedCellUtils, "expandFocusedRegion"); - expandSpy = sinon.spy(Regions, "expandRegion"); locateDrag.returns(REGION_3); }); - afterEach(() => { - (FocusedCellUtils.expandFocusedRegion as sinon.SinonSpy).restore(); - (Regions.expandRegion as sinon.SinonSpy).restore(); - }); - it("expands selection from focused cell (if provided)", () => { const component = mountDragSelectable({ focusedCell: toFocusedCell(REGION), @@ -384,18 +367,18 @@ describe("DragSelectable", () => { item.mouse("mousedown", { shiftKey: true }); - expect(expandFocusedSpy.calledOnce, "calls FCU.expandFocusedRegion on mousedown").to.be.true; + expect(expandFocusedRegion.calledOnce, "calls FCU.expandFocusedRegion on mousedown").to.be.true; expect(onSelection.calledOnce, "calls onSelection on mousedown").to.be.true; item.mouse("mousemove", { shiftKey: true }); - expect(expandFocusedSpy.calledTwice, "calls FCU.expandFocusedRegion on mousemove").to.be.true; + expect(expandFocusedRegion.calledTwice, "calls FCU.expandFocusedRegion on mousemove").to.be.true; expect(onSelection.calledTwice, "calls onSelection on mousemove").to.be.true; expect( - onSelection.secondCall.calledWith([expandFocusedSpy.secondCall.returnValue]), + onSelection.secondCall.calledWith([expandFocusedRegion.secondCall.returnValue]), "calls onSelection on mousemove with proper args", ).to.be.true; - expect(expandSpy.called, "doesn't call Regions.expandRegion").to.be.false; + expect(expandRegion.called, "doesn't call Regions.expandRegion").to.be.false; expect(onFocusedCell.called, "doesn't call onFocusedCell").to.be.false; }); @@ -404,17 +387,17 @@ describe("DragSelectable", () => { const item = getItem(component); item.mouse("mousedown", { shiftKey: true }); - expect(expandSpy.calledOnce, "calls Regions.expandRegion on mousedown").to.be.true; + expect(expandRegion.calledOnce, "calls Regions.expandRegion on mousedown").to.be.true; item.mouse("mousemove", { shiftKey: true }); - expect(expandSpy.calledTwice, "calls Regions.expandRegion on mousemove").to.be.true; + expect(expandRegion.calledTwice, "calls Regions.expandRegion on mousemove").to.be.true; expect(onSelection.calledTwice, "calls onSelection on mousemove").to.be.true; expect( - onSelection.secondCall.calledWith([expandSpy.secondCall.returnValue]), + onSelection.secondCall.calledWith([expandRegion.secondCall.returnValue]), "calls onSelection on mousemove with proper args", ).to.be.true; - expect(expandFocusedSpy.called, "calls FocusedCellUtils.expandFocusedRegion").to.be.false; + expect(expandFocusedRegion.called, "calls FocusedCellUtils.expandFocusedRegion").to.be.false; expect(onFocusedCell.called, "doesn't call onFocusedCell").to.be.false; }); });