@sveltejs/adapter-vercel 2.1.0 → 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 +66 -6
- 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 = {
|
|
@@ -216,11 +222,6 @@ const plugin = function (defaults = {}) {
|
|
|
216
222
|
/** @type {import('@sveltejs/kit').RouteDefinition<any>[]} */ (group.routes)
|
|
217
223
|
);
|
|
218
224
|
|
|
219
|
-
if (singular) {
|
|
220
|
-
// Special case: One function for all routes
|
|
221
|
-
static_config.routes.push({ src: '/.*', dest: `/${name}` });
|
|
222
|
-
}
|
|
223
|
-
|
|
224
225
|
for (const route of group.routes) {
|
|
225
226
|
functions.set(route.pattern.toString(), name);
|
|
226
227
|
}
|
|
@@ -286,6 +287,12 @@ const plugin = function (defaults = {}) {
|
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
289
|
|
|
290
|
+
if (singular) {
|
|
291
|
+
// Common case: One function for all routes
|
|
292
|
+
// Needs to happen after ISR or else regex swallows all other matches
|
|
293
|
+
static_config.routes.push({ src: '/.*', dest: `/fn` });
|
|
294
|
+
}
|
|
295
|
+
|
|
289
296
|
builder.log.minor('Copying assets...');
|
|
290
297
|
|
|
291
298
|
builder.writeClient(dirs.static);
|
|
@@ -488,7 +495,7 @@ async function create_function_bundle(builder, entry, dir, config) {
|
|
|
488
495
|
maxDuration: config.maxDuration,
|
|
489
496
|
handler: path.relative(base + ancestor, entry),
|
|
490
497
|
launcherType: 'Nodejs',
|
|
491
|
-
experimentalResponseStreaming:
|
|
498
|
+
experimentalResponseStreaming: !config.isr
|
|
492
499
|
},
|
|
493
500
|
null,
|
|
494
501
|
'\t'
|
|
@@ -498,4 +505,57 @@ async function create_function_bundle(builder, entry, dir, config) {
|
|
|
498
505
|
write(`${dir}/package.json`, JSON.stringify({ type: 'module' }));
|
|
499
506
|
}
|
|
500
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
|
+
|
|
501
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"
|