@netlify/plugin-nextjs 4.1.3 → 4.2.3
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/README.md +22 -1
- package/lib/helpers/cache.js +3 -3
- package/lib/helpers/config.js +3 -3
- package/lib/helpers/files.js +63 -59
- package/lib/helpers/functions.js +18 -15
- package/lib/helpers/redirects.js +132 -39
- package/lib/helpers/utils.js +8 -18
- package/lib/helpers/verification.js +27 -21
- package/lib/index.js +27 -26
- package/lib/templates/getHandler.js +60 -46
- package/lib/templates/getPageResolver.js +4 -4
- package/lib/templates/handlerUtils.js +21 -8
- package/lib/templates/ipx.js +1 -1
- package/package.json +10 -15
package/README.md
CHANGED
|
@@ -31,6 +31,12 @@ npm install -D @netlify/plugin-nextjs
|
|
|
31
31
|
package = "@netlify/plugin-nextjs"
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
## Deploying
|
|
35
|
+
|
|
36
|
+
If you build on Netlify, this plugin will work with no additional configuration. However if you are building and
|
|
37
|
+
deploying locally using the Netlify CLI, you must deploy using `netlify deploy --build`. Running the
|
|
38
|
+
build and deploy commands separately will not work, because the plugin will not generate the required configuration.
|
|
39
|
+
|
|
34
40
|
## Migrating from an older version of the plugin
|
|
35
41
|
|
|
36
42
|
You can manually upgrade from the previous version of the plugin by running the following command:
|
|
@@ -58,7 +64,8 @@ it.
|
|
|
58
64
|
|
|
59
65
|
If you currently use redirects or rewrites on your site, see
|
|
60
66
|
[the Rewrites and Redirects guide](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/redirects-rewrites.md)
|
|
61
|
-
for information on changes to how they are handled in this version.
|
|
67
|
+
for information on changes to how they are handled in this version. In particular, note that `_redirects` and `_headers`
|
|
68
|
+
files must be placed in `public`, not in the root of the site.
|
|
62
69
|
|
|
63
70
|
If you want to use Next 12's beta Middleware feature, this will mostly work as expected but please
|
|
64
71
|
[read the docs on some caveats and workarounds](https://github.com/netlify/netlify-plugin-nextjs/blob/main/docs/middleware.md)
|
|
@@ -85,6 +92,20 @@ you can remove it. Alternatively you can
|
|
|
85
92
|
support. See [`demos/next-export`](https://github.com/netlify/netlify-plugin-nextjs/tree/main/demos/next-export) for an
|
|
86
93
|
example.
|
|
87
94
|
|
|
95
|
+
## Asset optimization
|
|
96
|
+
|
|
97
|
+
Netlify [asset optimization](https://docs.netlify.com/site-deploys/post-processing/) should not be used with Next.js
|
|
98
|
+
sites. Assets are already optimized by Next.js at build time, and doing further optimization can break your site. Ensure
|
|
99
|
+
that it is not enabled at **Site settings > Build & deploy > Post processing > Asset optimization**.
|
|
100
|
+
|
|
101
|
+
## Generated functions
|
|
102
|
+
|
|
103
|
+
This plugin works by generating three Netlify functions that handle requests that haven't been pre-rendered. These are
|
|
104
|
+
`___netlify-handler` (for SSR and API routes), `___netlify-odb-handler` (for ISR and fallback routes), and `_ipx` (for
|
|
105
|
+
images). You can see the requests for these in [the function logs](https://docs.netlify.com/functions/logs/). For ISR
|
|
106
|
+
and fallback routes you will not see any requests that are served from the edge cache, just actual rendering requests.
|
|
107
|
+
These are all internal functions, so you won't find them in your site's own functions directory.
|
|
108
|
+
|
|
88
109
|
## Feedback
|
|
89
110
|
|
|
90
111
|
If you think you have found a bug in the plugin,
|
package/lib/helpers/cache.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.saveCache = exports.restoreCache = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const restoreCache = async ({ cache, publish }) => {
|
|
6
|
-
const cacheDir = path_1.join(publish, 'cache');
|
|
6
|
+
const cacheDir = (0, path_1.join)(publish, 'cache');
|
|
7
7
|
if (await cache.restore(cacheDir)) {
|
|
8
8
|
console.log('Next.js cache restored.');
|
|
9
9
|
}
|
|
@@ -13,8 +13,8 @@ const restoreCache = async ({ cache, publish }) => {
|
|
|
13
13
|
};
|
|
14
14
|
exports.restoreCache = restoreCache;
|
|
15
15
|
const saveCache = async ({ cache, publish }) => {
|
|
16
|
-
const cacheDir = path_1.join(publish, 'cache');
|
|
17
|
-
const buildManifest = path_1.join(publish, 'build-manifest.json');
|
|
16
|
+
const cacheDir = (0, path_1.join)(publish, 'cache');
|
|
17
|
+
const buildManifest = (0, path_1.join)(publish, 'build-manifest.json');
|
|
18
18
|
if (await cache.save(cacheDir, { digests: [buildManifest] })) {
|
|
19
19
|
console.log('Next.js cache saved.');
|
|
20
20
|
}
|
package/lib/helpers/config.js
CHANGED
|
@@ -13,7 +13,7 @@ const defaultFailBuild = (message, { error }) => {
|
|
|
13
13
|
};
|
|
14
14
|
const getNextConfig = async function getNextConfig({ publish, failBuild = defaultFailBuild, }) {
|
|
15
15
|
try {
|
|
16
|
-
const { config, appDir, ignore } = await fs_extra_1.readJSON(pathe_1.join(publish, 'required-server-files.json'));
|
|
16
|
+
const { config, appDir, ignore } = await (0, fs_extra_1.readJSON)((0, pathe_1.join)(publish, 'required-server-files.json'));
|
|
17
17
|
if (!config) {
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
19
19
|
// @ts-ignore
|
|
@@ -28,7 +28,7 @@ const getNextConfig = async function getNextConfig({ publish, failBuild = defaul
|
|
|
28
28
|
exports.getNextConfig = getNextConfig;
|
|
29
29
|
const resolveModuleRoot = (moduleName) => {
|
|
30
30
|
try {
|
|
31
|
-
return pathe_1.dirname(pathe_1.relative(process.cwd(), require.resolve(`${moduleName}/package.json`, { paths: [process.cwd()] })));
|
|
31
|
+
return (0, pathe_1.dirname)((0, pathe_1.relative)(process.cwd(), require.resolve(`${moduleName}/package.json`, { paths: [process.cwd()] })));
|
|
32
32
|
}
|
|
33
33
|
catch {
|
|
34
34
|
return null;
|
|
@@ -45,7 +45,7 @@ const configureHandlerFunctions = ({ netlifyConfig, publish, ignore = [] }) => {
|
|
|
45
45
|
(_a = netlifyConfig.functions)[functionName] || (_a[functionName] = { included_files: [], external_node_modules: [] });
|
|
46
46
|
netlifyConfig.functions[functionName].node_bundler = 'nft';
|
|
47
47
|
(_b = netlifyConfig.functions[functionName]).included_files || (_b.included_files = []);
|
|
48
|
-
netlifyConfig.functions[functionName].included_files.push('.env', '.env.local', '.env.production', '.env.production.local', `${publish}/server/**`, `${publish}/serverless/**`, `${publish}/*.json`, `${publish}/BUILD_ID`, `${publish}/static/chunks/webpack-middleware*.js`, `!${publish}/server/**/*.js.nft.json`, ...ignore.map((path) => `!${slash_1.default(path)}`));
|
|
48
|
+
netlifyConfig.functions[functionName].included_files.push('.env', '.env.local', '.env.production', '.env.production.local', `${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)}`));
|
|
49
49
|
const nextRoot = resolveModuleRoot('next');
|
|
50
50
|
if (nextRoot) {
|
|
51
51
|
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`, `!${nextRoot}/dist/compiled/terser/bundle.min.js`);
|
package/lib/helpers/files.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.movePublicFiles = exports.unpatchNextFiles = exports.patchNextFiles = exports.moveStaticPages = exports.matchesRewrite = exports.matchesRedirect = exports.matchMiddleware = exports.stripLocale = exports.isDynamicRoute = void 0;
|
|
6
|
+
exports.movePublicFiles = exports.unpatchNextFiles = exports.patchNextFiles = exports.moveStaticPages = exports.getMiddleware = exports.matchesRewrite = exports.matchesRedirect = exports.matchMiddleware = exports.stripLocale = exports.isDynamicRoute = void 0;
|
|
7
7
|
/* eslint-disable max-lines */
|
|
8
8
|
const os_1 = require("os");
|
|
9
9
|
const chalk_1 = require("chalk");
|
|
@@ -43,33 +43,37 @@ const matchesRedirect = (file, redirects) => {
|
|
|
43
43
|
exports.matchesRedirect = matchesRedirect;
|
|
44
44
|
const matchesRewrite = (file, rewrites) => {
|
|
45
45
|
if (Array.isArray(rewrites)) {
|
|
46
|
-
return exports.matchesRedirect(file, rewrites);
|
|
46
|
+
return (0, exports.matchesRedirect)(file, rewrites);
|
|
47
47
|
}
|
|
48
48
|
if (!Array.isArray(rewrites === null || rewrites === void 0 ? void 0 : rewrites.beforeFiles)) {
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
-
return exports.matchesRedirect(file, rewrites.beforeFiles);
|
|
51
|
+
return (0, exports.matchesRedirect)(file, rewrites.beforeFiles);
|
|
52
52
|
};
|
|
53
53
|
exports.matchesRewrite = matchesRewrite;
|
|
54
|
+
const getMiddleware = async (publish) => {
|
|
55
|
+
var _a;
|
|
56
|
+
const manifestPath = (0, pathe_1.join)(publish, 'server', 'middleware-manifest.json');
|
|
57
|
+
if ((0, fs_extra_1.existsSync)(manifestPath)) {
|
|
58
|
+
const manifest = await (0, fs_extra_1.readJson)(manifestPath, { throws: false });
|
|
59
|
+
return (_a = manifest === null || manifest === void 0 ? void 0 : manifest.sortedMiddleware) !== null && _a !== void 0 ? _a : [];
|
|
60
|
+
}
|
|
61
|
+
return [];
|
|
62
|
+
};
|
|
63
|
+
exports.getMiddleware = getMiddleware;
|
|
54
64
|
// eslint-disable-next-line max-lines-per-function
|
|
55
65
|
const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
56
66
|
console.log('Moving static page files to serve from CDN...');
|
|
57
|
-
const outputDir = pathe_1.join(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless');
|
|
58
|
-
const root = pathe_1.join(outputDir, 'pages');
|
|
59
|
-
const buildId = fs_extra_1.readFileSync(pathe_1.join(netlifyConfig.build.publish, 'BUILD_ID'), 'utf8').trim();
|
|
60
|
-
const dataDir = pathe_1.join('_next', 'data', buildId);
|
|
61
|
-
await fs_extra_1.ensureDir(dataDir);
|
|
67
|
+
const outputDir = (0, pathe_1.join)(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless');
|
|
68
|
+
const root = (0, pathe_1.join)(outputDir, 'pages');
|
|
69
|
+
const buildId = (0, fs_extra_1.readFileSync)((0, pathe_1.join)(netlifyConfig.build.publish, 'BUILD_ID'), 'utf8').trim();
|
|
70
|
+
const dataDir = (0, pathe_1.join)('_next', 'data', buildId);
|
|
71
|
+
await (0, fs_extra_1.ensureDir)(dataDir);
|
|
62
72
|
// Load the middleware manifest so we can check if a file matches it before moving
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (manifest === null || manifest === void 0 ? void 0 : manifest.middleware) {
|
|
68
|
-
middleware = Object.keys(manifest.middleware).map((path) => path.slice(1));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
const prerenderManifest = await fs_extra_1.readJson(pathe_1.join(netlifyConfig.build.publish, 'prerender-manifest.json'));
|
|
72
|
-
const { redirects, rewrites } = await fs_extra_1.readJson(pathe_1.join(netlifyConfig.build.publish, 'routes-manifest.json'));
|
|
73
|
+
const middlewarePaths = await (0, exports.getMiddleware)(netlifyConfig.build.publish);
|
|
74
|
+
const middleware = middlewarePaths.map((path) => path.slice(1));
|
|
75
|
+
const prerenderManifest = await (0, fs_extra_1.readJson)((0, pathe_1.join)(netlifyConfig.build.publish, 'prerender-manifest.json'));
|
|
76
|
+
const { redirects, rewrites } = await (0, fs_extra_1.readJson)((0, pathe_1.join)(netlifyConfig.build.publish, 'routes-manifest.json'));
|
|
73
77
|
const isrFiles = new Set();
|
|
74
78
|
const shortRevalidateRoutes = [];
|
|
75
79
|
Object.entries(prerenderManifest.routes).forEach(([route, { initialRevalidateSeconds }]) => {
|
|
@@ -87,20 +91,20 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
87
91
|
const filesManifest = {};
|
|
88
92
|
const moveFile = async (file) => {
|
|
89
93
|
const isData = file.endsWith('.json');
|
|
90
|
-
const source = pathe_1.join(root, file);
|
|
91
|
-
const targetFile = isData ? pathe_1.join(dataDir, file) : file;
|
|
94
|
+
const source = (0, pathe_1.join)(root, file);
|
|
95
|
+
const targetFile = isData ? (0, pathe_1.join)(dataDir, file) : file;
|
|
92
96
|
files.push(file);
|
|
93
97
|
filesManifest[file] = targetFile;
|
|
94
|
-
const dest = pathe_1.join(netlifyConfig.build.publish, targetFile);
|
|
98
|
+
const dest = (0, pathe_1.join)(netlifyConfig.build.publish, targetFile);
|
|
95
99
|
try {
|
|
96
|
-
await fs_extra_1.move(source, dest);
|
|
100
|
+
await (0, fs_extra_1.move)(source, dest);
|
|
97
101
|
}
|
|
98
102
|
catch (error) {
|
|
99
103
|
console.warn('Error moving file', source, error);
|
|
100
104
|
}
|
|
101
105
|
};
|
|
102
106
|
// Move all static files, except error documents and nft manifests
|
|
103
|
-
const pages = await globby_1.default(['**/*.{html,json}', '!**/(500|404|*.js.nft).{html,json}'], {
|
|
107
|
+
const pages = await (0, globby_1.default)(['**/*.{html,json}', '!**/(500|404|*.js.nft).{html,json}'], {
|
|
104
108
|
cwd: root,
|
|
105
109
|
dot: true,
|
|
106
110
|
});
|
|
@@ -109,27 +113,27 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
109
113
|
const matchedRedirects = new Set();
|
|
110
114
|
const matchedRewrites = new Set();
|
|
111
115
|
// Limit concurrent file moves to number of cpus or 2 if there is only 1
|
|
112
|
-
const limit = p_limit_1.default(Math.max(2, os_1.cpus().length));
|
|
116
|
+
const limit = (0, p_limit_1.default)(Math.max(2, (0, os_1.cpus)().length));
|
|
113
117
|
const promises = pages.map((rawPath) => {
|
|
114
|
-
const filePath = slash_1.default(rawPath);
|
|
118
|
+
const filePath = (0, slash_1.default)(rawPath);
|
|
115
119
|
// Don't move ISR files, as they're used for the first request
|
|
116
120
|
if (isrFiles.has(filePath)) {
|
|
117
121
|
return;
|
|
118
122
|
}
|
|
119
|
-
if (exports.isDynamicRoute(filePath)) {
|
|
123
|
+
if ((0, exports.isDynamicRoute)(filePath)) {
|
|
120
124
|
return;
|
|
121
125
|
}
|
|
122
|
-
if (exports.matchesRedirect(filePath, redirects)) {
|
|
126
|
+
if ((0, exports.matchesRedirect)(filePath, redirects)) {
|
|
123
127
|
matchedRedirects.add(filePath);
|
|
124
128
|
return;
|
|
125
129
|
}
|
|
126
|
-
if (exports.matchesRewrite(filePath, rewrites)) {
|
|
130
|
+
if ((0, exports.matchesRewrite)(filePath, rewrites)) {
|
|
127
131
|
matchedRewrites.add(filePath);
|
|
128
132
|
return;
|
|
129
133
|
}
|
|
130
134
|
// Middleware matches against the unlocalised path
|
|
131
|
-
const unlocalizedPath = exports.stripLocale(rawPath, i18n === null || i18n === void 0 ? void 0 : i18n.locales);
|
|
132
|
-
const middlewarePath = exports.matchMiddleware(middleware, unlocalizedPath);
|
|
135
|
+
const unlocalizedPath = (0, exports.stripLocale)(rawPath, i18n === null || i18n === void 0 ? void 0 : i18n.locales);
|
|
136
|
+
const middlewarePath = (0, exports.matchMiddleware)(middleware, unlocalizedPath);
|
|
133
137
|
// 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
|
|
134
138
|
if (middlewarePath) {
|
|
135
139
|
matchingMiddleware.add(middlewarePath);
|
|
@@ -141,67 +145,67 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
141
145
|
await Promise.all(promises);
|
|
142
146
|
console.log(`Moved ${files.length} files`);
|
|
143
147
|
if (matchedPages.size !== 0) {
|
|
144
|
-
console.log(chalk_1.yellowBright(outdent_1.outdent `
|
|
148
|
+
console.log((0, chalk_1.yellowBright)((0, outdent_1.outdent) `
|
|
145
149
|
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.
|
|
146
150
|
This is fine, but we're letting you know because it may not be what you expect.
|
|
147
151
|
`));
|
|
148
|
-
console.log(outdent_1.outdent `
|
|
152
|
+
console.log((0, outdent_1.outdent) `
|
|
149
153
|
The following middleware matched statically-rendered pages:
|
|
150
154
|
|
|
151
|
-
${chalk_1.yellowBright([...matchingMiddleware].map((mid) => `- /${mid}/_middleware`).join('\n'))}
|
|
155
|
+
${(0, chalk_1.yellowBright)([...matchingMiddleware].map((mid) => `- /${mid}/_middleware`).join('\n'))}
|
|
152
156
|
${constants_1.DIVIDER}
|
|
153
157
|
`);
|
|
154
158
|
// There could potentially be thousands of matching pages, so we don't want to spam the console with this
|
|
155
159
|
if (matchedPages.size < 50) {
|
|
156
|
-
console.log(outdent_1.outdent `
|
|
160
|
+
console.log((0, outdent_1.outdent) `
|
|
157
161
|
The following files matched middleware and were not moved to the CDN:
|
|
158
162
|
|
|
159
|
-
${chalk_1.yellowBright([...matchedPages].map((mid) => `- ${mid}`).join('\n'))}
|
|
163
|
+
${(0, chalk_1.yellowBright)([...matchedPages].map((mid) => `- ${mid}`).join('\n'))}
|
|
160
164
|
${constants_1.DIVIDER}
|
|
161
165
|
`);
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
if (matchedRedirects.size !== 0 || matchedRewrites.size !== 0) {
|
|
165
|
-
console.log(chalk_1.yellowBright(outdent_1.outdent `
|
|
169
|
+
console.log((0, chalk_1.yellowBright)((0, outdent_1.outdent) `
|
|
166
170
|
Skipped moving ${matchedRedirects.size + matchedRewrites.size} files because they match redirects or beforeFiles rewrites, so cannot be deployed to the CDN and will be served from the origin instead.
|
|
167
171
|
`));
|
|
168
172
|
if (matchedRedirects.size < 50 && matchedRedirects.size !== 0) {
|
|
169
|
-
console.log(outdent_1.outdent `
|
|
173
|
+
console.log((0, outdent_1.outdent) `
|
|
170
174
|
The following files matched redirects and were not moved to the CDN:
|
|
171
175
|
|
|
172
|
-
${chalk_1.yellowBright([...matchedRedirects].map((mid) => `- ${mid}`).join('\n'))}
|
|
176
|
+
${(0, chalk_1.yellowBright)([...matchedRedirects].map((mid) => `- ${mid}`).join('\n'))}
|
|
173
177
|
${constants_1.DIVIDER}
|
|
174
178
|
`);
|
|
175
179
|
}
|
|
176
180
|
if (matchedRewrites.size < 50 && matchedRewrites.size !== 0) {
|
|
177
|
-
console.log(outdent_1.outdent `
|
|
181
|
+
console.log((0, outdent_1.outdent) `
|
|
178
182
|
The following files matched beforeFiles rewrites and were not moved to the CDN:
|
|
179
183
|
|
|
180
|
-
${chalk_1.yellowBright([...matchedRewrites].map((mid) => `- ${mid}`).join('\n'))}
|
|
184
|
+
${(0, chalk_1.yellowBright)([...matchedRewrites].map((mid) => `- ${mid}`).join('\n'))}
|
|
181
185
|
${constants_1.DIVIDER}
|
|
182
186
|
`);
|
|
183
187
|
}
|
|
184
188
|
}
|
|
185
189
|
// Write the manifest for use in the serverless functions
|
|
186
|
-
await fs_extra_1.writeJson(pathe_1.join(netlifyConfig.build.publish, 'static-manifest.json'), Object.entries(filesManifest));
|
|
190
|
+
await (0, fs_extra_1.writeJson)((0, pathe_1.join)(netlifyConfig.build.publish, 'static-manifest.json'), Object.entries(filesManifest));
|
|
187
191
|
if (i18n === null || i18n === void 0 ? void 0 : i18n.defaultLocale) {
|
|
188
192
|
// Copy the default locale into the root
|
|
189
|
-
const defaultLocaleDir = pathe_1.join(netlifyConfig.build.publish, i18n.defaultLocale);
|
|
190
|
-
if (fs_extra_1.existsSync(defaultLocaleDir)) {
|
|
191
|
-
await fs_extra_1.copy(defaultLocaleDir, `${netlifyConfig.build.publish}/`);
|
|
193
|
+
const defaultLocaleDir = (0, pathe_1.join)(netlifyConfig.build.publish, i18n.defaultLocale);
|
|
194
|
+
if ((0, fs_extra_1.existsSync)(defaultLocaleDir)) {
|
|
195
|
+
await (0, fs_extra_1.copy)(defaultLocaleDir, `${netlifyConfig.build.publish}/`);
|
|
192
196
|
}
|
|
193
|
-
const defaultLocaleIndex = pathe_1.join(netlifyConfig.build.publish, `${i18n.defaultLocale}.html`);
|
|
194
|
-
const indexHtml = pathe_1.join(netlifyConfig.build.publish, 'index.html');
|
|
195
|
-
if (fs_extra_1.existsSync(defaultLocaleIndex) && !fs_extra_1.existsSync(indexHtml)) {
|
|
197
|
+
const defaultLocaleIndex = (0, pathe_1.join)(netlifyConfig.build.publish, `${i18n.defaultLocale}.html`);
|
|
198
|
+
const indexHtml = (0, pathe_1.join)(netlifyConfig.build.publish, 'index.html');
|
|
199
|
+
if ((0, fs_extra_1.existsSync)(defaultLocaleIndex) && !(0, fs_extra_1.existsSync)(indexHtml)) {
|
|
196
200
|
try {
|
|
197
|
-
await fs_extra_1.copy(defaultLocaleIndex, indexHtml, { overwrite: false });
|
|
198
|
-
await fs_extra_1.copy(pathe_1.join(netlifyConfig.build.publish, `${i18n.defaultLocale}.json`), pathe_1.join(netlifyConfig.build.publish, 'index.json'), { overwrite: false });
|
|
201
|
+
await (0, fs_extra_1.copy)(defaultLocaleIndex, indexHtml, { overwrite: false });
|
|
202
|
+
await (0, fs_extra_1.copy)((0, pathe_1.join)(netlifyConfig.build.publish, `${i18n.defaultLocale}.json`), (0, pathe_1.join)(netlifyConfig.build.publish, 'index.json'), { overwrite: false });
|
|
199
203
|
}
|
|
200
204
|
catch { }
|
|
201
205
|
}
|
|
202
206
|
}
|
|
203
207
|
if (shortRevalidateRoutes.length !== 0) {
|
|
204
|
-
console.log(outdent_1.outdent `
|
|
208
|
+
console.log((0, outdent_1.outdent) `
|
|
205
209
|
The following routes use "revalidate" values of under ${constants_1.MINIMUM_REVALIDATE_SECONDS} seconds, which is not supported.
|
|
206
210
|
They will use a revalidate time of ${constants_1.MINIMUM_REVALIDATE_SECONDS} seconds instead.
|
|
207
211
|
`);
|
|
@@ -217,16 +221,16 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
217
221
|
};
|
|
218
222
|
exports.moveStaticPages = moveStaticPages;
|
|
219
223
|
const patchFile = async ({ file, from, to }) => {
|
|
220
|
-
if (!fs_extra_1.existsSync(file)) {
|
|
224
|
+
if (!(0, fs_extra_1.existsSync)(file)) {
|
|
221
225
|
return;
|
|
222
226
|
}
|
|
223
|
-
const content = await fs_extra_1.readFile(file, 'utf8');
|
|
227
|
+
const content = await (0, fs_extra_1.readFile)(file, 'utf8');
|
|
224
228
|
if (content.includes(to)) {
|
|
225
229
|
return;
|
|
226
230
|
}
|
|
227
231
|
const newContent = content.replace(from, to);
|
|
228
|
-
await fs_extra_1.writeFile(`${file}.orig`, content);
|
|
229
|
-
await fs_extra_1.writeFile(file, newContent);
|
|
232
|
+
await (0, fs_extra_1.writeFile)(`${file}.orig`, content);
|
|
233
|
+
await (0, fs_extra_1.writeFile)(file, newContent);
|
|
230
234
|
};
|
|
231
235
|
const getServerFile = (root) => {
|
|
232
236
|
let serverFile;
|
|
@@ -262,8 +266,8 @@ exports.patchNextFiles = patchNextFiles;
|
|
|
262
266
|
const unpatchNextFiles = async (root) => {
|
|
263
267
|
const serverFile = getServerFile(root);
|
|
264
268
|
const origFile = `${serverFile}.orig`;
|
|
265
|
-
if (fs_extra_1.existsSync(origFile)) {
|
|
266
|
-
await fs_extra_1.move(origFile, serverFile, { overwrite: true });
|
|
269
|
+
if ((0, fs_extra_1.existsSync)(origFile)) {
|
|
270
|
+
await (0, fs_extra_1.move)(origFile, serverFile, { overwrite: true });
|
|
267
271
|
}
|
|
268
272
|
};
|
|
269
273
|
exports.unpatchNextFiles = unpatchNextFiles;
|
|
@@ -274,9 +278,9 @@ const movePublicFiles = async ({ appDir, outdir, publish, }) => {
|
|
|
274
278
|
// If it exists, copy the files from the public folder there in order to include
|
|
275
279
|
// any files that were generated during the build. Otherwise, copy the public
|
|
276
280
|
// directory from the original app directory.
|
|
277
|
-
const publicDir = outdir ? pathe_1.join(appDir, outdir, 'public') : pathe_1.join(appDir, 'public');
|
|
278
|
-
if (fs_extra_1.existsSync(publicDir)) {
|
|
279
|
-
await fs_extra_1.copy(publicDir, `${publish}/`);
|
|
281
|
+
const publicDir = outdir ? (0, pathe_1.join)(appDir, outdir, 'public') : (0, pathe_1.join)(appDir, 'public');
|
|
282
|
+
if ((0, fs_extra_1.existsSync)(publicDir)) {
|
|
283
|
+
await (0, fs_extra_1.copy)(publicDir, `${publish}/`);
|
|
280
284
|
}
|
|
281
285
|
};
|
|
282
286
|
exports.movePublicFiles = movePublicFiles;
|
package/lib/helpers/functions.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.setupImageFunction = exports.generatePagesResolver = exports.generateFunctions = void 0;
|
|
7
|
+
const node_bridge_1 = __importDefault(require("@vercel/node-bridge"));
|
|
4
8
|
const fs_extra_1 = require("fs-extra");
|
|
5
9
|
const pathe_1 = require("pathe");
|
|
6
10
|
const constants_1 = require("../constants");
|
|
@@ -8,15 +12,14 @@ const getHandler_1 = require("../templates/getHandler");
|
|
|
8
12
|
const getPageResolver_1 = require("../templates/getPageResolver");
|
|
9
13
|
const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }, appDir) => {
|
|
10
14
|
const functionsDir = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const publishDir = pathe_1.relative(functionDir, pathe_1.join(process.cwd(), PUBLISH_DIR));
|
|
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));
|
|
14
17
|
const writeHandler = async (func, isODB) => {
|
|
15
|
-
const handlerSource = await getHandler_1.getHandler({ isODB, publishDir, appDir: pathe_1.relative(functionDir, appDir) });
|
|
16
|
-
await fs_extra_1.ensureDir(pathe_1.join(functionsDir, func));
|
|
17
|
-
await fs_extra_1.writeFile(pathe_1.join(functionsDir, func, `${func}.js`), handlerSource);
|
|
18
|
-
await fs_extra_1.copyFile(
|
|
19
|
-
await fs_extra_1.copyFile(pathe_1.join(__dirname, '..', '..', 'lib', 'templates', 'handlerUtils.js'), pathe_1.join(functionsDir, func, 'handlerUtils.js'));
|
|
18
|
+
const handlerSource = await (0, getHandler_1.getHandler)({ isODB, publishDir, appDir: (0, pathe_1.relative)(functionDir, appDir) });
|
|
19
|
+
await (0, fs_extra_1.ensureDir)((0, pathe_1.join)(functionsDir, func));
|
|
20
|
+
await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsDir, func, `${func}.js`), handlerSource);
|
|
21
|
+
await (0, fs_extra_1.copyFile)(node_bridge_1.default, (0, pathe_1.join)(functionsDir, func, 'bridge.js'));
|
|
22
|
+
await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'handlerUtils.js'), (0, pathe_1.join)(functionsDir, func, 'handlerUtils.js'));
|
|
20
23
|
};
|
|
21
24
|
await writeHandler(constants_1.HANDLER_FUNCTION_NAME, false);
|
|
22
25
|
await writeHandler(constants_1.ODB_FUNCTION_NAME, true);
|
|
@@ -28,25 +31,25 @@ exports.generateFunctions = generateFunctions;
|
|
|
28
31
|
*/
|
|
29
32
|
const generatePagesResolver = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, PUBLISH_DIR }, target, }) => {
|
|
30
33
|
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
|
|
31
|
-
const jsSource = await getPageResolver_1.getPageResolver({
|
|
34
|
+
const jsSource = await (0, getPageResolver_1.getPageResolver)({
|
|
32
35
|
publish: PUBLISH_DIR,
|
|
33
36
|
target,
|
|
34
37
|
});
|
|
35
|
-
await fs_extra_1.writeFile(pathe_1.join(functionsPath, constants_1.ODB_FUNCTION_NAME, 'pages.js'), jsSource);
|
|
36
|
-
await fs_extra_1.writeFile(pathe_1.join(functionsPath, constants_1.HANDLER_FUNCTION_NAME, 'pages.js'), jsSource);
|
|
38
|
+
await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsPath, constants_1.ODB_FUNCTION_NAME, 'pages.js'), jsSource);
|
|
39
|
+
await (0, fs_extra_1.writeFile)((0, pathe_1.join)(functionsPath, constants_1.HANDLER_FUNCTION_NAME, 'pages.js'), jsSource);
|
|
37
40
|
};
|
|
38
41
|
exports.generatePagesResolver = generatePagesResolver;
|
|
39
42
|
// Move our next/image function into the correct functions directory
|
|
40
43
|
const setupImageFunction = async ({ constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC }, imageconfig = {}, netlifyConfig, basePath, }) => {
|
|
41
44
|
const functionsPath = INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC;
|
|
42
45
|
const functionName = `${constants_1.IMAGE_FUNCTION_NAME}.js`;
|
|
43
|
-
const functionDirectory = pathe_1.join(functionsPath, constants_1.IMAGE_FUNCTION_NAME);
|
|
44
|
-
await fs_extra_1.ensureDir(functionDirectory);
|
|
45
|
-
await fs_extra_1.writeJSON(pathe_1.join(functionDirectory, 'imageconfig.json'), {
|
|
46
|
+
const functionDirectory = (0, pathe_1.join)(functionsPath, constants_1.IMAGE_FUNCTION_NAME);
|
|
47
|
+
await (0, fs_extra_1.ensureDir)(functionDirectory);
|
|
48
|
+
await (0, fs_extra_1.writeJSON)((0, pathe_1.join)(functionDirectory, 'imageconfig.json'), {
|
|
46
49
|
...imageconfig,
|
|
47
50
|
basePath: [basePath, constants_1.IMAGE_FUNCTION_NAME].join('/'),
|
|
48
51
|
});
|
|
49
|
-
await fs_extra_1.copyFile(pathe_1.join(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), pathe_1.join(functionDirectory, functionName));
|
|
52
|
+
await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'ipx.js'), (0, pathe_1.join)(functionDirectory, functionName));
|
|
50
53
|
const imagePath = imageconfig.path || '/_next/image';
|
|
51
54
|
netlifyConfig.redirects.push({
|
|
52
55
|
from: `${imagePath}*`,
|