@netlify/plugin-nextjs 5.0.0-rc.3 → 5.0.0-rc.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.
@@ -7,6 +7,9 @@
7
7
  import {
8
8
  require_out
9
9
  } from "./chunk-VZNKO4OO.js";
10
+ import {
11
+ verifyNextVersion
12
+ } from "./chunk-MGPEWDDD.js";
10
13
  import {
11
14
  RUN_CONFIG
12
15
  } from "./chunk-UYKENJEU.js";
@@ -17,19 +20,43 @@ import {
17
20
  // src/build/content/server.ts
18
21
  var import_fast_glob = __toESM(require_out(), 1);
19
22
  import { existsSync } from "node:fs";
20
- import { cp, mkdir, readFile, readdir, readlink, symlink, writeFile } from "node:fs/promises";
23
+ import {
24
+ cp,
25
+ mkdir,
26
+ readFile,
27
+ readdir,
28
+ readlink,
29
+ symlink,
30
+ writeFile,
31
+ access
32
+ } from "node:fs/promises";
21
33
  import { createRequire } from "node:module";
22
34
  import { dirname, join, resolve, sep } from "node:path";
23
- import { sep as posixSep, relative as posixRelative } from "node:path/posix";
35
+ import { sep as posixSep, join as posixJoin } from "node:path/posix";
24
36
  var toPosixPath = (path) => path.split(sep).join(posixSep);
37
+ function isError(error) {
38
+ return error instanceof Error;
39
+ }
25
40
  var copyNextServerCode = async (ctx) => {
26
41
  const reqServerFilesPath = join(
27
42
  ctx.standaloneRootDir,
28
- ctx.relPublishDir,
43
+ ctx.relativeAppDir,
44
+ ctx.requiredServerFiles.config.distDir,
29
45
  "required-server-files.json"
30
46
  );
47
+ try {
48
+ await access(reqServerFilesPath);
49
+ } catch (error) {
50
+ if (isError(error) && error.code === "ENOENT") {
51
+ ctx.failBuild(
52
+ `Failed creating server handler. required-server-files.json file not found at expected location "${reqServerFilesPath}". Your repository setup is currently not yet supported.`
53
+ );
54
+ } else {
55
+ throw error;
56
+ }
57
+ }
31
58
  const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
32
- if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.packagePath}/?`), "") !== reqServerFiles.config.distDir) {
59
+ if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.relativeAppDir}/?`), "") !== reqServerFiles.config.distDir) {
33
60
  reqServerFiles.config.distDir = ctx.nextDistDir;
34
61
  await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
35
62
  }
@@ -96,7 +123,7 @@ var copyNextDependencies = async (ctx) => {
96
123
  const dest = join(ctx.serverHandlerDir, entry);
97
124
  await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true });
98
125
  if (entry === "node_modules") {
99
- await recreateNodeModuleSymlinks(ctx.resolve("node_modules"), dest);
126
+ await recreateNodeModuleSymlinks(ctx.resolveFromSiteDir("node_modules"), dest);
100
127
  }
101
128
  });
102
129
  const rootSrcDir = join(ctx.standaloneRootDir, "node_modules");
@@ -109,9 +136,20 @@ var copyNextDependencies = async (ctx) => {
109
136
  );
110
137
  }
111
138
  await Promise.all(promises);
112
- const require2 = createRequire(ctx.serverHandlerDir);
139
+ const serverHandlerRequire = createRequire(posixJoin(ctx.serverHandlerDir, ":internal:"));
140
+ let nextVersion;
141
+ try {
142
+ const { version } = serverHandlerRequire("next/package.json");
143
+ if (version) {
144
+ nextVersion = version;
145
+ }
146
+ } catch {
147
+ }
148
+ if (nextVersion) {
149
+ verifyNextVersion(ctx, nextVersion);
150
+ }
113
151
  try {
114
- const nextEntryAbsolutePath = require2.resolve("next");
152
+ const nextEntryAbsolutePath = serverHandlerRequire.resolve("next");
115
153
  const nextRequire = createRequire(nextEntryAbsolutePath);
116
154
  nextRequire.resolve("styled-jsx");
117
155
  } catch {
@@ -165,42 +203,8 @@ var verifyHandlerDirStructure = async (ctx) => {
165
203
  const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), "utf-8"));
166
204
  const expectedBuildIDPath = join(ctx.serverHandlerDir, runConfig.distDir, "BUILD_ID");
167
205
  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
206
  ctx.failBuild(
203
- `Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".${additionalGuidance}`
207
+ `Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".`
204
208
  );
205
209
  }
206
210
  };