@sveltejs/adapter-netlify 7.0.0-next.2 → 7.0.0-next.3
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/package.json +3 -2
- package/utils.js +78 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-netlify",
|
|
3
|
-
"version": "7.0.0-next.
|
|
3
|
+
"version": "7.0.0-next.3",
|
|
4
4
|
"description": "A SvelteKit adapter that creates a Netlify app",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adapter",
|
|
@@ -29,6 +29,7 @@
|
|
|
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
|
],
|
|
@@ -42,7 +43,7 @@
|
|
|
42
43
|
"@types/node": "^22.19.19",
|
|
43
44
|
"typescript": "^6.0.3",
|
|
44
45
|
"vitest": "^4.1.9",
|
|
45
|
-
"@sveltejs/kit": "^3.0.0-next.
|
|
46
|
+
"@sveltejs/kit": "^3.0.0-next.8"
|
|
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
|
+
}
|