Skip to content

Commit

Permalink
typescript: handle multiple tsconfig.json files
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTereshenkov committed Aug 22, 2024
1 parent 6a966ae commit 65ad3ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
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 @@ -63,15 +63,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 All @@ -85,7 +91,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 @@ -114,7 +120,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 directory_digest_to_digest_contents(all_files)

return AllTSConfigs(
Expand Down

0 comments on commit 65ad3ad

Please sign in to comment.