nuxt-typed-router 3.0.3 → 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 +33 -36
- package/package.json +10 -11
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -235,12 +235,12 @@ function createTypeValidatePathCondition(elements) {
|
|
|
235
235
|
const typeName = `Validate${nanoid(7)}`;
|
|
236
236
|
const params = /* @__PURE__ */ new Map();
|
|
237
237
|
const routeName = elements.flat()[0].routeName;
|
|
238
|
-
|
|
238
|
+
elements.flat().every((elem) => elem.type === "name");
|
|
239
239
|
const isLocale = elements.flat()[0].isLocale;
|
|
240
240
|
const condition = `type ${typeName}<T> = T extends \`/${elements.map((elementArray, index) => {
|
|
241
241
|
return elementArray.map((elem) => {
|
|
242
242
|
const isLast = index === elements.flat().length - 1;
|
|
243
|
-
if (elem.type === "name" && isLast
|
|
243
|
+
if (elem.type === "name" && isLast) {
|
|
244
244
|
const id = nanoid(6);
|
|
245
245
|
params.set(elem.id, id);
|
|
246
246
|
return `${elem.content}\${infer ${id}}`;
|
|
@@ -255,7 +255,7 @@ function createTypeValidatePathCondition(elements) {
|
|
|
255
255
|
}
|
|
256
256
|
}).join("");
|
|
257
257
|
}).join("/")}\`
|
|
258
|
-
? ${
|
|
258
|
+
? ${elements.flat().map((elem, index) => {
|
|
259
259
|
let output = "";
|
|
260
260
|
const isLast = index === elements.flat().length - 1;
|
|
261
261
|
const isName = elem.type === "name";
|
|
@@ -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,38 +1384,43 @@ 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(
|
|
1399
|
+
new RegExp(
|
|
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 === "/" ? "?" : ""}`,
|
|
1409
|
+
"g"
|
|
1410
|
+
)
|
|
1411
|
+
);
|
|
1416
1412
|
});
|
|
1417
1413
|
}
|
|
1418
1414
|
return false;
|
|
1419
1415
|
}
|
|
1420
1416
|
function modifyRoutePrefixDefaultIfI18n(route) {
|
|
1421
|
-
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1417
|
+
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1422
1418
|
if (i18n && route.name) {
|
|
1423
1419
|
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1420
|
+
const i18LocalesRecognizer = i18nLocales?.map((m) => m.replace(specialCharacterRegxp, "\\$&")).join("|");
|
|
1424
1421
|
if (i18nOptions?.strategy === "prefix_and_default") {
|
|
1425
1422
|
const routeDefaultRegXp = new RegExp(
|
|
1426
|
-
`([a-zA-Z-]+)${separator}
|
|
1423
|
+
`([a-zA-Z-]+)${separator}(${i18LocalesRecognizer})${separator}default`,
|
|
1427
1424
|
"g"
|
|
1428
1425
|
);
|
|
1429
1426
|
const match = routeDefaultRegXp.exec(route.name);
|
|
@@ -1432,7 +1429,7 @@ function modifyRoutePrefixDefaultIfI18n(route) {
|
|
|
1432
1429
|
route.name = routeName;
|
|
1433
1430
|
}
|
|
1434
1431
|
} else if (i18nOptions?.strategy === "prefix_except_default") {
|
|
1435
|
-
|
|
1432
|
+
let defaultLocale = i18nLocales.find((f) => f === i18nOptions.defaultLocale) ? i18nOptions.defaultLocale?.replace(specialCharacterRegxp, "\\$&") : "";
|
|
1436
1433
|
const routeDefaultNameRegXp = new RegExp(`^([a-zA-Z-]+)${separator}${defaultLocale}`, "g");
|
|
1437
1434
|
const match = routeDefaultNameRegXp.exec(route.name);
|
|
1438
1435
|
if (match) {
|
|
@@ -1474,7 +1471,7 @@ function walkThoughRoutes({
|
|
|
1474
1471
|
}) {
|
|
1475
1472
|
modifyRoutePrefixDefaultIfI18n(route);
|
|
1476
1473
|
const newPath = `${parent?.path ?? ""}${route.path.startsWith("/") ? route.path : `/${route.path}`}`;
|
|
1477
|
-
const isLocaleRoute = isLocale ||
|
|
1474
|
+
const isLocaleRoute = isLocale || is18Sibling(output.routesPaths, route);
|
|
1478
1475
|
output.routesPaths.push({
|
|
1479
1476
|
name: route.name,
|
|
1480
1477
|
path: newPath,
|
|
@@ -1543,7 +1540,7 @@ function constructRouteMap(routesConfig) {
|
|
|
1543
1540
|
});
|
|
1544
1541
|
return output;
|
|
1545
1542
|
} catch (e) {
|
|
1546
|
-
throw new Error(
|
|
1543
|
+
throw new Error(`Generation failed: ${e}`);
|
|
1547
1544
|
}
|
|
1548
1545
|
}
|
|
1549
1546
|
function startGenerator({ output, routesConfig }) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-typed-router",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.5",
|
|
4
4
|
"description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -65,13 +65,13 @@
|
|
|
65
65
|
"defu": "^6.1.2",
|
|
66
66
|
"lodash-es": "^4.17.21",
|
|
67
67
|
"log-symbols": "^5.1.0",
|
|
68
|
-
"mkdirp": "^2.1.
|
|
68
|
+
"mkdirp": "^2.1.5",
|
|
69
69
|
"nanoid": "^4.0.1",
|
|
70
70
|
"pathe": "1.1.0",
|
|
71
71
|
"prettier": "2.8.4"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@nuxt/devtools": "^0.2.
|
|
74
|
+
"@nuxt/devtools": "^0.2.5",
|
|
75
75
|
"@nuxt/module-builder": "^0.2.1",
|
|
76
76
|
"@nuxt/test-utils": "^3.2.2",
|
|
77
77
|
"@nuxt/types": "^2.16.0",
|
|
@@ -79,23 +79,22 @@
|
|
|
79
79
|
"@nuxtjs/i18n": "8.0.0-beta.9",
|
|
80
80
|
"@nuxtjs/web-vitals": "^0.2.2",
|
|
81
81
|
"@types/lodash-es": "^4.17.6",
|
|
82
|
-
"@types/
|
|
83
|
-
"@types/node": "^18.14.0",
|
|
82
|
+
"@types/node": "^18.14.6",
|
|
84
83
|
"@types/prettier": "^2.7.2",
|
|
85
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
86
|
-
"@typescript-eslint/parser": "^5.
|
|
84
|
+
"@typescript-eslint/eslint-plugin": "^5.54.1",
|
|
85
|
+
"@typescript-eslint/parser": "^5.54.1",
|
|
87
86
|
"@vue/test-utils": "^2.3.0",
|
|
88
87
|
"bumpp": "9.0.0",
|
|
89
88
|
"changelogithub": "0.12.7",
|
|
90
89
|
"cross-env": "^7.0.3",
|
|
91
90
|
"eslint": "8.35.0",
|
|
92
|
-
"eslint-config-prettier": "^8.
|
|
91
|
+
"eslint-config-prettier": "^8.7.0",
|
|
93
92
|
"eslint-plugin-vue": "^9.9.0",
|
|
94
93
|
"nuxt": "3.2.3",
|
|
95
|
-
"playwright": "1.31.
|
|
96
|
-
"tsd": "^0.
|
|
94
|
+
"playwright": "1.31.2",
|
|
95
|
+
"tsd": "^0.26.0",
|
|
97
96
|
"typescript": "^4.9.5",
|
|
98
|
-
"vitest": "^0.29.
|
|
97
|
+
"vitest": "^0.29.2",
|
|
99
98
|
"vue-eslint-parser": "^9.1.0",
|
|
100
99
|
"vue-router": "^4.1.6",
|
|
101
100
|
"vue-tsc": "^1.1.7"
|