Skip to content
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/happy-beers-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare': patch
---

fix: correctly warn users when assets key is missing
2 changes: 1 addition & 1 deletion packages/adapter-auto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"typescript": "^5.3.3",
"vitest": "catalog:"
},
Expand Down
16 changes: 1 addition & 15 deletions packages/adapter-cloudflare/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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 } from './utils.js';
import { getPlatformProxy, unstable_readConfig } from 'wrangler';

/** @type {import('./index.js').default} */
Expand Down Expand Up @@ -302,20 +302,6 @@ function validate_config(config_file = undefined) {
return wrangler_config;
}

/**
* @param {import('wrangler').Unstable_Config} wrangler_config
* @returns {boolean}
*/
function is_building_for_cloudflare_pages(wrangler_config) {
return (
!!process.env.CF_PAGES ||
!wrangler_config.configPath ||
!!wrangler_config.pages_build_output_dir ||
!wrangler_config.main ||
!wrangler_config.assets
);
}

/** @param {string} str */
function posixify(str) {
return str.replace(/\\/g, '/');
Expand Down
9 changes: 6 additions & 3 deletions packages/adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"format": "pnpm lint --write",
"check": "tsc --skipLibCheck",
"prepublishOnly": "pnpm build",
"test": "pnpm build && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test"
"test:unit": "vitest run",
"test:e2e": "pnpm build && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
"test": "pnpm test:unit && pnpm test:e2e"
},
"dependencies": {
"@cloudflare/workers-types": "^4.20250507.0",
Expand All @@ -47,9 +49,10 @@
"devDependencies": {
"@playwright/test": "catalog:",
"@sveltejs/kit": "workspace:^",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"esbuild": "^0.25.4",
"typescript": "^5.3.3"
"typescript": "^5.3.3",
"vitest": "catalog:"
},
"peerDependencies": {
"@sveltejs/kit": "^2.0.0",
Expand Down
9 changes: 8 additions & 1 deletion packages/adapter-cloudflare/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
"lib": ["es2021"],
"types": ["@cloudflare/workers-types"]
},
"include": ["index.js", "utils.js", "test/utils.js", "internal.d.ts", "src/worker.js"]
"include": [
"index.js",
"utils.js",
"utils.spec.js",
"test/utils.js",
"internal.d.ts",
"src/worker.js"
]
}
17 changes: 17 additions & 0 deletions packages/adapter-cloudflare/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import process from 'node:process';

/**
* @param {import('wrangler').Unstable_Config} wrangler_config
* @returns {boolean}
*/
export function is_building_for_cloudflare_pages(wrangler_config) {
if (process.env.CF_PAGES || wrangler_config.pages_build_output_dir) {
return true;
}

if (wrangler_config.main || wrangler_config.assets) {
return false;
}

return true;
}
67 changes: 67 additions & 0 deletions packages/adapter-cloudflare/utils.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { describe, test, vi, expect } from 'vitest';
import { is_building_for_cloudflare_pages } from './utils.js';

describe('detects Cloudflare Pages project', () => {
test('by default', () => {
expect(
is_building_for_cloudflare_pages(/** @type {import('wrangler').Unstable_Config} */ ({}))
).toBe(true);
});

test('CF_PAGES environment variable', () => {
vi.stubEnv('CF_PAGES', '1');
const result = is_building_for_cloudflare_pages(
/** @type {import('wrangler').Unstable_Config} */ ({})
);
vi.unstubAllEnvs();
expect(result).toBe(true);
});

test('empty Wrangler configuration file', () => {
expect(
is_building_for_cloudflare_pages(
/** @type {import('wrangler').Unstable_Config} */ ({
configPath: 'wrangler.jsonc'
})
)
).toBe(true);
});

test('pages_build_output_dir config key', () => {
expect(
is_building_for_cloudflare_pages(
/** @type {import('wrangler').Unstable_Config} */ ({
configPath: 'wrangler.jsonc',
pages_build_output_dir: 'dist'
})
)
).toBe(true);
});
});

describe('detects Cloudflare Workers project', () => {
test('main config key', () => {
expect(
is_building_for_cloudflare_pages(
/** @type {import('wrangler').Unstable_Config} */ ({
configPath: 'wrangler.jsonc',
main: 'dist/index.js'
})
)
).toBe(false);
});

test('assets config key', () => {
expect(
is_building_for_cloudflare_pages(
/** @type {import('wrangler').Unstable_Config} */ ({
configPath: 'wrangler.jsonc',
assets: {
directory: 'dist/assets',
binding: 'ASSETS'
}
})
)
).toBe(false);
});
});
2 changes: 1 addition & 1 deletion packages/adapter-netlify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@rollup/plugin-node-resolve": "^16.0.0",
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"@types/set-cookie-parser": "^2.4.7",
"rollup": "^4.14.2",
"typescript": "^5.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@polka/url": "^1.0.0-next.28",
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"polka": "^1.0.0-next.28",
"sirv": "^3.0.0",
"typescript": "^5.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@playwright/test": "catalog:",
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"sirv": "^3.0.0",
"svelte": "^5.35.5",
"typescript": "^5.3.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-vercel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"devDependencies": {
"@sveltejs/kit": "workspace:^",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"typescript": "^5.3.3",
"vitest": "catalog:"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/enhanced-img/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/estree": "^1.0.5",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"rollup": "^4.27.4",
"svelte": "^5.35.5",
"typescript": "^5.6.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@playwright/test": "catalog:",
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/connect": "^3.4.38",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"@types/set-cookie-parser": "^2.4.7",
"dts-buddy": "^0.6.1",
"rollup": "^4.14.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1955,7 +1955,7 @@ declare module '@sveltejs/kit' {
* Checks whether this is an error thrown by {@link error}.
* @param status The status to filter for.
* */
export function isHttpError<T extends number>(e: unknown, status?: T | undefined): e is (HttpError_1 & {
export function isHttpError<T extends number>(e: unknown, status?: T): e is (HttpError_1 & {
status: T extends undefined ? never : T;
});
/**
Expand Down Expand Up @@ -1985,13 +1985,13 @@ declare module '@sveltejs/kit' {
* @param data The value that will be serialized as JSON.
* @param init Options such as `status` and `headers` that will be added to the response. `Content-Type: application/json` and `Content-Length` headers will be added automatically.
*/
export function json(data: any, init?: ResponseInit | undefined): Response;
export function json(data: any, init?: ResponseInit): Response;
/**
* Create a `Response` object from the supplied body.
* @param body The value that will be used as-is.
* @param init Options such as `status` and `headers` that will be added to the response. A `Content-Length` header will be added automatically.
*/
export function text(body: string, init?: ResponseInit | undefined): Response;
export function text(body: string, init?: ResponseInit): Response;
/**
* Create an `ActionFailure` object. Call when form submission fails.
* @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
Expand Down Expand Up @@ -2290,7 +2290,7 @@ declare module '$app/navigation' {
invalidateAll?: boolean | undefined;
invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
state?: App.PageState | undefined;
} | undefined): Promise<void>;
}): Promise<void>;
/**
* Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
*
Expand Down
2 changes: 1 addition & 1 deletion packages/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"devDependencies": {
"@sveltejs/vite-plugin-svelte": "catalog:",
"@types/node": "^18.19.48",
"@types/node": "^18.19.119",
"@types/semver": "^7.5.6",
"prettier": "^3.1.1",
"svelte": "^5.35.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/package/src/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function walk(cwd, dirs = false) {
}
}

return walk_dir(''), all_files;
return (walk_dir(''), all_files);
}

/**
Expand Down
Loading
Loading