@netlify/plugin-nextjs 4.23.4 → 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.
@@ -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
- (_a = netlifyConfig.functions)._ipx || (_a._ipx = {});
66
- netlifyConfig.functions._ipx.node_bundler = 'nft';
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: [] });
@@ -118,7 +118,9 @@ const writeEdgeFunctions = async (netlifyConfig) => {
118
118
  const nextConfig = nextConfigFile.config;
119
119
  await (0, fs_extra_1.copy)(getEdgeTemplatePath('../edge-shared'), (0, path_1.join)(edgeFunctionRoot, 'edge-shared'));
120
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)) {
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)) {
122
124
  console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
123
125
  const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
124
126
  await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
@@ -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
- // If we have edge functions then the request will have already been rewritten
57
- // so this won't match. This is matched if edge is disabled or unavailable.
58
- netlifyConfig.redirects.push({
59
- from: `${imagePath}*`,
60
- query: { url: ':url', w: ':width', q: ':quality' },
61
- to: `${basePath}/${constants_1.IMAGE_FUNCTION_NAME}/w_:width,q_:quality/:url`,
62
- status: 301,
63
- });
64
- netlifyConfig.redirects.push({
65
- from: `${basePath}/${constants_1.IMAGE_FUNCTION_NAME}/*`,
66
- to: `/.netlify/builders/${constants_1.IMAGE_FUNCTION_NAME}`,
67
- status: 200,
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.23.4",
3
+ "version": "4.24.0",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "devDependencies": {
35
35
  "@delucis/if-env": "^1.1.2",
36
- "@netlify/build": "^27.18.6",
36
+ "@netlify/build": "^27.20.1",
37
37
  "@types/fs-extra": "^9.0.13",
38
38
  "@types/jest": "^27.4.1",
39
39
  "@types/merge-stream": "^1.1.2",