Skip to content

Commit d39ce27

Browse files
authored
feat: add support for Edge Functions (#1310)
* refactor: move into npm workspace * fix: correct tsconfig * chore: use plugin wrapper * ci: always install using latest node * feat: add edge support * chore: don't use Next to lint demos * fix: remove image redirect if using edge * chore: move plugin into subdirectory * chore: fix workspace * chore: fix test * chore: add typescript devdep * fix: switch to early return for static assets * chore: remove npmrc * chore: update name * chore: fix template path * chore: revert unneeded changes * ci: fix test script * chore: regenerate package-lock * chore: dedupe react * chore: update demos * chore: more devdeps for demos * chore: add dep on plugin
1 parent 78ec8e7 commit d39ce27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+8608
-6407
lines changed

.eslintignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
node_modules
33
test
44
lib
5-
demos
5+
demos
6+
plugin/src/templates/edge

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module.exports = {
1515
'node/exports-style': 0,
1616
'node/global-require': 0,
1717
'node/prefer-global/process': 0,
18+
// Allow a single word inline so that it can do language tags for syntax highlighting
19+
// ['error', { ignorePattern: /^ (\w+) $/ }],
20+
'no-inline-comments': 0,
1821
'no-magic-numbers': 0,
1922
'no-param-reassign': 0,
2023
'no-promise-executor-return': 0,

.github/workflows/test.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ jobs:
2727
- uses: actions/checkout@v2
2828
- name: Installing with latest Node.js
2929
uses: actions/setup-node@v2
30-
if: "${{ matrix.node-version != '*' }}"
3130
with:
3231
node-version: '*'
3332
check-latest: true
3433
- name: NPM Install
35-
run: npm ci
34+
run: npm install
3635
- name: Switching to Node.js ${{ matrix.node-version }} to run tests
3736
uses: actions/setup-node@v2
3837
if: "${{ matrix.node-version != '*' }}"
@@ -64,12 +63,11 @@ jobs:
6463
- uses: actions/checkout@v2
6564
- name: Installing with latest Node.js
6665
uses: actions/setup-node@v2
67-
if: "${{ matrix.node-version != '*' }}"
6866
with:
6967
node-version: '*'
7068
check-latest: true
7169
- name: NPM Install
72-
run: npm ci
70+
run: npm install
7371
- name: Install Next.js Canary
7472
run: npm install -D next@canary --legacy-peer-deps
7573
- name: Switching to Node.js ${{ matrix.node-version }} to run tests

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ node_modules
2020
# Test
2121
lib
2222
tsconfig.json
23-
demos/nx-next-monorepo-demo
23+
demos/nx-next-monorepo-demo
24+
plugin/src/templates/edge

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"deno.enablePaths": [
3+
"plugin/src/templates/edge",
4+
"demos/middleware/.netlify/edge-functions",
5+
"demos/server-components/.netlify/edge-functions",
6+
],
7+
"deno.unstable": true,
8+
"deno.importMap": "demos/server-components/.netlify/edge-functions-import-map.json"
9+
}

demos/base-path/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"description": "",
55
"devDependencies": {
66
"@netlify/plugin-nextjs": "*",
7+
"@types/fs-extra": "^9.0.13",
8+
"@types/jest": "^27.4.1",
9+
"@types/node": "^17.0.25",
710
"husky": "^7.0.4",
811
"if-env": "^1.0.4",
912
"npm-run-all": "^4.1.5",

demos/default/package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"description": "",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"build": "next build"
88
},
99
"repository": {
1010
"type": "git",
@@ -18,10 +18,15 @@
1818
"homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
1919
"dependencies": {
2020
"@reach/dialog": "^0.16.2",
21-
"@reach/visually-hidden": "^0.16.0"
21+
"@reach/visually-hidden": "^0.16.0",
22+
"react": "^18.0.0",
23+
"react-dom": "^18.0.0"
2224
},
2325
"devDependencies": {
2426
"@netlify/plugin-nextjs": "*",
27+
"@types/fs-extra": "^9.0.13",
28+
"@types/jest": "^27.4.1",
29+
"@types/node": "^17.0.25",
2530
"husky": "^7.0.4",
2631
"if-env": "^1.0.4",
2732
"npm-run-all": "^4.1.5",

demos/middleware/.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel

demos/middleware/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with
2+
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
3+
4+
## Getting Started
5+
6+
First, run the development server:
7+
8+
```bash
9+
npm run dev
10+
# or
11+
yarn dev
12+
```
13+
14+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
15+
16+
You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the file.
17+
18+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on
19+
[http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.js`.
20+
21+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as
22+
[API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
23+
24+
## Learn More
25+
26+
To learn more about Next.js, take a look at the following resources:
27+
28+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
29+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

demos/middleware/netlify.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[build]
2+
command = "npm run build"
3+
publish = ".next"
4+
5+
[environment]
6+
NEXT_USE_NETLIFY_EDGE = "true"
7+
8+
[[plugins]]
9+
package = "../plugin-wrapper/"
10+
11+
# This is a fake plugin, that makes it run npm install
12+
[[plugins]]
13+
package = "@netlify/plugin-local-install-core"
14+
15+
[functions]
16+
included_files = [
17+
"!node_modules/sharp/vendor/8.12.2/darwin-*/**/*",
18+
"!node_modules/sharp/build/Release/sharp-darwin-*"
19+
]
20+
21+
[dev]
22+
framework = "#static"

0 commit comments

Comments
 (0)