Skip to content

Commit 3b84d2d

Browse files
committed
Use basePath option for relative links
Resolves #3009
1 parent 12a3f3a commit 3b84d2d

File tree

17 files changed

+118
-59
lines changed

17 files changed

+118
-59
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ title: Changelog
44

55
## Unreleased
66

7+
### Features
8+
9+
- The `basePath` option now also affects relative link resolution, TypeDoc will also check for
10+
paths relative to the provided base path. If you instead want TypeDoc to only change the rendered
11+
base path for sources, use the `displayBasePath` option, #3009.
12+
713
### Bug Fixes
814

915
- Fixed bug introduced in 0.28.8 where TypeDoc could not render docs with some mixin classes, #3007.

index.html

Lines changed: 0 additions & 6 deletions
This file was deleted.

site/declaration-references.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ title: Declaration References
44

55
# Declaration References
66

7-
> [!note]
8-
> If [--useTsLinkResolution](options/comments.md#usetslinkresolution) is turned on (the default) this page likely
9-
> **does not apply** for your links. Declaration references are used only if that option is off or TypeScript
10-
> fails to resolve a link.
7+
> [!note] If [--useTsLinkResolution](options/comments.md#usetslinkresolution) is turned on (the default) this page
8+
> likely **does not apply** for your links within comments (though it will be used for
9+
> [external documents](./external-documents.md) and for the readme file). Declaration references are used only if that option is
10+
> off or TypeScript fails to resolve a link.
1111
1212
Some tags like [`{@link}`](tags/link.md) and [`{@inheritDoc}`](tags/inheritDoc.md) can refer to other
1313
members of the documentation. These tags use declaration references to name another declaration.

site/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Options which control TypeDoc's HTML output.
3535

3636
## Comment Options
3737

38-
Options which control how TypeDoc parses comments.
38+
Options which control how TypeDoc parses comments and documents.
3939

4040
{@listOptions options/comments.md}
4141

site/options/input.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ If a `"typedoc"` [conditional export](https://nodejs.org/api/packages.html#condi
3535
TypeDoc will use it instead of the `"import"` export condition.
3636

3737
The set of entry points provided to TypeDoc determines the names displayed in the documentation.
38-
By default, TypeDoc will derive a [basePath](output.md#basepath) based on your entry point
38+
By default, TypeDoc will derive a [displayBasePath](output.md#displaybasepath) based on your entry point
3939
paths to determine the displayed module name, but it can be also be set with the [`@module`](../tags/module.md) tag.
4040

4141
## entryPointStrategy
@@ -311,14 +311,24 @@ If you are updating documentation for a forked package, you probably want to pas
311311
typedoc --disableGit
312312
```
313313

314-
Prevents TypeDoc from using Git to try to determine if sources can be linked, with this enabled, sources will always be linked, even if not part of a git repo.
314+
Prevents TypeDoc from using Git to try to determine if sources can be linked, with this enabled, sources will always be
315+
linked, even if not part of a git repo.
315316

316317
## readme
317318

318319
```bash
319320
typedoc --readme <path/to/readme|none>
320321
```
321322

322-
Path to the readme file that should be displayed on the index page. If set to
323-
`none`, or no readme file is automatically discovered, the index page will be
324-
disabled.
323+
Path to the readme file that should be displayed on the index page. If set to `none`, or no readme file is automatically
324+
discovered, the index page will be disabled.
325+
326+
## basePath
327+
328+
```bash
329+
typedoc --basePath ./
330+
```
331+
332+
Path to a directory containing asset files which will be checked when resolving relative paths of links and images
333+
within documentation comments and external documents. If specified, this will also be used for the default value of
334+
the [displayBasePath](output.md#displaybasepath) option.

site/options/output.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,15 @@ export default {
318318
};
319319
```
320320

321-
## basePath
321+
## displayBasePath
322322

323323
```bash
324-
$ typedoc --basePath ./ --entryPoints src/index.ts
324+
$ typedoc --displayBasePath ./ --entryPoints src/index.ts
325325
```
326326

327327
Specifies the base path to be used when displaying file paths. If not set, TypeDoc will guess by taking the lowest
328-
common directory to all source files. In the above example, TypeDoc would display links to `index.ts` rather than `src/index.ts`.
328+
common directory to all source files. In the above example, TypeDoc would display links to `index.ts` rather than `src/index.ts`
329+
if `displayBasePath` was not specified. Defaults to the value of [basePath](input.md#basepath)
329330

330331
> [!note]
331332
> This option only affects displayed paths. It _does not_ affect where TypeDoc will create links to.

site/options/package-options.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ at the root level. The following tables indicate where an option should be set.
5353
| [`gitRemote`](input.md#gitremote) | Package | |
5454
| [`disableGit`](input.md#disablegit) | Package | |
5555
| [`readme`](input.md#readme) | Both | Root: Site readme, Package: Package readme |
56+
| [`basePath`](input.md#basepath) | Both | Root: Site readme, documents, Package: Package readme, documentation comments, documents |
5657

5758
## Output Options
5859

@@ -77,7 +78,7 @@ at the root level. The following tables indicate where an option should be set.
7778
| [`customFooterHtmlDisableWrapper`](output.md#customfooterhtmldisablewrapper) | Root | |
7879
| [`markdownItOptions`](output.md#markdownitoptions) | Root | |
7980
| [`markdownItLoader`](output.md#markdownitloader) | Root | |
80-
| [`basePath`](output.md#basepath) | Both | Used to determine file names of entry points and documents |
81+
| [`displayBasePath`](output.md#displaybasepath) | Both | Used to determine file names of entry points and documents |
8182
| [`cname`](output.md#cname) | Root | |
8283
| [`favicon`](output.md#favicon) | Root | |
8384
| [`sourceLinkExternal`](output.md#sourcelinkexternal) | Root | |

src/lib/application.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ export class Application extends AbstractComponent<
148148

149149
options = new Options();
150150

151+
/**
152+
* Due for deprecation in 0.29, use the reference to this on {@link ProjectReflection},
153+
* this was the wrong place for this member to live.
154+
*/
151155
files: FileRegistry = new ValidatingFileRegistry();
152156

153157
/** @internal */
@@ -273,6 +277,10 @@ export class Application extends AbstractComponent<
273277
this.logger.level = this.options.getValue("logLevel");
274278
}
275279

280+
if (this.files instanceof ValidatingFileRegistry) {
281+
this.files.basePath = this.options.getValue("basePath");
282+
}
283+
276284
for (
277285
const [lang, locales] of Object.entries(
278286
this.options.getValue("locales"),
@@ -827,7 +835,7 @@ export class Application extends AbstractComponent<
827835
for (const { dir, options } of projectsToConvert) {
828836
this.logger.info(i18n.converting_project_at_0(nicePath(dir)));
829837
this.options = options;
830-
this.files = new ValidatingFileRegistry();
838+
this.files = new ValidatingFileRegistry(options.getValue("basePath"));
831839
let project = await this.convert();
832840
if (project) {
833841
this.validate(project);

src/lib/converter/plugins/SourcePlugin.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SourceReference } from "../../models/index.js";
1010
import { gitIsInstalled, RepositoryManager } from "../utils/repository.js";
1111
import { ConverterEvents } from "../converter-events.js";
1212
import type { Converter } from "../converter.js";
13-
import { i18n, type NormalizedPath } from "#utils";
13+
import { i18n } from "#utils";
1414

1515
/**
1616
* A handler that attaches source file information to reflections.
@@ -31,8 +31,9 @@ export class SourcePlugin extends ConverterComponent {
3131
@Option("sourceLinkTemplate")
3232
accessor sourceLinkTemplate!: string;
3333

34-
@Option("basePath")
35-
accessor basePath!: NormalizedPath;
34+
get displayBasePath() {
35+
return this.application.options.getValue("displayBasePath") || this.application.options.getValue("basePath");
36+
}
3637

3738
/**
3839
* All file names to find the base path from.
@@ -157,7 +158,7 @@ export class SourcePlugin extends ConverterComponent {
157158
);
158159
}
159160

160-
const basePath = this.basePath || getCommonDirectory([...this.fileNames]);
161+
const basePath = this.displayBasePath || getCommonDirectory([...this.fileNames]);
161162
this.repositories ||= new RepositoryManager(
162163
basePath,
163164
this.gitRevision,

src/lib/internationalization/locales/en.cts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,12 +311,14 @@ export = {
311311
"Use the specified remote for linking to GitHub/Bitbucket source files. Has no effect if disableGit or disableSources is set",
312312
help_disableGit:
313313
"Assume that all can be linked to with the sourceLinkTemplate, sourceLinkTemplate must be set if this is enabled. {path} will be rooted at basePath",
314-
help_basePath: "Specifies the base path to be used when displaying file paths",
314+
help_displayBasePath:
315+
"Specifies the base path to be used when displaying file paths. If not specified, basePath is used.",
315316
help_excludeTags: "Remove the listed block/modifier tags from doc comments",
316317
help_notRenderedTags: "Tags which will be preserved in doc comments, but not rendered when creating output",
317318
help_cascadedModifierTags: "Modifier tags which should be copied to all children of the parent reflection",
318319
help_readme:
319320
"Path to the readme file that should be displayed on the index page. Pass `none` to disable the index page and start the documentation on the globals page",
321+
help_basePath: "Specifies a path which links may be resolved relative to.",
320322
help_cname: "Set the CNAME file text, it's useful for custom domains on GitHub Pages",
321323
help_favicon: "Path to favicon to include as the site icon",
322324
help_sourceLinkExternal:

0 commit comments

Comments
 (0)