-
-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: experimental typed routes (#3142)
- Loading branch information
1 parent
f61b540
commit c103d13
Showing
16 changed files
with
416 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
externals: ['node:fs', 'node:url', 'webpack', '@babel/parser'] | ||
externals: ['node:fs', 'node:url', 'webpack', '@babel/parser', 'unplugin-vue-router', 'unplugin-vue-router/options'] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup } from '../utils' | ||
import fs from 'node:fs/promises' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/basic_usage`, import.meta.url)), | ||
browser: false, | ||
// overrides | ||
nuxtConfig: { | ||
experimental: { | ||
typedPages: true | ||
} | ||
} | ||
}) | ||
|
||
describe('`experimental.typedPages` undefined or enabled', async () => { | ||
test('generates route types', async () => { | ||
expect( | ||
await fs.readFile( | ||
fileURLToPath( | ||
new URL( | ||
`../fixtures/basic_usage/.nuxt/___experimental_typed_pages_spec_ts/types/typed-router-i18n.d.ts`, | ||
import.meta.url | ||
) | ||
), | ||
'utf-8' | ||
) | ||
).toMatchInlineSnapshot(` | ||
"/* 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 RouteNamedMapI18n { | ||
'index': RouteRecordInfo<'index', '/', Record<never, never>, Record<never, never>>, | ||
'pathMatch': RouteRecordInfo<'pathMatch', '/:pathMatch(.*)*', { pathMatch?: ParamValueZeroOrMore<true> }, { pathMatch?: ParamValueZeroOrMore<false> }>, | ||
'about': RouteRecordInfo<'about', '/about', Record<never, never>, Record<never, never>>, | ||
'api-products': RouteRecordInfo<'api-products', '/api/products', Record<never, never>, Record<never, never>>, | ||
'api-products-product': RouteRecordInfo<'api-products-product', '/api/products/:product()', { product: ParamValue<true> }, { product: ParamValue<false> }>, | ||
'api-products-data': RouteRecordInfo<'api-products-data', '/api/products-data', Record<never, never>, Record<never, never>>, | ||
'category-slug': RouteRecordInfo<'category-slug', '/category/:slug()', { slug: ParamValue<true> }, { slug: ParamValue<false> }>, | ||
'composables': RouteRecordInfo<'composables', '/composables', Record<never, never>, Record<never, never>>, | ||
'experimental-slug': RouteRecordInfo<'experimental-slug', '/experimental/:slug(.*)*', { slug?: ParamValueZeroOrMore<true> }, { slug?: ParamValueZeroOrMore<false> }>, | ||
'experimental-auto-import-translation-functions': RouteRecordInfo<'experimental-auto-import-translation-functions', '/experimental/auto-import-translation-functions', Record<never, never>, Record<never, never>>, | ||
'greetings': RouteRecordInfo<'greetings', '/greetings', Record<never, never>, Record<never, never>>, | ||
'layer-page': RouteRecordInfo<'layer-page', '/layer-page', Record<never, never>, Record<never, never>>, | ||
'layer-parent': RouteRecordInfo<'layer-parent', '/layer-parent', Record<never, never>, Record<never, never>>, | ||
'layer-parent-layer-child': RouteRecordInfo<'layer-parent-layer-child', '/layer-parent/layer-child', Record<never, never>, Record<never, never>>, | ||
'long-text': RouteRecordInfo<'long-text', '/long-text', Record<never, never>, Record<never, never>>, | ||
'nested-test-route': RouteRecordInfo<'nested-test-route', '/nested/test-route', Record<never, never>, Record<never, never>>, | ||
'nuxt-context-extension': RouteRecordInfo<'nuxt-context-extension', '/nuxt-context-extension', Record<never, never>, Record<never, never>>, | ||
'page with spaces': RouteRecordInfo<'page with spaces', '/page%20with%20spaces', Record<never, never>, Record<never, never>>, | ||
'post-id': RouteRecordInfo<'post-id', '/post/:id()', { id: ParamValue<true> }, { id: ParamValue<false> }>, | ||
'products': RouteRecordInfo<'products', '/products', Record<never, never>, Record<never, never>>, | ||
'products-slug': RouteRecordInfo<'products-slug', '/products/:slug()', { slug: ParamValue<true> }, { slug: ParamValue<false> }>, | ||
'user-profile': RouteRecordInfo<'user-profile', '/user/profile', Record<never, never>, Record<never, never>>, | ||
} | ||
} | ||
" | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup } from '../utils' | ||
import fs from 'node:fs/promises' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/basic_usage`, import.meta.url)), | ||
browser: false, | ||
// overrides | ||
nuxtConfig: { | ||
experimental: { | ||
typedPages: true | ||
}, | ||
i18n: { | ||
experimental: { | ||
typedPages: false | ||
} | ||
} | ||
} | ||
}) | ||
|
||
describe('`experimental.typedPages` explicitly disabled', async () => { | ||
test('does not generate types', async () => { | ||
await expect( | ||
fs.access( | ||
fileURLToPath( | ||
new URL( | ||
`../fixtures/basic_usage/.nuxt/___experimental_typed_pages_explicit_disable_spec_ts/types/typed-router-i18n.d.ts`, | ||
import.meta.url | ||
) | ||
) | ||
) | ||
).rejects.toThrowError() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.