@netlify/plugin-nextjs 4.28.4-appdir.0 → 4.28.4
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/edge.js +8 -25
- package/lib/helpers/files.js +8 -10
- package/lib/helpers/functions.js +13 -7
- package/lib/index.js +3 -3
- package/lib/templates/getApiHandler.js +1 -1
- package/lib/templates/getHandler.js +7 -5
- package/lib/templates/getPageResolver.js +8 -13
- package/lib/templates/handlerUtils.js +6 -8
- package/package.json +2 -2
- package/src/templates/edge/runtime.ts +5 -11
package/lib/helpers/edge.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.writeEdgeFunctions = exports.writeDevEdgeFunction = exports.cleanupEdgeFunctions = exports.
|
|
6
|
+
exports.writeEdgeFunctions = exports.writeDevEdgeFunction = exports.cleanupEdgeFunctions = exports.loadMiddlewareManifest = void 0;
|
|
7
7
|
/* eslint-disable max-lines */
|
|
8
8
|
const fs_1 = require("fs");
|
|
9
9
|
const path_1 = require("path");
|
|
@@ -13,15 +13,14 @@ const fs_extra_1 = require("fs-extra");
|
|
|
13
13
|
const outdent_1 = require("outdent");
|
|
14
14
|
const config_1 = require("./config");
|
|
15
15
|
const matchers_1 = require("./matchers");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const loadMiddlewareManifest = (netlifyConfig) => {
|
|
17
|
+
const middlewarePath = (0, path_1.resolve)(netlifyConfig.build.publish, 'server', 'middleware-manifest.json');
|
|
18
|
+
if (!(0, fs_1.existsSync)(middlewarePath)) {
|
|
19
|
+
return null;
|
|
19
20
|
}
|
|
21
|
+
return (0, fs_extra_1.readJson)(middlewarePath);
|
|
20
22
|
};
|
|
21
|
-
const loadMiddlewareManifest = (netlifyConfig) => maybeLoadJson((0, path_1.resolve)(netlifyConfig.build.publish, 'server', 'middleware-manifest.json'));
|
|
22
23
|
exports.loadMiddlewareManifest = loadMiddlewareManifest;
|
|
23
|
-
const loadAppPathRoutesManifest = (netlifyConfig) => maybeLoadJson((0, path_1.resolve)(netlifyConfig.build.publish, 'app-path-routes-manifest.json'));
|
|
24
|
-
exports.loadAppPathRoutesManifest = loadAppPathRoutesManifest;
|
|
25
24
|
/**
|
|
26
25
|
* Convert the Next middleware name into a valid Edge Function name
|
|
27
26
|
*/
|
|
@@ -96,7 +95,7 @@ const getMiddlewareBundle = async ({ edgeFunctionDefinition, netlifyConfig, }) =
|
|
|
96
95
|
};
|
|
97
96
|
const getEdgeTemplatePath = (file) => (0, path_1.join)(__dirname, '..', '..', 'src', 'templates', 'edge', file);
|
|
98
97
|
const copyEdgeSourceFile = ({ file, target, edgeFunctionDir, }) => fs_1.promises.copyFile(getEdgeTemplatePath(file), (0, path_1.join)(edgeFunctionDir, target !== null && target !== void 0 ? target : file));
|
|
99
|
-
const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, netlifyConfig,
|
|
98
|
+
const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, netlifyConfig, nextConfig, }) => {
|
|
100
99
|
const name = sanitizeName(edgeFunctionDefinition.name);
|
|
101
100
|
const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, name);
|
|
102
101
|
const bundle = await getMiddlewareBundle({
|
|
@@ -124,14 +123,6 @@ const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, net
|
|
|
124
123
|
else {
|
|
125
124
|
matchers.push(...edgeFunctionDefinition.matchers);
|
|
126
125
|
}
|
|
127
|
-
// If the EF matches a page, it's an app dir page so needs a matcher too
|
|
128
|
-
// The object will be empty if appDir isn't enabled in the Next config
|
|
129
|
-
if (pageRegexMap && edgeFunctionDefinition.page in appPathRoutesManifest) {
|
|
130
|
-
const regexp = pageRegexMap.get(appPathRoutesManifest[edgeFunctionDefinition.page]);
|
|
131
|
-
if (regexp) {
|
|
132
|
-
matchers.push({ regexp });
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
126
|
await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionDir, 'matchers.json'), matchers);
|
|
136
127
|
// We add a defintion for each matching path
|
|
137
128
|
return matchers.map((matcher) => {
|
|
@@ -164,7 +155,7 @@ exports.writeDevEdgeFunction = writeDevEdgeFunction;
|
|
|
164
155
|
/**
|
|
165
156
|
* Writes Edge Functions for the Next middleware
|
|
166
157
|
*/
|
|
167
|
-
const writeEdgeFunctions = async (
|
|
158
|
+
const writeEdgeFunctions = async (netlifyConfig) => {
|
|
168
159
|
const manifest = {
|
|
169
160
|
functions: [],
|
|
170
161
|
version: 1,
|
|
@@ -211,20 +202,12 @@ const writeEdgeFunctions = async ({ netlifyConfig, routesManifest, }) => {
|
|
|
211
202
|
// Older versions of the manifest format don't have the functions field
|
|
212
203
|
// No, the version field was not incremented
|
|
213
204
|
if (typeof middlewareManifest.functions === 'object') {
|
|
214
|
-
// When using the app dir, we also need to check if the EF matches a page
|
|
215
|
-
const appPathRoutesManifest = await (0, exports.loadAppPathRoutesManifest)(netlifyConfig);
|
|
216
|
-
const pageRegexMap = new Map([...(routesManifest.dynamicRoutes || []), ...(routesManifest.staticRoutes || [])].map((route) => [
|
|
217
|
-
route.page,
|
|
218
|
-
route.regex,
|
|
219
|
-
]));
|
|
220
205
|
for (const edgeFunctionDefinition of Object.values(middlewareManifest.functions)) {
|
|
221
206
|
usesEdge = true;
|
|
222
207
|
const functionDefinitions = await writeEdgeFunction({
|
|
223
208
|
edgeFunctionDefinition,
|
|
224
209
|
edgeFunctionRoot,
|
|
225
210
|
netlifyConfig,
|
|
226
|
-
pageRegexMap,
|
|
227
|
-
appPathRoutesManifest,
|
|
228
211
|
nextConfig,
|
|
229
212
|
});
|
|
230
213
|
manifest.functions.push(...functionDefinitions);
|
package/lib/helpers/files.js
CHANGED
|
@@ -70,6 +70,7 @@ exports.getMiddleware = getMiddleware;
|
|
|
70
70
|
const moveStaticPages = async ({ netlifyConfig, target, i18n, basePath, }) => {
|
|
71
71
|
console.log('Moving static page files to serve from CDN...');
|
|
72
72
|
const outputDir = (0, pathe_1.join)(netlifyConfig.build.publish, target === 'server' ? 'server' : 'serverless');
|
|
73
|
+
const root = (0, pathe_1.join)(outputDir, 'pages');
|
|
73
74
|
const buildId = (0, fs_extra_1.readFileSync)((0, pathe_1.join)(netlifyConfig.build.publish, 'BUILD_ID'), 'utf8').trim();
|
|
74
75
|
const dataDir = (0, pathe_1.join)('_next', 'data', buildId);
|
|
75
76
|
await (0, fs_extra_1.ensureDir)((0, pathe_1.join)(netlifyConfig.build.publish, dataDir));
|
|
@@ -91,17 +92,14 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, basePath, }) => {
|
|
|
91
92
|
}
|
|
92
93
|
}
|
|
93
94
|
});
|
|
94
|
-
|
|
95
|
+
const files = [];
|
|
95
96
|
const filesManifest = {};
|
|
96
97
|
const moveFile = async (file) => {
|
|
97
|
-
// Strip the initial 'app' or 'pages' directory from the output path
|
|
98
|
-
const pathname = file.split('/').slice(1).join('/');
|
|
99
|
-
// .rsc data files go next to the html file
|
|
100
98
|
const isData = file.endsWith('.json');
|
|
101
|
-
const source = (0, pathe_1.join)(
|
|
102
|
-
const targetFile = isData ? (0, pathe_1.join)(dataDir,
|
|
99
|
+
const source = (0, pathe_1.join)(root, file);
|
|
100
|
+
const targetFile = isData ? (0, pathe_1.join)(dataDir, file) : file;
|
|
103
101
|
const targetPath = basePath ? (0, pathe_1.join)(basePath, targetFile) : targetFile;
|
|
104
|
-
|
|
102
|
+
files.push(file);
|
|
105
103
|
filesManifest[file] = targetPath;
|
|
106
104
|
const dest = (0, pathe_1.join)(netlifyConfig.build.publish, targetPath);
|
|
107
105
|
try {
|
|
@@ -112,8 +110,8 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, basePath, }) => {
|
|
|
112
110
|
}
|
|
113
111
|
};
|
|
114
112
|
// Move all static files, except error documents and nft manifests
|
|
115
|
-
const pages = await (0, globby_1.default)(['{
|
|
116
|
-
cwd:
|
|
113
|
+
const pages = await (0, globby_1.default)(['**/*.{html,json}', '!**/(500|404|*.js.nft).{html,json}'], {
|
|
114
|
+
cwd: root,
|
|
117
115
|
dot: true,
|
|
118
116
|
});
|
|
119
117
|
const matchingMiddleware = new Set();
|
|
@@ -151,7 +149,7 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, basePath, }) => {
|
|
|
151
149
|
return limit(moveFile, filePath);
|
|
152
150
|
});
|
|
153
151
|
await Promise.all(promises);
|
|
154
|
-
console.log(`Moved ${
|
|
152
|
+
console.log(`Moved ${files.length} files`);
|
|
155
153
|
if (matchedPages.size !== 0) {
|
|
156
154
|
console.log((0, chalk_1.yellowBright)((0, outdent_1.outdent) `
|
|
157
155
|
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.
|
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.getApiRouteConfigs = exports.setupImageFunction = exports.generatePagesResolver = exports.generateFunctions = void 0;
|
|
6
|
+
exports.warnOnApiRoutes = exports.getExtendedApiRouteConfigs = exports.getApiRouteConfigs = 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"));
|
|
@@ -20,13 +20,10 @@ const utils_1 = require("./utils");
|
|
|
20
20
|
const generateFunctions = async ({ FUNCTIONS_SRC = constants_1.DEFAULT_FUNCTIONS_SRC, INTERNAL_FUNCTIONS_SRC, PUBLISH_DIR }, appDir, apiRoutes) => {
|
|
21
21
|
const publish = (0, pathe_1.resolve)(PUBLISH_DIR);
|
|
22
22
|
const functionsDir = (0, pathe_1.resolve)(INTERNAL_FUNCTIONS_SRC || FUNCTIONS_SRC);
|
|
23
|
+
console.log({ functionsDir });
|
|
23
24
|
const functionDir = (0, pathe_1.join)(functionsDir, constants_1.HANDLER_FUNCTION_NAME);
|
|
24
25
|
const publishDir = (0, pathe_1.relative)(functionDir, publish);
|
|
25
26
|
for (const { route, config, compiled } of apiRoutes) {
|
|
26
|
-
// Don't write a lambda if the runtime is edge
|
|
27
|
-
if (config.runtime === 'experimental-edge') {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
27
|
const apiHandlerSource = await (0, getApiHandler_1.getApiHandler)({
|
|
31
28
|
page: route,
|
|
32
29
|
config,
|
|
@@ -128,12 +125,21 @@ const getApiRouteConfigs = async (publish, baseDir) => {
|
|
|
128
125
|
const pages = await (0, fs_extra_1.readJSON)((0, pathe_1.join)(publish, 'server', 'pages-manifest.json'));
|
|
129
126
|
const apiRoutes = Object.keys(pages).filter((page) => page.startsWith('/api/'));
|
|
130
127
|
const pagesDir = (0, pathe_1.join)(baseDir, 'pages');
|
|
131
|
-
return Promise.all(apiRoutes.map(async (apiRoute) => {
|
|
128
|
+
return await Promise.all(apiRoutes.map(async (apiRoute) => {
|
|
132
129
|
const filePath = (0, files_1.getSourceFileForPage)(apiRoute, pagesDir);
|
|
133
130
|
return { route: apiRoute, config: await (0, analysis_1.extractConfigFromFile)(filePath), compiled: pages[apiRoute] };
|
|
134
131
|
}));
|
|
135
132
|
};
|
|
136
133
|
exports.getApiRouteConfigs = getApiRouteConfigs;
|
|
134
|
+
/**
|
|
135
|
+
* Looks for extended API routes (background and scheduled functions) and extract the config from the source file.
|
|
136
|
+
*/
|
|
137
|
+
const getExtendedApiRouteConfigs = async (publish, baseDir) => {
|
|
138
|
+
const settledApiRoutes = await (0, exports.getApiRouteConfigs)(publish, baseDir);
|
|
139
|
+
// We only want to return the API routes that are background or scheduled functions
|
|
140
|
+
return settledApiRoutes.filter((apiRoute) => apiRoute.config.type !== undefined);
|
|
141
|
+
};
|
|
142
|
+
exports.getExtendedApiRouteConfigs = getExtendedApiRouteConfigs;
|
|
137
143
|
/**
|
|
138
144
|
* Warn the user of the caveats if they're using background or scheduled API routes
|
|
139
145
|
*/
|
|
@@ -152,7 +158,7 @@ const warnOnApiRoutes = async ({ FUNCTIONS_DIST, }) => {
|
|
|
152
158
|
}
|
|
153
159
|
if (functions.some((func) => func.schedule)) {
|
|
154
160
|
console.warn((0, outdent_1.outdent) `
|
|
155
|
-
${chalk_1.default.yellowBright `Using scheduled API routes`}
|
|
161
|
+
${chalk_1.default.yellowBright `Using scheduled API routes`}
|
|
156
162
|
These are run on a schedule when deployed to production.
|
|
157
163
|
You can test them locally by loading them in your browser but this will not be available when deployed, and any returned value is ignored.
|
|
158
164
|
`);
|
package/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ const plugin = {
|
|
|
44
44
|
}
|
|
45
45
|
const { publish } = netlifyConfig.build;
|
|
46
46
|
(0, verification_1.checkNextSiteHasBuilt)({ publish, failBuild });
|
|
47
|
-
const { appDir, basePath, i18n, images, target, ignore, trailingSlash, outdir, experimental
|
|
47
|
+
const { appDir, basePath, i18n, images, target, ignore, trailingSlash, outdir, experimental } = await (0, config_1.getNextConfig)({
|
|
48
48
|
publish,
|
|
49
49
|
failBuild,
|
|
50
50
|
});
|
|
@@ -92,7 +92,7 @@ const plugin = {
|
|
|
92
92
|
}
|
|
93
93
|
const buildId = (0, fs_extra_1.readFileSync)((0, path_1.join)(publish, 'BUILD_ID'), 'utf8').trim();
|
|
94
94
|
await (0, config_1.configureHandlerFunctions)({ netlifyConfig, ignore, publish: (0, path_1.relative)(process.cwd(), publish) });
|
|
95
|
-
const apiRoutes = await (0, functions_1.
|
|
95
|
+
const apiRoutes = await (0, functions_1.getExtendedApiRouteConfigs)(publish, appDir);
|
|
96
96
|
await (0, functions_1.generateFunctions)(constants, appDir, apiRoutes);
|
|
97
97
|
await (0, functions_1.generatePagesResolver)({ target, constants });
|
|
98
98
|
await (0, files_1.movePublicFiles)({ appDir, outdir, publish });
|
|
@@ -118,7 +118,7 @@ const plugin = {
|
|
|
118
118
|
buildId,
|
|
119
119
|
apiRoutes,
|
|
120
120
|
});
|
|
121
|
-
await (0, edge_1.writeEdgeFunctions)(
|
|
121
|
+
await (0, edge_1.writeEdgeFunctions)(netlifyConfig);
|
|
122
122
|
},
|
|
123
123
|
async onPostBuild({ netlifyConfig: { build: { publish }, redirects, headers, }, utils: { status, cache, functions, build: { failBuild }, }, constants: { FUNCTIONS_DIST }, }) {
|
|
124
124
|
await (0, cache_1.saveCache)({ cache, publish });
|
|
@@ -105,7 +105,7 @@ const getApiHandler = ({ page, config, publishDir = '../../../.next', appDir = '
|
|
|
105
105
|
const { config } = require("${publishDir}/required-server-files.json")
|
|
106
106
|
let staticManifest
|
|
107
107
|
const path = require("path");
|
|
108
|
-
const pageRoot = path.resolve(path.join(__dirname, "${publishDir}", "
|
|
108
|
+
const pageRoot = path.resolve(path.join(__dirname, "${publishDir}", "serverless", "pages"));
|
|
109
109
|
const handler = (${makeHandler.toString()})(config, "${appDir}", pageRoot, ${JSON.stringify(page)})
|
|
110
110
|
exports.handler = ${config.type === "experimental-scheduled" /* ApiRouteType.SCHEDULED */ ? `schedule(${JSON.stringify(config.schedule)}, handler);` : 'handler'}
|
|
111
111
|
`;
|
|
@@ -15,7 +15,6 @@ const { augmentFsModule, getMaxAge, getMultiValueHeaders, getNextServer } = requ
|
|
|
15
15
|
// eslint-disable-next-line max-params
|
|
16
16
|
const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') => {
|
|
17
17
|
var _a;
|
|
18
|
-
console.log('makeHandler', process.env);
|
|
19
18
|
// Change working directory into the site root, unless using Nx, which moves the
|
|
20
19
|
// dist directory and handles this itself
|
|
21
20
|
const dir = path.resolve(__dirname, app);
|
|
@@ -38,7 +37,9 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
|
|
|
38
37
|
for (const [key, value] of Object.entries(conf.env)) {
|
|
39
38
|
process.env[key] = String(value);
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
// Set during the request as it needs the host header. Hoisted so we can define the function once
|
|
41
|
+
let base;
|
|
42
|
+
augmentFsModule({ promises, staticManifest, pageRoot, getBase: () => base });
|
|
42
43
|
// We memoize this because it can be shared between requests, but don't instantiate it until
|
|
43
44
|
// the first request because we need the host and port.
|
|
44
45
|
let bridge;
|
|
@@ -48,6 +49,9 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
|
|
|
48
49
|
}
|
|
49
50
|
const url = new URL(event.rawUrl);
|
|
50
51
|
const port = Number.parseInt(url.port) || 80;
|
|
52
|
+
const { host } = event.headers;
|
|
53
|
+
const protocol = event.headers['x-forwarded-proto'] || 'http';
|
|
54
|
+
base = `${protocol}://${host}`;
|
|
51
55
|
const NextServer = getNextServer();
|
|
52
56
|
const nextServer = new NextServer({
|
|
53
57
|
conf,
|
|
@@ -72,8 +76,6 @@ const makeHandler = (conf, app, pageRoot, staticManifest = [], mode = 'ssr') =>
|
|
|
72
76
|
};
|
|
73
77
|
return async function handler(event, context) {
|
|
74
78
|
var _a, _b, _c;
|
|
75
|
-
const baseUrl = process.env.CONTEXT === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL;
|
|
76
|
-
console.log('Using baseUrl', baseUrl, process.env);
|
|
77
79
|
let requestMode = mode;
|
|
78
80
|
// Ensure that paths are encoded - but don't double-encode them
|
|
79
81
|
event.path = new URL(event.rawUrl).pathname;
|
|
@@ -140,7 +142,7 @@ const getHandler = ({ isODB = false, publishDir = '../../../.next', appDir = '..
|
|
|
140
142
|
staticManifest = require("${publishDir}/static-manifest.json")
|
|
141
143
|
} catch {}
|
|
142
144
|
const path = require("path");
|
|
143
|
-
const pageRoot = path.resolve(path.join(__dirname, "${publishDir}", "server"));
|
|
145
|
+
const pageRoot = path.resolve(path.join(__dirname, "${publishDir}", config.target === "server" ? "server" : "serverless", "pages"));
|
|
144
146
|
exports.handler = ${isODB
|
|
145
147
|
? `builder((${makeHandler.toString()})(config, "${appDir}", pageRoot, staticManifest, 'odb'));`
|
|
146
148
|
: `(${makeHandler.toString()})(config, "${appDir}", pageRoot, staticManifest, 'ssr');`}
|
|
@@ -5,31 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getSinglePageResolver = exports.getPageResolver = void 0;
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
-
const fs_extra_1 = require("fs-extra");
|
|
9
|
-
const globby_1 = __importDefault(require("globby"));
|
|
10
8
|
const outdent_1 = require("outdent");
|
|
11
9
|
const pathe_1 = require("pathe");
|
|
12
10
|
const slash_1 = __importDefault(require("slash"));
|
|
11
|
+
const tiny_glob_1 = __importDefault(require("tiny-glob"));
|
|
13
12
|
const constants_1 = require("../constants");
|
|
14
13
|
const files_1 = require("../helpers/files");
|
|
15
14
|
// Generate a file full of require.resolve() calls for all the pages in the
|
|
16
15
|
// build. This is used by the nft bundler to find all the pages.
|
|
17
16
|
const getPageResolver = async ({ publish, target }) => {
|
|
18
|
-
const functionDir =
|
|
19
|
-
const root =
|
|
20
|
-
const pages = await (0,
|
|
17
|
+
const functionDir = path_1.posix.resolve(path_1.posix.join('.netlify', 'functions', constants_1.HANDLER_FUNCTION_NAME));
|
|
18
|
+
const root = path_1.posix.resolve((0, slash_1.default)(publish), target === 'server' ? 'server' : 'serverless', 'pages');
|
|
19
|
+
const pages = await (0, tiny_glob_1.default)('**/*.js', {
|
|
21
20
|
cwd: root,
|
|
22
21
|
dot: true,
|
|
23
22
|
});
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return files === null || files === void 0 ? void 0 : files.map((file) => (0, path_1.resolve)(root, dir, file));
|
|
28
|
-
}));
|
|
29
|
-
const deduped = [...new Set(dependencies.flat())];
|
|
30
|
-
const pageFiles = deduped.map((file) => `require.resolve('${(0, pathe_1.relative)(functionDir, file)}')`).sort();
|
|
23
|
+
const pageFiles = pages
|
|
24
|
+
.map((page) => `require.resolve('${path_1.posix.relative(functionDir, path_1.posix.join(root, (0, slash_1.default)(page)))}')`)
|
|
25
|
+
.sort();
|
|
31
26
|
return (0, outdent_1.outdent) `
|
|
32
|
-
// This file is purely to allow nft to know about these pages.
|
|
27
|
+
// This file is purely to allow nft to know about these pages. It should be temporary.
|
|
33
28
|
exports.resolvePages = () => {
|
|
34
29
|
try {
|
|
35
30
|
${pageFiles.join('\n ')}
|
|
@@ -75,7 +75,7 @@ exports.getMultiValueHeaders = getMultiValueHeaders;
|
|
|
75
75
|
/**
|
|
76
76
|
* Monkey-patch the fs module to download missing files from the CDN
|
|
77
77
|
*/
|
|
78
|
-
const augmentFsModule = ({ promises, staticManifest, pageRoot, }) => {
|
|
78
|
+
const augmentFsModule = ({ promises, staticManifest, pageRoot, getBase, }) => {
|
|
79
79
|
// Only do this if we have some static files moved to the CDN
|
|
80
80
|
if (staticManifest.length === 0) {
|
|
81
81
|
return;
|
|
@@ -93,24 +93,22 @@ const augmentFsModule = ({ promises, staticManifest, pageRoot, }) => {
|
|
|
93
93
|
const statsOrig = promises.stat;
|
|
94
94
|
// ...then money-patch it to see if it's requesting a CDN file
|
|
95
95
|
promises.readFile = (async (file, options) => {
|
|
96
|
-
|
|
97
|
-
const baseUrl = process.env.CONTEXT === 'production' ? process.env.URL : process.env.DEPLOY_PRIME_URL;
|
|
98
|
-
console.log('Using baseUrl', baseUrl);
|
|
96
|
+
const base = getBase();
|
|
99
97
|
// We only care about page files
|
|
100
98
|
if (file.startsWith(pageRoot)) {
|
|
101
|
-
// We only want the part after
|
|
99
|
+
// We only want the part after `pages/`
|
|
102
100
|
const filePath = file.slice(pageRoot.length + 1);
|
|
103
101
|
// Is it in the CDN and not local?
|
|
104
102
|
if (staticFiles.has(filePath) && !(0, fs_1.existsSync)(file)) {
|
|
105
103
|
// This name is safe to use, because it's one that was already created by Next
|
|
106
104
|
const cacheFile = path_1.default.join(cacheDir, filePath);
|
|
107
|
-
const url = `${
|
|
105
|
+
const url = `${base}/${staticFiles.get(filePath)}`;
|
|
108
106
|
// If it's already downloading we can wait for it to finish
|
|
109
107
|
if (downloadPromises.has(url)) {
|
|
110
108
|
await downloadPromises.get(url);
|
|
111
109
|
}
|
|
112
110
|
// Have we already cached it? We download every time if running locally to avoid staleness
|
|
113
|
-
if ((!(0, fs_1.existsSync)(cacheFile) || process.env.NETLIFY_DEV) &&
|
|
111
|
+
if ((!(0, fs_1.existsSync)(cacheFile) || process.env.NETLIFY_DEV) && base) {
|
|
114
112
|
await promises.mkdir(path_1.default.dirname(cacheFile), { recursive: true });
|
|
115
113
|
try {
|
|
116
114
|
// Append the path to our host and we can load it like a regular page
|
|
@@ -131,7 +129,7 @@ const augmentFsModule = ({ promises, staticManifest, pageRoot, }) => {
|
|
|
131
129
|
promises.stat = ((file, options) => {
|
|
132
130
|
// We only care about page files
|
|
133
131
|
if (file.startsWith(pageRoot)) {
|
|
134
|
-
// We only want the part after
|
|
132
|
+
// We only want the part after `pages/`
|
|
135
133
|
const cacheFile = path_1.default.join(cacheDir, file.slice(pageRoot.length + 1));
|
|
136
134
|
if ((0, fs_1.existsSync)(cacheFile)) {
|
|
137
135
|
return statsOrig(cacheFile, options);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.28.4
|
|
3
|
+
"version": "4.28.4",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@delucis/if-env": "^1.1.2",
|
|
39
|
-
"@netlify/build": "^28.1.
|
|
39
|
+
"@netlify/build": "^28.1.7",
|
|
40
40
|
"@types/fs-extra": "^9.0.13",
|
|
41
41
|
"@types/jest": "^27.4.1",
|
|
42
42
|
"@types/merge-stream": "^1.1.2",
|
|
@@ -13,12 +13,6 @@ export interface FetchEventResult {
|
|
|
13
13
|
waitUntil: Promise<any>
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface I18NConfig {
|
|
17
|
-
defaultLocale: string
|
|
18
|
-
localeDetection?: false
|
|
19
|
-
locales: string[]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
export interface RequestData {
|
|
23
17
|
geo?: {
|
|
24
18
|
city?: string
|
|
@@ -32,7 +26,7 @@ export interface RequestData {
|
|
|
32
26
|
method: string
|
|
33
27
|
nextConfig?: {
|
|
34
28
|
basePath?: string
|
|
35
|
-
i18n?:
|
|
29
|
+
i18n?: Record<string, unknown>
|
|
36
30
|
trailingSlash?: boolean
|
|
37
31
|
}
|
|
38
32
|
page?: {
|
|
@@ -56,10 +50,10 @@ declare global {
|
|
|
56
50
|
globalThis.NFRequestContextMap ||= new Map()
|
|
57
51
|
|
|
58
52
|
const handler = async (req: Request, context: Context) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
if (Deno.env.get('NETLIFY_DEV')) {
|
|
54
|
+
// Don't run in dev
|
|
55
|
+
return
|
|
56
|
+
}
|
|
63
57
|
|
|
64
58
|
const url = new URL(req.url)
|
|
65
59
|
|