@sveltejs/adapter-netlify 1.0.4 → 2.0.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.
@@ -1,5 +1,7 @@
1
1
  import './shims.js';
2
2
  import { Server } from '0SERVER';
3
+ import 'node:stream/web';
4
+ import 'node:crypto';
3
5
  import 'assert';
4
6
  import 'net';
5
7
  import 'http';
@@ -1,3 +1,5 @@
1
+ import { ReadableStream as ReadableStream$1, TransformStream, WritableStream } from 'node:stream/web';
2
+ import { webcrypto } from 'node:crypto';
1
3
  import require$$0$1 from 'assert';
2
4
  import require$$4 from 'net';
3
5
  import require$$2 from 'http';
@@ -5,7 +7,7 @@ import require$$0$2 from 'stream';
5
7
  import require$$7 from 'buffer';
6
8
  import require$$0 from 'util';
7
9
  import require$$8 from 'querystring';
8
- import require$$13, { ReadableStream as ReadableStream$1, TransformStream, WritableStream } from 'stream/web';
10
+ import require$$13 from 'stream/web';
9
11
  import require$$0$3 from 'worker_threads';
10
12
  import require$$1 from 'perf_hooks';
11
13
  import require$$4$1 from 'util/types';
@@ -16,7 +18,7 @@ import require$$3 from 'async_hooks';
16
18
  import require$$1$1 from 'console';
17
19
  import require$$3$1 from 'zlib';
18
20
  import require$$6 from 'string_decoder';
19
- import require$$0$5, { webcrypto } from 'crypto';
21
+ import require$$0$5 from 'crypto';
20
22
  import require$$1$2 from 'diagnostics_channel';
21
23
 
22
24
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -648,8 +650,23 @@ function ReadableStreamFrom$1 (iterable) {
648
650
  )
649
651
  }
650
652
 
653
+ // The chunk should be a FormData instance and contains
654
+ // all the required methods.
651
655
  function isFormDataLike (chunk) {
652
- return chunk && chunk.constructor && chunk.constructor.name === 'FormData'
656
+ return (chunk &&
657
+ chunk.constructor && chunk.constructor.name === 'FormData' &&
658
+ typeof chunk === 'object' &&
659
+ (typeof chunk.append === 'function' &&
660
+ typeof chunk.delete === 'function' &&
661
+ typeof chunk.get === 'function' &&
662
+ typeof chunk.getAll === 'function' &&
663
+ typeof chunk.has === 'function' &&
664
+ typeof chunk.set === 'function' &&
665
+ typeof chunk.entries === 'function' &&
666
+ typeof chunk.keys === 'function' &&
667
+ typeof chunk.values === 'function' &&
668
+ typeof chunk.forEach === 'function')
669
+ )
653
670
  }
654
671
 
655
672
  const kEnumerableProperty = Object.create(null);
@@ -685,6 +702,94 @@ var util$g = {
685
702
  buildURL: buildURL$2
686
703
  };
687
704
 
705
+ let fastNow = Date.now();
706
+ let fastNowTimeout;
707
+
708
+ const fastTimers = [];
709
+
710
+ function onTimeout () {
711
+ fastNow = Date.now();
712
+
713
+ let len = fastTimers.length;
714
+ let idx = 0;
715
+ while (idx < len) {
716
+ const timer = fastTimers[idx];
717
+
718
+ if (timer.expires && fastNow >= timer.expires) {
719
+ timer.expires = 0;
720
+ timer.callback(timer.opaque);
721
+ }
722
+
723
+ if (timer.expires === 0) {
724
+ timer.active = false;
725
+ if (idx !== len - 1) {
726
+ fastTimers[idx] = fastTimers.pop();
727
+ } else {
728
+ fastTimers.pop();
729
+ }
730
+ len -= 1;
731
+ } else {
732
+ idx += 1;
733
+ }
734
+ }
735
+
736
+ if (fastTimers.length > 0) {
737
+ refreshTimeout();
738
+ }
739
+ }
740
+
741
+ function refreshTimeout () {
742
+ if (fastNowTimeout && fastNowTimeout.refresh) {
743
+ fastNowTimeout.refresh();
744
+ } else {
745
+ clearTimeout(fastNowTimeout);
746
+ fastNowTimeout = setTimeout(onTimeout, 1e3);
747
+ if (fastNowTimeout.unref) {
748
+ fastNowTimeout.unref();
749
+ }
750
+ }
751
+ }
752
+
753
+ class Timeout {
754
+ constructor (callback, delay, opaque) {
755
+ this.callback = callback;
756
+ this.delay = delay;
757
+ this.opaque = opaque;
758
+ this.expires = 0;
759
+ this.active = false;
760
+
761
+ this.refresh();
762
+ }
763
+
764
+ refresh () {
765
+ if (!this.active) {
766
+ this.active = true;
767
+ fastTimers.push(this);
768
+ if (!fastNowTimeout || fastTimers.length === 1) {
769
+ refreshTimeout();
770
+ fastNow = Date.now();
771
+ }
772
+ }
773
+
774
+ this.expires = fastNow + this.delay;
775
+ }
776
+
777
+ clear () {
778
+ this.expires = 0;
779
+ }
780
+ }
781
+
782
+ var timers$1 = {
783
+ setTimeout (callback, delay, opaque) {
784
+ return new Timeout(callback, delay, opaque)
785
+ },
786
+ clearTimeout (timeout) {
787
+ if (timeout && timeout.clear) {
788
+ timeout.clear();
789
+ }
790
+ }
791
+ };
792
+
688
793
  var utils$1;
689
794
  var hasRequiredUtils$1;
690
795
 
@@ -4461,6 +4566,12 @@ function requireDataURL () {
4461
4566
 
4462
4567
  const encoder = new TextEncoder();
4463
4568
 
4569
+ // Regex
4570
+ const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+-.^_|~A-z0-9]+$/;
4571
+ const HTTP_WHITESPACE_REGEX = /(\u000A|\u000D|\u0009|\u0020)/; // eslint-disable-line
4572
+ // https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
4573
+ const HTTP_QUOTED_STRING_TOKENS = /^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/; // eslint-disable-line
4574
+
4464
4575
  // https://fetch.spec.whatwg.org/#data-url-processor
4465
4576
  /** @param {URL} dataURL */
4466
4577
  function dataURLProcessor (dataURL) {
@@ -4481,8 +4592,8 @@ function requireDataURL () {
4481
4592
  // 5. Let mimeType be the result of collecting a
4482
4593
  // sequence of code points that are not equal
4483
4594
  // to U+002C (,), given position.
4484
- let mimeType = collectASequenceOfCodePoints(
4485
- (char) => char !== ',',
4595
+ let mimeType = collectASequenceOfCodePointsFast(
4596
+ ',',
4486
4597
  input,
4487
4598
  position
4488
4599
  );
@@ -4595,6 +4706,25 @@ function requireDataURL () {
4595
4706
  return result
4596
4707
  }
4597
4708
 
4709
+ /**
4710
+ * A faster collectASequenceOfCodePoints that only works when comparing a single character.
4711
+ * @param {string} char
4712
+ * @param {string} input
4713
+ * @param {{ position: number }} position
4714
+ */
4715
+ function collectASequenceOfCodePointsFast (char, input, position) {
4716
+ const idx = input.indexOf(char, position.position);
4717
+ const start = position.position;
4718
+
4719
+ if (idx === -1) {
4720
+ position.position = input.length;
4721
+ return input.slice(start)
4722
+ }
4723
+
4724
+ position.position = idx;
4725
+ return input.slice(start, position.position)
4726
+ }
4727
+
4598
4728
  // https://url.spec.whatwg.org/#string-percent-decode
4599
4729
  /** @param {string} input */
4600
4730
  function stringPercentDecode (input) {
@@ -4664,8 +4794,8 @@ function requireDataURL () {
4664
4794
  // 3. Let type be the result of collecting a sequence
4665
4795
  // of code points that are not U+002F (/) from
4666
4796
  // input, given position.
4667
- const type = collectASequenceOfCodePoints(
4668
- (char) => char !== '/',
4797
+ const type = collectASequenceOfCodePointsFast(
4798
+ '/',
4669
4799
  input,
4670
4800
  position
4671
4801
  );
@@ -4673,7 +4803,7 @@ function requireDataURL () {
4673
4803
  // 4. If type is the empty string or does not solely
4674
4804
  // contain HTTP token code points, then return failure.
4675
4805
  // https://mimesniff.spec.whatwg.org/#http-token-code-point
4676
- if (type.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(type)) {
4806
+ if (type.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(type)) {
4677
4807
  return 'failure'
4678
4808
  }
4679
4809
 
@@ -4689,8 +4819,8 @@ function requireDataURL () {
4689
4819
  // 7. Let subtype be the result of collecting a sequence of
4690
4820
  // code points that are not U+003B (;) from input, given
4691
4821
  // position.
4692
- let subtype = collectASequenceOfCodePoints(
4693
- (char) => char !== ';',
4822
+ let subtype = collectASequenceOfCodePointsFast(
4823
+ ';',
4694
4824
  input,
4695
4825
  position
4696
4826
  );
@@ -4700,7 +4830,7 @@ function requireDataURL () {
4700
4830
 
4701
4831
  // 9. If subtype is the empty string or does not solely
4702
4832
  // contain HTTP token code points, then return failure.
4703
- if (subtype.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(subtype)) {
4833
+ if (subtype.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(subtype)) {
4704
4834
  return 'failure'
4705
4835
  }
4706
4836
 
@@ -4714,9 +4844,7 @@ function requireDataURL () {
4714
4844
  /** @type {Map<string, string>} */
4715
4845
  parameters: new Map(),
4716
4846
  // https://mimesniff.spec.whatwg.org/#mime-type-essence
4717
- get essence () {
4718
- return `${this.type}/${this.subtype}`
4719
- }
4847
+ essence: `${type}/${subtype}`
4720
4848
  };
4721
4849
 
4722
4850
  // 11. While position is not past the end of input:
@@ -4728,7 +4856,7 @@ function requireDataURL () {
4728
4856
  // whitespace from input given position.
4729
4857
  collectASequenceOfCodePoints(
4730
4858
  // https://fetch.spec.whatwg.org/#http-whitespace
4731
- (char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char), // eslint-disable-line
4859
+ char => HTTP_WHITESPACE_REGEX.test(char),
4732
4860
  input,
4733
4861
  position
4734
4862
  );
@@ -4776,8 +4904,8 @@ function requireDataURL () {
4776
4904
 
4777
4905
  // 2. Collect a sequence of code points that are not
4778
4906
  // U+003B (;) from input, given position.
4779
- collectASequenceOfCodePoints(
4780
- (char) => char !== ';',
4907
+ collectASequenceOfCodePointsFast(
4908
+ ';',
4781
4909
  input,
4782
4910
  position
4783
4911
  );
@@ -4787,8 +4915,8 @@ function requireDataURL () {
4787
4915
  // 1. Set parameterValue to the result of collecting
4788
4916
  // a sequence of code points that are not U+003B (;)
4789
4917
  // from input, given position.
4790
- parameterValue = collectASequenceOfCodePoints(
4791
- (char) => char !== ';',
4918
+ parameterValue = collectASequenceOfCodePointsFast(
4919
+ ';',
4792
4920
  input,
4793
4921
  position
4794
4922
  );
@@ -4811,9 +4939,8 @@ function requireDataURL () {
4811
4939
  // then set mimeType’s parameters[parameterName] to parameterValue.
4812
4940
  if (
4813
4941
  parameterName.length !== 0 &&
4814
- /^[!#$%&'*+-.^_|~A-z0-9]+$/.test(parameterName) &&
4815
- // https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
4816
- !/^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/.test(parameterValue) && // eslint-disable-line
4942
+ HTTP_TOKEN_CODEPOINTS.test(parameterName) &&
4943
+ !HTTP_QUOTED_STRING_TOKENS.test(parameterValue) &&
4817
4944
  !mimeType.parameters.has(parameterName)
4818
4945
  ) {
4819
4946
  mimeType.parameters.set(parameterName, parameterValue);
@@ -5615,7 +5742,7 @@ function requireFormdata () {
5615
5742
  lastModified: value.lastModified
5616
5743
  };
5617
5744
 
5618
- value = value instanceof File
5745
+ value = (NativeFile && value instanceof NativeFile) || value instanceof UndiciFile
5619
5746
  ? new File([value], filename, options)
5620
5747
  : new FileLike(value, filename, options);
5621
5748
  }
@@ -6376,7 +6503,7 @@ let Request$1 = class Request {
6376
6503
 
6377
6504
  this.blocking = blocking == null ? false : blocking;
6378
6505
 
6379
- this.reset = reset == null ? false : reset;
6506
+ this.reset = reset == null ? null : reset;
6380
6507
 
6381
6508
  this.host = null;
6382
6509
 
@@ -6511,11 +6638,16 @@ let Request$1 = class Request {
6511
6638
  };
6512
6639
 
6513
6640
  function processHeaderValue (key, val) {
6514
- if (val && (typeof val === 'object' && !Array.isArray(val))) {
6641
+ if (val && typeof val === 'object') {
6515
6642
  throw new InvalidArgumentError$i(`invalid ${key} header`)
6516
- } else if (headerCharRegex.exec(val) !== null) {
6643
+ }
6644
+
6645
+ val = val != null ? `${val}` : '';
6646
+
6647
+ if (headerCharRegex.exec(val) !== null) {
6517
6648
  throw new InvalidArgumentError$i(`invalid ${key} header`)
6518
6649
  }
6650
+
6519
6651
  return `${key}: ${val}\r\n`
6520
6652
  }
6521
6653
 
@@ -6545,11 +6677,10 @@ function processHeader (request, key, val) {
6545
6677
  } else if (
6546
6678
  request.contentType === null &&
6547
6679
  key.length === 12 &&
6548
- key.toLowerCase() === 'content-type' &&
6549
- headerCharRegex.exec(val) === null
6680
+ key.toLowerCase() === 'content-type'
6550
6681
  ) {
6551
6682
  request.contentType = val;
6552
- request.headers += `${key}: ${val}\r\n`;
6683
+ request.headers += processHeaderValue(key, val);
6553
6684
  } else if (
6554
6685
  key.length === 17 &&
6555
6686
  key.toLowerCase() === 'transfer-encoding'
@@ -6559,7 +6690,7 @@ function processHeader (request, key, val) {
6559
6690
  key.length === 10 &&
6560
6691
  key.toLowerCase() === 'connection'
6561
6692
  ) {
6562
- const value = val.toLowerCase();
6693
+ const value = typeof val === 'string' ? val.toLowerCase() : null;
6563
6694
  if (value !== 'close' && value !== 'keep-alive') {
6564
6695
  throw new InvalidArgumentError$i('invalid connection header')
6565
6696
  } else if (value === 'close') {
@@ -6923,6 +7054,12 @@ function buildConnector$3 ({ maxCachedSessions, socketPath, timeout, ...opts })
6923
7054
  });
6924
7055
  }
6925
7056
 
7057
+ // Set TCP keep alive options on the socket here instead of in connect() for the case of assigning the socket
7058
+ if (options.keepAlive == null || options.keepAlive) {
7059
+ const keepAliveInitialDelay = options.keepAliveInitialDelay === undefined ? 60e3 : options.keepAliveInitialDelay;
7060
+ socket.setKeepAlive(true, keepAliveInitialDelay);
7061
+ }
7062
+
6926
7063
  const cancelTimeout = setupTimeout(() => onConnectTimeout(socket), timeout);
6927
7064
 
6928
7065
  socket
@@ -7530,6 +7667,7 @@ function requireLlhttp_simd_wasm () {
7530
7667
  const assert$3 = require$$0$1;
7531
7668
  const net = require$$4;
7532
7669
  const util$b = util$g;
7670
+ const timers = timers$1;
7533
7671
  const Request = request$2;
7534
7672
  const DispatcherBase$3 = dispatcherBase;
7535
7673
  const {
@@ -7590,6 +7728,7 @@ const {
7590
7728
  kLocalAddress,
7591
7729
  kMaxResponseSize
7592
7730
  } = symbols$3;
7731
+ const FastBuffer = Buffer[Symbol.species];
7593
7732
 
7594
7733
  const kClosedResolve$1 = Symbol('kClosedResolve');
7595
7734
 
@@ -7885,9 +8024,8 @@ async function lazyllhttp () {
7885
8024
  },
7886
8025
  wasm_on_status: (p, at, len) => {
7887
8026
  assert$3.strictEqual(currentParser.ptr, p);
7888
- const start = at - currentBufferPtr;
7889
- const end = start + len;
7890
- return currentParser.onStatus(currentBufferRef.slice(start, end)) || 0
8027
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset;
8028
+ return currentParser.onStatus(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
7891
8029
  },
7892
8030
  wasm_on_message_begin: (p) => {
7893
8031
  assert$3.strictEqual(currentParser.ptr, p);
@@ -7895,15 +8033,13 @@ async function lazyllhttp () {
7895
8033
  },
7896
8034
  wasm_on_header_field: (p, at, len) => {
7897
8035
  assert$3.strictEqual(currentParser.ptr, p);
7898
- const start = at - currentBufferPtr;
7899
- const end = start + len;
7900
- return currentParser.onHeaderField(currentBufferRef.slice(start, end)) || 0
8036
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset;
8037
+ return currentParser.onHeaderField(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
7901
8038
  },
7902
8039
  wasm_on_header_value: (p, at, len) => {
7903
8040
  assert$3.strictEqual(currentParser.ptr, p);
7904
- const start = at - currentBufferPtr;
7905
- const end = start + len;
7906
- return currentParser.onHeaderValue(currentBufferRef.slice(start, end)) || 0
8041
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset;
8042
+ return currentParser.onHeaderValue(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
7907
8043
  },
7908
8044
  wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => {
7909
8045
  assert$3.strictEqual(currentParser.ptr, p);
@@ -7911,9 +8047,8 @@ async function lazyllhttp () {
7911
8047
  },
7912
8048
  wasm_on_body: (p, at, len) => {
7913
8049
  assert$3.strictEqual(currentParser.ptr, p);
7914
- const start = at - currentBufferPtr;
7915
- const end = start + len;
7916
- return currentParser.onBody(currentBufferRef.slice(start, end)) || 0
8050
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset;
8051
+ return currentParser.onBody(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
7917
8052
  },
7918
8053
  wasm_on_message_complete: (p) => {
7919
8054
  assert$3.strictEqual(currentParser.ptr, p);
@@ -7926,9 +8061,8 @@ async function lazyllhttp () {
7926
8061
  }
7927
8062
 
7928
8063
  let llhttpInstance = null;
7929
- let llhttpPromise = lazyllhttp()
7930
- .catch(() => {
7931
- });
8064
+ let llhttpPromise = lazyllhttp();
8065
+ llhttpPromise.catch();
7932
8066
 
7933
8067
  let currentParser = null;
7934
8068
  let currentBufferRef = null;
@@ -7964,15 +8098,16 @@ class Parser {
7964
8098
 
7965
8099
  this.keepAlive = '';
7966
8100
  this.contentLength = '';
8101
+ this.connection = '';
7967
8102
  this.maxResponseSize = client[kMaxResponseSize];
7968
8103
  }
7969
8104
 
7970
8105
  setTimeout (value, type) {
7971
8106
  this.timeoutType = type;
7972
8107
  if (value !== this.timeoutValue) {
7973
- clearTimeout(this.timeout);
8108
+ timers.clearTimeout(this.timeout);
7974
8109
  if (value) {
7975
- this.timeout = setTimeout(onParserTimeout, value, this);
8110
+ this.timeout = timers.setTimeout(onParserTimeout, value, this);
7976
8111
  // istanbul ignore else: only for jest
7977
8112
  if (this.timeout.unref) {
7978
8113
  this.timeout.unref();
@@ -8088,7 +8223,7 @@ class Parser {
8088
8223
  this.llhttp.llhttp_free(this.ptr);
8089
8224
  this.ptr = null;
8090
8225
 
8091
- clearTimeout(this.timeout);
8226
+ timers.clearTimeout(this.timeout);
8092
8227
  this.timeout = null;
8093
8228
  this.timeoutValue = null;
8094
8229
  this.timeoutType = null;
@@ -8139,6 +8274,8 @@ class Parser {
8139
8274
  const key = this.headers[len - 2];
8140
8275
  if (key.length === 10 && key.toString().toLowerCase() === 'keep-alive') {
8141
8276
  this.keepAlive += buf.toString();
8277
+ } else if (key.length === 10 && key.toString().toLowerCase() === 'connection') {
8278
+ this.connection += buf.toString();
8142
8279
  } else if (key.length === 14 && key.toString().toLowerCase() === 'content-length') {
8143
8280
  this.contentLength += buf.toString();
8144
8281
  }
@@ -8232,7 +8369,11 @@ class Parser {
8232
8369
  assert$3.strictEqual(this.timeoutType, TIMEOUT_HEADERS);
8233
8370
 
8234
8371
  this.statusCode = statusCode;
8235
- this.shouldKeepAlive = shouldKeepAlive;
8372
+ this.shouldKeepAlive = (
8373
+ shouldKeepAlive ||
8374
+ // Override llhttp value which does not allow keepAlive for HEAD.
8375
+ (request.method === 'HEAD' && !socket[kReset] && this.connection.toLowerCase() === 'keep-alive')
8376
+ );
8236
8377
 
8237
8378
  if (this.statusCode >= 200) {
8238
8379
  const bodyTimeout = request.bodyTimeout != null
@@ -8262,7 +8403,7 @@ class Parser {
8262
8403
  this.headers = [];
8263
8404
  this.headersSize = 0;
8264
8405
 
8265
- if (shouldKeepAlive && client[kPipelining]) {
8406
+ if (this.shouldKeepAlive && client[kPipelining]) {
8266
8407
  const keepAliveTimeout = this.keepAlive ? util$b.parseKeepAliveTimeout(this.keepAlive) : null;
8267
8408
 
8268
8409
  if (keepAliveTimeout != null) {
@@ -8292,7 +8433,6 @@ class Parser {
8292
8433
  }
8293
8434
 
8294
8435
  if (request.method === 'HEAD') {
8295
- assert$3(socket[kReset]);
8296
8436
  return 1
8297
8437
  }
8298
8438
 
@@ -8366,6 +8506,7 @@ class Parser {
8366
8506
  this.bytesRead = 0;
8367
8507
  this.contentLength = '';
8368
8508
  this.keepAlive = '';
8509
+ this.connection = '';
8369
8510
 
8370
8511
  assert$3(this.headers.length % 2 === 0);
8371
8512
  this.headers = [];
@@ -8590,8 +8731,6 @@ async function connect$1 (client) {
8590
8731
 
8591
8732
  assert$3(socket);
8592
8733
 
8593
- client[kSocket] = socket;
8594
-
8595
8734
  socket[kNoRef] = false;
8596
8735
  socket[kWriting] = false;
8597
8736
  socket[kReset] = false;
@@ -8607,6 +8746,8 @@ async function connect$1 (client) {
8607
8746
  .on('end', onSocketEnd)
8608
8747
  .on('close', onSocketClose);
8609
8748
 
8749
+ client[kSocket] = socket;
8750
+
8610
8751
  if (channels.connected.hasSubscribers) {
8611
8752
  channels.connected.publish({
8612
8753
  connectParams: {
@@ -8692,7 +8833,7 @@ function _resume (client, sync) {
8692
8833
 
8693
8834
  const socket = client[kSocket];
8694
8835
 
8695
- if (socket) {
8836
+ if (socket && !socket.destroyed) {
8696
8837
  if (client[kSize$4] === 0) {
8697
8838
  if (!socket[kNoRef] && socket.unref) {
8698
8839
  socket.unref();
@@ -8759,7 +8900,7 @@ function _resume (client, sync) {
8759
8900
 
8760
8901
  if (!socket) {
8761
8902
  connect$1(client);
8762
- continue
8903
+ return
8763
8904
  }
8764
8905
 
8765
8906
  if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {
@@ -8899,8 +9040,8 @@ function write (client, request) {
8899
9040
  socket[kReset] = true;
8900
9041
  }
8901
9042
 
8902
- if (reset) {
8903
- socket[kReset] = true;
9043
+ if (reset != null) {
9044
+ socket[kReset] = reset;
8904
9045
  }
8905
9046
 
8906
9047
  if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) {
@@ -12264,7 +12405,7 @@ class ProxyAgent extends DispatcherBase {
12264
12405
 
12265
12406
  this[kRequestTls] = opts.requestTls;
12266
12407
  this[kProxyTls] = opts.proxyTls;
12267
- this[kProxyHeaders] = {};
12408
+ this[kProxyHeaders] = opts.headers || {};
12268
12409
 
12269
12410
  if (opts.auth && opts.token) {
12270
12411
  throw new InvalidArgumentError$1('opts.auth cannot be used in combination with opts.token')
@@ -12561,7 +12702,11 @@ function requireHeaders () {
12561
12702
 
12562
12703
  // 2. Append (name, value) to list.
12563
12704
  if (exists) {
12564
- this[kHeadersMap].set(lowercaseName, { name: exists.name, value: `${exists.value}, ${value}` });
12705
+ const delimiter = lowercaseName === 'cookie' ? '; ' : ', ';
12706
+ this[kHeadersMap].set(lowercaseName, {
12707
+ name: exists.name,
12708
+ value: `${exists.value}${delimiter}${value}`
12709
+ });
12565
12710
  } else {
12566
12711
  this[kHeadersMap].set(lowercaseName, { name, value });
12567
12712
  }
@@ -14554,7 +14699,7 @@ function requireFetch () {
14554
14699
  const { isErrored, isReadable } = util$g;
14555
14700
  const { dataURLProcessor, serializeAMimeType } = requireDataURL();
14556
14701
  const { TransformStream } = require$$13;
14557
- const { getGlobalDispatcher } = requireUndici();
14702
+ const { getGlobalDispatcher } = global$2;
14558
14703
  const { webidl } = requireWebidl();
14559
14704
  const { STATUS_CODES } = require$$2;
14560
14705
 
@@ -16375,8 +16520,6 @@ function requireFetch () {
16375
16520
  body: fetchParams.controller.dispatcher.isMockActive ? request.body && request.body.source : body,
16376
16521
  headers: request.headersList[kHeadersCaseInsensitive],
16377
16522
  maxRedirections: 0,
16378
- bodyTimeout: 300_000,
16379
- headersTimeout: 300_000,
16380
16523
  upgrade: request.mode === 'websocket' ? 'websocket' : undefined
16381
16524
  },
16382
16525
  {
@@ -19554,7 +19697,6 @@ function requireConnection () {
19554
19697
  if (hasRequiredConnection) return connection;
19555
19698
  hasRequiredConnection = 1;
19556
19699
 
19557
- // TODO: crypto isn't available in all environments
19558
19700
  const { randomBytes, createHash } = require$$0$5;
19559
19701
  const diagnosticsChannel = require$$1$2;
19560
19702
  const { uid, states } = requireConstants();
@@ -20192,23 +20334,14 @@ function requireWebsocket () {
20192
20334
  // not throw an exception must increase the bufferedAmount attribute
20193
20335
  // by the length of data’s buffer in bytes.
20194
20336
 
20195
- const ab = new ArrayBuffer(data.byteLength);
20196
-
20197
- if (Buffer.isBuffer(data)) {
20198
- // new Buffer signature is deprecated
20199
- Buffer.from(ab).set(data);
20200
- } else {
20201
- new data.constructor(ab).set(data);
20202
- }
20203
-
20204
- const value = Buffer.from(ab);
20337
+ const ab = Buffer.from(data, data.byteOffset, data.byteLength);
20205
20338
 
20206
- const frame = new WebsocketFrameSend(value);
20339
+ const frame = new WebsocketFrameSend(ab);
20207
20340
  const buffer = frame.createFrame(opcodes.BINARY);
20208
20341
 
20209
- this.#bufferedAmount += value.byteLength;
20342
+ this.#bufferedAmount += ab.byteLength;
20210
20343
  socket.write(buffer, () => {
20211
- this.#bufferedAmount -= value.byteLength;
20344
+ this.#bufferedAmount -= ab.byteLength;
20212
20345
  });
20213
20346
  } else if (isBlobLike(data)) {
20214
20347
  // If the WebSocket connection is established, and the WebSocket
@@ -20473,6 +20606,14 @@ function requireUndici () {
20473
20606
  const nodeMajor = Number(nodeVersion[0]);
20474
20607
  const nodeMinor = Number(nodeVersion[1]);
20475
20608
 
20609
+ let hasCrypto;
20610
+ try {
20611
+ require('crypto');
20612
+ hasCrypto = true;
20613
+ } catch {
20614
+ hasCrypto = false;
20615
+ }
20616
+
20476
20617
  Object.assign(Dispatcher.prototype, api$1);
20477
20618
 
20478
20619
  undici.Dispatcher = Dispatcher;
@@ -20575,9 +20716,14 @@ function requireUndici () {
20575
20716
  undici.getCookies = getCookies;
20576
20717
  undici.getSetCookies = getSetCookies;
20577
20718
  undici.setCookie = setCookie;
20719
+
20720
+ const { parseMIMEType, serializeAMimeType } = requireDataURL();
20721
+
20722
+ undici.parseMIMEType = parseMIMEType;
20723
+ undici.serializeAMimeType = serializeAMimeType;
20578
20724
  }
20579
20725
 
20580
- if (nodeMajor >= 18) {
20726
+ if (nodeMajor >= 18 && hasCrypto) {
20581
20727
  const { WebSocket } = requireWebsocket();
20582
20728
 
20583
20729
  undici.WebSocket = WebSocket;
package/index.js CHANGED
@@ -162,10 +162,17 @@ async function generate_lambda_functions({ builder, publish, split }) {
162
162
  // Configuring the function to use ESM as the output format.
163
163
  const fn_config = JSON.stringify({ config: { nodeModuleFormat: 'esm' }, version: 1 });
164
164
 
165
+ builder.log.minor('Generating serverless functions...');
166
+
165
167
  if (split) {
166
- builder.log.minor('Generating serverless functions...');
168
+ const seen = new Set();
169
+
170
+ for (let i = 0; i < builder.routes.length; i++) {
171
+ const route = builder.routes[i];
172
+ if (route.prerender === true) continue;
173
+
174
+ const routes = [route];
167
175
 
168
- await builder.createEntries((route) => {
169
176
  const parts = [];
170
177
  // Netlify's syntax uses '*' and ':param' as "splats" and "placeholders"
171
178
  // https://docs.netlify.com/routing/redirects/redirect-options/#splats
@@ -183,27 +190,33 @@ async function generate_lambda_functions({ builder, publish, split }) {
183
190
  const pattern = `/${parts.join('/')}`;
184
191
  const name = parts.join('-').replace(/[:.]/g, '_').replace('*', '__rest') || 'index';
185
192
 
186
- return {
187
- id: pattern,
188
- filter: (other) => matches(route.segments, other.segments),
189
- complete: (entry) => {
190
- const manifest = entry.generateManifest({
191
- relativePath: '../server'
192
- });
193
+ // skip routes with identical patterns, they were already folded into another function
194
+ if (seen.has(pattern)) continue;
195
+ seen.add(pattern);
193
196
 
194
- const fn = `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`;
197
+ // figure out which lower priority routes should be considered fallbacks
198
+ for (let j = i + 1; j < builder.routes.length; j += 1) {
199
+ if (routes[j].prerender === true) continue;
195
200
 
196
- writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
197
- writeFileSync(`.netlify/functions-internal/${name}.json`, fn_config);
198
-
199
- redirects.push(`${pattern} /.netlify/functions/${name} 200`);
200
- redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
201
+ if (matches(route.segments, routes[j].segments)) {
202
+ routes.push(builder.routes[j]);
201
203
  }
202
- };
203
- });
204
- } else {
205
- builder.log.minor('Generating serverless functions...');
204
+ }
205
+
206
+ const manifest = builder.generateManifest({
207
+ relativePath: '../server',
208
+ routes
209
+ });
210
+
211
+ const fn = `import { init } from '../serverless.js';\n\nexport const handler = init(${manifest});\n`;
206
212
 
213
+ writeFileSync(`.netlify/functions-internal/${name}.mjs`, fn);
214
+ writeFileSync(`.netlify/functions-internal/${name}.json`, fn_config);
215
+
216
+ redirects.push(`${pattern} /.netlify/functions/${name} 200`);
217
+ redirects.push(`${pattern}/__data.json /.netlify/functions/${name} 200`);
218
+ }
219
+ } else {
207
220
  const manifest = builder.generateManifest({
208
221
  relativePath: '../server'
209
222
  });
@@ -263,7 +276,7 @@ function get_publish_directory(netlify_config, builder) {
263
276
  }
264
277
 
265
278
  builder.log.warn(
266
- 'No netlify.toml found. Using default publish directory. Consult https://github.com/sveltejs/kit/tree/master/packages/adapter-netlify#configuration for more details '
279
+ 'No netlify.toml found. Using default publish directory. Consult https://kit.svelte.dev/docs/adapter-netlify#usage for more details'
267
280
  );
268
281
  }
269
282
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -38,10 +38,10 @@
38
38
  "rollup": "^3.7.0",
39
39
  "typescript": "^4.9.4",
40
40
  "uvu": "^0.5.6",
41
- "@sveltejs/kit": "^1.1.3"
41
+ "@sveltejs/kit": "^1.5.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@sveltejs/kit": "^1.0.0"
44
+ "@sveltejs/kit": "^1.5.0"
45
45
  },
46
46
  "scripts": {
47
47
  "dev": "rimraf files && rollup -cw",