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
This commit is contained in:
Nacho Vazquez 2023-02-03 12:19:44 -03:00 committed by GitHub
parent 79fca438e9
commit 45b41d98f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---
Uses config root path as location for Cloudflare Pages Functions

View file

@ -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);

View file

@ -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;
});
});