Skip to content

fix: mismatch between tsconfig.json and typedoc.json (Close #112) #116

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

Merged
merged 6 commits into from
May 2, 2024
Merged
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
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,10 @@ Configuration Reference
A list of directories to scan (non-recursively) for JS or TS source files, relative to Sphinx's conf.py file. Can be a string instead if there is only one. If there is more than one, ``root_for_relative_js_paths`` must be specified as well. Defaults to '../'.

``jsdoc_config_path``
A conf.py-relative path to a JSDoc config file, which is useful if you want to specify your own JSDoc options, like recursion and custom filename matching. If using TypeDoc, you can also point to a ``tsconfig.json`` file.
A conf.py-relative path to a JSDoc config file, which is useful if you want to specify your own JSDoc options, like recursion and custom filename matching. If using TypeDoc, you can also point to a ``typedoc.json`` file.

``jsdoc_tsconfig_path``
If using TypeDoc, specify the path of ``tsconfig.json`` file

``root_for_relative_js_paths``
Relative JS entity paths are resolved relative to this path. Defaults to ``js_source_path`` if it is only one item.
Expand Down
1 change: 1 addition & 0 deletions sphinx_js/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def setup(app: Sphinx) -> None:
"js_source_path", default=["../"], rebuild="env", types=[str, list]
)
app.add_config_value("jsdoc_config_path", default=None, rebuild="env")
app.add_config_value("jsdoc_tsconfig_path", default=None, rebuild="env")
app.add_config_value("ts_type_xref_formatter", None, "env")
app.add_config_value("ts_type_bold", False, "env")
app.add_config_value("ts_sphinx_js_config", None, "env")
Expand Down
30 changes: 19 additions & 11 deletions sphinx_js/typedoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def version_to_str(t: Sequence[int]) -> str:

def typedoc_output(
abs_source_paths: Sequence[str],
sphinx_conf_dir: str | pathlib.Path,
config_path: str,
base_dir: str,
config_file: str | None,
sphinx_conf_dir: str | pathlib.Path,
typedoc_config_path: str | None,
tsconfig_path: str | None,
ts_sphinx_js_config: str | None,
) -> list[ir.TopLevelUnion]:
"""Return the loaded JSON output of the TypeDoc command run over the given
paths."""
Expand All @@ -70,12 +71,18 @@ def typedoc_output(
dir = Path(__file__).parent.resolve() / "js"
command.add("--import", str(dir / "registerImportHook.mjs"))
command.add(str(dir / "call_typedoc.ts"))
if config_file:
command.add("--sphinx-js-config", config_file)
if ts_sphinx_js_config:
command.add("--sphinx-js-config", ts_sphinx_js_config)
command.add("--entryPointStrategy", "expand")

if config_path:
tsconfig_path = str((Path(sphinx_conf_dir) / config_path).resolve())
if typedoc_config_path:
typedoc_config_path = str(
(Path(sphinx_conf_dir) / typedoc_config_path).absolute()
)
command.add("--options", typedoc_config_path)

if tsconfig_path:
tsconfig_path = str((Path(sphinx_conf_dir) / tsconfig_path).absolute())
command.add("--tsconfig", tsconfig_path)

command.add("--basePath", base_dir)
Expand Down Expand Up @@ -125,10 +132,11 @@ def from_disk(
) -> "Analyzer":
json = typedoc_output(
abs_source_paths,
app.confdir,
app.config.jsdoc_config_path,
base_dir,
app.config.ts_sphinx_js_config,
base_dir=base_dir,
sphinx_conf_dir=app.confdir,
typedoc_config_path=app.config.jsdoc_config_path,
tsconfig_path=app.config.jsdoc_tsconfig_path,
ts_sphinx_js_config=app.config.ts_sphinx_js_config,
)
return cls(json, base_dir)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_build_ts/source/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
author = "Erik Rose"
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

jsdoc_config_path = "../tsconfig.json"
jsdoc_config_path = "../typedoc.json"
jsdoc_tsconfig_path = "../tsconfig.json"
js_language = "typescript"
from sphinx.util import rst

Expand Down
1 change: 1 addition & 0 deletions tests/test_build_ts/source/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 6 additions & 5 deletions tests/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ def setup_class(cls):
config_file = Path(__file__).parent / "sphinxJsConfig.ts"

cls.json = typedoc_output(
[join(cls._source_dir, file) for file in cls.files],
cls._source_dir,
"tsconfig.json",
cls._source_dir,
str(config_file),
abs_source_paths=[join(cls._source_dir, file) for file in cls.files],
base_dir=cls._source_dir,
ts_sphinx_js_config=str(config_file),
typedoc_config_path=None,
tsconfig_path="tsconfig.json",
sphinx_conf_dir=cls._source_dir,
)


Expand Down