@netlify/plugin-nextjs 4.37.5-experimental-no-bundler.0 → 4.38.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/helpers/config.js +11 -18
- package/lib/helpers/dev.js +0 -3
- package/lib/helpers/files.js +1 -104
- package/lib/helpers/flags.js +1 -7
- package/lib/helpers/functions.js +5 -82
- package/lib/index.js +1 -5
- package/lib/templates/getHandler.js +0 -5
- package/lib/templates/server.js +12 -2
- package/package.json +1 -1
package/lib/helpers/config.js
CHANGED
|
@@ -69,8 +69,8 @@ exports.hasManuallyAddedModule = hasManuallyAddedModule;
|
|
|
69
69
|
* so that the file `[id].js` is matched correctly.
|
|
70
70
|
*/
|
|
71
71
|
const escapeGlob = (path) => path.replace(/\[/g, '*').replace(/]/g, '*');
|
|
72
|
-
const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [], apiLambdas,
|
|
73
|
-
var _a;
|
|
72
|
+
const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [], apiLambdas, splitApiRoutes, }) => {
|
|
73
|
+
var _a, _b, _c;
|
|
74
74
|
const config = await (0, exports.getRequiredServerFiles)(publish);
|
|
75
75
|
const files = config.files || [];
|
|
76
76
|
const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`));
|
|
@@ -97,23 +97,16 @@ const configureHandlerFunctions = async ({ netlifyConfig, publish, ignore = [],
|
|
|
97
97
|
}
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const { functionName, includedFiles } = lambda;
|
|
103
|
-
(_a = netlifyConfig.functions)[functionName] || (_a[functionName] = { included_files: [] });
|
|
104
|
-
netlifyConfig.functions[functionName].node_bundler = 'none';
|
|
105
|
-
(_b = netlifyConfig.functions[functionName]).included_files || (_b.included_files = []);
|
|
106
|
-
netlifyConfig.functions[functionName].included_files.push(...includedFiles.map(escapeGlob));
|
|
107
|
-
};
|
|
108
|
-
if (ssrLambdas.length === 0) {
|
|
109
|
-
configureFunction(constants_1.HANDLER_FUNCTION_NAME);
|
|
110
|
-
configureFunction(constants_1.ODB_FUNCTION_NAME);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
ssrLambdas.forEach(configureLambda);
|
|
114
|
-
}
|
|
100
|
+
configureFunction(constants_1.HANDLER_FUNCTION_NAME);
|
|
101
|
+
configureFunction(constants_1.ODB_FUNCTION_NAME);
|
|
115
102
|
if (splitApiRoutes) {
|
|
116
|
-
apiLambdas
|
|
103
|
+
for (const apiLambda of apiLambdas) {
|
|
104
|
+
const { functionName, includedFiles } = apiLambda;
|
|
105
|
+
(_b = netlifyConfig.functions)[functionName] || (_b[functionName] = { included_files: [] });
|
|
106
|
+
netlifyConfig.functions[functionName].node_bundler = 'none';
|
|
107
|
+
(_c = netlifyConfig.functions[functionName]).included_files || (_c.included_files = []);
|
|
108
|
+
netlifyConfig.functions[functionName].included_files.push(...includedFiles.map(escapeGlob));
|
|
109
|
+
}
|
|
117
110
|
}
|
|
118
111
|
else {
|
|
119
112
|
configureFunction('_api_*');
|
package/lib/helpers/dev.js
CHANGED
|
@@ -7,13 +7,10 @@ exports.onPreDev = void 0;
|
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const execa_1 = __importDefault(require("execa"));
|
|
9
9
|
const edge_1 = require("./edge");
|
|
10
|
-
const files_1 = require("./files");
|
|
11
10
|
// The types haven't been updated yet
|
|
12
11
|
const onPreDev = async ({ constants, netlifyConfig }) => {
|
|
13
12
|
var _a;
|
|
14
13
|
const base = (_a = netlifyConfig.build.base) !== null && _a !== void 0 ? _a : process.cwd();
|
|
15
|
-
// Need to patch the files, because build might not have been run
|
|
16
|
-
await (0, files_1.patchNextFiles)(base);
|
|
17
14
|
await (0, edge_1.writeDevEdgeFunction)(constants);
|
|
18
15
|
// Don't await this or it will never finish
|
|
19
16
|
execa_1.default.node((0, path_1.resolve)(__dirname, '..', '..', 'lib', 'helpers', 'middlewareWatcher.js'), [base, process.env.NODE_ENV === 'test' ? '--once' : ''], {
|
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.removeMetadataFiles = exports.movePublicFiles = exports.
|
|
6
|
+
exports.removeMetadataFiles = exports.movePublicFiles = exports.getDependenciesOfFile = exports.getSourceFileForPage = exports.getServerFile = exports.moveStaticPages = exports.getMiddleware = exports.matchesRewrite = exports.matchesRedirect = exports.matchMiddleware = exports.stripLocale = exports.isDynamicRoute = void 0;
|
|
7
7
|
const os_1 = require("os");
|
|
8
8
|
const chalk_1 = require("chalk");
|
|
9
9
|
const fs_extra_1 = require("fs-extra");
|
|
@@ -236,36 +236,6 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, basePath, }) => {
|
|
|
236
236
|
}
|
|
237
237
|
};
|
|
238
238
|
exports.moveStaticPages = moveStaticPages;
|
|
239
|
-
const PATCH_WARNING = `/* File patched by Netlify */`;
|
|
240
|
-
/**
|
|
241
|
-
* Attempt to patch a source file, preserving a backup
|
|
242
|
-
*/
|
|
243
|
-
const patchFile = async ({ file, replacements, }) => {
|
|
244
|
-
if (!(0, fs_extra_1.existsSync)(file)) {
|
|
245
|
-
console.warn('File was not found');
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
let content = await (0, fs_extra_1.readFile)(file, 'utf8');
|
|
249
|
-
// If the file has already been patched, patch the backed-up original instead
|
|
250
|
-
if (content.includes(PATCH_WARNING) && (0, fs_extra_1.existsSync)(`${file}.orig`)) {
|
|
251
|
-
content = await (0, fs_extra_1.readFile)(`${file}.orig`, 'utf8');
|
|
252
|
-
}
|
|
253
|
-
const newContent = replacements.reduce((acc, [from, to]) => {
|
|
254
|
-
if (acc.includes(to)) {
|
|
255
|
-
console.log('Already patched. Skipping.');
|
|
256
|
-
return acc;
|
|
257
|
-
}
|
|
258
|
-
return acc.replace(from, to);
|
|
259
|
-
}, content);
|
|
260
|
-
if (newContent === content) {
|
|
261
|
-
console.warn('File was not changed');
|
|
262
|
-
return false;
|
|
263
|
-
}
|
|
264
|
-
await (0, fs_extra_1.writeFile)(`${file}.orig`, content);
|
|
265
|
-
await (0, fs_extra_1.writeFile)(file, `${newContent}\n${PATCH_WARNING}`);
|
|
266
|
-
console.log('Done');
|
|
267
|
-
return true;
|
|
268
|
-
};
|
|
269
239
|
/**
|
|
270
240
|
* The file we need has moved around a bit over the past few versions,
|
|
271
241
|
* so we iterate through the options until we find it
|
|
@@ -312,79 +282,6 @@ const getDependenciesOfFile = async (file) => {
|
|
|
312
282
|
return dependencies.files.map((dep) => (0, pathe_1.resolve)((0, pathe_1.dirname)(file), dep));
|
|
313
283
|
};
|
|
314
284
|
exports.getDependenciesOfFile = getDependenciesOfFile;
|
|
315
|
-
const baseServerReplacements = [
|
|
316
|
-
// force manual revalidate during cache fetches
|
|
317
|
-
// for more info https://github.com/netlify/next-runtime/pull/1541
|
|
318
|
-
[
|
|
319
|
-
`checkIsManualRevalidate(req, this.renderOpts.previewProps)`,
|
|
320
|
-
`checkIsManualRevalidate(process.env._REVALIDATE_SSG ? { headers: { 'x-prerender-revalidate': this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)`,
|
|
321
|
-
],
|
|
322
|
-
// In https://github.com/vercel/next.js/pull/47803 checkIsManualRevalidate was renamed to checkIsOnDemandRevalidate
|
|
323
|
-
[
|
|
324
|
-
`checkIsOnDemandRevalidate(req, this.renderOpts.previewProps)`,
|
|
325
|
-
`checkIsOnDemandRevalidate(process.env._REVALIDATE_SSG ? { headers: { 'x-prerender-revalidate': this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)`,
|
|
326
|
-
],
|
|
327
|
-
// format of checkIsOnDemandRevalidate changed in 13.3.4
|
|
328
|
-
[
|
|
329
|
-
'checkIsOnDemandRevalidate)(req, this.renderOpts.previewProps)',
|
|
330
|
-
'checkIsOnDemandRevalidate)(process.env._REVALIDATE_SSG ? { headers: { "x-prerender-revalidate": this.renderOpts.previewProps.previewModeId } } : req, this.renderOpts.previewProps)',
|
|
331
|
-
],
|
|
332
|
-
// ensure ISR 404 pages send the correct SWR cache headers
|
|
333
|
-
[`private: isPreviewMode || is404Page && cachedData`, `private: isPreviewMode && cachedData`],
|
|
334
|
-
];
|
|
335
|
-
const nextServerReplacements = [
|
|
336
|
-
[
|
|
337
|
-
`getMiddlewareManifest() {\n if (this.minimalMode) return null;`,
|
|
338
|
-
`getMiddlewareManifest() {\n if (this.minimalMode || (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1')) return null;`,
|
|
339
|
-
],
|
|
340
|
-
[
|
|
341
|
-
`generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode) return []`,
|
|
342
|
-
`generateCatchAllMiddlewareRoute(devReady) {\n if (this.minimalMode || (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1')) return [];`,
|
|
343
|
-
],
|
|
344
|
-
[
|
|
345
|
-
`generateCatchAllMiddlewareRoute() {\n if (this.minimalMode) return undefined;`,
|
|
346
|
-
`generateCatchAllMiddlewareRoute() {\n if (this.minimalMode || (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1')) return undefined;`,
|
|
347
|
-
],
|
|
348
|
-
[
|
|
349
|
-
`getMiddlewareManifest() {\n if (this.minimalMode) {`,
|
|
350
|
-
`getMiddlewareManifest() {\n if (!this.minimalMode && (!process.env.NETLIFY_DEV && process.env.NEXT_DISABLE_NETLIFY_EDGE === 'true' || process.env.NEXT_DISABLE_NETLIFY_EDGE === '1')) {`,
|
|
351
|
-
],
|
|
352
|
-
];
|
|
353
|
-
const patchNextFiles = async (root) => {
|
|
354
|
-
const baseServerFile = (0, exports.getServerFile)(root);
|
|
355
|
-
console.log(`Patching ${baseServerFile}`);
|
|
356
|
-
if (baseServerFile) {
|
|
357
|
-
await patchFile({
|
|
358
|
-
file: baseServerFile,
|
|
359
|
-
replacements: baseServerReplacements,
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
const nextServerFile = (0, exports.getServerFile)(root, false);
|
|
363
|
-
console.log(`Patching ${nextServerFile}`);
|
|
364
|
-
if (nextServerFile) {
|
|
365
|
-
await patchFile({
|
|
366
|
-
file: nextServerFile,
|
|
367
|
-
replacements: nextServerReplacements,
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
exports.patchNextFiles = patchNextFiles;
|
|
372
|
-
const unpatchFile = async (file) => {
|
|
373
|
-
const origFile = `${file}.orig`;
|
|
374
|
-
if ((0, fs_extra_1.existsSync)(origFile)) {
|
|
375
|
-
await (0, fs_extra_1.move)(origFile, file, { overwrite: true });
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
exports.unpatchFile = unpatchFile;
|
|
379
|
-
const unpatchNextFiles = async (root) => {
|
|
380
|
-
const baseServerFile = (0, exports.getServerFile)(root);
|
|
381
|
-
await (0, exports.unpatchFile)(baseServerFile);
|
|
382
|
-
const nextServerFile = (0, exports.getServerFile)(root, false);
|
|
383
|
-
if (nextServerFile !== baseServerFile) {
|
|
384
|
-
await (0, exports.unpatchFile)(nextServerFile);
|
|
385
|
-
}
|
|
386
|
-
};
|
|
387
|
-
exports.unpatchNextFiles = unpatchNextFiles;
|
|
388
285
|
const movePublicFiles = async ({ appDir, outdir, publish, basePath, }) => {
|
|
389
286
|
// `outdir` is a config property added when using Next.js with Nx. It's typically
|
|
390
287
|
// a relative path outside of the appDir, e.g. '../../dist/apps/<app-name>', and
|
package/lib/helpers/flags.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.
|
|
6
|
+
exports.splitApiRoutes = void 0;
|
|
7
7
|
const destr_1 = __importDefault(require("destr"));
|
|
8
8
|
const fs_extra_1 = require("fs-extra");
|
|
9
9
|
const pathe_1 = require("pathe");
|
|
@@ -32,9 +32,3 @@ const splitApiRoutes = (featureFlags, publish) => {
|
|
|
32
32
|
return isEnabled;
|
|
33
33
|
};
|
|
34
34
|
exports.splitApiRoutes = splitApiRoutes;
|
|
35
|
-
const bundleBasedOnNftFiles = (featureFlags) => {
|
|
36
|
-
var _a, _b;
|
|
37
|
-
const isEnabled = (_b = (_a = (0, destr_1.default)(process.env.NEXT_BUNDLE_BASED_ON_NFT_FILES)) !== null && _a !== void 0 ? _a : featureFlags.next_bundle_based_on_nft_files) !== null && _b !== void 0 ? _b : false;
|
|
38
|
-
return isEnabled;
|
|
39
|
-
};
|
|
40
|
-
exports.bundleBasedOnNftFiles = bundleBasedOnNftFiles;
|
package/lib/helpers/functions.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.warnOnApiRoutes = exports.packSingleFunction = exports.getExtendedApiRouteConfigs = exports.getApiRouteConfigs = exports.getAPILambdas = exports.
|
|
6
|
+
exports.warnOnApiRoutes = exports.packSingleFunction = exports.getExtendedApiRouteConfigs = exports.getApiRouteConfigs = exports.getAPILambdas = exports.getAPIPRouteCommonDependencies = exports.traceNPMPackage = exports.setupImageFunction = exports.generatePagesResolver = exports.generateFunctions = void 0;
|
|
7
7
|
const node_bridge_1 = __importDefault(require("@vercel/node-bridge"));
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
const destr_1 = __importDefault(require("destr"));
|
|
@@ -21,7 +21,7 @@ const files_1 = require("./files");
|
|
|
21
21
|
const functionsMetaData_1 = require("./functionsMetaData");
|
|
22
22
|
const pack_1 = require("./pack");
|
|
23
23
|
const utils_1 = require("./utils");
|
|
24
|
-
const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }, appDir, apiLambdas
|
|
24
|
+
const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }, appDir, apiLambdas) => {
|
|
25
25
|
const publish = (0, pathe_1.resolve)(PUBLISH_DIR);
|
|
26
26
|
const functionsDir = (0, pathe_1.resolve)(INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC);
|
|
27
27
|
const functionDir = (0, pathe_1.join)(functionsDir, constants_1.HANDLER_FUNCTION_NAME);
|
|
@@ -81,11 +81,6 @@ const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS
|
|
|
81
81
|
await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'requireHooks.js'), (0, pathe_1.join)(functionsDir, functionName, 'requireHooks.js'));
|
|
82
82
|
await (0, fs_extra_1.copyFile)((0, pathe_1.join)(__dirname, '..', '..', 'lib', 'templates', 'handlerUtils.js'), (0, pathe_1.join)(functionsDir, functionName, 'handlerUtils.js'));
|
|
83
83
|
await (0, functionsMetaData_1.writeFunctionConfiguration)({ functionName, functionTitle, functionsDir });
|
|
84
|
-
const nfInternalFiles = await (0, tiny_glob_1.default)((0, pathe_1.join)(functionsDir, functionName, '**'));
|
|
85
|
-
const lambda = ssrLambdas.find((l) => l.functionName === functionName);
|
|
86
|
-
if (lambda) {
|
|
87
|
-
lambda.includedFiles.push(...nfInternalFiles);
|
|
88
|
-
}
|
|
89
84
|
};
|
|
90
85
|
await writeHandler(constants_1.HANDLER_FUNCTION_NAME, constants_1.HANDLER_FUNCTION_TITLE, false);
|
|
91
86
|
await writeHandler(constants_1.ODB_FUNCTION_NAME, constants_1.ODB_FUNCTION_TITLE, true);
|
|
@@ -204,19 +199,16 @@ const traceNPMPackage = async (packageName, publish) => {
|
|
|
204
199
|
}
|
|
205
200
|
};
|
|
206
201
|
exports.traceNPMPackage = traceNPMPackage;
|
|
207
|
-
const
|
|
202
|
+
const getAPIPRouteCommonDependencies = async (publish) => {
|
|
208
203
|
const deps = await Promise.all([
|
|
209
204
|
traceRequiredServerFiles(publish),
|
|
210
205
|
traceNextServer(publish),
|
|
211
206
|
// used by our own bridge.js
|
|
212
207
|
(0, exports.traceNPMPackage)('follow-redirects', publish),
|
|
213
|
-
// using package.json because otherwise, we'd find some /dist/... path
|
|
214
|
-
(0, exports.traceNPMPackage)('@netlify/functions/package.json', publish),
|
|
215
|
-
(0, exports.traceNPMPackage)('is-promise', publish),
|
|
216
208
|
]);
|
|
217
209
|
return deps.flat(1);
|
|
218
210
|
};
|
|
219
|
-
exports.
|
|
211
|
+
exports.getAPIPRouteCommonDependencies = getAPIPRouteCommonDependencies;
|
|
220
212
|
const sum = (arr) => arr.reduce((v, current) => v + current, 0);
|
|
221
213
|
// TODO: cache results
|
|
222
214
|
const getBundleWeight = async (patterns) => {
|
|
@@ -232,77 +224,8 @@ const getBundleWeight = async (patterns) => {
|
|
|
232
224
|
}));
|
|
233
225
|
return sum(sizes.flat(1));
|
|
234
226
|
};
|
|
235
|
-
const changeExtension = (file, extension) => {
|
|
236
|
-
const base = (0, pathe_1.basename)(file, (0, pathe_1.extname)(file));
|
|
237
|
-
return (0, pathe_1.join)((0, pathe_1.dirname)(file), base + extension);
|
|
238
|
-
};
|
|
239
|
-
const getSSRDependencies = async (publish) => {
|
|
240
|
-
const prerenderManifest = await (0, fs_extra_1.readJSON)((0, pathe_1.join)(publish, 'prerender-manifest.json'));
|
|
241
|
-
return [
|
|
242
|
-
...Object.entries(prerenderManifest.routes).flatMap(([route, ssgRoute]) => {
|
|
243
|
-
if (ssgRoute.initialRevalidateSeconds === false) {
|
|
244
|
-
return [];
|
|
245
|
-
}
|
|
246
|
-
if (ssgRoute.dataRoute.endsWith('.rsc')) {
|
|
247
|
-
return [
|
|
248
|
-
(0, pathe_1.join)(publish, 'server', 'app', ssgRoute.dataRoute),
|
|
249
|
-
(0, pathe_1.join)(publish, 'server', 'app', changeExtension(ssgRoute.dataRoute, '.html')),
|
|
250
|
-
];
|
|
251
|
-
}
|
|
252
|
-
const trimmedPath = route === '/' ? 'index' : route.slice(1);
|
|
253
|
-
return [
|
|
254
|
-
(0, pathe_1.join)(publish, 'server', 'pages', `${trimmedPath}.html`),
|
|
255
|
-
(0, pathe_1.join)(publish, 'server', 'pages', `${trimmedPath}.json`),
|
|
256
|
-
];
|
|
257
|
-
}),
|
|
258
|
-
(0, pathe_1.join)(publish, '**', '*.html'),
|
|
259
|
-
];
|
|
260
|
-
};
|
|
261
|
-
const getSSRLambdas = async (publish) => {
|
|
262
|
-
const commonDependencies = await (0, exports.getCommonDependencies)(publish);
|
|
263
|
-
const ssrRoutes = await getSSRRoutes(publish);
|
|
264
|
-
// TODO: for now, they're the same - but we should separate them
|
|
265
|
-
const nonOdbRoutes = ssrRoutes;
|
|
266
|
-
const odbRoutes = ssrRoutes;
|
|
267
|
-
const ssrDependencies = await getSSRDependencies(publish);
|
|
268
|
-
return [
|
|
269
|
-
{
|
|
270
|
-
functionName: constants_1.HANDLER_FUNCTION_NAME,
|
|
271
|
-
functionTitle: constants_1.HANDLER_FUNCTION_TITLE,
|
|
272
|
-
includedFiles: [
|
|
273
|
-
...commonDependencies,
|
|
274
|
-
...ssrDependencies,
|
|
275
|
-
...nonOdbRoutes.flatMap((route) => route.includedFiles),
|
|
276
|
-
],
|
|
277
|
-
routes: nonOdbRoutes,
|
|
278
|
-
},
|
|
279
|
-
{
|
|
280
|
-
functionName: constants_1.ODB_FUNCTION_NAME,
|
|
281
|
-
functionTitle: constants_1.ODB_FUNCTION_TITLE,
|
|
282
|
-
includedFiles: [...commonDependencies, ...ssrDependencies, ...odbRoutes.flatMap((route) => route.includedFiles)],
|
|
283
|
-
routes: odbRoutes,
|
|
284
|
-
},
|
|
285
|
-
];
|
|
286
|
-
};
|
|
287
|
-
exports.getSSRLambdas = getSSRLambdas;
|
|
288
|
-
const getSSRRoutes = async (publish) => {
|
|
289
|
-
const pages = (await (0, fs_extra_1.readJSON)((0, pathe_1.join)(publish, 'server', 'pages-manifest.json')));
|
|
290
|
-
const routes = Object.entries(pages).filter(([page, compiled]) => !page.startsWith('/api/') && !compiled.endsWith('.html'));
|
|
291
|
-
return await Promise.all(routes.map(async ([route, compiled]) => {
|
|
292
|
-
const functionName = (0, utils_1.getFunctionNameForPage)(route);
|
|
293
|
-
const compiledPath = (0, pathe_1.join)(publish, 'server', compiled);
|
|
294
|
-
const routeDependencies = await (0, files_1.getDependenciesOfFile)(compiledPath);
|
|
295
|
-
const includedFiles = [compiledPath, ...routeDependencies];
|
|
296
|
-
return {
|
|
297
|
-
functionName,
|
|
298
|
-
route,
|
|
299
|
-
compiled,
|
|
300
|
-
includedFiles,
|
|
301
|
-
};
|
|
302
|
-
}));
|
|
303
|
-
};
|
|
304
227
|
const getAPILambdas = async (publish, baseDir, pageExtensions) => {
|
|
305
|
-
const commonDependencies = await (0, exports.
|
|
228
|
+
const commonDependencies = await (0, exports.getAPIPRouteCommonDependencies)(publish);
|
|
306
229
|
const threshold = constants_1.LAMBDA_WARNING_SIZE - (await getBundleWeight(commonDependencies));
|
|
307
230
|
const apiRoutes = await (0, exports.getApiRouteConfigs)(publish, baseDir, pageExtensions);
|
|
308
231
|
const packFunctions = async (routes, type) => {
|
package/lib/index.js
CHANGED
|
@@ -22,7 +22,6 @@ const verification_1 = require("./helpers/verification");
|
|
|
22
22
|
const plugin = {
|
|
23
23
|
async onPreBuild({ constants, netlifyConfig, utils: { build: { failBuild }, cache, }, }) {
|
|
24
24
|
var _a;
|
|
25
|
-
console.log("using local version");
|
|
26
25
|
const { publish } = netlifyConfig.build;
|
|
27
26
|
if ((0, utils_1.shouldSkip)()) {
|
|
28
27
|
await (0, cache_1.restoreCache)({ cache, publish });
|
|
@@ -96,19 +95,16 @@ const plugin = {
|
|
|
96
95
|
const apiLambdas = (0, flags_1.splitApiRoutes)(featureFlags, publish)
|
|
97
96
|
? await (0, functions_1.getAPILambdas)(publish, appDir, pageExtensions)
|
|
98
97
|
: await (0, functions_1.getExtendedApiRouteConfigs)(publish, appDir, pageExtensions).then((extendedRoutes) => extendedRoutes.map(functions_1.packSingleFunction));
|
|
99
|
-
|
|
100
|
-
await (0, functions_1.generateFunctions)(constants, appDir, apiLambdas, ssrLambdas);
|
|
98
|
+
await (0, functions_1.generateFunctions)(constants, appDir, apiLambdas);
|
|
101
99
|
await (0, functions_1.generatePagesResolver)(constants);
|
|
102
100
|
await (0, config_1.configureHandlerFunctions)({
|
|
103
101
|
netlifyConfig,
|
|
104
102
|
ignore,
|
|
105
103
|
publish: (0, path_1.relative)(process.cwd(), publish),
|
|
106
104
|
apiLambdas,
|
|
107
|
-
ssrLambdas,
|
|
108
105
|
splitApiRoutes: (0, flags_1.splitApiRoutes)(featureFlags, publish),
|
|
109
106
|
});
|
|
110
107
|
await (0, files_1.movePublicFiles)({ appDir, outdir, publish, basePath });
|
|
111
|
-
await (0, files_1.patchNextFiles)(appDir);
|
|
112
108
|
if (!(0, destr_1.default)(process.env.SERVE_STATIC_FILES_FROM_ORIGIN)) {
|
|
113
109
|
await (0, files_1.moveStaticPages)({ target, netlifyConfig, i18n, basePath });
|
|
114
110
|
}
|
|
@@ -37,9 +37,6 @@ const makeHandler = ({ conf, app, pageRoot, NextServer, staticManifest = [], mod
|
|
|
37
37
|
(_a = process.env).NODE_ENV || (_a.NODE_ENV = 'production');
|
|
38
38
|
// We don't want to write ISR files to disk in the lambda environment
|
|
39
39
|
conf.experimental.isrFlushToDisk = false;
|
|
40
|
-
// This is our flag that we use when patching the source
|
|
41
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
42
|
-
process.env._REVALIDATE_SSG = 'true';
|
|
43
40
|
for (const [key, value] of Object.entries(conf.env)) {
|
|
44
41
|
process.env[key] = String(value);
|
|
45
42
|
}
|
|
@@ -151,8 +148,6 @@ const getHandler = ({ isODB = false, publishDir = '../../../.next', appDir = '..
|
|
|
151
148
|
throw new Error('Could not find Next.js server')
|
|
152
149
|
}
|
|
153
150
|
|
|
154
|
-
process.env.NODE_ENV = 'production';
|
|
155
|
-
|
|
156
151
|
const { Server } = require("http");
|
|
157
152
|
const { promises } = require("fs");
|
|
158
153
|
// We copy the file here rather than requiring from the node module
|
package/lib/templates/server.js
CHANGED
|
@@ -18,10 +18,12 @@ const getNetlifyNextServer = (NextServer) => {
|
|
|
18
18
|
getRequestHandler() {
|
|
19
19
|
const handler = super.getRequestHandler();
|
|
20
20
|
return async (req, res, parsedUrl) => {
|
|
21
|
+
var _a;
|
|
21
22
|
// preserve the URL before Next.js mutates it for i18n
|
|
22
23
|
const { url, headers } = req;
|
|
23
24
|
// conditionally use the prebundled React module
|
|
24
25
|
this.netlifyPrebundleReact(url);
|
|
26
|
+
// intercept on-demand revalidation requests and handle with the Netlify API
|
|
25
27
|
if (headers['x-prerender-revalidate'] && this.netlifyConfig.revalidateToken) {
|
|
26
28
|
// handle on-demand revalidation by purging the ODB cache
|
|
27
29
|
await this.netlifyRevalidate(url);
|
|
@@ -29,10 +31,18 @@ const getNetlifyNextServer = (NextServer) => {
|
|
|
29
31
|
res.statusCode = 200;
|
|
30
32
|
res.setHeader('x-nextjs-cache', 'REVALIDATED');
|
|
31
33
|
res.send();
|
|
34
|
+
return;
|
|
32
35
|
}
|
|
33
|
-
|
|
34
|
-
|
|
36
|
+
// force Next to revalidate all requests so that we always have fresh content
|
|
37
|
+
// for our ODBs and middleware is disabled at the origin
|
|
38
|
+
// but ignore in preview mode (prerender_bypass is set to true in preview mode)
|
|
39
|
+
// because otherwise revalidate will override preview mode
|
|
40
|
+
if (!((_a = headers.cookie) === null || _a === void 0 ? void 0 : _a.includes('__prerender_bypass'))) {
|
|
41
|
+
// this header controls whether Next.js will revalidate the page
|
|
42
|
+
// and needs to be set to the preview mode id to enable it
|
|
43
|
+
headers['x-prerender-revalidate'] = this.renderOpts.previewProps.previewModeId;
|
|
35
44
|
}
|
|
45
|
+
return handler(req, res, parsedUrl);
|
|
36
46
|
};
|
|
37
47
|
}
|
|
38
48
|
// doing what they do in https://github.com/vercel/vercel/blob/1663db7ca34d3dd99b57994f801fb30b72fbd2f3/packages/next/src/server-build.ts#L576-L580
|