nuxt-typed-router 3.0.1 → 3.0.3
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/README.md +3 -3
- package/dist/module.json +1 -1
- package/dist/module.mjs +52 -29
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -89,10 +89,10 @@ export default defineNuxtConfig({
|
|
|
89
89
|
|
|
90
90
|
# Roadmap
|
|
91
91
|
|
|
92
|
-
- [
|
|
93
|
-
- [
|
|
94
|
-
- [ ] Add support for `validate` in `definePageMeta`
|
|
92
|
+
- [x] Add `path` autocomplete with TS string templates
|
|
93
|
+
- [x] Add support for `validate` and `redirect` in `definePageMeta`
|
|
95
94
|
- [x] Add `strict` option to prevent path navigation
|
|
95
|
+
- [ ] Enforce strong params typing depending of origin route
|
|
96
96
|
|
|
97
97
|
|
|
98
98
|
## Development
|
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;
|
|
@@ -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>(
|
|
@@ -1395,6 +1407,42 @@ function extractChunkMain(chunkName) {
|
|
|
1395
1407
|
return chunkArray?.join("/");
|
|
1396
1408
|
}
|
|
1397
1409
|
|
|
1410
|
+
function hasi18nSibling(source, route) {
|
|
1411
|
+
const { i18n, i18nOptions, i18nLocales } = moduleOptionStore;
|
|
1412
|
+
if (i18n && i18nOptions?.strategy !== "no_prefix") {
|
|
1413
|
+
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1414
|
+
return source.some((rt) => {
|
|
1415
|
+
return route.name?.match(new RegExp(`^(${rt.name})${separator}[a-zA-Z]+`, "g")) || rt.path !== "/" && route.path?.match(new RegExp(`/?[${i18nLocales?.join("|")}]${rt.path}`, "g"));
|
|
1416
|
+
});
|
|
1417
|
+
}
|
|
1418
|
+
return false;
|
|
1419
|
+
}
|
|
1420
|
+
function modifyRoutePrefixDefaultIfI18n(route) {
|
|
1421
|
+
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1422
|
+
if (i18n && route.name) {
|
|
1423
|
+
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1424
|
+
if (i18nOptions?.strategy === "prefix_and_default") {
|
|
1425
|
+
const routeDefaultRegXp = new RegExp(
|
|
1426
|
+
`([a-zA-Z-]+)${separator}[a-zA-Z]+${separator}default`,
|
|
1427
|
+
"g"
|
|
1428
|
+
);
|
|
1429
|
+
const match = routeDefaultRegXp.exec(route.name);
|
|
1430
|
+
if (match) {
|
|
1431
|
+
const [_, routeName] = match;
|
|
1432
|
+
route.name = routeName;
|
|
1433
|
+
}
|
|
1434
|
+
} else if (i18nOptions?.strategy === "prefix_except_default") {
|
|
1435
|
+
const defaultLocale = i18nOptions.defaultLocale;
|
|
1436
|
+
const routeDefaultNameRegXp = new RegExp(`^([a-zA-Z-]+)${separator}${defaultLocale}`, "g");
|
|
1437
|
+
const match = routeDefaultNameRegXp.exec(route.name);
|
|
1438
|
+
if (match) {
|
|
1439
|
+
const [_, routeName] = match;
|
|
1440
|
+
route.name = routeName;
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1398
1446
|
function createKeyedName(route, parent) {
|
|
1399
1447
|
const splittedPaths = route.path.split("/");
|
|
1400
1448
|
const parentPath = splittedPaths[splittedPaths.length - 1];
|
|
@@ -1414,31 +1462,6 @@ function createNameKeyFromFullName(route, level, parentName) {
|
|
|
1414
1462
|
const keyName = route.path === "" ? "index" : camelCase(splitted.join("-")) || "index";
|
|
1415
1463
|
return keyName;
|
|
1416
1464
|
}
|
|
1417
|
-
function hasi18nSibling(source, route) {
|
|
1418
|
-
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1419
|
-
if (i18n) {
|
|
1420
|
-
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1421
|
-
return source.some((rt) => {
|
|
1422
|
-
return route.name?.match(new RegExp(`^(${rt.name})${separator}[a-zA-Z]+`, "g")) || rt.path !== "/" && route.path?.match(new RegExp(`/?[a-zA-Z]+${rt.path}`, "g"));
|
|
1423
|
-
});
|
|
1424
|
-
}
|
|
1425
|
-
return false;
|
|
1426
|
-
}
|
|
1427
|
-
function modifyRoutePrefixDefaultIfI18n(route) {
|
|
1428
|
-
const { i18n, i18nOptions } = moduleOptionStore;
|
|
1429
|
-
if (i18n && route.name && i18nOptions?.strategy === "prefix_and_default") {
|
|
1430
|
-
const separator = i18nOptions?.routesNameSeparator ?? "___";
|
|
1431
|
-
const routeDefaultRegXp = new RegExp(
|
|
1432
|
-
`([a-zA-Z-]+)${separator}[a-zA-Z]+${separator}default`,
|
|
1433
|
-
"g"
|
|
1434
|
-
);
|
|
1435
|
-
const match = routeDefaultRegXp.exec(route.name);
|
|
1436
|
-
if (match) {
|
|
1437
|
-
const [_, routeName] = match;
|
|
1438
|
-
route.name = routeName;
|
|
1439
|
-
}
|
|
1440
|
-
}
|
|
1441
|
-
}
|
|
1442
1465
|
function walkThoughRoutes({
|
|
1443
1466
|
route,
|
|
1444
1467
|
level,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-typed-router",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.3",
|
|
4
4
|
"description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"prepack": "nuxt-module-build",
|
|
20
20
|
"dev": "nuxi dev playground",
|
|
21
21
|
"dev:build": "nuxi build playground",
|
|
22
|
+
"prepare:playground": "nuxi prepare playground",
|
|
22
23
|
"dev:prepare": "nuxt-module-build --stub && nuxi prepare playground && pnpm run test:prepare-fixtures",
|
|
23
24
|
"build:test": "cross-env NUXT_BUILD_TYPE=stub pnpm run prepack && pnpm run dev:build",
|
|
24
25
|
"test:prepare-fixtures": "nuxi prepare test/fixtures/simple && nuxi prepare test/fixtures/withOptions && nuxi prepare test/fixtures/complex",
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
"docs:dev": "cd docs && pnpm run dev",
|
|
31
32
|
"docs:build": "npm run dev:prepare && cd docs && nuxi generate",
|
|
32
33
|
"typecheck": "tsc --noEmit",
|
|
33
|
-
"release": "
|
|
34
|
+
"release": "bumpp && npm publish && git push --follow-tags"
|
|
34
35
|
},
|
|
35
36
|
"publishConfig": {
|
|
36
37
|
"access": "public"
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
"prettier": "2.8.4"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
|
-
"@nuxt/devtools": "^0.
|
|
74
|
+
"@nuxt/devtools": "^0.2.4",
|
|
74
75
|
"@nuxt/module-builder": "^0.2.1",
|
|
75
76
|
"@nuxt/test-utils": "^3.2.2",
|
|
76
77
|
"@nuxt/types": "^2.16.0",
|
|
@@ -84,16 +85,17 @@
|
|
|
84
85
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
85
86
|
"@typescript-eslint/parser": "^5.53.0",
|
|
86
87
|
"@vue/test-utils": "^2.3.0",
|
|
88
|
+
"bumpp": "9.0.0",
|
|
89
|
+
"changelogithub": "0.12.7",
|
|
87
90
|
"cross-env": "^7.0.3",
|
|
88
|
-
"eslint": "8.
|
|
91
|
+
"eslint": "8.35.0",
|
|
89
92
|
"eslint-config-prettier": "^8.6.0",
|
|
90
93
|
"eslint-plugin-vue": "^9.9.0",
|
|
91
|
-
"nuxt": "3.2.
|
|
92
|
-
"playwright": "1.31.
|
|
93
|
-
"standard-version": "^9.5.0",
|
|
94
|
+
"nuxt": "3.2.3",
|
|
95
|
+
"playwright": "1.31.1",
|
|
94
96
|
"tsd": "^0.25.0",
|
|
95
97
|
"typescript": "^4.9.5",
|
|
96
|
-
"vitest": "^0.
|
|
98
|
+
"vitest": "^0.29.1",
|
|
97
99
|
"vue-eslint-parser": "^9.1.0",
|
|
98
100
|
"vue-router": "^4.1.6",
|
|
99
101
|
"vue-tsc": "^1.1.7"
|