nuxt-typed-router 3.0.4 → 3.0.5
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 +25 -33
- package/package.json +1 -1
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);
|
|
@@ -1392,29 +1384,28 @@ async function saveGeneratedFiles({ outputData }) {
|
|
|
1392
1384
|
|
|
1393
1385
|
function extractUnMatchingSiblings(mainRoute, siblingRoutes) {
|
|
1394
1386
|
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;
|
|
1387
|
+
return s.name !== mainRoute.name;
|
|
1403
1388
|
});
|
|
1404
1389
|
}
|
|
1405
|
-
function extractChunkMain(chunkName) {
|
|
1406
|
-
let chunkArray = chunkName?.split("/");
|
|
1407
|
-
return chunkArray?.join("/");
|
|
1408
|
-
}
|
|
1409
1390
|
|
|
1410
|
-
|
|
1391
|
+
const specialCharacterRegxp = /([^a-zA-Z0-9_])/gm;
|
|
1392
|
+
function is18Sibling(source, route) {
|
|
1411
1393
|
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1412
1394
|
if (i18n && i18nOptions?.strategy !== "no_prefix") {
|
|
1413
1395
|
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1396
|
+
const i18LocalesRecognizer = i18nLocales?.map((m) => m.replace(specialCharacterRegxp, "\\$&")).join("|");
|
|
1414
1397
|
return source.some((rt) => {
|
|
1415
|
-
return route.name?.match(
|
|
1398
|
+
return route.name?.match(
|
|
1416
1399
|
new RegExp(
|
|
1417
|
-
|
|
1400
|
+
`^(${rt.name?.replace(
|
|
1401
|
+
specialCharacterRegxp,
|
|
1402
|
+
"\\$&"
|
|
1403
|
+
)})${separator}(${i18LocalesRecognizer})`,
|
|
1404
|
+
"g"
|
|
1405
|
+
)
|
|
1406
|
+
) || route.path?.match(
|
|
1407
|
+
new RegExp(
|
|
1408
|
+
`/?(${i18LocalesRecognizer})${rt.path.replace(specialCharacterRegxp, "\\$&")}${rt.path === "/" ? "?" : ""}`,
|
|
1418
1409
|
"g"
|
|
1419
1410
|
)
|
|
1420
1411
|
);
|
|
@@ -1423,12 +1414,13 @@ function hasi18nSibling(source, route) {
|
|
|
1423
1414
|
return false;
|
|
1424
1415
|
}
|
|
1425
1416
|
function modifyRoutePrefixDefaultIfI18n(route) {
|
|
1426
|
-
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1417
|
+
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1427
1418
|
if (i18n && route.name) {
|
|
1428
1419
|
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1420
|
+
const i18LocalesRecognizer = i18nLocales?.map((m) => m.replace(specialCharacterRegxp, "\\$&")).join("|");
|
|
1429
1421
|
if (i18nOptions?.strategy === "prefix_and_default") {
|
|
1430
1422
|
const routeDefaultRegXp = new RegExp(
|
|
1431
|
-
`([a-zA-Z-]+)${separator}
|
|
1423
|
+
`([a-zA-Z-]+)${separator}(${i18LocalesRecognizer})${separator}default`,
|
|
1432
1424
|
"g"
|
|
1433
1425
|
);
|
|
1434
1426
|
const match = routeDefaultRegXp.exec(route.name);
|
|
@@ -1437,7 +1429,7 @@ function modifyRoutePrefixDefaultIfI18n(route) {
|
|
|
1437
1429
|
route.name = routeName;
|
|
1438
1430
|
}
|
|
1439
1431
|
} else if (i18nOptions?.strategy === "prefix_except_default") {
|
|
1440
|
-
|
|
1432
|
+
let defaultLocale = i18nLocales.find((f) => f === i18nOptions.defaultLocale) ? i18nOptions.defaultLocale?.replace(specialCharacterRegxp, "\\$&") : "";
|
|
1441
1433
|
const routeDefaultNameRegXp = new RegExp(`^([a-zA-Z-]+)${separator}${defaultLocale}`, "g");
|
|
1442
1434
|
const match = routeDefaultNameRegXp.exec(route.name);
|
|
1443
1435
|
if (match) {
|
|
@@ -1479,7 +1471,7 @@ function walkThoughRoutes({
|
|
|
1479
1471
|
}) {
|
|
1480
1472
|
modifyRoutePrefixDefaultIfI18n(route);
|
|
1481
1473
|
const newPath = `${parent?.path ?? ""}${route.path.startsWith("/") ? route.path : `/${route.path}`}`;
|
|
1482
|
-
const isLocaleRoute = isLocale ||
|
|
1474
|
+
const isLocaleRoute = isLocale || is18Sibling(output.routesPaths, route);
|
|
1483
1475
|
output.routesPaths.push({
|
|
1484
1476
|
name: route.name,
|
|
1485
1477
|
path: newPath,
|