@sveltejs/adapter-netlify 1.0.5 → 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 : {};
@@ -700,6 +702,94 @@ var util$g = {
700
702
  buildURL: buildURL$2
701
703
  };
702
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
+
703
793
  var utils$1;
704
794
  var hasRequiredUtils$1;
705
795
 
@@ -4502,8 +4592,8 @@ function requireDataURL () {
4502
4592
  // 5. Let mimeType be the result of collecting a
4503
4593
  // sequence of code points that are not equal
4504
4594
  // to U+002C (,), given position.
4505
- let mimeType = collectASequenceOfCodePoints(
4506
- (char) => char !== ',',
4595
+ let mimeType = collectASequenceOfCodePointsFast(
4596
+ ',',
4507
4597
  input,
4508
4598
  position
4509
4599
  );
@@ -4616,6 +4706,25 @@ function requireDataURL () {
4616
4706
  return result
4617
4707
  }
4618
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
+
4619
4728
  // https://url.spec.whatwg.org/#string-percent-decode
4620
4729
  /** @param {string} input */
4621
4730
  function stringPercentDecode (input) {
@@ -4685,8 +4794,8 @@ function requireDataURL () {
4685
4794
  // 3. Let type be the result of collecting a sequence
4686
4795
  // of code points that are not U+002F (/) from
4687
4796
  // input, given position.
4688
- const type = collectASequenceOfCodePoints(
4689
- (char) => char !== '/',
4797
+ const type = collectASequenceOfCodePointsFast(
4798
+ '/',
4690
4799
  input,
4691
4800
  position
4692
4801
  );
@@ -4710,8 +4819,8 @@ function requireDataURL () {
4710
4819
  // 7. Let subtype be the result of collecting a sequence of
4711
4820
  // code points that are not U+003B (;) from input, given
4712
4821
  // position.
4713
- let subtype = collectASequenceOfCodePoints(
4714
- (char) => char !== ';',
4822
+ let subtype = collectASequenceOfCodePointsFast(
4823
+ ';',
4715
4824
  input,
4716
4825
  position
4717
4826
  );
@@ -4795,8 +4904,8 @@ function requireDataURL () {
4795
4904
 
4796
4905
  // 2. Collect a sequence of code points that are not
4797
4906
  // U+003B (;) from input, given position.
4798
- collectASequenceOfCodePoints(
4799
- (char) => char !== ';',
4907
+ collectASequenceOfCodePointsFast(
4908
+ ';',
4800
4909
  input,
4801
4910
  position
4802
4911
  );
@@ -4806,8 +4915,8 @@ function requireDataURL () {
4806
4915
  // 1. Set parameterValue to the result of collecting
4807
4916
  // a sequence of code points that are not U+003B (;)
4808
4917
  // from input, given position.
4809
- parameterValue = collectASequenceOfCodePoints(
4810
- (char) => char !== ';',
4918
+ parameterValue = collectASequenceOfCodePointsFast(
4919
+ ';',
4811
4920
  input,
4812
4921
  position
4813
4922
  );
@@ -6529,11 +6638,16 @@ let Request$1 = class Request {
6529
6638
  };
6530
6639
 
6531
6640
  function processHeaderValue (key, val) {
6532
- if (val && (typeof val === 'object' && !Array.isArray(val))) {
6641
+ if (val && typeof val === 'object') {
6533
6642
  throw new InvalidArgumentError$i(`invalid ${key} header`)
6534
- } else if (headerCharRegex.exec(val) !== null) {
6643
+ }
6644
+
6645
+ val = val != null ? `${val}` : '';
6646
+
6647
+ if (headerCharRegex.exec(val) !== null) {
6535
6648
  throw new InvalidArgumentError$i(`invalid ${key} header`)
6536
6649
  }
6650
+
6537
6651
  return `${key}: ${val}\r\n`
6538
6652
  }
6539
6653
 
@@ -6563,11 +6677,10 @@ function processHeader (request, key, val) {
6563
6677
  } else if (
6564
6678
  request.contentType === null &&
6565
6679
  key.length === 12 &&
6566
- key.toLowerCase() === 'content-type' &&
6567
- headerCharRegex.exec(val) === null
6680
+ key.toLowerCase() === 'content-type'
6568
6681
  ) {
6569
6682
  request.contentType = val;
6570
- request.headers += `${key}: ${val}\r\n`;
6683
+ request.headers += processHeaderValue(key, val);
6571
6684
  } else if (
6572
6685
  key.length === 17 &&
6573
6686
  key.toLowerCase() === 'transfer-encoding'
@@ -6577,7 +6690,7 @@ function processHeader (request, key, val) {
6577
6690
  key.length === 10 &&
6578
6691
  key.toLowerCase() === 'connection'
6579
6692
  ) {
6580
- const value = val.toLowerCase();
6693
+ const value = typeof val === 'string' ? val.toLowerCase() : null;
6581
6694
  if (value !== 'close' && value !== 'keep-alive') {
6582
6695
  throw new InvalidArgumentError$i('invalid connection header')
6583
6696
  } else if (value === 'close') {
@@ -6941,6 +7054,12 @@ function buildConnector$3 ({ maxCachedSessions, socketPath, timeout, ...opts })
6941
7054
  });
6942
7055
  }
6943
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
+
6944
7063
  const cancelTimeout = setupTimeout(() => onConnectTimeout(socket), timeout);
6945
7064
 
6946
7065
  socket
@@ -7548,6 +7667,7 @@ function requireLlhttp_simd_wasm () {
7548
7667
  const assert$3 = require$$0$1;
7549
7668
  const net = require$$4;
7550
7669
  const util$b = util$g;
7670
+ const timers = timers$1;
7551
7671
  const Request = request$2;
7552
7672
  const DispatcherBase$3 = dispatcherBase;
7553
7673
  const {
@@ -7608,6 +7728,7 @@ const {
7608
7728
  kLocalAddress,
7609
7729
  kMaxResponseSize
7610
7730
  } = symbols$3;
7731
+ const FastBuffer = Buffer[Symbol.species];
7611
7732
 
7612
7733
  const kClosedResolve$1 = Symbol('kClosedResolve');
7613
7734
 
@@ -7903,9 +8024,8 @@ async function lazyllhttp () {
7903
8024
  },
7904
8025
  wasm_on_status: (p, at, len) => {
7905
8026
  assert$3.strictEqual(currentParser.ptr, p);
7906
- const start = at - currentBufferPtr;
7907
- const end = start + len;
7908
- 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
7909
8029
  },
7910
8030
  wasm_on_message_begin: (p) => {
7911
8031
  assert$3.strictEqual(currentParser.ptr, p);
@@ -7913,15 +8033,13 @@ async function lazyllhttp () {
7913
8033
  },
7914
8034
  wasm_on_header_field: (p, at, len) => {
7915
8035
  assert$3.strictEqual(currentParser.ptr, p);
7916
- const start = at - currentBufferPtr;
7917
- const end = start + len;
7918
- 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
7919
8038
  },
7920
8039
  wasm_on_header_value: (p, at, len) => {
7921
8040
  assert$3.strictEqual(currentParser.ptr, p);
7922
- const start = at - currentBufferPtr;
7923
- const end = start + len;
7924
- 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
7925
8043
  },
7926
8044
  wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => {
7927
8045
  assert$3.strictEqual(currentParser.ptr, p);
@@ -7929,9 +8047,8 @@ async function lazyllhttp () {
7929
8047
  },
7930
8048
  wasm_on_body: (p, at, len) => {
7931
8049
  assert$3.strictEqual(currentParser.ptr, p);
7932
- const start = at - currentBufferPtr;
7933
- const end = start + len;
7934
- 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
7935
8052
  },
7936
8053
  wasm_on_message_complete: (p) => {
7937
8054
  assert$3.strictEqual(currentParser.ptr, p);
@@ -7988,9 +8105,9 @@ class Parser {
7988
8105
  setTimeout (value, type) {
7989
8106
  this.timeoutType = type;
7990
8107
  if (value !== this.timeoutValue) {
7991
- clearTimeout(this.timeout);
8108
+ timers.clearTimeout(this.timeout);
7992
8109
  if (value) {
7993
- this.timeout = setTimeout(onParserTimeout, value, this);
8110
+ this.timeout = timers.setTimeout(onParserTimeout, value, this);
7994
8111
  // istanbul ignore else: only for jest
7995
8112
  if (this.timeout.unref) {
7996
8113
  this.timeout.unref();
@@ -8106,7 +8223,7 @@ class Parser {
8106
8223
  this.llhttp.llhttp_free(this.ptr);
8107
8224
  this.ptr = null;
8108
8225
 
8109
- clearTimeout(this.timeout);
8226
+ timers.clearTimeout(this.timeout);
8110
8227
  this.timeout = null;
8111
8228
  this.timeoutValue = null;
8112
8229
  this.timeoutType = null;
@@ -12585,7 +12702,11 @@ function requireHeaders () {
12585
12702
 
12586
12703
  // 2. Append (name, value) to list.
12587
12704
  if (exists) {
12588
- 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
+ });
12589
12710
  } else {
12590
12711
  this[kHeadersMap].set(lowercaseName, { name, value });
12591
12712
  }
@@ -20595,6 +20716,11 @@ function requireUndici () {
20595
20716
  undici.getCookies = getCookies;
20596
20717
  undici.getSetCookies = getSetCookies;
20597
20718
  undici.setCookie = setCookie;
20719
+
20720
+ const { parseMIMEType, serializeAMimeType } = requireDataURL();
20721
+
20722
+ undici.parseMIMEType = parseMIMEType;
20723
+ undici.serializeAMimeType = serializeAMimeType;
20598
20724
  }
20599
20725
 
20600
20726
  if (nodeMajor >= 18 && hasCrypto) {
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
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "1.0.5",
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.2.4"
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",