Fix Cloudflare directory mode regression (#6046)
* Fix Cloudflare directory mode regression * Adding a changeset
This commit is contained in:
parent
d9787a6ff6
commit
df32011652
3 changed files with 33 additions and 6 deletions
5
.changeset/long-boats-perform.md
Normal file
5
.changeset/long-boats-perform.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/cloudflare': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Cloudflare fix for building to directory mode
|
|
@ -3,7 +3,7 @@ import esbuild from 'esbuild';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import glob from 'tiny-glob';
|
import glob from 'tiny-glob';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath, pathToFileURL } from 'url';
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
mode: 'directory' | 'advanced';
|
mode: 'directory' | 'advanced';
|
||||||
|
@ -89,9 +89,11 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'astro:build:done': async ({ pages }) => {
|
'astro:build:done': async ({ pages }) => {
|
||||||
const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server)),
|
const entryPath = fileURLToPath(new URL(_buildConfig.serverEntry, _buildConfig.server));
|
||||||
entryUrl = new URL(_buildConfig.serverEntry, _config.outDir),
|
const entryUrl = new URL(_buildConfig.serverEntry, _config.outDir);
|
||||||
buildPath = fileURLToPath(entryUrl);
|
const buildPath = fileURLToPath(entryUrl);
|
||||||
|
// A URL for the final build path after renaming
|
||||||
|
const finalBuildUrl = pathToFileURL(buildPath.replace(/\.mjs$/, '.js'));
|
||||||
|
|
||||||
await esbuild.build({
|
await esbuild.build({
|
||||||
target: 'es2020',
|
target: 'es2020',
|
||||||
|
@ -108,7 +110,7 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Rename to worker.js
|
// 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
|
// throw the server folder in the bin
|
||||||
const serverUrl = new URL(_buildConfig.server);
|
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/`);
|
const functionsUrl = new URL(`file://${process.cwd()}/functions/`);
|
||||||
await fs.promises.mkdir(functionsUrl, { recursive: true });
|
await fs.promises.mkdir(functionsUrl, { recursive: true });
|
||||||
const directoryUrl = new URL('[[path]].js', functionsUrl);
|
const directoryUrl = new URL('[[path]].js', functionsUrl);
|
||||||
await fs.promises.rename(entryUrl, directoryUrl);
|
await fs.promises.rename(finalBuildUrl, directoryUrl);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
20
packages/integrations/cloudflare/test/directory.test.js
Normal file
20
packages/integrations/cloudflare/test/directory.test.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
import { loadFixture, runCLI } from './test-utils.js';
|
||||||
|
import { expect } from 'chai';
|
||||||
|
import * as cheerio from 'cheerio';
|
||||||
|
import cloudflare from '../dist/index.js';
|
||||||
|
|
||||||
|
describe('mode: "directory"', () => {
|
||||||
|
/** @type {import('./test-utils').Fixture} */
|
||||||
|
let fixture;
|
||||||
|
|
||||||
|
before(async () => {
|
||||||
|
fixture = await loadFixture({
|
||||||
|
root: './fixtures/basics/',
|
||||||
|
adapter: cloudflare({ mode: 'directory' })
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Builds', async () => {
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue