@netlify/plugin-nextjs 4.23.3 → 4.24.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.
- package/lib/helpers/config.js +7 -2
- package/lib/helpers/edge.js +20 -3
- package/lib/helpers/functions.js +41 -25
- package/lib/index.js +22 -28
- package/package.json +4 -3
package/lib/helpers/config.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.generateCustomHeaders = exports.configureHandlerFunctions = exports.updateRequiredServerFiles = exports.getRequiredServerFiles = exports.getNextConfig = void 0;
|
|
7
|
+
const destr_1 = __importDefault(require("destr"));
|
|
7
8
|
const fs_extra_1 = require("fs-extra");
|
|
8
9
|
const pathe_1 = require("pathe");
|
|
9
10
|
const slash_1 = __importDefault(require("slash"));
|
|
@@ -62,8 +63,12 @@ const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [] }
|
|
|
62
63
|
const files = config.files || [];
|
|
63
64
|
const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`));
|
|
64
65
|
/* eslint-disable no-underscore-dangle */
|
|
65
|
-
(
|
|
66
|
-
|
|
66
|
+
if (!(0, destr_1.default)(process.env.DISABLE_IPX)) {
|
|
67
|
+
(_a = netlifyConfig.functions)._ipx || (_a._ipx = {});
|
|
68
|
+
netlifyConfig.functions._ipx.node_bundler = 'nft';
|
|
69
|
+
}
|
|
70
|
+
/* eslint-enable no-underscore-dangle */
|
|
71
|
+
;
|
|
67
72
|
[constants_1.HANDLER_FUNCTION_NAME, constants_1.ODB_FUNCTION_NAME].forEach((functionName) => {
|
|
68
73
|
var _a, _b;
|
|
69
74
|
(_a = netlifyConfig.functions)[functionName] || (_a[functionName] = { included_files: [], external_node_modules: [] });
|
package/lib/helpers/edge.js
CHANGED
|
@@ -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,14 @@ 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) &&
|
|
122
|
+
!(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE) &&
|
|
123
|
+
!(0, destr_1.default)(process.env.DISABLE_IPX)) {
|
|
116
124
|
console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
|
|
117
125
|
const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
|
|
118
126
|
await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
|
|
@@ -123,13 +131,15 @@ const writeEdgeFunctions = async (netlifyConfig) => {
|
|
|
123
131
|
path: '/_next/image*',
|
|
124
132
|
});
|
|
125
133
|
}
|
|
126
|
-
if (
|
|
134
|
+
if (!(0, destr_1.default)(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
|
|
127
135
|
const middlewareManifest = await (0, exports.loadMiddlewareManifest)(netlifyConfig);
|
|
128
136
|
if (!middlewareManifest) {
|
|
129
137
|
console.error("Couldn't find the middleware manifest");
|
|
130
138
|
return;
|
|
131
139
|
}
|
|
140
|
+
let usesEdge = false;
|
|
132
141
|
for (const middleware of middlewareManifest.sortedMiddleware) {
|
|
142
|
+
usesEdge = true;
|
|
133
143
|
const edgeFunctionDefinition = middlewareManifest.middleware[middleware];
|
|
134
144
|
const functionDefinitions = await writeEdgeFunction({
|
|
135
145
|
edgeFunctionDefinition,
|
|
@@ -142,6 +152,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
|
|
|
142
152
|
// No, the version field was not incremented
|
|
143
153
|
if (typeof middlewareManifest.functions === 'object') {
|
|
144
154
|
for (const edgeFunctionDefinition of Object.values(middlewareManifest.functions)) {
|
|
155
|
+
usesEdge = true;
|
|
145
156
|
const functionDefinitions = await writeEdgeFunction({
|
|
146
157
|
edgeFunctionDefinition,
|
|
147
158
|
edgeFunctionRoot,
|
|
@@ -150,6 +161,12 @@ const writeEdgeFunctions = async (netlifyConfig) => {
|
|
|
150
161
|
manifest.functions.push(...functionDefinitions);
|
|
151
162
|
}
|
|
152
163
|
}
|
|
164
|
+
if (usesEdge) {
|
|
165
|
+
console.log((0, outdent_1.outdent) `
|
|
166
|
+
✨ Deploying middleware and functions to ${(0, chalk_1.greenBright) `Netlify Edge Functions`} ✨
|
|
167
|
+
This feature is in beta. Please share your feedback here: https://ntl.fyi/next-netlify-edge
|
|
168
|
+
`);
|
|
169
|
+
}
|
|
153
170
|
}
|
|
154
171
|
await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionRoot, 'manifest.json'), manifest);
|
|
155
172
|
};
|
package/lib/helpers/functions.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.setupImageFunction = exports.generatePagesResolver = exports.generateFunctions = void 0;
|
|
7
7
|
const node_bridge_1 = __importDefault(require("@vercel/node-bridge"));
|
|
8
|
+
const destr_1 = __importDefault(require("destr"));
|
|
8
9
|
const fs_extra_1 = require("fs-extra");
|
|
9
10
|
const pathe_1 = require("pathe");
|
|
10
11
|
const constants_1 = require("../constants");
|
|
@@ -40,32 +41,47 @@ const generatePagesResolver = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNC
|
|
|
40
41
|
};
|
|
41
42
|
exports.generatePagesResolver = generatePagesResolver;
|
|
42
43
|
// Move our next/image function into the correct functions directory
|
|
43
|
-
const setupImageFunction = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC }, imageconfig = {}, netlifyConfig, basePath, remotePatterns, responseHeaders, }) => {
|
|
44
|
-
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
|
|
45
|
-
const functionName = `${constants_1.IMAGE_FUNCTION_NAME}.js`;
|
|
46
|
-
const functionDirectory = (0, pathe_1.join)(functionsPath, constants_1.IMAGE_FUNCTION_NAME);
|
|
47
|
-
await (0, fs_extra_1.ensureDir)(functionDirectory);
|
|
48
|
-
await (0, fs_extra_1.writeJSON)((0, pathe_1.join)(functionDirectory, 'imageconfig.json'), {
|
|
49
|
-
...imageconfig,
|
|
50
|
-
basePath: [basePath, constants_1.IMAGE_FUNCTION_NAME].join('/'),
|
|
51
|
-
remotePatterns,
|
|
52
|
-
responseHeaders,
|
|
53
|
-
});
|
|
54
|
-
await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), (0, pathe_1.join)(functionDirectory, functionName));
|
|
44
|
+
const setupImageFunction = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, IS_LOCAL }, imageconfig = {}, netlifyConfig, basePath, remotePatterns, responseHeaders, }) => {
|
|
55
45
|
const imagePath = imageconfig.path || '/_next/image';
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
46
|
+
if ((0, destr_1.default)(process.env.DISABLE_IPX)) {
|
|
47
|
+
// If no image loader is specified, need to redirect to a 404 page since there's no
|
|
48
|
+
// backing loader to serve local site images once deployed to Netlify
|
|
49
|
+
if (!IS_LOCAL && imageconfig.loader === 'default') {
|
|
50
|
+
netlifyConfig.redirects.push({
|
|
51
|
+
from: `${imagePath}*`,
|
|
52
|
+
query: { url: ':url', w: ':width', q: ':quality' },
|
|
53
|
+
to: '/404.html',
|
|
54
|
+
status: 404,
|
|
55
|
+
force: true,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
|
|
61
|
+
const functionName = `${constants_1.IMAGE_FUNCTION_NAME}.js`;
|
|
62
|
+
const functionDirectory = (0, pathe_1.join)(functionsPath, constants_1.IMAGE_FUNCTION_NAME);
|
|
63
|
+
await (0, fs_extra_1.ensureDir)(functionDirectory);
|
|
64
|
+
await (0, fs_extra_1.writeJSON)((0, pathe_1.join)(functionDirectory, 'imageconfig.json'), {
|
|
65
|
+
...imageconfig,
|
|
66
|
+
basePath: [basePath, constants_1.IMAGE_FUNCTION_NAME].join('/'),
|
|
67
|
+
remotePatterns,
|
|
68
|
+
responseHeaders,
|
|
69
|
+
});
|
|
70
|
+
await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), (0, pathe_1.join)(functionDirectory, functionName));
|
|
71
|
+
// If we have edge functions then the request will have already been rewritten
|
|
72
|
+
// so this won't match. This is matched if edge is disabled or unavailable.
|
|
73
|
+
netlifyConfig.redirects.push({
|
|
74
|
+
from: `${imagePath}*`,
|
|
75
|
+
query: { url: ':url', w: ':width', q: ':quality' },
|
|
76
|
+
to: `${basePath}/${constants_1.IMAGE_FUNCTION_NAME}/w_:width,q_:quality/:url`,
|
|
77
|
+
status: 301,
|
|
78
|
+
});
|
|
79
|
+
netlifyConfig.redirects.push({
|
|
80
|
+
from: `${basePath}/${constants_1.IMAGE_FUNCTION_NAME}/*`,
|
|
81
|
+
to: `/.netlify/builders/${constants_1.IMAGE_FUNCTION_NAME}`,
|
|
82
|
+
status: 200,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
69
85
|
if (basePath) {
|
|
70
86
|
// next/image generates image static URLs that still point at the site root
|
|
71
87
|
netlifyConfig.redirects.push({
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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) &&
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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.
|
|
3
|
+
"version": "4.24.0",
|
|
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",
|
|
@@ -32,7 +33,7 @@
|
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@delucis/if-env": "^1.1.2",
|
|
35
|
-
"@netlify/build": "^27.
|
|
36
|
+
"@netlify/build": "^27.20.1",
|
|
36
37
|
"@types/fs-extra": "^9.0.13",
|
|
37
38
|
"@types/jest": "^27.4.1",
|
|
38
39
|
"@types/merge-stream": "^1.1.2",
|
|
@@ -63,4 +64,4 @@
|
|
|
63
64
|
"engines": {
|
|
64
65
|
"node": ">=12.0.0"
|
|
65
66
|
}
|
|
66
|
-
}
|
|
67
|
+
}
|