@sveltejs/adapter-vercel 2.1.1 → 2.2.0
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/index.js +59 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -39,6 +39,12 @@ const plugin = function (defaults = {}) {
|
|
|
39
39
|
builder.rimraf(dir);
|
|
40
40
|
builder.rimraf(tmp);
|
|
41
41
|
|
|
42
|
+
if (fs.existsSync('vercel.json')) {
|
|
43
|
+
const vercel_file = fs.readFileSync('vercel.json', 'utf-8');
|
|
44
|
+
const vercel_config = JSON.parse(vercel_file);
|
|
45
|
+
validate_vercel_json(builder, vercel_config);
|
|
46
|
+
}
|
|
47
|
+
|
|
42
48
|
const files = fileURLToPath(new URL('./files', import.meta.url).href);
|
|
43
49
|
|
|
44
50
|
const dirs = {
|
|
@@ -499,4 +505,57 @@ async function create_function_bundle(builder, entry, dir, config) {
|
|
|
499
505
|
write(`${dir}/package.json`, JSON.stringify({ type: 'module' }));
|
|
500
506
|
}
|
|
501
507
|
|
|
508
|
+
/**
|
|
509
|
+
*
|
|
510
|
+
* @param {import('@sveltejs/kit').Builder} builder
|
|
511
|
+
* @param {any} vercel_config
|
|
512
|
+
*/
|
|
513
|
+
function validate_vercel_json(builder, vercel_config) {
|
|
514
|
+
if (builder.routes.length > 0 && !builder.routes[0].api) {
|
|
515
|
+
// bail — we're on an older SvelteKit version that doesn't
|
|
516
|
+
// populate `route.api.methods`, so we can't check
|
|
517
|
+
// to see if cron paths are valid
|
|
518
|
+
return;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
const crons = /** @type {Array<unknown>} */ (
|
|
522
|
+
Array.isArray(vercel_config?.crons) ? vercel_config.crons : []
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
/** For a route to be considered 'valid', it must be an API route with a GET handler */
|
|
526
|
+
const valid_routes = builder.routes.filter((route) => route.api.methods.includes('GET'));
|
|
527
|
+
|
|
528
|
+
/** @type {Array<string>} */
|
|
529
|
+
const unmatched_paths = [];
|
|
530
|
+
|
|
531
|
+
for (const cron of crons) {
|
|
532
|
+
if (typeof cron !== 'object' || cron === null || !('path' in cron)) {
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const { path } = cron;
|
|
537
|
+
if (typeof path !== 'string') {
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
for (const route of valid_routes) {
|
|
542
|
+
if (route.pattern.test(path)) {
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
unmatched_paths.push(path);
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
builder.log.warn(
|
|
551
|
+
`\nvercel.json defines cron tasks that use paths that do not correspond to an API route with a GET handler (ignore this if the request is handled in your \`handle\` hook):`
|
|
552
|
+
);
|
|
553
|
+
|
|
554
|
+
for (const path of unmatched_paths) {
|
|
555
|
+
console.log(` - ${path}`);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
console.log('');
|
|
559
|
+
}
|
|
560
|
+
|
|
502
561
|
export default plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/adapter-vercel",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@types/node": "^16.18.6",
|
|
31
31
|
"typescript": "^4.9.4",
|
|
32
|
-
"@sveltejs/kit": "^1.8.
|
|
32
|
+
"@sveltejs/kit": "^1.8.7"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"@sveltejs/kit": "^1.5.0"
|