@sveltejs/adapter-netlify 7.0.0-next.2 → 7.0.0-next.4

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/files/edge.js CHANGED
@@ -19,10 +19,8 @@ const initialized = server.init({
19
19
  });
20
20
  /** @type {import('@netlify/edge-functions').EdgeFunction} */
21
21
  async function handler(request, context) {
22
- if (!origin) {
23
- origin = new URL(request.url).origin;
24
- await initialized;
25
- }
22
+ if (!origin) origin = new URL(request.url).origin;
23
+ await initialized;
26
24
  return server.respond(request, {
27
25
  platform: { context },
28
26
  getClientAddress() {
package/index.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  import { Adapter } from '@sveltejs/kit';
2
2
  import './ambient.d.ts';
3
3
 
4
- export default function plugin(opts?: { split?: boolean; edge?: boolean }): Adapter;
4
+ export interface AdapterOptions {
5
+ /**
6
+ * If `true`, your app will be deployed as a [Netlify Edge Function](https://docs.netlify.com/build/edge-functions/overview/) rather than the standard Node-based function.
7
+ * @default false
8
+ */
9
+ edge?: boolean;
10
+ /**
11
+ * If `true`, your app will be split into multiple functions instead of a single one for the entire app.
12
+ *
13
+ * If `edge` is `true`, this option cannot be used.
14
+ * @default false
15
+ */
16
+ split?: boolean;
17
+ }
18
+
19
+ export default function plugin(opts?: AdapterOptions): Adapter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/adapter-netlify",
3
- "version": "7.0.0-next.2",
3
+ "version": "7.0.0-next.4",
4
4
  "description": "A SvelteKit adapter that creates a Netlify app",
5
5
  "keywords": [
6
6
  "adapter",
@@ -29,20 +29,21 @@
29
29
  "files": [
30
30
  "files",
31
31
  "index.js",
32
+ "utils.js",
32
33
  "index.d.ts",
33
34
  "ambient.d.ts"
34
35
  ],
35
36
  "dependencies": {
36
37
  "@iarna/toml": "^2.2.5",
37
38
  "@netlify/functions": "^5.3.0",
38
- "rolldown": "^1.1.2"
39
+ "rolldown": "^1.2.0"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@netlify/edge-functions": "^3.0.8",
42
43
  "@types/node": "^22.19.19",
43
44
  "typescript": "^6.0.3",
44
- "vitest": "^4.1.9",
45
- "@sveltejs/kit": "^3.0.0-next.7"
45
+ "vitest": "^4.1.10",
46
+ "@sveltejs/kit": "^3.0.0-next.12"
46
47
  },
47
48
  "peerDependencies": {
48
49
  "@sveltejs/kit": "^2.31.0"
package/utils.js ADDED
@@ -0,0 +1,78 @@
1
+ import { resolve } from 'node:path';
2
+ import process from 'node:process';
3
+
4
+ /**
5
+ * @typedef {{ rest: boolean, dynamic: boolean, content: string }} RouteSegment
6
+ */
7
+
8
+ /**
9
+ * @typedef {{
10
+ * build?: { publish?: string }
11
+ * functions?: { node_bundler?: 'zisi' | 'esbuild' }
12
+ * }} NetlifyConfig
13
+ */
14
+
15
+ /**
16
+ * @param {RouteSegment[]} a
17
+ * @param {RouteSegment[]} b
18
+ * @returns {boolean}
19
+ */
20
+ export function matches(a, b) {
21
+ if (a[0] && b[0]) {
22
+ if (b[0].rest) {
23
+ if (b.length === 1) return true;
24
+
25
+ const next_b = b.slice(1);
26
+
27
+ for (let i = 0; i < a.length; i += 1) {
28
+ if (matches(a.slice(i), next_b)) return true;
29
+ }
30
+
31
+ return false;
32
+ }
33
+
34
+ if (!b[0].dynamic) {
35
+ if (!a[0].dynamic && a[0].content !== b[0].content) return false;
36
+ }
37
+
38
+ if (a.length === 1 && b.length === 1) return true;
39
+ return matches(a.slice(1), b.slice(1));
40
+ } else if (a[0]) {
41
+ return a.length === 1 && a[0].rest;
42
+ } else {
43
+ return b.length === 1 && b[0].rest;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * @param {NetlifyConfig | null} netlify_config
49
+ * @param {import('@sveltejs/kit').Builder} builder
50
+ * @returns {string | undefined}
51
+ */
52
+ export function get_publish_directory(netlify_config, builder) {
53
+ if (netlify_config) {
54
+ if (!netlify_config.build?.publish) {
55
+ builder.log.minor('No publish directory specified in netlify.toml, using default');
56
+ return;
57
+ }
58
+
59
+ if (resolve(netlify_config.build.publish) === process.cwd()) {
60
+ throw new Error(
61
+ 'The publish directory cannot be set to the site root. Please change it to another value such as "build" in netlify.toml.'
62
+ );
63
+ }
64
+ return netlify_config.build.publish;
65
+ }
66
+
67
+ builder.log.warn(
68
+ 'No netlify.toml found. Using default publish directory. Consult https://svelte.dev/docs/kit/adapter-netlify#usage for more details'
69
+ );
70
+ }
71
+
72
+ /**
73
+ * @param {*} value
74
+ * @returns {string}
75
+ */
76
+ export function s(value) {
77
+ return JSON.stringify(value, null, '\t');
78
+ }