nuxt-typed-router 3.1.2 → 3.1.4-beta.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/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "3.1.2"
8
+ "version": "3.1.4-beta.0"
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
 
@@ -662,7 +657,8 @@ function createIndexFile() {
662
657
  )}
663
658
  ${returnIfTrue(
664
659
  i18n,
665
- `export {useLocalePath, useLocaleRoute, TypedToLocalePath, TypedLocaleRoute} from './__i18n-router';`
660
+ `export {useLocalePath, useLocaleRoute} from './__i18n-router';
661
+ export type {TypedToLocalePath, TypedLocaleRoute} from './__i18n-router';`
666
662
  )}
667
663
 
668
664
 
@@ -794,7 +790,7 @@ function createNavigateToFile() {
794
790
 
795
791
  interface NavigateToFunction {
796
792
  <T extends RoutesNamesList, P extends string, E extends boolean = false>(
797
- to: TypedRouteLocationRawFromName<T, P, E>,
793
+ to: TypedRouteLocationRawFromName<T, P>,
798
794
  options?: TypedNavigateToOptions<E>
799
795
  ) : Promise<void | NavigationFailure | TypedRouteFromName<T>>
800
796
  ${returnIfTrue(
@@ -838,6 +834,7 @@ function createTypeUtilsRuntimeFile() {
838
834
  function createi18nRouterFile() {
839
835
  const { router } = moduleOptionStore.getResolvedStrictOptions();
840
836
  const { i18nOptions, pathCheck, i18nLocales } = moduleOptionStore;
837
+ const LocalePathType = i18nOptions?.strategy === "no_prefix" ? "TypedPathParameter" : "TypedLocalePathParameter";
841
838
  return (
842
839
  /* typescript */
843
840
  `
@@ -847,7 +844,7 @@ function createi18nRouterFile() {
847
844
  import type {RoutesNamesList} from './__routes';
848
845
  ${returnIfTrue(
849
846
  pathCheck,
850
- `import type {TypedLocalePathParameter, RouteNameFromLocalePath} from './__paths';`
847
+ `import type {TypedLocalePathParameter, TypedPathParameter, RouteNameFromLocalePath} from './__paths';`
851
848
  )}
852
849
 
853
850
  export type I18nLocales = ${i18nLocales?.length ? i18nLocales.map((loc) => `"${loc}"`).join("|") : "string"};
@@ -862,7 +859,7 @@ function createi18nRouterFile() {
862
859
  ${returnIfTrue(
863
860
  pathCheck && !router.strictToArgument,
864
861
  `<T extends string>(
865
- to: TypedLocalePathParameter<T>,
862
+ to: ${LocalePathType}<T>,
866
863
  locale?: I18nLocales | undefined
867
864
  ) : [T] extends [never] ? string : Required<TypedRouteLocationRawFromName<RouteNameFromLocalePath<T>, T>>;`
868
865
  )}
@@ -876,7 +873,7 @@ function createi18nRouterFile() {
876
873
  <T extends RoutesNamesList, P extends string>(to: TypedRouteLocationRawFromName<T, P>, locale?: I18nLocales | undefined) : TypedRouteFromName<T>
877
874
  ${returnIfTrue(
878
875
  pathCheck && !router.strictToArgument,
879
- ` <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>>;`
880
877
  )}
881
878
  }
882
879
 
@@ -889,7 +886,7 @@ function createi18nRouterFile() {
889
886
  );
890
887
  }
891
888
 
892
- const routeParamExtractRegxp = /(:(\w+)(\(.+\)[*+]?)?(\?)?)+/g;
889
+ const routeParamExtractRegxp = /(:(\w+)(\(.*[^(]\)[*+]?)?(\?)?)+/g;
893
890
  function extractParamsFromPathDecl(path) {
894
891
  let params = [];
895
892
  let matches;
@@ -932,7 +929,7 @@ function extractRouteParamsFromPath(path, isIndexFileForRouting, previousParams)
932
929
  return allMergedParams;
933
930
  }
934
931
 
935
- const ExtractRegex = /(^(\/)?([^:/]+)?(:(\w+)(\(.+\)[*+]?)?(\?)?)*([^:/]+)?)+/g;
932
+ const ExtractRegex = /(^(\/)?([^:/]+)?(:(\w+)(\((.*)\)[*+]?)?(\?)?)*([^:/]+)?)+/g;
936
933
  function destructurePath(path, route) {
937
934
  let allPathElements = [];
938
935
  let _path = `${path}`;
@@ -949,7 +946,7 @@ function extractPathElements(partOfPath, route) {
949
946
  let matches;
950
947
  matches = ExtractRegex.exec(partOfPath);
951
948
  if (matches) {
952
- const [_, mtch, slash, path1, paramDef, key, catchAll, optional, path2] = matches;
949
+ const [_, mtch, slash, path1, paramDef, key, catchAll, parentheseContent, optional, path2] = matches;
953
950
  if (mtch) {
954
951
  strippedPath = mtch;
955
952
  const sharedProperties = {
@@ -967,7 +964,7 @@ function extractPathElements(partOfPath, route) {
967
964
  }
968
965
  if (key) {
969
966
  pathElements.push({
970
- type: catchAll ? "catchAll" : optional ? "optionalParam" : "param",
967
+ type: catchAll && parentheseContent ? "catchAll" : optional ? "optionalParam" : "param",
971
968
  content: key,
972
969
  id: nanoid$1(6),
973
970
  ...sharedProperties
@@ -989,7 +986,10 @@ function extractPathElements(partOfPath, route) {
989
986
  function createPathsFiles({ routesPaths }) {
990
987
  const { i18n, i18nOptions } = moduleOptionStore;
991
988
  const hasPrefixStrategy = i18n && i18nOptions?.strategy !== "no_prefix";
992
- 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) => {
993
993
  const pathCountA = a.path.split("/");
994
994
  const pathCountB = b.path.split("/");
995
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.2",
3
+ "version": "3.1.4-beta.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",
@@ -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"