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 f742b71a..51310fd4 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_sphinx_js_config", None, "env") diff --git a/sphinx_js/typedoc.py b/sphinx_js/typedoc.py index edeb9e48..01ea597f 100644 --- a/sphinx_js/typedoc.py +++ b/sphinx_js/typedoc.py @@ -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.""" @@ -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) @@ -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) 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..0967ef42 --- /dev/null +++ b/tests/test_build_ts/source/typedoc.json @@ -0,0 +1 @@ +{} diff --git a/tests/testing.py b/tests/testing.py index 17002c64..8949e12a 100644 --- a/tests/testing.py +++ b/tests/testing.py @@ -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, )