nuxt-typed-router 3.1.3 → 3.1.4

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
@@ -16,6 +16,9 @@
16
16
  [![npm downloads][npm-total-downloads-src]][npm-downloads-href]
17
17
  <img src='https://img.shields.io/npm/l/nuxt-typed-router.svg'>
18
18
 
19
+ > ⚠️ Nuxt 3.4 introduced a breaking change in its router output
20
+ > Install `v3.1.4-beta.0` of nuxt-typed-router if you're using this Nuxt version
21
+
19
22
  ## Provide a type safe router to Nuxt with auto-generated typed definitions for route path, name and params
20
23
 
21
24
  - Supports all programmatic navigation utils (`NuxtLink`, `useRouter`, `navigateTo`, `useRoute`, `useLocalePath`, etc...)
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "3.1.3"
8
+ "version": "3.1.4"
9
9
  }
package/dist/module.mjs CHANGED
@@ -8,7 +8,7 @@ import prettier from 'prettier';
8
8
  import fs, { existsSync } from 'fs';
9
9
  import { fileURLToPath } from 'url';
10
10
  import { dirname, resolve } from 'pathe';
11
- import mkdirp from 'mkdirp';
11
+ import { mkdirp } from 'mkdirp';
12
12
  import { camelCase } from 'lodash-es';
13
13
  import { readFile } from 'fs/promises';
14
14
 
@@ -365,7 +365,7 @@ function createTypedRouterFile() {
365
365
  /**
366
366
  * Alternative version of {@link TypedRouteLocationRaw} but with a name generic
367
367
  */
368
- export type TypedRouteLocationRawFromName<T extends RoutesNamesList, P extends string = string, E extends boolean = false> =
368
+ export type TypedRouteLocationRawFromName<T extends RoutesNamesList, P extends string = string> =
369
369
  | (Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & TypedLocationAsRelativeRaw<T>)
370
370
  | Omit<RouteLocationPathRaw, 'path'>
371
371
  ${returnIfTrue(
@@ -401,15 +401,10 @@ function createTypedRouterFile() {
401
401
  * const myRoute = '/foo' as TypedRouteLocation;
402
402
  * \`\`\`
403
403
  * */
404
- export type TypedRouteLocation<T extends string = '/'> =
405
- | (Omit<Exclude<RouteLocationRaw, string>, 'name' | 'params'> & RoutesNamedLocations)
406
- | Omit<RouteLocationPathRaw, 'path'>
407
- ${returnIfTrue(
408
- pathCheck && !strictOptions.router.strictRouteLocation,
409
- `& {path?: TypedPathParameter<T>}`
410
- )}
411
- ${returnIfTrue(!pathCheck && !strictOptions.router.strictToArgument, ` | string`)}
412
- ${returnIfTrue(pathCheck && !strictOptions.router.strictToArgument, `| TypedPathParameter<T>`)}
404
+ export type TypedRouteLocation<T extends '/' = '/'> =
405
+ TypedRouteLocationRawFromName<any, T>
406
+ ${returnIfTrue(!pathCheck && !strictOptions.router.strictToArgument, ` & string`)}
407
+ ${returnIfTrue(pathCheck && !strictOptions.router.strictToArgument, `& TypedPathParameter<T>`)}
413
408
  ;
414
409
 
415
410
 
@@ -795,7 +790,7 @@ function createNavigateToFile() {
795
790
 
796
791
  interface NavigateToFunction {
797
792
  <T extends RoutesNamesList, P extends string, E extends boolean = false>(
798
- to: TypedRouteLocationRawFromName<T, P, E>,
793
+ to: TypedRouteLocationRawFromName<T, P>,
799
794
  options?: TypedNavigateToOptions<E>
800
795
  ) : Promise<void | NavigationFailure | TypedRouteFromName<T>>
801
796
  ${returnIfTrue(
@@ -839,6 +834,7 @@ function createTypeUtilsRuntimeFile() {
839
834
  function createi18nRouterFile() {
840
835
  const { router } = moduleOptionStore.getResolvedStrictOptions();
841
836
  const { i18nOptions, pathCheck, i18nLocales } = moduleOptionStore;
837
+ const LocalePathType = i18nOptions?.strategy === "no_prefix" ? "TypedPathParameter" : "TypedLocalePathParameter";
842
838
  return (
843
839
  /* typescript */
844
840
  `
@@ -848,7 +844,7 @@ function createi18nRouterFile() {
848
844
  import type {RoutesNamesList} from './__routes';
849
845
  ${returnIfTrue(
850
846
  pathCheck,
851
- `import type {TypedLocalePathParameter, RouteNameFromLocalePath} from './__paths';`
847
+ `import type {TypedLocalePathParameter, TypedPathParameter, RouteNameFromLocalePath} from './__paths';`
852
848
  )}
853
849
 
854
850
  export type I18nLocales = ${i18nLocales?.length ? i18nLocales.map((loc) => `"${loc}"`).join("|") : "string"};
@@ -863,7 +859,7 @@ function createi18nRouterFile() {
863
859
  ${returnIfTrue(
864
860
  pathCheck && !router.strictToArgument,
865
861
  `<T extends string>(
866
- to: TypedLocalePathParameter<T>,
862
+ to: ${LocalePathType}<T>,
867
863
  locale?: I18nLocales | undefined
868
864
  ) : [T] extends [never] ? string : Required<TypedRouteLocationRawFromName<RouteNameFromLocalePath<T>, T>>;`
869
865
  )}
@@ -877,7 +873,7 @@ function createi18nRouterFile() {
877
873
  <T extends RoutesNamesList, P extends string>(to: TypedRouteLocationRawFromName<T, P>, locale?: I18nLocales | undefined) : TypedRouteFromName<T>
878
874
  ${returnIfTrue(
879
875
  pathCheck && !router.strictToArgument,
880
- ` <T extends string>(to: TypedLocalePathParameter<T>, locale?: I18nLocales | undefined) : TypedRouteFromName<RouteNameFromLocalePath<T>>;`
876
+ ` <T extends string>(to: ${LocalePathType}<T>, locale?: I18nLocales | undefined) : TypedRouteFromName<RouteNameFromLocalePath<T>>;`
881
877
  )}
882
878
  }
883
879
 
@@ -890,7 +886,7 @@ function createi18nRouterFile() {
890
886
  );
891
887
  }
892
888
 
893
- const routeParamExtractRegxp = /(:(\w+)(\(.+\)[*+]?)?(\?)?)+/g;
889
+ const routeParamExtractRegxp = /(:(\w+)(\(.*[^(]\)[*+]?)?(\?)?)+/g;
894
890
  function extractParamsFromPathDecl(path) {
895
891
  let params = [];
896
892
  let matches;
@@ -933,7 +929,7 @@ function extractRouteParamsFromPath(path, isIndexFileForRouting, previousParams)
933
929
  return allMergedParams;
934
930
  }
935
931
 
936
- const ExtractRegex = /(^(\/)?([^:/]+)?(:(\w+)(\(.+\)[*+]?)?(\?)?)*([^:/]+)?)+/g;
932
+ const ExtractRegex = /(^(\/)?([^:/]+)?(:(\w+)(\((.*)\)[*+]?)?(\?)?)*([^:/]+)?)+/g;
937
933
  function destructurePath(path, route) {
938
934
  let allPathElements = [];
939
935
  let _path = `${path}`;
@@ -950,7 +946,7 @@ function extractPathElements(partOfPath, route) {
950
946
  let matches;
951
947
  matches = ExtractRegex.exec(partOfPath);
952
948
  if (matches) {
953
- const [_, mtch, slash, path1, paramDef, key, catchAll, optional, path2] = matches;
949
+ const [_, mtch, slash, path1, paramDef, key, catchAll, parentheseContent, optional, path2] = matches;
954
950
  if (mtch) {
955
951
  strippedPath = mtch;
956
952
  const sharedProperties = {
@@ -968,7 +964,7 @@ function extractPathElements(partOfPath, route) {
968
964
  }
969
965
  if (key) {
970
966
  pathElements.push({
971
- type: catchAll ? "catchAll" : optional ? "optionalParam" : "param",
967
+ type: catchAll && parentheseContent ? "catchAll" : optional ? "optionalParam" : "param",
972
968
  content: key,
973
969
  id: nanoid$1(6),
974
970
  ...sharedProperties
@@ -990,7 +986,10 @@ function extractPathElements(partOfPath, route) {
990
986
  function createPathsFiles({ routesPaths }) {
991
987
  const { i18n, i18nOptions } = moduleOptionStore;
992
988
  const hasPrefixStrategy = i18n && i18nOptions?.strategy !== "no_prefix";
993
- const filteredRoutesPaths = routesPaths.filter((route) => !routesPaths.find((r) => `${route.path}/` === r.path)).sort((a, b) => {
989
+ const filteredRoutesPaths = routesPaths.filter((route) => !routesPaths.find((r) => `${route.path}/` === r.path)).map((route) => ({
990
+ ...route,
991
+ path: route.path.replace(/\(\)/g, "")
992
+ })).sort((a, b) => {
994
993
  const pathCountA = a.path.split("/");
995
994
  const pathCountB = b.path.split("/");
996
995
  pathCountA.splice(0, 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
5
5
  "type": "module",
6
6
  "main": "./dist/module.cjs",
@@ -59,20 +59,20 @@
59
59
  "url": "https://github.com/victorgarciaesgi/nuxt-typed-router/issues"
60
60
  },
61
61
  "dependencies": {
62
- "@nuxt/kit": "^3.3.2",
62
+ "@nuxt/kit": "^3.4.1",
63
63
  "chalk": "^5.2.0",
64
64
  "defu": "^6.1.2",
65
65
  "lodash-es": "^4.17.21",
66
66
  "log-symbols": "^5.1.0",
67
- "mkdirp": "^2.1.6",
67
+ "mkdirp": "^3.0.0",
68
68
  "nanoid": "^4.0.2",
69
69
  "pathe": "1.1.0",
70
70
  "prettier": "2.8.7"
71
71
  },
72
72
  "devDependencies": {
73
- "@nuxt/devtools": "^0.3.1",
74
- "@nuxt/module-builder": "^0.2.1",
75
- "@nuxt/test-utils": "^3.3.2",
73
+ "@nuxt/devtools": "^0.4.0",
74
+ "@nuxt/module-builder": "^0.3.0",
75
+ "@nuxt/test-utils": "^3.4.1",
76
76
  "@nuxt/types": "^2.16.3",
77
77
  "@nuxtjs/eslint-config-typescript": "^12.0.0",
78
78
  "@nuxtjs/i18n": "8.0.0-beta.9",
@@ -80,21 +80,21 @@
80
80
  "@types/lodash-es": "^4.17.7",
81
81
  "@types/node": "^18.15.11",
82
82
  "@types/prettier": "^2.7.2",
83
- "@typescript-eslint/eslint-plugin": "^5.57.0",
84
- "@typescript-eslint/parser": "^5.57.0",
83
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
84
+ "@typescript-eslint/parser": "^5.58.0",
85
85
  "@vue/test-utils": "^2.3.2",
86
86
  "bumpp": "9.1.0",
87
87
  "changelogithub": "0.12.7",
88
88
  "cross-env": "^7.0.3",
89
- "eslint": "8.37.0",
89
+ "eslint": "8.38.0",
90
90
  "eslint-config-prettier": "^8.8.0",
91
91
  "eslint-plugin-vue": "^9.10.0",
92
- "nuxt": "3.3.2",
93
- "nuxt-seo-kit": "1.3.5",
94
- "playwright": "1.32.1",
92
+ "nuxt": "3.4.1",
93
+ "nuxt-seo-kit": "1.3.6",
94
+ "playwright": "1.32.3",
95
95
  "tsd": "^0.28.1",
96
- "typescript": "^5.0.3",
97
- "vitest": "^0.29.8",
96
+ "typescript": "^5.0.4",
97
+ "vitest": "^0.30.1",
98
98
  "vue-eslint-parser": "^9.1.1",
99
99
  "vue-router": "^4.1.6",
100
100
  "vue-tsc": "^1.1.7"