summaryrefslogtreecommitdiff
path: root/packages/integrations/cloudflare/src
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@skypack.dev> 2023-01-30 14:50:44 -0500
committerGravatar GitHub <noreply@github.com> 2023-01-30 14:50:44 -0500
commit16ddf556b5932bcce9f6500d72d0202e93772ef5 (patch)
tree989273e8e807e2cce0c756ba6e03f7883efaf7a6 /packages/integrations/cloudflare/src
parent4eb4ef2b6391f99d27324483551996136f6de4a6 (diff)
downloadastro-16ddf556b5932bcce9f6500d72d0202e93772ef5.tar.gz
astro-16ddf556b5932bcce9f6500d72d0202e93772ef5.tar.zst
astro-16ddf556b5932bcce9f6500d72d0202e93772ef5.zip
Fix Cloudflare directory mode regression (#6046)
* Fix Cloudflare directory mode regression * Adding a changeset
Diffstat (limited to 'packages/integrations/cloudflare/src')
-rw-r--r--packages/integrations/cloudflare/src/index.ts14
1 files changed, 8 insertions, 6 deletions
diff --git a/packages/integrations/cloudflare/src/index.ts b/packages/integrations/cloudflare/src/index.ts
index a859e3009..3433cf46d 100644
--- a/packages/integrations/cloudflare/src/index.ts
+++ b/packages/integrations/cloudflare/src/index.ts
@@ -3,7 +3,7 @@ import esbuild from 'esbuild';
import * as fs from 'fs';
import * as os from 'os';
import glob from 'tiny-glob';
-import { fileURLToPath } from 'url';
+import { fileURLToPath, pathToFileURL } from 'url';
type Options = {
mode: 'directory' | 'advanced';
@@ -89,9 +89,11 @@ export default function createIntegration(args?: Options): AstroIntegration {
}
},
'astro:build:done': async ({ pages }) => {
- const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)),
- entryUrl = new URL(_buildConfig.serverEntry, _config.outDir),
- buildPath = fileURLToPath(entryUrl);
+ const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
+ const entryUrl = new URL(_buildConfig.serverEntry, _config.outDir);
+ const buildPath = fileURLToPath(entryUrl);
+ // A URL for the final build path after renaming
+ const finalBuildUrl = pathToFileURL(buildPath.replace(/\.mjs$/, '.js'));
await esbuild.build({
target: 'es2020',
@@ -108,7 +110,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
});
// Rename to worker.js
- await fs.promises.rename(buildPath, buildPath.replace(/\.mjs$/, '.js'));
+ await fs.promises.rename(buildPath, finalBuildUrl);
// throw the server folder in the bin
const serverUrl = new URL(_buildConfig.server);
@@ -204,7 +206,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
const functionsUrl = new URL(`file://${process.cwd()}/functions/`);
await fs.promises.mkdir(functionsUrl, { recursive: true });
const directoryUrl = new URL('[[path]].js', functionsUrl);
- await fs.promises.rename(entryUrl, directoryUrl);
+ await fs.promises.rename(finalBuildUrl, directoryUrl);
}
},
},