diff --git a/.changeset/stupid-lies-remain.md b/.changeset/stupid-lies-remain.md new file mode 100644 index 000000000000..83a7bec30d45 --- /dev/null +++ b/.changeset/stupid-lies-remain.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-vercel': patch +--- + +fix: remove `images` from route-level config diff --git a/packages/adapter-vercel/index.d.ts b/packages/adapter-vercel/index.d.ts index 6d9f8d359891..74aaed8cd620 100644 --- a/packages/adapter-vercel/index.d.ts +++ b/packages/adapter-vercel/index.d.ts @@ -29,11 +29,6 @@ export interface ServerlessConfig { */ split?: boolean; - /** - * https://vercel.com/docs/build-output-api/v3/configuration#images - */ - images?: ImagesConfig; - /** * [Incremental Static Regeneration](https://vercel.com/docs/concepts/incremental-static-regeneration/overview) configuration. * Serverless only. @@ -100,7 +95,12 @@ export interface EdgeConfig { split?: boolean; } -export type Config = EdgeConfig | ServerlessConfig; +export type Config = (EdgeConfig | ServerlessConfig) & { + /** + * https://vercel.com/docs/build-output-api/v3/configuration#images + */ + images?: ImagesConfig; +}; // we copy the RequestContext interface from `@vercel/edge` because that package can't co-exist with `@types/node`. // see https://github.com/sveltejs/kit/pull/9280#issuecomment-1452110035 diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index 7506a90d782d..11d7223dfa0f 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -22,7 +22,7 @@ const get_default_runtime = () => { // https://vercel.com/docs/functions/edge-functions/edge-runtime#compatible-node.js-modules const compatible_node_modules = ['async_hooks', 'events', 'buffer', 'assert', 'util']; -/** @type {import('.').default} **/ +/** @type {import('./index.js').default} **/ const plugin = function (defaults = {}) { if ('edge' in defaults) { throw new Error("{ edge: true } has been removed in favour of { runtime: 'edge' }"); @@ -69,8 +69,8 @@ const plugin = function (defaults = {}) { /** * @param {string} name - * @param {import('.').ServerlessConfig} config - * @param {import('@sveltejs/kit').RouteDefinition[]} routes + * @param {import('./index.js').ServerlessConfig} config + * @param {import('@sveltejs/kit').RouteDefinition[]} routes */ async function generate_serverless_function(name, config, routes) { const dir = `${dirs.functions}/${name}.func`; @@ -99,8 +99,8 @@ const plugin = function (defaults = {}) { /** * @param {string} name - * @param {import('.').EdgeConfig} config - * @param {import('@sveltejs/kit').RouteDefinition[]} routes + * @param {import('./index.js').EdgeConfig} config + * @param {import('@sveltejs/kit').RouteDefinition[]} routes */ async function generate_edge_function(name, config, routes) { const tmp = builder.getBuildDirectory(`vercel-tmp/${name}`); @@ -146,7 +146,8 @@ const plugin = function (defaults = {}) { console.error(formatted.join('\n')); } - } catch (error) { + } catch (err) { + const error = /** @type {import('esbuild').BuildFailure} */ (err); for (const e of error.errors) { for (const node of e.notes) { const match = @@ -192,7 +193,7 @@ const plugin = function (defaults = {}) { ); } - /** @type {Map[] }>} */ + /** @type {Map[] }>} */ const groups = new Map(); /** @type {Map} */ @@ -201,7 +202,7 @@ const plugin = function (defaults = {}) { /** @type {Map} */ const functions = new Map(); - /** @type {Map, { expiration: number | false, bypassToken: string | undefined, allowQuery: string[], group: number, passQuery: true }>} */ + /** @type {Map, { expiration: number | false, bypassToken: string | undefined, allowQuery: string[], group: number, passQuery: true }>} */ const isr_config = new Map(); /** @type {Set} */ @@ -220,7 +221,7 @@ const plugin = function (defaults = {}) { } const node_runtime = /nodejs([0-9]+)\.x/.exec(runtime); - if (runtime !== 'edge' && (!node_runtime || node_runtime[1] < 18)) { + if (runtime !== 'edge' && (!node_runtime || parseInt(node_runtime[1]) < 18)) { throw new Error( `Invalid runtime '${runtime}' for route ${route.id}. Valid runtimes are 'edge' and 'nodejs18.x' or higher ` + '(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 = {}) { }; }; -/** @param {import('.').EdgeConfig & import('.').ServerlessConfig} config */ +/** @param {import('./index.js').EdgeConfig & import('./index.js').ServerlessConfig} config */ function hash_config(config) { return [ config.runtime ?? '', @@ -424,7 +425,7 @@ function write(file, data) { // This function is duplicated in adapter-static /** * @param {import('@sveltejs/kit').Builder} builder - * @param {import('.').Config} config + * @param {import('./index.js').Config} config * @param {string} dir */ function static_vercel_config(builder, config, dir) { @@ -434,7 +435,7 @@ function static_vercel_config(builder, config, dir) { /** @type {Record} */ const overrides = {}; - /** @type {import('./index').ImagesConfig} */ + /** @type {import('./index.js').ImagesConfig | undefined} */ const images = config.images; for (const [src, redirect] of builder.prerendered.redirects) { @@ -531,7 +532,7 @@ function static_vercel_config(builder, config, dir) { * @param {import('@sveltejs/kit').Builder} builder * @param {string} entry * @param {string} dir - * @param {import('.').ServerlessConfig} config + * @param {import('./index.js').ServerlessConfig} config */ async function create_function_bundle(builder, entry, dir, config) { fs.rmSync(dir, { force: true, recursive: true }); diff --git a/packages/adapter-vercel/tsconfig.json b/packages/adapter-vercel/tsconfig.json index 8aa63e3d2a76..3d157ebc29e5 100644 --- a/packages/adapter-vercel/tsconfig.json +++ b/packages/adapter-vercel/tsconfig.json @@ -13,6 +13,5 @@ "paths": { "@sveltejs/kit": ["../kit/types/index"] } - }, - "include": ["**/*.js", "index.d.ts", "internal.d.ts"] + } }