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

WIP typescript: handle multiple tsconfig.json files #21347

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions pants.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ backend_packages.add = [
"pants.backend.experimental.java.lint.google_java_format",
"pants.backend.experimental.java.debug_goals",
"pants.backend.experimental.javascript",
"pants.backend.experimental.typescript",
"pants.backend.experimental.javascript.lint.prettier",
"pants.backend.experimental.python",
"pants.backend.experimental.python.packaging.pyoxidizer",
Expand Down
12 changes: 10 additions & 2 deletions src/python/pants/backend/typescript/tsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,21 @@ async def _read_parent_config(
relative = os.path.dirname(child_path)
else:
relative = child_path
print(f"Child path: {child_path}")
print(f"Extends path: {extends_path}")

relative = os.path.normpath(os.path.join(relative, extends_path))
print(f"Relative: {relative}")
if not extends_path.endswith(".json"):
relative = os.path.join(relative, target_file)
parent = next((other for other in others if other.path == relative), None)
print(f"Parent: {parent}")
if not parent:
logger.warning(
f"pants could not locate {child_path}'s 'extends' at {relative}. Found: {[other.path for other in others]}."
)
return None

return await Get( # Must be a Get until https://github.com/pantsbuild/pants/pull/21174 lands
TSConfig, ParseTSConfigRequest(parent, others, target_file)
)
Expand Down Expand Up @@ -118,7 +124,7 @@ def _parse_config_from_content(content: FileContent) -> tuple[TSConfig, str | No
module_resolution=compiler_options.get("moduleResolution"),
paths=compiler_options.get("paths"),
base_url=compiler_options.get("baseUrl"),
), compiler_options.get("extends")
), parsed_ts_config_json.get("extends")


@rule
Expand Down Expand Up @@ -147,7 +153,9 @@ class TSConfigsRequest:

@rule
async def construct_effective_ts_configs(req: TSConfigsRequest) -> AllTSConfigs:
all_files = await path_globs_to_digest(PathGlobs([f"**/{req.target_file}"]))
all_files = await path_globs_to_digest(
PathGlobs([f"**/{req.target_file}", "**/tsconfig*.json", "**/jsconfig*.json"])
)
digest_contents = await get_digest_contents(all_files)

return AllTSConfigs(
Expand Down
Loading