@sveltejs/adapter-netlify 1.0.0-next.37 → 1.0.0-next.40

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
@@ -51,7 +51,7 @@ During compilation, redirect rules are automatically appended to your `_redirect
51
51
  ### Using Netlify Forms
52
52
 
53
53
  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!)
54
- 2. Netlify's build bot parses your HTML files at deploy time, which means your form must be [prerendered](https://kit.svelte.dev/docs#ssr-and-javascript-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.
54
+ 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.
55
55
  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.
56
56
 
57
57
  ### Using Netlify Functions
@@ -2,8 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var handler = require('./handler-bc05d78e.js');
6
- require('./server/app.js');
5
+ require('./shims-24e5b259.js');
6
+ var app_js = require('./server/app.js');
7
7
  require('node:http');
8
8
  require('node:https');
9
9
  require('node:zlib');
@@ -12,6 +12,82 @@ require('node:util');
12
12
  require('node:url');
13
13
  require('net');
14
14
 
15
+ /**
16
+ *
17
+ * @param {import('@sveltejs/kit').SSRManifest} manifest
18
+ * @returns {import('@netlify/functions').Handler}
19
+ */
20
+ function init(manifest) {
21
+ /** @type {import('@sveltejs/kit').App} */
22
+ const app = new app_js.App(manifest);
15
23
 
24
+ return async (event) => {
25
+ const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
16
26
 
17
- exports.init = handler.init;
27
+ const encoding = isBase64Encoded ? 'base64' : 'utf-8';
28
+ const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
29
+
30
+ const rendered = await app.render({
31
+ url: rawUrl,
32
+ method: httpMethod,
33
+ headers,
34
+ rawBody
35
+ });
36
+
37
+ if (!rendered) {
38
+ return {
39
+ statusCode: 404,
40
+ body: 'Not found'
41
+ };
42
+ }
43
+
44
+ const partial_response = {
45
+ statusCode: rendered.status,
46
+ ...split_headers(rendered.headers)
47
+ };
48
+
49
+ if (rendered.body instanceof Uint8Array) {
50
+ // Function responses should be strings (or undefined), and responses with binary
51
+ // content should be base64 encoded and set isBase64Encoded to true.
52
+ // https://github.com/netlify/functions/blob/main/src/function/response.ts
53
+ return {
54
+ ...partial_response,
55
+ isBase64Encoded: true,
56
+ body: Buffer.from(rendered.body).toString('base64')
57
+ };
58
+ }
59
+
60
+ return {
61
+ ...partial_response,
62
+ body: rendered.body
63
+ };
64
+ };
65
+ }
66
+
67
+ /**
68
+ * Splits headers into two categories: single value and multi value
69
+ * @param {Record<string, string | string[]>} headers
70
+ * @returns {{
71
+ * headers: Record<string, string>,
72
+ * multiValueHeaders: Record<string, string[]>
73
+ * }}
74
+ */
75
+ function split_headers(headers) {
76
+ /** @type {Record<string, string>} */
77
+ const h = {};
78
+
79
+ /** @type {Record<string, string[]>} */
80
+ const m = {};
81
+
82
+ for (const key in headers) {
83
+ const value = headers[key];
84
+ const target = Array.isArray(value) ? m : h;
85
+ target[key] = value;
86
+ }
87
+ return {
88
+ headers: h,
89
+ multiValueHeaders: m
90
+ };
91
+ }
92
+
93
+ exports.init = init;
@@ -3,7 +3,7 @@
3
3
  require('node:fs');
4
4
  require('node:path');
5
5
  var node_worker_threads = require('node:worker_threads');
6
- var handler = require('./handler-bc05d78e.js');
6
+ var shims = require('./shims-24e5b259.js');
7
7
  require('node:http');
8
8
  require('node:https');
9
9
  require('node:zlib');
@@ -11,7 +11,6 @@ require('node:stream');
11
11
  require('node:util');
12
12
  require('node:url');
13
13
  require('net');
14
- require('./server/app.js');
15
14
 
16
15
  globalThis.DOMException || (() => {
17
16
  const port = new node_worker_threads.MessageChannel().port1;
@@ -371,7 +370,7 @@ async function toFormData(Body, ct) {
371
370
  let contentType;
372
371
  let filename;
373
372
  const entryChunks = [];
374
- const formData = new handler.FormData();
373
+ const formData = new shims.FormData();
375
374
 
376
375
  const onPartData = ui8a => {
377
376
  entryValue += decoder.decode(ui8a, {stream: true});
@@ -382,7 +381,7 @@ async function toFormData(Body, ct) {
382
381
  };
383
382
 
384
383
  const appendFileToFormData = () => {
385
- const file = new handler.File(entryChunks, filename, {type: contentType});
384
+ const file = new shims.File(entryChunks, filename, {type: contentType});
386
385
  formData.append(entryName, file);
387
386
  };
388
387
 
@@ -7,7 +7,6 @@ var Stream = require('node:stream');
7
7
  var node_util = require('node:util');
8
8
  var node_url = require('node:url');
9
9
  var net = require('net');
10
- var app_js = require('./server/app.js');
11
10
 
12
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
12
 
@@ -4850,7 +4849,7 @@ class Body {
4850
4849
  return formData;
4851
4850
  }
4852
4851
 
4853
- const {toFormData} = await Promise.resolve().then(function () { return require('./multipart-parser-b87ea3e5.js'); });
4852
+ const {toFormData} = await Promise.resolve().then(function () { return require('./multipart-parser-52bc5518.js'); });
4854
4853
  return toFormData(this.body, ct);
4855
4854
  }
4856
4855
 
@@ -6504,18 +6503,22 @@ function __fetch_polyfill() {
6504
6503
  Object.defineProperties(globalThis, {
6505
6504
  fetch: {
6506
6505
  enumerable: true,
6506
+ configurable: true,
6507
6507
  value: fetch
6508
6508
  },
6509
6509
  Response: {
6510
6510
  enumerable: true,
6511
+ configurable: true,
6511
6512
  value: Response
6512
6513
  },
6513
6514
  Request: {
6514
6515
  enumerable: true,
6516
+ configurable: true,
6515
6517
  value: Request
6516
6518
  },
6517
6519
  Headers: {
6518
6520
  enumerable: true,
6521
+ configurable: true,
6519
6522
  value: Headers
6520
6523
  }
6521
6524
  });
@@ -6523,78 +6526,5 @@ function __fetch_polyfill() {
6523
6526
 
6524
6527
  __fetch_polyfill();
6525
6528
 
6526
- function init(manifest) {
6527
- const app = new app_js.App(manifest);
6528
-
6529
- return async (event) => {
6530
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
6531
-
6532
- const encoding = isBase64Encoded ? 'base64' : headers['content-encoding'] || 'utf-8';
6533
- const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
6534
-
6535
- const rendered = await app.render({
6536
- url: rawUrl,
6537
- method: httpMethod,
6538
- headers,
6539
- rawBody
6540
- });
6541
-
6542
- if (!rendered) {
6543
- return {
6544
- statusCode: 404,
6545
- body: 'Not found'
6546
- };
6547
- }
6548
-
6549
- const partial_response = {
6550
- statusCode: rendered.status,
6551
- ...split_headers(rendered.headers)
6552
- };
6553
-
6554
- if (rendered.body instanceof Uint8Array) {
6555
- // Function responses should be strings (or undefined), and responses with binary
6556
- // content should be base64 encoded and set isBase64Encoded to true.
6557
- // https://github.com/netlify/functions/blob/main/src/function/response.ts
6558
- return {
6559
- ...partial_response,
6560
- isBase64Encoded: true,
6561
- body: Buffer.from(rendered.body).toString('base64')
6562
- };
6563
- }
6564
-
6565
- return {
6566
- ...partial_response,
6567
- body: rendered.body
6568
- };
6569
- };
6570
- }
6571
-
6572
- /**
6573
- * Splits headers into two categories: single value and multi value
6574
- * @param {Record<string, string | string[]>} headers
6575
- * @returns {{
6576
- * headers: Record<string, string>,
6577
- * multiValueHeaders: Record<string, string[]>
6578
- * }}
6579
- */
6580
- function split_headers(headers) {
6581
- /** @type {Record<string, string>} */
6582
- const h = {};
6583
-
6584
- /** @type {Record<string, string[]>} */
6585
- const m = {};
6586
-
6587
- for (const key in headers) {
6588
- const value = headers[key];
6589
- const target = Array.isArray(value) ? m : h;
6590
- target[key] = value;
6591
- }
6592
- return {
6593
- headers: h,
6594
- multiValueHeaders: m
6595
- };
6596
- }
6597
-
6598
6529
  exports.File = File;
6599
6530
  exports.FormData = FormData;
6600
- exports.init = init;
@@ -0,0 +1,11 @@
1
+ 'use strict';
2
+
3
+ require('./shims-24e5b259.js');
4
+ require('node:http');
5
+ require('node:https');
6
+ require('node:zlib');
7
+ require('node:stream');
8
+ require('node:util');
9
+ require('node:url');
10
+ require('net');
11
+
@@ -1,5 +1,5 @@
1
- export { i as init } from './handler-5924cdbc.js';
2
- import './server/app.js';
1
+ import './shims-c8fba98f.js';
2
+ import { App } from './server/app.js';
3
3
  import 'node:http';
4
4
  import 'node:https';
5
5
  import 'node:zlib';
@@ -7,3 +7,83 @@ import 'node:stream';
7
7
  import 'node:util';
8
8
  import 'node:url';
9
9
  import 'net';
10
+
11
+ /**
12
+ *
13
+ * @param {import('@sveltejs/kit').SSRManifest} manifest
14
+ * @returns {import('@netlify/functions').Handler}
15
+ */
16
+ function init(manifest) {
17
+ /** @type {import('@sveltejs/kit').App} */
18
+ const app = new App(manifest);
19
+
20
+ return async (event) => {
21
+ const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
22
+
23
+ const encoding = isBase64Encoded ? 'base64' : 'utf-8';
24
+ const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
25
+
26
+ const rendered = await app.render({
27
+ url: rawUrl,
28
+ method: httpMethod,
29
+ headers,
30
+ rawBody
31
+ });
32
+
33
+ if (!rendered) {
34
+ return {
35
+ statusCode: 404,
36
+ body: 'Not found'
37
+ };
38
+ }
39
+
40
+ const partial_response = {
41
+ statusCode: rendered.status,
42
+ ...split_headers(rendered.headers)
43
+ };
44
+
45
+ if (rendered.body instanceof Uint8Array) {
46
+ // Function responses should be strings (or undefined), and responses with binary
47
+ // content should be base64 encoded and set isBase64Encoded to true.
48
+ // https://github.com/netlify/functions/blob/main/src/function/response.ts
49
+ return {
50
+ ...partial_response,
51
+ isBase64Encoded: true,
52
+ body: Buffer.from(rendered.body).toString('base64')
53
+ };
54
+ }
55
+
56
+ return {
57
+ ...partial_response,
58
+ body: rendered.body
59
+ };
60
+ };
61
+ }
62
+
63
+ /**
64
+ * Splits headers into two categories: single value and multi value
65
+ * @param {Record<string, string | string[]>} headers
66
+ * @returns {{
67
+ * headers: Record<string, string>,
68
+ * multiValueHeaders: Record<string, string[]>
69
+ * }}
70
+ */
71
+ function split_headers(headers) {
72
+ /** @type {Record<string, string>} */
73
+ const h = {};
74
+
75
+ /** @type {Record<string, string[]>} */
76
+ const m = {};
77
+
78
+ for (const key in headers) {
79
+ const value = headers[key];
80
+ const target = Array.isArray(value) ? m : h;
81
+ target[key] = value;
82
+ }
83
+ return {
84
+ headers: h,
85
+ multiValueHeaders: m
86
+ };
87
+ }
88
+
89
+ export { init };
@@ -1,7 +1,7 @@
1
1
  import 'node:fs';
2
2
  import 'node:path';
3
3
  import { MessageChannel } from 'node:worker_threads';
4
- import { F as FormData, a as File } from './handler-5924cdbc.js';
4
+ import { F as FormData, a as File } from './shims-c8fba98f.js';
5
5
  import 'node:http';
6
6
  import 'node:https';
7
7
  import 'node:zlib';
@@ -9,7 +9,6 @@ import 'node:stream';
9
9
  import 'node:util';
10
10
  import 'node:url';
11
11
  import 'net';
12
- import './server/app.js';
13
12
 
14
13
  globalThis.DOMException || (() => {
15
14
  const port = new MessageChannel().port1;
@@ -5,7 +5,6 @@ import Stream, { PassThrough, pipeline } from 'node:stream';
5
5
  import { deprecate, types } from 'node:util';
6
6
  import { format } from 'node:url';
7
7
  import { isIP } from 'net';
8
- import { App } from './server/app.js';
9
8
 
10
9
  /**
11
10
  * Returns a `Buffer` instance from the given data URI `uri`.
@@ -4841,7 +4840,7 @@ class Body {
4841
4840
  return formData;
4842
4841
  }
4843
4842
 
4844
- const {toFormData} = await import('./multipart-parser-1104e57c.js');
4843
+ const {toFormData} = await import('./multipart-parser-a360c9ae.js');
4845
4844
  return toFormData(this.body, ct);
4846
4845
  }
4847
4846
 
@@ -6495,18 +6494,22 @@ function __fetch_polyfill() {
6495
6494
  Object.defineProperties(globalThis, {
6496
6495
  fetch: {
6497
6496
  enumerable: true,
6497
+ configurable: true,
6498
6498
  value: fetch
6499
6499
  },
6500
6500
  Response: {
6501
6501
  enumerable: true,
6502
+ configurable: true,
6502
6503
  value: Response
6503
6504
  },
6504
6505
  Request: {
6505
6506
  enumerable: true,
6507
+ configurable: true,
6506
6508
  value: Request
6507
6509
  },
6508
6510
  Headers: {
6509
6511
  enumerable: true,
6512
+ configurable: true,
6510
6513
  value: Headers
6511
6514
  }
6512
6515
  });
@@ -6514,76 +6517,4 @@ function __fetch_polyfill() {
6514
6517
 
6515
6518
  __fetch_polyfill();
6516
6519
 
6517
- function init(manifest) {
6518
- const app = new App(manifest);
6519
-
6520
- return async (event) => {
6521
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
6522
-
6523
- const encoding = isBase64Encoded ? 'base64' : headers['content-encoding'] || 'utf-8';
6524
- const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
6525
-
6526
- const rendered = await app.render({
6527
- url: rawUrl,
6528
- method: httpMethod,
6529
- headers,
6530
- rawBody
6531
- });
6532
-
6533
- if (!rendered) {
6534
- return {
6535
- statusCode: 404,
6536
- body: 'Not found'
6537
- };
6538
- }
6539
-
6540
- const partial_response = {
6541
- statusCode: rendered.status,
6542
- ...split_headers(rendered.headers)
6543
- };
6544
-
6545
- if (rendered.body instanceof Uint8Array) {
6546
- // Function responses should be strings (or undefined), and responses with binary
6547
- // content should be base64 encoded and set isBase64Encoded to true.
6548
- // https://github.com/netlify/functions/blob/main/src/function/response.ts
6549
- return {
6550
- ...partial_response,
6551
- isBase64Encoded: true,
6552
- body: Buffer.from(rendered.body).toString('base64')
6553
- };
6554
- }
6555
-
6556
- return {
6557
- ...partial_response,
6558
- body: rendered.body
6559
- };
6560
- };
6561
- }
6562
-
6563
- /**
6564
- * Splits headers into two categories: single value and multi value
6565
- * @param {Record<string, string | string[]>} headers
6566
- * @returns {{
6567
- * headers: Record<string, string>,
6568
- * multiValueHeaders: Record<string, string[]>
6569
- * }}
6570
- */
6571
- function split_headers(headers) {
6572
- /** @type {Record<string, string>} */
6573
- const h = {};
6574
-
6575
- /** @type {Record<string, string[]>} */
6576
- const m = {};
6577
-
6578
- for (const key in headers) {
6579
- const value = headers[key];
6580
- const target = Array.isArray(value) ? m : h;
6581
- target[key] = value;
6582
- }
6583
- return {
6584
- headers: h,
6585
- multiValueHeaders: m
6586
- };
6587
- }
6588
-
6589
- export { FormData as F, File as a, init as i };
6520
+ export { FormData as F, File as a };
@@ -0,0 +1,8 @@
1
+ import './shims-c8fba98f.js';
2
+ import 'node:http';
3
+ import 'node:https';
4
+ import 'node:zlib';
5
+ import 'node:stream';
6
+ import 'node:util';
7
+ import 'node:url';
8
+ import 'net';
package/index.js CHANGED
@@ -129,7 +129,13 @@ export default function ({ split = false } = {}) {
129
129
  builder.copy('_redirects', redirect_file);
130
130
  appendFileSync(redirect_file, `\n\n${redirects.join('\n')}`);
131
131
 
132
- // TODO write a _headers file that makes client-side assets immutable
132
+ builder.log.minor('Writing custom headers...');
133
+ const headers_file = join(publish, '_headers');
134
+ builder.copy('_headers', headers_file);
135
+ appendFileSync(
136
+ headers_file,
137
+ `\n\n/${builder.appDir}/*\n cache-control: public\n cache-control: immutable\n cache-control: max-age=31536000\n`
138
+ );
133
139
  }
134
140
  };
135
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "1.0.0-next.37",
3
+ "version": "1.0.0-next.40",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -27,10 +27,11 @@
27
27
  "tiny-glob": "^0.2.9"
28
28
  },
29
29
  "devDependencies": {
30
+ "@netlify/functions": "^0.10.0",
30
31
  "@rollup/plugin-commonjs": "^21.0.0",
31
32
  "@rollup/plugin-json": "^4.1.0",
32
33
  "@rollup/plugin-node-resolve": "^13.0.5",
33
- "@sveltejs/kit": "1.0.0-next.208",
34
+ "@sveltejs/kit": "1.0.0-next.233",
34
35
  "rimraf": "^3.0.2",
35
36
  "rollup": "^2.58.0"
36
37
  },