@netlify/plugin-nextjs 4.2.5 → 4.2.8
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 +1 -0
- package/lib/helpers/cache.js +26 -5
- package/lib/helpers/files.js +17 -12
- package/lib/helpers/functions.js +1 -1
- package/lib/helpers/verification.js +2 -2
- package/lib/index.js +1 -1
- package/lib/templates/getHandler.js +4 -1
- package/package.json +5 -5
package/lib/constants.js
CHANGED
package/lib/helpers/cache.js
CHANGED
|
@@ -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
|
|
7
|
-
if (
|
|
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
|
|
17
|
-
|
|
18
|
-
|
|
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 {
|
package/lib/helpers/files.js
CHANGED
|
@@ -63,7 +63,7 @@ const getMiddleware = async (publish) => {
|
|
|
63
63
|
};
|
|
64
64
|
exports.getMiddleware = getMiddleware;
|
|
65
65
|
// eslint-disable-next-line max-lines-per-function
|
|
66
|
-
const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
66
|
+
const moveStaticPages = async ({ netlifyConfig, target, i18n, basePath, }) => {
|
|
67
67
|
console.log('Moving static page files to serve from CDN...');
|
|
68
68
|
const outputDir = (0, pathe_1.join)(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless');
|
|
69
69
|
const root = (0, pathe_1.join)(outputDir, 'pages');
|
|
@@ -94,9 +94,10 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
94
94
|
const isData = file.endsWith('.json');
|
|
95
95
|
const source = (0, pathe_1.join)(root, file);
|
|
96
96
|
const targetFile = isData ? (0, pathe_1.join)(dataDir, file) : file;
|
|
97
|
+
const targetPath = basePath ? (0, pathe_1.join)(basePath, targetFile) : targetFile;
|
|
97
98
|
files.push(file);
|
|
98
|
-
filesManifest[file] =
|
|
99
|
-
const dest = (0, pathe_1.join)(netlifyConfig.build.publish,
|
|
99
|
+
filesManifest[file] = targetPath;
|
|
100
|
+
const dest = (0, pathe_1.join)(netlifyConfig.build.publish, targetPath);
|
|
100
101
|
try {
|
|
101
102
|
await (0, fs_extra_1.move)(source, dest);
|
|
102
103
|
}
|
|
@@ -190,19 +191,23 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
190
191
|
// Write the manifest for use in the serverless functions
|
|
191
192
|
await (0, fs_extra_1.writeJson)((0, pathe_1.join)(netlifyConfig.build.publish, 'static-manifest.json'), Object.entries(filesManifest));
|
|
192
193
|
if (i18n === null || i18n === void 0 ? void 0 : i18n.defaultLocale) {
|
|
194
|
+
const rootPath = basePath ? (0, pathe_1.join)(netlifyConfig.build.publish, basePath) : netlifyConfig.build.publish;
|
|
193
195
|
// Copy the default locale into the root
|
|
194
|
-
const defaultLocaleDir = (0, pathe_1.join)(
|
|
196
|
+
const defaultLocaleDir = (0, pathe_1.join)(rootPath, i18n.defaultLocale);
|
|
195
197
|
if ((0, fs_extra_1.existsSync)(defaultLocaleDir)) {
|
|
196
|
-
await (0, fs_extra_1.copy)(defaultLocaleDir, `${
|
|
198
|
+
await (0, fs_extra_1.copy)(defaultLocaleDir, `${rootPath}/`);
|
|
197
199
|
}
|
|
198
|
-
const defaultLocaleIndex = (0, pathe_1.join)(
|
|
199
|
-
const indexHtml = (0, pathe_1.join)(
|
|
200
|
+
const defaultLocaleIndex = (0, pathe_1.join)(rootPath, `${i18n.defaultLocale}.html`);
|
|
201
|
+
const indexHtml = (0, pathe_1.join)(rootPath, 'index.html');
|
|
200
202
|
if ((0, fs_extra_1.existsSync)(defaultLocaleIndex) && !(0, fs_extra_1.existsSync)(indexHtml)) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
203
|
+
await (0, fs_extra_1.copy)(defaultLocaleIndex, indexHtml, { overwrite: false }).catch(() => {
|
|
204
|
+
/* ignore */
|
|
205
|
+
});
|
|
206
|
+
await (0, fs_extra_1.copy)((0, pathe_1.join)(rootPath, `${i18n.defaultLocale}.json`), (0, pathe_1.join)(rootPath, 'index.json'), {
|
|
207
|
+
overwrite: false,
|
|
208
|
+
}).catch(() => {
|
|
209
|
+
/* ignore */
|
|
210
|
+
});
|
|
206
211
|
}
|
|
207
212
|
}
|
|
208
213
|
if (shortRevalidateRoutes.length !== 0) {
|
package/lib/helpers/functions.js
CHANGED
|
@@ -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.
|
|
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 "${
|
|
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
|
}
|
package/lib/index.js
CHANGED
|
@@ -49,7 +49,7 @@ const plugin = {
|
|
|
49
49
|
console.log("The flag 'EXPERIMENTAL_MOVE_STATIC_PAGES' is no longer required, as it is now the default. To disable this behavior, set the env var 'SERVE_STATIC_FILES_FROM_ORIGIN' to 'true'");
|
|
50
50
|
}
|
|
51
51
|
if (!process.env.SERVE_STATIC_FILES_FROM_ORIGIN) {
|
|
52
|
-
await (0, files_1.moveStaticPages)({ target, netlifyConfig, i18n });
|
|
52
|
+
await (0, files_1.moveStaticPages)({ target, netlifyConfig, i18n, basePath });
|
|
53
53
|
}
|
|
54
54
|
await (0, redirects_1.generateStaticRedirects)({
|
|
55
55
|
netlifyConfig,
|
|
@@ -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
|
|
@@ -45,7 +48,7 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
|
|
|
45
48
|
const NextServer = getNextServer();
|
|
46
49
|
const nextServer = new NextServer({
|
|
47
50
|
conf,
|
|
48
|
-
dir
|
|
51
|
+
dir,
|
|
49
52
|
customServer: false,
|
|
50
53
|
hostname: url.hostname,
|
|
51
54
|
port,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.8",
|
|
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.
|
|
57
|
-
"@netlify/ipx": "^0.0.
|
|
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.
|
|
79
|
-
"@netlify/eslint-config-node": "^5.1.
|
|
78
|
+
"@netlify/build": "^26.5.0",
|
|
79
|
+
"@netlify/eslint-config-node": "^5.1.6",
|
|
80
80
|
"@reach/dialog": "^0.16.2",
|
|
81
81
|
"@reach/visually-hidden": "^0.16.0",
|
|
82
82
|
"@testing-library/cypress": "^8.0.1",
|