Skip to content

Commit

Permalink
fix: mismatch between tsconfig.json and typedoc.json (Close #112) (#116)
Browse files Browse the repository at this point in the history
The parameter `jsdoc_config_path` was pointing to `typedoc --tsconfig` which is
the compiler options, it should be the typedoc configuration `typedoc --options`

I added a parameter `jsdoc_tsconfig_path` to be able to specify the `typedoc
--tsconfig` if needed

I updated unit test and doc.

It is a breaking change so we might want to bump version or add migration note.
Available to update the PR as needed.
  • Loading branch information
hoodmane authored May 2, 2024
1 parent eeee98a commit 92451b8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
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

0 comments on commit 92451b8

Please sign in to comment.