next-static-paths icon indicating copy to clipboard operation
next-static-paths copied to clipboard

Sort generated Paths to avoid git diff when running `next-static-paths`

Open nirtamir2 opened this issue 2 years ago • 2 comments

I add as a pre-commit hook to files in pages the next-static-paths script to generate the static-paths.d.ts. I notice that sometimes it creates useless git diff in static-paths.d.ts that is the same as before but with a different paths order.

Diggin into the code I found it uses globby inside. As referenced here https://github.com/sindresorhus/globby/issues/131#issuecomment-513565156 the globby results are not deterministic. I think this causes the git diff.

Can we sort the results to avoid this useless diff?

We can use globbySync and run manual sort after it instead of globbyStream https://github.com/Schniz/next-static-paths/blob/main/packages/next-static-paths/cli/command-generate.ts#L105 here but it can hurt performance a bit

Thanks!

nirtamir2 avatar Aug 22 '22 11:08 nirtamir2