@sveltejs/adapter-netlify 1.0.3 → 1.0.5

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/README.md CHANGED
@@ -2,113 +2,11 @@
2
2
 
3
3
  A SvelteKit adapter that creates a Netlify app.
4
4
 
5
- If you're using [adapter-auto](../adapter-auto), you don't need to install this unless you need to specify Netlify-specific options, since it's already included.
5
+ If you're using [adapter-auto](https://kit.svelte.dev/docs/adapter-auto), you don't need to install this unless you need to specify Netlify-specific options, since it's already included.
6
6
 
7
- ## Installation
7
+ ## Docs
8
8
 
9
- ```bash
10
- npm i -D @sveltejs/adapter-netlify
11
- ```
12
-
13
- You can then configure it inside of `svelte.config.js`:
14
-
15
- ```js
16
- import adapter from '@sveltejs/adapter-netlify';
17
-
18
- export default {
19
- kit: {
20
- // default options are shown
21
- adapter: adapter({
22
- // if true, will create a Netlify Edge Function rather
23
- // than using standard Node-based functions
24
- edge: false,
25
-
26
- // if true, will split your app into multiple functions
27
- // instead of creating a single one for the entire app.
28
- // if `edge` is true, this option cannot be used
29
- split: false
30
- })
31
- }
32
- };
33
- ```
34
-
35
- Then, make sure you have a [netlify.toml](https://docs.netlify.com/configure-builds/file-based-configuration) file in the project root. This will determine where to write static assets based on the `build.publish` settings, as per this sample configuration:
36
-
37
- ```toml
38
- [build]
39
- command = "npm run build"
40
- publish = "build"
41
- ```
42
-
43
- If the `netlify.toml` file or the `build.publish` value is missing, a default value of `"build"` will be used. Note that if you have set the publish directory in the Netlify UI to something else then you will need to set it in `netlify.toml` too, or use the default value of `"build"`.
44
-
45
- ### Node version
46
-
47
- New projects will use Node 16 by default. However, if you're upgrading a project you created a while ago it may be stuck on an older version. See [the Netlify docs](https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript) for details on manually specifying Node 16 or newer.
48
-
49
- ## Netlify Edge Functions (beta)
50
-
51
- SvelteKit supports the beta release of [Netlify Edge Functions](https://docs.netlify.com/netlify-labs/experimental-features/edge-functions/). If you pass the option `edge: true` to the `adapter` function, server-side rendering will happen in a Deno-based edge function that's deployed close to the site visitor. If set to `false` (the default), the site will deploy to standard Node-based Netlify Functions.
52
-
53
- ```js
54
- import adapter from '@sveltejs/adapter-netlify';
55
-
56
- export default {
57
- kit: {
58
- adapter: adapter({
59
- // will create a Netlify Edge Function using Deno-based
60
- // rather than using standard Node-based functions
61
- edge: true
62
- })
63
- }
64
- };
65
- ```
66
-
67
- ## Netlify alternatives to SvelteKit functionality
68
-
69
- You may build your app using functionality provided directly by SvelteKit without relying on any Netlify functionality. Using the SvelteKit versions of these features will allow them to be used in dev mode, tested with integration tests, and to work with other adapters should you ever decide to switch away from Netlify. However, in some scenarios you may find it beneficial to use the Netlify versions of these features. One example would be if you're migrating an app that's already hosted on Netlify to SvelteKit.
70
-
71
- ### Using Netlify Redirect Rules
72
-
73
- During compilation, redirect rules are automatically appended to your `_redirects` file. (If it doesn't exist yet, it will be created.) That means:
74
-
75
- - `[[redirects]]` in `netlify.toml` will never match as `_redirects` has a [higher priority](https://docs.netlify.com/routing/redirects/#rule-processing-order). So always put your rules in the [`_redirects` file](https://docs.netlify.com/routing/redirects/#syntax-for-the-redirects-file).
76
- - `_redirects` shouldn't have any custom "catch all" rules such as `/* /foobar/:splat`. Otherwise the automatically appended rule will never be applied as Netlify is only processing [the first matching rule](https://docs.netlify.com/routing/redirects/#rule-processing-order).
77
-
78
- ### Using Netlify Forms
79
-
80
- 1. Create your Netlify HTML form as described [here](https://docs.netlify.com/forms/setup/#html-forms), e.g. as `/routes/contact.svelte`. (Don't forget to add the hidden `form-name` input element!)
81
- 2. Netlify's build bot parses your HTML files at deploy time, which means your form must be [prerendered](https://kit.svelte.dev/docs/page-options#prerender) as HTML. You can either add `export const prerender = true` to your `contact.svelte` to prerender just that page or set the `kit.prerender.force: true` option to prerender all pages.
82
- 3. If your Netlify form has a [custom success message](https://docs.netlify.com/forms/setup/#success-messages) like `<form netlify ... action="/success">` then ensure the corresponding `/routes/success.svelte` exists and is prerendered.
83
-
84
- ### Using Netlify Functions
85
-
86
- With this adapter, SvelteKit endpoints are hosted as [Netlify Functions](https://docs.netlify.com/functions/overview/). Netlify function handlers have additional context, including [Netlify Identity](https://docs.netlify.com/visitor-access/identity/) information. You can access this context via the `event.platform.context` field inside your hooks and `+page.server` or `+layout.server` endpoints. These are [serverless functions](https://docs.netlify.com/functions/overview/) when the `edge` property is `false` in the adapter config or [edge functions](https://docs.netlify.com/edge-functions/overview/#app) when it is `true`.
87
-
88
- ```js
89
- // +page.server.js
90
- export const load = async (event) => {
91
- const context = event.platform.context;
92
- console.log(context); // shows up in your functions log in the Netlify app
93
- };
94
- ```
95
-
96
- Additionally, you can add your own Netlify functions by creating a directory for them and adding the configuration to your `netlify.toml` file. For example:
97
-
98
- ```toml
99
- [build]
100
- command = "npm run build"
101
- publish = "build"
102
-
103
- [functions]
104
- directory = "functions"
105
- ```
106
-
107
- ## Troubleshooting
108
-
109
- ### Accessing the file system
110
-
111
- You can't access the file system through methods like `fs.readFileSync` in Serverless/Edge environments. If you need to access files that way, do that during building the app through [prerendering](https://kit.svelte.dev/docs/page-options#prerender). If you have a blog for example and don't want to manage your content through a CMS, then you need to prerender the content (or prerender the endpoint from which you get it) and redeploy your blog everytime you add new content.
9
+ [Docs](https://kit.svelte.dev/docs/adapter-netlify)
112
10
 
113
11
  ## Changelog
114
12
 
@@ -648,8 +648,23 @@ function ReadableStreamFrom$1 (iterable) {
648
648
  )
649
649
  }
650
650
 
651
+ // The chunk should be a FormData instance and contains
652
+ // all the required methods.
651
653
  function isFormDataLike (chunk) {
652
- return chunk && chunk.constructor && chunk.constructor.name === 'FormData'
654
+ return (chunk &&
655
+ chunk.constructor && chunk.constructor.name === 'FormData' &&
656
+ typeof chunk === 'object' &&
657
+ (typeof chunk.append === 'function' &&
658
+ typeof chunk.delete === 'function' &&
659
+ typeof chunk.get === 'function' &&
660
+ typeof chunk.getAll === 'function' &&
661
+ typeof chunk.has === 'function' &&
662
+ typeof chunk.set === 'function' &&
663
+ typeof chunk.entries === 'function' &&
664
+ typeof chunk.keys === 'function' &&
665
+ typeof chunk.values === 'function' &&
666
+ typeof chunk.forEach === 'function')
667
+ )
653
668
  }
654
669
 
655
670
  const kEnumerableProperty = Object.create(null);
@@ -4461,6 +4476,12 @@ function requireDataURL () {
4461
4476
 
4462
4477
  const encoder = new TextEncoder();
4463
4478
 
4479
+ // Regex
4480
+ const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+-.^_|~A-z0-9]+$/;
4481
+ const HTTP_WHITESPACE_REGEX = /(\u000A|\u000D|\u0009|\u0020)/; // eslint-disable-line
4482
+ // https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
4483
+ const HTTP_QUOTED_STRING_TOKENS = /^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/; // eslint-disable-line
4484
+
4464
4485
  // https://fetch.spec.whatwg.org/#data-url-processor
4465
4486
  /** @param {URL} dataURL */
4466
4487
  function dataURLProcessor (dataURL) {
@@ -4673,7 +4694,7 @@ function requireDataURL () {
4673
4694
  // 4. If type is the empty string or does not solely
4674
4695
  // contain HTTP token code points, then return failure.
4675
4696
  // https://mimesniff.spec.whatwg.org/#http-token-code-point
4676
- if (type.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(type)) {
4697
+ if (type.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(type)) {
4677
4698
  return 'failure'
4678
4699
  }
4679
4700
 
@@ -4700,7 +4721,7 @@ function requireDataURL () {
4700
4721
 
4701
4722
  // 9. If subtype is the empty string or does not solely
4702
4723
  // contain HTTP token code points, then return failure.
4703
- if (subtype.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(subtype)) {
4724
+ if (subtype.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(subtype)) {
4704
4725
  return 'failure'
4705
4726
  }
4706
4727
 
@@ -4714,9 +4735,7 @@ function requireDataURL () {
4714
4735
  /** @type {Map<string, string>} */
4715
4736
  parameters: new Map(),
4716
4737
  // https://mimesniff.spec.whatwg.org/#mime-type-essence
4717
- get essence () {
4718
- return `${this.type}/${this.subtype}`
4719
- }
4738
+ essence: `${type}/${subtype}`
4720
4739
  };
4721
4740
 
4722
4741
  // 11. While position is not past the end of input:
@@ -4728,7 +4747,7 @@ function requireDataURL () {
4728
4747
  // whitespace from input given position.
4729
4748
  collectASequenceOfCodePoints(
4730
4749
  // https://fetch.spec.whatwg.org/#http-whitespace
4731
- (char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char), // eslint-disable-line
4750
+ char => HTTP_WHITESPACE_REGEX.test(char),
4732
4751
  input,
4733
4752
  position
4734
4753
  );
@@ -4811,9 +4830,8 @@ function requireDataURL () {
4811
4830
  // then set mimeType’s parameters[parameterName] to parameterValue.
4812
4831
  if (
4813
4832
  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
4833
+ HTTP_TOKEN_CODEPOINTS.test(parameterName) &&
4834
+ !HTTP_QUOTED_STRING_TOKENS.test(parameterValue) &&
4817
4835
  !mimeType.parameters.has(parameterName)
4818
4836
  ) {
4819
4837
  mimeType.parameters.set(parameterName, parameterValue);
@@ -5615,7 +5633,7 @@ function requireFormdata () {
5615
5633
  lastModified: value.lastModified
5616
5634
  };
5617
5635
 
5618
- value = value instanceof File
5636
+ value = (NativeFile && value instanceof NativeFile) || value instanceof UndiciFile
5619
5637
  ? new File([value], filename, options)
5620
5638
  : new FileLike(value, filename, options);
5621
5639
  }
@@ -6376,7 +6394,7 @@ let Request$1 = class Request {
6376
6394
 
6377
6395
  this.blocking = blocking == null ? false : blocking;
6378
6396
 
6379
- this.reset = reset == null ? false : reset;
6397
+ this.reset = reset == null ? null : reset;
6380
6398
 
6381
6399
  this.host = null;
6382
6400
 
@@ -7926,9 +7944,8 @@ async function lazyllhttp () {
7926
7944
  }
7927
7945
 
7928
7946
  let llhttpInstance = null;
7929
- let llhttpPromise = lazyllhttp()
7930
- .catch(() => {
7931
- });
7947
+ let llhttpPromise = lazyllhttp();
7948
+ llhttpPromise.catch();
7932
7949
 
7933
7950
  let currentParser = null;
7934
7951
  let currentBufferRef = null;
@@ -7964,6 +7981,7 @@ class Parser {
7964
7981
 
7965
7982
  this.keepAlive = '';
7966
7983
  this.contentLength = '';
7984
+ this.connection = '';
7967
7985
  this.maxResponseSize = client[kMaxResponseSize];
7968
7986
  }
7969
7987
 
@@ -8139,6 +8157,8 @@ class Parser {
8139
8157
  const key = this.headers[len - 2];
8140
8158
  if (key.length === 10 && key.toString().toLowerCase() === 'keep-alive') {
8141
8159
  this.keepAlive += buf.toString();
8160
+ } else if (key.length === 10 && key.toString().toLowerCase() === 'connection') {
8161
+ this.connection += buf.toString();
8142
8162
  } else if (key.length === 14 && key.toString().toLowerCase() === 'content-length') {
8143
8163
  this.contentLength += buf.toString();
8144
8164
  }
@@ -8232,7 +8252,11 @@ class Parser {
8232
8252
  assert$3.strictEqual(this.timeoutType, TIMEOUT_HEADERS);
8233
8253
 
8234
8254
  this.statusCode = statusCode;
8235
- this.shouldKeepAlive = shouldKeepAlive;
8255
+ this.shouldKeepAlive = (
8256
+ shouldKeepAlive ||
8257
+ // Override llhttp value which does not allow keepAlive for HEAD.
8258
+ (request.method === 'HEAD' && !socket[kReset] && this.connection.toLowerCase() === 'keep-alive')
8259
+ );
8236
8260
 
8237
8261
  if (this.statusCode >= 200) {
8238
8262
  const bodyTimeout = request.bodyTimeout != null
@@ -8262,7 +8286,7 @@ class Parser {
8262
8286
  this.headers = [];
8263
8287
  this.headersSize = 0;
8264
8288
 
8265
- if (shouldKeepAlive && client[kPipelining]) {
8289
+ if (this.shouldKeepAlive && client[kPipelining]) {
8266
8290
  const keepAliveTimeout = this.keepAlive ? util$b.parseKeepAliveTimeout(this.keepAlive) : null;
8267
8291
 
8268
8292
  if (keepAliveTimeout != null) {
@@ -8292,7 +8316,6 @@ class Parser {
8292
8316
  }
8293
8317
 
8294
8318
  if (request.method === 'HEAD') {
8295
- assert$3(socket[kReset]);
8296
8319
  return 1
8297
8320
  }
8298
8321
 
@@ -8366,6 +8389,7 @@ class Parser {
8366
8389
  this.bytesRead = 0;
8367
8390
  this.contentLength = '';
8368
8391
  this.keepAlive = '';
8392
+ this.connection = '';
8369
8393
 
8370
8394
  assert$3(this.headers.length % 2 === 0);
8371
8395
  this.headers = [];
@@ -8590,8 +8614,6 @@ async function connect$1 (client) {
8590
8614
 
8591
8615
  assert$3(socket);
8592
8616
 
8593
- client[kSocket] = socket;
8594
-
8595
8617
  socket[kNoRef] = false;
8596
8618
  socket[kWriting] = false;
8597
8619
  socket[kReset] = false;
@@ -8607,6 +8629,8 @@ async function connect$1 (client) {
8607
8629
  .on('end', onSocketEnd)
8608
8630
  .on('close', onSocketClose);
8609
8631
 
8632
+ client[kSocket] = socket;
8633
+
8610
8634
  if (channels.connected.hasSubscribers) {
8611
8635
  channels.connected.publish({
8612
8636
  connectParams: {
@@ -8692,7 +8716,7 @@ function _resume (client, sync) {
8692
8716
 
8693
8717
  const socket = client[kSocket];
8694
8718
 
8695
- if (socket) {
8719
+ if (socket && !socket.destroyed) {
8696
8720
  if (client[kSize$4] === 0) {
8697
8721
  if (!socket[kNoRef] && socket.unref) {
8698
8722
  socket.unref();
@@ -8759,7 +8783,7 @@ function _resume (client, sync) {
8759
8783
 
8760
8784
  if (!socket) {
8761
8785
  connect$1(client);
8762
- continue
8786
+ return
8763
8787
  }
8764
8788
 
8765
8789
  if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {
@@ -8899,8 +8923,8 @@ function write (client, request) {
8899
8923
  socket[kReset] = true;
8900
8924
  }
8901
8925
 
8902
- if (reset) {
8903
- socket[kReset] = true;
8926
+ if (reset != null) {
8927
+ socket[kReset] = reset;
8904
8928
  }
8905
8929
 
8906
8930
  if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) {
@@ -12264,7 +12288,7 @@ class ProxyAgent extends DispatcherBase {
12264
12288
 
12265
12289
  this[kRequestTls] = opts.requestTls;
12266
12290
  this[kProxyTls] = opts.proxyTls;
12267
- this[kProxyHeaders] = {};
12291
+ this[kProxyHeaders] = opts.headers || {};
12268
12292
 
12269
12293
  if (opts.auth && opts.token) {
12270
12294
  throw new InvalidArgumentError$1('opts.auth cannot be used in combination with opts.token')
@@ -14554,7 +14578,7 @@ function requireFetch () {
14554
14578
  const { isErrored, isReadable } = util$g;
14555
14579
  const { dataURLProcessor, serializeAMimeType } = requireDataURL();
14556
14580
  const { TransformStream } = require$$13;
14557
- const { getGlobalDispatcher } = requireUndici();
14581
+ const { getGlobalDispatcher } = global$2;
14558
14582
  const { webidl } = requireWebidl();
14559
14583
  const { STATUS_CODES } = require$$2;
14560
14584
 
@@ -16375,8 +16399,6 @@ function requireFetch () {
16375
16399
  body: fetchParams.controller.dispatcher.isMockActive ? request.body && request.body.source : body,
16376
16400
  headers: request.headersList[kHeadersCaseInsensitive],
16377
16401
  maxRedirections: 0,
16378
- bodyTimeout: 300_000,
16379
- headersTimeout: 300_000,
16380
16402
  upgrade: request.mode === 'websocket' ? 'websocket' : undefined
16381
16403
  },
16382
16404
  {
@@ -19554,7 +19576,6 @@ function requireConnection () {
19554
19576
  if (hasRequiredConnection) return connection;
19555
19577
  hasRequiredConnection = 1;
19556
19578
 
19557
- // TODO: crypto isn't available in all environments
19558
19579
  const { randomBytes, createHash } = require$$0$5;
19559
19580
  const diagnosticsChannel = require$$1$2;
19560
19581
  const { uid, states } = requireConstants();
@@ -20192,23 +20213,14 @@ function requireWebsocket () {
20192
20213
  // not throw an exception must increase the bufferedAmount attribute
20193
20214
  // by the length of data’s buffer in bytes.
20194
20215
 
20195
- const ab = new ArrayBuffer(data.byteLength);
20216
+ const ab = Buffer.from(data, data.byteOffset, data.byteLength);
20196
20217
 
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);
20205
-
20206
- const frame = new WebsocketFrameSend(value);
20218
+ const frame = new WebsocketFrameSend(ab);
20207
20219
  const buffer = frame.createFrame(opcodes.BINARY);
20208
20220
 
20209
- this.#bufferedAmount += value.byteLength;
20221
+ this.#bufferedAmount += ab.byteLength;
20210
20222
  socket.write(buffer, () => {
20211
- this.#bufferedAmount -= value.byteLength;
20223
+ this.#bufferedAmount -= ab.byteLength;
20212
20224
  });
20213
20225
  } else if (isBlobLike(data)) {
20214
20226
  // If the WebSocket connection is established, and the WebSocket
@@ -20473,6 +20485,14 @@ function requireUndici () {
20473
20485
  const nodeMajor = Number(nodeVersion[0]);
20474
20486
  const nodeMinor = Number(nodeVersion[1]);
20475
20487
 
20488
+ let hasCrypto;
20489
+ try {
20490
+ require('crypto');
20491
+ hasCrypto = true;
20492
+ } catch {
20493
+ hasCrypto = false;
20494
+ }
20495
+
20476
20496
  Object.assign(Dispatcher.prototype, api$1);
20477
20497
 
20478
20498
  undici.Dispatcher = Dispatcher;
@@ -20577,7 +20597,7 @@ function requireUndici () {
20577
20597
  undici.setCookie = setCookie;
20578
20598
  }
20579
20599
 
20580
- if (nodeMajor >= 18) {
20600
+ if (nodeMajor >= 18 && hasCrypto) {
20581
20601
  const { WebSocket } = requireWebsocket();
20582
20602
 
20583
20603
  undici.WebSocket = WebSocket;
package/index.js CHANGED
@@ -263,7 +263,7 @@ function get_publish_directory(netlify_config, builder) {
263
263
  }
264
264
 
265
265
  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 '
266
+ 'No netlify.toml found. Using default publish directory. Consult https://kit.svelte.dev/docs/adapter-netlify#usage for more details'
267
267
  );
268
268
  }
269
269
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -38,7 +38,7 @@
38
38
  "rollup": "^3.7.0",
39
39
  "typescript": "^4.9.4",
40
40
  "uvu": "^0.5.6",
41
- "@sveltejs/kit": "^1.1.1"
41
+ "@sveltejs/kit": "^1.2.4"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@sveltejs/kit": "^1.0.0"