Repository: tatethurston/nextjs-routes
Pull request #143 (2023-04-11 06:22:02)

Change export file path(d.ts)
Save the file to the "@types" folder for the following reasons. 

[ Why recommend ]
1. The purpose of the @types folder is to collect type definition files (*.d.ts) from external libraries.

2. You can tell by looking at the folder name that the file (nextjs-routes.d.ts) is associated with an external library.

3. Folder separation allows you to obtain a separation of concerns effect from the root path.




Patch:
diff --git a/README.md b/README.md
index 655ef10..f8b5b3a 100644
--- a/README.md
+++ b/README.md
@@ -76,9 +76,9 @@
    npx next build
    ```
 
-That's it! A `nextjs-routes.d.ts` file will be generated the first time you start your server. Check this file into version control. `next/link` and `next/router` type definitions have been augmented to verify your application's routes. No more broken links, and you get route autocompletion 🙌.
+That's it! A `@types/nextjs-routes.d.ts` file will be generated the first time you start your server. Check this file into version control. `next/link` and `next/router` type definitions have been augmented to verify your application's routes. No more broken links, and you get route autocompletion 🙌.
 
-In development, whenever your routes change, your `nextjs-routes.d.ts` file will automatically update.
+In development, whenever your routes change, your `@types/nextjs-routes.d.ts` file will automatically update.
 
 If you would prefer to generate the route types file outside of `next dev` or `next build` you can also invoke the cli directly: `npx nextjs-routes`.
 
@@ -222,7 +222,7 @@ export const getServerSideProps = (async (context) => {
 
 ## How does this work? 🤔
 
-`nextjs-routes` generates types for the `pathname` and `query` for every page in your `pages` and/or `app` directory. The generated types are written to `nextjs-routes.d.ts` which is automatically referenced by your Next project's `tsconfig.json`. `nextjs-routes.d.ts` redefines the types for `next/link` and `next/router` and applies the generated route types.
+`nextjs-routes` generates types for the `pathname` and `query` for every page in your `pages` and/or `app` directory. The generated types are written to `@types/nextjs-routes.d.ts` which is automatically referenced by your Next project's `tsconfig.json`. `@types/nextjs-routes.d.ts` redefines the types for `next/link` and `next/router` and applies the generated route types.
 
 ## What if I need a runtime?
 
diff --git a/src/core.ts b/src/core.ts
index 125a8ad..0eb45bc 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -387,7 +387,7 @@ export function getPageRoutes(files: string[], opts: Opts): string[] {
 export function writeNextJSRoutes(options: NextJSRoutesOptions): void {
   const defaultOptions = {
     dir: process.cwd(),
-    outDir: "",
+    outDir: "@types",
     pageExtensions: ["tsx", "ts", "jsx", "js"],
   };
   const opts = {


Test patch:
diff --git a/e2e/nextjs-routes.d.ts b/e2e/@types/nextjs-routes.d.ts
similarity index 100%
rename from e2e/nextjs-routes.d.ts
rename to e2e/@types/nextjs-routes.d.ts
diff --git a/examples/app/nextjs-routes.d.ts b/examples/app/@types/nextjs-routes.d.ts
similarity index 100%
rename from examples/app/nextjs-routes.d.ts
rename to examples/app/@types/nextjs-routes.d.ts
diff --git a/examples/intl/nextjs-routes.d.ts b/examples/intl/@types/nextjs-routes.d.ts
similarity index 100%
rename from examples/intl/nextjs-routes.d.ts
rename to examples/intl/@types/nextjs-routes.d.ts
diff --git a/src/__snapshots__/core.test.ts.snap b/src/__snapshots__/core.test.ts.snap
index 1b902bc..ce1b93a 100644
--- a/src/__snapshots__/core.test.ts.snap
+++ b/src/__snapshots__/core.test.ts.snap
@@ -3,7 +3,7 @@
 exports[`route generation app directory (experimental) 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -183,7 +183,7 @@ declare module "next/router" {
 exports[`route generation configuration i18n 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -563,7 +563,7 @@ declare module "next/router" {
 exports[`route generation configuration pageExtensions configured 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -743,7 +743,7 @@ declare module "next/router" {
 exports[`route generation configuration pageExtensions default 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -921,7 +921,7 @@ declare module "next/router" {
 exports[`route generation dedupes 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -1099,7 +1099,7 @@ declare module "next/router" {
 exports[`route generation no routes 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -1277,7 +1277,7 @@ declare module "next/router" {
 exports[`route generation transforms windows paths 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0
@@ -1455,7 +1455,7 @@ declare module "next/router" {
 exports[`route generation typescript 1`] = `
 [
   [
-    "nextjs-routes.d.ts",
+    "@types/nextjs-routes.d.ts",
     "// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
 // This file will be automatically regenerated when your Next.js server is running.
 // nextjs-routes version: 2.0.0