From 593ed6aa3760fc15447c77db2b396e6f921f5d80 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Mon, 10 Jun 2024 20:08:36 -0700 Subject: [PATCH] chore: move @types deps to the ts_config target Source code doesn't have to include any indication these 'ambient' types are required. However we can force users to be explicit in the tsconfig of which `@types` packages to include in compilation. This follows the locality principle, since the types weren't referenced in the sources, the deps dont belong on the ts_project. --- frontend/next.js/BUILD.bazel | 6 ++++++ frontend/next.js/pages/BUILD.bazel | 4 ---- frontend/next.js/tsconfig.json | 8 +++++++- frontend/packages/one/BUILD.bazel | 18 +++++++++--------- frontend/packages/one/tsconfig.json | 4 +++- frontend/react/BUILD.bazel | 1 + frontend/react/src/BUILD.bazel | 3 +-- frontend/react/tsconfig.json | 5 ++++- 8 files changed, 31 insertions(+), 18 deletions(-) diff --git a/frontend/next.js/BUILD.bazel b/frontend/next.js/BUILD.bazel index 21321342a..7328fa350 100644 --- a/frontend/next.js/BUILD.bazel +++ b/frontend/next.js/BUILD.bazel @@ -16,6 +16,12 @@ ts_config( name = "tsconfig", src = "tsconfig.json", visibility = ["//visibility:public"], + deps = [ + ":node_modules/@types/is-even", + ":node_modules/@types/jest", + ":node_modules/@types/react", + ":node_modules/@types/react-dom", + ], ) next( diff --git a/frontend/next.js/pages/BUILD.bazel b/frontend/next.js/pages/BUILD.bazel index a93360eaa..992354ebd 100644 --- a/frontend/next.js/pages/BUILD.bazel +++ b/frontend/next.js/pages/BUILD.bazel @@ -20,9 +20,6 @@ ts_project( visibility = ["//next.js:__subpackages__"], deps = [ "//next.js:node_modules/@bazel-example/one", - "//next.js:node_modules/@types/is-even", - "//next.js:node_modules/@types/react", - "//next.js:node_modules/@types/react-dom", "//next.js:node_modules/next", "//next.js/pages/api", ], @@ -38,7 +35,6 @@ ts_project( deps = [ "//next.js:node_modules/@testing-library/jest-dom", "//next.js:node_modules/@testing-library/react", - "//next.js:node_modules/@types/jest", "//next.js/pages", ], ) diff --git a/frontend/next.js/tsconfig.json b/frontend/next.js/tsconfig.json index 7ee0239cf..674968e96 100644 --- a/frontend/next.js/tsconfig.json +++ b/frontend/next.js/tsconfig.json @@ -11,7 +11,13 @@ "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, - "jsx": "react-jsx" + "jsx": "react-jsx", + "types": [ + "is-even", + "jest", + "react", + "react-dom" + ] }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], "exclude": ["node_modules"] diff --git a/frontend/packages/one/BUILD.bazel b/frontend/packages/one/BUILD.bazel index 401000d2b..c43891850 100644 --- a/frontend/packages/one/BUILD.bazel +++ b/frontend/packages/one/BUILD.bazel @@ -1,23 +1,23 @@ load("@aspect_rules_js//npm:defs.bzl", "npm_package") -load("@aspect_rules_ts//ts:defs.bzl", "ts_project") +load("@aspect_rules_ts//ts:defs.bzl", "ts_config", "ts_project") load("@npm//:defs.bzl", "npm_link_all_packages") npm_link_all_packages(name = "node_modules") +ts_config( + name = "tsconfig", + src = "tsconfig.json", + deps = [":node_modules/@types/is-odd"], +) + ts_project( name = "one_ts", srcs = ["src/main.ts"], # runtime direct dependencies of the linked npm package - data = [ - ":node_modules/is-odd", - ], + data = [":node_modules/is-odd"], declaration = True, transpiler = "tsc", - # transpile time direct dependencies - deps = [ - ":node_modules/@types/is-odd", - "//next.js:node_modules/@types/node", - ], + tsconfig = ":tsconfig", ) # make this library available via node_modules diff --git a/frontend/packages/one/tsconfig.json b/frontend/packages/one/tsconfig.json index 8321e81d8..86bac0ace 100644 --- a/frontend/packages/one/tsconfig.json +++ b/frontend/packages/one/tsconfig.json @@ -2,6 +2,8 @@ "compilerOptions": { "declaration": true, "esModuleInterop": true, - + "types": [ + "is-odd" + ] } } \ No newline at end of file diff --git a/frontend/react/BUILD.bazel b/frontend/react/BUILD.bazel index 03a679a8a..4aac46a56 100644 --- a/frontend/react/BUILD.bazel +++ b/frontend/react/BUILD.bazel @@ -21,6 +21,7 @@ ts_config( name = "tsconfig", src = "tsconfig.json", visibility = ["//visibility:public"], + deps = [":node_modules/@types/react"], ) tsconfig_to_swcconfig.t2s( diff --git a/frontend/react/src/BUILD.bazel b/frontend/react/src/BUILD.bazel index 62ed6d250..9c385e6f0 100644 --- a/frontend/react/src/BUILD.bazel +++ b/frontend/react/src/BUILD.bazel @@ -23,7 +23,6 @@ ts_project( tsconfig = "//react:tsconfig", visibility = ["//react:__subpackages__"], deps = [ - "//react:node_modules/@types/react", "//react:node_modules/react", "//react:node_modules/react-dom", "//react:node_modules/vite-plugin-svgr", @@ -43,7 +42,7 @@ ts_project( "//:node_modules/vitest", "//react:node_modules/@testing-library/jest-dom", "//react:node_modules/@testing-library/react", - "//react:node_modules/@types/jest", + "//react:node_modules/@types", ], ) diff --git a/frontend/react/tsconfig.json b/frontend/react/tsconfig.json index 0b9e08271..0436817e0 100644 --- a/frontend/react/tsconfig.json +++ b/frontend/react/tsconfig.json @@ -14,7 +14,10 @@ "resolveJsonModule": true, "isolatedModules": true, "declaration": true, - "jsx": "react-jsx" + "jsx": "react-jsx", + "types": [ + "react" + ] }, "include": ["src"] }