feat(cloudflare): add support for user defined entryfile#13837
feat(cloudflare): add support for user defined entryfile#13837alexanderniebuhr merged 18 commits intomainfrom
Conversation
🦋 Changeset detectedLatest commit: ecab6a3 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
astro
@astrojs/cloudflare
@astrojs/netlify
@astrojs/node
@astrojs/vercel
commit: |
59064a4 to
eb32a48
Compare
|
I think I would rename |
|
I like the suggestion, however we need to allow the option to add other named exports, since Cloudflare Durable Options needs them. |
|
Do you have an example of that? Maybe official cloudflare docs? |
|
@florian-lefebvre you can see an example of a whole entryfile here: https://developers.cloudflare.com/durable-objects/get-started/#summary-and-final-code |
|
Ah I missed the |
I can't answer that, but it would be amazing and best if core could either allow all exports, or maybe infer them automatically and process them. Not sure who is the best to ask about it? 🤔 |
|
cc @ematipico maybe you have context on that? |
|
I would like to answer your question, however I miss a lot of context of what we're trying to do. For example the description of the PR doesn't explain what this new feature is about, and I can't understand the connection of the feature with "export everything from core". Could you provide more information, please? Happy to help! |
|
@ematipico This PR adds the optional possibility for a user to provide their own A user defined import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
import { handle } from '@astrojs/cloudflare/handler'
import { DurableObject } from 'cloudflare:workers';
class MyDurableObject extends DurableObject<Env> {
constructor(ctx: DurableObjectState, env: Env) {
// Required, as we're extending the base class.
super(ctx, env)
}
}
export function createExports(manifest: SSRManifest) {
const app = new App(manifest);
return {
default: {
async fetch(request, env, ctx) {
return handle(manifest, app, request, env, ctx);
},
} satisfies ExportedHandler<Env>,
MyDurableObject: MyDurableObject,
}
}As you can see in this example it has Can we get rid of the |
I believe everything is possible, we just need to find a way around it :) Here's the code that handles the astro/packages/astro/src/core/build/plugins/plugin-ssr.ts Lines 186 to 195 in fbcfa68 As you can see, that array is used to generate the proper SSR code ( We could create an option, like |
|
Cool. Still that is out of scope for this PR. I'll add an issue to track and investigate it. |
ematipico
left a comment
There was a problem hiding this comment.
Overall, the feature seems good. I left some comments in the code. The changeset is missing, can you please add it?
florian-lefebvre
left a comment
There was a problem hiding this comment.
Don't forget the changeset!
sarah11918
left a comment
There was a problem hiding this comment.
Quick thoughts on the changeset for your configuration, @alexanderniebuhr
ematipico
left a comment
There was a problem hiding this comment.
There's some inconsistency between the docs of the new options and their implementation. To be more precise, workerEntryPoint.exports now says:
By default, this is set to
['default']
I don't know which one is the correct one, and it should be addressed.
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
packages/integrations/cloudflare/test/fixtures/custom-entryfile/worker-configuration.d.ts
Outdated
Show resolved
Hide resolved
florian-lefebvre
left a comment
There was a problem hiding this comment.
Some little knits but looks good to me!
|
I all address all your nits in a second :) |
|
Just checking here because there's some discrepency in the docs PR:
Just want to make sure I know what's happening here! |
Yes that's correct.
By default it is undefined. Not sure if an empty array is better.
That explanation is correct. So yeah |
Oh, that's fine! I was noticing in the docs PR where the default value was still listed as This all makes sense now. 😄 |
sarah11918
left a comment
There was a problem hiding this comment.
Changeset here looks good! (one small missing word).
Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
…3837) Co-authored-by: Sarah Rainsberger <5098874+sarah11918@users.noreply.github.com>
Changes
Testing
Docs