-
-
Notifications
You must be signed in to change notification settings - Fork 124
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
SSG: support wildcards in static paths #666
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Wow, thanks for working on it. Let me do a quick first review. |
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 guess types has to be updated, no?
e2e/25_static-wildcard.spec.ts
Outdated
|
||
let standaloneDir: string; | ||
const exampleDir = fileURLToPath( | ||
new URL('../examples/25_static-wildcard', import.meta.url), |
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.
Can you move it to fixtures
instead of examples
?
e2e/25_static-wildcard.spec.ts
Outdated
// Which will cause files in `src` folder to be empty. | ||
// I don't know why | ||
const tmpDir = process.env.TEMP_DIR ? process.env.TEMP_DIR : tmpdir(); | ||
standaloneDir = await mkdtemp(join(tmpDir, 'waku-07-router-')); |
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.
07-router
sounds strange here.
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.
Copy & paste 🙈
break; | ||
case 'group': | ||
pathItems.push(staticPath[slugIndex++]!); | ||
break; |
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.
Well, now you read the create-page.ts code, do you have any idea to improve it or completely rewrite it?
I wonder how readable the code is. It's unlikely that the code is easy to read.
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 did find my way in reasonable time, so it can't be that bad 😄
I fully agree with the comment on line 29, but there is no unit test framework. I suppose we would use vitest?
// FIXME we should add unit tests for some functions and type utils. |
Happy to take a stab at this, in a separate PR.
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.
That would be more than helpful!
Yes, let's add vitest. A separate PR would be perfect.
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.
And, ts-expect
.
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.
There we go: #667
I created a pure setup-PR first, since i'm also working on another PR where vitest would help.
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.
Will you add some tests for this?
Maybe we should have a separate PR to add tests without this PR change first.
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.
Was not too easy to find a way to test it. But i think this gives good coverage to do a confident refactor in a later step: #692
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.
So the unit tests immediately revealed a regression! 😅
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.
That's nice! Yeah, because I was very unsure that I could review the code.
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.
first review
thanks for working on it. this seems like a good improvement.
// GitHub Action on Windows doesn't support mkdtemp on global temp dir, | ||
// Which will cause files in `src` folder to be empty. | ||
// I don't know why | ||
const tmpDir = process.env.TEMP_DIR ? process.env.TEMP_DIR : tmpdir(); |
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.
So, does that mean TEMP_DIR
is a workaround for Windows?
@himself65 thoughts?
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.
yes, but I think we could just make things under .cache folder? I forget why I prefer to use tmpdir here
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.
Oh, this comment is copied from e2e/07_router_standalone.spec.ts
.
Okay, please tackle it separately from this PR.
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.
yes, copy from my code 😆
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.
yes, copy from my code 😆
I like to call it "proudly found elsewhere".
break; | ||
case 'group': | ||
pathItems.push(staticPath[slugIndex++]!); | ||
break; |
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.
Will you add some tests for this?
Maybe we should have a separate PR to add tests without this PR change first.
# Conflicts: # pnpm-lock.yaml # tsconfig.e2e.json
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.
second review
export const getConfig = async () => { | ||
return { | ||
render: 'static', | ||
staticPaths: [[], 'foo', ['bar', 'baz']], | ||
}; | ||
}; |
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 isn't type checked.
I wonder whether we should make ssg-wildcard
with createPages
API instead of fs-router.
We can say that types are covered with unit tests, but still fixtures should be as basic as possible?
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.
Actually, it is not type-covered in createPages
either:
waku/packages/waku/tests/create-pages.test.ts
Lines 60 to 67 in 10c2865
// TODO: This fails at runtime, but not at type level. | |
// \@ts-expect-error: static paths do not match the slug pattern | |
createPage({ | |
render: 'static', | |
path: '/test/[a]/[b]', | |
staticPaths: ['c'], | |
component: () => 'Hello', | |
}); |
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.
Oh, I see. I hope we can fix it.
My question still holds: Should we make fixtures use low-level createPages instead of fs-router? (Unless we specifically tests fs-router.)
What do you think?
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.
Good question. My gut feeling would be to use integration tests to cover as much ground as possible, but in this case createPages
is a common entry point (and even my preferred one). Also fs-router.ts
is a good target for a unit test.
But this then should also apply to partial-build
and ssg-performance
. And most other tests don't use createPages
but defineRouter
. Maybe another PR where we look at the e2e setup holistically, including the typing hiccups that we encountered?
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.
Sure. Sounds all good!
break; | ||
case 'group': | ||
pathItems.push(staticPath[slugIndex++]!); | ||
break; |
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.
That's nice! Yeah, because I was very unsure that I could review the code.
# Conflicts: # tsconfig.e2e.json
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.
Well, I don't fully read the code carefully, but let's trust the tests.
Allow wildcards in static paths. The main use case would be scenarios where waku is used as a static site generator and paths are controlled by a headless CMS.