@netlify/plugin-nextjs 5.1.1 → 5.2.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/dist/build/advanced-api-routes.js +121 -4
- package/dist/build/cache.js +25 -4
- package/dist/build/content/prerendered.js +234 -8
- package/dist/build/content/server.js +259 -14
- package/dist/build/content/static.js +96 -11
- package/dist/build/functions/edge.js +511 -5
- package/dist/build/functions/server.js +131 -12
- package/dist/build/image-cdn.js +1626 -3
- package/dist/build/plugin-context.js +236 -5
- package/dist/build/templates/handler-monorepo.tmpl.js +3 -0
- package/dist/build/templates/handler.tmpl.js +3 -0
- package/dist/build/verification.js +81 -8
- package/dist/esm-chunks/{package-YB7ERSH4.js → package-ZBRSUKN7.js} +6 -6
- package/dist/index.js +25 -36
- package/dist/run/config.js +25 -6
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +6 -567
- package/dist/run/handlers/request-context.cjs +8 -1
- package/dist/run/handlers/server.js +20 -22
- package/dist/run/handlers/tracing.js +1 -1
- package/dist/run/headers.js +198 -8
- package/dist/run/next.cjs +49 -567
- package/dist/{esm-chunks/chunk-PMRBBOBY.js → run/regional-blob-store.cjs} +117 -263
- package/dist/run/revalidate.js +17 -3
- package/dist/run/systemlog.js +94 -3
- package/dist/shared/blobkey.js +15 -3
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-3NYX5FXN.js +0 -188
- package/dist/esm-chunks/chunk-3SUDZQ7L.js +0 -40
- package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
- package/dist/esm-chunks/chunk-74THQNRG.js +0 -110
- package/dist/esm-chunks/chunk-BG455SFE.js +0 -133
- package/dist/esm-chunks/chunk-F5VQRN6L.js +0 -127
- package/dist/esm-chunks/chunk-HYBEXB2Z.js +0 -105
- package/dist/esm-chunks/chunk-MCEOSJH6.js +0 -1637
- package/dist/esm-chunks/chunk-MRD3XSKD.js +0 -248
- package/dist/esm-chunks/chunk-OBKVBMAL.js +0 -524
- package/dist/esm-chunks/chunk-PH26UF2W.js +0 -86
- package/dist/esm-chunks/chunk-RL4K4CVH.js +0 -27
- package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
- package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
- package/dist/esm-chunks/chunk-ZKJEJNSJ.js +0 -278
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/build/plugin-context.ts
|
|
9
|
-
import { readFileSync } from "node:fs";
|
|
10
|
-
import { readFile } from "node:fs/promises";
|
|
11
|
-
import { join, relative, resolve } from "node:path";
|
|
12
|
-
import { fileURLToPath } from "node:url";
|
|
13
|
-
var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url));
|
|
14
|
-
var PLUGIN_DIR = join(MODULE_DIR, "../..");
|
|
15
|
-
var DEFAULT_PUBLISH_DIR = ".next";
|
|
16
|
-
var SERVER_HANDLER_NAME = "___netlify-server-handler";
|
|
17
|
-
var EDGE_HANDLER_NAME = "___netlify-edge-handler";
|
|
18
|
-
var PluginContext = class {
|
|
19
|
-
utils;
|
|
20
|
-
netlifyConfig;
|
|
21
|
-
pluginName;
|
|
22
|
-
pluginVersion;
|
|
23
|
-
constants;
|
|
24
|
-
packageJSON;
|
|
25
|
-
/** Absolute path of the next runtime plugin directory */
|
|
26
|
-
pluginDir = PLUGIN_DIR;
|
|
27
|
-
get relPublishDir() {
|
|
28
|
-
return this.constants.PUBLISH_DIR ?? join(this.constants.PACKAGE_PATH || "", DEFAULT_PUBLISH_DIR);
|
|
29
|
-
}
|
|
30
|
-
/** Temporary directory for stashing the build output */
|
|
31
|
-
get tempPublishDir() {
|
|
32
|
-
return this.resolveFromPackagePath(".netlify/.next");
|
|
33
|
-
}
|
|
34
|
-
/** Absolute path of the publish directory */
|
|
35
|
-
get publishDir() {
|
|
36
|
-
return resolve(this.relPublishDir);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Relative package path in non monorepo setups this is an empty string
|
|
40
|
-
* This path is provided by Next.js RequiredServerFiles manifest
|
|
41
|
-
* @example ''
|
|
42
|
-
* @example 'apps/my-app'
|
|
43
|
-
*/
|
|
44
|
-
get relativeAppDir() {
|
|
45
|
-
return this.requiredServerFiles.relativeAppDir ?? "";
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* The working directory inside the lambda that is used for monorepos to execute the serverless function
|
|
49
|
-
*/
|
|
50
|
-
get lambdaWorkingDirectory() {
|
|
51
|
-
return join("/var/task", this.distDirParent);
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Retrieves the root of the `.next/standalone` directory
|
|
55
|
-
*/
|
|
56
|
-
get standaloneRootDir() {
|
|
57
|
-
return join(this.publishDir, "standalone");
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* The resolved relative next dist directory defaults to `.next`,
|
|
61
|
-
* but can be configured through the next.config.js. For monorepos this will include the packagePath
|
|
62
|
-
* If we need just the plain dist dir use the `nextDistDir`
|
|
63
|
-
*/
|
|
64
|
-
get distDir() {
|
|
65
|
-
const dir = this.buildConfig.distDir ?? DEFAULT_PUBLISH_DIR;
|
|
66
|
-
return relative(process.cwd(), resolve(this.relativeAppDir, dir));
|
|
67
|
-
}
|
|
68
|
-
/** Represents the parent directory of the .next folder or custom distDir */
|
|
69
|
-
get distDirParent() {
|
|
70
|
-
return join(this.distDir, "..");
|
|
71
|
-
}
|
|
72
|
-
/** The `.next` folder or what the custom dist dir is set to */
|
|
73
|
-
get nextDistDir() {
|
|
74
|
-
return relative(this.distDirParent, this.distDir);
|
|
75
|
-
}
|
|
76
|
-
/** Retrieves the `.next/standalone/` directory monorepo aware */
|
|
77
|
-
get standaloneDir() {
|
|
78
|
-
return join(this.standaloneRootDir, this.distDirParent);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Absolute path of the directory that is published and deployed to the Netlify CDN
|
|
82
|
-
* Will be swapped with the publish directory
|
|
83
|
-
* `.netlify/static`
|
|
84
|
-
*/
|
|
85
|
-
get staticDir() {
|
|
86
|
-
return this.resolveFromPackagePath(".netlify/static");
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Absolute path of the directory that will be deployed to the blob store
|
|
90
|
-
* `.netlify/blobs/deploy`
|
|
91
|
-
*/
|
|
92
|
-
get blobDir() {
|
|
93
|
-
return this.resolveFromPackagePath(".netlify/blobs/deploy");
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Absolute path of the directory containing the files for the serverless lambda function
|
|
97
|
-
* `.netlify/functions-internal`
|
|
98
|
-
*/
|
|
99
|
-
get serverFunctionsDir() {
|
|
100
|
-
return this.resolveFromPackagePath(".netlify/functions-internal");
|
|
101
|
-
}
|
|
102
|
-
/** Absolute path of the server handler */
|
|
103
|
-
get serverHandlerRootDir() {
|
|
104
|
-
return join(this.serverFunctionsDir, SERVER_HANDLER_NAME);
|
|
105
|
-
}
|
|
106
|
-
get serverHandlerDir() {
|
|
107
|
-
if (this.relativeAppDir.length === 0) {
|
|
108
|
-
return this.serverHandlerRootDir;
|
|
109
|
-
}
|
|
110
|
-
return join(this.serverHandlerRootDir, this.distDirParent);
|
|
111
|
-
}
|
|
112
|
-
get nextServerHandler() {
|
|
113
|
-
if (this.relativeAppDir.length !== 0) {
|
|
114
|
-
return join(this.lambdaWorkingDirectory, ".netlify/dist/run/handlers/server.js");
|
|
115
|
-
}
|
|
116
|
-
return "./.netlify/dist/run/handlers/server.js";
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Absolute path of the directory containing the files for deno edge functions
|
|
120
|
-
* `.netlify/edge-functions`
|
|
121
|
-
*/
|
|
122
|
-
get edgeFunctionsDir() {
|
|
123
|
-
return this.resolveFromPackagePath(".netlify/edge-functions");
|
|
124
|
-
}
|
|
125
|
-
/** Absolute path of the edge handler */
|
|
126
|
-
get edgeHandlerDir() {
|
|
127
|
-
return join(this.edgeFunctionsDir, EDGE_HANDLER_NAME);
|
|
128
|
-
}
|
|
129
|
-
constructor(options) {
|
|
130
|
-
this.packageJSON = JSON.parse(readFileSync(join(PLUGIN_DIR, "package.json"), "utf-8"));
|
|
131
|
-
this.pluginName = this.packageJSON.name;
|
|
132
|
-
this.pluginVersion = this.packageJSON.version;
|
|
133
|
-
this.constants = options.constants;
|
|
134
|
-
this.utils = options.utils;
|
|
135
|
-
this.netlifyConfig = options.netlifyConfig;
|
|
136
|
-
}
|
|
137
|
-
/** Resolves a path correctly with mono repository awareness for .netlify directories mainly */
|
|
138
|
-
resolveFromPackagePath(...args) {
|
|
139
|
-
return resolve(this.constants.PACKAGE_PATH || "", ...args);
|
|
140
|
-
}
|
|
141
|
-
/** Resolves a path correctly from site directory */
|
|
142
|
-
resolveFromSiteDir(...args) {
|
|
143
|
-
return resolve(this.requiredServerFiles.appDir, ...args);
|
|
144
|
-
}
|
|
145
|
-
/** Get the next prerender-manifest.json */
|
|
146
|
-
async getPrerenderManifest() {
|
|
147
|
-
return JSON.parse(await readFile(join(this.publishDir, "prerender-manifest.json"), "utf-8"));
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Get Next.js middleware config from the build output
|
|
151
|
-
*/
|
|
152
|
-
async getMiddlewareManifest() {
|
|
153
|
-
return JSON.parse(
|
|
154
|
-
await readFile(join(this.publishDir, "server/middleware-manifest.json"), "utf-8")
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
// don't make private as it is handy inside testing to override the config
|
|
158
|
-
_requiredServerFiles = null;
|
|
159
|
-
/** Get RequiredServerFiles manifest from build output **/
|
|
160
|
-
get requiredServerFiles() {
|
|
161
|
-
if (!this._requiredServerFiles) {
|
|
162
|
-
this._requiredServerFiles = JSON.parse(
|
|
163
|
-
readFileSync(join(this.publishDir, "required-server-files.json"), "utf-8")
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
return this._requiredServerFiles;
|
|
167
|
-
}
|
|
168
|
-
/** Get Next Config from build output **/
|
|
169
|
-
get buildConfig() {
|
|
170
|
-
return this.requiredServerFiles.config;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Get Next.js routes manifest from the build output
|
|
174
|
-
*/
|
|
175
|
-
async getRoutesManifest() {
|
|
176
|
-
return JSON.parse(await readFile(join(this.publishDir, "routes-manifest.json"), "utf-8"));
|
|
177
|
-
}
|
|
178
|
-
/** Fails a build with a message and an optional error */
|
|
179
|
-
failBuild(message, error) {
|
|
180
|
-
return this.utils.build.failBuild(message, error instanceof Error ? { error } : void 0);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export {
|
|
185
|
-
SERVER_HANDLER_NAME,
|
|
186
|
-
EDGE_HANDLER_NAME,
|
|
187
|
-
PluginContext
|
|
188
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
PLUGIN_DIR,
|
|
9
|
-
RUN_CONFIG
|
|
10
|
-
} from "./chunk-UYKENJEU.js";
|
|
11
|
-
|
|
12
|
-
// src/run/config.ts
|
|
13
|
-
import { existsSync } from "node:fs";
|
|
14
|
-
import { readFile } from "node:fs/promises";
|
|
15
|
-
import { join, resolve } from "node:path";
|
|
16
|
-
var getRunConfig = async () => {
|
|
17
|
-
return JSON.parse(await readFile(resolve(PLUGIN_DIR, RUN_CONFIG), "utf-8"));
|
|
18
|
-
};
|
|
19
|
-
var setRunConfig = (config) => {
|
|
20
|
-
const cacheHandler = join(PLUGIN_DIR, ".netlify/dist/run/handlers/cache.cjs");
|
|
21
|
-
if (!existsSync(cacheHandler)) {
|
|
22
|
-
throw new Error(`Cache handler not found at ${cacheHandler}`);
|
|
23
|
-
}
|
|
24
|
-
config.experimental = {
|
|
25
|
-
...config.experimental,
|
|
26
|
-
incrementalCacheHandlerPath: cacheHandler
|
|
27
|
-
};
|
|
28
|
-
config.cacheHandler = cacheHandler;
|
|
29
|
-
config.cacheMaxMemorySize = 0;
|
|
30
|
-
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(config);
|
|
31
|
-
};
|
|
32
|
-
var getTagsManifest = async () => {
|
|
33
|
-
return JSON.parse(await readFile(resolve(PLUGIN_DIR, ".netlify/tags-manifest.json"), "utf-8"));
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export {
|
|
37
|
-
getRunConfig,
|
|
38
|
-
setRunConfig,
|
|
39
|
-
getTagsManifest
|
|
40
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// src/build/cache.ts
|
|
9
|
-
import { existsSync } from "node:fs";
|
|
10
|
-
import { rm } from "node:fs/promises";
|
|
11
|
-
import { join } from "node:path";
|
|
12
|
-
var saveBuildCache = async (ctx) => {
|
|
13
|
-
const { cache } = ctx.utils;
|
|
14
|
-
const cacheDir = join(ctx.publishDir, "cache");
|
|
15
|
-
if (existsSync(cacheDir)) {
|
|
16
|
-
await rm(join(cacheDir, "fetch-cache"), { recursive: true, force: true });
|
|
17
|
-
await cache.save(cacheDir);
|
|
18
|
-
console.log("Next.js cache saved");
|
|
19
|
-
} else {
|
|
20
|
-
console.log("No Next.js cache to save");
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
var restoreBuildCache = async (ctx) => {
|
|
24
|
-
const { cache } = ctx.utils;
|
|
25
|
-
const cacheDir = join(ctx.publishDir, "cache");
|
|
26
|
-
if (await cache.restore(cacheDir)) {
|
|
27
|
-
console.log("Next.js cache restored");
|
|
28
|
-
} else {
|
|
29
|
-
console.log("No Next.js cache to restore");
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export {
|
|
34
|
-
saveBuildCache,
|
|
35
|
-
restoreBuildCache
|
|
36
|
-
};
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
encodeBlobKey
|
|
9
|
-
} from "./chunk-TYCYFZ22.js";
|
|
10
|
-
import {
|
|
11
|
-
wrapTracer
|
|
12
|
-
} from "./chunk-PDPDW32D.js";
|
|
13
|
-
import {
|
|
14
|
-
init_esm,
|
|
15
|
-
trace
|
|
16
|
-
} from "./chunk-Y3K5Q6FP.js";
|
|
17
|
-
import {
|
|
18
|
-
require_out
|
|
19
|
-
} from "./chunk-VZNKO4OO.js";
|
|
20
|
-
import {
|
|
21
|
-
__toESM
|
|
22
|
-
} from "./chunk-5JVNISGM.js";
|
|
23
|
-
|
|
24
|
-
// src/build/content/static.ts
|
|
25
|
-
init_esm();
|
|
26
|
-
import { existsSync } from "node:fs";
|
|
27
|
-
import { cp, mkdir, rename, rm } from "node:fs/promises";
|
|
28
|
-
import { basename, join } from "node:path";
|
|
29
|
-
var import_fast_glob = __toESM(require_out(), 1);
|
|
30
|
-
var tracer = wrapTracer(trace.getTracer("Next runtime"));
|
|
31
|
-
var copyStaticContent = async (ctx) => {
|
|
32
|
-
return tracer.withActiveSpan("copyStaticContent", async () => {
|
|
33
|
-
const srcDir = join(ctx.publishDir, "server/pages");
|
|
34
|
-
const destDir = ctx.blobDir;
|
|
35
|
-
const paths = await (0, import_fast_glob.default)("**/*.+(html|json)", {
|
|
36
|
-
cwd: srcDir,
|
|
37
|
-
extglob: true
|
|
38
|
-
});
|
|
39
|
-
try {
|
|
40
|
-
await Promise.all(
|
|
41
|
-
paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
|
|
42
|
-
await cp(join(srcDir, path), join(destDir, await encodeBlobKey(path)), {
|
|
43
|
-
recursive: true,
|
|
44
|
-
force: true
|
|
45
|
-
});
|
|
46
|
-
})
|
|
47
|
-
);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
ctx.failBuild("Failed assembling static pages for upload", error);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
var copyStaticAssets = async (ctx) => {
|
|
54
|
-
return tracer.withActiveSpan("copyStaticAssets", async (span) => {
|
|
55
|
-
try {
|
|
56
|
-
await rm(ctx.staticDir, { recursive: true, force: true });
|
|
57
|
-
const { basePath } = await ctx.getRoutesManifest();
|
|
58
|
-
if (existsSync(ctx.resolveFromSiteDir("public"))) {
|
|
59
|
-
await cp(ctx.resolveFromSiteDir("public"), join(ctx.staticDir, basePath), {
|
|
60
|
-
recursive: true
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
if (existsSync(join(ctx.publishDir, "static"))) {
|
|
64
|
-
await cp(join(ctx.publishDir, "static"), join(ctx.staticDir, basePath, "_next/static"), {
|
|
65
|
-
recursive: true
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
} catch (error) {
|
|
69
|
-
span.end();
|
|
70
|
-
ctx.failBuild("Failed copying static assets", error);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
var copyStaticExport = async (ctx) => {
|
|
75
|
-
await tracer.withActiveSpan("copyStaticExport", async () => {
|
|
76
|
-
try {
|
|
77
|
-
await rm(ctx.staticDir, { recursive: true, force: true });
|
|
78
|
-
await cp(ctx.resolveFromSiteDir("out"), ctx.staticDir, { recursive: true });
|
|
79
|
-
} catch (error) {
|
|
80
|
-
ctx.failBuild("Failed copying static export", error);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
var publishStaticDir = async (ctx) => {
|
|
85
|
-
try {
|
|
86
|
-
await rm(ctx.tempPublishDir, { recursive: true, force: true });
|
|
87
|
-
await mkdir(basename(ctx.tempPublishDir), { recursive: true });
|
|
88
|
-
await rename(ctx.publishDir, ctx.tempPublishDir);
|
|
89
|
-
await rename(ctx.staticDir, ctx.publishDir);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
ctx.failBuild("Failed publishing static content", error instanceof Error ? { error } : {});
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
var unpublishStaticDir = async (ctx) => {
|
|
95
|
-
try {
|
|
96
|
-
if (existsSync(ctx.tempPublishDir)) {
|
|
97
|
-
await rename(ctx.publishDir, ctx.staticDir);
|
|
98
|
-
await rename(ctx.tempPublishDir, ctx.publishDir);
|
|
99
|
-
}
|
|
100
|
-
} catch {
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export {
|
|
105
|
-
copyStaticContent,
|
|
106
|
-
copyStaticAssets,
|
|
107
|
-
copyStaticExport,
|
|
108
|
-
publishStaticDir,
|
|
109
|
-
unpublishStaticDir
|
|
110
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
__require
|
|
9
|
-
} from "./chunk-5JVNISGM.js";
|
|
10
|
-
|
|
11
|
-
// src/build/advanced-api-routes.ts
|
|
12
|
-
import { existsSync } from "node:fs";
|
|
13
|
-
import { readFile } from "node:fs/promises";
|
|
14
|
-
import { join } from "node:path";
|
|
15
|
-
var ApiRouteType = /* @__PURE__ */ ((ApiRouteType2) => {
|
|
16
|
-
ApiRouteType2["SCHEDULED"] = "experimental-scheduled";
|
|
17
|
-
ApiRouteType2["BACKGROUND"] = "experimental-background";
|
|
18
|
-
return ApiRouteType2;
|
|
19
|
-
})(ApiRouteType || {});
|
|
20
|
-
async function getAPIRoutesConfigs(ctx) {
|
|
21
|
-
const functionsConfigManifestPath = join(
|
|
22
|
-
ctx.publishDir,
|
|
23
|
-
"server",
|
|
24
|
-
"functions-config-manifest.json"
|
|
25
|
-
);
|
|
26
|
-
if (!existsSync(functionsConfigManifestPath)) {
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
const functionsConfigManifest = JSON.parse(
|
|
30
|
-
await readFile(functionsConfigManifestPath, "utf-8")
|
|
31
|
-
);
|
|
32
|
-
const appDir = ctx.resolveFromSiteDir(".");
|
|
33
|
-
const pagesDir = join(appDir, "pages");
|
|
34
|
-
const srcPagesDir = join(appDir, "src", "pages");
|
|
35
|
-
const { pageExtensions } = ctx.requiredServerFiles.config;
|
|
36
|
-
return Promise.all(
|
|
37
|
-
Object.keys(functionsConfigManifest.functions).map(async (apiRoute) => {
|
|
38
|
-
const filePath = getSourceFileForPage(apiRoute, [pagesDir, srcPagesDir], pageExtensions);
|
|
39
|
-
const sharedFields = {
|
|
40
|
-
apiRoute,
|
|
41
|
-
filePath,
|
|
42
|
-
config: {}
|
|
43
|
-
};
|
|
44
|
-
if (filePath) {
|
|
45
|
-
const config = await extractConfigFromFile(filePath, appDir);
|
|
46
|
-
return {
|
|
47
|
-
...sharedFields,
|
|
48
|
-
config
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
return sharedFields;
|
|
52
|
-
})
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
var SOURCE_FILE_EXTENSIONS = ["js", "jsx", "ts", "tsx"];
|
|
56
|
-
var getSourceFileForPage = (page, roots, pageExtensions = SOURCE_FILE_EXTENSIONS) => {
|
|
57
|
-
for (const root of roots) {
|
|
58
|
-
for (const extension of pageExtensions) {
|
|
59
|
-
const file = join(root, `${page}.${extension}`);
|
|
60
|
-
if (existsSync(file)) {
|
|
61
|
-
return file;
|
|
62
|
-
}
|
|
63
|
-
const fileAtFolderIndex = join(root, page, `index.${extension}`);
|
|
64
|
-
if (existsSync(fileAtFolderIndex)) {
|
|
65
|
-
return fileAtFolderIndex;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
var findModuleFromBase = ({
|
|
71
|
-
paths,
|
|
72
|
-
candidates
|
|
73
|
-
}) => {
|
|
74
|
-
for (const candidate of candidates) {
|
|
75
|
-
try {
|
|
76
|
-
const modulePath = __require.resolve(candidate, { paths });
|
|
77
|
-
if (modulePath) {
|
|
78
|
-
return modulePath;
|
|
79
|
-
}
|
|
80
|
-
} catch {
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
for (const candidate of candidates) {
|
|
84
|
-
try {
|
|
85
|
-
const modulePath = __require.resolve(candidate);
|
|
86
|
-
if (modulePath) {
|
|
87
|
-
return modulePath;
|
|
88
|
-
}
|
|
89
|
-
} catch {
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
};
|
|
94
|
-
var extractConstValue;
|
|
95
|
-
var parseModule;
|
|
96
|
-
var extractConfigFromFile = async (apiFilePath, appDir) => {
|
|
97
|
-
if (!apiFilePath || !existsSync(apiFilePath)) {
|
|
98
|
-
return {};
|
|
99
|
-
}
|
|
100
|
-
const extractConstValueModulePath = findModuleFromBase({
|
|
101
|
-
paths: [appDir],
|
|
102
|
-
candidates: ["next/dist/build/analysis/extract-const-value"]
|
|
103
|
-
});
|
|
104
|
-
const parseModulePath = findModuleFromBase({
|
|
105
|
-
paths: [appDir],
|
|
106
|
-
candidates: ["next/dist/build/analysis/parse-module"]
|
|
107
|
-
});
|
|
108
|
-
if (!extractConstValueModulePath || !parseModulePath) {
|
|
109
|
-
return {};
|
|
110
|
-
}
|
|
111
|
-
if (!extractConstValue && extractConstValueModulePath) {
|
|
112
|
-
extractConstValue = __require(extractConstValueModulePath);
|
|
113
|
-
}
|
|
114
|
-
if (!parseModule && parseModulePath) {
|
|
115
|
-
parseModule = __require(parseModulePath).parseModule;
|
|
116
|
-
}
|
|
117
|
-
const { extractExportedConstValue } = extractConstValue;
|
|
118
|
-
const fileContent = await readFile(apiFilePath, "utf8");
|
|
119
|
-
if (!fileContent.includes("config")) {
|
|
120
|
-
return {};
|
|
121
|
-
}
|
|
122
|
-
const ast = await parseModule(apiFilePath, fileContent);
|
|
123
|
-
try {
|
|
124
|
-
return extractExportedConstValue(ast, "config");
|
|
125
|
-
} catch {
|
|
126
|
-
return {};
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export {
|
|
131
|
-
ApiRouteType,
|
|
132
|
-
getAPIRoutesConfigs
|
|
133
|
-
};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
copyNextDependencies,
|
|
9
|
-
copyNextServerCode,
|
|
10
|
-
verifyHandlerDirStructure,
|
|
11
|
-
writeTagsManifest
|
|
12
|
-
} from "./chunk-ZKJEJNSJ.js";
|
|
13
|
-
import {
|
|
14
|
-
wrapTracer
|
|
15
|
-
} from "./chunk-PDPDW32D.js";
|
|
16
|
-
import {
|
|
17
|
-
init_esm,
|
|
18
|
-
trace
|
|
19
|
-
} from "./chunk-Y3K5Q6FP.js";
|
|
20
|
-
import {
|
|
21
|
-
require_out
|
|
22
|
-
} from "./chunk-VZNKO4OO.js";
|
|
23
|
-
import {
|
|
24
|
-
SERVER_HANDLER_NAME
|
|
25
|
-
} from "./chunk-3NYX5FXN.js";
|
|
26
|
-
import {
|
|
27
|
-
__toESM
|
|
28
|
-
} from "./chunk-5JVNISGM.js";
|
|
29
|
-
|
|
30
|
-
// src/build/functions/server.ts
|
|
31
|
-
init_esm();
|
|
32
|
-
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
33
|
-
import { join, relative } from "node:path";
|
|
34
|
-
import { join as posixJoin } from "node:path/posix";
|
|
35
|
-
var import_fast_glob = __toESM(require_out(), 1);
|
|
36
|
-
var tracer = wrapTracer(trace.getTracer("Next runtime"));
|
|
37
|
-
var copyHandlerDependencies = async (ctx) => {
|
|
38
|
-
await tracer.withActiveSpan("copyHandlerDependencies", async (span) => {
|
|
39
|
-
const promises = [];
|
|
40
|
-
const { included_files: includedFiles = [] } = ctx.netlifyConfig.functions?.["*"] || {};
|
|
41
|
-
span.setAttribute("next.includedFiles", includedFiles.join(","));
|
|
42
|
-
if (includedFiles.length !== 0) {
|
|
43
|
-
const resolvedFiles = await Promise.all(
|
|
44
|
-
includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
|
|
45
|
-
);
|
|
46
|
-
for (const filePath of resolvedFiles.flat()) {
|
|
47
|
-
promises.push(
|
|
48
|
-
cp(
|
|
49
|
-
join(process.cwd(), filePath),
|
|
50
|
-
// the serverHandlerDir is aware of the dist dir.
|
|
51
|
-
// The distDir must not be the package path therefore we need to rely on the
|
|
52
|
-
// serverHandlerDir instead of the serverHandlerRootDir
|
|
53
|
-
// therefore we need to remove the package path from the filePath
|
|
54
|
-
join(ctx.serverHandlerDir, relative(ctx.relativeAppDir, filePath)),
|
|
55
|
-
{
|
|
56
|
-
recursive: true,
|
|
57
|
-
force: true
|
|
58
|
-
}
|
|
59
|
-
)
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
|
|
64
|
-
for (const filePath of fileList) {
|
|
65
|
-
promises.push(
|
|
66
|
-
cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerDir, ".netlify", filePath), {
|
|
67
|
-
recursive: true,
|
|
68
|
-
force: true
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
await Promise.all(promises);
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
var writeHandlerManifest = async (ctx) => {
|
|
76
|
-
await writeFile(
|
|
77
|
-
join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.json`),
|
|
78
|
-
JSON.stringify({
|
|
79
|
-
config: {
|
|
80
|
-
name: "Next.js Server Handler",
|
|
81
|
-
generator: `${ctx.pluginName}@${ctx.pluginVersion}`,
|
|
82
|
-
nodeBundler: "none",
|
|
83
|
-
// the folders can vary in monorepos based on the folder structure of the user so we have to glob all
|
|
84
|
-
includedFiles: ["**"],
|
|
85
|
-
includedFilesBasePath: ctx.serverHandlerRootDir
|
|
86
|
-
},
|
|
87
|
-
version: 1
|
|
88
|
-
}),
|
|
89
|
-
"utf-8"
|
|
90
|
-
);
|
|
91
|
-
};
|
|
92
|
-
var writePackageMetadata = async (ctx) => {
|
|
93
|
-
await writeFile(
|
|
94
|
-
join(ctx.serverHandlerRootDir, "package.json"),
|
|
95
|
-
JSON.stringify({ type: "module" })
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
var getHandlerFile = async (ctx) => {
|
|
99
|
-
const templatesDir = join(ctx.pluginDir, "dist/build/templates");
|
|
100
|
-
if (ctx.relativeAppDir.length !== 0) {
|
|
101
|
-
const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
|
|
102
|
-
return template.replaceAll("{{cwd}}", posixJoin(ctx.lambdaWorkingDirectory)).replace("{{nextServerHandler}}", posixJoin(ctx.nextServerHandler));
|
|
103
|
-
}
|
|
104
|
-
return await readFile(join(templatesDir, "handler.tmpl.js"), "utf-8");
|
|
105
|
-
};
|
|
106
|
-
var writeHandlerFile = async (ctx) => {
|
|
107
|
-
const handler = await getHandlerFile(ctx);
|
|
108
|
-
await writeFile(join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.mjs`), handler);
|
|
109
|
-
};
|
|
110
|
-
var createServerHandler = async (ctx) => {
|
|
111
|
-
await tracer.withActiveSpan("createServerHandler", async () => {
|
|
112
|
-
await rm(ctx.serverFunctionsDir, { recursive: true, force: true });
|
|
113
|
-
await mkdir(join(ctx.serverHandlerDir, ".netlify"), { recursive: true });
|
|
114
|
-
await copyNextServerCode(ctx);
|
|
115
|
-
await copyNextDependencies(ctx);
|
|
116
|
-
await writeTagsManifest(ctx);
|
|
117
|
-
await copyHandlerDependencies(ctx);
|
|
118
|
-
await writeHandlerManifest(ctx);
|
|
119
|
-
await writePackageMetadata(ctx);
|
|
120
|
-
await writeHandlerFile(ctx);
|
|
121
|
-
await verifyHandlerDirStructure(ctx);
|
|
122
|
-
});
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export {
|
|
126
|
-
createServerHandler
|
|
127
|
-
};
|