-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathutils.js
More file actions
78 lines (66 loc) · 1.82 KB
/
Copy pathutils.js
File metadata and controls
78 lines (66 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import { resolve } from 'node:path';
import process from 'node:process';
/**
* @typedef {{ rest: boolean, dynamic: boolean, content: string }} RouteSegment
*/
/**
* @typedef {{
* build?: { publish?: string }
* functions?: { node_bundler?: 'zisi' | 'esbuild' }
* }} NetlifyConfig
*/
/**
* @param {RouteSegment[]} a
* @param {RouteSegment[]} b
* @returns {boolean}
*/
export function matches(a, b) {
if (a[0] && b[0]) {
if (b[0].rest) {
if (b.length === 1) return true;
const next_b = b.slice(1);
for (let i = 0; i < a.length; i += 1) {
if (matches(a.slice(i), next_b)) return true;
}
return false;
}
if (!b[0].dynamic) {
if (!a[0].dynamic && a[0].content !== b[0].content) return false;
}
if (a.length === 1 && b.length === 1) return true;
return matches(a.slice(1), b.slice(1));
} else if (a[0]) {
return a.length === 1 && a[0].rest;
} else {
return b.length === 1 && b[0].rest;
}
}
/**
* @param {NetlifyConfig | null} netlify_config
* @param {import('@sveltejs/kit').Builder} builder
* @returns {string | undefined}
*/
export function get_publish_directory(netlify_config, builder) {
if (netlify_config) {
if (!netlify_config.build?.publish) {
builder.log.minor('No publish directory specified in netlify.toml, using default');
return;
}
if (resolve(netlify_config.build.publish) === process.cwd()) {
throw new Error(
'The publish directory cannot be set to the site root. Please change it to another value such as "build" in netlify.toml.'
);
}
return netlify_config.build.publish;
}
builder.log.warn(
'No netlify.toml found. Using default publish directory. Consult https://svelte.dev/docs/kit/adapter-netlify#usage for more details'
);
}
/**
* @param {*} value
* @returns {string}
*/
export function s(value) {
return JSON.stringify(value, null, '\t');
}