nuxt-typed-router 3.0.2 → 3.0.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/dist/module.json +1 -1
- package/dist/module.mjs +27 -10
- package/package.json +10 -11
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -20,6 +20,7 @@ class ModuleOptionsStore {
|
|
|
20
20
|
this.rootDir = "";
|
|
21
21
|
this.i18n = false;
|
|
22
22
|
this.i18nOptions = null;
|
|
23
|
+
this.i18nLocales = [];
|
|
23
24
|
}
|
|
24
25
|
updateOptions(options) {
|
|
25
26
|
if (options.plugin != null)
|
|
@@ -32,10 +33,21 @@ class ModuleOptionsStore {
|
|
|
32
33
|
this.rootDir = options.rootDir;
|
|
33
34
|
if (options.i18n != null)
|
|
34
35
|
this.i18n = options.i18n;
|
|
35
|
-
if (options.i18nOptions != null)
|
|
36
|
+
if (options.i18nOptions != null) {
|
|
36
37
|
this.i18nOptions = options.i18nOptions;
|
|
37
|
-
|
|
38
|
+
if (options.i18nOptions.locales) {
|
|
39
|
+
this.i18nLocales = options.i18nOptions.locales.map((l) => {
|
|
40
|
+
if (typeof l === "string") {
|
|
41
|
+
return l;
|
|
42
|
+
} else {
|
|
43
|
+
return l.code;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (options.experimentalPathCheck != null) {
|
|
38
49
|
this.experimentalPathCheck = options.experimentalPathCheck;
|
|
50
|
+
}
|
|
39
51
|
}
|
|
40
52
|
getResolvedStrictOptions() {
|
|
41
53
|
let resolved;
|
|
@@ -223,12 +235,12 @@ function createTypeValidatePathCondition(elements) {
|
|
|
223
235
|
const typeName = `Validate${nanoid(7)}`;
|
|
224
236
|
const params = /* @__PURE__ */ new Map();
|
|
225
237
|
const routeName = elements.flat()[0].routeName;
|
|
226
|
-
|
|
238
|
+
elements.flat().every((elem) => elem.type === "name");
|
|
227
239
|
const isLocale = elements.flat()[0].isLocale;
|
|
228
240
|
const condition = `type ${typeName}<T> = T extends \`/${elements.map((elementArray, index) => {
|
|
229
241
|
return elementArray.map((elem) => {
|
|
230
242
|
const isLast = index === elements.flat().length - 1;
|
|
231
|
-
if (elem.type === "name" && isLast
|
|
243
|
+
if (elem.type === "name" && isLast) {
|
|
232
244
|
const id = nanoid(6);
|
|
233
245
|
params.set(elem.id, id);
|
|
234
246
|
return `${elem.content}\${infer ${id}}`;
|
|
@@ -243,7 +255,7 @@ function createTypeValidatePathCondition(elements) {
|
|
|
243
255
|
}
|
|
244
256
|
}).join("");
|
|
245
257
|
}).join("/")}\`
|
|
246
|
-
? ${
|
|
258
|
+
? ${elements.flat().map((elem, index) => {
|
|
247
259
|
let output = "";
|
|
248
260
|
const isLast = index === elements.flat().length - 1;
|
|
249
261
|
const isName = elem.type === "name";
|
|
@@ -785,7 +797,7 @@ function createTypeUtilsRuntimeFile() {
|
|
|
785
797
|
|
|
786
798
|
function createi18nRouterFile() {
|
|
787
799
|
const { router } = moduleOptionStore.getResolvedStrictOptions();
|
|
788
|
-
const { i18nOptions, experimentalPathCheck } = moduleOptionStore;
|
|
800
|
+
const { i18nOptions, experimentalPathCheck, i18nLocales } = moduleOptionStore;
|
|
789
801
|
return (
|
|
790
802
|
/* typescript */
|
|
791
803
|
`
|
|
@@ -798,7 +810,7 @@ function createi18nRouterFile() {
|
|
|
798
810
|
`import type {TypedLocalePathParameter, RouteNameFromLocalePath} from './__paths';`
|
|
799
811
|
)}
|
|
800
812
|
|
|
801
|
-
export type I18nLocales = ${
|
|
813
|
+
export type I18nLocales = ${i18nLocales?.length ? i18nLocales.map((loc) => `"${loc}"`).join("|") : "string"};
|
|
802
814
|
|
|
803
815
|
export interface TypedToLocalePath {
|
|
804
816
|
<T extends RoutesNamesList, P extends string>(
|
|
@@ -1396,11 +1408,16 @@ function extractChunkMain(chunkName) {
|
|
|
1396
1408
|
}
|
|
1397
1409
|
|
|
1398
1410
|
function hasi18nSibling(source, route) {
|
|
1399
|
-
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1411
|
+
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1400
1412
|
if (i18n && i18nOptions?.strategy !== "no_prefix") {
|
|
1401
1413
|
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1402
1414
|
return source.some((rt) => {
|
|
1403
|
-
return route.name?.match(new RegExp(`^(${rt.name})${separator}[a-zA-Z]+`, "g")) || rt.path !== "/" && route.path?.match(
|
|
1415
|
+
return route.name?.match(new RegExp(`^(${rt.name})${separator}[a-zA-Z]+`, "g")) || rt.path !== "/" && route.path?.match(
|
|
1416
|
+
new RegExp(
|
|
1417
|
+
`/?[${i18nLocales?.map((m) => m.replace(/[^a-zA-Z0-9_]/gm, "\\$&")).join("|")}]${rt.path}`,
|
|
1418
|
+
"g"
|
|
1419
|
+
)
|
|
1420
|
+
);
|
|
1404
1421
|
});
|
|
1405
1422
|
}
|
|
1406
1423
|
return false;
|
|
@@ -1531,7 +1548,7 @@ function constructRouteMap(routesConfig) {
|
|
|
1531
1548
|
});
|
|
1532
1549
|
return output;
|
|
1533
1550
|
} catch (e) {
|
|
1534
|
-
throw new Error(
|
|
1551
|
+
throw new Error(`Generation failed: ${e}`);
|
|
1535
1552
|
}
|
|
1536
1553
|
}
|
|
1537
1554
|
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.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",
|
|
@@ -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"
|