From e7b113a8db8416a7b215cea7852c1ae4be1d3fae Mon Sep 17 00:00:00 2001 From: Alessio Marchi <65831826+kettei-sproutty@users.noreply.github.com> Date: Sun, 16 Jun 2024 19:07:25 +0200 Subject: [PATCH 1/5] chore(cloudflare): throw error if routes are configured in _routes.json --- packages/adapter-cloudflare/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/index.js b/packages/adapter-cloudflare/index.js index aa141f85312b..98bf1c8367eb 100644 --- a/packages/adapter-cloudflare/index.js +++ b/packages/adapter-cloudflare/index.js @@ -1,4 +1,4 @@ -import { writeFileSync } from 'node:fs'; +import { existsSync, writeFileSync } from 'node:fs'; import * as path from 'node:path'; import { fileURLToPath } from 'node:url'; import * as esbuild from 'esbuild'; @@ -24,6 +24,15 @@ export default function (options = {}) { return { name: '@sveltejs/adapter-cloudflare', async adapt(builder) { + const has_routes_json = existsSync('_routes.json'); + + // if there are no routes inside svelte config, and _routes.json exists, user is expecting to configure cloudflare routes in the wrong way. + if (!options.routes && has_routes_json) { + throw new Error( + 'Cloudflare routes should be configured inside svelte config, not in _routes.json' + ); + } + const files = fileURLToPath(new URL('./files', import.meta.url).href); const dest = builder.getBuildDirectory('cloudflare'); const tmp = builder.getBuildDirectory('cloudflare-tmp'); From 500c7d20608a0fb01170cd2ee9e382d468288e8e Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Mon, 17 Jun 2024 13:15:53 -0700 Subject: [PATCH 2/5] Update packages/adapter-cloudflare/index.js --- packages/adapter-cloudflare/index.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/adapter-cloudflare/index.js b/packages/adapter-cloudflare/index.js index 98bf1c8367eb..8f0ffd811502 100644 --- a/packages/adapter-cloudflare/index.js +++ b/packages/adapter-cloudflare/index.js @@ -24,12 +24,9 @@ export default function (options = {}) { return { name: '@sveltejs/adapter-cloudflare', async adapt(builder) { - const has_routes_json = existsSync('_routes.json'); - - // if there are no routes inside svelte config, and _routes.json exists, user is expecting to configure cloudflare routes in the wrong way. - if (!options.routes && has_routes_json) { + if (!options.routes && existsSync('_routes.json')) { throw new Error( - 'Cloudflare routes should be configured inside svelte config, not in _routes.json' + 'Cloudflare routes should be configured in svelte.config.js rather than _routes.json' ); } From f154aa7d60982707abc14b3fa8a839524e0fe8a7 Mon Sep 17 00:00:00 2001 From: Alessio Marchi <65831826+kettei-sproutty@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:51:08 +0200 Subject: [PATCH 3/5] chore(adapter-cloudflare): remove check on options.routes --- packages/adapter-cloudflare/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-cloudflare/index.js b/packages/adapter-cloudflare/index.js index 8f0ffd811502..7ec6539862bf 100644 --- a/packages/adapter-cloudflare/index.js +++ b/packages/adapter-cloudflare/index.js @@ -24,7 +24,7 @@ export default function (options = {}) { return { name: '@sveltejs/adapter-cloudflare', async adapt(builder) { - if (!options.routes && existsSync('_routes.json')) { + if (existsSync('_routes.json')) { throw new Error( 'Cloudflare routes should be configured in svelte.config.js rather than _routes.json' ); From 0609fd8f91e00f5f0e3cf8768d6f52eeea438682 Mon Sep 17 00:00:00 2001 From: Alessio Marchi <65831826+kettei-sproutty@users.noreply.github.com> Date: Tue, 18 Jun 2024 11:58:21 +0200 Subject: [PATCH 4/5] chore(adapter-cloudflare): changeset --- .changeset/angry-spies-rule.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/angry-spies-rule.md diff --git a/.changeset/angry-spies-rule.md b/.changeset/angry-spies-rule.md new file mode 100644 index 000000000000..81eabf34aaed --- /dev/null +++ b/.changeset/angry-spies-rule.md @@ -0,0 +1,5 @@ +--- +"@sveltejs/adapter-cloudflare": patch +--- + +chore: throw an error if `_routes.json` is detected From 2e99678e40075d838910b0704061e5eeaadd5b04 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Tue, 18 Jun 2024 06:17:00 -0700 Subject: [PATCH 5/5] Update .changeset/angry-spies-rule.md --- .changeset/angry-spies-rule.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/angry-spies-rule.md b/.changeset/angry-spies-rule.md index 81eabf34aaed..bf25fd3008fa 100644 --- a/.changeset/angry-spies-rule.md +++ b/.changeset/angry-spies-rule.md @@ -1,5 +1,5 @@ --- -"@sveltejs/adapter-cloudflare": patch +"@sveltejs/adapter-cloudflare": minor --- -chore: throw an error if `_routes.json` is detected +feat: validate that no `_routes.json` is present to avoid overwriting it