@netlify/plugin-nextjs 5.0.0-rc.2 → 5.0.0-rc.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.
@@ -7,21 +7,22 @@
7
7
  import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
+ verifyHandlerDirStructure,
10
11
  writeTagsManifest
11
- } from "./chunk-52WMBYKL.js";
12
+ } from "./chunk-BKDCZVBK.js";
12
13
  import {
13
14
  require_out
14
15
  } from "./chunk-VZNKO4OO.js";
15
16
  import {
16
17
  SERVER_HANDLER_NAME
17
- } from "./chunk-655Y7ISI.js";
18
+ } from "./chunk-3NYX5FXN.js";
18
19
  import {
19
20
  __toESM
20
21
  } from "./chunk-5JVNISGM.js";
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 { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises";
25
26
  import { join, relative } from "node:path";
26
27
  import { join as posixJoin } from "node:path/posix";
27
28
  var copyHandlerDependencies = async (ctx) => {
@@ -39,7 +40,7 @@ var copyHandlerDependencies = async (ctx) => {
39
40
  // The distDir must not be the package path therefore we need to rely on the
40
41
  // serverHandlerDir instead of the serverHandlerRootDir
41
42
  // therefore we need to remove the package path from the filePath
42
- join(ctx.serverHandlerDir, relative(ctx.packagePath, filePath)),
43
+ join(ctx.serverHandlerDir, relative(ctx.relativeAppDir, filePath)),
43
44
  {
44
45
  recursive: true,
45
46
  force: true
@@ -84,7 +85,7 @@ var writePackageMetadata = async (ctx) => {
84
85
  };
85
86
  var getHandlerFile = async (ctx) => {
86
87
  const templatesDir = join(ctx.pluginDir, "dist/build/templates");
87
- if (ctx.packagePath.length !== 0) {
88
+ if (ctx.relativeAppDir.length !== 0) {
88
89
  const template = await readFile(join(templatesDir, "handler-monorepo.tmpl.js"), "utf-8");
89
90
  return template.replaceAll("{{cwd}}", posixJoin(ctx.lambdaWorkingDirectory)).replace("{{nextServerHandler}}", posixJoin(ctx.nextServerHandler));
90
91
  }
@@ -106,6 +107,7 @@ var createServerHandler = async (ctx) => {
106
107
  writePackageMetadata(ctx),
107
108
  writeHandlerFile(ctx)
108
109
  ]);
110
+ await verifyHandlerDirStructure(ctx);
109
111
  };
110
112
 
111
113
  export {
@@ -7,6 +7,9 @@
7
7
  import {
8
8
  require_out
9
9
  } from "./chunk-VZNKO4OO.js";
10
+ import {
11
+ verifyNextVersion
12
+ } from "./chunk-7CY6B4WT.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 } 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 {
@@ -161,9 +199,19 @@ var replaceMiddlewareManifest = async (sourcePath, destPath) => {
161
199
  const newData = JSON.stringify(newManifest);
162
200
  await writeFile(destPath, newData);
163
201
  };
202
+ var verifyHandlerDirStructure = async (ctx) => {
203
+ const runConfig = JSON.parse(await readFile(join(ctx.serverHandlerDir, RUN_CONFIG), "utf-8"));
204
+ const expectedBuildIDPath = join(ctx.serverHandlerDir, runConfig.distDir, "BUILD_ID");
205
+ if (!existsSync(expectedBuildIDPath)) {
206
+ ctx.failBuild(
207
+ `Failed creating server handler. BUILD_ID file not found at expected location "${expectedBuildIDPath}".`
208
+ );
209
+ }
210
+ };
164
211
 
165
212
  export {
166
213
  copyNextServerCode,
167
214
  copyNextDependencies,
168
- writeTagsManifest
215
+ writeTagsManifest,
216
+ verifyHandlerDirStructure
169
217
  };