@netlify/plugin-nextjs 4.23.2 → 4.23.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.
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.enableEdgeInNextConfig = exports.writeEdgeFunctions = exports.writeDevEdgeFunction = exports.cleanupEdgeFunctions = exports.loadMiddlewareManifest = void 0;
4
7
  /* eslint-disable max-lines */
5
8
  const fs_1 = require("fs");
6
9
  const path_1 = require("path");
10
+ const chalk_1 = require("chalk");
11
+ const destr_1 = __importDefault(require("destr"));
7
12
  const fs_extra_1 = require("fs-extra");
13
+ const outdent_1 = require("outdent");
14
+ const config_1 = require("./config");
8
15
  const loadMiddlewareManifest = (netlifyConfig) => {
9
16
  const middlewarePath = (0, path_1.resolve)(netlifyConfig.build.publish, 'server', 'middleware-manifest.json');
10
17
  if (!(0, fs_1.existsSync)(middlewarePath)) {
@@ -106,8 +113,12 @@ const writeEdgeFunctions = async (netlifyConfig) => {
106
113
  };
107
114
  const edgeFunctionRoot = (0, path_1.resolve)('.netlify', 'edge-functions');
108
115
  await (0, fs_extra_1.emptyDir)(edgeFunctionRoot);
116
+ const { publish } = netlifyConfig.build;
117
+ const nextConfigFile = await (0, config_1.getRequiredServerFiles)(publish);
118
+ const nextConfig = nextConfigFile.config;
109
119
  await (0, fs_extra_1.copy)(getEdgeTemplatePath('../edge-shared'), (0, path_1.join)(edgeFunctionRoot, 'edge-shared'));
110
- if (!process.env.NEXT_DISABLE_EDGE_IMAGES) {
120
+ await (0, fs_extra_1.writeJSON)((0, path_1.join)(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig);
121
+ if (!(0, destr_1.default)(process.env.NEXT_DISABLE_EDGE_IMAGES) && !(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
111
122
  console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
112
123
  const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
113
124
  await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
@@ -118,13 +129,15 @@ const writeEdgeFunctions = async (netlifyConfig) => {
118
129
  path: '/_next/image*',
119
130
  });
120
131
  }
121
- if (process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1') {
132
+ if (!(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
122
133
  const middlewareManifest = await (0, exports.loadMiddlewareManifest)(netlifyConfig);
123
134
  if (!middlewareManifest) {
124
135
  console.error("Couldn't find the middleware manifest");
125
136
  return;
126
137
  }
138
+ let usesEdge = false;
127
139
  for (const middleware of middlewareManifest.sortedMiddleware) {
140
+ usesEdge = true;
128
141
  const edgeFunctionDefinition = middlewareManifest.middleware[middleware];
129
142
  const functionDefinitions = await writeEdgeFunction({
130
143
  edgeFunctionDefinition,
@@ -137,6 +150,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
137
150
  // No, the version field was not incremented
138
151
  if (typeof middlewareManifest.functions === 'object') {
139
152
  for (const edgeFunctionDefinition of Object.values(middlewareManifest.functions)) {
153
+ usesEdge = true;
140
154
  const functionDefinitions = await writeEdgeFunction({
141
155
  edgeFunctionDefinition,
142
156
  edgeFunctionRoot,
@@ -145,6 +159,12 @@ const writeEdgeFunctions = async (netlifyConfig) => {
145
159
  manifest.functions.push(...functionDefinitions);
146
160
  }
147
161
  }
162
+ if (usesEdge) {
163
+ console.log((0, outdent_1.outdent) `
164
+ ✨ Deploying middleware and functions to ${(0, chalk_1.greenBright) `Netlify Edge Functions`} ✨
165
+ This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
166
+ `);
167
+ }
148
168
  }
149
169
  await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionRoot, 'manifest.json'), manifest);
150
170
  };
package/lib/index.js CHANGED
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  /* eslint-disable max-lines */
4
7
  const path_1 = require("path");
5
8
  const chalk_1 = require("chalk");
9
+ const destr_1 = __importDefault(require("destr"));
6
10
  const fs_extra_1 = require("fs-extra");
7
11
  const outdent_1 = require("outdent");
8
12
  const constants_1 = require("./constants");
@@ -46,26 +50,23 @@ const plugin = {
46
50
  });
47
51
  await (0, edge_1.cleanupEdgeFunctions)(constants);
48
52
  const middlewareManifest = await (0, edge_1.loadMiddlewareManifest)(netlifyConfig);
49
- let usingEdge = false;
50
- if ((middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.functions) && Object.keys(middlewareManifest.functions).length !== 0) {
51
- usingEdge = true;
52
- if (process.env.NEXT_DISABLE_NETLIFY_EDGE === 'true' || process.env.NEXT_DISABLE_NETLIFY_EDGE === '1') {
53
- failBuild((0, outdent_1.outdent) `
54
- You are using Next.js experimental edge runtime, but have set NEXT_DISABLE_NETLIFY_EDGE to true. This is not supported.
55
- To use edge runtime, remove the env var ${(0, chalk_1.bold) `NEXT_DISABLE_NETLIFY_EDGE`} or set it to false.
56
- `);
57
- }
53
+ if ((middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.functions) &&
54
+ Object.keys(middlewareManifest.functions).length !== 0 &&
55
+ (0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
56
+ failBuild((0, outdent_1.outdent) `
57
+ You are using Next.js experimental edge runtime, but have set NEXT_DISABLE_NETLIFY_EDGE to true. This is not supported.
58
+ To use edge runtime, remove the env var ${(0, chalk_1.bold) `NEXT_DISABLE_NETLIFY_EDGE`}.
59
+ `);
58
60
  }
59
- if ((middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.middleware) && Object.keys(middlewareManifest.middleware).length !== 0) {
60
- usingEdge = true;
61
- if (process.env.NEXT_DISABLE_NETLIFY_EDGE === 'true' || process.env.NEXT_DISABLE_NETLIFY_EDGE === '1') {
62
- console.log((0, chalk_1.redBright)((0, outdent_1.outdent) `
63
- You are using Next.js Middleware without Netlify Edge Functions.
64
- This is deprecated because it negatively affects performance and will disable ISR and static rendering.
65
- It also disables advanced middleware features from @netlify/next
66
- To get the best performance and use Netlify Edge Functions, remove the env var ${(0, chalk_1.bold) `NEXT_DISABLE_NETLIFY_EDGE`} or set it to false.
67
- `));
68
- }
61
+ if ((middlewareManifest === null || middlewareManifest === void 0 ? void 0 : middlewareManifest.middleware) &&
62
+ Object.keys(middlewareManifest.middleware).length !== 0 &&
63
+ (0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
64
+ console.log((0, chalk_1.redBright)((0, outdent_1.outdent) `
65
+ You are using Next.js Middleware without Netlify Edge Functions.
66
+ This is deprecated because it negatively affects performance and will disable ISR and static rendering.
67
+ It also disables advanced middleware features from @netlify/next
68
+ To get the best performance and use Netlify Edge Functions, remove the env var ${(0, chalk_1.bold) `NEXT_DISABLE_NETLIFY_EDGE`}.
69
+ `));
69
70
  }
70
71
  if ((0, utils_1.isNextAuthInstalled)()) {
71
72
  const config = await (0, config_1.getRequiredServerFiles)(publish);
@@ -93,7 +94,7 @@ const plugin = {
93
94
  await (0, functions_1.generatePagesResolver)({ target, constants });
94
95
  await (0, files_1.movePublicFiles)({ appDir, outdir, publish });
95
96
  await (0, files_1.patchNextFiles)(basePath);
96
- if (!process.env.SERVE_STATIC_FILES_FROM_ORIGIN) {
97
+ if (!(0, destr_1.default)(process.env.SERVE_STATIC_FILES_FROM_ORIGIN)) {
97
98
  await (0, files_1.moveStaticPages)({ target, netlifyConfig, i18n, basePath });
98
99
  }
99
100
  await (0, redirects_1.generateStaticRedirects)({
@@ -113,14 +114,7 @@ const plugin = {
113
114
  nextConfig: { basePath, i18n, trailingSlash, appDir },
114
115
  buildId,
115
116
  });
116
- if (usingEdge) {
117
- await (0, edge_1.writeEdgeFunctions)(netlifyConfig);
118
- await (0, edge_1.enableEdgeInNextConfig)(publish);
119
- console.log((0, outdent_1.outdent) `
120
- ✨ Deploying middleware and functions to ${(0, chalk_1.greenBright) `Netlify Edge Functions`} ✨
121
- This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
122
- `);
123
- }
117
+ await (0, edge_1.writeEdgeFunctions)(netlifyConfig);
124
118
  },
125
119
  async onPostBuild({ netlifyConfig: { build: { publish }, redirects, headers, }, utils: { status, cache, functions, build: { failBuild }, }, constants: { FUNCTIONS_DIST }, }) {
126
120
  await (0, cache_1.saveCache)({ cache, publish });
@@ -103,13 +103,13 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
103
103
  // Long-expiry TTL is basically no TTL, so we'll skip it
104
104
  if (ttl > 0 && ttl < ONE_YEAR_IN_SECONDS) {
105
105
  result.ttl = ttl;
106
- requestMode = 'isr';
106
+ requestMode = `odb ttl=${ttl}`;
107
107
  }
108
108
  }
109
109
  multiValueHeaders['cache-control'] = ['public, max-age=0, must-revalidate'];
110
110
  }
111
- multiValueHeaders['x-render-mode'] = [requestMode];
112
- console.log(`[${event.httpMethod}] ${event.path} (${requestMode === null || requestMode === void 0 ? void 0 : requestMode.toUpperCase()}${result.ttl > 0 ? ` ${result.ttl}s` : ''})`);
111
+ multiValueHeaders['x-nf-render-mode'] = [requestMode];
112
+ console.log(`[${event.httpMethod}] ${event.path} (${requestMode === null || requestMode === void 0 ? void 0 : requestMode.toUpperCase()})`);
113
113
  return {
114
114
  ...result,
115
115
  multiValueHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.23.2",
3
+ "version": "4.23.4",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -15,6 +15,7 @@
15
15
  "@netlify/ipx": "^1.2.5",
16
16
  "@vercel/node-bridge": "^2.1.0",
17
17
  "chalk": "^4.1.2",
18
+ "destr": "^1.1.1",
18
19
  "execa": "^5.1.1",
19
20
  "fs-extra": "^10.0.0",
20
21
  "globby": "^11.0.4",
@@ -63,4 +64,4 @@
63
64
  "engines": {
64
65
  "node": ">=12.0.0"
65
66
  }
66
- }
67
+ }
@@ -1,6 +1,7 @@
1
1
  import type { Context } from 'https://edge.netlify.com'
2
2
  // Available at build time
3
3
  import matchers from './matchers.json' assert { type: 'json' }
4
+ import nextConfig from '../edge-shared/nextConfig.json' assert { type: 'json' }
4
5
  import edgeFunction from './bundle.js'
5
6
  import { buildResponse } from '../edge-shared/utils.ts'
6
7
  import { getMiddlewareRouteMatcher, MiddlewareRouteMatch, searchParamsToUrlQuery } from '../edge-shared/next-utils.ts'
@@ -32,7 +33,7 @@ export interface RequestData {
32
33
  name?: string
33
34
  params?: { [key: string]: string }
34
35
  }
35
- url: string
36
+ url: URL
36
37
  body?: ReadableStream<Uint8Array>
37
38
  }
38
39
 
@@ -81,10 +82,11 @@ const handler = async (req: Request, context: Context) => {
81
82
  const request: RequestData = {
82
83
  headers: Object.fromEntries(req.headers.entries()),
83
84
  geo,
84
- url: url.toString(),
85
+ url,
85
86
  method: req.method,
86
87
  ip: context.ip,
87
88
  body: req.body ?? undefined,
89
+ nextConfig,
88
90
  }
89
91
 
90
92
  try {
File without changes