nuxt-typed-router 3.3.3 → 3.4.0

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/README.md CHANGED
@@ -60,8 +60,6 @@ Demo repo 🧪 : [nuxt-typed-router-demo](https://github.com/victorgarciaesgi/nu
60
60
  # Compatibility:
61
61
 
62
62
  - Nuxt 3
63
- - Nuxt 2 (via [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2))
64
-
65
63
 
66
64
 
67
65
  # Quick start
@@ -76,16 +74,6 @@ npm install -D nuxt-typed-router
76
74
  pnpm install -D nuxt-typed-router
77
75
  ```
78
76
 
79
- ### Nuxt 2 legacy (not maintained)
80
-
81
- Nuxt 2 version is no longer maintained, but still available in [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2)
82
- It only has route name autocomplete functionnality
83
-
84
- ```bash
85
- yarn add -D nuxt-typed-router@legacy
86
- # or
87
- npm install -D nuxt-typed-router@legacy
88
- ```
89
77
 
90
78
  # Configuration
91
79
  Register the module in the `nuxt.config.ts`, done!
package/dist/module.d.mts CHANGED
@@ -27,14 +27,14 @@ interface ModuleOptions {
27
27
  * Remove Nuxt definitions to avoid conflicts
28
28
  * @default true
29
29
  */
30
- experimentalRemoveNuxtDefs?: boolean;
30
+ removeNuxtDefs?: boolean;
31
31
  /**
32
32
  * ⚠️ Experimental
33
33
  *
34
34
  * Exclude certain routes from being included into the generated types
35
35
  * Ex: 404 routes or catchAll routes
36
36
  */
37
- experimentalIgnoreRoutes?: string[];
37
+ ignoreRoutes?: string[];
38
38
  }
39
39
  interface StrictOptions {
40
40
  NuxtLink?: StrictParamsOptions;
package/dist/module.d.ts CHANGED
@@ -27,14 +27,14 @@ interface ModuleOptions {
27
27
  * Remove Nuxt definitions to avoid conflicts
28
28
  * @default true
29
29
  */
30
- experimentalRemoveNuxtDefs?: boolean;
30
+ removeNuxtDefs?: boolean;
31
31
  /**
32
32
  * ⚠️ Experimental
33
33
  *
34
34
  * Exclude certain routes from being included into the generated types
35
35
  * Ex: 404 routes or catchAll routes
36
36
  */
37
- experimentalIgnoreRoutes?: string[];
37
+ ignoreRoutes?: string[];
38
38
  }
39
39
  interface StrictOptions {
40
40
  NuxtLink?: StrictParamsOptions;
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "3.3.3"
8
+ "version": "3.4.0"
9
9
  }
package/dist/module.mjs CHANGED
@@ -24,7 +24,7 @@ class ModuleOptionsStore {
24
24
  i18n = false;
25
25
  i18nOptions = null;
26
26
  i18nLocales = [];
27
- experimentalIgnoreRoutes = [];
27
+ ignoreRoutes = [];
28
28
  updateOptions(options) {
29
29
  if (options.plugin != null)
30
30
  this.plugin = options.plugin;
@@ -58,12 +58,12 @@ class ModuleOptionsStore {
58
58
  if (options.pathCheck != null) {
59
59
  this.pathCheck = options.pathCheck;
60
60
  }
61
- if (options.experimentalIgnoreRoutes) {
62
- this.experimentalIgnoreRoutes = options.experimentalIgnoreRoutes;
61
+ if (options.ignoreRoutes) {
62
+ this.ignoreRoutes = options.ignoreRoutes;
63
63
  }
64
64
  }
65
65
  get resolvedIgnoredRoutes() {
66
- return this.experimentalIgnoreRoutes.map((file) => path.join(this.pagesDir, file));
66
+ return this.ignoreRoutes.map((file) => path.join(this.pagesDir, file));
67
67
  }
68
68
  getResolvedStrictOptions() {
69
69
  let resolved;
@@ -358,6 +358,19 @@ function createTypedRouterFile() {
358
358
 
359
359
  // - Routes location for navigation types (ex: router.push or navigateTo)
360
360
 
361
+
362
+ export type NuxtRoute<T extends RoutesNamesList, P extends string, E extends boolean = false> =
363
+ | TypedRouteLocationRawFromName<T, P>
364
+ ${returnIfTrue(!pathCheck && !strictOptions.NuxtLink.strictToArgument, ` | string`)}
365
+ ${returnIfTrue(
366
+ pathCheck && strictOptions.NuxtLink.strictToArgument,
367
+ ` | (E extends true ? string : never)`
368
+ )}
369
+ ${returnIfTrue(
370
+ pathCheck && !strictOptions.NuxtLink.strictToArgument,
371
+ ` | (E extends true ? string : TypedPathParameter<P>)`
372
+ )}
373
+
361
374
  /**
362
375
  * RouteLocationRaw with discrimanated name and params properties
363
376
  * {@link RouteLocationRaw}
@@ -460,22 +473,14 @@ function createTypedRouterFile() {
460
473
  *
461
474
  * @param to - Route location to navigate to
462
475
  */
463
- push<T extends RoutesNamesList, P extends string>(to: TypedRouteLocationRawFromName<T, P>): Promise<NavigationFailure | void | undefined>;
464
- ${returnIfTrue(
465
- pathCheck && !strictOptions.router.strictToArgument,
466
- `push<T extends string>(to: TypedPathParameter<T>): Promise<NavigationFailure | void | undefined>;`
467
- )}
476
+ push<T extends RoutesNamesList, P extends string>(to: NuxtRoute<T, P>): Promise<NavigationFailure | void | undefined>;
468
477
  /**
469
478
  * Programmatically navigate to a new URL by replacing the current entry in
470
479
  * the history stack.
471
480
  *
472
481
  * @param to - Route location to navigate to
473
482
  */
474
- replace<T extends RoutesNamesList, P extends string>(to: TypedRouteLocationRawFromName<T, P>): Promise<NavigationFailure | void | undefined>;
475
- ${returnIfTrue(
476
- pathCheck && !strictOptions.router.strictToArgument,
477
- `replace<T extends string>(to: TypedPathParameter<T>): Promise<NavigationFailure | void | undefined>;`
478
- )}
483
+ replace<T extends RoutesNamesList, P extends string>(to: NuxtRoute<T, P>): Promise<NavigationFailure | void | undefined>;
479
484
  }
480
485
 
481
486
 
@@ -520,24 +525,25 @@ function createTypedRouterFile() {
520
525
  }
521
526
 
522
527
  function createTypedRouterDefinitionFile() {
523
- const strictOptions = moduleOptionStore.getResolvedStrictOptions();
528
+ moduleOptionStore.getResolvedStrictOptions();
524
529
  const { plugin, autoImport, i18n, pathCheck } = moduleOptionStore;
525
530
  return (
526
531
  /* typescript */
527
532
  `
528
533
 
529
- import type { NuxtLinkProps, PageMeta } from '#app';
534
+ import type { NuxtLinkProps, PageMeta } from 'nuxt/app';
530
535
  import NuxtLink from 'nuxt/dist/app/components/nuxt-link';
531
536
  import type { RouteLocationRaw, RouteLocationPathRaw } from 'vue-router';
532
537
  import type { RoutesNamedLocations, RoutesNamesListRecord, RoutesNamesList } from './__routes';
533
- import type {TypedRouter, TypedRoute, TypedRouteLocationRawFromName, TypedLocationAsRelativeRaw} from './__router';
538
+ import type {TypedRouter, TypedRoute, TypedRouteLocationRawFromName, TypedLocationAsRelativeRaw, NuxtRoute} from './__router';
534
539
  import { useRoute as _useRoute } from './__useTypedRoute';
535
540
  import { useRouter as _useRouter } from './__useTypedRouter';
536
541
  import { useLink as _useLink } from './__useTypedLink';
537
542
  import { navigateTo as _navigateTo } from './__navigateTo';
538
543
  ${returnIfTrue(
539
544
  i18n,
540
- `import { useLocalePath as _useLocalePath, useLocaleRoute as _useLocaleRoute} from './__i18n-router';`
545
+ `import { useLocalePath as _useLocalePath, useLocaleRoute as _useLocaleRoute} from './__i18n-router';
546
+ import type {TypedNuxtLinkLocale} from './__NuxtLinkLocale'`
541
547
  )}
542
548
 
543
549
  import {definePageMeta as _definePageMeta} from './__definePageMeta';
@@ -569,40 +575,28 @@ function createTypedRouterDefinitionFile() {
569
575
  )}
570
576
  }
571
577
 
572
- type TypedNuxtLinkProps<T extends string, E extends boolean = false> = Omit<NuxtLinkProps, 'to' | 'external'> &
578
+ type TypedNuxtLinkProps<
579
+ T extends RoutesNamesList,
580
+ P extends string,
581
+ E extends boolean = false> = Omit<NuxtLinkProps, 'to' | 'external'> &
573
582
  {
574
- to:
575
- | Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & RoutesNamedLocations
576
- | Omit<RouteLocationPathRaw, 'path'>
577
- ${returnIfTrue(
578
- pathCheck && !strictOptions.NuxtLink.strictRouteLocation,
579
- `& {path?: (E extends true ? string : TypedPathParameter<T>)}`
580
- )}
581
- ${returnIfTrue(!pathCheck && !strictOptions.NuxtLink.strictToArgument, ` | string`)}
582
- ${returnIfTrue(
583
- pathCheck && strictOptions.NuxtLink.strictToArgument,
584
- ` | (E extends true ? string : void)`
585
- )}
586
- ${returnIfTrue(
587
- pathCheck && !strictOptions.NuxtLink.strictToArgument,
588
- ` | (E extends true ? string : TypedPathParameter<T>)`
589
- )},
583
+ to: NuxtRoute<T, P, E>,
590
584
  external?: E
591
585
  }
592
586
 
593
587
 
594
588
 
595
- export type TypedNuxtLink = new <P extends string, E extends boolean = false>(props: TypedNuxtLinkProps<P, E>) => Omit<
589
+ export type TypedNuxtLink = new <T extends RoutesNamesList, P extends string, E extends boolean = false>(props: TypedNuxtLinkProps<T, P, E>) => Omit<
596
590
  typeof NuxtLink,
597
591
  '$props'
598
592
  > & {
599
- $props: TypedNuxtLinkProps<P, E>;
593
+ $props: TypedNuxtLinkProps<T, P, E>;
600
594
  };
601
595
 
602
- // Declare runtime-core instead of vue for compatibility issues with pnpm
603
596
  declare module 'vue' {
604
597
  interface GlobalComponents {
605
598
  NuxtLink: TypedNuxtLink;
599
+ ${returnIfTrue(i18n, ` NuxtLinkLocale: TypedNuxtLinkLocale;`)}
606
600
  }
607
601
  }
608
602
 
@@ -644,6 +638,7 @@ function createIndexFile() {
644
638
  TypedRouteLocationRaw,
645
639
  TypedRouteLocationRawFromName,
646
640
  TypedRouter,
641
+ NuxtRoute
647
642
  } from './__router';
648
643
  export { routesNames } from './__routes';
649
644
  export type {
@@ -908,7 +903,7 @@ function createTypeUtilsRuntimeFile() {
908
903
  }
909
904
 
910
905
  function createi18nRouterFile() {
911
- const { router } = moduleOptionStore.getResolvedStrictOptions();
906
+ const { router, NuxtLink } = moduleOptionStore.getResolvedStrictOptions();
912
907
  const { i18nOptions, pathCheck, i18nLocales } = moduleOptionStore;
913
908
  const LocalePathType = i18nOptions?.strategy === "no_prefix" ? "TypedPathParameter" : "TypedLocalePathParameter";
914
909
  return (
@@ -925,6 +920,16 @@ function createi18nRouterFile() {
925
920
 
926
921
  export type I18nLocales = ${i18nLocales?.length ? i18nLocales.map((loc) => `"${loc}"`).join("|") : "string"};
927
922
 
923
+
924
+ export type NuxtLocaleRoute<T extends RoutesNamesList, P extends string, E extends boolean = false> =
925
+ | TypedRouteLocationRawFromName<T, P>
926
+ ${returnIfTrue(!pathCheck && !NuxtLink.strictToArgument, ` | string`)}
927
+ ${returnIfTrue(pathCheck && NuxtLink.strictToArgument, ` | (E extends true ? string : never)`)}
928
+ ${returnIfTrue(
929
+ pathCheck && !NuxtLink.strictToArgument,
930
+ ` | (E extends true ? string : ${LocalePathType}<P>)`
931
+ )}
932
+
928
933
  export interface TypedToLocalePath {
929
934
  <T extends RoutesNamesList, P extends string>(
930
935
  to: TypedRouteLocationRawFromName<T, P>,
@@ -1181,7 +1186,7 @@ function createDefinePageMetaFile() {
1181
1186
  `
1182
1187
 
1183
1188
  import { definePageMeta as defaultDefinePageMeta } from '#imports';
1184
- import type {PageMeta, NuxtError} from '#app'
1189
+ import type {PageMeta, NuxtError} from 'nuxt/app'
1185
1190
  import type {TypedRouteFromName, TypedRoute, TypedRouteLocationRawFromName, TypedRouteLocationRaw} from './__router';
1186
1191
  import type {RoutesNamesList} from './__routes';
1187
1192
  ${returnIfTrue(pathCheck, `import type {TypedPathParameter} from './__paths';`)}
@@ -1301,6 +1306,40 @@ export const helpers = {
1301
1306
  );
1302
1307
  }
1303
1308
 
1309
+ function createNuxtLinkLocaleDefinitionFile() {
1310
+ moduleOptionStore.getResolvedStrictOptions();
1311
+ return (
1312
+ /* typescript */
1313
+ `
1314
+
1315
+ import type { NuxtLinkProps, PageMeta } from 'nuxt/app';
1316
+ import NuxtLink from 'nuxt/dist/app/components/nuxt-link';
1317
+ import type { RoutesNamedLocations, RoutesNamesListRecord, RoutesNamesList } from './__routes';
1318
+ import type {TypedRouter, TypedRoute, TypedRouteLocationRawFromName, TypedLocationAsRelativeRaw} from './__router';
1319
+ import type {NuxtLocaleRoute, I18nLocales} from './__i18n-router';
1320
+
1321
+
1322
+ type TypedNuxtLinkLocaleProps<
1323
+ T extends RoutesNamesList,
1324
+ P extends string,
1325
+ E extends boolean = false> = Omit<NuxtLinkProps, 'to' | 'external'> &
1326
+ {
1327
+ to: NuxtLocaleRoute<T, P, E>,
1328
+ external?: E,
1329
+ locale?: E extends true ? never : I18nLocales
1330
+ }
1331
+
1332
+ export type TypedNuxtLinkLocale = new <T extends RoutesNamesList, P extends string, E extends boolean = false>(props: TypedNuxtLinkLocaleProps<T, P, E>) => Omit<
1333
+ typeof NuxtLink,
1334
+ '$props'
1335
+ > & {
1336
+ $props: TypedNuxtLinkLocaleProps<T, P, E>;
1337
+ };
1338
+
1339
+ `
1340
+ );
1341
+ }
1342
+
1304
1343
  async function handleAddPlugin() {
1305
1344
  const pluginName = "__typed-router.plugin.ts";
1306
1345
  addPluginTemplate({
@@ -1412,6 +1451,10 @@ async function saveGeneratedFiles({ outputData }) {
1412
1451
  fileName: "__i18n-router.ts",
1413
1452
  content: createi18nRouterFile()
1414
1453
  });
1454
+ filesMap.push({
1455
+ fileName: "__NuxtLinkLocale.ts",
1456
+ content: createNuxtLinkLocaleDefinitionFile()
1457
+ });
1415
1458
  }
1416
1459
  await Promise.all(
1417
1460
  filesMap.map(({ content, fileName }) => {
@@ -1667,7 +1710,7 @@ async function removeNuxtDefinitions({
1667
1710
  encoding: "utf8"
1668
1711
  });
1669
1712
  const replacedNuxtLink = componentDefinitions.replace(
1670
- /'NuxtLink': typeof import\(".*"\)\['default'\]/gm,
1713
+ /'NuxtLink': typeof import\(".*"\)\['default'\]|'NuxtLinkLocale': typeof import\(".*"\)\['default'\]/gm,
1671
1714
  ""
1672
1715
  );
1673
1716
  processPathAndWriteFile({
@@ -1712,8 +1755,8 @@ const module = defineNuxtModule({
1712
1755
  plugin: false,
1713
1756
  strict: false,
1714
1757
  pathCheck: true,
1715
- experimentalRemoveNuxtDefs: true,
1716
- experimentalIgnoreRoutes: []
1758
+ removeNuxtDefs: true,
1759
+ ignoreRoutes: []
1717
1760
  },
1718
1761
  setup(moduleOptions, nuxt) {
1719
1762
  const { resolve } = createResolver(import.meta.url);
@@ -1752,7 +1795,7 @@ const module = defineNuxtModule({
1752
1795
  experimentalRfc436: true
1753
1796
  };
1754
1797
  }
1755
- if (moduleOptions.experimentalRemoveNuxtDefs) {
1798
+ if (moduleOptions.removeNuxtDefs) {
1756
1799
  removeNuxtDefinitions({
1757
1800
  autoImport: nuxt.options.imports.autoImport ?? true,
1758
1801
  buildDir: nuxt.options.buildDir
@@ -1760,7 +1803,7 @@ const module = defineNuxtModule({
1760
1803
  }
1761
1804
  });
1762
1805
  nuxt.hook("build:done", () => {
1763
- if (moduleOptions.experimentalRemoveNuxtDefs) {
1806
+ if (moduleOptions.removeNuxtDefs) {
1764
1807
  removeNuxtDefinitions({
1765
1808
  autoImport: nuxt.options.imports.autoImport ?? true,
1766
1809
  buildDir: nuxt.options.buildDir
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "3.3.3",
3
+ "version": "3.4.0",
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,41 +60,41 @@
60
60
  "url": "https://github.com/victorgarciaesgi/nuxt-typed-router/issues"
61
61
  },
62
62
  "dependencies": {
63
- "@nuxt/kit": "3.8.1",
63
+ "@nuxt/kit": "3.8.2",
64
64
  "chalk": "5.3.0",
65
65
  "defu": "6.1.3",
66
66
  "lodash-es": "4.17.21",
67
- "log-symbols": "5.1.0",
67
+ "log-symbols": "6.0.0",
68
68
  "mkdirp": "3.0.1",
69
69
  "nanoid": "5.0.3",
70
70
  "pathe": "1.1.1"
71
71
  },
72
72
  "devDependencies": {
73
- "@nuxt/devtools": "1.0.0",
73
+ "@nuxt/devtools": "1.0.3",
74
74
  "@nuxt/module-builder": "0.5.4",
75
75
  "@nuxt/test-utils": "3.8.1",
76
76
  "@nuxt/types": "2.17.2",
77
77
  "@nuxtjs/eslint-config-typescript": "12.1.0",
78
- "@nuxtjs/i18n": "8.0.0-beta.10",
78
+ "@nuxtjs/i18n": "8.0.0-rc.5",
79
79
  "@nuxtjs/web-vitals": "0.2.6",
80
- "@types/lodash-es": "4.17.11",
81
- "@types/node": "20.9.0",
80
+ "@types/lodash-es": "4.17.12",
81
+ "@types/node": "20.10.0",
82
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",
83
+ "@typescript-eslint/eslint-plugin": "6.12.0",
84
+ "@typescript-eslint/parser": "6.12.0",
85
+ "@vue/test-utils": "2.4.2",
86
86
  "bumpp": "9.2.0",
87
87
  "changelogithub": "0.13.2",
88
88
  "cross-env": "7.0.3",
89
- "eslint": "8.53.0",
89
+ "eslint": "8.54.0",
90
90
  "eslint-config-prettier": "9.0.0",
91
91
  "eslint-plugin-vue": "9.18.1",
92
- "nuxt": "3.8.1",
92
+ "nuxt": "3.8.2",
93
93
  "nuxt-seo-kit": "1.3.13",
94
94
  "playwright": "1.37.0",
95
- "prettier": "3.0.3",
95
+ "prettier": "3.1.0",
96
96
  "tsd": "0.29.0",
97
- "typescript": "5.2.2",
97
+ "typescript": "5.3.2",
98
98
  "vitest": "0.34.6",
99
99
  "vue-eslint-parser": "9.3.2",
100
100
  "vue-router": "4.2.5",