Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider tsx files on typescript dependency inference #21844

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/notes/2.25.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -50,6 +51,8 @@ def rule_runner() -> RuleRunner:
*typescript_register.target_types(),
TypeScriptSourceTarget,
TypeScriptSourcesGeneratorTarget,
TSXSourceTarget,
TSXSourcesGeneratorTarget,
JSSourceTarget,
JSSourcesGeneratorTarget,
],
Expand All @@ -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";
Expand All @@ -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": "",
Expand All @@ -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": "",
}
)

Expand All @@ -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"),
}


Expand Down
Loading