@netlify/plugin-nextjs 4.17.1-runtime.1 → 4.17.1-runtime.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/helpers/dev.js
CHANGED
|
@@ -11,15 +11,16 @@ const edge_1 = require("./edge");
|
|
|
11
11
|
const files_1 = require("./files");
|
|
12
12
|
// The types haven't been updated yet
|
|
13
13
|
const onPreDev = async ({ constants, netlifyConfig }) => {
|
|
14
|
+
var _a;
|
|
15
|
+
const base = (_a = netlifyConfig.build.base) !== null && _a !== void 0 ? _a : process.cwd();
|
|
14
16
|
// Need to patch the files, because build might not have been run
|
|
15
|
-
await (0, files_1.patchNextFiles)(
|
|
17
|
+
await (0, files_1.patchNextFiles)(base);
|
|
16
18
|
// Clean up old functions
|
|
17
19
|
await (0, fs_extra_1.unlink)((0, path_1.resolve)('.netlify', 'middleware.js')).catch(() => {
|
|
18
20
|
// Ignore if it doesn't exist
|
|
19
21
|
});
|
|
20
22
|
await (0, edge_1.writeDevEdgeFunction)(constants);
|
|
21
|
-
if (!(0, fs_extra_1.existsSync)((0, path_1.resolve)(
|
|
22
|
-
!(0, fs_extra_1.existsSync)((0, path_1.resolve)(netlifyConfig.build.base, 'middleware.js'))) {
|
|
23
|
+
if (!(0, fs_extra_1.existsSync)((0, path_1.resolve)(base, 'middleware.ts')) && !(0, fs_extra_1.existsSync)((0, path_1.resolve)(base, 'middleware.js'))) {
|
|
23
24
|
console.log("No middleware found. Create a 'middleware.ts' or 'middleware.js' file in your project root to add custom middleware.");
|
|
24
25
|
}
|
|
25
26
|
else {
|
|
@@ -32,8 +33,8 @@ const onPreDev = async ({ constants, netlifyConfig }) => {
|
|
|
32
33
|
`--format=esm`,
|
|
33
34
|
'--watch',
|
|
34
35
|
// Watch for both, because it can have either ts or js
|
|
35
|
-
(0, path_1.resolve)(
|
|
36
|
-
(0, path_1.resolve)(
|
|
36
|
+
(0, path_1.resolve)(base, 'middleware.ts'),
|
|
37
|
+
(0, path_1.resolve)(base, 'middleware.js'),
|
|
37
38
|
]);
|
|
38
39
|
childProcess.stdout.pipe(process.stdout);
|
|
39
40
|
childProcess.stderr.pipe(process.stderr);
|
package/lib/helpers/edge.js
CHANGED
|
@@ -82,7 +82,7 @@ const writeDevEdgeFunction = async ({ INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/ed
|
|
|
82
82
|
await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionRoot, 'manifest.json'), manifest);
|
|
83
83
|
const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'next-dev');
|
|
84
84
|
await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
|
|
85
|
-
await copyEdgeSourceFile({ edgeFunctionDir, file: 'next-dev.
|
|
85
|
+
await copyEdgeSourceFile({ edgeFunctionDir, file: 'next-dev.js', target: 'index.js' });
|
|
86
86
|
await copyEdgeSourceFile({ edgeFunctionDir, file: 'utils.ts' });
|
|
87
87
|
};
|
|
88
88
|
exports.writeDevEdgeFunction = writeDevEdgeFunction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.17.1-runtime.
|
|
3
|
+
"version": "4.17.1-runtime.4",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@delucis/if-env": "^1.1.2",
|
|
33
|
-
"@netlify/build": "^27.
|
|
33
|
+
"@netlify/build": "^27.15.0",
|
|
34
34
|
"@types/fs-extra": "^9.0.13",
|
|
35
35
|
"@types/jest": "^27.4.1",
|
|
36
36
|
"@types/node": "^17.0.25",
|
|
@@ -1,81 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { fromFileUrl } from 'https://deno.land/std/path/mod.ts'
|
|
1
|
+
import { NextRequest } from 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js'
|
|
2
|
+
import { NextResponse } from 'https://esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js'
|
|
3
|
+
import { fromFileUrl } from 'https://deno.land/std@0.151.0/path/mod.ts'
|
|
4
4
|
import { buildResponse } from './utils.ts'
|
|
5
5
|
|
|
6
|
-
export interface FetchEventResult {
|
|
7
|
-
response: Response
|
|
8
|
-
waitUntil: Promise<unknown>
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
interface I18NConfig {
|
|
12
|
-
defaultLocale: string
|
|
13
|
-
domains?: DomainLocale[]
|
|
14
|
-
localeDetection?: false
|
|
15
|
-
locales: string[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface DomainLocale {
|
|
19
|
-
defaultLocale: string
|
|
20
|
-
domain: string
|
|
21
|
-
http?: true
|
|
22
|
-
locales?: string[]
|
|
23
|
-
}
|
|
24
|
-
export interface NextRequestInit extends RequestInit {
|
|
25
|
-
geo?: {
|
|
26
|
-
city?: string
|
|
27
|
-
country?: string
|
|
28
|
-
region?: string
|
|
29
|
-
}
|
|
30
|
-
ip?: string
|
|
31
|
-
nextConfig?: {
|
|
32
|
-
basePath?: string
|
|
33
|
-
i18n?: I18NConfig | null
|
|
34
|
-
trailingSlash?: boolean
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface RequestData {
|
|
39
|
-
geo?: {
|
|
40
|
-
city?: string
|
|
41
|
-
country?: string
|
|
42
|
-
region?: string
|
|
43
|
-
latitude?: string
|
|
44
|
-
longitude?: string
|
|
45
|
-
}
|
|
46
|
-
headers: Record<string, string>
|
|
47
|
-
ip?: string
|
|
48
|
-
method: string
|
|
49
|
-
nextConfig?: {
|
|
50
|
-
basePath?: string
|
|
51
|
-
i18n?: Record<string, unknown>
|
|
52
|
-
trailingSlash?: boolean
|
|
53
|
-
}
|
|
54
|
-
page?: {
|
|
55
|
-
name?: string
|
|
56
|
-
params?: { [key: string]: string }
|
|
57
|
-
}
|
|
58
|
-
url: string
|
|
59
|
-
body?: ReadableStream<Uint8Array>
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export interface RequestContext {
|
|
63
|
-
request: Request
|
|
64
|
-
context: Context
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare global {
|
|
68
|
-
// deno-lint-ignore no-var
|
|
69
|
-
var NFRequestContextMap: Map<string, RequestContext>
|
|
70
|
-
// deno-lint-ignore no-var
|
|
71
|
-
var __dirname: string
|
|
72
|
-
}
|
|
73
|
-
|
|
74
6
|
globalThis.NFRequestContextMap ||= new Map()
|
|
75
7
|
globalThis.__dirname = fromFileUrl(new URL('./', import.meta.url)).slice(0, -1)
|
|
76
8
|
|
|
77
9
|
// Check if a file exists, given a relative path
|
|
78
|
-
const exists = async (relativePath
|
|
10
|
+
const exists = async (relativePath) => {
|
|
79
11
|
const path = fromFileUrl(new URL(relativePath, import.meta.url))
|
|
80
12
|
try {
|
|
81
13
|
await Deno.stat(path)
|
|
@@ -87,8 +19,9 @@ const exists = async (relativePath: string) => {
|
|
|
87
19
|
throw error
|
|
88
20
|
}
|
|
89
21
|
}
|
|
22
|
+
let idx = 0
|
|
90
23
|
|
|
91
|
-
const handler = async (req
|
|
24
|
+
const handler = async (req, context) => {
|
|
92
25
|
// Uncomment when CLI update lands
|
|
93
26
|
// if (!Deno.env.get('NETLIFY_DEV')) {
|
|
94
27
|
// // Only run in dev
|
|
@@ -102,8 +35,9 @@ const handler = async (req: Request, context: Context) => {
|
|
|
102
35
|
// because that would also throw if there's an error in the middleware,
|
|
103
36
|
// which we would want to surface not ignore.
|
|
104
37
|
if (await exists('../../middleware.js')) {
|
|
105
|
-
//
|
|
106
|
-
|
|
38
|
+
// We need to cache-bust the import because otherwise it will claim it
|
|
39
|
+
// doesn't exist if the user creates it after the server starts
|
|
40
|
+
const nextMiddleware = await import(`../../middleware.js#${idx++}`)
|
|
107
41
|
middleware = nextMiddleware.middleware
|
|
108
42
|
} else {
|
|
109
43
|
// No middleware, so we silently return
|
|
@@ -111,7 +45,7 @@ const handler = async (req: Request, context: Context) => {
|
|
|
111
45
|
}
|
|
112
46
|
|
|
113
47
|
// This is the format expected by Next.js
|
|
114
|
-
const geo
|
|
48
|
+
const geo = {
|
|
115
49
|
country: context.geo.country?.code,
|
|
116
50
|
region: context.geo.subdivision?.code,
|
|
117
51
|
city: context.geo.city,
|
|
@@ -125,7 +59,7 @@ const handler = async (req: Request, context: Context) => {
|
|
|
125
59
|
context,
|
|
126
60
|
})
|
|
127
61
|
|
|
128
|
-
const request
|
|
62
|
+
const request = {
|
|
129
63
|
headers: Object.fromEntries(req.headers.entries()),
|
|
130
64
|
geo,
|
|
131
65
|
method: req.method,
|
|
@@ -133,7 +67,7 @@ const handler = async (req: Request, context: Context) => {
|
|
|
133
67
|
body: req.body || undefined,
|
|
134
68
|
}
|
|
135
69
|
|
|
136
|
-
const nextRequest
|
|
70
|
+
const nextRequest = new NextRequest(req, request)
|
|
137
71
|
|
|
138
72
|
try {
|
|
139
73
|
const response = await middleware(nextRequest)
|