Skip to content

Commit 7133648

Browse files
fix: remove images from route-level config (#12280)
* fix: add images to edge config types * relative paths * images config can only be specified at the project level * update changeset * live dangerously * downgrade changeset --------- Co-authored-by: Rich Harris <[email protected]>
1 parent 9aa59db commit 7133648

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

.changeset/stupid-lies-remain.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-vercel': patch
3+
---
4+
5+
fix: remove `images` from route-level config

packages/adapter-vercel/index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ export interface ServerlessConfig {
2929
*/
3030
split?: boolean;
3131

32-
/**
33-
* https://vercel.com/docs/build-output-api/v3/configuration#images
34-
*/
35-
images?: ImagesConfig;
36-
3732
/**
3833
* [Incremental Static Regeneration](https://vercel.com/docs/concepts/incremental-static-regeneration/overview) configuration.
3934
* Serverless only.
@@ -100,7 +95,12 @@ export interface EdgeConfig {
10095
split?: boolean;
10196
}
10297

103-
export type Config = EdgeConfig | ServerlessConfig;
98+
export type Config = (EdgeConfig | ServerlessConfig) & {
99+
/**
100+
* https://vercel.com/docs/build-output-api/v3/configuration#images
101+
*/
102+
images?: ImagesConfig;
103+
};
104104

105105
// we copy the RequestContext interface from `@vercel/edge` because that package can't co-exist with `@types/node`.
106106
// see https://github.com/sveltejs/kit/pull/9280#issuecomment-1452110035

packages/adapter-vercel/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const get_default_runtime = () => {
2222
// https://vercel.com/docs/functions/edge-functions/edge-runtime#compatible-node.js-modules
2323
const compatible_node_modules = ['async_hooks', 'events', 'buffer', 'assert', 'util'];
2424

25-
/** @type {import('.').default} **/
25+
/** @type {import('./index.js').default} **/
2626
const plugin = function (defaults = {}) {
2727
if ('edge' in defaults) {
2828
throw new Error("{ edge: true } has been removed in favour of { runtime: 'edge' }");
@@ -69,8 +69,8 @@ const plugin = function (defaults = {}) {
6969

7070
/**
7171
* @param {string} name
72-
* @param {import('.').ServerlessConfig} config
73-
* @param {import('@sveltejs/kit').RouteDefinition<import('.').Config>[]} routes
72+
* @param {import('./index.js').ServerlessConfig} config
73+
* @param {import('@sveltejs/kit').RouteDefinition<import('./index.js').Config>[]} routes
7474
*/
7575
async function generate_serverless_function(name, config, routes) {
7676
const dir = `${dirs.functions}/${name}.func`;
@@ -99,8 +99,8 @@ const plugin = function (defaults = {}) {
9999

100100
/**
101101
* @param {string} name
102-
* @param {import('.').EdgeConfig} config
103-
* @param {import('@sveltejs/kit').RouteDefinition<import('.').EdgeConfig>[]} routes
102+
* @param {import('./index.js').EdgeConfig} config
103+
* @param {import('@sveltejs/kit').RouteDefinition<import('./index.js').EdgeConfig>[]} routes
104104
*/
105105
async function generate_edge_function(name, config, routes) {
106106
const tmp = builder.getBuildDirectory(`vercel-tmp/${name}`);
@@ -146,7 +146,8 @@ const plugin = function (defaults = {}) {
146146

147147
console.error(formatted.join('\n'));
148148
}
149-
} catch (error) {
149+
} catch (err) {
150+
const error = /** @type {import('esbuild').BuildFailure} */ (err);
150151
for (const e of error.errors) {
151152
for (const node of e.notes) {
152153
const match =
@@ -192,7 +193,7 @@ const plugin = function (defaults = {}) {
192193
);
193194
}
194195

195-
/** @type {Map<string, { i: number, config: import('.').Config, routes: import('@sveltejs/kit').RouteDefinition<import('.').Config>[] }>} */
196+
/** @type {Map<string, { i: number, config: import('./index.js').Config, routes: import('@sveltejs/kit').RouteDefinition<import('./index.js').Config>[] }>} */
196197
const groups = new Map();
197198

198199
/** @type {Map<string, { hash: string, route_id: string }>} */
@@ -201,7 +202,7 @@ const plugin = function (defaults = {}) {
201202
/** @type {Map<string, string>} */
202203
const functions = new Map();
203204

204-
/** @type {Map<import('@sveltejs/kit').RouteDefinition<import('.').Config>, { expiration: number | false, bypassToken: string | undefined, allowQuery: string[], group: number, passQuery: true }>} */
205+
/** @type {Map<import('@sveltejs/kit').RouteDefinition<import('./index.js').Config>, { expiration: number | false, bypassToken: string | undefined, allowQuery: string[], group: number, passQuery: true }>} */
205206
const isr_config = new Map();
206207

207208
/** @type {Set<string>} */
@@ -220,7 +221,7 @@ const plugin = function (defaults = {}) {
220221
}
221222

222223
const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime);
223-
if (runtime !== 'edge' && (!node_runtime || node_runtime[1] < 18)) {
224+
if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) < 18)) {
224225
throw new Error(
225226
`Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs18.x' or higher ` +
226227
'(see the Node.js Version section in your Vercel project settings for info on the currently supported versions).'
@@ -395,7 +396,7 @@ const plugin = function (defaults = {}) {
395396
};
396397
};
397398

398-
/** @param {import('.').EdgeConfig & import('.').ServerlessConfig} config */
399+
/** @param {import('./index.js').EdgeConfig & import('./index.js').ServerlessConfig} config */
399400
function hash_config(config) {
400401
return [
401402
config.runtime ?? '',
@@ -424,7 +425,7 @@ function write(file, data) {
424425
// This function is duplicated in adapter-static
425426
/**
426427
* @param {import('@sveltejs/kit').Builder} builder
427-
* @param {import('.').Config} config
428+
* @param {import('./index.js').Config} config
428429
* @param {string} dir
429430
*/
430431
function static_vercel_config(builder, config, dir) {
@@ -434,7 +435,7 @@ function static_vercel_config(builder, config, dir) {
434435
/** @type {Record<string, { path: string }>} */
435436
const overrides = {};
436437

437-
/** @type {import('./index').ImagesConfig} */
438+
/** @type {import('./index.js').ImagesConfig | undefined} */
438439
const images = config.images;
439440

440441
for (const [src, redirect] of builder.prerendered.redirects) {
@@ -531,7 +532,7 @@ function static_vercel_config(builder, config, dir) {
531532
* @param {import('@sveltejs/kit').Builder} builder
532533
* @param {string} entry
533534
* @param {string} dir
534-
* @param {import('.').ServerlessConfig} config
535+
* @param {import('./index.js').ServerlessConfig} config
535536
*/
536537
async function create_function_bundle(builder, entry, dir, config) {
537538
fs.rmSync(dir, { force: true, recursive: true });

packages/adapter-vercel/tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,5 @@
1313
"paths": {
1414
"@sveltejs/kit": ["../kit/types/index"]
1515
}
16-
},
17-
"include": ["**/*.js", "index.d.ts", "internal.d.ts"]
16+
}
1817
}

0 commit comments

Comments
 (0)