From dbe0e560b0a387186ae28f6315db48516332f83a Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Mon, 25 Apr 2022 16:20:10 +0300 Subject: [PATCH 1/5] [adapter-vercel] Make all root routes be called `index` instead of an empty string --- packages/adapter-vercel/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index 728996d7e6db..96cbb16f3740 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -340,7 +340,7 @@ async function v3(builder, external, edge, split) { .slice(1, -2) // remove leading / and trailing $/ .replace(/\\\//g, '/')}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes - await generate_function(route.id, src, entry.generateManifest); + await generate_function(createValidFunctionName(route.id), src, entry.generateManifest); } }; }); @@ -385,3 +385,20 @@ function write(file, data) { writeFileSync(file, data); } + +/** + * Make all root routes be called `index`: + * + * @example + * ```js + * createValidFunctionName("") // "index" + * createValidFunctionName("nested") // "nested" + * createValidFunctionName("nested/") // "nested/index" + * ``` + * + * @param {string} routeId + * @returns {string} route id that is a valid function name + */ +function createValidFunctionName(routeId) { + return routeId.replace(/(\/|^)$/, '$1index'); +} From 30f3223fc590440d9af1a2c85175a341981c0beb Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Mon, 25 Apr 2022 16:24:53 +0300 Subject: [PATCH 2/5] Add changeset --- .changeset/shiny-needles-divide.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/shiny-needles-divide.md diff --git a/.changeset/shiny-needles-divide.md b/.changeset/shiny-needles-divide.md new file mode 100644 index 000000000000..772b850a07a8 --- /dev/null +++ b/.changeset/shiny-needles-divide.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-vercel': patch +--- + +Fix `edge:true, split: true` build error for root routes when deploying to Vercel From 3abbdbb00a0dd51a804396181b3c3bddcdbcbd03 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 25 Apr 2022 09:54:09 -0400 Subject: [PATCH 3/5] Update packages/adapter-vercel/index.js --- packages/adapter-vercel/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index 96cbb16f3740..34809f4bcf2f 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -340,7 +340,7 @@ async function v3(builder, external, edge, split) { .slice(1, -2) // remove leading / and trailing $/ .replace(/\\\//g, '/')}(?:/__data.json)?$`; // TODO adding /__data.json is a temporary workaround — those endpoints should be treated as distinct routes - await generate_function(createValidFunctionName(route.id), src, entry.generateManifest); + await generate_function(route.id || 'index', src, entry.generateManifest); } }; }); From def823dbee7e6c4bd34ce857e447b529b9b04a85 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 25 Apr 2022 09:54:14 -0400 Subject: [PATCH 4/5] Update packages/adapter-vercel/index.js --- packages/adapter-vercel/index.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index 34809f4bcf2f..f98c2c4b5137 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -385,20 +385,3 @@ function write(file, data) { writeFileSync(file, data); } - -/** - * Make all root routes be called `index`: - * - * @example - * ```js - * createValidFunctionName("") // "index" - * createValidFunctionName("nested") // "nested" - * createValidFunctionName("nested/") // "nested/index" - * ``` - * - * @param {string} routeId - * @returns {string} route id that is a valid function name - */ -function createValidFunctionName(routeId) { - return routeId.replace(/(\/|^)$/, '$1index'); -} From 7f6ff2091e9f2d3c1be06fcfb40f25bddb8fbd05 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 25 Apr 2022 10:06:16 -0400 Subject: [PATCH 5/5] Update .changeset/shiny-needles-divide.md Co-authored-by: Conduitry --- .changeset/shiny-needles-divide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/shiny-needles-divide.md b/.changeset/shiny-needles-divide.md index 772b850a07a8..9dbc612a36eb 100644 --- a/.changeset/shiny-needles-divide.md +++ b/.changeset/shiny-needles-divide.md @@ -2,4 +2,4 @@ '@sveltejs/adapter-vercel': patch --- -Fix `edge:true, split: true` build error for root routes when deploying to Vercel +Fix `edge: true, split: true` build error for root routes when deploying to Vercel