@netlify/plugin-nextjs 4.2.6 → 4.3.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/constants.js CHANGED
@@ -9,6 +9,7 @@ exports.HIDDEN_PATHS = [
9
9
  '/cache/*',
10
10
  '/server/*',
11
11
  '/serverless/*',
12
+ '/trace',
12
13
  '/traces',
13
14
  '/routes-manifest.json',
14
15
  '/build-manifest.json',
@@ -1,10 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.saveCache = exports.restoreCache = void 0;
4
+ const fs_1 = require("fs");
4
5
  const path_1 = require("path");
6
+ const utils_1 = require("./utils");
7
+ const findDistDir = (publish) => {
8
+ // In normal operation, the dist dir is the same as the publish dir
9
+ if (!(0, utils_1.shouldSkip)()) {
10
+ return publish;
11
+ }
12
+ // In this situation, the user has disabled the plugin, which means that they might be using next export,
13
+ // so we'll look in a few places to find the site root. This allows us to find the .next directory.
14
+ for (const root of [(0, path_1.resolve)(publish, '..'), (0, path_1.resolve)(publish, '..', '..')]) {
15
+ if ((0, fs_1.existsSync)((0, path_1.join)(root, 'next.config.js'))) {
16
+ return (0, path_1.join)(root, '.next');
17
+ }
18
+ }
19
+ return null;
20
+ };
5
21
  const restoreCache = async ({ cache, publish }) => {
6
- const cacheDir = (0, path_1.join)(publish, 'cache');
7
- if (await cache.restore(cacheDir)) {
22
+ const distDir = findDistDir(publish);
23
+ if (!distDir) {
24
+ return;
25
+ }
26
+ if (await cache.restore((0, path_1.join)(distDir, 'cache'))) {
8
27
  console.log('Next.js cache restored.');
9
28
  }
10
29
  else {
@@ -13,9 +32,11 @@ const restoreCache = async ({ cache, publish }) => {
13
32
  };
14
33
  exports.restoreCache = restoreCache;
15
34
  const saveCache = async ({ cache, publish }) => {
16
- const cacheDir = (0, path_1.join)(publish, 'cache');
17
- const buildManifest = (0, path_1.join)(publish, 'build-manifest.json');
18
- if (await cache.save(cacheDir, { digests: [buildManifest] })) {
35
+ const distDir = findDistDir(publish);
36
+ if (!distDir) {
37
+ return;
38
+ }
39
+ if (await cache.save((0, path_1.join)(distDir, 'cache'))) {
19
40
  console.log('Next.js cache saved.');
20
41
  }
21
42
  else {
@@ -54,6 +54,9 @@ const matchesRewrite = (file, rewrites) => {
54
54
  exports.matchesRewrite = matchesRewrite;
55
55
  const getMiddleware = async (publish) => {
56
56
  var _a;
57
+ if (process.env.NEXT_SKIP_MIDDLEWARE) {
58
+ return [];
59
+ }
57
60
  const manifestPath = (0, pathe_1.join)(publish, 'server', 'middleware-manifest.json');
58
61
  if ((0, fs_extra_1.existsSync)(manifestPath)) {
59
62
  const manifest = await (0, fs_extra_1.readJson)(manifestPath, { throws: false });
@@ -13,7 +13,7 @@ const getPageResolver_1 = require("../templates/getPageResolver");
13
13
  const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }, appDir) => {
14
14
  const functionsDir = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
15
15
  const functionDir = (0, pathe_1.join)(process.cwd(), functionsDir, constants_1.HANDLER_FUNCTION_NAME);
16
- const publishDir = (0, pathe_1.relative)(functionDir, (0, pathe_1.join)(process.cwd(), PUBLISH_DIR));
16
+ const publishDir = (0, pathe_1.relative)(functionDir, (0, pathe_1.resolve)(PUBLISH_DIR));
17
17
  const writeHandler = async (func, isODB) => {
18
18
  const handlerSource = await (0, getHandler_1.getHandler)({ isODB, publishDir, appDir: (0, pathe_1.relative)(functionDir, appDir) });
19
19
  await (0, fs_extra_1.ensureDir)((0, pathe_1.join)(functionsDir, func));
@@ -66,7 +66,7 @@ const checkNextSiteHasBuilt = ({ publish, failBuild, }) => {
66
66
  ? `Your publish directory is set to "out", but in most cases it should be ".next".`
67
67
  : `In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`;
68
68
  return failBuild((0, outdent_1.outdent) `
69
- The directory "${path_1.default.relative(process.cwd(), publish)}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
69
+ 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.
70
70
  ${outWarning}
71
71
  If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
72
72
  `);
@@ -82,7 +82,7 @@ exports.checkNextSiteHasBuilt = checkNextSiteHasBuilt;
82
82
  const checkForRootPublish = ({ publish, failBuild, }) => {
83
83
  if (path_1.default.resolve(publish) === path_1.default.resolve('.')) {
84
84
  failBuild((0, outdent_1.outdent) `
85
- Your publish directory is pointing to the base directory of your site. This is not supported for Next.js sites, and is probably a mistake.
85
+ Your publish directory is pointing to the base directory of your site. This is not supported for Next.js sites, and is probably a mistake.
86
86
  In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config, or the Next site is in a subdirectory.
87
87
  `);
88
88
  }
@@ -14,6 +14,9 @@ const { augmentFsModule, getMaxAge, getMultiValueHeaders, getNextServer } = requ
14
14
  // eslint-disable-next-line max-params
15
15
  const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') => {
16
16
  var _a;
17
+ // Change working directory into the site root
18
+ const dir = path.resolve(__dirname, app);
19
+ process.chdir(dir);
17
20
  // This is just so nft knows about the page entrypoints. It's not actually used
18
21
  try {
19
22
  // eslint-disable-next-line node/no-missing-require
@@ -27,6 +30,9 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
27
30
  // This is our flag that we use when patching the source
28
31
  // eslint-disable-next-line no-underscore-dangle
29
32
  process.env._BYPASS_SSG = 'true';
33
+ for (const [key, value] of Object.entries(conf.env)) {
34
+ process.env[key] = String(value);
35
+ }
30
36
  // Set during the request as it needs the host header. Hoisted so we can define the function once
31
37
  let base;
32
38
  augmentFsModule({ promises, staticManifest, pageRoot, getBase: () => base });
@@ -45,7 +51,7 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
45
51
  const NextServer = getNextServer();
46
52
  const nextServer = new NextServer({
47
53
  conf,
48
- dir: path.resolve(__dirname, app),
54
+ dir,
49
55
  customServer: false,
50
56
  hostname: url.hostname,
51
57
  port,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "4.2.6",
3
+ "version": "4.3.0",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -53,8 +53,8 @@
53
53
  },
54
54
  "homepage": "https://github.com/netlify/netlify-plugin-nextjs#readme",
55
55
  "dependencies": {
56
- "@netlify/functions": "^0.11.0",
57
- "@netlify/ipx": "^0.0.9",
56
+ "@netlify/functions": "^1.0.0",
57
+ "@netlify/ipx": "^0.0.10",
58
58
  "@vercel/node-bridge": "^2.1.0",
59
59
  "chalk": "^4.1.2",
60
60
  "fs-extra": "^10.0.0",
@@ -75,8 +75,8 @@
75
75
  "@babel/core": "^7.15.8",
76
76
  "@babel/preset-env": "^7.15.8",
77
77
  "@babel/preset-typescript": "^7.16.0",
78
- "@netlify/build": "^26.3.1",
79
- "@netlify/eslint-config-node": "^5.1.4",
78
+ "@netlify/build": "^26.5.0",
79
+ "@netlify/eslint-config-node": "^5.1.7",
80
80
  "@reach/dialog": "^0.16.2",
81
81
  "@reach/visually-hidden": "^0.16.0",
82
82
  "@testing-library/cypress": "^8.0.1",