nuxt-typed-router 3.3.2 → 3.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/module.json +1 -1
- package/dist/module.mjs +95 -32
- package/dist/types.d.mts +3 -2
- package/dist/types.d.ts +3 -2
- package/package.json +33 -33
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -12,27 +12,19 @@ import { mkdirp } from 'mkdirp';
|
|
|
12
12
|
import { camelCase } from 'lodash-es';
|
|
13
13
|
import { readFile } from 'fs/promises';
|
|
14
14
|
|
|
15
|
-
var __defProp = Object.defineProperty;
|
|
16
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
|
-
var __publicField = (obj, key, value) => {
|
|
18
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
|
-
return value;
|
|
20
|
-
};
|
|
21
15
|
class ModuleOptionsStore {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
__publicField(this, "experimentalIgnoreRoutes", []);
|
|
35
|
-
}
|
|
16
|
+
plugin = false;
|
|
17
|
+
strict = false;
|
|
18
|
+
pathCheck = true;
|
|
19
|
+
autoImport = false;
|
|
20
|
+
rootDir = "";
|
|
21
|
+
buildDir = "";
|
|
22
|
+
srcDir = "";
|
|
23
|
+
pagesDir = "";
|
|
24
|
+
i18n = false;
|
|
25
|
+
i18nOptions = null;
|
|
26
|
+
i18nLocales = [];
|
|
27
|
+
experimentalIgnoreRoutes = [];
|
|
36
28
|
updateOptions(options) {
|
|
37
29
|
if (options.plugin != null)
|
|
38
30
|
this.plugin = options.plugin;
|
|
@@ -220,7 +212,7 @@ function createLocaleRoutePathSchema(routePaths) {
|
|
|
220
212
|
${routePaths.filter((f) => !!f.path && !f.isLocale).map((route) => `"${route.path}"`).join("|")}
|
|
221
213
|
`;
|
|
222
214
|
}
|
|
223
|
-
function createValidatePathTypes(pathElements, withLocale = false) {
|
|
215
|
+
function createValidatePathTypes(pathElements, routesList, withLocale = false) {
|
|
224
216
|
let pathConditions = pathElements.map(createTypeValidatePathCondition).filter((f) => {
|
|
225
217
|
if (withLocale) {
|
|
226
218
|
return !f.isLocale;
|
|
@@ -243,14 +235,14 @@ function createValidatePathTypes(pathElements, withLocale = false) {
|
|
|
243
235
|
: ${pathConditions.length ? `\`Error: \${${pathConditions.map((t) => `${t.typeName}<T>`).join("|")}}\`` : "never"}
|
|
244
236
|
: never;
|
|
245
237
|
|
|
246
|
-
|
|
238
|
+
// RouteNameFromPath, RouteNameFromLocalePath
|
|
247
239
|
export type RouteNameFrom${returnIfTrue(
|
|
248
240
|
withLocale,
|
|
249
241
|
"Locale"
|
|
250
242
|
)}Path<T extends string> = T extends string
|
|
251
243
|
? T extends '/'
|
|
252
244
|
? "index"
|
|
253
|
-
${pathConditions.length ? `: ${pathConditions.map((t) => `${t.typeName}<T> extends true ? "${t.routeName}"`).join(": ")} : never` : ": never"}
|
|
245
|
+
${pathConditions.length ? `: ${pathConditions.filter((f) => routesList.includes(f.routeName)).map((t) => `${t.typeName}<T> extends true ? "${t.routeName}"`).join(": ")} : never` : ": never"}
|
|
254
246
|
: never;
|
|
255
247
|
|
|
256
248
|
`;
|
|
@@ -541,6 +533,7 @@ function createTypedRouterDefinitionFile() {
|
|
|
541
533
|
import type {TypedRouter, TypedRoute, TypedRouteLocationRawFromName, TypedLocationAsRelativeRaw} from './__router';
|
|
542
534
|
import { useRoute as _useRoute } from './__useTypedRoute';
|
|
543
535
|
import { useRouter as _useRouter } from './__useTypedRouter';
|
|
536
|
+
import { useLink as _useLink } from './__useTypedLink';
|
|
544
537
|
import { navigateTo as _navigateTo } from './__navigateTo';
|
|
545
538
|
${returnIfTrue(
|
|
546
539
|
i18n,
|
|
@@ -560,6 +553,7 @@ function createTypedRouterDefinitionFile() {
|
|
|
560
553
|
`
|
|
561
554
|
const useRoute: typeof _useRoute;
|
|
562
555
|
const useRouter: typeof _useRouter;
|
|
556
|
+
const useLink: typeof _useLink;
|
|
563
557
|
const navigateTo: typeof _navigateTo;
|
|
564
558
|
const definePageMeta: typeof _definePageMeta;
|
|
565
559
|
|
|
@@ -661,6 +655,7 @@ function createIndexFile() {
|
|
|
661
655
|
} from './__routes';
|
|
662
656
|
export { useRoute } from './__useTypedRoute';
|
|
663
657
|
export { useRouter } from './__useTypedRouter';
|
|
658
|
+
export { useLink } from './__useTypedLink';
|
|
664
659
|
export { navigateTo } from './__navigateTo';
|
|
665
660
|
export { definePageMeta } from './__definePageMeta';
|
|
666
661
|
export { helpers } from './__helpers';
|
|
@@ -688,7 +683,7 @@ function createPluginFile() {
|
|
|
688
683
|
/* typescript */
|
|
689
684
|
`
|
|
690
685
|
|
|
691
|
-
import { defineNuxtPlugin, useRouter, useRoute } from '#
|
|
686
|
+
import { defineNuxtPlugin, useRouter, useRoute } from '#imports';
|
|
692
687
|
import {TypedRouter, TypedRoute, routesNames} from '@typed-router';
|
|
693
688
|
|
|
694
689
|
export default defineNuxtPlugin(() => {
|
|
@@ -711,7 +706,7 @@ function createUseTypedRouteFile() {
|
|
|
711
706
|
return (
|
|
712
707
|
/* typescript */
|
|
713
708
|
`
|
|
714
|
-
import { useRoute as defaultRoute } from '#
|
|
709
|
+
import { useRoute as defaultRoute } from '#imports';
|
|
715
710
|
import type { RoutesNamesList } from './__routes';
|
|
716
711
|
import type {TypedRoute, TypedRouteFromName} from './__router'
|
|
717
712
|
|
|
@@ -752,7 +747,7 @@ function createUseTypedRouterFile() {
|
|
|
752
747
|
/* typescript */
|
|
753
748
|
`
|
|
754
749
|
|
|
755
|
-
import { useRouter as defaultRouter } from '#
|
|
750
|
+
import { useRouter as defaultRouter } from '#imports';
|
|
756
751
|
import type { TypedRouter } from './__router';
|
|
757
752
|
|
|
758
753
|
/**
|
|
@@ -774,13 +769,76 @@ function createUseTypedRouterFile() {
|
|
|
774
769
|
);
|
|
775
770
|
}
|
|
776
771
|
|
|
772
|
+
function createUseTypedLinkFile() {
|
|
773
|
+
const strictOptions = moduleOptionStore.getResolvedStrictOptions();
|
|
774
|
+
const { pathCheck } = moduleOptionStore;
|
|
775
|
+
return (
|
|
776
|
+
/* typescript */
|
|
777
|
+
`
|
|
778
|
+
|
|
779
|
+
import { useLink as defaultLink } from '#imports';
|
|
780
|
+
import type {MaybeRef} from 'vue';
|
|
781
|
+
import type { NavigateToOptions } from 'nuxt/dist/app/composables/router';
|
|
782
|
+
import type { NavigationFailure } from 'vue-router';
|
|
783
|
+
import type { TypedRouteLocationRawFromName, TypedRouteFromName, TypedRoute } from './__router';
|
|
784
|
+
import type { RoutesNamesList } from './__routes';
|
|
785
|
+
${returnIfTrue(
|
|
786
|
+
pathCheck,
|
|
787
|
+
`import type {TypedPathParameter, RouteNameFromPath} from './__paths';`
|
|
788
|
+
)}
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
type LinkedRoute<T extends RoutesNamesList> = {
|
|
792
|
+
route: ComputedRef<TypedRouteFromName<T> & {
|
|
793
|
+
href: string;
|
|
794
|
+
}>;
|
|
795
|
+
href: ComputedRef<string>;
|
|
796
|
+
isActive: ComputedRef<boolean>;
|
|
797
|
+
isExactActive: ComputedRef<boolean>;
|
|
798
|
+
navigate: (e?: MouseEvent) => Promise<void | NavigationFailure>;
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
interface UseLinkFunction {
|
|
803
|
+
<T extends RoutesNamesList, P extends string>(
|
|
804
|
+
props: {
|
|
805
|
+
to: MaybeRef<TypedRouteLocationRawFromName<T, P>>,
|
|
806
|
+
replace?: MaybeRef<boolean>
|
|
807
|
+
}
|
|
808
|
+
) : LinkedRoute<T>
|
|
809
|
+
${returnIfTrue(
|
|
810
|
+
pathCheck && !strictOptions.router.strictToArgument,
|
|
811
|
+
`<T extends string>(
|
|
812
|
+
props: {
|
|
813
|
+
to: MaybeRef<TypedPathParameter<T>>,
|
|
814
|
+
replace?: MaybeRef<boolean>
|
|
815
|
+
}
|
|
816
|
+
) : LinkedRoute<RouteNameFromPath<T>>`
|
|
817
|
+
)}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Typed clone of \`useLink\`
|
|
822
|
+
*
|
|
823
|
+
* @exemple
|
|
824
|
+
*
|
|
825
|
+
* \`\`\`ts
|
|
826
|
+
* const router = useLink(props);
|
|
827
|
+
* \`\`\`
|
|
828
|
+
*/
|
|
829
|
+
export const useLink: UseLinkFunction = defaultLink as any;
|
|
830
|
+
|
|
831
|
+
`
|
|
832
|
+
);
|
|
833
|
+
}
|
|
834
|
+
|
|
777
835
|
function createNavigateToFile() {
|
|
778
836
|
const { router } = moduleOptionStore.getResolvedStrictOptions();
|
|
779
837
|
const { pathCheck } = moduleOptionStore;
|
|
780
838
|
return (
|
|
781
839
|
/* typescript */
|
|
782
840
|
`
|
|
783
|
-
import { navigateTo as defaultNavigateTo } from '#
|
|
841
|
+
import { navigateTo as defaultNavigateTo } from '#imports';
|
|
784
842
|
import type { NavigateToOptions } from 'nuxt/dist/app/composables/router';
|
|
785
843
|
import type { NavigationFailure } from 'vue-router';
|
|
786
844
|
import type { TypedRouteLocationRawFromName, TypedRouteFromName, TypedRoute } from './__router';
|
|
@@ -818,7 +876,8 @@ function createNavigateToFile() {
|
|
|
818
876
|
) : Promise<void | NavigationFailure | TypedRouteFromName<RouteNameFromPath<T>>>`
|
|
819
877
|
)}
|
|
820
878
|
}
|
|
821
|
-
|
|
879
|
+
|
|
880
|
+
export const navigateTo: NavigateToFunction = defaultNavigateTo as any;
|
|
822
881
|
|
|
823
882
|
`
|
|
824
883
|
);
|
|
@@ -1000,7 +1059,7 @@ function extractPathElements(partOfPath, route) {
|
|
|
1000
1059
|
return { pathElements, strippedPath };
|
|
1001
1060
|
}
|
|
1002
1061
|
|
|
1003
|
-
function createPathsFiles({ routesPaths }) {
|
|
1062
|
+
function createPathsFiles({ routesPaths, routesList }) {
|
|
1004
1063
|
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1005
1064
|
const hasPrefixStrategy = i18n && i18nOptions?.strategy !== "no_prefix";
|
|
1006
1065
|
const filteredRoutesPaths = routesPaths.filter((route) => !routesPaths.find((r) => `${route.path}/` === r.path)).map((route) => ({
|
|
@@ -1048,8 +1107,8 @@ function createPathsFiles({ routesPaths }) {
|
|
|
1048
1107
|
const pathElements = filteredRoutesPaths.filter((f) => f.path && f.path !== "/").map((route) => {
|
|
1049
1108
|
return route.path.split("/").filter((f) => f.length).map((m) => destructurePath(m, route));
|
|
1050
1109
|
}).filter((f) => f.length);
|
|
1051
|
-
const validatePathTypes = createValidatePathTypes(pathElements);
|
|
1052
|
-
const validateLocalePathTypes = createValidatePathTypes(pathElements, true);
|
|
1110
|
+
const validatePathTypes = createValidatePathTypes(pathElements, routesList);
|
|
1111
|
+
const validateLocalePathTypes = createValidatePathTypes(pathElements, routesList, true);
|
|
1053
1112
|
return (
|
|
1054
1113
|
/* typescript */
|
|
1055
1114
|
`
|
|
@@ -1307,6 +1366,10 @@ async function saveGeneratedFiles({ outputData }) {
|
|
|
1307
1366
|
fileName: "__useTypedRoute.ts",
|
|
1308
1367
|
content: createUseTypedRouteFile()
|
|
1309
1368
|
},
|
|
1369
|
+
{
|
|
1370
|
+
fileName: "__useTypedLink.ts",
|
|
1371
|
+
content: createUseTypedLinkFile()
|
|
1372
|
+
},
|
|
1310
1373
|
{
|
|
1311
1374
|
fileName: "__paths.d.ts",
|
|
1312
1375
|
content: createPathsFiles(outputData)
|
|
@@ -1451,7 +1514,7 @@ function walkThoughRoutes({
|
|
|
1451
1514
|
return;
|
|
1452
1515
|
}
|
|
1453
1516
|
const newPath = `${parent?.path ?? ""}${route.path.startsWith("/") || parent?.path === "/" ? route.path : `/${route.path}`}`;
|
|
1454
|
-
if (parent?.path !== "/") {
|
|
1517
|
+
if (parent?.path !== "/" || newPath !== parent?.path) {
|
|
1455
1518
|
output.routesPaths.push({
|
|
1456
1519
|
name: route.name,
|
|
1457
1520
|
path: newPath,
|
package/dist/types.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { ModuleOptions } from './module'
|
|
2
|
+
import type { ModuleOptions } from './module'
|
|
3
|
+
|
|
3
4
|
|
|
4
5
|
declare module '@nuxt/schema' {
|
|
5
6
|
interface NuxtConfig { ['nuxtTypedRouter']?: Partial<ModuleOptions> }
|
|
@@ -12,4 +13,4 @@ declare module 'nuxt/schema' {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
export { ModuleOptions, default } from './module'
|
|
16
|
+
export type { ModuleOptions, default } from './module'
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
|
|
2
|
-
import { ModuleOptions } from './module'
|
|
2
|
+
import type { ModuleOptions } from './module'
|
|
3
|
+
|
|
3
4
|
|
|
4
5
|
declare module '@nuxt/schema' {
|
|
5
6
|
interface NuxtConfig { ['nuxtTypedRouter']?: Partial<ModuleOptions> }
|
|
@@ -12,4 +13,4 @@ declare module 'nuxt/schema' {
|
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
|
|
15
|
-
export { ModuleOptions, default } from './module'
|
|
16
|
+
export type { ModuleOptions, default } from './module'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-typed-router",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.3",
|
|
4
4
|
"description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -60,44 +60,44 @@
|
|
|
60
60
|
"url": "https://github.com/victorgarciaesgi/nuxt-typed-router/issues"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@nuxt/kit": "
|
|
64
|
-
"chalk": "
|
|
65
|
-
"defu": "
|
|
66
|
-
"lodash-es": "
|
|
67
|
-
"log-symbols": "
|
|
68
|
-
"mkdirp": "
|
|
69
|
-
"nanoid": "
|
|
63
|
+
"@nuxt/kit": "3.8.1",
|
|
64
|
+
"chalk": "5.3.0",
|
|
65
|
+
"defu": "6.1.3",
|
|
66
|
+
"lodash-es": "4.17.21",
|
|
67
|
+
"log-symbols": "5.1.0",
|
|
68
|
+
"mkdirp": "3.0.1",
|
|
69
|
+
"nanoid": "5.0.3",
|
|
70
70
|
"pathe": "1.1.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@nuxt/devtools": "
|
|
74
|
-
"@nuxt/module-builder": "
|
|
75
|
-
"@nuxt/test-utils": "
|
|
76
|
-
"@nuxt/types": "
|
|
77
|
-
"@nuxtjs/eslint-config-typescript": "
|
|
73
|
+
"@nuxt/devtools": "1.0.0",
|
|
74
|
+
"@nuxt/module-builder": "0.5.4",
|
|
75
|
+
"@nuxt/test-utils": "3.8.1",
|
|
76
|
+
"@nuxt/types": "2.17.2",
|
|
77
|
+
"@nuxtjs/eslint-config-typescript": "12.1.0",
|
|
78
78
|
"@nuxtjs/i18n": "8.0.0-beta.10",
|
|
79
|
-
"@nuxtjs/web-vitals": "
|
|
80
|
-
"@types/lodash-es": "
|
|
81
|
-
"@types/node": "
|
|
82
|
-
"@types/prettier": "
|
|
83
|
-
"@typescript-eslint/eslint-plugin": "
|
|
84
|
-
"@typescript-eslint/parser": "
|
|
85
|
-
"@vue/test-utils": "
|
|
79
|
+
"@nuxtjs/web-vitals": "0.2.6",
|
|
80
|
+
"@types/lodash-es": "4.17.11",
|
|
81
|
+
"@types/node": "20.9.0",
|
|
82
|
+
"@types/prettier": "3.0.0",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "6.10.0",
|
|
84
|
+
"@typescript-eslint/parser": "6.10.0",
|
|
85
|
+
"@vue/test-utils": "2.4.1",
|
|
86
86
|
"bumpp": "9.2.0",
|
|
87
|
-
"changelogithub": "0.13.
|
|
88
|
-
"cross-env": "
|
|
89
|
-
"eslint": "8.
|
|
90
|
-
"eslint-config-prettier": "
|
|
91
|
-
"eslint-plugin-vue": "
|
|
92
|
-
"nuxt": "3.8.
|
|
87
|
+
"changelogithub": "0.13.2",
|
|
88
|
+
"cross-env": "7.0.3",
|
|
89
|
+
"eslint": "8.53.0",
|
|
90
|
+
"eslint-config-prettier": "9.0.0",
|
|
91
|
+
"eslint-plugin-vue": "9.18.1",
|
|
92
|
+
"nuxt": "3.8.1",
|
|
93
93
|
"nuxt-seo-kit": "1.3.13",
|
|
94
|
-
"playwright": "1.
|
|
94
|
+
"playwright": "1.37.0",
|
|
95
95
|
"prettier": "3.0.3",
|
|
96
|
-
"tsd": "
|
|
97
|
-
"typescript": "
|
|
98
|
-
"vitest": "
|
|
99
|
-
"vue-eslint-parser": "
|
|
100
|
-
"vue-router": "
|
|
101
|
-
"vue-tsc": "
|
|
96
|
+
"tsd": "0.29.0",
|
|
97
|
+
"typescript": "5.2.2",
|
|
98
|
+
"vitest": "0.34.6",
|
|
99
|
+
"vue-eslint-parser": "9.3.2",
|
|
100
|
+
"vue-router": "4.2.5",
|
|
101
|
+
"vue-tsc": "1.8.22"
|
|
102
102
|
}
|
|
103
103
|
}
|