From 79f49acbe13673bfc27e794bcfae518f38c4a4fe Mon Sep 17 00:00:00 2001 From: Marvin Frachet Date: Mon, 13 Feb 2023 02:19:38 +0100 Subject: [PATCH] Fix 6206: Cloudflare function path resolving one step above (#6208) * Fix 6206: Cloudflare function path resolving one step above --- .changeset/lazy-coins-compete.md | 5 +++++ packages/integrations/cloudflare/src/index.ts | 3 ++- packages/integrations/cloudflare/test/directory.test.js | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/lazy-coins-compete.md diff --git a/.changeset/lazy-coins-compete.md b/.changeset/lazy-coins-compete.md new file mode 100644 index 000000000000..04b23077df87 --- /dev/null +++ b/.changeset/lazy-coins-compete.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Fix path file that was generated outside the functions folder diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 7ba1cc63148a..0343e6e81874 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -203,8 +203,9 @@ export default function createIntegration(args?: Options): AstroIntegration { } if (isModeDirectory) { - const functionsUrl = new URL('functions', _config.root); + const functionsUrl = new URL('functions/', _config.root); await fs.promises.mkdir(functionsUrl, { recursive: true }); + const directoryUrl = new URL('[[path]].js', functionsUrl); await fs.promises.rename(finalBuildUrl, directoryUrl); } diff --git a/packages/integrations/cloudflare/test/directory.test.js b/packages/integrations/cloudflare/test/directory.test.js index e5b5205745cf..67693310a7e0 100644 --- a/packages/integrations/cloudflare/test/directory.test.js +++ b/packages/integrations/cloudflare/test/directory.test.js @@ -17,5 +17,6 @@ describe('mode: "directory"', () => { it('generates functions folder inside the project root', async () => { expect(await fixture.pathExists('../functions')).to.be.true; + expect(await fixture.pathExists('../functions/[[path]].js')).to.be.true; }); });