diff --git a/docs/notes/2.25.x.md b/docs/notes/2.25.x.md index 4b3f772fc8a..33a0f59344d 100644 --- a/docs/notes/2.25.x.md +++ b/docs/notes/2.25.x.md @@ -188,6 +188,10 @@ The NodeJS subsystem now supports configuring additional tools that should be av The paths to these tools will be included in the PATH used in the execution sandbox, so that they may be used by NodeJS processes during execution. +#### TypeScript + +The dependency inference now considers `.tsx` files. + ### Plugin API changes The version of Python used by Pants itself is now [3.11](https://docs.python.org/3/whatsnew/3.11.html) (up from 3.9). diff --git a/src/python/pants/backend/typescript/dependency_inference/rules.py b/src/python/pants/backend/typescript/dependency_inference/rules.py index 5e5aaa9ef53..2019e4fb71d 100644 --- a/src/python/pants/backend/typescript/dependency_inference/rules.py +++ b/src/python/pants/backend/typescript/dependency_inference/rules.py @@ -25,6 +25,7 @@ ) from pants.backend.javascript.subsystems.nodejs_infer import NodeJSInfer from pants.backend.javascript.target_types import JS_FILE_EXTENSIONS +from pants.backend.tsx.target_types import TSX_FILE_EXTENSIONS from pants.backend.typescript import tsconfig from pants.backend.typescript.target_types import ( TS_FILE_EXTENSIONS, @@ -128,7 +129,7 @@ async def infer_typescript_source_dependencies( _determine_import_from_candidates( candidates, candidate_pkgs, - file_extensions=TS_FILE_EXTENSIONS + JS_FILE_EXTENSIONS, + file_extensions=TS_FILE_EXTENSIONS + TSX_FILE_EXTENSIONS + JS_FILE_EXTENSIONS, ) for string, candidates in import_strings.imports.items() ), diff --git a/src/python/pants/backend/typescript/dependency_inference/rules_test.py b/src/python/pants/backend/typescript/dependency_inference/rules_test.py index 45100d90cba..dafb3ed9b57 100644 --- a/src/python/pants/backend/typescript/dependency_inference/rules_test.py +++ b/src/python/pants/backend/typescript/dependency_inference/rules_test.py @@ -14,6 +14,7 @@ ) from pants.backend.javascript.package_json import AllPackageJson from pants.backend.javascript.target_types import JSSourcesGeneratorTarget, JSSourceTarget +from pants.backend.tsx.target_types import TSXSourcesGeneratorTarget, TSXSourceTarget from pants.backend.typescript.dependency_inference.rules import ( InferTypeScriptDependenciesRequest, TypeScriptSourceInferenceFieldSet, @@ -50,6 +51,8 @@ def rule_runner() -> RuleRunner: *typescript_register.target_types(), TypeScriptSourceTarget, TypeScriptSourcesGeneratorTarget, + TSXSourceTarget, + TSXSourcesGeneratorTarget, JSSourceTarget, JSSourcesGeneratorTarget, ], @@ -61,7 +64,13 @@ def rule_runner() -> RuleRunner: def test_infers_typescript_file_imports_dependencies(rule_runner: RuleRunner) -> None: rule_runner.write_files( { - "src/ts/BUILD": "typescript_sources()\njavascript_sources(name='js')", + "src/ts/BUILD": dedent( + """\ + typescript_sources() + tsx_sources(name='tsx') + javascript_sources(name='js') + """ + ), "src/ts/index.ts": dedent( """\ import { x } from "./localModuleA"; @@ -77,6 +86,9 @@ def test_infers_typescript_file_imports_dependencies(rule_runner: RuleRunner) -> // You can import a JS module in a TypeScript module import { x } from './localModuleJs'; + + // You can import a TSX module in a TypeScript module + import { x } from './localModuleTsx'; """ ), "src/ts/localModuleA.ts": "", @@ -88,6 +100,7 @@ def test_infers_typescript_file_imports_dependencies(rule_runner: RuleRunner) -> "src/ts/localModuleG.ts": "", "src/ts/localModuleH.ts": "", "src/ts/localModuleJs.js": "", + "src/ts/localModuleTsx.tsx": "", } ) @@ -107,6 +120,7 @@ def test_infers_typescript_file_imports_dependencies(rule_runner: RuleRunner) -> Address("src/ts", relative_file_path="localModuleG.ts"), Address("src/ts", relative_file_path="localModuleH.ts"), Address("src/ts", relative_file_path="localModuleJs.js", target_name="js"), + Address("src/ts", relative_file_path="localModuleTsx.tsx", target_name="tsx"), }