Skip to content
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

Make basePath configurable #1924

Closed
jan-molak opened this issue Apr 26, 2022 · 4 comments
Closed

Make basePath configurable #1924

jan-molak opened this issue Apr 26, 2022 · 4 comments
Labels
enhancement Improved functionality

Comments

@jan-molak
Copy link

Search terms

Monorepo, lerna, nrwl, fileName

Expected Behavior

Given a mono-repo with modules under a common directory, for example:

packages
- module-A
  - src
    - index.ts
- module-B
  - src
    - index.ts

I'd expect fileName discovered for index.ts in module-A (and module-B) to include the common directory name, so packages/module-A/src/index.ts instead of just module-A/src/index.ts

Actual Behavior

To my understanding, when TypeDoc parses the sourcecode, it calls getCommonDirectory to automatically determine the root directory.

However, for mono-repos that follow the structure recommended by Lerna (with all the public modules under packages), the fileName determined by TypeDoc is incorrect since it misses the top-level sub-directory name.

This then has a knock-on effect on other projects such as docusaurus-plugin-typedoc-api, which use fileName to determine the location of the file in the GitHub repository - see milesj/docusaurus-plugin-typedoc-api#39

Steps to reproduce the bug

See above

Proposed solution

It feels like making the basePath in onBeginResolve configurable could solve this problem:

    private onBeginResolve(context: Context) {
-        this.basePath = getCommonDirectory([...this.fileNames]);
+        this.basePath = this.basePath || getCommonDirectory([...this.fileNames]);
        for (const file of context.project.files) {
            const fileName = (file.fileName = normalizePath(
                relative(this.basePath, file.fileName)
            ));
            this.fileMappings[fileName] = file;
        }
    }

Environment

  • Typedoc version: 0.22.13
  • TypeScript version: 4.6.3
  • Node.js version: 16.13.1
  • OS: macOS 12.3.1
@jan-molak jan-molak added the bug Functionality does not match expectation label Apr 26, 2022
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Apr 27, 2022

The specific problem you're running into I believe will be resolved by 0.23, which adds a url to sources:

"sources": [
{
"fileName": "alias.ts",
"line": 14,
"character": 12,
"url": "https://github.com/TypeStrong/typedoc/blob/fake/src/test/converter/alias/alias.ts#L14"
}
],

That said, I'm not opposed to a baseDir option which controls this, preventing the getCommonDirectory behavior.

@milesj
Copy link

milesj commented May 9, 2022

@Gerrit0 Will this url be available for the JSON outputs also?

@Gerrit0
Copy link
Collaborator

Gerrit0 commented May 9, 2022

Yes, url is included in the json in 0.23

@milesj
Copy link

milesj commented May 9, 2022

Awesome, looking forward to it.

@Gerrit0 Gerrit0 added enhancement Improved functionality and removed bug Functionality does not match expectation labels May 30, 2022
@Gerrit0 Gerrit0 closed this as completed in 98903d3 Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improved functionality
Projects
None yet
Development

No branches or pull requests

3 participants