Skip to content

Commit

Permalink
add app directory route support
Browse files Browse the repository at this point in the history
fixes #178.
  • Loading branch information
tatethurston committed Nov 4, 2023
1 parent 827b178 commit b639e3b
Show file tree
Hide file tree
Showing 10 changed files with 2,878 additions and 3,451 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.12
20.9.0
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.1.0

- Add experimental support for app directory [route handler](https://nextjs.org/docs/app/building-your-application/routing/route-handlers). See [#178](https://github.com/tatethurston/nextjs-routes/issues/178).

## 2.0.1

- Fix `GetServerSidePropsContext` and `GetServerSidePropsResult` types. Thanks @po4tion!
Expand Down
12 changes: 6 additions & 6 deletions examples/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
"start": "next start"
},
"dependencies": {
"next": "^13.3.0",
"next": "^14.0.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "18.15.11",
"@types/react": "18.0.33",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"@types/node": "20.8.10",
"@types/react": "18.2.34",
"eslint": "8.53.0",
"eslint-config-next": "14.0.1",
"nextjs-routes": "workspace:*",
"typescript": "5.0.4"
"typescript": "5.2.2"
}
}
12 changes: 6 additions & 6 deletions examples/intl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"start": "next start"
},
"dependencies": {
"next": "^13.3.0",
"next": "^14.0.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "18.15.11",
"@types/react": "18.0.33",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"@types/node": "20.8.10",
"@types/react": "18.2.34",
"eslint": "8.53.0",
"eslint-config-next": "14.0.1",
"nextjs-routes": "workspace:*",
"typescript": "5.0.4"
"typescript": "5.2.2"
}
}
22 changes: 11 additions & 11 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
"start": "next start"
},
"dependencies": {
"next": "^13.3.0",
"next": "^14.0.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.0",
"@types/node": "18.15.11",
"@types/react": "18.0.33",
"@types/testing-library__jest-dom": "^5.14.5",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"@types/jest": "^29.5.7",
"@types/node": "20.8.10",
"@types/react": "18.2.34",
"@types/testing-library__jest-dom": "^6.0.0",
"eslint": "8.53.0",
"eslint-config-next": "14.0.1",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"nextjs-routes": "workspace:*",
"typescript": "5.0.4"
"typescript": "5.2.2"
}
}
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
"examples:each": "for e in ./examples/*; do (cd \"$e\" && $npm_config_command); done",
"examples:regen": "npm run examples:each --command='pnpm next build'",
"lint": "pnpm typecheck && prettier --check . && eslint . && pnpm prettier-package-json --list-different './{packages,examples}/*/package.json'",
"lint:fix": "prettier --write '**/*.{ts,cts,mts,tsx,md,json,yaml}' && prettier-package-json --write './{packages,exmaples}/**/package.json' && eslint --fix .",
"lint:fix": "prettier --write '**/*.{ts,cts,mts,tsx,md,json,yaml}' && prettier-package-json --write './{packages,exmaples}/*/package.json' && eslint --fix .",
"prepare": "husky install",
"test": "npm run e2e:setup && jest",
"test:ci": "npm run test --coverage",
"typecheck": "pnpm -r exec tsc --noEmit"
"test": "pnpm run e2e:setup && jest",
"test:ci": "pnpm run test --coverage",
"typecheck": "pnpm --recursive exec tsc --noEmit"
},
"sideEffects": false,
"devDependencies": {
"@babel/preset-env": "^7.21.5",
"@babel/preset-typescript": "^7.21.5",
"@swc/core": "^1.3.56",
"@types/jest": "^29.5.1",
"@types/node": "^18.16.3",
"@types/react": "^18.2.0",
"@types/webpack": "^5.28.1",
"@typescript-eslint/eslint-plugin": "^5.59.2",
"@typescript-eslint/parser": "^5.59.2",
"babel-loader": "^9.1.2",
"@babel/preset-env": "^7.23.2",
"@babel/preset-typescript": "^7.23.2",
"@swc/core": "^1.3.95",
"@types/jest": "^29.5.7",
"@types/node": "^20.8.10",
"@types/react": "^18.2.34",
"@types/webpack": "^5.28.4",
"@typescript-eslint/eslint-plugin": "^6.9.1",
"@typescript-eslint/parser": "^6.9.1",
"babel-loader": "^9.1.3",
"codecov": "^3.8.3",
"eslint": "^8.39.0",
"eslint-config-prettier": "^8.8.0",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"husky": "^8.0.3",
"jest": "^29.5.0",
"next": "^13.3.4",
"prettier": "^2.8.8",
"jest": "^29.7.0",
"next": "^14.0.1",
"prettier": "^3.0.3",
"prettier-package-json": "^2.8.0",
"swc-loader": "^0.2.3",
"typescript": "^5.0.4",
"webpack": "^5.81.0",
"webpack-cli": "^5.0.2"
"typescript": "^5.2.2",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
},
"packageManager": "pnpm@7.17.0"
"packageManager": "pnpm@8.10.2"
}
8 changes: 4 additions & 4 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
"start": "next start"
},
"dependencies": {
"next": "*",
"react": "*",
"react-dom": "*"
"next": "^14.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"nextjs-routes": "workspace:*",
"typescript": "*"
"typescript": "^5.2.2"
}
}
2 changes: 1 addition & 1 deletion packages/nextjs-routes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-routes",
"version": "2.0.1",
"version": "2.1.0",
"description": "Type safe routing for Next.js",
"license": "MIT",
"author": "Tate <tatethurston@gmail.com>",
Expand Down
10 changes: 6 additions & 4 deletions packages/nextjs-routes/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,13 @@ function commonProcessing(paths: string[], opts: Opts): string[] {
);
}

const APP_DIRECTORY_ROUTABLE = ["page", "route"];

export function getAppRoutes(files: string[], opts: Opts): string[] {
return (
commonProcessing(files, opts)
// app pages must be named 'page'
.filter((file) => parse(file).name === "page")
.filter((file) => APP_DIRECTORY_ROUTABLE.includes(parse(file).name))
.map((file) =>
// transform filepath to url path
file
Expand All @@ -361,17 +363,17 @@ export function getAppRoutes(files: string[], opts: Opts): string[] {
(segment) => !(segment.startsWith("(") && segment.endsWith(")"))
)
// remove page
.filter((file) => parse(file).name !== "page")
.filter((file) => !APP_DIRECTORY_ROUTABLE.includes(parse(file).name))
.join(sep)
)
// handle index page
.map((file) => (file === "" ? "/" : file))
);
}

export function getPageRoutes(files: string[], opts: Opts): string[] {
const NEXTJS_NON_ROUTABLE = ["/_app", "/_document", "/_error", "/middleware"];
const NEXTJS_NON_ROUTABLE = ["/_app", "/_document", "/_error", "/middleware"];

export function getPageRoutes(files: string[], opts: Opts): string[] {
return (
commonProcessing(files, opts)
// remove index if present (/foos/index.ts is the same as /foos.ts)
Expand Down
Loading

0 comments on commit b639e3b

Please sign in to comment.