nuxt-typed-router 3.0.4 → 3.0.6
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 +27 -33
- package/package.json +3 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -290,25 +290,19 @@ function createRoutesTypesFile({
|
|
|
290
290
|
routesParams,
|
|
291
291
|
routesPaths
|
|
292
292
|
}) {
|
|
293
|
-
const filteredRoutesList = routesList.filter(
|
|
294
|
-
(routeName, index) => routesList.indexOf(routeName) === index
|
|
295
|
-
);
|
|
296
|
-
const filteredRoutesParams = routesParams.filter(
|
|
297
|
-
(route, index) => routesParams.findIndex((r) => route.name === r.name) === index
|
|
298
|
-
);
|
|
299
293
|
return (
|
|
300
294
|
/* typescript */
|
|
301
295
|
`
|
|
302
|
-
${createRoutesNamesListExport(
|
|
296
|
+
${createRoutesNamesListExport(routesList)}
|
|
303
297
|
export type WithoutBracket<T extends string> = T extends \`:\${string}\` ? never : T;
|
|
304
298
|
|
|
305
|
-
${createRoutesParamsRecordExport(
|
|
299
|
+
${createRoutesParamsRecordExport(routesParams)}
|
|
306
300
|
|
|
307
|
-
${createRoutesParamsRecordResolvedExport(
|
|
301
|
+
${createRoutesParamsRecordResolvedExport(routesParams)}
|
|
308
302
|
|
|
309
|
-
${createRoutesNamedLocationsExport(
|
|
303
|
+
${createRoutesNamedLocationsExport(routesParams)}
|
|
310
304
|
|
|
311
|
-
${createRoutesNamedLocationsResolvedExport(
|
|
305
|
+
${createRoutesNamedLocationsResolvedExport(routesParams)}
|
|
312
306
|
|
|
313
307
|
export type RoutesNamesListRecord = ${routesDeclTemplate};
|
|
314
308
|
|
|
@@ -949,9 +943,7 @@ function extractPathElements(partOfPath, route) {
|
|
|
949
943
|
function createPathsFiles({ routesPaths }) {
|
|
950
944
|
const { i18n, i18nOptions } = moduleOptionStore;
|
|
951
945
|
const hasPrefixStrategy = i18n && i18nOptions?.strategy !== "no_prefix";
|
|
952
|
-
const filteredRoutesPaths = routesPaths.filter(
|
|
953
|
-
(route, index) => routesPaths.findIndex((r) => route.name === r.name) === index && !routesPaths.find((r) => `${route.path}/` === r.path)
|
|
954
|
-
).sort((a, b) => {
|
|
946
|
+
const filteredRoutesPaths = routesPaths.filter((route) => !routesPaths.find((r) => `${route.path}/` === r.path)).sort((a, b) => {
|
|
955
947
|
const pathCountA = a.path.split("/");
|
|
956
948
|
const pathCountB = b.path.split("/");
|
|
957
949
|
pathCountA.splice(0, 1);
|
|
@@ -1087,6 +1079,8 @@ function createDefinePageMetaFile() {
|
|
|
1087
1079
|
*/
|
|
1088
1080
|
validate?: (route: [T] extends [never] ? TypedRoute : TypedRouteFromName<T>) => boolean | Promise<boolean> | Partial<NuxtError> | Promise<Partial<NuxtError>>;
|
|
1089
1081
|
key?: false | string | ((route: [T] extends [never] ? TypedRoute : TypedRouteFromName<T>) => string);
|
|
1082
|
+
/** Allow types augmented by other modules */
|
|
1083
|
+
[key: string]: any;
|
|
1090
1084
|
}
|
|
1091
1085
|
|
|
1092
1086
|
|
|
@@ -1392,29 +1386,28 @@ async function saveGeneratedFiles({ outputData }) {
|
|
|
1392
1386
|
|
|
1393
1387
|
function extractUnMatchingSiblings(mainRoute, siblingRoutes) {
|
|
1394
1388
|
return siblingRoutes?.filter((s) => {
|
|
1395
|
-
|
|
1396
|
-
if (chunkName) {
|
|
1397
|
-
const siblingChunkName = extractChunkMain(s.file);
|
|
1398
|
-
if (!siblingChunkName)
|
|
1399
|
-
return false;
|
|
1400
|
-
return chunkName !== siblingChunkName;
|
|
1401
|
-
}
|
|
1402
|
-
return false;
|
|
1389
|
+
return s.name !== mainRoute.name;
|
|
1403
1390
|
});
|
|
1404
1391
|
}
|
|
1405
|
-
function extractChunkMain(chunkName) {
|
|
1406
|
-
let chunkArray = chunkName?.split("/");
|
|
1407
|
-
return chunkArray?.join("/");
|
|
1408
|
-
}
|
|
1409
1392
|
|
|
1410
|
-
|
|
1393
|
+
const specialCharacterRegxp = /([^a-zA-Z0-9_])/gm;
|
|
1394
|
+
function is18Sibling(source, route) {
|
|
1411
1395
|
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1412
1396
|
if (i18n && i18nOptions?.strategy !== "no_prefix") {
|
|
1413
1397
|
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1398
|
+
const i18LocalesRecognizer = i18nLocales?.map((m) => m.replace(specialCharacterRegxp, "\\$&")).join("|");
|
|
1414
1399
|
return source.some((rt) => {
|
|
1415
|
-
return route.name?.match(
|
|
1400
|
+
return route.name?.match(
|
|
1416
1401
|
new RegExp(
|
|
1417
|
-
|
|
1402
|
+
`^(${rt.name?.replace(
|
|
1403
|
+
specialCharacterRegxp,
|
|
1404
|
+
"\\$&"
|
|
1405
|
+
)})${separator}(${i18LocalesRecognizer})`,
|
|
1406
|
+
"g"
|
|
1407
|
+
)
|
|
1408
|
+
) || route.path?.match(
|
|
1409
|
+
new RegExp(
|
|
1410
|
+
`/?(${i18LocalesRecognizer})${rt.path.replace(specialCharacterRegxp, "\\$&")}${rt.path === "/" ? "?" : ""}`,
|
|
1418
1411
|
"g"
|
|
1419
1412
|
)
|
|
1420
1413
|
);
|
|
@@ -1423,12 +1416,13 @@ function hasi18nSibling(source, route) {
|
|
|
1423
1416
|
return false;
|
|
1424
1417
|
}
|
|
1425
1418
|
function modifyRoutePrefixDefaultIfI18n(route) {
|
|
1426
|
-
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1419
|
+
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1427
1420
|
if (i18n && route.name) {
|
|
1428
1421
|
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1422
|
+
const i18LocalesRecognizer = i18nLocales?.map((m) => m.replace(specialCharacterRegxp, "\\$&")).join("|");
|
|
1429
1423
|
if (i18nOptions?.strategy === "prefix_and_default") {
|
|
1430
1424
|
const routeDefaultRegXp = new RegExp(
|
|
1431
|
-
`([a-zA-Z-]+)${separator}
|
|
1425
|
+
`([a-zA-Z-]+)${separator}(${i18LocalesRecognizer})${separator}default`,
|
|
1432
1426
|
"g"
|
|
1433
1427
|
);
|
|
1434
1428
|
const match = routeDefaultRegXp.exec(route.name);
|
|
@@ -1437,7 +1431,7 @@ function modifyRoutePrefixDefaultIfI18n(route) {
|
|
|
1437
1431
|
route.name = routeName;
|
|
1438
1432
|
}
|
|
1439
1433
|
} else if (i18nOptions?.strategy === "prefix_except_default") {
|
|
1440
|
-
|
|
1434
|
+
let defaultLocale = i18nLocales.find((f) => f === i18nOptions.defaultLocale) ? i18nOptions.defaultLocale?.replace(specialCharacterRegxp, "\\$&") : "";
|
|
1441
1435
|
const routeDefaultNameRegXp = new RegExp(`^([a-zA-Z-]+)${separator}${defaultLocale}`, "g");
|
|
1442
1436
|
const match = routeDefaultNameRegXp.exec(route.name);
|
|
1443
1437
|
if (match) {
|
|
@@ -1479,7 +1473,7 @@ function walkThoughRoutes({
|
|
|
1479
1473
|
}) {
|
|
1480
1474
|
modifyRoutePrefixDefaultIfI18n(route);
|
|
1481
1475
|
const newPath = `${parent?.path ?? ""}${route.path.startsWith("/") ? route.path : `/${route.path}`}`;
|
|
1482
|
-
const isLocaleRoute = isLocale ||
|
|
1476
|
+
const isLocaleRoute = isLocale || is18Sibling(output.routesPaths, route);
|
|
1483
1477
|
output.routesPaths.push({
|
|
1484
1478
|
name: route.name,
|
|
1485
1479
|
path: newPath,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-typed-router",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"vitest": "^0.29.2",
|
|
98
98
|
"vue-eslint-parser": "^9.1.0",
|
|
99
99
|
"vue-router": "^4.1.6",
|
|
100
|
-
"vue-tsc": "^1.1.7"
|
|
100
|
+
"vue-tsc": "^1.1.7",
|
|
101
|
+
"nuxt-seo-kit": "1.3.4"
|
|
101
102
|
}
|
|
102
103
|
}
|