@netlify/plugin-nextjs 4.23.3 → 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,16 @@
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");
8
14
  const config_1 = require("./config");
9
15
  const loadMiddlewareManifest = (netlifyConfig) => {
10
16
  const middlewarePath = (0, path_1.resolve)(netlifyConfig.build.publish, 'server', 'middleware-manifest.json');
@@ -107,12 +113,12 @@ const writeEdgeFunctions = async (netlifyConfig) => {
107
113
  };
108
114
  const edgeFunctionRoot = (0, path_1.resolve)('.netlify', 'edge-functions');
109
115
  await (0, fs_extra_1.emptyDir)(edgeFunctionRoot);
110
- await (0, fs_extra_1.copy)(getEdgeTemplatePath('../edge-shared'), (0, path_1.join)(edgeFunctionRoot, 'edge-shared'));
111
116
  const { publish } = netlifyConfig.build;
112
117
  const nextConfigFile = await (0, config_1.getRequiredServerFiles)(publish);
113
118
  const nextConfig = nextConfigFile.config;
119
+ await (0, fs_extra_1.copy)(getEdgeTemplatePath('../edge-shared'), (0, path_1.join)(edgeFunctionRoot, 'edge-shared'));
114
120
  await (0, fs_extra_1.writeJSON)((0, path_1.join)(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig);
115
- if (!process.env.NEXT_DISABLE_EDGE_IMAGES) {
121
+ if (!(0, destr_1.default)(process.env.NEXT_DISABLE_EDGE_IMAGES) && !(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
116
122
  console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
117
123
  const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
118
124
  await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
@@ -123,13 +129,15 @@ const writeEdgeFunctions = async (netlifyConfig) => {
123
129
  path: '/_next/image*',
124
130
  });
125
131
  }
126
- 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)) {
127
133
  const middlewareManifest = await (0, exports.loadMiddlewareManifest)(netlifyConfig);
128
134
  if (!middlewareManifest) {
129
135
  console.error("Couldn't find the middleware manifest");
130
136
  return;
131
137
  }
138
+ let usesEdge = false;
132
139
  for (const middleware of middlewareManifest.sortedMiddleware) {
140
+ usesEdge = true;
133
141
  const edgeFunctionDefinition = middlewareManifest.middleware[middleware];
134
142
  const functionDefinitions = await writeEdgeFunction({
135
143
  edgeFunctionDefinition,
@@ -142,6 +150,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
142
150
  // No, the version field was not incremented
143
151
  if (typeof middlewareManifest.functions === 'object') {
144
152
  for (const edgeFunctionDefinition of Object.values(middlewareManifest.functions)) {
153
+ usesEdge = true;
145
154
  const functionDefinitions = await writeEdgeFunction({
146
155
  edgeFunctionDefinition,
147
156
  edgeFunctionRoot,
@@ -150,6 +159,12 @@ const writeEdgeFunctions = async (netlifyConfig) => {
150
159
  manifest.functions.push(...functionDefinitions);
151
160
  }
152
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
+ }
153
168
  }
154
169
  await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionRoot, 'manifest.json'), manifest);
155
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 });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.23.3",
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
+ }