From 45b41d98f50dc9f76a5004a8b3346f393f1a6cb6 Mon Sep 17 00:00:00 2001 From: Nacho Vazquez Date: Fri, 3 Feb 2023 12:19:44 -0300 Subject: [PATCH] fix: use the root of the project as the functions location (#6075) * fix: use the root of the project as the functions location * test: add test to check where the functions folder is added --- .changeset/honest-beds-flow.md | 5 +++++ packages/integrations/cloudflare/src/index.ts | 2 +- .../integrations/cloudflare/test/directory.test.js | 13 +++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 .changeset/honest-beds-flow.md diff --git a/.changeset/honest-beds-flow.md b/.changeset/honest-beds-flow.md new file mode 100644 index 0000000000..ddf54699f9 --- /dev/null +++ b/.changeset/honest-beds-flow.md @@ -0,0 +1,5 @@ +--- +'@astrojs/cloudflare': patch +--- + +Uses config root path as location for Cloudflare Pages Functions diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 3433cf46d7..7ba1cc6314 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -203,7 +203,7 @@ export default function createIntegration(args?: Options): AstroIntegration { } if (isModeDirectory) { - const functionsUrl = new URL(`file://${process.cwd()}/functions/`); + 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 7c299f5266..e5b5205745 100644 --- a/packages/integrations/cloudflare/test/directory.test.js +++ b/packages/integrations/cloudflare/test/directory.test.js @@ -1,20 +1,21 @@ -import { loadFixture, runCLI } from './test-utils.js'; +import { loadFixture } from './test-utils.js'; import { expect } from 'chai'; -import * as cheerio from 'cheerio'; import cloudflare from '../dist/index.js'; +/** @type {import('./test-utils').Fixture} */ describe('mode: "directory"', () => { - /** @type {import('./test-utils').Fixture} */ let fixture; before(async () => { fixture = await loadFixture({ root: './fixtures/basics/', + output: 'server', adapter: cloudflare({ mode: 'directory' }), }); - }); - - it('Builds', async () => { await fixture.build(); }); + + it('generates functions folder inside the project root', async () => { + expect(await fixture.pathExists('../functions')).to.be.true; + }); });