@netlify/plugin-nextjs 4.39.4 → 4.40.1

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.
@@ -138,7 +138,7 @@ exports.writeDevEdgeFunction = writeDevEdgeFunction;
138
138
  /**
139
139
  * Writes an edge function that routes RSC data requests to the `.rsc` route
140
140
  */
141
- const generateRscDataEdgeManifest = async ({ prerenderManifest, appPathRoutesManifest, }) => {
141
+ const generateRscDataEdgeManifest = async ({ prerenderManifest, appPathRoutesManifest, packagePath = '', }) => {
142
142
  const generator = await (0, functionsMetaData_1.getPluginVersion)();
143
143
  if (!prerenderManifest || !appPathRoutesManifest) {
144
144
  return [];
@@ -158,7 +158,7 @@ const generateRscDataEdgeManifest = async ({ prerenderManifest, appPathRoutesMan
158
158
  if (staticAppdirRoutes.length === 0 && dynamicAppDirRoutes.length === 0) {
159
159
  return [];
160
160
  }
161
- const edgeFunctionDir = (0, path_1.resolve)('.netlify', 'edge-functions', 'rsc-data');
161
+ const edgeFunctionDir = (0, path_1.resolve)(packagePath, '.netlify', 'edge-functions', 'rsc-data');
162
162
  await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
163
163
  await copyEdgeSourceFile({ edgeFunctionDir, file: 'rsc-data.ts' });
164
164
  return [
@@ -196,7 +196,7 @@ exports.getEdgeFunctionPatternForPage = getEdgeFunctionPatternForPage;
196
196
  * Writes Edge Functions for the Next middleware
197
197
  */
198
198
  // eslint-disable-next-line max-lines-per-function
199
- const writeEdgeFunctions = async ({ netlifyConfig, routesManifest, }) => {
199
+ const writeEdgeFunctions = async ({ netlifyConfig, routesManifest, constants: { PACKAGE_PATH = '' }, }) => {
200
200
  var _a;
201
201
  const generator = await (0, functionsMetaData_1.getPluginVersion)();
202
202
  const manifest = {
@@ -204,7 +204,7 @@ const writeEdgeFunctions = async ({ netlifyConfig, routesManifest, }) => {
204
204
  layers: [],
205
205
  version: 1,
206
206
  };
207
- const edgeFunctionRoot = (0, path_1.resolve)('.netlify', 'edge-functions');
207
+ const edgeFunctionRoot = (0, path_1.resolve)(PACKAGE_PATH, '.netlify', 'edge-functions');
208
208
  await (0, fs_extra_1.emptyDir)(edgeFunctionRoot);
209
209
  const { publish } = netlifyConfig.build;
210
210
  const nextConfigFile = await (0, config_1.getRequiredServerFiles)(publish);
@@ -219,6 +219,7 @@ const writeEdgeFunctions = async ({ netlifyConfig, routesManifest, }) => {
219
219
  return;
220
220
  }
221
221
  const rscFunctions = await (0, exports.generateRscDataEdgeManifest)({
222
+ packagePath: PACKAGE_PATH,
222
223
  prerenderManifest: await (0, exports.loadPrerenderManifest)(netlifyConfig),
223
224
  appPathRoutesManifest: await (0, exports.loadAppPathRoutesManifest)(netlifyConfig),
224
225
  });
@@ -21,7 +21,7 @@ const files_1 = require("./files");
21
21
  const functionsMetaData_1 = require("./functionsMetaData");
22
22
  const pack_1 = require("./pack");
23
23
  const utils_1 = require("./utils");
24
- const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }, appDir, apiLambdas, ssrLambdas) => {
24
+ const generateFunctions = async ({ INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR, PACKAGE_PATH = '', FUNCTIONS_SRC = (0, pathe_1.join)(PACKAGE_PATH, constants_1.DEFAULT_FUNCTIONS_SRC), }, appDir, apiLambdas, ssrLambdas) => {
25
25
  const publish = (0, pathe_1.resolve)(PUBLISH_DIR);
26
26
  const functionsDir = (0, pathe_1.resolve)(INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC);
27
27
  const functionDir = (0, pathe_1.join)(functionsDir, constants_1.HANDLER_FUNCTION_NAME);
@@ -95,15 +95,15 @@ exports.generateFunctions = generateFunctions;
95
95
  * Writes a file in each function directory that contains references to every page entrypoint.
96
96
  * This is just so that the nft bundler knows about them. We'll eventually do this better.
97
97
  */
98
- const generatePagesResolver = async ({ INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, PUBLISH_DIR, }) => {
98
+ const generatePagesResolver = async ({ INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR, PACKAGE_PATH = '', FUNCTIONS_SRC = (0, pathe_1.join)(PACKAGE_PATH, constants_1.DEFAULT_FUNCTIONS_SRC), }) => {
99
99
  const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
100
- const jsSource = await (0, getPageResolver_1.getResolverForPages)(PUBLISH_DIR);
100
+ const jsSource = await (0, getPageResolver_1.getResolverForPages)(PUBLISH_DIR, PACKAGE_PATH);
101
101
  await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsPath, constants_1.ODB_FUNCTION_NAME, 'pages.js'), jsSource);
102
102
  await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsPath, constants_1.HANDLER_FUNCTION_NAME, 'pages.js'), jsSource);
103
103
  };
104
104
  exports.generatePagesResolver = generatePagesResolver;
105
105
  // Move our next/image function into the correct functions directory
106
- const setupImageFunction = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, IS_LOCAL }, imageconfig = {}, netlifyConfig, basePath, remotePatterns, responseHeaders, }) => {
106
+ const setupImageFunction = async ({ constants: { IS_LOCAL, INTERNAL_FUNCTIONS_SRC, PACKAGE_PATH = '', FUNCTIONS_SRC = (0, pathe_1.join)(PACKAGE_PATH, constants_1.DEFAULT_FUNCTIONS_SRC), }, imageconfig = {}, netlifyConfig, basePath, remotePatterns, responseHeaders, }) => {
107
107
  const imagePath = imageconfig.path || '/_next/image';
108
108
  if ((0, destr_1.default)(process.env.DISABLE_IPX)) {
109
109
  // If no image loader is specified, need to redirect to a 404 page since there's no
package/lib/index.js CHANGED
@@ -128,7 +128,7 @@ const plugin = {
128
128
  buildId,
129
129
  apiLambdas,
130
130
  });
131
- await (0, edge_1.writeEdgeFunctions)({ netlifyConfig, routesManifest });
131
+ await (0, edge_1.writeEdgeFunctions)({ constants, netlifyConfig, routesManifest });
132
132
  },
133
133
  async onPostBuild({ netlifyConfig: { build: { publish }, redirects, headers, }, utils: { status, cache, functions, build: { failBuild }, }, constants: { FUNCTIONS_DIST }, }) {
134
134
  await (0, cache_1.saveCache)({ cache, publish });
@@ -68,8 +68,7 @@ const makeHandler = ({ conf, app, pageRoot, NextServer, staticManifest = [], mod
68
68
  try {
69
69
  await requestHandler(req, res);
70
70
  }
71
- catch (error) {
72
- console.error(error);
71
+ catch {
73
72
  throw new Error('Error handling request. See function logs for details.');
74
73
  }
75
74
  });
@@ -39,8 +39,8 @@ const getResolverForDependencies = ({ dependencies, functionDir, }) => {
39
39
  `;
40
40
  };
41
41
  exports.getResolverForDependencies = getResolverForDependencies;
42
- const getResolverForPages = async (publish) => {
43
- const functionDir = (0, pathe_1.resolve)('.netlify', 'functions', constants_1.HANDLER_FUNCTION_NAME);
42
+ const getResolverForPages = async (publish, packagePath) => {
43
+ const functionDir = (0, pathe_1.resolve)(packagePath, '.netlify', 'functions', constants_1.HANDLER_FUNCTION_NAME);
44
44
  const dependencies = await (0, exports.getAllPageDependencies)(publish);
45
45
  return (0, exports.getResolverForDependencies)({ dependencies, functionDir });
46
46
  };
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.localizeDataRoute = exports.localizeRoute = exports.unlocalizeRoute = exports.joinPaths = exports.normalizeRoute = exports.netlifyApiFetch = exports.normalizePath = exports.getPrefetchResponse = exports.augmentFsModule = exports.getMultiValueHeaders = exports.getMaxAge = exports.downloadFile = void 0;
6
+ exports.getMatchedRoute = exports.localizeDataRoute = exports.localizeRoute = exports.unlocalizeRoute = exports.joinPaths = exports.normalizeRoute = exports.netlifyApiFetch = exports.normalizePath = exports.getPrefetchResponse = exports.augmentFsModule = exports.getMultiValueHeaders = exports.getMaxAge = exports.downloadFile = void 0;
7
7
  const fs_1 = require("fs");
8
8
  const os_1 = require("os");
9
9
  const path_1 = __importDefault(require("path"));
@@ -230,3 +230,16 @@ const localizeDataRoute = (dataRoute, localizedRoute) => {
230
230
  .replace(/\/index\.json$/, '.json');
231
231
  };
232
232
  exports.localizeDataRoute = localizeDataRoute;
233
+ const getMatchedRoute = (paths, routesManifest, parsedUrl, basePath, trailingSlash) => routesManifest === null || routesManifest === void 0 ? void 0 : routesManifest.find((route) => {
234
+ // Some internationalized routes are automatically removing the locale prefix making the path not match the route
235
+ // we can use the parsedURL, which has the locale included and will match
236
+ const base = '/';
237
+ return new RegExp(route.regex).test(new URL(
238
+ // If using basepath config, we have to use the original path to match the route
239
+ // This seems to only be an issue on the index page when using group routes
240
+ parsedUrl ||
241
+ (basePath && paths === (trailingSlash && !(basePath === null || basePath === void 0 ? void 0 : basePath.endsWith('/')) ? `${basePath}/` : basePath)
242
+ ? base
243
+ : paths), 'http://n').pathname);
244
+ });
245
+ exports.getMatchedRoute = getMatchedRoute;
@@ -7,6 +7,10 @@ const handlerUtils_1 = require("./handlerUtils");
7
7
  // eslint-disable-next-line max-lines-per-function
8
8
  const getNetlifyNextServer = (NextServer) => {
9
9
  class NetlifyNextServer extends NextServer {
10
+ getAppRouterReactVersion() {
11
+ var _a;
12
+ return ((_a = this.nextConfig.experimental) === null || _a === void 0 ? void 0 : _a.serverActions) ? 'experimental' : 'next';
13
+ }
10
14
  constructor(options, netlifyConfig) {
11
15
  super(options);
12
16
  this.netlifyConfig = netlifyConfig;
@@ -28,7 +32,7 @@ const getNetlifyNextServer = (NextServer) => {
28
32
  // preserve the URL before Next.js mutates it for i18n
29
33
  const { url, headers } = req;
30
34
  // conditionally use the prebundled React module
31
- this.netlifyPrebundleReact(url);
35
+ this.netlifyPrebundleReact(url, this.nextConfig, parsedUrl);
32
36
  // intercept on-demand revalidation requests and handle with the Netlify API
33
37
  if (headers['x-prerender-revalidate'] && this.netlifyConfig.revalidateToken) {
34
38
  // handle on-demand revalidation by purging the ODB cache
@@ -52,22 +56,19 @@ const getNetlifyNextServer = (NextServer) => {
52
56
  };
53
57
  }
54
58
  // doing what they do in https://github.com/vercel/vercel/blob/1663db7ca34d3dd99b57994f801fb30b72fbd2f3/packages/next/src/server-build.ts#L576-L580
55
- netlifyPrebundleReact(path) {
56
- var _a, _b, _c;
59
+ async netlifyPrebundleReact(path, { basePath, trailingSlash }, parsedUrl) {
60
+ var _a, _b;
57
61
  const routesManifest = (_a = this.getRoutesManifest) === null || _a === void 0 ? void 0 : _a.call(this);
58
62
  const appPathsRoutes = (_b = this.getAppPathRoutes) === null || _b === void 0 ? void 0 : _b.call(this);
59
63
  const routes = routesManifest && [...routesManifest.staticRoutes, ...routesManifest.dynamicRoutes];
60
- const matchedRoute = routes === null || routes === void 0 ? void 0 : routes.find((route) => new RegExp(route.regex).test(new URL(path, 'http://n').pathname));
64
+ const matchedRoute = await (0, handlerUtils_1.getMatchedRoute)(path, routes, parsedUrl, basePath, trailingSlash);
61
65
  const isAppRoute = appPathsRoutes && matchedRoute ? appPathsRoutes[matchedRoute.page] : false;
62
66
  if (isAppRoute) {
63
67
  // app routes should use prebundled React
64
68
  // eslint-disable-next-line no-underscore-dangle
65
- process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = ((_c = this.nextConfig.experimental) === null || _c === void 0 ? void 0 : _c.serverActions)
66
- ? 'experimental'
67
- : 'next';
69
+ process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = this.getAppRouterReactVersion();
68
70
  return;
69
71
  }
70
- // pages routes should use use node_modules React
71
72
  // eslint-disable-next-line no-underscore-dangle
72
73
  process.env.__NEXT_PRIVATE_PREBUNDLED_REACT = '';
73
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.39.4",
3
+ "version": "4.40.1",
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.20.1",
40
+ "@netlify/build": "^29.20.6",
41
41
  "@types/fs-extra": "^9.0.13",
42
42
  "@types/jest": "^27.4.1",
43
43
  "@types/merge-stream": "^1.1.2",