nuxt-typed-router 3.2.6 → 3.3.1

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.d.ts CHANGED
@@ -28,6 +28,13 @@ interface ModuleOptions {
28
28
  * @default true
29
29
  */
30
30
  experimentalRemoveNuxtDefs?: boolean;
31
+ /**
32
+ * ⚠️ Experimental
33
+ *
34
+ * Exclude certain routes from being included into the generated types
35
+ * Ex: 404 routes or catchAll routes
36
+ */
37
+ experimentalIgnoreRoutes?: string[];
31
38
  }
32
39
  interface StrictOptions {
33
40
  NuxtLink?: StrictParamsOptions;
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0",
6
6
  "bridge": false
7
7
  },
8
- "version": "3.2.6"
8
+ "version": "3.3.1"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  import { addPluginTemplate, extendPages, createResolver, defineNuxtModule } from '@nuxt/kit';
2
2
  import chalk from 'chalk';
3
3
  import logSymbols from 'log-symbols';
4
+ import path from 'path';
4
5
  import { defu } from 'defu';
5
6
  import { customAlphabet } from 'nanoid/non-secure';
6
7
  import { nanoid as nanoid$1 } from 'nanoid';
@@ -19,9 +20,12 @@ class ModuleOptionsStore {
19
20
  this.autoImport = false;
20
21
  this.rootDir = "";
21
22
  this.buildDir = "";
23
+ this.srcDir = "";
24
+ this.pagesDir = "";
22
25
  this.i18n = false;
23
26
  this.i18nOptions = null;
24
27
  this.i18nLocales = [];
28
+ this.experimentalIgnoreRoutes = [];
25
29
  }
26
30
  updateOptions(options) {
27
31
  if (options.plugin != null)
@@ -32,8 +36,11 @@ class ModuleOptionsStore {
32
36
  this.autoImport = options.autoImport;
33
37
  if (options.rootDir != null)
34
38
  this.rootDir = options.rootDir;
39
+ if (options.srcDir != null)
40
+ this.srcDir = options.srcDir;
35
41
  if (options.buildDir != null)
36
42
  this.buildDir = options.buildDir;
43
+ this.pagesDir = path.join(this.srcDir, "pages");
37
44
  if (options.i18n != null)
38
45
  this.i18n = options.i18n;
39
46
  if (options.i18nOptions != null) {
@@ -53,6 +60,12 @@ class ModuleOptionsStore {
53
60
  if (options.pathCheck != null) {
54
61
  this.pathCheck = options.pathCheck;
55
62
  }
63
+ if (options.experimentalIgnoreRoutes) {
64
+ this.experimentalIgnoreRoutes = options.experimentalIgnoreRoutes;
65
+ }
66
+ }
67
+ get resolvedIgnoredRoutes() {
68
+ return this.experimentalIgnoreRoutes.map((file) => path.join(this.pagesDir, file));
56
69
  }
57
70
  getResolvedStrictOptions() {
58
71
  let resolved;
@@ -1383,7 +1396,7 @@ function modifyRoutePrefixDefaultIfI18n(route) {
1383
1396
  }
1384
1397
  } else if (i18nOptions?.strategy === "prefix_except_default") {
1385
1398
  let defaultLocale = i18nLocales.find((f) => f === i18nOptions.defaultLocale) ? i18nOptions.defaultLocale?.replace(specialCharacterRegxp, "\\$&") : "";
1386
- const routeDefaultNameRegXp = new RegExp(`^([a-zA-Z-]+)${separator}${defaultLocale}`, "g");
1399
+ const routeDefaultNameRegXp = new RegExp(`^([a-zA-Z0-9-]+)${separator}${defaultLocale}`, "g");
1387
1400
  const match = routeDefaultNameRegXp.exec(route.name);
1388
1401
  if (match) {
1389
1402
  const [_, routeName] = match;
@@ -1428,6 +1441,9 @@ function walkThoughRoutes({
1428
1441
  }) {
1429
1442
  const route = modifyRoutePrefixDefaultIfI18n(_route);
1430
1443
  const isLocaleRoute = isLocale || is18Sibling(output.routesPaths, route);
1444
+ if (route.file && moduleOptionStore.resolvedIgnoredRoutes.includes(route.file)) {
1445
+ return;
1446
+ }
1431
1447
  const newPath = `${parent?.path ?? ""}${route.path.startsWith("/") || parent?.path === "/" ? route.path : `/${route.path}`}`;
1432
1448
  if (parent?.path !== "/") {
1433
1449
  output.routesPaths.push({
@@ -1527,8 +1543,9 @@ async function createTypedRouter({
1527
1543
  }) {
1528
1544
  try {
1529
1545
  const rootDir = nuxt.options.rootDir;
1546
+ const srcDir = nuxt.options.srcDir;
1530
1547
  const autoImport = nuxt.options.imports.autoImport ?? true;
1531
- moduleOptionStore.updateOptions({ rootDir, autoImport });
1548
+ moduleOptionStore.updateOptions({ rootDir, autoImport, srcDir });
1532
1549
  if (!isHookCall) {
1533
1550
  if (routesConfig) {
1534
1551
  await nuxt.callHook("pages:extend", routesConfig);
@@ -1626,7 +1643,8 @@ const module = defineNuxtModule({
1626
1643
  plugin: false,
1627
1644
  strict: false,
1628
1645
  pathCheck: true,
1629
- experimentalRemoveNuxtDefs: true
1646
+ experimentalRemoveNuxtDefs: true,
1647
+ experimentalIgnoreRoutes: []
1630
1648
  },
1631
1649
  setup(moduleOptions, nuxt) {
1632
1650
  const { resolve } = createResolver(import.meta.url);
@@ -1672,6 +1690,14 @@ const module = defineNuxtModule({
1672
1690
  });
1673
1691
  }
1674
1692
  });
1693
+ nuxt.hook("build:done", () => {
1694
+ if (moduleOptions.experimentalRemoveNuxtDefs) {
1695
+ removeNuxtDefinitions({
1696
+ autoImport: nuxt.options.imports.autoImport ?? true,
1697
+ buildDir: nuxt.options.buildDir
1698
+ });
1699
+ }
1700
+ });
1675
1701
  if (nuxt.options.dev) {
1676
1702
  nuxt.hook("devtools:customTabs", (tabs) => {
1677
1703
  tabs.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "3.2.6",
3
+ "version": "3.3.1",
4
4
  "description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
5
5
  "type": "module",
6
6
  "main": "./dist/module.cjs",