-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
feat: allow post-processing generated DTS file #601
Conversation
commit: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #601 +/- ##
==========================================
- Coverage 61.72% 61.66% -0.06%
==========================================
Files 32 32
Lines 3135 3138 +3
Branches 580 580
==========================================
Hits 1935 1935
- Misses 1194 1197 +3
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Thanks! Ideally, editing the tree would be a preferred approach. Do you have any specific use case that requires this approach? It seems a bit like an escape hatch |
I get that, and we should probably include a warning that this is not meant for altering the generated output. The idea here is that a framework may want to append something to the generated file, such as this potential Nuxt example: /* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-router. ‼️ DO NOT MODIFY THIS FILE ‼️
// It's recommended to commit this file.
// Make sure to add this file to your tsconfig.json file as an "includes" or "files" entry.
declare module 'vue-router/auto-routes' {
import type {
RouteRecordInfo,
ParamValue,
ParamValueOneOrMore,
ParamValueZeroOrMore,
ParamValueZeroOrOne,
} from 'vue-router'
/**
* Route name map generated by unplugin-vue-router
*/
export interface RouteNamedMap {
'index': RouteRecordInfo<'index', '/', Record<never, never>, Record<never, never>>,
'topics-id': RouteRecordInfo<'topics-id', '/topics/:id()', { id: ParamValue<true> }, { id: ParamValue<false> }>,
'topics-id-view': RouteRecordInfo<'topics-id-view', '/topics/:id()/whatever/view', { id: ParamValue<true> }, { id: ParamValue<false> }>,
}
}
declare module '#app' {
export interface RouteFilePathNameMap {
'/app/pages/index.vue': 'index',
'/app/pages/topics/[id].vue': 'topics-id',
'/app/pages/topics/[id]/view.vue': 'topics-id-view',
}
}
|
That part can be added to a different dts. I think that makes more sense |
Fair enough! So just write the separate DTS file after |
Yes, that sounds right |
This adds a
postProcessDTS
option, which is a sync or async function that receives the generated DTS file's contents and lets that function return a modified string. This allows frameworks to add info of their own on the type-level in the generated DTS file.An example of how this may be used:
routesFolder: []
and usesbeforeWriteFiles
to provide their own route tree.I included an E2E test that tests this functionality. I couldn't figure out whether the E2E tests are actually ran in the CI though? They don't seem to be ran when running
pnpm test
. However, I did run the test manually and it did succeed.