@netlify/plugin-nextjs 5.0.0-beta.3 → 5.0.0-beta.5

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.
Files changed (40) hide show
  1. package/dist/build/cache.js +4 -4
  2. package/dist/build/content/prerendered.js +5 -5
  3. package/dist/build/content/server.js +5 -5
  4. package/dist/build/content/static.js +6 -5
  5. package/dist/build/functions/edge.js +7 -6
  6. package/dist/build/functions/server.js +8 -7
  7. package/dist/build/image-cdn.js +4 -4
  8. package/dist/build/plugin-context.js +5 -4
  9. package/dist/esm-chunks/{chunk-TJKO3X6O.js → chunk-5OSUYKC4.js} +33 -8
  10. package/dist/esm-chunks/{chunk-Z7ZMLVTM.js → chunk-AMJYZZKR.js} +8 -7
  11. package/dist/esm-chunks/{chunk-S5JXJCXP.js → chunk-BPBL55OP.js} +6 -6
  12. package/dist/esm-chunks/{chunk-ALO2SSMH.js → chunk-CFYLTWDR.js} +39 -28
  13. package/dist/esm-chunks/{chunk-5SZ5JD6J.js → chunk-COJ526HO.js} +39 -11
  14. package/dist/esm-chunks/{chunk-H46DW7YI.js → chunk-EPSI5TTB.js} +2 -2
  15. package/dist/esm-chunks/{chunk-FFCTA32Q.js → chunk-HFQPUU7P.js} +36 -17
  16. package/dist/esm-chunks/{chunk-4AJYXTWN.js → chunk-K233JI4O.js} +2 -2
  17. package/dist/esm-chunks/{chunk-AVWFCGVE.js → chunk-MFN4GH7U.js} +3 -3
  18. package/dist/esm-chunks/{chunk-B6QMRLBH.js → chunk-NE4HYI2D.js} +3 -3
  19. package/dist/esm-chunks/chunk-TYCYFZ22.js +25 -0
  20. package/dist/esm-chunks/{chunk-SMSOJ2OS.js → chunk-W5TLWQMF.js} +6 -9
  21. package/dist/esm-chunks/{chunk-RSKIKBZH.js → chunk-WELZ7LFO.js} +2 -2
  22. package/dist/esm-chunks/{chunk-GHDGGK6V.js → chunk-X7XIMV6B.js} +3 -3
  23. package/dist/esm-chunks/{chunk-XQ65S4R2.js → chunk-XA2CZH5Y.js} +2 -2
  24. package/dist/esm-chunks/{chunk-OIL5MDCV.js → chunk-XIP2W57K.js} +12 -5
  25. package/dist/index.js +22 -15
  26. package/dist/run/config.js +5 -5
  27. package/dist/run/constants.js +4 -4
  28. package/dist/run/handlers/cache.cjs +38 -9
  29. package/dist/run/handlers/server.js +15 -12
  30. package/dist/run/headers.js +5 -4
  31. package/dist/run/next.cjs +30 -3
  32. package/dist/run/revalidate.js +4 -4
  33. package/dist/run/systemlog.js +4 -4
  34. package/dist/shared/blobkey.js +13 -0
  35. package/edge-runtime/vendor/import_map.json +0 -6
  36. package/edge-runtime/vendor.ts +0 -3
  37. package/package.json +1 -1
  38. package/edge-runtime/vendor/esm.sh/v91/next@12.2.5/deno/dist/compiled/cookie.js +0 -13
  39. package/edge-runtime/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/request.js +0 -12
  40. package/edge-runtime/vendor/esm.sh/v91/next@12.2.5/deno/dist/server/web/spec-extension/response.js +0 -5
@@ -1,14 +1,14 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  restoreBuildCache,
9
9
  saveBuildCache
10
- } from "../esm-chunks/chunk-XQ65S4R2.js";
11
- import "../esm-chunks/chunk-RSKIKBZH.js";
10
+ } from "../esm-chunks/chunk-XA2CZH5Y.js";
11
+ import "../esm-chunks/chunk-WELZ7LFO.js";
12
12
  export {
13
13
  restoreBuildCache,
14
14
  saveBuildCache
@@ -1,15 +1,15 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  copyFetchContent,
9
9
  copyPrerenderedContent
10
- } from "../../esm-chunks/chunk-S5JXJCXP.js";
11
- import "../../esm-chunks/chunk-AVWFCGVE.js";
12
- import "../../esm-chunks/chunk-RSKIKBZH.js";
10
+ } from "../../esm-chunks/chunk-BPBL55OP.js";
11
+ import "../../esm-chunks/chunk-MFN4GH7U.js";
12
+ import "../../esm-chunks/chunk-WELZ7LFO.js";
13
13
  export {
14
14
  copyFetchContent,
15
15
  copyPrerenderedContent
@@ -1,6 +1,6 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
@@ -8,9 +8,9 @@ import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
10
  writeTagsManifest
11
- } from "../../esm-chunks/chunk-5SZ5JD6J.js";
12
- import "../../esm-chunks/chunk-AVWFCGVE.js";
13
- import "../../esm-chunks/chunk-RSKIKBZH.js";
11
+ } from "../../esm-chunks/chunk-COJ526HO.js";
12
+ import "../../esm-chunks/chunk-MFN4GH7U.js";
13
+ import "../../esm-chunks/chunk-WELZ7LFO.js";
14
14
  export {
15
15
  copyNextDependencies,
16
16
  copyNextServerCode,
@@ -1,6 +1,6 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
@@ -9,9 +9,10 @@ import {
9
9
  copyStaticContent,
10
10
  publishStaticDir,
11
11
  unpublishStaticDir
12
- } from "../../esm-chunks/chunk-Z7ZMLVTM.js";
13
- import "../../esm-chunks/chunk-AVWFCGVE.js";
14
- import "../../esm-chunks/chunk-RSKIKBZH.js";
12
+ } from "../../esm-chunks/chunk-AMJYZZKR.js";
13
+ import "../../esm-chunks/chunk-MFN4GH7U.js";
14
+ import "../../esm-chunks/chunk-TYCYFZ22.js";
15
+ import "../../esm-chunks/chunk-WELZ7LFO.js";
15
16
  export {
16
17
  copyStaticAssets,
17
18
  copyStaticContent,
@@ -1,15 +1,16 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  createEdgeHandlers
9
- } from "../../esm-chunks/chunk-FFCTA32Q.js";
10
- import "../../esm-chunks/chunk-AVWFCGVE.js";
11
- import "../../esm-chunks/chunk-TJKO3X6O.js";
12
- import "../../esm-chunks/chunk-RSKIKBZH.js";
9
+ } from "../../esm-chunks/chunk-HFQPUU7P.js";
10
+ import "../../esm-chunks/chunk-MFN4GH7U.js";
11
+ import "../../esm-chunks/chunk-5OSUYKC4.js";
12
+ import "../../esm-chunks/chunk-TYCYFZ22.js";
13
+ import "../../esm-chunks/chunk-WELZ7LFO.js";
13
14
  export {
14
15
  createEdgeHandlers
15
16
  };
@@ -1,16 +1,17 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  createServerHandler
9
- } from "../../esm-chunks/chunk-ALO2SSMH.js";
10
- import "../../esm-chunks/chunk-5SZ5JD6J.js";
11
- import "../../esm-chunks/chunk-AVWFCGVE.js";
12
- import "../../esm-chunks/chunk-TJKO3X6O.js";
13
- import "../../esm-chunks/chunk-RSKIKBZH.js";
9
+ } from "../../esm-chunks/chunk-CFYLTWDR.js";
10
+ import "../../esm-chunks/chunk-COJ526HO.js";
11
+ import "../../esm-chunks/chunk-MFN4GH7U.js";
12
+ import "../../esm-chunks/chunk-5OSUYKC4.js";
13
+ import "../../esm-chunks/chunk-TYCYFZ22.js";
14
+ import "../../esm-chunks/chunk-WELZ7LFO.js";
14
15
  export {
15
16
  createServerHandler
16
17
  };
@@ -1,13 +1,13 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  setImageConfig
9
- } from "../esm-chunks/chunk-H46DW7YI.js";
10
- import "../esm-chunks/chunk-RSKIKBZH.js";
9
+ } from "../esm-chunks/chunk-EPSI5TTB.js";
10
+ import "../esm-chunks/chunk-WELZ7LFO.js";
11
11
  export {
12
12
  setImageConfig
13
13
  };
@@ -1,6 +1,6 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
@@ -8,8 +8,9 @@ import {
8
8
  EDGE_HANDLER_NAME,
9
9
  PluginContext,
10
10
  SERVER_HANDLER_NAME
11
- } from "../esm-chunks/chunk-TJKO3X6O.js";
12
- import "../esm-chunks/chunk-RSKIKBZH.js";
11
+ } from "../esm-chunks/chunk-5OSUYKC4.js";
12
+ import "../esm-chunks/chunk-TYCYFZ22.js";
13
+ import "../esm-chunks/chunk-WELZ7LFO.js";
13
14
  export {
14
15
  EDGE_HANDLER_NAME,
15
16
  PluginContext,
@@ -1,12 +1,14 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
+ import {
8
+ encodeBlobKey
9
+ } from "./chunk-TYCYFZ22.js";
7
10
 
8
11
  // src/build/plugin-context.ts
9
- import { Buffer } from "node:buffer";
10
12
  import { readFileSync } from "node:fs";
11
13
  import { mkdir, readFile, writeFile } from "node:fs/promises";
12
14
  import { dirname, join, resolve } from "node:path";
@@ -28,6 +30,24 @@ var PluginContext = class {
28
30
  get publishDir() {
29
31
  return resolve(this.constants.PUBLISH_DIR);
30
32
  }
33
+ /**
34
+ * Relative package path in non monorepo setups this is an empty string
35
+ * @example ''
36
+ * @example 'apps/my-app'
37
+ */
38
+ get packagePath() {
39
+ return this.constants.PACKAGE_PATH || "";
40
+ }
41
+ /**
42
+ * Retrieves the root of the `.next/standalone` directory
43
+ */
44
+ get standaloneRootDir() {
45
+ return join(this.publishDir, "standalone");
46
+ }
47
+ /** Retrieves the `.next/standalone/` directory monorepo aware */
48
+ get standaloneDir() {
49
+ return join(this.standaloneRootDir, this.constants.PACKAGE_PATH || "");
50
+ }
31
51
  /**
32
52
  * Absolute path of the directory that is published and deployed to the Netlify CDN
33
53
  * Will be swapped with the publish directory
@@ -51,9 +71,15 @@ var PluginContext = class {
51
71
  return this.resolve(".netlify/functions-internal");
52
72
  }
53
73
  /** Absolute path of the server handler */
54
- get serverHandlerDir() {
74
+ get serverHandlerRootDir() {
55
75
  return join(this.serverFunctionsDir, SERVER_HANDLER_NAME);
56
76
  }
77
+ get serverHandlerDir() {
78
+ return join(this.serverHandlerRootDir, this.constants.PACKAGE_PATH || "");
79
+ }
80
+ get nextServerHandler() {
81
+ return join(this.constants.PACKAGE_PATH || "", "dist/run/handlers/server.js");
82
+ }
57
83
  /**
58
84
  * Absolute path of the directory containing the files for deno edge functions
59
85
  * `.netlify/edge-functions`
@@ -100,11 +126,10 @@ var PluginContext = class {
100
126
  return JSON.parse(await readFile(join(this.publishDir, "routes-manifest.json"), "utf-8"));
101
127
  }
102
128
  /**
103
- * Write a cache entry to the blob upload directory using
104
- * base64 keys to avoid collisions with directories
129
+ * Write a cache entry to the blob upload directory.
105
130
  */
106
- async writeCacheEntry(key, value) {
107
- const path = join(this.blobDir, Buffer.from(key).toString("base64"));
131
+ async writeCacheEntry(route, value) {
132
+ const path = join(this.blobDir, await encodeBlobKey(route));
108
133
  const entry = JSON.stringify({
109
134
  lastModified: Date.now(),
110
135
  value
@@ -1,19 +1,21 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  require_out
9
- } from "./chunk-AVWFCGVE.js";
9
+ } from "./chunk-MFN4GH7U.js";
10
+ import {
11
+ encodeBlobKey
12
+ } from "./chunk-TYCYFZ22.js";
10
13
  import {
11
14
  __toESM
12
- } from "./chunk-RSKIKBZH.js";
15
+ } from "./chunk-WELZ7LFO.js";
13
16
 
14
17
  // src/build/content/static.ts
15
18
  var import_fast_glob = __toESM(require_out(), 1);
16
- import { Buffer } from "node:buffer";
17
19
  import { existsSync } from "node:fs";
18
20
  import { cp, mkdir, rename, rm } from "node:fs/promises";
19
21
  import { join } from "node:path";
@@ -27,8 +29,7 @@ var copyStaticContent = async (ctx) => {
27
29
  try {
28
30
  await Promise.all(
29
31
  paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
30
- const key = Buffer.from(path).toString("base64");
31
- await cp(join(srcDir, path), join(destDir, key), { recursive: true });
32
+ await cp(join(srcDir, path), join(destDir, await encodeBlobKey(path)), { recursive: true });
32
33
  })
33
34
  );
34
35
  } catch (error) {
@@ -1,22 +1,22 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  require_out
9
- } from "./chunk-AVWFCGVE.js";
9
+ } from "./chunk-MFN4GH7U.js";
10
10
  import {
11
11
  __toESM
12
- } from "./chunk-RSKIKBZH.js";
12
+ } from "./chunk-WELZ7LFO.js";
13
13
 
14
14
  // src/build/content/prerendered.ts
15
15
  var import_fast_glob = __toESM(require_out(), 1);
16
16
  import { existsSync } from "node:fs";
17
17
  import { readFile } from "node:fs/promises";
18
18
  import { join } from "node:path";
19
- var routeToFilePath = (path) => path.replace(/^\//, "") || "index";
19
+ var routeToFilePath = (path) => path === "/" ? "/index" : path;
20
20
  var buildPagesCacheValue = async (path) => ({
21
21
  kind: "PAGE",
22
22
  html: await readFile(`${path}.html`, "utf-8"),
@@ -63,7 +63,7 @@ var copyPrerenderedContent = async (ctx) => {
63
63
  })
64
64
  );
65
65
  if (existsSync(join(ctx.publishDir, `server/app/_not-found.html`))) {
66
- const key = "404";
66
+ const key = "/404";
67
67
  const value = await buildAppCacheValue(join(ctx.publishDir, "server/app/_not-found"));
68
68
  await ctx.writeCacheEntry(key, value);
69
69
  }
@@ -1,6 +1,6 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
@@ -8,16 +8,16 @@ import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
10
  writeTagsManifest
11
- } from "./chunk-5SZ5JD6J.js";
11
+ } from "./chunk-COJ526HO.js";
12
12
  import {
13
13
  require_out
14
- } from "./chunk-AVWFCGVE.js";
14
+ } from "./chunk-MFN4GH7U.js";
15
15
  import {
16
16
  SERVER_HANDLER_NAME
17
- } from "./chunk-TJKO3X6O.js";
17
+ } from "./chunk-5OSUYKC4.js";
18
18
  import {
19
19
  __toESM
20
- } from "./chunk-RSKIKBZH.js";
20
+ } from "./chunk-WELZ7LFO.js";
21
21
 
22
22
  // src/build/functions/server.ts
23
23
  var import_fast_glob = __toESM(require_out(), 1);
@@ -33,21 +33,15 @@ var copyHandlerDependencies = async (ctx) => {
33
33
  };
34
34
  var writeHandlerManifest = async (ctx) => {
35
35
  await writeFile(
36
- join(ctx.serverHandlerDir, `${SERVER_HANDLER_NAME}.json`),
36
+ join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.json`),
37
37
  JSON.stringify({
38
38
  config: {
39
39
  name: "Next.js Server Handler",
40
40
  generator: `${ctx.pluginName}@${ctx.pluginVersion}`,
41
41
  nodeBundler: "none",
42
- includedFiles: [
43
- `${SERVER_HANDLER_NAME}*`,
44
- "package.json",
45
- "dist/**",
46
- ".next/**",
47
- ".netlify/**",
48
- "node_modules/**"
49
- ],
50
- includedFilesBasePath: ctx.serverHandlerDir
42
+ // the folders can vary in monorepos based on the folder structure of the user so we have to glob all
43
+ includedFiles: ["**"],
44
+ includedFilesBasePath: ctx.serverHandlerRootDir
51
45
  },
52
46
  version: 1
53
47
  }),
@@ -55,21 +49,38 @@ var writeHandlerManifest = async (ctx) => {
55
49
  );
56
50
  };
57
51
  var writePackageMetadata = async (ctx) => {
58
- await writeFile(join(ctx.serverHandlerDir, "package.json"), JSON.stringify({ type: "module" }));
59
- };
60
- var writeHandlerFile = async (ctx) => {
61
52
  await writeFile(
62
- join(ctx.serverHandlerDir, `${SERVER_HANDLER_NAME}.js`),
63
- `
64
- import handler from './dist/run/handlers/server.js';
65
- export default handler;
66
- export const config = {
67
- path: '/*',
68
- preferStatic: true
69
- };
70
- `
53
+ join(ctx.serverHandlerRootDir, "package.json"),
54
+ JSON.stringify({ type: "module" })
71
55
  );
72
56
  };
57
+ var getHandlerFile = (ctx) => {
58
+ const config = `
59
+ export const config = {
60
+ path: '/*',
61
+ preferStatic: true,
62
+ }`;
63
+ if (ctx.packagePath.length !== 0) {
64
+ return `process.chdir('${join("/var/task", ctx.packagePath)}');
65
+
66
+ let cachedHandler;
67
+ export default async function(...args) {
68
+ if (!cachedHandler) {
69
+ const { default: handler } = await import('./${ctx.nextServerHandler}');
70
+ cachedHandler = handler;
71
+ }
72
+ return cachedHandler(...args)
73
+ };
74
+
75
+ ${config}`;
76
+ }
77
+ return `import handler from './dist/run/handlers/server.js';
78
+ export default handler;
79
+ ${config}`;
80
+ };
81
+ var writeHandlerFile = async (ctx) => {
82
+ await writeFile(join(ctx.serverHandlerRootDir, `${SERVER_HANDLER_NAME}.mjs`), getHandlerFile(ctx));
83
+ };
73
84
  var createServerHandler = async (ctx) => {
74
85
  await rm(ctx.serverFunctionsDir, { recursive: true, force: true });
75
86
  await mkdir(join(ctx.serverHandlerDir, ".netlify"), { recursive: true });
@@ -1,23 +1,24 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  require_out
9
- } from "./chunk-AVWFCGVE.js";
9
+ } from "./chunk-MFN4GH7U.js";
10
10
  import {
11
11
  __toESM
12
- } from "./chunk-RSKIKBZH.js";
12
+ } from "./chunk-WELZ7LFO.js";
13
13
 
14
14
  // src/build/content/server.ts
15
15
  var import_fast_glob = __toESM(require_out(), 1);
16
16
  import { existsSync } from "node:fs";
17
17
  import { cp, mkdir, readFile, readdir, readlink, symlink, writeFile } from "node:fs/promises";
18
- import { dirname, join } from "node:path";
18
+ import { createRequire } from "node:module";
19
+ import { dirname, join, resolve } from "node:path";
19
20
  var copyNextServerCode = async (ctx) => {
20
- const srcDir = join(ctx.publishDir, "standalone/.next");
21
+ const srcDir = join(ctx.standaloneDir, ".next");
21
22
  const destDir = join(ctx.serverHandlerDir, ".next");
22
23
  const paths = await (0, import_fast_glob.default)(
23
24
  [`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
@@ -57,17 +58,44 @@ async function recreateNodeModuleSymlinks(src, dest, org) {
57
58
  if (org) {
58
59
  await mkdir(join(dest, org), { recursive: true });
59
60
  }
60
- await symlink(symlinkDest, symlinkSrc);
61
+ await symlink(symlinkTarget, symlinkSrc);
61
62
  }
62
63
  }
63
64
  })
64
65
  );
65
66
  }
66
67
  var copyNextDependencies = async (ctx) => {
67
- const srcDir = join(ctx.publishDir, "standalone/node_modules");
68
- const destDir = join(ctx.serverHandlerDir, "node_modules");
69
- await cp(srcDir, destDir, { recursive: true });
70
- await recreateNodeModuleSymlinks(ctx.resolve("node_modules"), destDir);
68
+ const entries = await readdir(ctx.standaloneDir);
69
+ const promises = entries.map(async (entry) => {
70
+ if (entry === "package.json" || entry === ".next") {
71
+ return;
72
+ }
73
+ const src = join(ctx.standaloneDir, entry);
74
+ const dest = join(ctx.serverHandlerDir, entry);
75
+ await cp(src, dest, { recursive: true, verbatimSymlinks: true });
76
+ if (entry === "node_modules") {
77
+ await recreateNodeModuleSymlinks(ctx.resolve("node_modules"), dest);
78
+ }
79
+ });
80
+ const rootSrcDir = join(ctx.standaloneRootDir, "node_modules");
81
+ const rootDestDir = join(ctx.serverHandlerRootDir, "node_modules");
82
+ if (existsSync(rootSrcDir) && ctx.standaloneRootDir !== ctx.standaloneDir) {
83
+ promises.push(
84
+ cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true }).then(
85
+ () => recreateNodeModuleSymlinks(resolve("node_modules"), rootDestDir)
86
+ )
87
+ );
88
+ }
89
+ await Promise.all(promises);
90
+ const require2 = createRequire(ctx.serverHandlerDir);
91
+ try {
92
+ require2.resolve("styled-jsx");
93
+ require2.resolve("next");
94
+ } catch {
95
+ throw new Error(
96
+ "node_modules are not installed correctly, if you are using pnpm please set the public hoist pattern to: `public-hoist-pattern[]=*`.\nRefer to your docs for more details: https://docs.netlify.com/integrations/frameworks/next-js/overview/#pnpm-support"
97
+ );
98
+ }
71
99
  };
72
100
  var writeTagsManifest = async (ctx) => {
73
101
  const manifest = await ctx.getPrerenderManifest();
@@ -1,6 +1,6 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
@@ -1,18 +1,18 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  require_out
9
- } from "./chunk-AVWFCGVE.js";
9
+ } from "./chunk-MFN4GH7U.js";
10
10
  import {
11
11
  EDGE_HANDLER_NAME
12
- } from "./chunk-TJKO3X6O.js";
12
+ } from "./chunk-5OSUYKC4.js";
13
13
  import {
14
14
  __toESM
15
- } from "./chunk-RSKIKBZH.js";
15
+ } from "./chunk-WELZ7LFO.js";
16
16
 
17
17
  // src/build/functions/edge.ts
18
18
  var import_fast_glob = __toESM(require_out(), 1);
@@ -59,21 +59,34 @@ var writeHandlerFile = async (ctx, { matchers, name }) => {
59
59
  `
60
60
  );
61
61
  };
62
- var copyHandlerDependencies = async (ctx, { name, files }) => {
62
+ var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
63
63
  const edgeRuntimePath = join(ctx.pluginDir, "edge-runtime");
64
- const srcDir = ctx.resolve(".next/standalone/.next");
64
+ const srcDir = join(ctx.standaloneDir, ".next");
65
65
  const shimPath = join(edgeRuntimePath, "shim/index.js");
66
66
  const shim = await readFile(shimPath, "utf8");
67
67
  const imports = `import './edge-runtime-webpack.js';`;
68
68
  const exports = `export default _ENTRIES["middleware_${name}"].default;`;
69
+ const parts = [shim, imports];
70
+ if (wasm?.length) {
71
+ parts.push(
72
+ `import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";`
73
+ );
74
+ for (const wasmChunk of wasm ?? []) {
75
+ const data = await readFile(join(srcDir, wasmChunk.filePath));
76
+ parts.push(
77
+ `const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
78
+ data.toString("base64")
79
+ )}).buffer`
80
+ );
81
+ }
82
+ }
69
83
  await Promise.all(
70
84
  files.map(async (file) => {
71
85
  const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }));
72
86
  if (file === `server/${name}.js`) {
73
87
  const entrypoint = await readFile(join(srcDir, file), "utf8");
74
- const parts = [shim, imports, entrypoint, exports];
75
88
  await mkdir(dirname(join(destDir, file)), { recursive: true });
76
- await writeFile(join(destDir, file), parts.join("\n;"));
89
+ await writeFile(join(destDir, file), [...parts, entrypoint, exports].join("\n;"));
77
90
  return;
78
91
  }
79
92
  await cp(join(srcDir, file), join(destDir, file));
@@ -85,13 +98,19 @@ var createEdgeHandler = async (ctx, definition) => {
85
98
  await writeHandlerFile(ctx, definition);
86
99
  };
87
100
  var getHandlerName = ({ name }) => `${EDGE_HANDLER_NAME}-${name.replace(/\W/g, "-")}`;
88
- var buildHandlerDefinition = (ctx, { name, matchers, page }) => ({
89
- function: getHandlerName({ name }),
90
- name: name === "middleware" ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`,
91
- pattern: matchers[0].regexp,
92
- cache: name === "middleware" ? void 0 : "manual",
93
- generator: `${ctx.pluginName}@${ctx.pluginVersion}`
94
- });
101
+ var buildHandlerDefinition = (ctx, { name, matchers, page }) => {
102
+ const fun = getHandlerName({ name });
103
+ const funName = name === "middleware" ? "Next.js Middleware Handler" : `Next.js Edge Handler: ${page}`;
104
+ const cache = name === "middleware" ? void 0 : "manual";
105
+ const generator = `${ctx.pluginName}@${ctx.pluginVersion}`;
106
+ return matchers.map((matcher) => ({
107
+ function: fun,
108
+ name: funName,
109
+ pattern: matcher.regexp,
110
+ cache,
111
+ generator
112
+ }));
113
+ };
95
114
  var createEdgeHandlers = async (ctx) => {
96
115
  await rm(ctx.edgeFunctionsDir, { recursive: true, force: true });
97
116
  const nextManifest = await ctx.getMiddlewareManifest();
@@ -100,7 +119,7 @@ var createEdgeHandlers = async (ctx) => {
100
119
  // ...Object.values(nextManifest.functions)
101
120
  ];
102
121
  await Promise.all(nextDefinitions.map((def) => createEdgeHandler(ctx, def)));
103
- const netlifyDefinitions = nextDefinitions.map((def) => buildHandlerDefinition(ctx, def));
122
+ const netlifyDefinitions = nextDefinitions.flatMap((def) => buildHandlerDefinition(ctx, def));
104
123
  const netlifyManifest = {
105
124
  version: 1,
106
125
  functions: netlifyDefinitions
@@ -1,6 +1,6 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
@@ -1,13 +1,13 @@
1
1
 
2
- const require = await (async () => {
3
- const { createRequire } = await import("node:module");
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
7
  import {
8
8
  __commonJS,
9
9
  __require
10
- } from "./chunk-RSKIKBZH.js";
10
+ } from "./chunk-WELZ7LFO.js";
11
11
 
12
12
  // node_modules/fast-glob/out/utils/array.js
13
13
  var require_array = __commonJS({