@netlify/plugin-nextjs 4.33.0 → 4.33.1-lazy-server-import.0

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.
@@ -11,13 +11,14 @@ const path = require('path');
11
11
  const { URLSearchParams, URL } = require('url');
12
12
  const { Bridge } = require('@vercel/node-bridge/bridge');
13
13
  const { augmentFsModule, getMaxAge, getMultiValueHeaders, getPrefetchResponse, normalizePath, } = require('./handlerUtils');
14
- const { NetlifyNextServer } = require('./server');
15
14
  // We return a function and then call `toString()` on it to serialise it as the launcher function
16
15
  // eslint-disable-next-line max-params, max-lines-per-function
17
16
  const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') => {
18
17
  var _a;
19
18
  // Change working directory into the site root, unless using Nx, which moves the
20
19
  // dist directory and handles this itself
20
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
21
+ const { NetlifyNextServer } = require('./server');
21
22
  const dir = path.resolve(__dirname, app);
22
23
  if (pageRoot.startsWith(dir)) {
23
24
  process.chdir(dir);
@@ -145,7 +146,6 @@ const getHandler = ({ isODB = false, publishDir = '../../../.next', appDir = '..
145
146
  // We copy the file here rather than requiring from the node module
146
147
  const { Bridge } = require("./bridge");
147
148
  const { augmentFsModule, getMaxAge, getMultiValueHeaders, getPrefetchResponse, getNextServer, normalizePath } = require('./handlerUtils')
148
- const { NetlifyNextServer } = require('./server')
149
149
 
150
150
  ${isODB ? `const { builder } = require("@netlify/functions")` : ''}
151
151
  const { config } = require("${publishDir}/required-server-files.json")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.33.0",
3
+ "version": "4.33.1-lazy-server-import.0",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@delucis/if-env": "^1.1.2",
40
- "@netlify/build": "^29.7.1",
40
+ "@netlify/build": "^29.9.0",
41
41
  "@types/fs-extra": "^9.0.13",
42
42
  "@types/jest": "^27.4.1",
43
43
  "@types/merge-stream": "^1.1.2",
@@ -1,14 +1,18 @@
1
1
  import type { EdgeFunction } from 'https://edge.netlify.com'
2
2
 
3
+ // These are copied from next/dist/build. This file gets copied as part of the next
4
+ // runtime build and can't reference the next package directly.
5
+ //
6
+ // Latest types at https://github.com/vercel/next.js/blob/4a2df3c3752aeddc50fd5ab053440eccf71ae50b/packages/next/src/build/index.ts#L140
3
7
  export declare type SsgRoute = {
4
8
  initialRevalidateSeconds: number | false
5
9
  srcRoute: string | null
6
- dataRoute: string
10
+ dataRoute: string | null
7
11
  }
8
12
  export declare type DynamicSsgRoute = {
9
13
  routeRegex: string
10
14
  fallback: string | null | false
11
- dataRoute: string
15
+ dataRoute: string | null
12
16
  dataRouteRegex: string
13
17
  }
14
18
  export declare type PrerenderManifest = {
@@ -35,7 +39,7 @@ const rscifyPath = (route: string) => {
35
39
  export const getRscDataRouter = ({ routes: staticRoutes, dynamicRoutes }: PrerenderManifest): EdgeFunction => {
36
40
  const staticRouteSet = new Set(
37
41
  Object.entries(staticRoutes)
38
- .filter(([, { dataRoute }]) => dataRoute.endsWith('.rsc'))
42
+ .filter(([, { dataRoute }]) => dataRoute?.endsWith('.rsc'))
39
43
  .map(([route]) => route),
40
44
  )
41
45
 
@@ -57,10 +57,15 @@ export const addMiddlewareHeaders = async (
57
57
  return response
58
58
  }
59
59
 
60
+ interface ResponseCookies {
61
+ readonly _headers: Headers
62
+ }
63
+
60
64
  interface MiddlewareResponse extends Response {
61
65
  originResponse: Response
62
66
  dataTransforms: NextDataTransform[]
63
67
  elementHandlers: Array<[selector: string, handlers: ElementHandlers]>
68
+ get cookies(): ResponseCookies
64
69
  }
65
70
 
66
71
  interface MiddlewareRequest {
@@ -184,6 +189,12 @@ export const buildResponse = async ({
184
189
  if (request.method === 'HEAD' || request.method === 'OPTIONS') {
185
190
  return response.originResponse
186
191
  }
192
+
193
+ // NextResponse doesn't set cookies onto the originResponse, so we need to copy them over
194
+ if (response.cookies._headers.has('set-cookie')) {
195
+ response.originResponse.headers.set('set-cookie', response.cookies._headers.get('set-cookie')!)
196
+ }
197
+
187
198
  // If it's JSON we don't need to use the rewriter, we can just parse it
188
199
  if (response.originResponse.headers.get('content-type')?.includes('application/json')) {
189
200
  const props = await response.originResponse.json()