-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathutils.js
More file actions
51 lines (44 loc) · 1.92 KB
/
utils.js
File metadata and controls
51 lines (44 loc) · 1.92 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
import process from 'node:process';
/**
* @param {import('wrangler').Unstable_Config} wrangler_config
* @returns {boolean}
*/
export function is_building_for_cloudflare_pages(wrangler_config) {
if (process.env.CF_PAGES || wrangler_config.pages_build_output_dir) {
return true;
}
if (!!process.env.WORKERS_CI || wrangler_config.main || wrangler_config.assets) {
return false;
}
return true;
}
/**
* @param {import('wrangler').Unstable_Config} wrangler_config
*/
export function validate_worker_settings(wrangler_config) {
// we don't support workers sites
if (wrangler_config.site) {
throw new Error(
`You must remove all \`site\` keys in ${wrangler_config.configPath}. Consult https://svelte.dev/docs/kit/adapter-cloudflare#Migrating-from-Workers-Sites`
);
}
// we need the `assets.directory` key so that the static assets are deployed
if ((wrangler_config.main || wrangler_config.assets) && !wrangler_config.assets?.directory) {
throw new Error(
`You must specify the \`assets.directory\` key in ${wrangler_config.configPath}. Consult https://developers.cloudflare.com/workers/static-assets/binding/#directory`
);
}
// we need the `assets.binding` key so that the Worker can access the static assets
if (wrangler_config.main && !wrangler_config.assets?.binding) {
throw new Error(
`You must specify the \`assets.binding\` key in ${wrangler_config.configPath} before deploying your Worker. Consult https://developers.cloudflare.com/workers/static-assets/binding/#binding`
);
}
// the user might have forgot the `main` key or should remove the `assets.binding`
// key to deploy static assets without a Worker
if (!wrangler_config.main && wrangler_config.assets?.binding) {
throw new Error(
`You must set the \`main\` key in ${wrangler_config.configPath} if you want to deploy a Worker alongside your static assets or remove the \`assets.binding\` key if you only want to deploy static assets.`
);
}
}