Skip to content

fix: resolve assets.directory path from wrangler config #14036

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

Merged
merged 4 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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/new-donkeys-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/adapter-cloudflare": patch
---

fix: resolve the absolute path of the Wrangler config setting `assets.directory` in case the config file is in a different directory than the root project
11 changes: 9 additions & 2 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { VERSION } from '@sveltejs/kit';
import { copyFileSync, existsSync, writeFileSync } from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { is_building_for_cloudflare_pages, validate_worker_settings } from './utils.js';
import { getPlatformProxy, unstable_readConfig } from 'wrangler';
import { is_building_for_cloudflare_pages, validate_worker_settings } from './utils.js';

const name = '@sveltejs/adapter-cloudflare';
const [kit_major, kit_minor] = VERSION.split('.');
Expand Down Expand Up @@ -32,6 +33,7 @@ export default function (options = {}) {
}

const wrangler_config = validate_wrangler_config(options.config);

const building_for_cloudflare_pages = is_building_for_cloudflare_pages(wrangler_config);

let dest = builder.getBuildDirectory('cloudflare');
Expand All @@ -48,7 +50,12 @@ export default function (options = {}) {
worker_dest = wrangler_config.main;
}
if (wrangler_config.assets?.directory) {
dest = wrangler_config.assets.directory;
// wrangler doesn't resolve `assets.directory` to an absolute path unlike
// `main` and `pages_build_output_dir` so we need to do it ourselves here
const parent_dir = wrangler_config.configPath
? path.dirname(path.resolve(wrangler_config.configPath))
: process.cwd();
dest = path.resolve(parent_dir, wrangler_config.assets.directory);
}
if (wrangler_config.assets?.binding) {
assets_binding = wrangler_config.assets.binding;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// we've moved the wrangler config away from the root of the project
// to test that the adapter still resolves the paths correctly
{
"$schema": "../node_modules/wrangler/config-schema.json",
"main": "../dist/index.js",
"assets": {
"directory": "../dist/public",
"binding": "ASSETS"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import adapter from '../../../index.js';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter()
adapter: adapter({
config: 'config/wrangler.jsonc'
})
}
};

Expand Down
7 changes: 0 additions & 7 deletions packages/adapter-cloudflare/test/apps/workers/wrangler.jsonc

This file was deleted.