nuxt-typed-router 2.0.0-beta.1 โ†’ 2.0.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # ๐Ÿš—๐Ÿšฆ Typed Router for Nuxt
1
+
2
2
 
3
3
  <p align="center">
4
- <img width='100' src="https://raw.githubusercontent.com/victorgarciaesgi/nuxt-typed-router/master/.github/images/logo.png" alt="nuxt-typed-router logo">
4
+ <img src="https://raw.githubusercontent.com/victorgarciaesgi/nuxt-typed-router/master/.github/images/cover.png" alt="nuxt-typed-router cover">
5
5
  </p>
6
6
 
7
7
 
@@ -18,26 +18,40 @@
18
18
 
19
19
  ## Provide a type safe router to Nuxt with auto-generated typed definitions for route names and autocompletion for route params
20
20
 
21
- - ๐ŸŽ Provides a hook `useTypedRouter` that returns an alias of `$typedRouter` and also a typed list of your routes
22
- - ๐Ÿšš Expose a global method `$typedRouter` (clone of vue-router), but typed with the routes defined in `pages` directory
23
- - ๐Ÿšฆ Provides auto-completion and errors for route params in `push` and `replace` methods
21
+ - Automaticaly provides types check and autocomplete to `NuxtLink`
22
+ - Exports a `useTypedRouter` and `useTypedRoute` composable
23
+ - Supports routes defined in `config.extendRoutes`
24
+ - Infer route params based on route name
25
+ - Provide global `$typedRouter` util
26
+
27
+ <br/>
24
28
 
25
29
  <br/>
30
+ <p align="center">
31
+ <img src="https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/.github/images/nuxt-router.gif?raw=true"/>
32
+ </p>
33
+ <br/>
34
+
35
+
36
+ # Documentation
37
+
38
+ [![Open in StackBlitz](https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/.github/images/redirectDoc.svg?raw=true)](https://nuxt-typed-router.vercel.app/)
39
+
40
+ # Play with it
41
+ [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/edit/github-7e4xvw?file=store/testRouter.ts)
26
42
 
27
- Demo ๐Ÿงช : [nuxt-typed-router-demo](https://github.com/victorgarciaesgi/nuxt-typed-router-demo)
43
+ Demo repo ๐Ÿงช : [nuxt-typed-router-demo](https://github.com/victorgarciaesgi/nuxt-typed-router-demo)
28
44
 
29
- ## Compatibility:
45
+ <br/>
46
+
47
+ # Compatibility:
30
48
 
31
49
  - Nuxt 3
32
50
  - Nuxt 2 (via [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2))
33
51
 
34
- <br/>
35
- <p align="center">
36
- <img src="https://github.com/victorgarciaesgi/nuxt-typed-router/blob/master/.github/images/in-action.gif?raw=true"/>
37
- </p>
38
- <br/>
39
52
 
40
- # Installation
53
+
54
+ # Quick start
41
55
 
42
56
  ### For Nuxt 3
43
57
 
@@ -50,6 +64,7 @@ npm install -D nuxt-typed-router
50
64
  ### Nuxt 2 legacy
51
65
 
52
66
  Nuxt 2 version is no longer maintained, but still available in [`nuxt2` branch](https://github.com/victorgarciaesgi/nuxt-typed-router/tree/nuxt2)
67
+ It only has route name autocomplete functionnality
53
68
 
54
69
  ```bash
55
70
  yarn add -D nuxt-typed-router@legacy
@@ -57,9 +72,8 @@ yarn add -D nuxt-typed-router@legacy
57
72
  npm install -D nuxt-typed-router@legacy
58
73
  ```
59
74
 
60
- # Quick start
61
-
62
- First, register the module in the `nuxt.config.ts`
75
+ # Configuration
76
+ Register the module in the `nuxt.config.ts`, done!
63
77
 
64
78
  ```ts
65
79
  export default defineNuxtConfig({
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.0.0-rc.1",
6
6
  "bridge": false
7
7
  },
8
- "version": "2.0.0-beta.1"
8
+ "version": "2.0.1"
9
9
  }
package/dist/module.mjs CHANGED
@@ -171,7 +171,8 @@ function createDeclarationRoutesFile() {
171
171
  function createRuntimeIndexFile() {
172
172
  return `
173
173
  ${watermarkTemplate}
174
- export {routesNames, TypedRouteList} from './__routes';
174
+ export { routesNames } from './__routes';
175
+ export type { TypedRouteList } from './__routes';
175
176
  export * from './__useTypedRouter';
176
177
  export * from './__useTypedRoute';
177
178
  `;
@@ -205,7 +206,7 @@ function createTypedRouteParamsExport(routesParams) {
205
206
  return `export type TypedRouteParams = {
206
207
  ${routesParams.map(
207
208
  ({ name, params }) => `"${name}": ${params.length ? `{
208
- ${params.map(({ key, required, type }) => `"${key}"${required ? "" : "?"}: ${type}`).join(",\n")}
209
+ ${params.map(({ key, required }) => `"${key}"${required ? "" : "?"}: string | number`).join(",\n")}
209
210
  }` : "never"}`
210
211
  ).join(",\n")}
211
212
  }`;
@@ -214,7 +215,7 @@ function createTypedRouteNamedMapperExport(routesParams) {
214
215
  return `export type TypedRouteNamedMapper =
215
216
  ${routesParams.map(
216
217
  ({ name, params }) => `{name: "${name}" ${params.length ? `, params${params.some((s) => s.required) ? "" : "?"}: {
217
- ${params.map(({ key, required, type }) => `"${key}"${required ? "" : "?"}: ${type}`).join(",\n")}
218
+ ${params.map(({ key, required }) => `"${key}"${required ? "" : "?"}: string | number`).join(",\n")}
218
219
  }` : ""}}`
219
220
  ).join("|\n")}
220
221
  `;
@@ -227,7 +228,9 @@ function createResolvedTypedRouteNamedMapperExport(routesParams) {
227
228
  } & (
228
229
  ${routesParams.map(
229
230
  ({ name, params }) => `{name: "${name}" ${params.length ? `, params: {
230
- ${params.map(({ key, type }) => `"${key}": ${type}`).join(",\n")}
231
+ ${params.map(
232
+ ({ key, notRequiredOnPage }) => `"${key}"${notRequiredOnPage ? "?" : ""}: string`
233
+ ).join(",\n")}
231
234
  }` : ""}}`
232
235
  ).join("|\n")}
233
236
  )
@@ -457,15 +460,15 @@ function extractRouteParamsFromPath(path, isIndexFileForRouting, previousParams)
457
460
  if (matches) {
458
461
  const [_, mtch, key, optional] = matches;
459
462
  if (mtch) {
460
- params.push({ name: key, required: !optional });
463
+ params.push({ name: key, optional: !!optional });
461
464
  }
462
465
  }
463
466
  } while (matches);
464
467
  let allMergedParams = params.map(
465
- ({ name, required }) => ({
468
+ ({ name, optional }) => ({
466
469
  key: name,
467
- type: "string | number",
468
- required
470
+ required: !optional,
471
+ notRequiredOnPage: optional
469
472
  })
470
473
  );
471
474
  if (previousParams?.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-typed-router",
3
- "version": "2.0.0-beta.1",
3
+ "version": "2.0.1",
4
4
  "description": "Provide autocompletion for pages route names generated by Nuxt router",
5
5
  "type": "module",
6
6
  "main": "./dist/module.cjs",
@@ -20,11 +20,11 @@
20
20
  "dev": "nuxi dev playground",
21
21
  "dev:build": "nuxi build playground",
22
22
  "dev:prepare": "nuxt-module-build --stub && nuxi prepare playground",
23
- "build:test": "cross-env NUXT_BUILD_TYPE=stub pnpm run prepack && pnpm run dev:build",
24
- "test": "pnpm run dev:prepare && pnpm run build:test && vitest run",
25
- "test:watch": "pnpm run build:test && vitest",
26
- "docs:dev": "cd docs && pnpm run dev",
27
- "docs:buid": "(cd docs && nuxi build)"
23
+ "build:test": "cross-env NUXT_BUILD_TYPE=stub yarn prepack && yarn dev:build",
24
+ "test": "yarn dev:prepare && yarn build:test && vitest run",
25
+ "test:watch": "yarn build:test && vitest",
26
+ "docs:dev": "cd docs && yarn dev",
27
+ "docs:build": "npm run dev:prepare && cd docs && nuxi generate"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"
@@ -39,6 +39,7 @@
39
39
  "nuxt 3",
40
40
  "nuxt 3 router"
41
41
  ],
42
+ "homepage": "https://nuxt-typed-router.vercel.app/",
42
43
  "repository": {
43
44
  "type": "git",
44
45
  "url": "git+https://victorgarciaesgi@github.com/victorgarciaesgi/nuxt-typed-router.git"