@netlify/plugin-nextjs 5.0.0-rc.1 → 5.0.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  copyFetchContent,
9
9
  copyPrerenderedContent
10
- } from "../../esm-chunks/chunk-67EWAGDQ.js";
10
+ } from "../../esm-chunks/chunk-LWQKZVSS.js";
11
11
  import "../../esm-chunks/chunk-VZNKO4OO.js";
12
12
  import "../../esm-chunks/chunk-TYCYFZ22.js";
13
13
  import "../../esm-chunks/chunk-5JVNISGM.js";
@@ -7,13 +7,15 @@
7
7
  import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
+ verifyHandlerDirStructure,
10
11
  writeTagsManifest
11
- } from "../../esm-chunks/chunk-4J4A5OE2.js";
12
+ } from "../../esm-chunks/chunk-GFISNHVP.js";
12
13
  import "../../esm-chunks/chunk-VZNKO4OO.js";
13
14
  import "../../esm-chunks/chunk-UYKENJEU.js";
14
15
  import "../../esm-chunks/chunk-5JVNISGM.js";
15
16
  export {
16
17
  copyNextDependencies,
17
18
  copyNextServerCode,
19
+ verifyHandlerDirStructure,
18
20
  writeTagsManifest
19
21
  };
@@ -9,7 +9,7 @@ import {
9
9
  copyStaticContent,
10
10
  publishStaticDir,
11
11
  unpublishStaticDir
12
- } from "../../esm-chunks/chunk-WQIG4U66.js";
12
+ } from "../../esm-chunks/chunk-MPZEWLBG.js";
13
13
  import "../../esm-chunks/chunk-VZNKO4OO.js";
14
14
  import "../../esm-chunks/chunk-TYCYFZ22.js";
15
15
  import "../../esm-chunks/chunk-5JVNISGM.js";
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {
8
8
  createEdgeHandlers
9
- } from "../../esm-chunks/chunk-ZZOGIP2V.js";
9
+ } from "../../esm-chunks/chunk-ATFMKC2X.js";
10
10
  import "../../esm-chunks/chunk-VZNKO4OO.js";
11
11
  import "../../esm-chunks/chunk-655Y7ISI.js";
12
12
  import "../../esm-chunks/chunk-5JVNISGM.js";
@@ -6,8 +6,8 @@
6
6
 
7
7
  import {
8
8
  createServerHandler
9
- } from "../../esm-chunks/chunk-GAZUUVZW.js";
10
- import "../../esm-chunks/chunk-4J4A5OE2.js";
9
+ } from "../../esm-chunks/chunk-A6CMEU53.js";
10
+ import "../../esm-chunks/chunk-GFISNHVP.js";
11
11
  import "../../esm-chunks/chunk-VZNKO4OO.js";
12
12
  import "../../esm-chunks/chunk-655Y7ISI.js";
13
13
  import "../../esm-chunks/chunk-UYKENJEU.js";
@@ -7,8 +7,9 @@
7
7
  import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
+ verifyHandlerDirStructure,
10
11
  writeTagsManifest
11
- } from "./chunk-4J4A5OE2.js";
12
+ } from "./chunk-GFISNHVP.js";
12
13
  import {
13
14
  require_out
14
15
  } from "./chunk-VZNKO4OO.js";
@@ -21,18 +22,43 @@ import {
21
22
 
22
23
  // src/build/functions/server.ts
23
24
  var import_fast_glob = __toESM(require_out(), 1);
24
- import { cp, mkdir, readFile, rm, writeFile } from "fs/promises";
25
- import { join } from "node:path";
25
+ import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
26
+ import { join, relative } from "node:path";
27
+ import { join as posixJoin } from "node:path/posix";
26
28
  var copyHandlerDependencies = async (ctx) => {
29
+ const promises = [];
30
+ const { included_files: includedFiles = [] } = ctx.netlifyConfig.functions?.["*"] || {};
31
+ if (includedFiles.length !== 0) {
32
+ const resolvedFiles = await Promise.all(
33
+ includedFiles.map((globPattern) => (0, import_fast_glob.glob)(globPattern, { cwd: process.cwd() }))
34
+ );
35
+ for (const filePath of resolvedFiles.flat()) {
36
+ promises.push(
37
+ cp(
38
+ join(process.cwd(), filePath),
39
+ // the serverHandlerDir is aware of the dist dir.
40
+ // The distDir must not be the package path therefore we need to rely on the
41
+ // serverHandlerDir instead of the serverHandlerRootDir
42
+ // therefore we need to remove the package path from the filePath
43
+ join(ctx.serverHandlerDir, relative(ctx.packagePath, filePath)),
44
+ {
45
+ recursive: true,
46
+ force: true
47
+ }
48
+ )
49
+ );
50
+ }
51
+ }
27
52
  const fileList = await (0, import_fast_glob.glob)("dist/**/*", { cwd: ctx.pluginDir });
28
- await Promise.all(
29
- [...fileList].map(
30
- (path) => cp(join(ctx.pluginDir, path), join(ctx.serverHandlerDir, ".netlify", path), {
53
+ for (const filePath of fileList) {
54
+ promises.push(
55
+ cp(join(ctx.pluginDir, filePath), join(ctx.serverHandlerDir, ".netlify", filePath), {
31
56
  recursive: true,
32
57
  force: true
33
58
  })
34
- )
35
- );
59
+ );
60
+ }
61
+ await Promise.all(promises);
36
62
  };
37
63
  var writeHandlerManifest = async (ctx) => {
38
64
  await writeFile(
@@ -61,7 +87,7 @@ var getHandlerFile = async (ctx) => {
61
87
  const templatesDir = join(ctx.pluginDir, "dist/build/templates");
62
88
  if (ctx.packagePath.length !== 0) {
63
89
  const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
64
- return template.replaceAll("{{cwd}}", ctx.lambdaWorkingDirectory).replace("{{nextServerHandler}}", ctx.nextServerHandler);
90
+ return template.replaceAll("{{cwd}}", posixJoin(ctx.lambdaWorkingDirectory)).replace("{{nextServerHandler}}", posixJoin(ctx.nextServerHandler));
65
91
  }
66
92
  return await readFile(join(templatesDir, "handler.tmpl.js"), "utf-8");
67
93
  };
@@ -81,6 +107,7 @@ var createServerHandler = async (ctx) => {
81
107
  writePackageMetadata(ctx),
82
108
  writeHandlerFile(ctx)
83
109
  ]);
110
+ await verifyHandlerDirStructure(ctx);
84
111
  };
85
112
 
86
113
  export {
@@ -393,7 +393,7 @@ var require_dist = __commonJS({
393
393
  var import_fast_glob = __toESM(require_out(), 1);
394
394
  var import_path_to_regexp = __toESM(require_dist(), 1);
395
395
  import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
396
- import { dirname, join, relative } from "node:path";
396
+ import { dirname, join } from "node:path";
397
397
  var writeEdgeManifest = async (ctx, manifest) => {
398
398
  await mkdir(ctx.edgeFunctionsDir, { recursive: true });
399
399
  await writeFile(join(ctx.edgeFunctionsDir, "manifest.json"), JSON.stringify(manifest, null, 2));
@@ -459,38 +459,31 @@ var writeHandlerFile = async (ctx, { matchers, name }) => {
459
459
  var copyHandlerDependencies = async (ctx, { name, files, wasm }) => {
460
460
  const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
461
461
  const destDir = join(ctx.edgeFunctionsDir, getHandlerName({ name }));
462
- await Promise.all(
463
- files.map(async (file) => {
464
- if (file === `server/${name}.js`) {
465
- const edgeRuntimeDir = join(ctx.pluginDir, "edge-runtime");
466
- const shimPath = join(edgeRuntimeDir, "shim/index.js");
467
- const shim = await readFile(shimPath, "utf8");
468
- const importsDir = relative(dirname(join(srcDir, file)), join(srcDir, "server"));
469
- const importsSrc = `${importsDir || "."}/edge-runtime-webpack.js`;
470
- const imports = `import '${importsSrc}';`;
471
- const exports = `export default _ENTRIES["middleware_${name}"].default;`;
472
- const parts = [shim, imports];
473
- if (wasm?.length) {
474
- parts.push(
475
- `import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";`
476
- );
477
- for (const wasmChunk of wasm ?? []) {
478
- const data = await readFile(join(srcDir, wasmChunk.filePath));
479
- parts.push(
480
- `const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
481
- data.toString("base64")
482
- )}).buffer`
483
- );
484
- }
485
- }
486
- const entrypoint = await readFile(join(srcDir, file), "utf8");
487
- await mkdir(dirname(join(destDir, file)), { recursive: true });
488
- await writeFile(join(destDir, file), [...parts, entrypoint, exports].join("\n;"));
489
- } else {
490
- await cp(join(srcDir, file), join(destDir, file));
491
- }
492
- })
493
- );
462
+ const edgeRuntimeDir = join(ctx.pluginDir, "edge-runtime");
463
+ const shimPath = join(edgeRuntimeDir, "shim/index.js");
464
+ const shim = await readFile(shimPath, "utf8");
465
+ const parts = [shim];
466
+ if (wasm?.length) {
467
+ parts.push(
468
+ `import { decode as _base64Decode } from "../edge-runtime/vendor/deno.land/std@0.175.0/encoding/base64.ts";`
469
+ );
470
+ for (const wasmChunk of wasm ?? []) {
471
+ const data = await readFile(join(srcDir, wasmChunk.filePath));
472
+ parts.push(
473
+ `const ${wasmChunk.name} = _base64Decode(${JSON.stringify(
474
+ data.toString("base64")
475
+ )}).buffer`
476
+ );
477
+ }
478
+ }
479
+ for (const file of files) {
480
+ const entrypoint = await readFile(join(srcDir, file), "utf8");
481
+ parts.push(`;// Concatenated file: ${file}
482
+ `, entrypoint);
483
+ }
484
+ const exports = `export default _ENTRIES["middleware_${name}"].default;`;
485
+ await mkdir(dirname(join(destDir, `server/${name}.js`)), { recursive: true });
486
+ await writeFile(join(destDir, `server/${name}.js`), [...parts, exports].join("\n"));
494
487
  };
495
488
  var createEdgeHandler = async (ctx, definition) => {
496
489
  await copyHandlerDependencies(ctx, definition);
@@ -19,7 +19,9 @@ var import_fast_glob = __toESM(require_out(), 1);
19
19
  import { existsSync } from "node:fs";
20
20
  import { cp, mkdir, readFile, readdir, readlink, symlink, writeFile } from "node:fs/promises";
21
21
  import { createRequire } from "node:module";
22
- import { dirname, join, resolve } from "node:path";
22
+ import { dirname, join, resolve, sep } from "node:path";
23
+ import { sep as posixSep, relative as posixRelative } from "node:path/posix";
24
+ var toPosixPath = (path) => path.split(sep).join(posixSep);
23
25
  var copyNextServerCode = async (ctx) => {
24
26
  const reqServerFilesPath = join(
25
27
  ctx.standaloneRootDir,
@@ -27,7 +29,7 @@ var copyNextServerCode = async (ctx) => {
27
29
  "required-server-files.json"
28
30
  );
29
31
  const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
30
- if (ctx.distDir.replace(new RegExp(`^${ctx.packagePath}/?`), "") !== reqServerFiles.config.distDir) {
32
+ if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.packagePath}/?`), "") !== reqServerFiles.config.distDir) {
31
33
  reqServerFiles.config.distDir = ctx.nextDistDir;
32
34
  await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
33
35
  }
@@ -38,7 +40,7 @@ var copyNextServerCode = async (ctx) => {
38
40
  "utf-8"
39
41
  );
40
42
  const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
41
- const nextFolder = ctx.distDir === ctx.buildConfig.distDir ? ctx.distDir : ctx.nextDistDir;
43
+ const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir;
42
44
  const destDir = join(ctx.serverHandlerDir, nextFolder);
43
45
  const paths = await (0, import_fast_glob.default)(
44
46
  [`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
@@ -109,8 +111,9 @@ var copyNextDependencies = async (ctx) => {
109
111
  await Promise.all(promises);
110
112
  const require2 = createRequire(ctx.serverHandlerDir);
111
113
  try {
112
- require2.resolve("styled-jsx");
113
- require2.resolve("next");
114
+ const nextEntryAbsolutePath = require2.resolve("next");
115
+ const nextRequire = createRequire(nextEntryAbsolutePath);
116
+ nextRequire.resolve("styled-jsx");
114
117
  } catch {
115
118
  throw new Error(
116
119
  "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"
@@ -158,9 +161,53 @@ var replaceMiddlewareManifest = async (sourcePath, destPath) => {
158
161
  const newData = JSON.stringify(newManifest);
159
162
  await writeFile(destPath, newData);
160
163
  };
164
+ var verifyHandlerDirStructure = async (ctx) => {
165
+ const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), "utf-8"));
166
+ const expectedBuildIDPath = join(ctx.serverHandlerDir, runConfig.distDir, "BUILD_ID");
167
+ if (!existsSync(expectedBuildIDPath)) {
168
+ let additionalGuidance = "";
169
+ try {
170
+ const paths = await (0, import_fast_glob.default)("**/BUILD_ID", {
171
+ cwd: ctx.serverHandlerRootDir,
172
+ dot: true,
173
+ absolute: true,
174
+ ignore: ["**/node_modules/**"]
175
+ });
176
+ const potentiallyNeededPackagePaths = paths.map((path) => {
177
+ const relativePathToBuildID = posixRelative(
178
+ toPosixPath(ctx.serverHandlerDir),
179
+ toPosixPath(path)
180
+ );
181
+ const removedDistDirBuildId = relativePathToBuildID.replace(
182
+ new RegExp(`/?${toPosixPath(runConfig.distDir)}/BUILD_ID$`),
183
+ ""
184
+ );
185
+ return removedDistDirBuildId === relativePathToBuildID ? "" : removedDistDirBuildId;
186
+ }).filter(Boolean);
187
+ if (potentiallyNeededPackagePaths.length !== 0) {
188
+ additionalGuidance = `
189
+
190
+ It looks like your site is part of monorepo and Netlify is currently not configured correctly for this case.
191
+
192
+ Current package path: ${ctx.packagePath ? `"${ctx.packagePath}"` : "<not set>"}
193
+ Package path candidates:
194
+ ${potentiallyNeededPackagePaths.map((path) => ` - "${path}"`).join(
195
+ "\n"
196
+ )}
197
+
198
+ Refer to https://docs.netlify.com/configure-builds/monorepos/ for more information about monorepo configuration.`;
199
+ }
200
+ } catch {
201
+ }
202
+ ctx.failBuild(
203
+ `Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".${additionalGuidance}`
204
+ );
205
+ }
206
+ };
161
207
 
162
208
  export {
163
209
  copyNextServerCode,
164
210
  copyNextDependencies,
165
- writeTagsManifest
211
+ writeTagsManifest,
212
+ verifyHandlerDirStructure
166
213
  };