summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nacho Vazquez <nachovc1410@gmail.com> 2023-02-03 12:19:44 -0300
committerGravatar GitHub <noreply@github.com> 2023-02-03 16:19:44 +0100
commit45b41d98f50dc9f76a5004a8b3346f393f1a6cb6 (patch)
tree682baae31d09194e2281d1b100d8b032aaf86ba2
parent79fca438e97a5d0f25defd28676835ab3885149b (diff)
downloadastro-45b41d98f50dc9f76a5004a8b3346f393f1a6cb6.tar.gz
astro-45b41d98f50dc9f76a5004a8b3346f393f1a6cb6.tar.zst
astro-45b41d98f50dc9f76a5004a8b3346f393f1a6cb6.zip
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
-rw-r--r--.changeset/honest-beds-flow.md5
-rw-r--r--packages/integrations/cloudflare/src/index.ts2
-rw-r--r--packages/integrations/cloudflare/test/directory.test.js11
3 files changed, 12 insertions, 6 deletions
diff --git a/.changeset/honest-beds-flow.md b/.changeset/honest-beds-flow.md
new file mode 100644
index 000000000..ddf54699f
--- /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 3433cf46d..7ba1cc631 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 7c299f526..e5b520574 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' }),
});
+ await fixture.build();
});
- it('Builds', async () => {
- await fixture.build();
+ it('generates functions folder inside the project root', async () => {
+ expect(await fixture.pathExists('../functions')).to.be.true;
});
});