@netlify/plugin-nextjs 4.0.0-beta.7 → 4.0.0-beta.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/helpers/files.js +55 -2
- package/lib/helpers/verification.js +13 -14
- package/lib/index.js +3 -0
- package/package.json +3 -3
- package/lib/.DS_Store +0 -0
package/lib/helpers/files.js
CHANGED
|
@@ -1,15 +1,39 @@
|
|
|
1
1
|
// @ts-check
|
|
2
2
|
const { cpus } = require('os');
|
|
3
|
+
const { yellowBright } = require('chalk');
|
|
3
4
|
const { existsSync, readJson, move, cpSync, copy, writeJson } = require('fs-extra');
|
|
4
5
|
const globby = require('globby');
|
|
6
|
+
const { outdent } = require('outdent');
|
|
5
7
|
const pLimit = require('p-limit');
|
|
6
8
|
const { join } = require('pathe');
|
|
7
9
|
const slash = require('slash');
|
|
8
10
|
const TEST_ROUTE = /(|\/)\[[^/]+?](\/|\.html|$)/;
|
|
9
11
|
const isDynamicRoute = (route) => TEST_ROUTE.test(route);
|
|
10
|
-
|
|
12
|
+
const stripLocale = (rawPath, locales = []) => {
|
|
13
|
+
const [locale, ...segments] = rawPath.split('/');
|
|
14
|
+
if (locales.includes(locale)) {
|
|
15
|
+
return segments.join('/');
|
|
16
|
+
}
|
|
17
|
+
return rawPath;
|
|
18
|
+
};
|
|
19
|
+
const matchMiddleware = (middleware, filePath) => middleware.includes('') ||
|
|
20
|
+
(middleware === null || middleware === void 0 ? void 0 : middleware.find((middlewarePath) => filePath === middlewarePath || filePath === `${middlewarePath}.html` || filePath.startsWith(`${middlewarePath}/`)));
|
|
21
|
+
exports.matchMiddleware = matchMiddleware;
|
|
22
|
+
exports.stripLocale = stripLocale;
|
|
23
|
+
exports.isDynamicRoute = isDynamicRoute;
|
|
24
|
+
exports.moveStaticPages = async ({ netlifyConfig, target, i18n }) => {
|
|
11
25
|
console.log('Moving static page files to serve from CDN...');
|
|
12
|
-
const
|
|
26
|
+
const outputDir = join(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless');
|
|
27
|
+
const root = join(outputDir, 'pages');
|
|
28
|
+
// Load the middleware manifest so we can check if a file matches it before moving
|
|
29
|
+
let middleware;
|
|
30
|
+
const manifestPath = join(outputDir, 'middleware-manifest.json');
|
|
31
|
+
if (existsSync(manifestPath)) {
|
|
32
|
+
const manifest = await readJson(manifestPath);
|
|
33
|
+
if (manifest === null || manifest === void 0 ? void 0 : manifest.middleware) {
|
|
34
|
+
middleware = Object.keys(manifest.middleware).map((path) => path.slice(1));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
13
37
|
const files = [];
|
|
14
38
|
const moveFile = async (file) => {
|
|
15
39
|
const source = join(root, file);
|
|
@@ -22,6 +46,8 @@ exports.moveStaticPages = async ({ netlifyConfig, target, i18n, failBuild }) =>
|
|
|
22
46
|
cwd: root,
|
|
23
47
|
dot: true,
|
|
24
48
|
});
|
|
49
|
+
const matchingMiddleware = new Set();
|
|
50
|
+
const matchedPages = new Set();
|
|
25
51
|
// Limit concurrent file moves to number of cpus or 2 if there is only 1
|
|
26
52
|
const limit = pLimit(Math.max(2, cpus().length));
|
|
27
53
|
const promises = pages.map(async (rawPath) => {
|
|
@@ -29,10 +55,37 @@ exports.moveStaticPages = async ({ netlifyConfig, target, i18n, failBuild }) =>
|
|
|
29
55
|
if (isDynamicRoute(filePath)) {
|
|
30
56
|
return;
|
|
31
57
|
}
|
|
58
|
+
// Middleware matches against the unlocalised path
|
|
59
|
+
const unlocalizedPath = stripLocale(rawPath, i18n === null || i18n === void 0 ? void 0 : i18n.locales);
|
|
60
|
+
const middlewarePath = matchMiddleware(middleware, unlocalizedPath);
|
|
61
|
+
// If a file matches middleware it can't be offloaded to the CDN, and needs to stay at the origin to be served by next/server
|
|
62
|
+
if (middlewarePath) {
|
|
63
|
+
matchingMiddleware.add(middlewarePath);
|
|
64
|
+
matchedPages.add(rawPath);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
32
67
|
return limit(moveFile, filePath);
|
|
33
68
|
});
|
|
34
69
|
await Promise.all(promises);
|
|
35
70
|
console.log(`Moved ${files.length} files`);
|
|
71
|
+
if (matchedPages.size !== 0) {
|
|
72
|
+
console.log(yellowBright(outdent `
|
|
73
|
+
Skipped moving ${matchedPages.size} ${matchedPages.size === 1 ? 'file because it matches' : 'files because they match'} middleware, so cannot be deployed to the CDN and will be served from the origin instead. This is fine, but we're letting you know because it may not be what you expect.
|
|
74
|
+
`));
|
|
75
|
+
console.log(outdent `
|
|
76
|
+
The following middleware matched statically-rendered pages:
|
|
77
|
+
|
|
78
|
+
${yellowBright([...matchingMiddleware].map((mid) => `- /${mid}/_middleware`).join('\n'))}
|
|
79
|
+
`);
|
|
80
|
+
// There could potentially be thousands of matching pages, so we don't want to spam the console with this
|
|
81
|
+
if (matchedPages.size < 50) {
|
|
82
|
+
console.log(outdent `
|
|
83
|
+
The following files matched middleware and were not moved to the CDN:
|
|
84
|
+
|
|
85
|
+
${yellowBright([...matchedPages].map((mid) => `- ${mid}`).join('\n'))}
|
|
86
|
+
`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
36
89
|
// Write the manifest for use in the serverless functions
|
|
37
90
|
await writeJson(join(netlifyConfig.build.publish, 'static-manifest.json'), files);
|
|
38
91
|
if (i18n === null || i18n === void 0 ? void 0 : i18n.defaultLocale) {
|
|
@@ -21,15 +21,14 @@ exports.checkForOldFunctions = async ({ functions }) => {
|
|
|
21
21
|
const oldFunctions = (await functions.list()).filter(({ name }) => name.startsWith('next_'));
|
|
22
22
|
if (oldFunctions.length !== 0) {
|
|
23
23
|
console.log(yellowBright(outdent `
|
|
24
|
-
|
|
24
|
+
We have found the following functions in your site that seem to be left over from the old Next.js plugin (v3). We have guessed this because the name starts with "next_".
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
${reset(oldFunctions.map(({ name }) => `- ${name}`).join('\n'))}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
If they were created by the old plugin, these functions are likely to cause errors so should be removed. You can do this by deleting the following directories:
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
`));
|
|
30
|
+
${reset(oldFunctions.map(({ mainFile }) => `- ${path.relative(process.cwd(), path.dirname(mainFile))}`).join('\n'))}
|
|
31
|
+
`));
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
34
|
exports.checkNextSiteHasBuilt = ({ publish, failBuild }) => {
|
|
@@ -38,20 +37,22 @@ exports.checkNextSiteHasBuilt = ({ publish, failBuild }) => {
|
|
|
38
37
|
The directory "${path.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.
|
|
39
38
|
In most cases it should be set to the site's ".next" directory path, unless you have chosen a custom "distDir" in your Next config.
|
|
40
39
|
If you are using "next export" then the Essential Next.js plugin should be removed. See https://ntl.fyi/remove-plugin for details.
|
|
41
|
-
|
|
40
|
+
`);
|
|
42
41
|
}
|
|
43
42
|
if (existsSync(path.join(publish, 'export-detail.json'))) {
|
|
44
43
|
failBuild(outdent `
|
|
45
44
|
Detected that "next export" was run, but site is incorrectly publishing the ".next" directory.
|
|
46
45
|
This plugin is not needed for "next export" so should be removed, and publish directory set to "out".
|
|
47
|
-
See https://ntl.fyi/remove-plugin for more details on how to remove this plugin
|
|
46
|
+
See https://ntl.fyi/remove-plugin for more details on how to remove this plugin.
|
|
47
|
+
`);
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
exports.checkForRootPublish = ({ publish, failBuild }) => {
|
|
51
51
|
if (path.resolve(publish) === path.resolve('.')) {
|
|
52
52
|
failBuild(outdent `
|
|
53
53
|
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.
|
|
54
|
-
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
|
|
54
|
+
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.
|
|
55
|
+
`);
|
|
55
56
|
}
|
|
56
57
|
};
|
|
57
58
|
// 50MB, which is the documented max, though the hard max seems to be higher
|
|
@@ -67,11 +68,9 @@ exports.checkZipSize = async (file, maxSize = LAMBDA_MAX_SIZE) => {
|
|
|
67
68
|
}
|
|
68
69
|
// We don't fail the build, because the actual hard max size is larger so it might still succeed
|
|
69
70
|
console.log(redBright(outdent `
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
large number of pre-rendered pages included.
|
|
74
|
-
|
|
71
|
+
The function zip ${yellowBright(relative(process.cwd(), file))} size is ${prettyBytes(size)}, which is larger than the maximum supported size of ${prettyBytes(maxSize)}.
|
|
72
|
+
There are a few reasons this could happen. You may have accidentally bundled a large dependency, or you might have a
|
|
73
|
+
large number of pre-rendered pages included.
|
|
75
74
|
`));
|
|
76
75
|
const zip = new StreamZip({ file });
|
|
77
76
|
console.log(`Contains ${await zip.entriesCount} files`);
|
package/lib/index.js
CHANGED
|
@@ -27,6 +27,9 @@ module.exports = {
|
|
|
27
27
|
await generatePagesResolver({ netlifyConfig, target, constants });
|
|
28
28
|
await movePublicFiles({ appDir, publish });
|
|
29
29
|
if (process.env.EXPERIMENTAL_MOVE_STATIC_PAGES) {
|
|
30
|
+
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'");
|
|
31
|
+
}
|
|
32
|
+
if (!process.env.SERVE_STATIC_FILES_FROM_ORIGIN) {
|
|
30
33
|
await moveStaticPages({ target, failBuild, netlifyConfig, i18n });
|
|
31
34
|
}
|
|
32
35
|
await setupImageFunction({ constants, imageconfig: images, netlifyConfig, basePath });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.8",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"files": [
|
|
@@ -72,8 +72,8 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@babel/core": "^7.15.8",
|
|
74
74
|
"@babel/preset-env": "^7.15.8",
|
|
75
|
-
"@netlify/build": "^18.
|
|
76
|
-
"@netlify/eslint-config-node": "^3.3.
|
|
75
|
+
"@netlify/build": "^18.25.1",
|
|
76
|
+
"@netlify/eslint-config-node": "^3.3.7",
|
|
77
77
|
"@testing-library/cypress": "^8.0.1",
|
|
78
78
|
"@types/fs-extra": "^9.0.13",
|
|
79
79
|
"@types/jest": "^27.0.2",
|
package/lib/.DS_Store
DELETED
|
Binary file
|