Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility for Next.js v14 #54

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @baked-dev @jjantschulev
* @macku
36 changes: 9 additions & 27 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,16 @@ concurrency:
cancel-in-progress: true

jobs:
unimported:
name: Check unimported
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: whopio/[email protected]
with:
token: ${{ github.token }}
projects: "packages/codegen,packages/runtime"

install:
name: Install node modules
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7.13.6
- uses: pnpm/action-setup@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
check-latest: true
cache: pnpm
- name: Install all packages
Expand All @@ -44,33 +32,29 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7.13.6
- uses: pnpm/action-setup@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
check-latest: true
cache: pnpm
- name: Install all packages
run: pnpm install
- name: Run eslint
run: pnpx eslint ./ --max-warnings 0
run: pnpm eslint ./ --max-warnings 0

build:
name: Build packages
needs: install
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7.13.6
- uses: pnpm/action-setup@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
check-latest: true
cache: pnpm
- name: Install all packages
Expand All @@ -84,13 +68,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7.13.6
- uses: pnpm/action-setup@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
check-latest: true
cache: pnpm
- name: Install all packages
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ jobs:
token: ${{ github.token }}
- uses: actions/checkout@v3
if: steps.check.outputs.can-publish == 'true'
- uses: pnpm/action-setup@v2
with:
version: 7.13.6
- uses: pnpm/action-setup@v3
if: steps.check.outputs.can-publish == 'true'
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20
check-latest: true
cache: pnpm
if: steps.check.outputs.can-publish == 'true'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ yarn-error.log*

# turbo
.turbo

# ide
.idea/
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
2 changes: 1 addition & 1 deletion examples/basic-js/app/[locale]/middleware.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import("next-app-middleware/runtime").MiddlewareHandler<{ locale: string }>}
* @type {import("@cxnpl/next-app-middleware/runtime").MiddlewareHandler<{ locale: string }>}
*/
export default () => {
// console.log("middleware", req.params.locale);
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-js/app/[locale]/redirect/redirect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import("next-app-middleware/runtime").RedirectHandler<{ locale: string }>}
* @type {import("@cxnpl/next-app-middleware/runtime").RedirectHandler<{ locale: string }>}
*/
export default () => {
return "/";
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-js/app/[locale]/rewrite/rewrite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import("next-app-middleware/runtime").RewriteHandler<{ locale: string }>}
* @type {import("@cxnpl/next-app-middleware/runtime").RewriteHandler<{ locale: string }>}
*/
export default ({ params: { locale } }) => {
return `/${locale}`;
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-js/app/forward.dynamic.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import("next-app-middleware/runtime").DynamicForwarder}
* @type {import("@cxnpl/next-app-middleware/runtime").DynamicForwarder}
*/
export const locale = () => {
return "en";
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-js/middleware.hooks.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @type {import("next-app-middleware/runtime").ResponseHook>}
* @type {import("@cxnpl/next-app-middleware/runtime").ResponseHook>}
*/
export const response = (res) => {
console.log(res.status);
Expand Down
5 changes: 1 addition & 4 deletions examples/basic-js/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const { withMiddleware } = require("next-app-middleware");
const { withMiddleware } = require("@cxnpl/next-app-middleware");

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
basePath: "/js",
};

Expand Down
4 changes: 2 additions & 2 deletions examples/basic-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
"@next/font": "13.1.6",
"eslint": "8.30.0",
"eslint-config-next": "13.1.6",
"next": "13.1.6",
"next": "14.1.1",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"devDependencies": {
"@types/node": "^17.0.45",
"eslint-config-js": "workspace:^0.0.0",
"next-app-middleware": "workspace:0.0.0",
"@cxnpl/next-app-middleware": "workspace:0.0.0",
"typescript": "^4.9.5"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareHandler } from "next-app-middleware/runtime";
import { MiddlewareHandler } from "@cxnpl/next-app-middleware/runtime";

const middleware: MiddlewareHandler<{ theme: string; user: string }> = (
req
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/app/with-middleware/[theme]/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareHandler } from "next-app-middleware/runtime";
import { MiddlewareHandler } from "@cxnpl/next-app-middleware/runtime";

const middleware: MiddlewareHandler<{ theme: string }> = (req) => {
console.log("middleware", req.params.theme);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RedirectHandler } from "next-app-middleware/runtime";
import type { RedirectHandler } from "@cxnpl/next-app-middleware/runtime";

const redirect: RedirectHandler<{ theme: string }> = () => {
return "/";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RewriteHandler } from "next-app-middleware/runtime";
import type { RewriteHandler } from "@cxnpl/next-app-middleware/runtime";

const rewrite: RewriteHandler<{ theme: string }> = ({ params: { theme } }) => {
return "/" + theme;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareHandler } from "next-app-middleware/runtime";
import { MiddlewareHandler } from "@cxnpl/next-app-middleware/runtime";

const middleware: MiddlewareHandler<{ slug: string[] }> = (req) => {
console.log("middleware", req.params.slug);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareHandler } from "next-app-middleware/runtime";
import { MiddlewareHandler } from "@cxnpl/next-app-middleware/runtime";

const middleware: MiddlewareHandler<{ slug2: string[] }> = (req) => {
console.log("...slug2", req.params.slug2);
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/app/with-middleware/forward.dynamic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DynamicForwarder } from "next-app-middleware/runtime";
import { DynamicForwarder } from "@cxnpl/next-app-middleware/runtime";

export const theme: DynamicForwarder = (req, res) => {
const themeCookie = req.cookies.get("__theme");
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/app/with-middleware/forward.static.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { StaticForwarder } from "next-app-middleware/runtime";
import { StaticForwarder } from "@cxnpl/next-app-middleware/runtime";

export const hosted: StaticForwarder = () => {
return true;
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/app/with-middleware/js/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MiddlewareHandler } from "next-app-middleware/runtime";
import { MiddlewareHandler } from "@cxnpl/next-app-middleware/runtime";

const middleware: MiddlewareHandler = (req) => {
console.log("middleware", req.url);
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/middleware.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {
ErrorHook,
GenericHook,
ParamsHook,
} from "next-app-middleware/runtime";
} from "@cxnpl/next-app-middleware/runtime";
import { NextResponse } from "next/server";

export const response: ResponseHook = (res) => {
Expand Down
5 changes: 1 addition & 4 deletions examples/basic/next.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* eslint-disable @typescript-eslint/no-var-requires */
// @ts-check
const { withMiddleware } = require("next-app-middleware");
const { withMiddleware } = require("@cxnpl/next-app-middleware");

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
appDir: true,
},
};

module.exports = withMiddleware(nextConfig);
6 changes: 3 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@next-app-middleware/basic-example",
"name": "@cxnpl/next-app-middleware-basic-example",
"version": "0.0.0",
"private": true,
"scripts": {
Expand All @@ -12,7 +12,7 @@
"@types/react": "18.0.26",
"@types/react-dom": "18.0.9",
"eslint": "8.29.0",
"next": "latest",
"next": "14.1.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "4.9.3"
Expand All @@ -21,6 +21,6 @@
"@types/node": "^17.0.45",
"eslint-config-next": "13.1.6",
"eslint-config-ts": "workspace:^0.0.0",
"next-app-middleware": "workspace:0.0.0"
"@cxnpl/next-app-middleware": "workspace:0.0.0"
}
}
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@whopio/next-app-middleware",
"name": "@cxnpl/next-app-middleware",
"version": "0.0.5",
"private": true,
"scripts": {
Expand All @@ -18,8 +18,7 @@
"node": ">=14.0.0"
},
"resolutions": {
"next": "13.2.4",
"eslint-config-next": "13.2.4"
},
"packageManager": "pnpm@7.13.6"
"packageManager": "pnpm@9.3.0+sha256.e1f9e8d1a16607a46dd3c158b5f7a7dc7945501d1c6222d454d63d033d1d918f"
}
1 change: 0 additions & 1 deletion packages/codegen/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
src
.turbo
tsconfig.json
.unimportedrc.json
4 changes: 0 additions & 4 deletions packages/codegen/.unimportedrc.json

This file was deleted.

4 changes: 2 additions & 2 deletions packages/codegen/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @next-app-middleware/codegen
# @cxnpl/next-app-middleware-codegen

Code-generator for `next-app-middleware`
Code-generator for `@cxnpl/next-app-middleware`
8 changes: 4 additions & 4 deletions packages/codegen/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@next-app-middleware/codegen",
"name": "@cxnpl/next-app-middleware-codegen",
"version": "0.0.0",
"description": "",
"private": false,
"main": "dist/index.js",
"types": "dist/index.d.ts",
"repository": "whopio/next-app-middleware",
"bugs": "https://github.com/whopio/next-app-middleware/issues",
"repository": "cxnpl-forks/next-app-middleware",
"bugs": "https://github.com/cxnpl-forks/next-app-middleware/issues",
"scripts": {
"bundle": "tsup ./src/index.ts --format cjs --dts",
"build": "pnpm run bundle --minify",
Expand All @@ -17,7 +17,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@next-app-middleware/runtime": "workspace:0.0.0",
"@cxnpl/next-app-middleware-runtime": "workspace:0.0.0",
"@swc/core": "^1.3.21",
"chokidar": "^3.5.3",
"fs-extra": "^11.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/build/eject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
Branch,
BranchTypes,
PathSegmentSwitch,
} from "@next-app-middleware/runtime/dist/router/ejected";
} from "@cxnpl/next-app-middleware-runtime/dist/router/ejected";
import { FlattenedRoute, RouteTypes, SegmentLayout } from "../types";

type MatcherMap = Map<string, FlattenedRoute | MatcherMap | true>;
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
Imports,
renderRouter,
} from "@next-app-middleware/runtime/dist/router/ejected";
} from "@cxnpl/next-app-middleware-runtime/dist/router/ejected";
import { transform } from "@swc/core";
import fse from "fs-extra";
import { join } from "path";
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/build/read-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RouterHooksConfig } from "@next-app-middleware/runtime/dist/router/ejected";
import { RouterHooksConfig } from "@cxnpl/next-app-middleware-runtime/dist/router/ejected";
import _glob from "glob";
import { promisify } from "util";
import logger from "../util/log";
Expand Down
1 change: 0 additions & 1 deletion packages/next-app-middleware/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
src
.turbo
tsconfig.json
.unimportedrc.json
3 changes: 0 additions & 3 deletions packages/next-app-middleware/.unimportedrc.json

This file was deleted.

Loading
Loading