Repository: tatethurston/nextjs-routes
Pull request #26 (2022-07-08 18:02:25)

remove prettier

codecov[bot]: # [Codecov](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston) Report
> Merging [#26](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston) (e652244) into [main](https://codecov.io/gh/tatethurston/nextjs-routes/commit/ba53773192412f667592ad40ef594929adc4778d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston) (ba53773) will **not change** coverage.
> The diff coverage is `100.00%`.

```diff
@@           Coverage Diff           @@
##             main      #26   +/-   ##
=======================================
  Coverage   98.24%   98.24%           
=======================================
  Files           1        1           
  Lines          57       57           
  Branches       13       13           
=======================================
  Hits           56       56           
  Misses          1        1           
```


| [Impacted Files](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston) | Coverage Δ | |
|---|---|---|
| [src/utils.ts](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston#diff-c3JjL3V0aWxzLnRz) | `98.24% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston). Last update [ba53773...e652244](https://codecov.io/gh/tatethurston/nextjs-routes/pull/26?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Tate+Thurston).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 056846a..769964b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## 0.0.17
+
+- re-export types from `next/link` and `next/router`
+
 ## 0.0.16
 
 - fixed prettier as an optional peer dependency
diff --git a/public.package.json b/public.package.json
index 3f42d67..882a6f0 100644
--- a/public.package.json
+++ b/public.package.json
@@ -15,13 +15,7 @@
   "sideEffects": false,
   "types": "index.d.ts",
   "peerDependencies": {
-    "next": "*",
-    "prettier": "^2.2.1"
-  },
-  "peerDependenciesMeta": {
-    "prettier": {
-      "optional": true
-    }
+    "next": "*"
   },
   "keywords": [
     "link",
diff --git a/src/cli.ts b/src/cli.ts
index 67bf6fc..c45e14e 100644
--- a/src/cli.ts
+++ b/src/cli.ts
@@ -6,20 +6,12 @@ import { getPagesDirectory, findFiles, generate, nextRoutes } from "./utils.js";
 
 const NEXTJS_PAGES_DIRECTORY = join(".", getPagesDirectory());
 
-async function main(): Promise<void> {
+function main(): void {
   const files = findFiles(NEXTJS_PAGES_DIRECTORY);
   const routes = nextRoutes(files);
-  let generated = generate(routes);
-
-  try {
-    const prettier = await import("prettier");
-    generated = prettier.format(generated, { parser: "typescript" });
-    // eslint-disable-next-line no-empty
-  } catch (e) {
-    console.warn(e);
-  }
+  const generated = generate(routes);
 
   writeFileSync("nextjs-routes.d.ts", generated);
 }
 
-void main();
+main();
diff --git a/src/utils.ts b/src/utils.ts
index 2390963..f9da3cf 100644
--- a/src/utils.ts
+++ b/src/utils.ts
@@ -114,6 +114,7 @@ export function generate(routes: Route[]): string {
 // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.'
 // Run \`yarn nextjs-routes\` to regenerate this file.
 /* eslint-disable */
+// prettier-ignore
 
 declare module "nextjs-routes" {
   export type Route =
@@ -121,9 +122,9 @@ declare module "nextjs-routes" {
       .map((route) => {
         const [query, requiredKeys] = getQueryInterface(route.query);
         if (requiredKeys > 0) {
-          return `{ pathname: '${route.pathname}'; query: Query<${query}> }`;
+          return `{ pathname: "${route.pathname}"; query: Query<${query}> }`;
         } else {
-          return `{ pathname: '${route.pathname}'; query?: Query | undefined }`;
+          return `{ pathname: "${route.pathname}"; query?: Query | undefined }`;
         }
       })
       .join("\n    | ")}
@@ -135,6 +136,7 @@ declare module "next/link" {
   import type { Route } from "nextjs-routes";
   import type { LinkProps as NextLinkProps } from "next/dist/client/link";
   import type { PropsWithChildren, MouseEventHandler } from "react";
+  export * from "next/dist/client/link";
 
   type RouteOrQuery = Route | { query?: { [key: string]: string | undefined } };
 
@@ -160,7 +162,8 @@ declare module "next/link" {
 declare module "next/router" {
   import type { Route } from "nextjs-routes";
   import type { NextRouter as Router } from "next/dist/client/router";
-  export { RouterEvent } from "next/dist/client/router";
+  export * from "next/dist/client/router";
+  export { default } from "next/dist/client/router";
 
   type TransitionOptions = Parameters<Router["push"]>[2];
 


Test patch:
diff --git a/e2e/nextjs-routes.d.ts b/e2e/nextjs-routes.d.ts
index 85e9c70..78c08d0 100644
--- a/e2e/nextjs-routes.d.ts
+++ b/e2e/nextjs-routes.d.ts
@@ -1,11 +1,12 @@
 // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.'
 // Run `yarn nextjs-routes` to regenerate this file.
 /* eslint-disable */
+// prettier-ignore
 
 declare module "nextjs-routes" {
   export type Route =
-    | { pathname: "/foos/[foo]"; query: Query<{ foo: string }> }
-    | { pathname: "/"; query?: Query | undefined };
+    | { pathname: "/foos/[foo]"; query: Query<{ foo: string; }> }
+    | { pathname: "/"; query?: Query | undefined }
 
   type Query<Params = {}> = Params & { [key: string]: string | undefined };
 }
@@ -14,6 +15,7 @@ declare module "next/link" {
   import type { Route } from "nextjs-routes";
   import type { LinkProps as NextLinkProps } from "next/dist/client/link";
   import type { PropsWithChildren, MouseEventHandler } from "react";
+  export * from "next/dist/client/link";
 
   type RouteOrQuery = Route | { query?: { [key: string]: string | undefined } };
 
@@ -39,7 +41,8 @@ declare module "next/link" {
 declare module "next/router" {
   import type { Route } from "nextjs-routes";
   import type { NextRouter as Router } from "next/dist/client/router";
-  export { RouterEvent } from "next/dist/client/router";
+  export * from "next/dist/client/router";
+  export { default } from "next/dist/client/router";
 
   type TransitionOptions = Parameters<Router["push"]>[2];
 
diff --git a/e2e/typetest.tsx b/e2e/typetest.tsx
index 61d3850..7914c2c 100644
--- a/e2e/typetest.tsx
+++ b/e2e/typetest.tsx
@@ -1,5 +1,6 @@
 import Link from "next/link";
-import { useRouter, RouterEvent } from "next/router";
+import { LinkProps } from "next/link";
+import { useRouter, RouterEvent, NextRouter } from "next/router";
 import type { Route } from "nextjs-routes";
 
 // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function
@@ -45,6 +46,15 @@ function expectType<T>(_value: T) {}
 // @ts-expect-error replace typo
 <Link href={{ query: {} }} replacey />;
 
+// LinkProps
+
+// ensure LinkProps is our LinkProps, not the untyped one
+
+expectType<LinkProps["href"]>({ pathname: "/" });
+
+// @ts-expect-error invalid pathname
+expectType<LinkProps["href"]>({ pathname: "/invalid" });
+
 // next/router
 const router = useRouter();
 
@@ -133,6 +143,17 @@ routerEvent = "routeChangeStart";
 // @ts-expect-error event typo
 routerEvent = "routeChangeStarty";
 
+// NextRouter
+
+// ensure NextRouter is our NextRouter, not the untyped one
+
+let nextRouter: NextRouter = undefined as unknown as NextRouter;
+
+nextRouter.push({ pathname: "/" });
+
+// @ts-expect-error invalid pathname
+nextRouter.push({ pathname: "/invalid" });
+
 // nextjs-routes
 
 // Route
diff --git a/src/__snapshots__/test.ts.snap b/src/__snapshots__/test.ts.snap
index 2b9af95..01929bb 100644
--- a/src/__snapshots__/test.ts.snap
+++ b/src/__snapshots__/test.ts.snap
@@ -4,27 +4,28 @@ exports[`route generation typescript 1`] = `
 "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.'
 // Run \`yarn nextjs-routes\` to regenerate this file.
 /* eslint-disable */
+// prettier-ignore
 
 declare module \\"nextjs-routes\\" {
   export type Route =
-    | { pathname: '/404'; query?: Query | undefined }
-    | { pathname: '/[foo]'; query: Query<{ foo: string; }> }
-    | { pathname: '/[foo]/[bar]/[baz]'; query: Query<{ foo: string;bar: string;baz: string; }> }
-    | { pathname: '/[foo]/bar/[baz]'; query: Query<{ foo: string;baz: string; }> }
-    | { pathname: '/[foo]/bar/[baz]/foo/[bar]'; query: Query<{ foo: string;baz: string;bar: string; }> }
-    | { pathname: '/[foo]/baz'; query: Query<{ foo: string; }> }
-    | { pathname: '/_debug/health-check'; query?: Query | undefined }
-    | { pathname: '/_error'; query?: Query | undefined }
-    | { pathname: '/api/[[...segments]]'; query?: Query | undefined }
-    | { pathname: '/api/[...segments]'; query: Query<{ segments: string[]; }> }
-    | { pathname: '/api/bar'; query?: Query | undefined }
-    | { pathname: '/foo/[slug]'; query: Query<{ slug: string; }> }
-    | { pathname: '/'; query?: Query | undefined }
-    | { pathname: '/not-found'; query?: Query | undefined }
-    | { pathname: '/settings/bars/[bar]'; query: Query<{ bar: string; }> }
-    | { pathname: '/settings/bars/[bar]/baz'; query: Query<{ bar: string; }> }
-    | { pathname: '/settings/foo'; query?: Query | undefined }
-    | { pathname: '/settings'; query?: Query | undefined }
+    | { pathname: \\"/404\\"; query?: Query | undefined }
+    | { pathname: \\"/[foo]\\"; query: Query<{ foo: string; }> }
+    | { pathname: \\"/[foo]/[bar]/[baz]\\"; query: Query<{ foo: string;bar: string;baz: string; }> }
+    | { pathname: \\"/[foo]/bar/[baz]\\"; query: Query<{ foo: string;baz: string; }> }
+    | { pathname: \\"/[foo]/bar/[baz]/foo/[bar]\\"; query: Query<{ foo: string;baz: string;bar: string; }> }
+    | { pathname: \\"/[foo]/baz\\"; query: Query<{ foo: string; }> }
+    | { pathname: \\"/_debug/health-check\\"; query?: Query | undefined }
+    | { pathname: \\"/_error\\"; query?: Query | undefined }
+    | { pathname: \\"/api/[[...segments]]\\"; query?: Query | undefined }
+    | { pathname: \\"/api/[...segments]\\"; query: Query<{ segments: string[]; }> }
+    | { pathname: \\"/api/bar\\"; query?: Query | undefined }
+    | { pathname: \\"/foo/[slug]\\"; query: Query<{ slug: string; }> }
+    | { pathname: \\"/\\"; query?: Query | undefined }
+    | { pathname: \\"/not-found\\"; query?: Query | undefined }
+    | { pathname: \\"/settings/bars/[bar]\\"; query: Query<{ bar: string; }> }
+    | { pathname: \\"/settings/bars/[bar]/baz\\"; query: Query<{ bar: string; }> }
+    | { pathname: \\"/settings/foo\\"; query?: Query | undefined }
+    | { pathname: \\"/settings\\"; query?: Query | undefined }
 
   type Query<Params = {}> = Params & { [key: string]: string | undefined };
 }
@@ -33,6 +34,7 @@ declare module \\"next/link\\" {
   import type { Route } from \\"nextjs-routes\\";
   import type { LinkProps as NextLinkProps } from \\"next/dist/client/link\\";
   import type { PropsWithChildren, MouseEventHandler } from \\"react\\";
+  export * from \\"next/dist/client/link\\";
 
   type RouteOrQuery = Route | { query?: { [key: string]: string | undefined } };
 
@@ -58,7 +60,8 @@ declare module \\"next/link\\" {
 declare module \\"next/router\\" {
   import type { Route } from \\"nextjs-routes\\";
   import type { NextRouter as Router } from \\"next/dist/client/router\\";
-  export { RouterEvent } from \\"next/dist/client/router\\";
+  export * from \\"next/dist/client/router\\";
+  export { default } from \\"next/dist/client/router\\";
 
   type TransitionOptions = Parameters<Router[\\"push\\"]>[2];