Repository: tatethurston/nextjs-routes (ts)

Issue:
Support for Custom Page Extensions
Hi there,

Using v0.1.0, I noticed that it doesn't seem to support [Custom Page Extensions](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions). Indeed, the generated `nextjs-routes.d.ts` file defines a route for every files found in the `pages` (or `src/pages`) directory, including non page ones.

I think it might be something you want to consider for #44.

Feel free to ask me anything that can help.

Thanks for this tool, Vercel should take inspiration from it!

Pull request:
Fixed pageExtensions
Definitely closes #74

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index baa814f..e7ecc5d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
 # Changelog
 
+## 0.1.3
+
+- Fix: [pageExtensions](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions) didn't support extensions containing one or more dots
+
 ## 0.1.2
 
 - `nextjs-routes` now respects [pageExtensions](https://nextjs.org/docs/api-reference/next.config.js/custom-page-extensions) from `next.config.js`.
diff --git a/public.package.json b/public.package.json
index 4f41577..1bb4e64 100644
--- a/public.package.json
+++ b/public.package.json
@@ -1,6 +1,6 @@
 {
   "name": "nextjs-routes",
-  "version": "0.1.2",
+  "version": "0.1.3",
   "description": "Type safe routing for Next.js",
   "license": "MIT",
   "author": "Tate <tatethurston@gmail.com>",
diff --git a/src/core.ts b/src/core.ts
index 44440a1..d2584cf 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -226,10 +226,8 @@ export function writeNextjsRoutes(options: NextJSRoutesOptions): void {
     mkdirSync(opts.outDir, { recursive: true });
   }
   const outputFilepath = join(opts.outDir, "nextjs-routes.d.ts");
-  const pageExtensions = new Set(opts.pageExtensions);
   const files = findFiles(join(".", opts.pagesDirectory)).filter((file) => {
-    const ext = file.slice(file.lastIndexOf(".") + 1);
-    return pageExtensions.has(ext);
+    return opts.pageExtensions.some((ext) => file.endsWith(ext));
   });
   const routes = nextRoutes(files, opts.pagesDirectory);
   const generated = generate(routes);


Test patch:
diff --git a/src/__snapshots__/core.test.ts.snap b/src/__snapshots__/core.test.ts.snap
index 9998bdf..d62b056 100644
--- a/src/__snapshots__/core.test.ts.snap
+++ b/src/__snapshots__/core.test.ts.snap
@@ -196,7 +196,8 @@ exports[`route generation pageExtensions configured 1`] = `
 declare module "nextjs-routes" {
   export type Route =
     | { pathname: "/404"; query?: Query | undefined }
-    | { pathname: "/"; query?: Query | undefined };
+    | { pathname: "/"; query?: Query | undefined }
+    | { pathname: "/foo"; query?: Query | undefined };
 
   type Query<Params = {}> = Params & { [key: string]: string | string[] | undefined };
 
diff --git a/src/core.test.ts b/src/core.test.ts
index 40e6bb4..038b916 100644
--- a/src/core.test.ts
+++ b/src/core.test.ts
@@ -83,10 +83,10 @@ describe("route generation", () => {
     });
 
     it("configured", () => {
-      findFilesMock.mockReturnValueOnce(["pages/404.ts", "pages/index.md"]);
+      findFilesMock.mockReturnValueOnce(["pages/404.ts", "pages/index.md", "pages/foo/index.page.tsx", "pages/foo/index.test.tsx"]);
       writeNextjsRoutes({
         pagesDirectory: "pages",
-        pageExtensions: ["ts", "md"],
+        pageExtensions: ["ts", "md", "page.tsx"],
       });
       expect(writeFileSyncMock.mock.calls).toMatchSnapshot();
     });