Skip to content

Commit

Permalink
fix(conf): correct resolve tsconfig paths
Browse files Browse the repository at this point in the history
commit_hash:c7a38b8cf8c701f23c49b920be863fc2d96c80a4
  • Loading branch information
zaverden committed Feb 14, 2025
1 parent 192fb51 commit bd22dcc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
10 changes: 5 additions & 5 deletions build/plugins/lib/nots/typescript/tests/test_ts_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def create_empty_ts_config(self, path):
def create_ts_config_with_data_once(self, path):
cfg = TsConfig(path=path)

if path == "/foo/./base-tsconfig.json":
if path == "/foo/base-tsconfig.json":
cfg.data = {"extends": "./extends/recursive/tsconfig.json"}
else:
cfg.data = {}
Expand All @@ -269,7 +269,7 @@ def test_extends_single_with_dot(self, monkeypatch):

paths = cfg_main.inline_extend({})

assert paths == ["./extends/tsconfig.json"]
assert paths == ["/foo/extends/tsconfig.json"]

def test_extends_single_without_dot(self, monkeypatch):
monkeypatch.setattr(TsConfig, "load", self.create_empty_ts_config)
Expand All @@ -279,7 +279,7 @@ def test_extends_single_without_dot(self, monkeypatch):

paths = cfg_main.inline_extend({"extends": "dir/extends"})

assert paths == ["dir/extends/tsconfig.json"]
assert paths == ["/foo/dir/extends/tsconfig.json"]

def test_extends_array(self, monkeypatch):
monkeypatch.setattr(TsConfig, "load", self.create_empty_ts_config)
Expand All @@ -289,7 +289,7 @@ def test_extends_array(self, monkeypatch):

paths = cfg_main.inline_extend({"extends": "dir/extends"})

assert paths == ["dir/extends/tsconfig1.json", "dir/extends/tsconfig2.json"]
assert paths == ["/foo/dir/extends/tsconfig1.json", "/foo/dir/extends/tsconfig2.json"]

def test_extends_empty_array(self):
cfg_main = TsConfig(path="/foo/tsconfig.json")
Expand All @@ -307,4 +307,4 @@ def test_recursive_extend(self, monkeypatch):

paths = cfg_main.inline_extend({})

assert paths == ["./base-tsconfig.json", "./extends/recursive/tsconfig.json"]
assert paths == ["/foo/base-tsconfig.json", "/foo/extends/recursive/tsconfig.json"]
9 changes: 4 additions & 5 deletions build/plugins/lib/nots/typescript/ts_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def extend_one(self, dep_paths, ext_value):

if ext_value.startswith("."):
base_config_path = ext_value

else:
dep_name = utils.extract_package_name_from_path(ext_value)
# the rest part is the ext config path
Expand All @@ -134,15 +133,15 @@ def extend_one(self, dep_paths, ext_value):
base_config_path = os.path.join(dep_path, file_path)

rel_path = os.path.dirname(base_config_path)
tsconfig_curdir_path = os.path.join(os.path.dirname(self.path), base_config_path)
if os.path.isdir(tsconfig_curdir_path):
base_config_path = os.path.normpath(os.path.join(os.path.dirname(self.path), base_config_path))
if os.path.isdir(base_config_path):
base_config_path = os.path.join(base_config_path, DEFAULT_TS_CONFIG_FILE)

# processing the base file recursively
base_config = TsConfig.load(os.path.join(os.path.dirname(self.path), base_config_path))
base_config = TsConfig.load(base_config_path)
paths = [base_config_path] + base_config.inline_extend(dep_paths)

self.merge(rel_path, base_config)

return paths

def inline_extend(self, dep_paths):
Expand Down
16 changes: 1 addition & 15 deletions build/plugins/nots.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from enum import auto, StrEnum
from typing import Any, Literal, TYPE_CHECKING


# noinspection PyUnresolvedReferences
import ymake

Expand Down Expand Up @@ -466,7 +465,7 @@ def on_ts_configure(unit: NotsUnitType) -> None:

tsconfig = TsConfig.load(abs_tsconfig_path)
config_files = tsconfig.inline_extend(dep_paths)
config_files = _resolve_module_files(unit, mod_dir, config_files)
config_files = [rootrel_arc_src(path, unit) for path in config_files]

use_tsconfig_outdir = unit.get("TS_CONFIG_USE_OUTDIR") == "yes"
tsconfig.validate(use_tsconfig_outdir)
Expand Down Expand Up @@ -714,19 +713,6 @@ def _setup_stylelint(unit: NotsUnitType) -> None:
unit.set(["TEST_RECIPES_VALUE", recipes_value])


def _resolve_module_files(unit: NotsUnitType, mod_dir: str, file_paths: list[str]) -> list[str]:
mod_dir_with_sep_len = len(mod_dir) + 1
resolved_files = []

for path in file_paths:
resolved = rootrel_arc_src(path, unit)
if resolved.startswith(mod_dir):
resolved = resolved[mod_dir_with_sep_len:]
resolved_files.append(resolved)

return resolved_files


def _set_resource_vars(
unit: NotsUnitType, erm_json: 'ErmJsonLite', tool: str, version: 'Version', nodejs_major: int = None
) -> None:
Expand Down

0 comments on commit bd22dcc

Please sign in to comment.