@netlify/plugin-nextjs 5.9.1 → 5.9.3-background-debug-logs.0

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,14 +7,14 @@
7
7
  import {
8
8
  copyFetchContent,
9
9
  copyPrerenderedContent
10
- } from "../../esm-chunks/chunk-BVYZSEV6.js";
11
- import "../../esm-chunks/chunk-TYCYFZ22.js";
10
+ } from "../../esm-chunks/chunk-J4D25YDX.js";
12
11
  import "../../esm-chunks/chunk-5QSXBV7L.js";
13
12
  import "../../esm-chunks/chunk-GNGHTHMQ.js";
14
13
  import "../../esm-chunks/chunk-ZSVHJNNY.js";
15
14
  import "../../esm-chunks/chunk-KGYJQ2U2.js";
16
15
  import "../../esm-chunks/chunk-ZENB67PD.js";
17
16
  import "../../esm-chunks/chunk-APO262HE.js";
17
+ import "../../esm-chunks/chunk-TYCYFZ22.js";
18
18
  import "../../esm-chunks/chunk-OEQOKJGE.js";
19
19
  export {
20
20
  copyFetchContent,
@@ -10,14 +10,14 @@ import {
10
10
  copyStaticExport,
11
11
  publishStaticDir,
12
12
  unpublishStaticDir
13
- } from "../../esm-chunks/chunk-HWMLYAVP.js";
14
- import "../../esm-chunks/chunk-TYCYFZ22.js";
13
+ } from "../../esm-chunks/chunk-NTLBFRPA.js";
15
14
  import "../../esm-chunks/chunk-5QSXBV7L.js";
16
15
  import "../../esm-chunks/chunk-GNGHTHMQ.js";
17
16
  import "../../esm-chunks/chunk-ZSVHJNNY.js";
18
17
  import "../../esm-chunks/chunk-KGYJQ2U2.js";
19
18
  import "../../esm-chunks/chunk-ZENB67PD.js";
20
19
  import "../../esm-chunks/chunk-APO262HE.js";
20
+ import "../../esm-chunks/chunk-TYCYFZ22.js";
21
21
  import "../../esm-chunks/chunk-OEQOKJGE.js";
22
22
  export {
23
23
  copyStaticAssets,
@@ -19,7 +19,7 @@ var nextResponseProxy = (res, requestContext) => {
19
19
  requestContext.didPagesRouterOnDemandRevalidate = true;
20
20
  const result = originalValue.apply(target, args);
21
21
  if (result && isPromise(result)) {
22
- requestContext.trackBackgroundWork(result);
22
+ requestContext.trackBackgroundWork(result, "res.revalidate");
23
23
  }
24
24
  return result;
25
25
  };
@@ -0,0 +1,156 @@
1
+
2
+ var require = await (async () => {
3
+ var { createRequire } = await import("node:module");
4
+ return createRequire(import.meta.url);
5
+ })();
6
+
7
+
8
+ // src/run/handlers/request-context.cts
9
+ import { AsyncLocalStorage } from "node:async_hooks";
10
+
11
+ // node_modules/@netlify/functions/dist/chunk-C6P2IO65.mjs
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __esm = (fn, res) => function __init() {
14
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
15
+ };
16
+
17
+ // node_modules/@netlify/functions/dist/chunk-ATZ7N7EG.mjs
18
+ import { env } from "process";
19
+ var systemLogTag;
20
+ var serializeError;
21
+ var LogLevel;
22
+ var SystemLogger;
23
+ var systemLogger;
24
+ var init_system_logger = __esm({
25
+ "src/lib/system_logger.ts"() {
26
+ systemLogTag = "__nfSystemLog";
27
+ serializeError = (error) => {
28
+ const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
29
+ return {
30
+ error: error.message,
31
+ error_cause: cause,
32
+ error_stack: error.stack
33
+ };
34
+ };
35
+ LogLevel = /* @__PURE__ */ ((LogLevel2) => {
36
+ LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
37
+ LogLevel2[LogLevel2["Log"] = 2] = "Log";
38
+ LogLevel2[LogLevel2["Error"] = 3] = "Error";
39
+ return LogLevel2;
40
+ })(LogLevel || {});
41
+ SystemLogger = class _SystemLogger {
42
+ fields;
43
+ logLevel;
44
+ constructor(fields = {}, logLevel = 2) {
45
+ this.fields = fields;
46
+ this.logLevel = logLevel;
47
+ }
48
+ doLog(logger, message) {
49
+ if (env.NETLIFY_DEV && !env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
50
+ return;
51
+ }
52
+ logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
53
+ }
54
+ log(message) {
55
+ if (this.logLevel > 2) {
56
+ return;
57
+ }
58
+ this.doLog(console.log, message);
59
+ }
60
+ debug(message) {
61
+ if (this.logLevel > 1) {
62
+ return;
63
+ }
64
+ this.doLog(console.debug, message);
65
+ }
66
+ error(message) {
67
+ if (this.logLevel > 3) {
68
+ return;
69
+ }
70
+ this.doLog(console.error, message);
71
+ }
72
+ withLogLevel(level) {
73
+ return new _SystemLogger(this.fields, level);
74
+ }
75
+ withFields(fields) {
76
+ return new _SystemLogger(
77
+ {
78
+ ...this.fields,
79
+ ...fields
80
+ },
81
+ this.logLevel
82
+ );
83
+ }
84
+ withError(error) {
85
+ const fields = error instanceof Error ? serializeError(error) : { error };
86
+ return this.withFields(fields);
87
+ }
88
+ };
89
+ systemLogger = new SystemLogger();
90
+ }
91
+ });
92
+
93
+ // node_modules/@netlify/functions/dist/chunk-7ANA32NV.mjs
94
+ var init_internal = __esm({
95
+ "src/internal.ts"() {
96
+ init_system_logger();
97
+ }
98
+ });
99
+
100
+ // node_modules/@netlify/functions/dist/internal.mjs
101
+ init_internal();
102
+
103
+ // src/run/handlers/request-context.cts
104
+ function createRequestContext(request, context) {
105
+ const backgroundWorkPromises = [];
106
+ let backgroundWorkCounter = 0;
107
+ return {
108
+ captureServerTiming: request?.headers.has("x-next-debug-logging") ?? false,
109
+ trackBackgroundWork: (promise, description) => {
110
+ backgroundWorkCounter += 1;
111
+ const counter = backgroundWorkCounter;
112
+ const label = `background #${counter} - ${description ?? "unknown"} - ${context?.requestId}`;
113
+ const start = Date.now();
114
+ console.log(`Start ${label}`);
115
+ const trackedPromise = promise.finally(() => {
116
+ console.log(`End ${label} - ${(Date.now() - start) / 1e3}s`);
117
+ });
118
+ if (context?.waitUntil) {
119
+ context.waitUntil(trackedPromise);
120
+ } else {
121
+ backgroundWorkPromises.push(trackedPromise);
122
+ }
123
+ },
124
+ get backgroundWorkPromise() {
125
+ return Promise.allSettled(backgroundWorkPromises);
126
+ },
127
+ logger: systemLogger.withLogLevel(
128
+ request?.headers.has("x-nf-debug-logging") || request?.headers.has("x-next-debug-logging") ? LogLevel.Debug : LogLevel.Log
129
+ )
130
+ };
131
+ }
132
+ var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
133
+ var requestContextAsyncLocalStorage;
134
+ function getRequestContextAsyncLocalStorage() {
135
+ if (requestContextAsyncLocalStorage) {
136
+ return requestContextAsyncLocalStorage;
137
+ }
138
+ const extendedGlobalThis = globalThis;
139
+ if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
140
+ return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
141
+ }
142
+ const storage = new AsyncLocalStorage();
143
+ requestContextAsyncLocalStorage = storage;
144
+ extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
145
+ return storage;
146
+ }
147
+ var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
148
+ function getLogger() {
149
+ return getRequestContext()?.logger ?? systemLogger;
150
+ }
151
+
152
+ export {
153
+ createRequestContext,
154
+ getRequestContext,
155
+ getLogger
156
+ };
@@ -6,7 +6,7 @@
6
6
 
7
7
  import {
8
8
  getRequestContext
9
- } from "./chunk-NDSDIXRD.js";
9
+ } from "./chunk-FB56KFLR.js";
10
10
  import {
11
11
  wrapTracer
12
12
  } from "./chunk-5QSXBV7L.js";
@@ -6,10 +6,10 @@
6
6
 
7
7
  import {
8
8
  getTracer
9
- } from "./chunk-KBX7SJLC.js";
9
+ } from "./chunk-PG4KVN6X.js";
10
10
  import {
11
11
  getRequestContext
12
- } from "./chunk-NDSDIXRD.js";
12
+ } from "./chunk-FB56KFLR.js";
13
13
  import {
14
14
  getRegionalBlobStore
15
15
  } from "./chunk-K4RDUZYO.js";
@@ -478,7 +478,6 @@ var import_fs_monkey = __toESM(require_lib());
478
478
  import fs from "fs/promises";
479
479
  import { relative, resolve } from "path";
480
480
  process.env.NODE_ENV = "production";
481
- console.time("import next server");
482
481
  var { getRequestHandlers } = __require("next/dist/server/lib/start-server.js");
483
482
  var ResponseCache = __require("next/dist/server/response-cache/index.js").default;
484
483
  var originalGet = ResponseCache.prototype.get;
@@ -491,7 +490,10 @@ ResponseCache.prototype.get = function get(...getArgs) {
491
490
  const workPromise = fn(...workFnArgs);
492
491
  const requestContext = getRequestContext();
493
492
  if (requestContext && workPromise instanceof Promise) {
494
- requestContext.trackBackgroundWork(workPromise);
493
+ requestContext.trackBackgroundWork(
494
+ workPromise,
495
+ `responseCache batcher ${JSON.stringify(key)}`
496
+ );
495
497
  }
496
498
  return await workPromise;
497
499
  };
@@ -506,7 +508,10 @@ ResponseCache.prototype.get = function get(...getArgs) {
506
508
  const workPromise = new Promise((_resolve) => {
507
509
  backgroundWork.set(key, _resolve);
508
510
  });
509
- requestContext.trackBackgroundWork(workPromise);
511
+ requestContext.trackBackgroundWork(
512
+ workPromise,
513
+ `responseCache pendingResponses ${JSON.stringify(key)}`
514
+ );
510
515
  }
511
516
  return originalPendingResponsesSet.call(this.pendingResponses, key, value);
512
517
  };
@@ -523,7 +528,6 @@ ResponseCache.prototype.get = function get(...getArgs) {
523
528
  }
524
529
  return originalGet.apply(this, getArgs);
525
530
  };
526
- console.timeEnd("import next server");
527
531
  async function getMockedRequestHandler(...args) {
528
532
  const tracer = getTracer();
529
533
  return tracer.withActiveSpan("mocked request handler", async () => {
@@ -8,7 +8,7 @@ import "./chunk-OEQOKJGE.js";
8
8
 
9
9
  // package.json
10
10
  var name = "@netlify/plugin-nextjs";
11
- var version = "5.9.1";
11
+ var version = "5.9.3-background-debug-logs.0";
12
12
  var description = "Run Next.js seamlessly on Netlify";
13
13
  var main = "./dist/index.js";
14
14
  var type = "module";
@@ -62,7 +62,7 @@ var devDependencies = {
62
62
  "@netlify/edge-bundler": "^12.2.3",
63
63
  "@netlify/edge-functions": "^2.11.0",
64
64
  "@netlify/eslint-config-node": "^7.0.1",
65
- "@netlify/functions": "^2.8.2",
65
+ "@netlify/functions": "^3.0.0",
66
66
  "@netlify/serverless-functions-api": "^1.30.1",
67
67
  "@netlify/zip-it-and-ship-it": "^9.41.0",
68
68
  "@opentelemetry/api": "^1.8.0",
package/dist/index.js CHANGED
@@ -6,15 +6,14 @@
6
6
 
7
7
  import {
8
8
  copyPrerenderedContent
9
- } from "./esm-chunks/chunk-BVYZSEV6.js";
9
+ } from "./esm-chunks/chunk-J4D25YDX.js";
10
10
  import {
11
11
  copyStaticAssets,
12
12
  copyStaticContent,
13
13
  copyStaticExport,
14
14
  publishStaticDir,
15
15
  unpublishStaticDir
16
- } from "./esm-chunks/chunk-HWMLYAVP.js";
17
- import "./esm-chunks/chunk-TYCYFZ22.js";
16
+ } from "./esm-chunks/chunk-NTLBFRPA.js";
18
17
  import {
19
18
  clearStaleEdgeHandlers,
20
19
  createEdgeHandlers
@@ -49,6 +48,7 @@ import {
49
48
  import "./esm-chunks/chunk-KGYJQ2U2.js";
50
49
  import "./esm-chunks/chunk-ZENB67PD.js";
51
50
  import "./esm-chunks/chunk-APO262HE.js";
51
+ import "./esm-chunks/chunk-TYCYFZ22.js";
52
52
  import "./esm-chunks/chunk-UYKENJEU.js";
53
53
  import "./esm-chunks/chunk-OEQOKJGE.js";
54
54