@netlify/plugin-nextjs 4.12.0 → 4.13.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.
@@ -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`);
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateConfig = exports.writeEdgeFunctions = exports.loadMiddlewareManifest = void 0;
4
+ /* eslint-disable max-lines */
4
5
  const fs_1 = require("fs");
5
6
  const path_1 = require("path");
6
7
  const fs_extra_1 = require("fs-extra");
@@ -80,7 +81,10 @@ const writeEdgeFunctions = async (netlifyConfig) => {
80
81
  if (!process.env.NEXT_USE_NETLIFY_EDGE) {
81
82
  console.log('Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.');
82
83
  }
83
- await copyEdgeSourceFile({ edgeFunctionDir: edgeFunctionRoot, file: 'ipx.ts' });
84
+ const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, 'ipx');
85
+ await (0, fs_extra_1.ensureDir)(edgeFunctionDir);
86
+ await copyEdgeSourceFile({ edgeFunctionDir, file: 'ipx.ts', target: 'index.ts' });
87
+ await (0, fs_extra_1.copyFile)((0, path_1.join)('.netlify', 'functions-internal', '_ipx', 'imageconfig.json'), (0, path_1.join)(edgeFunctionDir, 'imageconfig.json'));
84
88
  manifest.functions.push({
85
89
  function: 'ipx',
86
90
  path: '/_next/image*',
@@ -124,3 +128,4 @@ const updateConfig = async (publish) => {
124
128
  await (0, fs_extra_1.writeJSON)(configFile, config);
125
129
  };
126
130
  exports.updateConfig = updateConfig;
131
+ /* eslint-enable max-lines */
@@ -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.0",
3
+ "version": "4.13.0",
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.4.2",
32
32
  "@types/fs-extra": "^9.0.13",
33
33
  "@types/jest": "^27.4.1",
34
34
  "@types/node": "^17.0.25",
@@ -1,7 +1,7 @@
1
1
  import { Accepts } from "https://deno.land/x/accepts@2.1.1/mod.ts";
2
2
  import type { Context } from "netlify:edge";
3
3
  // Available at build time
4
- import imageconfig from "../functions-internal/_ipx/imageconfig.json" assert {
4
+ import imageconfig from "./imageconfig.json" assert {
5
5
  type: "json",
6
6
  };
7
7