diff --git a/README.rst b/README.rst index b432589e..776714ae 100644 --- a/README.rst +++ b/README.rst @@ -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. diff --git a/sphinx_js/__init__.py b/sphinx_js/__init__.py index 0636623f..76c3aee9 100644 --- a/sphinx_js/__init__.py +++ b/sphinx_js/__init__.py @@ -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_should_destructure_arg", None, "env") diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index b7bd38db..6bce131e 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -78,7 +78,8 @@ def version_to_str(t: Sequence[int]) -> str: def typedoc_output( abs_source_paths: list[str], sphinx_conf_dir: str | pathlib.Path, - config_path: str, + config_path: str | None, + tsconfig_path: str | None, base_dir: str, ) -> "Project": """Return the loaded JSON output of the TypeDoc command run over the given @@ -99,7 +100,11 @@ def typedoc_output( command.add("--entryPointStrategy", "expand") if config_path: - tsconfig_path = str((Path(sphinx_conf_dir) / config_path).resolve()) + config_path = str((Path(sphinx_conf_dir) / config_path).absolute()) + command.add("--options", 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) @@ -314,7 +319,11 @@ def from_disk( cls, abs_source_paths: list[str], app: Sphinx, base_dir: str ) -> "Analyzer": json = typedoc_output( - abs_source_paths, app.confdir, app.config.jsdoc_config_path, base_dir + abs_source_paths, + app.confdir, + app.config.jsdoc_config_path, + app.config.jsdoc_tsconfig_path, + base_dir, ) return cls( json, diff --git a/tests/test_build_ts/source/docs/conf.py b/tests/test_build_ts/source/docs/conf.py index 19ba8f72..748a4140 100644 --- a/tests/test_build_ts/source/docs/conf.py +++ b/tests/test_build_ts/source/docs/conf.py @@ -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 diff --git a/tests/test_build_ts/source/typedoc.json b/tests/test_build_ts/source/typedoc.json new file mode 100644 index 00000000..2f1ad9a6 --- /dev/null +++ b/tests/test_build_ts/source/typedoc.json @@ -0,0 +1,3 @@ +{ + "module": "modules" +} diff --git a/tests/testing.py b/tests/testing.py index 884e1430..93d616f5 100644 --- a/tests/testing.py +++ b/tests/testing.py @@ -81,6 +81,7 @@ def setup_class(cls): cls.json = typedoc_output( [join(cls._source_dir, file) for file in cls.files], cls._source_dir, + None, "tsconfig.json", cls._source_dir, )