-
Notifications
You must be signed in to change notification settings - Fork 9
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
fix: fixes generation issue with the Astro srcDir
option
#50
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your feedback and pull request, super appreciated 🙌
The changes definitely make sense and looks good to me. I only suggested a change to the approach to avoid issues on Windows. Regarding the tests, definitely not the best but I think this should be enough for now, and maybe we can switch to an E2E test in the future if we see the need.
Let me know what you think about the suggested changes but the overall PR looks good to me 👍
@@ -56,7 +60,7 @@ export async function generateTypeDoc(options: StarlightTypeDocOptions, base: st | |||
throw new Error('Failed to generate TypeDoc documentation.') | |||
} | |||
|
|||
const outputPath = path.join('src/content/docs', outputDirectory) | |||
const outputPath = path.join(`${config.srcDir.pathname}/content/docs`, outputDirectory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const outputPath = path.join(`${config.srcDir.pathname}/content/docs`, outputDirectory) | |
const outputPath = path.join(url.fileURLToPath(config.srcDir), 'content/docs', outputDirectory) |
Tested the change on Windows, and this approach would fail (probably because the driver letter is recognized as the protocol) so instead of getting something like C:\Users\…
, you get \C:\Users\…
which errors during the generation process.
Note that this would require an extra import url from 'node:url'
at the top.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always forget about Windows. Thanks for the catch
function generateTestTypeDoc(options: Parameters<typeof generateTypeDoc>[0]) { | ||
function generateTestTypeDoc( | ||
options: Parameters<typeof generateTypeDoc>[0], | ||
config: AstroConfig = starlightTypeDocAstroConfig as AstroConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config: AstroConfig = starlightTypeDocAstroConfig as AstroConfig, | |
config: Partial<AstroConfig> = starlightTypeDocAstroConfig, |
As it's only for tests, let's move the cast in this function so it avoids the need to do it in tests.
return generateTypeDoc( | ||
{ | ||
...starlightTypeDocOptions, | ||
...options, | ||
}, | ||
'/', | ||
config, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config, | |
config as AstroConfig, |
...starlightTypeDocOptions, | ||
entryPoints: ['../../fixtures/basics/src/functions.ts'], | ||
}, | ||
{ srcDir: new URL('docs/src', import.meta.url) } as AstroConfig, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ srcDir: new URL('docs/src', import.meta.url) } as AstroConfig, | |
{ srcDir: new URL('www/src', import.meta.url) }, |
And we should be able to remove this cast.
Let's also use www/src
for the test as docs
is already part of the path, maybe it's a bit more obvious to use a totally different directory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied my own setup (which gets confusing), so www
works for me
const mkdirSyncSpy = vi.mocked(fs.mkdirSync) | ||
|
||
expect(mkdirSyncSpy).toHaveBeenCalled() | ||
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString()).toMatch(/docs[/\\]src[/\\]content[/\\]docs[/\\]api$/) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString()).toMatch(/docs[/\\]src[/\\]content[/\\]docs[/\\]api$/) | |
expect(mkdirSyncSpy.mock.calls[0]?.[0].toString()).toMatch(/www[/\\]src[/\\]content[/\\]docs[/\\]api$/) |
To match the previous change.
pnpm-lock.yaml
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should indeed be reverted considering the scope of the changes.
46168ba
to
bb6253d
Compare
For the git history, I
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fast update, everything looks perfect to me 👍
Great job on that pull request, thanks for you contribution.
srcDir
option
First, I just found this tool and it's fantastic! Thanks for all the hard work.
Describe the pull request
Adds support for respecting the
srcDir
option from the Astro ConfigWhy
I have a lib that I work on and the docs are in the repo like this:
and my
docs/astro.config.mjs
looks like this:This was causing
starlight-typedoc
to generate the markdown files insrc
(the library source) and not indocs/src
thesrcDir
in the config.How
The changes were implemented primarily by passing in the whole
AstroConfig
togenerateTypeDoc
function, and updating theoutputPath
:Additional comments
(1) I've never used workspaces, and the changes in
pnpm-lock
are confusing to me. Let me know if I should revert those changes(2) I feel...eh about the tests, but I wasn't sure if there was a better way to fake the
AstroConfig
.