Skip to content

Commit fbb52a4

Browse files
chore: move middleware support into separate package (#1520)
* chore: move middleware support into separate package * chore: add build command * ci: update release please to publish more packages Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 40cb8a9 commit fbb52a4

16 files changed

+87
-32
lines changed

.github/workflows/release-please.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ jobs:
2828
if: ${{ steps.release.outputs.releases_created }}
2929
- name: Install dependencies
3030
run: CI=1 npm ci
31-
working-directory: plugin
32-
if: ${{ steps.release.outputs.releases_created }}
33-
- run: npm publish
34-
working-directory: plugin
3531
if: ${{ steps.release.outputs.releases_created }}
32+
- run: npm publish packages/runtime/
33+
if: ${{ steps.release.outputs['packages/runtime--version'] }}
34+
env:
35+
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
36+
- run: npm publish packages/next/
37+
if: ${{ steps.release.outputs['packages/next--version'] }}
3638
env:
3739
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
3840
- uses: netlify/submit-build-plugin-action@v1
39-
if: ${{ steps.release.outputs.releases_created }}
41+
if: ${{ steps.release.outputs['packages/runtime--version'] }}
4042
with:
4143
github-token: ${{ steps.get-token.outputs.token }}
42-
package-json-dir: plugin
44+
package-json-dir: packages/runtime

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@ Temporary Items
146146
.netlify
147147
demos/default/.next
148148
.parcel-cache
149-
packages/runtime/lib
150-
packages/runtime/dist-types
149+
packages/*/lib
151150

152151
# Cypress
153152
cypress/screenshots

demos/middleware/middleware.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NextResponse } from 'next/server'
22
import type { NextRequest } from 'next/server'
33

4-
import { MiddlewareRequest } from '@netlify/plugin-nextjs/middleware'
4+
import { MiddlewareRequest } from '@netlify/next'
55

66
export async function middleware(req: NextRequest) {
77
let response

demos/middleware/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dependencies": {
1212
"@netlify/plugin-nextjs": "*",
13+
"@netlify/next": "*",
1314
"next": "^12.2.0",
1415
"react": "18.0.0",
1516
"react-dom": "18.0.0"

package-lock.json

+19-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"format:check-fix:prettier": "run-e format:check:prettier format:fix:prettier",
1515
"format:check:prettier": "cross-env-shell prettier --check $npm_package_config_prettier",
1616
"format:fix:prettier": "cross-env-shell prettier --write $npm_package_config_prettier",
17-
"build": "npm run -w @netlify/plugin-nextjs build",
17+
"build": "npm run build -w packages/next -w packages/runtime",
1818
"postinstall": "run-s build install-husky",
1919
"install-husky": "if-env CI=1 || husky install node_modules/@netlify/eslint-config-node/.husky",
2020
"test": "run-s build:demo test:jest",

packages/next/package.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@netlify/next",
3+
"version": "0.0.1",
4+
"description": "Enhanced Next.js features on Netlify",
5+
"main": "lib/index.js",
6+
"files": [
7+
"lib/**/*"
8+
],
9+
"devDependencies": {
10+
"@types/node": "^17.0.25",
11+
"next": "^12.2.0",
12+
"npm-run-all": "^4.1.5",
13+
"typescript": "^4.6.3"
14+
},
15+
"scripts": {
16+
"prepublishOnly": "run-s clean build",
17+
"clean": "rimraf lib",
18+
"build": "tsc",
19+
"watch": "tsc --watch",
20+
"prepare": "npm run build"
21+
},
22+
"peerDependencies": {
23+
"next": ">=12.2.0"
24+
},
25+
"repository": {
26+
"type": "git",
27+
"url": "git+https://github.com/netlify/netlify-plugin-nextjs.git"
28+
},
29+
"author": "",
30+
"license": "MIT",
31+
"bugs": {
32+
"url": "https://github.com/netlify/netlify-plugin-nextjs/issues"
33+
},
34+
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
35+
"engines": {
36+
"node": ">=12.0.0"
37+
}
38+
}

packages/next/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './middleware'

packages/runtime/src/middleware/request.ts renamed to packages/next/src/middleware/request.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NextURL } from 'next/dist/server/web/next-url'
1+
import type { NextURL } from 'next/dist/server/web/next-url'
22
import { NextResponse } from 'next/server'
33
import type { NextRequest } from 'next/server'
44

packages/next/tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"declaration": true /* Generates corresponding '.d.ts' file. */,
5+
"outDir": "./lib" /* Redirect output structure to the directory. */,
6+
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
7+
},
8+
"include": [
9+
"src/**/*.ts",
10+
"src/**/*.js"
11+
]
12+
}

packages/runtime/package.json

+2-14
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,8 @@
66
"files": [
77
"lib/**/*",
88
"src/templates/edge/*",
9-
"manifest.yml",
10-
"middleware.js"
9+
"manifest.yml"
1110
],
12-
"typesVersions": {
13-
"*": {
14-
"middleware": [
15-
"dist-types/middleware"
16-
]
17-
}
18-
},
19-
"exports": {
20-
".": "./lib/index.js",
21-
"./middleware": "./lib/middleware/index.js"
22-
},
2311
"dependencies": {
2412
"@netlify/functions": "^1.0.0",
2513
"@netlify/ipx": "^1.2.0",
@@ -66,7 +54,7 @@
6654
"url": "git+https://github.com/netlify/netlify-plugin-nextjs.git"
6755
},
6856
"author": "",
69-
"license": "ISC",
57+
"license": "MIT",
7058
"bugs": {
7159
"url": "https://github.com/netlify/netlify-plugin-nextjs/issues"
7260
},

packages/runtime/tsconfig.json

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"outDir": "./lib" /* Redirect output structure to the directory. */,
5-
"declaration": true /* Generates corresponding '.d.ts' file. */,
6-
"declarationDir": "./dist-types",
75
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
86
},
97
"include": [

release-please-config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"bootstrap-sha": "62a4ce414f5b02f539902f88dd4b548df5cfa8ef",
33
"packages": {
4-
"packages/runtime": {}
4+
"packages/runtime": {},
5+
"packages/next": {}
56
}
67
}

0 commit comments

Comments
 (0)