From cd25d605cf8bb9d79f76b414dad05ab5ba696afc Mon Sep 17 00:00:00 2001 From: Nacho Vazquez Date: Fri, 3 Feb 2023 08:15:41 -0300 Subject: [PATCH] fix: use URL construction method correctly --- packages/integrations/cloudflare/src/index.ts | 18 +++++++++--------- .../cloudflare/test/directory.test.js | 5 +---- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts index 82cec2974acab..7ba1cc63148a9 100644 --- a/packages/integrations/cloudflare/src/index.ts +++ b/packages/integrations/cloudflare/src/index.ts @@ -18,15 +18,15 @@ interface BuildConfig { export function getAdapter(isModeDirectory: boolean): AstroAdapter { return isModeDirectory ? { - name: '@astrojs/cloudflare', - serverEntrypoint: '@astrojs/cloudflare/server.directory.js', - exports: ['onRequest'], - } + name: '@astrojs/cloudflare', + serverEntrypoint: '@astrojs/cloudflare/server.directory.js', + exports: ['onRequest'], + } : { - name: '@astrojs/cloudflare', - serverEntrypoint: '@astrojs/cloudflare/server.advanced.js', - exports: ['default'], - }; + name: '@astrojs/cloudflare', + serverEntrypoint: '@astrojs/cloudflare/server.advanced.js', + exports: ['default'], + }; } const SHIM = `globalThis.process = { @@ -203,7 +203,7 @@ export default function createIntegration(args?: Options): AstroIntegration { } if (isModeDirectory) { - const functionsUrl = new URL(`file://${_config.root}/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 860af7f4958e8..e0d74657bbcdf 100644 --- a/packages/integrations/cloudflare/test/directory.test.js +++ b/packages/integrations/cloudflare/test/directory.test.js @@ -2,8 +2,8 @@ import { loadFixture } from './test-utils.js'; import { expect } from 'chai'; import cloudflare from '../dist/index.js'; +/** @type {import('./test-utils').Fixture} */ describe('mode: "directory"', () => { - /** @type {import('./test-utils').Fixture} */ let fixture; before(async () => { @@ -16,9 +16,6 @@ describe('mode: "directory"', () => { }); it('generates the functions folder on under the config root', async () => { - // const functions = await fixture.readFile('/_routes.json') - // expect(routes.exclude).to.include('/one/'); - console.log(await fixture.readdir('../../basics')); expect(await fixture.pathExists('../functions')).to.be.true; }); });