Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove images from route-level config #12280

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/stupid-lies-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/adapter-vercel": patch
---

fix: add images to edge config types
4 changes: 4 additions & 0 deletions packages/adapter-vercel/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export interface EdgeConfig {
* If `true`, this route will always be deployed as its own separate function
*/
split?: boolean;
/**
* https://vercel.com/docs/build-output-api/v3/configuration#images
*/
images?: ImagesConfig;
Rich-Harris marked this conversation as resolved.
Show resolved Hide resolved
}

export type Config = EdgeConfig | ServerlessConfig;
Expand Down
27 changes: 14 additions & 13 deletions packages/adapter-vercel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }");
Expand Down Expand Up @@ -69,8 +69,8 @@ const plugin = function (defaults = {}) {

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

/**
* @param {string} name
* @param {import('.').EdgeConfig} config
* @param {import('@sveltejs/kit').RouteDefinition<import('.').EdgeConfig>[]} routes
* @param {import('index.js').EdgeConfig} config
* @param {import('@sveltejs/kit').RouteDefinition<import('index.js').EdgeConfig>[]} routes
*/
async function generate_edge_function(name, config, routes) {
const tmp = builder.getBuildDirectory(`vercel-tmp/${name}`);
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -192,7 +193,7 @@ const plugin = function (defaults = {}) {
);
}

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

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

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

/** @type {Set<string>} */
Expand All @@ -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).'
Expand Down Expand Up @@ -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 ?? '',
Expand Down Expand Up @@ -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) {
Expand All @@ -434,7 +435,7 @@ function static_vercel_config(builder, config, dir) {
/** @type {Record<string, { path: string }>} */
const overrides = {};

/** @type {import('./index').ImagesConfig} */
/** @type {import('./index.js').ImagesConfig | undefined} */
const images = config.images;

for (const [src, redirect] of builder.prerendered.redirects) {
Expand Down Expand Up @@ -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 });
Expand Down
3 changes: 1 addition & 2 deletions packages/adapter-vercel/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["**/*.js", "index.d.ts", "internal.d.ts"]
}
}
Loading