@sveltejs/adapter-netlify 1.0.0-next.38 → 1.0.0-next.41

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-a3623ede.js');
6
- require('./server/app.js');
5
+ require('./shims-24e5b259.js');
6
+ var APP = require('APP');
7
7
  require('node:http');
8
8
  require('node:https');
9
9
  require('node:zlib');
@@ -12,6 +12,78 @@ require('node:util');
12
12
  require('node:url');
13
13
  require('net');
14
14
 
15
+ /**
16
+ * @param {import('@sveltejs/kit').SSRManifest} manifest
17
+ * @returns {import('@netlify/functions').Handler}
18
+ */
19
+ function init(manifest) {
20
+ const app = new APP.App(manifest);
15
21
 
22
+ return async (event) => {
23
+ const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
16
24
 
17
- exports.init = handler.init;
25
+ const encoding = isBase64Encoded ? 'base64' : 'utf-8';
26
+ const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
27
+
28
+ const rendered = await app.render(
29
+ new Request(rawUrl, {
30
+ method: httpMethod,
31
+ headers: new Headers(headers),
32
+ body: rawBody
33
+ })
34
+ );
35
+
36
+ const partial_response = {
37
+ statusCode: rendered.status,
38
+ ...split_headers(rendered.headers)
39
+ };
40
+
41
+ // TODO this is probably wrong now?
42
+ if (rendered.body instanceof Uint8Array) {
43
+ // Function responses should be strings (or undefined), and responses with binary
44
+ // content should be base64 encoded and set isBase64Encoded to true.
45
+ // https://github.com/netlify/functions/blob/main/src/function/response.ts
46
+ return {
47
+ ...partial_response,
48
+ isBase64Encoded: true,
49
+ body: Buffer.from(rendered.body).toString('base64')
50
+ };
51
+ }
52
+
53
+ return {
54
+ ...partial_response,
55
+ body: await rendered.text()
56
+ };
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Splits headers into two categories: single value and multi value
62
+ * @param {Headers} headers
63
+ * @returns {{
64
+ * headers: Record<string, string>,
65
+ * multiValueHeaders: Record<string, string[]>
66
+ * }}
67
+ */
68
+ function split_headers(headers) {
69
+ /** @type {Record<string, string>} */
70
+ const h = {};
71
+
72
+ /** @type {Record<string, string[]>} */
73
+ const m = {};
74
+
75
+ headers.forEach((value, key) => {
76
+ if (key === 'set-cookie') {
77
+ m[key] = value.split(', ');
78
+ } else {
79
+ h[key] = value;
80
+ }
81
+ });
82
+
83
+ return {
84
+ headers: h,
85
+ multiValueHeaders: m
86
+ };
87
+ }
88
+
89
+ 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-a3623ede.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-e24c3004.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,84 +6526,5 @@ function __fetch_polyfill() {
6523
6526
 
6524
6527
  __fetch_polyfill();
6525
6528
 
6526
- /**
6527
- *
6528
- * @param {import('@sveltejs/kit').SSRManifest} manifest
6529
- * @returns {import('@netlify/functions').Handler}
6530
- */
6531
- function init(manifest) {
6532
- /** @type {import('@sveltejs/kit').App} */
6533
- const app = new app_js.App(manifest);
6534
-
6535
- return async (event) => {
6536
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
6537
-
6538
- const encoding = isBase64Encoded ? 'base64' : 'utf-8';
6539
- const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
6540
-
6541
- const rendered = await app.render({
6542
- url: rawUrl,
6543
- method: httpMethod,
6544
- headers,
6545
- rawBody
6546
- });
6547
-
6548
- if (!rendered) {
6549
- return {
6550
- statusCode: 404,
6551
- body: 'Not found'
6552
- };
6553
- }
6554
-
6555
- const partial_response = {
6556
- statusCode: rendered.status,
6557
- ...split_headers(rendered.headers)
6558
- };
6559
-
6560
- if (rendered.body instanceof Uint8Array) {
6561
- // Function responses should be strings (or undefined), and responses with binary
6562
- // content should be base64 encoded and set isBase64Encoded to true.
6563
- // https://github.com/netlify/functions/blob/main/src/function/response.ts
6564
- return {
6565
- ...partial_response,
6566
- isBase64Encoded: true,
6567
- body: Buffer.from(rendered.body).toString('base64')
6568
- };
6569
- }
6570
-
6571
- return {
6572
- ...partial_response,
6573
- body: rendered.body
6574
- };
6575
- };
6576
- }
6577
-
6578
- /**
6579
- * Splits headers into two categories: single value and multi value
6580
- * @param {Record<string, string | string[]>} headers
6581
- * @returns {{
6582
- * headers: Record<string, string>,
6583
- * multiValueHeaders: Record<string, string[]>
6584
- * }}
6585
- */
6586
- function split_headers(headers) {
6587
- /** @type {Record<string, string>} */
6588
- const h = {};
6589
-
6590
- /** @type {Record<string, string[]>} */
6591
- const m = {};
6592
-
6593
- for (const key in headers) {
6594
- const value = headers[key];
6595
- const target = Array.isArray(value) ? m : h;
6596
- target[key] = value;
6597
- }
6598
- return {
6599
- headers: h,
6600
- multiValueHeaders: m
6601
- };
6602
- }
6603
-
6604
6529
  exports.File = File;
6605
6530
  exports.FormData = FormData;
6606
- 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-1cae7b39.js';
2
- import './server/app.js';
1
+ import './shims-c8fba98f.js';
2
+ import { App } from 'APP';
3
3
  import 'node:http';
4
4
  import 'node:https';
5
5
  import 'node:zlib';
@@ -7,3 +7,79 @@ import 'node:stream';
7
7
  import 'node:util';
8
8
  import 'node:url';
9
9
  import 'net';
10
+
11
+ /**
12
+ * @param {import('@sveltejs/kit').SSRManifest} manifest
13
+ * @returns {import('@netlify/functions').Handler}
14
+ */
15
+ function init(manifest) {
16
+ const app = new App(manifest);
17
+
18
+ return async (event) => {
19
+ const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
20
+
21
+ const encoding = isBase64Encoded ? 'base64' : 'utf-8';
22
+ const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
23
+
24
+ const rendered = await app.render(
25
+ new Request(rawUrl, {
26
+ method: httpMethod,
27
+ headers: new Headers(headers),
28
+ body: rawBody
29
+ })
30
+ );
31
+
32
+ const partial_response = {
33
+ statusCode: rendered.status,
34
+ ...split_headers(rendered.headers)
35
+ };
36
+
37
+ // TODO this is probably wrong now?
38
+ if (rendered.body instanceof Uint8Array) {
39
+ // Function responses should be strings (or undefined), and responses with binary
40
+ // content should be base64 encoded and set isBase64Encoded to true.
41
+ // https://github.com/netlify/functions/blob/main/src/function/response.ts
42
+ return {
43
+ ...partial_response,
44
+ isBase64Encoded: true,
45
+ body: Buffer.from(rendered.body).toString('base64')
46
+ };
47
+ }
48
+
49
+ return {
50
+ ...partial_response,
51
+ body: await rendered.text()
52
+ };
53
+ };
54
+ }
55
+
56
+ /**
57
+ * Splits headers into two categories: single value and multi value
58
+ * @param {Headers} headers
59
+ * @returns {{
60
+ * headers: Record<string, string>,
61
+ * multiValueHeaders: Record<string, string[]>
62
+ * }}
63
+ */
64
+ function split_headers(headers) {
65
+ /** @type {Record<string, string>} */
66
+ const h = {};
67
+
68
+ /** @type {Record<string, string[]>} */
69
+ const m = {};
70
+
71
+ headers.forEach((value, key) => {
72
+ if (key === 'set-cookie') {
73
+ m[key] = value.split(', ');
74
+ } else {
75
+ h[key] = value;
76
+ }
77
+ });
78
+
79
+ return {
80
+ headers: h,
81
+ multiValueHeaders: m
82
+ };
83
+ }
84
+
85
+ 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-1cae7b39.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-b42aadce.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,82 +6517,4 @@ function __fetch_polyfill() {
6514
6517
 
6515
6518
  __fetch_polyfill();
6516
6519
 
6517
- /**
6518
- *
6519
- * @param {import('@sveltejs/kit').SSRManifest} manifest
6520
- * @returns {import('@netlify/functions').Handler}
6521
- */
6522
- function init(manifest) {
6523
- /** @type {import('@sveltejs/kit').App} */
6524
- const app = new App(manifest);
6525
-
6526
- return async (event) => {
6527
- const { httpMethod, headers, rawUrl, body, isBase64Encoded } = event;
6528
-
6529
- const encoding = isBase64Encoded ? 'base64' : 'utf-8';
6530
- const rawBody = typeof body === 'string' ? Buffer.from(body, encoding) : body;
6531
-
6532
- const rendered = await app.render({
6533
- url: rawUrl,
6534
- method: httpMethod,
6535
- headers,
6536
- rawBody
6537
- });
6538
-
6539
- if (!rendered) {
6540
- return {
6541
- statusCode: 404,
6542
- body: 'Not found'
6543
- };
6544
- }
6545
-
6546
- const partial_response = {
6547
- statusCode: rendered.status,
6548
- ...split_headers(rendered.headers)
6549
- };
6550
-
6551
- if (rendered.body instanceof Uint8Array) {
6552
- // Function responses should be strings (or undefined), and responses with binary
6553
- // content should be base64 encoded and set isBase64Encoded to true.
6554
- // https://github.com/netlify/functions/blob/main/src/function/response.ts
6555
- return {
6556
- ...partial_response,
6557
- isBase64Encoded: true,
6558
- body: Buffer.from(rendered.body).toString('base64')
6559
- };
6560
- }
6561
-
6562
- return {
6563
- ...partial_response,
6564
- body: rendered.body
6565
- };
6566
- };
6567
- }
6568
-
6569
- /**
6570
- * Splits headers into two categories: single value and multi value
6571
- * @param {Record<string, string | string[]>} headers
6572
- * @returns {{
6573
- * headers: Record<string, string>,
6574
- * multiValueHeaders: Record<string, string[]>
6575
- * }}
6576
- */
6577
- function split_headers(headers) {
6578
- /** @type {Record<string, string>} */
6579
- const h = {};
6580
-
6581
- /** @type {Record<string, string[]>} */
6582
- const m = {};
6583
-
6584
- for (const key in headers) {
6585
- const value = headers[key];
6586
- const target = Array.isArray(value) ? m : h;
6587
- target[key] = value;
6588
- }
6589
- return {
6590
- headers: h,
6591
- multiValueHeaders: m
6592
- };
6593
- }
6594
-
6595
- 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
@@ -50,8 +50,12 @@ export default function ({ split = false } = {}) {
50
50
  /** @type {string[]} */
51
51
  const redirects = [];
52
52
 
53
+ const replace = {
54
+ APP: './server/app.js'
55
+ };
56
+
53
57
  if (esm) {
54
- builder.copy(`${files}/esm`, '.netlify');
58
+ builder.copy(`${files}/esm`, '.netlify', { replace });
55
59
  } else {
56
60
  glob('**/*.js', { cwd: '.netlify/server' }).forEach((file) => {
57
61
  const filepath = `.netlify/server/${file}`;
@@ -60,7 +64,7 @@ export default function ({ split = false } = {}) {
60
64
  writeFileSync(filepath, output);
61
65
  });
62
66
 
63
- builder.copy(`${files}/cjs`, '.netlify');
67
+ builder.copy(`${files}/cjs`, '.netlify', { replace });
64
68
  writeFileSync(join('.netlify', 'package.json'), JSON.stringify({ type: 'commonjs' }));
65
69
  }
66
70
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "1.0.0-next.38",
3
+ "version": "1.0.0-next.41",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -31,7 +31,7 @@
31
31
  "@rollup/plugin-commonjs": "^21.0.0",
32
32
  "@rollup/plugin-json": "^4.1.0",
33
33
  "@rollup/plugin-node-resolve": "^13.0.5",
34
- "@sveltejs/kit": "1.0.0-next.218",
34
+ "@sveltejs/kit": "1.0.0-next.234",
35
35
  "rimraf": "^3.0.2",
36
36
  "rollup": "^2.58.0"
37
37
  },