Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@astrojs/cloudflare): SSR split file renaming misses ts endpoints #7568

Merged
merged 14 commits into from
Jul 17, 2023
Next Next commit
fix bug, where ts files where not renamed correctly
  • Loading branch information
alexanderniebuhr committed Jul 17, 2023
commit dcdb26d186e89d31516bce06fed3237ae1fbdab4
5 changes: 5 additions & 0 deletions .changeset/sweet-bats-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

fix bug where `.ts` files are not renamed to `.js
23 changes: 12 additions & 11 deletions packages/integrations/cloudflare/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ interface BuildConfig {
export function getAdapter(isModeDirectory: boolean): AstroAdapter {
return isModeDirectory
? {
name: '@astrojs/cloudflare',
serverEntrypoint: '@astrojs/cloudflare/server.directory.js',
exports: ['onRequest', 'manifest'],
}
name: '@astrojs/cloudflare',
serverEntrypoint: '@astrojs/cloudflare/server.directory.js',
exports: ['onRequest', 'manifest'],
}
: {
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 = {
Expand Down Expand Up @@ -138,7 +138,8 @@ export default function createIntegration(args?: Options): AstroIntegration {
const fileName = entryPointsRouteData[index].component
.replace('src/pages/', '')
.replace('.astro', '.js')
.replace(/(\[\.\.\.)(\w+)(\])/g, (_match, _p1, p2) => {
.replace('.ts', '.js')
.replace(/(\[\.\.\.)(\w+)(\])/g, (_match, _p1, p2, _p3) => {
return `[[${p2}]]`;
});

Expand Down Expand Up @@ -184,8 +185,8 @@ export default function createIntegration(args?: Options): AstroIntegration {
}

// // // throw the server folder in the bin
const serverUrl = new URL(_buildConfig.server);
await fs.promises.rm(serverUrl, { recursive: true, force: true });
// const serverUrl = new URL(_buildConfig.server);
// await fs.promises.rm(serverUrl, { recursive: true, force: true });

// move cloudflare specific files to the root
const cloudflareSpecialFiles = ['_headers', '_redirects', '_routes.json'];
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/cloudflare/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export function getProcessEnvProxy() {
console.warn(
// NOTE: \0 prevents Vite replacement
`Unable to access \`import.meta\0.env.${prop.toString()}\` on initialization ` +
`as the Cloudflare platform only provides the environment variables per request. ` +
`Please move the environment variable access inside a function ` +
`that's only called after a request has been received.`
`as the Cloudflare platform only provides the environment variables per request. ` +
`Please move the environment variable access inside a function ` +
`that's only called after a request has been received.`
);
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe('Cloudflare SSR split', () => {
expect(await fixture.pathExists('../functions/[person]/[car].js')).to.be.true;
expect(await fixture.pathExists('../functions/files/[[path]].js')).to.be.true;
expect(await fixture.pathExists('../functions/[language]/files/[[path]].js')).to.be.true;
expect(await fixture.pathExists('../functions/trpc/[trpc].js')).to.be.true;
});

it('generates pre-rendered files', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const prerender = false

import type { APIRoute } from 'astro'

export const all: APIRoute = (opts) => {
return ""
}