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:
parent
79fca438e9
commit
45b41d98f5
3 changed files with 13 additions and 7 deletions
5
.changeset/honest-beds-flow.md
Normal file
5
.changeset/honest-beds-flow.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/cloudflare': patch
|
||||
---
|
||||
|
||||
Uses config root path as location for Cloudflare Pages Functions
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue