@netlify/plugin-nextjs 4.12.1 → 4.13.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.
@@ -56,8 +56,11 @@ const resolveModuleRoot = (moduleName) => {
56
56
  }
57
57
  };
58
58
  const DEFAULT_EXCLUDED_MODULES = ['sharp', 'electron'];
59
- const configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) => {
59
+ const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [] }) => {
60
60
  var _a;
61
+ const config = await (0, exports.getRequiredServerFiles)(publish);
62
+ const files = config.files || [];
63
+ const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`));
61
64
  /* eslint-disable no-underscore-dangle */
62
65
  (_a = netlifyConfig.functions)._ipx || (_a._ipx = {});
63
66
  netlifyConfig.functions._ipx.node_bundler = 'nft';
@@ -66,7 +69,7 @@ const configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) => {
66
69
  (_a = netlifyConfig.functions)[functionName] || (_a[functionName] = { included_files: [], external_node_modules: [] });
67
70
  netlifyConfig.functions[functionName].node_bundler = 'nft';
68
71
  (_b = netlifyConfig.functions[functionName]).included_files || (_b.included_files = []);
69
- netlifyConfig.functions[functionName].included_files.push('.env', '.env.local', '.env.production', '.env.production.local', './public/locales/**', './next-i18next.config.js', `${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, `${publish}/static/chunks/webpack-middleware*.js`, `!${publish}/server/**/*.js.nft.json`, ...ignore.map((path) => `!${(0, slash_1.default)(path)}`));
72
+ netlifyConfig.functions[functionName].included_files.push('.env', '.env.local', '.env.production', '.env.production.local', './public/locales/**', './next-i18next.config.js', `${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, `${publish}/static/chunks/webpack-middleware*.js`, `!${publish}/server/**/*.js.nft.json`, ...cssFilesToInclude, ...ignore.map((path) => `!${(0, slash_1.default)(path)}`));
70
73
  const nextRoot = resolveModuleRoot('next');
71
74
  if (nextRoot) {
72
75
  netlifyConfig.functions[functionName].included_files.push(`!${nextRoot}/dist/server/lib/squoosh/**/*.wasm`, `!${nextRoot}/dist/next-server/server/lib/squoosh/**/*.wasm`, `!${nextRoot}/dist/compiled/webpack/bundle4.js`, `!${nextRoot}/dist/compiled/webpack/bundle5.js`);
@@ -270,13 +270,21 @@ const baseServerReplacements = [
270
270
  ];
271
271
  const nextServerReplacements = [
272
272
  [
273
- `getMiddlewareManifest() {\n if (!this.minimalMode) {`,
274
- `getMiddlewareManifest() {\n if (!this.minimalMode && !process.env.NEXT_USE_NETLIFY_EDGE) {`,
273
+ `getMiddlewareManifest() {\n if (this.minimalMode) return null;`,
274
+ `getMiddlewareManifest() {\n if (this.minimalMode || process.env.NEXT_USE_NETLIFY_EDGE) return null;`,
275
+ ],
276
+ [
277
+ `generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode) return []`,
278
+ `generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode || process.env.NEXT_USE_NETLIFY_EDGE) return [];`,
275
279
  ],
276
280
  [
277
281
  `generateCatchAllMiddlewareRoute() {\n if (this.minimalMode) return undefined;`,
278
282
  `generateCatchAllMiddlewareRoute() {\n if (this.minimalMode || process.env.NEXT_USE_NETLIFY_EDGE) return undefined;`,
279
283
  ],
284
+ [
285
+ `getMiddlewareManifest() {\n if (this.minimalMode) {`,
286
+ `getMiddlewareManifest() {\n if (!this.minimalMode && !process.env.NEXT_USE_NETLIFY_EDGE) {`,
287
+ ],
280
288
  ];
281
289
  const patchNextFiles = async (root) => {
282
290
  const baseServerFile = getServerFile(root);
@@ -66,9 +66,19 @@ const checkForOldFunctions = async ({ functions }) => {
66
66
  exports.checkForOldFunctions = checkForOldFunctions;
67
67
  const checkNextSiteHasBuilt = ({ publish, failBuild, }) => {
68
68
  if (!(0, fs_1.existsSync)(path_1.default.join(publish, 'BUILD_ID'))) {
69
- const outWarning = path_1.default.basename(publish) === 'out'
70
- ? `Your publish directory is set to "out", but in most cases it should be ".next".`
71
- : `In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`;
69
+ let outWarning;
70
+ if (path_1.default.basename(publish) === 'out') {
71
+ outWarning = `Your publish directory is set to "out", but in most cases it should be ".next".`;
72
+ }
73
+ else if (path_1.default.basename(publish) !== '.next' && (0, fs_1.existsSync)(path_1.default.join('.next', 'BUILD_ID'))) {
74
+ outWarning = (0, outdent_1.outdent) `
75
+ However, a '.next' directory was found with a production build.
76
+ Consider changing your 'publish' directory to '.next'
77
+ `;
78
+ }
79
+ else {
80
+ outWarning = `In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`;
81
+ }
72
82
  return failBuild((0, outdent_1.outdent) `
73
83
  The directory "${publish}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
74
84
  ${outWarning}
@@ -76,7 +86,7 @@ const checkNextSiteHasBuilt = ({ publish, failBuild, }) => {
76
86
  `);
77
87
  }
78
88
  if ((0, fs_1.existsSync)(path_1.default.join(publish, 'export-detail.json'))) {
79
- failBuild((0, outdent_1.outdent) `
89
+ return failBuild((0, outdent_1.outdent) `
80
90
  Detected that "next export" was run, but site is incorrectly publishing the ".next" directory.
81
91
  The publish directory should be set to "out", and you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
82
92
  `);
package/lib/index.js CHANGED
@@ -62,7 +62,7 @@ const plugin = {
62
62
  }
63
63
  }
64
64
  const buildId = (0, fs_extra_1.readFileSync)((0, path_1.join)(publish, 'BUILD_ID'), 'utf8').trim();
65
- (0, config_1.configureHandlerFunctions)({ netlifyConfig, ignore, publish: (0, path_1.relative)(process.cwd(), publish) });
65
+ await (0, config_1.configureHandlerFunctions)({ netlifyConfig, ignore, publish: (0, path_1.relative)(process.cwd(), publish) });
66
66
  await (0, functions_1.generateFunctions)(constants, appDir);
67
67
  await (0, functions_1.generatePagesResolver)({ target, constants });
68
68
  await (0, files_1.movePublicFiles)({ appDir, outdir, publish });
@@ -102,7 +102,7 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
102
102
  multiValueHeaders['cache-control'] = ['public, max-age=0, must-revalidate'];
103
103
  }
104
104
  multiValueHeaders['x-render-mode'] = [requestMode];
105
- console.log(`[${event.httpMethod}] ${event.path} (${requestMode === null || requestMode === void 0 ? void 0 : requestMode.toUpperCase()})`);
105
+ console.log(`[${event.httpMethod}] ${event.path} (${requestMode === null || requestMode === void 0 ? void 0 : requestMode.toUpperCase()}${result.ttl > 0 ? ` ${result.ttl}s` : ''})`);
106
106
  return {
107
107
  ...result,
108
108
  multiValueHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.12.1",
3
+ "version": "4.13.1",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@delucis/if-env": "^1.1.2",
31
- "@netlify/build": "^27.3.3",
31
+ "@netlify/build": "^27.5.0",
32
32
  "@types/fs-extra": "^9.0.13",
33
33
  "@types/jest": "^27.4.1",
34
34
  "@types/node": "^17.0.25",