@netlify/plugin-nextjs 5.12.1 → 5.13.1

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.
@@ -169,7 +169,7 @@ var __spreadArray = function(to, from, pack) {
169
169
  };
170
170
  var DiagComponentLogger = (
171
171
  /** @class */
172
- function() {
172
+ (function() {
173
173
  function DiagComponentLogger2(props) {
174
174
  this._namespace = props.namespace || "DiagComponentLogger";
175
175
  }
@@ -209,7 +209,7 @@ var DiagComponentLogger = (
209
209
  return logProxy("verbose", this._namespace, args);
210
210
  };
211
211
  return DiagComponentLogger2;
212
- }()
212
+ })()
213
213
  );
214
214
  function logProxy(funcName, namespace, args) {
215
215
  var logger = getGlobal("diag");
@@ -287,7 +287,7 @@ var __spreadArray2 = function(to, from, pack) {
287
287
  var API_NAME = "diag";
288
288
  var DiagAPI = (
289
289
  /** @class */
290
- function() {
290
+ (function() {
291
291
  function DiagAPI2() {
292
292
  function _logProxy(funcName) {
293
293
  return function() {
@@ -346,7 +346,7 @@ var DiagAPI = (
346
346
  return this._instance;
347
347
  };
348
348
  return DiagAPI2;
349
- }()
349
+ })()
350
350
  );
351
351
 
352
352
  // node_modules/@opentelemetry/api/build/esm/context/context.js
@@ -355,7 +355,7 @@ function createContextKey(description) {
355
355
  }
356
356
  var BaseContext = (
357
357
  /** @class */
358
- /* @__PURE__ */ function() {
358
+ /* @__PURE__ */ (function() {
359
359
  function BaseContext2(parentContext) {
360
360
  var self = this;
361
361
  self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
@@ -374,7 +374,7 @@ var BaseContext = (
374
374
  };
375
375
  }
376
376
  return BaseContext2;
377
- }()
377
+ })()
378
378
  );
379
379
  var ROOT_CONTEXT = new BaseContext();
380
380
 
@@ -407,7 +407,7 @@ var __spreadArray3 = function(to, from, pack) {
407
407
  };
408
408
  var NoopContextManager = (
409
409
  /** @class */
410
- function() {
410
+ (function() {
411
411
  function NoopContextManager2() {
412
412
  }
413
413
  NoopContextManager2.prototype.active = function() {
@@ -430,7 +430,7 @@ var NoopContextManager = (
430
430
  return this;
431
431
  };
432
432
  return NoopContextManager2;
433
- }()
433
+ })()
434
434
  );
435
435
 
436
436
  // node_modules/@opentelemetry/api/build/esm/api/context.js
@@ -464,7 +464,7 @@ var API_NAME2 = "context";
464
464
  var NOOP_CONTEXT_MANAGER = new NoopContextManager();
465
465
  var ContextAPI = (
466
466
  /** @class */
467
- function() {
467
+ (function() {
468
468
  function ContextAPI2() {
469
469
  }
470
470
  ContextAPI2.getInstance = function() {
@@ -498,7 +498,7 @@ var ContextAPI = (
498
498
  unregisterGlobal(API_NAME2, DiagAPI.instance());
499
499
  };
500
500
  return ContextAPI2;
501
- }()
501
+ })()
502
502
  );
503
503
 
504
504
  // node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js
@@ -520,7 +520,7 @@ var INVALID_SPAN_CONTEXT = {
520
520
  // node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js
521
521
  var NonRecordingSpan = (
522
522
  /** @class */
523
- function() {
523
+ (function() {
524
524
  function NonRecordingSpan2(_spanContext) {
525
525
  if (_spanContext === void 0) {
526
526
  _spanContext = INVALID_SPAN_CONTEXT;
@@ -553,7 +553,7 @@ var NonRecordingSpan = (
553
553
  NonRecordingSpan2.prototype.recordException = function(_exception, _time) {
554
554
  };
555
555
  return NonRecordingSpan2;
556
- }()
556
+ })()
557
557
  );
558
558
 
559
559
  // node_modules/@opentelemetry/api/build/esm/trace/context-utils.js
@@ -598,7 +598,7 @@ function wrapSpanContext(spanContext) {
598
598
  var contextApi = ContextAPI.getInstance();
599
599
  var NoopTracer = (
600
600
  /** @class */
601
- function() {
601
+ (function() {
602
602
  function NoopTracer2() {
603
603
  }
604
604
  NoopTracer2.prototype.startSpan = function(name, options, context2) {
@@ -638,7 +638,7 @@ var NoopTracer = (
638
638
  return contextApi.with(contextWithSpanSet, fn, void 0, span);
639
639
  };
640
640
  return NoopTracer2;
641
- }()
641
+ })()
642
642
  );
643
643
  function isSpanContext(spanContext) {
644
644
  return typeof spanContext === "object" && typeof spanContext["spanId"] === "string" && typeof spanContext["traceId"] === "string" && typeof spanContext["traceFlags"] === "number";
@@ -648,7 +648,7 @@ function isSpanContext(spanContext) {
648
648
  var NOOP_TRACER = new NoopTracer();
649
649
  var ProxyTracer = (
650
650
  /** @class */
651
- function() {
651
+ (function() {
652
652
  function ProxyTracer2(_provider, name, version, options) {
653
653
  this._provider = _provider;
654
654
  this.name = name;
@@ -674,27 +674,27 @@ var ProxyTracer = (
674
674
  return this._delegate;
675
675
  };
676
676
  return ProxyTracer2;
677
- }()
677
+ })()
678
678
  );
679
679
 
680
680
  // node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js
681
681
  var NoopTracerProvider = (
682
682
  /** @class */
683
- function() {
683
+ (function() {
684
684
  function NoopTracerProvider2() {
685
685
  }
686
686
  NoopTracerProvider2.prototype.getTracer = function(_name, _version, _options) {
687
687
  return new NoopTracer();
688
688
  };
689
689
  return NoopTracerProvider2;
690
- }()
690
+ })()
691
691
  );
692
692
 
693
693
  // node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js
694
694
  var NOOP_TRACER_PROVIDER = new NoopTracerProvider();
695
695
  var ProxyTracerProvider = (
696
696
  /** @class */
697
- function() {
697
+ (function() {
698
698
  function ProxyTracerProvider2() {
699
699
  }
700
700
  ProxyTracerProvider2.prototype.getTracer = function(name, version, options) {
@@ -713,7 +713,7 @@ var ProxyTracerProvider = (
713
713
  return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
714
714
  };
715
715
  return ProxyTracerProvider2;
716
- }()
716
+ })()
717
717
  );
718
718
 
719
719
  // node_modules/@opentelemetry/api/build/esm/trace/status.js
@@ -731,7 +731,7 @@ var context = ContextAPI.getInstance();
731
731
  var API_NAME3 = "trace";
732
732
  var TraceAPI = (
733
733
  /** @class */
734
- function() {
734
+ (function() {
735
735
  function TraceAPI2() {
736
736
  this._proxyTracerProvider = new ProxyTracerProvider();
737
737
  this.wrapSpanContext = wrapSpanContext;
@@ -767,7 +767,7 @@ var TraceAPI = (
767
767
  this._proxyTracerProvider = new ProxyTracerProvider();
768
768
  };
769
769
  return TraceAPI2;
770
- }()
770
+ })()
771
771
  );
772
772
 
773
773
  // node_modules/@opentelemetry/api/build/esm/trace-api.js
@@ -785,7 +785,7 @@ function wrapTracer(tracer2) {
785
785
  }
786
786
  var SugaredTracer = (
787
787
  /** @class */
788
- function() {
788
+ (function() {
789
789
  function SugaredTracer2(tracer2) {
790
790
  this._tracer = tracer2;
791
791
  this.startSpan = tracer2.startSpan.bind(this._tracer);
@@ -803,7 +803,7 @@ var SugaredTracer = (
803
803
  return handleFn(span, opts, fn);
804
804
  };
805
805
  return SugaredTracer2;
806
- }()
806
+ })()
807
807
  );
808
808
  function massageParams(arg, arg2, arg3) {
809
809
  var opts;
package/dist/run/next.cjs CHANGED
@@ -540,7 +540,7 @@ ResponseCache.prototype.get = function get(...getArgs) {
540
540
  }
541
541
  return originalGet.apply(this, getArgs);
542
542
  };
543
- async function getMockedRequestHandler(...args) {
543
+ async function getMockedRequestHandler(nextConfig, ...args) {
544
544
  const initContext = { initializingServer: true };
545
545
  const initAsyncLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
546
546
  const tracer = (0, import_tracer.getTracer)();
@@ -553,7 +553,7 @@ async function getMockedRequestHandler(...args) {
553
553
  } catch (error) {
554
554
  if (typeof path === "string" && path.endsWith(".html")) {
555
555
  const cacheStore = (0, import_storage.getMemoizedKeyValueStoreBackedByRegionalBlobStore)();
556
- const relPath = (0, import_node_path.relative)((0, import_node_path.resolve)(".next/server/pages"), path);
556
+ const relPath = (0, import_node_path.relative)((0, import_node_path.resolve)(nextConfig.distDir, "server/pages"), path);
557
557
  const file = await cacheStore.get(relPath, "staticHtml.get");
558
558
  if (file !== null) {
559
559
  if (file.isFullyStaticPage) {
@@ -0,0 +1,330 @@
1
+ import { Module, createRequire } from 'node:module'
2
+ import vm from 'node:vm'
3
+ import { sep } from 'node:path'
4
+ import { join, dirname, sep as posixSep } from 'node:path/posix'
5
+ import { fileURLToPath, pathToFileURL } from 'node:url'
6
+
7
+ const toPosixPath = (path: string) => path.split(sep).join(posixSep)
8
+
9
+ type RegisteredModule = {
10
+ source: string
11
+ loaded: boolean
12
+ filepath: string
13
+ // lazily parsed json string
14
+ parsedJson?: any
15
+ }
16
+ type ModuleResolutions = (subpath: string) => string
17
+ const registeredModules = new Map<string, RegisteredModule>()
18
+ const memoizedPackageResolvers = new WeakMap<RegisteredModule, ModuleResolutions>()
19
+
20
+ const require = createRequire(import.meta.url)
21
+
22
+ let hookedIn = false
23
+
24
+ function parseJson(matchedModule: RegisteredModule) {
25
+ if (matchedModule.parsedJson) {
26
+ return matchedModule.parsedJson
27
+ }
28
+
29
+ try {
30
+ const jsonContent = JSON.parse(matchedModule.source)
31
+ matchedModule.parsedJson = jsonContent
32
+ return jsonContent
33
+ } catch (error) {
34
+ throw new Error(`Failed to parse JSON module: ${matchedModule.filepath}`, { cause: error })
35
+ }
36
+ }
37
+
38
+ type Condition = string // 'import', 'require', 'default', 'node-addon' etc
39
+ type SubpathMatcher = string
40
+ type ConditionalTarget = { [key in Condition]: string | ConditionalTarget }
41
+ type SubpathTarget = string | ConditionalTarget
42
+ /**
43
+ * @example
44
+ * {
45
+ * ".": "./main.js",
46
+ * "./foo": {
47
+ * "import": "./foo.js",
48
+ * "require": "./foo.cjs"
49
+ * }
50
+ * }
51
+ */
52
+ type NormalizedExports = Record<SubpathMatcher, SubpathTarget | Record<Condition, SubpathTarget>>
53
+
54
+ // https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L555
55
+ function isConditionalExportsMainSugar(exports: any) {
56
+ if (typeof exports === 'string' || Array.isArray(exports)) {
57
+ return true
58
+ }
59
+ if (typeof exports !== 'object' || exports === null) {
60
+ return false
61
+ }
62
+
63
+ // not doing validation at this point, if the package.json was misconfigured
64
+ // we would not get to this point as it would throw when running `next build`
65
+ const keys = Object.keys(exports)
66
+ return keys.length > 0 && (keys[0] === '' || keys[0][0] !== '.')
67
+ }
68
+
69
+ // https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L671
70
+ function patternKeyCompare(a: string, b: string) {
71
+ const aPatternIndex = a.indexOf('*')
72
+ const bPatternIndex = b.indexOf('*')
73
+ const baseLenA = aPatternIndex === -1 ? a.length : aPatternIndex + 1
74
+ const baseLenB = bPatternIndex === -1 ? b.length : bPatternIndex + 1
75
+ if (baseLenA > baseLenB) {
76
+ return -1
77
+ }
78
+ if (baseLenB > baseLenA) {
79
+ return 1
80
+ }
81
+ if (aPatternIndex === -1) {
82
+ return 1
83
+ }
84
+ if (bPatternIndex === -1) {
85
+ return -1
86
+ }
87
+ if (a.length > b.length) {
88
+ return -1
89
+ }
90
+ if (b.length > a.length) {
91
+ return 1
92
+ }
93
+ return 0
94
+ }
95
+
96
+ function applyWildcardMatch(target: string, bestMatchSubpath?: string) {
97
+ return bestMatchSubpath ? target.replace('*', bestMatchSubpath) : target
98
+ }
99
+
100
+ // https://github.com/nodejs/node/blob/323f19c18fea06b9234a0c945394447b077fe565/lib/internal/modules/helpers.js#L76
101
+ const conditions = new Set(['require', 'node', 'node-addons', 'default'])
102
+
103
+ // https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L480
104
+ function matchConditions(target: SubpathTarget, bestMatchSubpath?: string) {
105
+ if (typeof target === 'string') {
106
+ return applyWildcardMatch(target, bestMatchSubpath)
107
+ }
108
+
109
+ if (Array.isArray(target) && target.length > 0) {
110
+ for (const targetItem of target) {
111
+ return matchConditions(targetItem, bestMatchSubpath)
112
+ }
113
+ }
114
+
115
+ if (typeof target === 'object' && target !== null) {
116
+ for (const [condition, targetValue] of Object.entries(target)) {
117
+ if (conditions.has(condition)) {
118
+ return matchConditions(targetValue, bestMatchSubpath)
119
+ }
120
+ }
121
+ }
122
+
123
+ throw new Error('Invalid package target')
124
+ }
125
+
126
+ function getPackageResolver(packageJsonMatchedModule: RegisteredModule) {
127
+ const memoized = memoizedPackageResolvers.get(packageJsonMatchedModule)
128
+ if (memoized) {
129
+ return memoized
130
+ }
131
+
132
+ // https://nodejs.org/api/packages.html#package-entry-points
133
+
134
+ const pkgJson = parseJson(packageJsonMatchedModule)
135
+
136
+ let exports: NormalizedExports | null = null
137
+ if (pkgJson.exports) {
138
+ // https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L590
139
+ exports = isConditionalExportsMainSugar(pkgJson.exports)
140
+ ? { '.': pkgJson.exports }
141
+ : pkgJson.exports
142
+ }
143
+
144
+ const resolveInPackage: ModuleResolutions = (subpath: string) => {
145
+ if (exports) {
146
+ const normalizedSubpath = subpath.length === 0 ? '.' : './' + subpath
147
+
148
+ // https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L594
149
+ // simple case with matching as-is
150
+ if (
151
+ normalizedSubpath in exports &&
152
+ !normalizedSubpath.includes('*') &&
153
+ !normalizedSubpath.endsWith('/')
154
+ ) {
155
+ return matchConditions(exports[normalizedSubpath])
156
+ }
157
+
158
+ // https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L610
159
+ let bestMatchKey = ''
160
+ let bestMatchSubpath
161
+ for (const key of Object.keys(exports)) {
162
+ const patternIndex = key.indexOf('*')
163
+ if (patternIndex !== -1 && normalizedSubpath.startsWith(key.slice(0, patternIndex))) {
164
+ const patternTrailer = key.slice(patternIndex + 1)
165
+ if (
166
+ normalizedSubpath.length > key.length &&
167
+ normalizedSubpath.endsWith(patternTrailer) &&
168
+ patternKeyCompare(bestMatchKey, key) === 1 &&
169
+ key.lastIndexOf('*') === patternIndex
170
+ ) {
171
+ bestMatchKey = key
172
+ bestMatchSubpath = normalizedSubpath.slice(
173
+ patternIndex,
174
+ normalizedSubpath.length - patternTrailer.length,
175
+ )
176
+ }
177
+ }
178
+ }
179
+
180
+ if (bestMatchKey && typeof bestMatchSubpath === 'string') {
181
+ const matchedTarget = exports[bestMatchKey]
182
+ return matchConditions(matchedTarget, bestMatchSubpath)
183
+ }
184
+
185
+ // if exports are defined, they are source of truth and any imports not allowed by it will fail
186
+ throw new Error(`Cannot find module '${normalizedSubpath}'`)
187
+ }
188
+
189
+ if (subpath.length === 0 && pkgJson.main) {
190
+ return pkgJson.main
191
+ }
192
+
193
+ return subpath
194
+ }
195
+
196
+ memoizedPackageResolvers.set(packageJsonMatchedModule, resolveInPackage)
197
+
198
+ return resolveInPackage
199
+ }
200
+
201
+ function seedCJSModuleCacheAndReturnTarget(matchedModule: RegisteredModule, parent: Module) {
202
+ if (matchedModule.loaded) {
203
+ return matchedModule.filepath
204
+ }
205
+ const { source, filepath } = matchedModule
206
+
207
+ const mod = new Module(filepath)
208
+ mod.parent = parent
209
+ mod.filename = filepath
210
+ mod.path = dirname(filepath)
211
+ // @ts-expect-error - private untyped API
212
+ mod.paths = Module._nodeModulePaths(mod.path)
213
+ require.cache[filepath] = mod
214
+
215
+ try {
216
+ if (filepath.endsWith('.json')) {
217
+ Object.assign(mod.exports, parseJson(matchedModule))
218
+ } else {
219
+ const wrappedSource = `(function (exports, require, module, __filename, __dirname) { ${source}\n});`
220
+ const compiled = vm.runInThisContext(wrappedSource, {
221
+ filename: filepath,
222
+ lineOffset: 0,
223
+ displayErrors: true,
224
+ })
225
+ const modRequire = createRequire(pathToFileURL(filepath, { windows: false }))
226
+ compiled(mod.exports, modRequire, mod, filepath, dirname(filepath))
227
+ }
228
+ mod.loaded = matchedModule.loaded = true
229
+ } catch (error) {
230
+ throw new Error(`Failed to compile CJS module: ${filepath}`, { cause: error })
231
+ }
232
+
233
+ return filepath
234
+ }
235
+
236
+ // ideally require.extensions could be used, but it does NOT include '.cjs', so hardcoding instead
237
+ const exts = ['.js', '.cjs', '.json']
238
+
239
+ function tryWithExtensions(filename: string) {
240
+ let matchedModule = registeredModules.get(filename)
241
+ if (!matchedModule) {
242
+ for (const ext of exts) {
243
+ // require("./test") might resolve to ./test.js
244
+ const targetWithExt = filename + ext
245
+
246
+ matchedModule = registeredModules.get(targetWithExt)
247
+ if (matchedModule) {
248
+ break
249
+ }
250
+ }
251
+ }
252
+
253
+ return matchedModule
254
+ }
255
+
256
+ function tryMatchingWithIndex(target: string) {
257
+ let matchedModule = tryWithExtensions(target)
258
+ if (!matchedModule) {
259
+ // require("./test") might resolve to ./test/index.js
260
+ const indexTarget = join(target, 'index')
261
+ matchedModule = tryWithExtensions(indexTarget)
262
+ }
263
+
264
+ return matchedModule
265
+ }
266
+
267
+ export function registerCJSModules(baseUrl: URL, modules: Map<string, string>) {
268
+ const basePath = dirname(toPosixPath(fileURLToPath(baseUrl, { windows: false })))
269
+
270
+ for (const [filename, source] of modules.entries()) {
271
+ const target = join(basePath, filename)
272
+ registeredModules.set(target, { source, loaded: false, filepath: target })
273
+ }
274
+
275
+ if (!hookedIn) {
276
+ // @ts-expect-error - private untyped API
277
+ const original_resolveFilename = Module._resolveFilename.bind(Module)
278
+ // @ts-expect-error - private untyped API
279
+ Module._resolveFilename = (...args) => {
280
+ let target = args[0]
281
+ let isRelative = args?.[0].startsWith('.')
282
+
283
+ if (isRelative) {
284
+ // only handle relative require paths
285
+ const requireFrom = toPosixPath(args?.[1]?.filename)
286
+
287
+ target = join(dirname(requireFrom), args[0])
288
+ }
289
+
290
+ let matchedModule = tryMatchingWithIndex(target)
291
+
292
+ if (!isRelative && !target.startsWith('/')) {
293
+ const packageName = target.startsWith('@')
294
+ ? target.split('/').slice(0, 2).join('/')
295
+ : target.split('/')[0]
296
+ const moduleInPackagePath = target.slice(packageName.length + 1)
297
+
298
+ for (const nodeModulePathsRaw of args[1].paths) {
299
+ const nodeModulePaths = toPosixPath(nodeModulePathsRaw)
300
+ const potentialPackageJson = join(nodeModulePaths, packageName, 'package.json')
301
+
302
+ const maybePackageJson = registeredModules.get(potentialPackageJson)
303
+
304
+ let relativeTarget = moduleInPackagePath
305
+
306
+ if (maybePackageJson) {
307
+ const packageResolver = getPackageResolver(maybePackageJson)
308
+
309
+ relativeTarget = packageResolver(moduleInPackagePath)
310
+ }
311
+
312
+ const potentialPath = join(nodeModulePaths, packageName, relativeTarget)
313
+
314
+ matchedModule = tryMatchingWithIndex(potentialPath)
315
+ if (matchedModule) {
316
+ break
317
+ }
318
+ }
319
+ }
320
+
321
+ if (matchedModule) {
322
+ return seedCJSModuleCacheAndReturnTarget(matchedModule, args[1])
323
+ }
324
+
325
+ return original_resolveFilename(...args)
326
+ }
327
+
328
+ hookedIn = true
329
+ }
330
+ }
@@ -0,0 +1,16 @@
1
+ // NOTE: This is a fragment of a JavaScript program that will be inlined with
2
+ // a Webpack bundle. You should not import this file from anywhere in the
3
+ // application.
4
+ import { AsyncLocalStorage } from 'node:async_hooks'
5
+
6
+ import { createRequire } from 'node:module' // used in dynamically generated part
7
+ import process from 'node:process'
8
+
9
+ import { registerCJSModules } from '../edge-runtime/lib/cjs.ts' // used in dynamically generated part
10
+
11
+ globalThis.process = process
12
+
13
+ globalThis.AsyncLocalStorage = AsyncLocalStorage
14
+
15
+ // needed for path.relative and path.resolve to work
16
+ Deno.cwd = () => ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.12.1",
3
+ "version": "5.13.1",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",
@@ -9,6 +9,8 @@
9
9
  "edge-runtime",
10
10
  "!edge-runtime/deno.json",
11
11
  "!edge-runtime/deno.lock",
12
+ "!edge-runtime/**/*.test.ts",
13
+ "!edge-runtime/lib/fixture",
12
14
  "manifest.yml"
13
15
  ],
14
16
  "engines": {
@@ -1,92 +0,0 @@
1
- import { assertEquals } from 'https://deno.land/std@0.175.0/testing/asserts.ts'
2
- import { mergeMiddlewareCookies } from './middleware.ts'
3
-
4
- const MIDDLEWARE_HEADER = 'x-middleware-set-cookie'
5
-
6
- Deno.test('mergeMiddlewareCookies', async (t) => {
7
- await t.step('should handle empty cookies', async () => {
8
- const request = new Request('https://www.test-url.com')
9
- const response = new Response()
10
-
11
- const result = mergeMiddlewareCookies(response, request)
12
- assertEquals(result, '')
13
- })
14
-
15
- await t.step('should return request cookies when there are no middleware headers', async () => {
16
- const request = new Request('https://www.test-url.com')
17
- const response = new Response()
18
-
19
- request.headers.set('Cookie', 'oatmeal=raisin')
20
-
21
- const result = mergeMiddlewareCookies(response, request)
22
- assertEquals(result, 'oatmeal=raisin')
23
- })
24
-
25
- await t.step('should not require cookies in request to be set', async () => {
26
- const request = new Request('https://www.test-url.com')
27
- const response = new Response()
28
-
29
- response.headers.set(MIDDLEWARE_HEADER, 'peanut=butter; Path=/')
30
-
31
- const result = mergeMiddlewareCookies(response, request)
32
- assertEquals(result, 'peanut=butter')
33
- })
34
-
35
- await t.step('should merge request and middleware cookies', async () => {
36
- const request = new Request('https://www.test-url.com')
37
- const response = new Response()
38
-
39
- request.headers.set('Cookie', 'oatmeal=raisin')
40
- response.headers.set(MIDDLEWARE_HEADER, 'peanut=butter; Path=/')
41
-
42
- const result = mergeMiddlewareCookies(response, request)
43
- assertEquals(result, 'oatmeal=raisin; peanut=butter')
44
- })
45
-
46
- await t.step('should overwrite request cookies with latest values', async () => {
47
- const request = new Request('https://www.test-url.com')
48
- const response = new Response()
49
-
50
- request.headers.set('Cookie', 'oatmeal=chocolate')
51
- response.headers.set(MIDDLEWARE_HEADER, 'oatmeal=raisin; Path=/')
52
-
53
- const result = mergeMiddlewareCookies(response, request)
54
- assertEquals(result, 'oatmeal=raisin')
55
- })
56
-
57
- await t.step('should not decode middleware cookie values', async () => {
58
- const request = new Request('https://www.test-url.com')
59
- const response = new Response()
60
-
61
- response.headers.set(MIDDLEWARE_HEADER, 'greeting=Hello%20from%20the%20cookie; Path=/')
62
-
63
- const result = mergeMiddlewareCookies(response, request)
64
- assertEquals(result, 'greeting=Hello%20from%20the%20cookie')
65
- })
66
-
67
- await t.step('should support multiple cookies being set in middleware', async () => {
68
- const request = new Request('https://www.test-url.com')
69
- const response = new Response()
70
-
71
- response.headers.set(
72
- MIDDLEWARE_HEADER,
73
- 'oatmeal=raisin; Path=/,peanut=butter; Path=/,chocolate=chip; Path=/',
74
- )
75
-
76
- const result = mergeMiddlewareCookies(response, request)
77
- assertEquals(result, 'oatmeal=raisin; peanut=butter; chocolate=chip')
78
- })
79
-
80
- await t.step('should ignore comma in middleware cookie expiry', async () => {
81
- const request = new Request('https://www.test-url.com')
82
- const response = new Response()
83
-
84
- response.headers.set(
85
- MIDDLEWARE_HEADER,
86
- 'oatmeal=raisin; Path=/; Expires=Wed, 23 Apr 2025 13:37:43 GMT; Max-Age=604800',
87
- )
88
-
89
- const result = mergeMiddlewareCookies(response, request)
90
- assertEquals(result, 'oatmeal=raisin')
91
- })
92
- })