@netlify/plugin-nextjs 5.0.0-rc.6 → 5.0.0-rc.8

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/run/next.cjs CHANGED
@@ -1121,6 +1121,9 @@ var getDeployStore = (options = {}) => {
1121
1121
  var import_fs_monkey = __toESM(require_lib());
1122
1122
  var import_request_context = require("./handlers/request-context.cjs");
1123
1123
  var import_tracer = require("./handlers/tracer.cjs");
1124
+ console.time("import next server");
1125
+ var { getRequestHandlers } = require("next/dist/server/lib/start-server.js");
1126
+ console.timeEnd("import next server");
1124
1127
  var fetchBeforeNextPatchedIt = globalThis.fetch;
1125
1128
  async function getMockedRequestHandlers(...args) {
1126
1129
  const tracer = (0, import_tracer.getTracer)();
@@ -1154,10 +1157,6 @@ async function getMockedRequestHandlers(...args) {
1154
1157
  // eslint-disable-next-line n/global-require, @typescript-eslint/no-var-requires
1155
1158
  require("fs").promises
1156
1159
  );
1157
- const { getRequestHandlers } = await tracer.withActiveSpan(
1158
- "import next server",
1159
- async () => import("next/dist/server/lib/start-server.js")
1160
- );
1161
1160
  return getRequestHandlers(...args);
1162
1161
  });
1163
1162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.0.0-rc.6",
3
+ "version": "5.0.0-rc.8",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -1,217 +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_out
9
- } from "./chunk-VZNKO4OO.js";
10
- import {
11
- verifyNextVersion
12
- } from "./chunk-MGPEWDDD.js";
13
- import {
14
- RUN_CONFIG
15
- } from "./chunk-UYKENJEU.js";
16
- import {
17
- __toESM
18
- } from "./chunk-5JVNISGM.js";
19
-
20
- // src/build/content/server.ts
21
- var import_fast_glob = __toESM(require_out(), 1);
22
- import { existsSync } from "node:fs";
23
- import {
24
- cp,
25
- mkdir,
26
- readFile,
27
- readdir,
28
- readlink,
29
- symlink,
30
- writeFile,
31
- access
32
- } from "node:fs/promises";
33
- import { createRequire } from "node:module";
34
- import { dirname, join, resolve, sep } from "node:path";
35
- import { sep as posixSep, join as posixJoin } from "node:path/posix";
36
- var toPosixPath = (path) => path.split(sep).join(posixSep);
37
- function isError(error) {
38
- return error instanceof Error;
39
- }
40
- var copyNextServerCode = async (ctx) => {
41
- const reqServerFilesPath = join(
42
- ctx.standaloneRootDir,
43
- ctx.relativeAppDir,
44
- ctx.requiredServerFiles.config.distDir,
45
- "required-server-files.json"
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
- }
58
- const reqServerFiles = JSON.parse(await readFile(reqServerFilesPath, "utf-8"));
59
- if (toPosixPath(ctx.distDir).replace(new RegExp(`^${ctx.relativeAppDir}/?`), "") !== reqServerFiles.config.distDir) {
60
- reqServerFiles.config.distDir = ctx.nextDistDir;
61
- await writeFile(reqServerFilesPath, JSON.stringify(reqServerFiles));
62
- }
63
- await mkdir(ctx.serverHandlerDir, { recursive: true });
64
- await writeFile(
65
- join(ctx.serverHandlerDir, RUN_CONFIG),
66
- JSON.stringify(reqServerFiles.config),
67
- "utf-8"
68
- );
69
- const srcDir = join(ctx.standaloneDir, ctx.nextDistDir);
70
- const nextFolder = toPosixPath(ctx.distDir) === toPosixPath(ctx.buildConfig.distDir) ? ctx.distDir : ctx.nextDistDir;
71
- const destDir = join(ctx.serverHandlerDir, nextFolder);
72
- const paths = await (0, import_fast_glob.default)(
73
- [`*`, `server/*`, `server/chunks/*`, `server/edge-chunks/*`, `server/+(app|pages)/**/*.js`],
74
- {
75
- cwd: srcDir,
76
- extglob: true
77
- }
78
- );
79
- await Promise.all(
80
- paths.map(async (path) => {
81
- const srcPath = join(srcDir, path);
82
- const destPath = join(destDir, path);
83
- if (path === "server/middleware-manifest.json") {
84
- try {
85
- await replaceMiddlewareManifest(srcPath, destPath);
86
- } catch (error) {
87
- throw new Error("Could not patch middleware manifest file", { cause: error });
88
- }
89
- return;
90
- }
91
- await cp(srcPath, destPath, { recursive: true, force: true });
92
- })
93
- );
94
- };
95
- async function recreateNodeModuleSymlinks(src, dest, org) {
96
- const dirents = await readdir(join(src, org || ""), { withFileTypes: true });
97
- await Promise.all(
98
- dirents.map(async (dirent) => {
99
- if (dirent.name.startsWith("@")) {
100
- return recreateNodeModuleSymlinks(src, dest, dirent.name);
101
- }
102
- if (dirent.isSymbolicLink()) {
103
- const symlinkSrc = join(dest, org || "", dirent.name);
104
- const symlinkTarget = await readlink(join(src, org || "", dirent.name));
105
- const symlinkDest = join(dest, org || "", symlinkTarget);
106
- if (existsSync(symlinkDest) && !existsSync(symlinkSrc)) {
107
- if (org) {
108
- await mkdir(join(dest, org), { recursive: true });
109
- }
110
- await symlink(symlinkTarget, symlinkSrc);
111
- }
112
- }
113
- })
114
- );
115
- }
116
- var copyNextDependencies = async (ctx) => {
117
- const entries = await readdir(ctx.standaloneDir);
118
- const promises = entries.map(async (entry) => {
119
- if (entry === "package.json" || entry === ctx.nextDistDir) {
120
- return;
121
- }
122
- const src = join(ctx.standaloneDir, entry);
123
- const dest = join(ctx.serverHandlerDir, entry);
124
- await cp(src, dest, { recursive: true, verbatimSymlinks: true, force: true });
125
- if (entry === "node_modules") {
126
- await recreateNodeModuleSymlinks(ctx.resolveFromSiteDir("node_modules"), dest);
127
- }
128
- });
129
- const rootSrcDir = join(ctx.standaloneRootDir, "node_modules");
130
- const rootDestDir = join(ctx.serverHandlerRootDir, "node_modules");
131
- if (existsSync(rootSrcDir) && ctx.standaloneRootDir !== ctx.standaloneDir) {
132
- promises.push(
133
- cp(rootSrcDir, rootDestDir, { recursive: true, verbatimSymlinks: true }).then(
134
- () => recreateNodeModuleSymlinks(resolve("node_modules"), rootDestDir)
135
- )
136
- );
137
- }
138
- await Promise.all(promises);
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
- }
151
- try {
152
- const nextEntryAbsolutePath = serverHandlerRequire.resolve("next");
153
- const nextRequire = createRequire(nextEntryAbsolutePath);
154
- nextRequire.resolve("styled-jsx");
155
- } catch {
156
- throw new Error(
157
- "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
- );
159
- }
160
- };
161
- var writeTagsManifest = async (ctx) => {
162
- const manifest = await ctx.getPrerenderManifest();
163
- const routes = Object.entries(manifest.routes).map(async ([route, definition]) => {
164
- let tags;
165
- if (definition.dataRoute?.endsWith(".rsc")) {
166
- const path = join(ctx.publishDir, `server/app/${route === "/" ? "/index" : route}.meta`);
167
- try {
168
- const file = await readFile(path, "utf-8");
169
- const meta = JSON.parse(file);
170
- tags = meta.headers["x-next-cache-tags"];
171
- } catch {
172
- if (!definition.dataRoute?.endsWith("/default.rsc")) {
173
- console.log(`Unable to read cache tags for: ${path}`);
174
- }
175
- }
176
- }
177
- if (definition.dataRoute?.endsWith(".json")) {
178
- tags = `_N_T_${route}`;
179
- }
180
- if (definition.dataRoute === null) {
181
- tags = definition.initialHeaders?.["x-next-cache-tags"];
182
- }
183
- return [route, tags];
184
- });
185
- await writeFile(
186
- join(ctx.serverHandlerDir, ".netlify/tags-manifest.json"),
187
- JSON.stringify(Object.fromEntries(await Promise.all(routes))),
188
- "utf-8"
189
- );
190
- };
191
- var replaceMiddlewareManifest = async (sourcePath, destPath) => {
192
- await mkdir(dirname(destPath), { recursive: true });
193
- const data = await readFile(sourcePath, "utf8");
194
- const manifest = JSON.parse(data);
195
- const newManifest = {
196
- ...manifest,
197
- middleware: {}
198
- };
199
- const newData = JSON.stringify(newManifest);
200
- await writeFile(destPath, newData);
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
- };
211
-
212
- export {
213
- copyNextServerCode,
214
- copyNextDependencies,
215
- writeTagsManifest,
216
- verifyHandlerDirStructure
217
- };
@@ -1,94 +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_out
9
- } from "./chunk-VZNKO4OO.js";
10
- import {
11
- encodeBlobKey
12
- } from "./chunk-TYCYFZ22.js";
13
- import {
14
- __toESM
15
- } from "./chunk-5JVNISGM.js";
16
-
17
- // src/build/content/static.ts
18
- var import_fast_glob = __toESM(require_out(), 1);
19
- import { existsSync } from "node:fs";
20
- import { cp, mkdir, rename, rm } from "node:fs/promises";
21
- import { basename, join } from "node:path";
22
- var copyStaticContent = async (ctx) => {
23
- const srcDir = join(ctx.publishDir, "server/pages");
24
- const destDir = ctx.blobDir;
25
- const paths = await (0, import_fast_glob.default)("**/*.+(html|json)", {
26
- cwd: srcDir,
27
- extglob: true
28
- });
29
- try {
30
- await Promise.all(
31
- paths.filter((path) => !paths.includes(`${path.slice(0, -5)}.json`)).map(async (path) => {
32
- await cp(join(srcDir, path), join(destDir, await encodeBlobKey(path)), {
33
- recursive: true,
34
- force: true
35
- });
36
- })
37
- );
38
- } catch (error) {
39
- ctx.failBuild("Failed assembling static pages for upload", error);
40
- }
41
- };
42
- var copyStaticAssets = async (ctx) => {
43
- try {
44
- await rm(ctx.staticDir, { recursive: true, force: true });
45
- const { basePath } = await ctx.getRoutesManifest();
46
- if (existsSync(ctx.resolveFromSiteDir("public"))) {
47
- await cp(ctx.resolveFromSiteDir("public"), join(ctx.staticDir, basePath), {
48
- recursive: true
49
- });
50
- }
51
- if (existsSync(join(ctx.publishDir, "static"))) {
52
- await cp(join(ctx.publishDir, "static"), join(ctx.staticDir, basePath, "_next/static"), {
53
- recursive: true
54
- });
55
- }
56
- } catch (error) {
57
- ctx.failBuild("Failed copying static assets", error);
58
- }
59
- };
60
- var copyStaticExport = async (ctx) => {
61
- try {
62
- await rm(ctx.staticDir, { recursive: true, force: true });
63
- await cp(ctx.resolveFromSiteDir("out"), ctx.staticDir, { recursive: true });
64
- } catch (error) {
65
- ctx.failBuild("Failed copying static export", error);
66
- }
67
- };
68
- var publishStaticDir = async (ctx) => {
69
- try {
70
- await rm(ctx.tempPublishDir, { recursive: true, force: true });
71
- await mkdir(basename(ctx.tempPublishDir), { recursive: true });
72
- await rename(ctx.publishDir, ctx.tempPublishDir);
73
- await rename(ctx.staticDir, ctx.publishDir);
74
- } catch (error) {
75
- ctx.failBuild("Failed publishing static content", error instanceof Error ? { error } : {});
76
- }
77
- };
78
- var unpublishStaticDir = async (ctx) => {
79
- try {
80
- if (existsSync(ctx.tempPublishDir)) {
81
- await rename(ctx.publishDir, ctx.staticDir);
82
- await rename(ctx.tempPublishDir, ctx.publishDir);
83
- }
84
- } catch {
85
- }
86
- };
87
-
88
- export {
89
- copyStaticContent,
90
- copyStaticAssets,
91
- copyStaticExport,
92
- publishStaticDir,
93
- unpublishStaticDir
94
- };