nuxt-typed-router 3.0.7 → 3.0.9

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
@@ -24,6 +24,11 @@ interface ModuleOptions {
24
24
  * @default false
25
25
  */
26
26
  strict?: boolean | StrictOptions;
27
+ /**
28
+ * Remove Nuxt definitions to avoid conflicts
29
+ * @default true
30
+ */
31
+ experimentalRemoveNuxtDefs?: boolean;
27
32
  }
28
33
  interface StrictOptions {
29
34
  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.0.7"
8
+ "version": "3.0.9"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { addPluginTemplate, extendPages, defineNuxtModule, createResolver } from '@nuxt/kit';
1
+ import { addPluginTemplate, extendPages, createResolver, defineNuxtModule } from '@nuxt/kit';
2
2
  import chalk from 'chalk';
3
3
  import logSymbols from 'log-symbols';
4
4
  import { defu } from 'defu';
@@ -10,6 +10,7 @@ import { fileURLToPath } from 'url';
10
10
  import { dirname, resolve } from 'pathe';
11
11
  import mkdirp from 'mkdirp';
12
12
  import { camelCase } from 'lodash-es';
13
+ import { readFile } from 'fs/promises';
13
14
 
14
15
  class ModuleOptionsStore {
15
16
  constructor() {
@@ -18,6 +19,7 @@ class ModuleOptionsStore {
18
19
  this.experimentalPathCheck = true;
19
20
  this.autoImport = false;
20
21
  this.rootDir = "";
22
+ this.buildDir = "";
21
23
  this.i18n = false;
22
24
  this.i18nOptions = null;
23
25
  this.i18nLocales = [];
@@ -31,6 +33,8 @@ class ModuleOptionsStore {
31
33
  this.autoImport = options.autoImport;
32
34
  if (options.rootDir != null)
33
35
  this.rootDir = options.rootDir;
36
+ if (options.buildDir != null)
37
+ this.buildDir = options.buildDir;
34
38
  if (options.i18n != null)
35
39
  this.i18n = options.i18n;
36
40
  if (options.i18nOptions != null) {
@@ -1613,6 +1617,46 @@ async function createTypedRouter({
1613
1617
  }
1614
1618
  }
1615
1619
 
1620
+ async function removeNuxtDefinitions({
1621
+ buildDir,
1622
+ autoImport
1623
+ }) {
1624
+ const { resolve } = createResolver(import.meta.url);
1625
+ const componentDefinitions = await readFile(resolve(buildDir, "components.d.ts"), {
1626
+ encoding: "utf8"
1627
+ });
1628
+ const replacedNuxtLink = componentDefinitions.replace(
1629
+ /'NuxtLink': typeof import\(".*"\)\['default'\]/gm,
1630
+ ""
1631
+ );
1632
+ processPathAndWriteFile({
1633
+ content: replacedNuxtLink,
1634
+ fileName: "components.d.ts",
1635
+ outDir: ".nuxt"
1636
+ });
1637
+ if (autoImport) {
1638
+ let globalDefinitions = await readFile(resolve(buildDir, "types/imports.d.ts"), {
1639
+ encoding: "utf8"
1640
+ });
1641
+ const importsToRemove = [
1642
+ "useRouter",
1643
+ "useRoute",
1644
+ "useLocalePath",
1645
+ "useLocaleRoute",
1646
+ "definePageMeta",
1647
+ "navigateTo"
1648
+ ].map((m) => new RegExp(`const ${m}: typeof import\\('.*'\\)\\['${m}'\\]`, "gm"));
1649
+ importsToRemove.forEach((imp) => {
1650
+ globalDefinitions = globalDefinitions.replace(imp, "");
1651
+ });
1652
+ processPathAndWriteFile({
1653
+ content: globalDefinitions,
1654
+ fileName: "types/imports.d.ts",
1655
+ outDir: ".nuxt"
1656
+ });
1657
+ }
1658
+ }
1659
+
1616
1660
  const module = defineNuxtModule({
1617
1661
  meta: {
1618
1662
  name: "nuxt-typed-router",
@@ -1622,7 +1666,8 @@ const module = defineNuxtModule({
1622
1666
  defaults: {
1623
1667
  plugin: false,
1624
1668
  strict: false,
1625
- experimentalPathCheck: true
1669
+ experimentalPathCheck: true,
1670
+ experimentalRemoveNuxtDefs: true
1626
1671
  },
1627
1672
  setup(moduleOptions, nuxt) {
1628
1673
  const { resolve } = createResolver(import.meta.url);
@@ -1661,6 +1706,12 @@ const module = defineNuxtModule({
1661
1706
  experimentalRfc436: true
1662
1707
  };
1663
1708
  }
1709
+ if (moduleOptions.experimentalRemoveNuxtDefs) {
1710
+ removeNuxtDefinitions({
1711
+ autoImport: nuxt.options.imports.autoImport ?? true,
1712
+ buildDir: nuxt.options.buildDir
1713
+ });
1714
+ }
1664
1715
  });
1665
1716
  if (nuxt.options.dev) {
1666
1717
  nuxt.hook("devtools:customTabs", (tabs) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "description": "Provide autocompletion for routes paths, names and params in Nuxt apps",
5
5
  "type": "module",
6
6
  "main": "./dist/module.cjs",