-
Notifications
You must be signed in to change notification settings - Fork 749
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
[C3] Use new vite based Remix template #5080
Merged
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6c46cae
Addressing PR feedback
jculvey 90628d2
Remove unwanted lockfile changes
jculvey 82b4e51
C3: Use new vite-cloudflare template in Remix projects
jculvey e5db867
Add e2e tests for remix
jculvey ddab6f3
Add ability to skip deploy in e2e and fix issue with verifyDev
jculvey 50b201e
changeset
jculvey c97ed2f
Skip win32 e2e for remix
jculvey c9f1634
Address PR feedback
jculvey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
"create-cloudflare": minor | ||
--- | ||
|
||
feature: Use new `vite-cloudflare` template in Remix projects. | ||
|
||
Remix has released a [new official Cloudflare template](https://remix.run/docs/en/main/future/vite#cloudflare-proxy) that uses `getBindingsProxy` under the hood to provide better support for bindings in dev. Remix projects created with C3 will now use this new template. | ||
|
||
Along with this change, projects will use the default vite-based dev command from `create-remix` instead of using `wrangler pages dev` on build output. | ||
|
||
A new `build-cf-types` script has also been added to re-generate the `Env` type defined in `load-context.ts` based on the contents of `wrangler.toml`. A default `wrangler.toml` will be added to new Remix projects to accomodate this workflow. |
20 changes: 20 additions & 0 deletions
20
packages/create-cloudflare/e2e-tests/fixtures/remix/app/routes/test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { LoaderFunctionArgs } from "@remix-run/cloudflare"; | ||
|
||
export async function loader({ context }: LoaderFunctionArgs) { | ||
const { env } = context.cloudflare; | ||
|
||
const { TEST } = env; | ||
|
||
return new Response( | ||
JSON.stringify({ | ||
success: true, | ||
test: TEST, | ||
}), | ||
{ | ||
status: 200, | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
} | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
packages/create-cloudflare/e2e-tests/fixtures/remix/wrangler.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[vars] | ||
TEST = "C3_TEST" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { logRaw } from "@cloudflare/cli"; | ||
import { brandColor } from "@cloudflare/cli/colors"; | ||
import { spinner } from "@cloudflare/cli/interactive"; | ||
import { transformFile } from "helpers/codemod"; | ||
import { runFrameworkGenerator } from "helpers/command.js"; | ||
import { detectPackageManager } from "helpers/packages"; | ||
import type { TemplateConfig } from "../../src/templates"; | ||
|
@@ -10,24 +13,55 @@ const generate = async (ctx: C3Context) => { | |
await runFrameworkGenerator(ctx, [ | ||
ctx.project.name, | ||
"--template", | ||
"https://github.com/remix-run/remix/tree/main/templates/cloudflare-pages", | ||
"https://github.com/remix-run/remix/tree/main/templates/vite-cloudflare", | ||
]); | ||
|
||
logRaw(""); // newline | ||
}; | ||
|
||
const configure = async () => { | ||
const typeDefsPath = "load-context.ts"; | ||
|
||
const s = spinner(); | ||
s.start(`Updating \`${typeDefsPath}\``); | ||
|
||
// Remove the empty Env declaration from the template to allow the type from | ||
// worker-configuration.d.ts to take over | ||
transformFile(typeDefsPath, { | ||
visitTSInterfaceDeclaration(n) { | ||
if (n.node.id.type === "Identifier" && n.node.id.name !== "Env") { | ||
return this.traverse(n); | ||
} | ||
|
||
// Removes the node | ||
n.replace(); | ||
return false; | ||
}, | ||
}); | ||
|
||
s.stop(`${brandColor("updated")} \`${typeDefsPath}\``); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
|
||
const config: TemplateConfig = { | ||
configVersion: 1, | ||
id: "remix", | ||
displayName: "Remix", | ||
platform: "pages", | ||
displayName: "Remix", | ||
copyFiles: { | ||
path: "./templates", | ||
}, | ||
generate, | ||
configure, | ||
transformPackageJson: async () => ({ | ||
scripts: { | ||
"pages:deploy": `${npm} run build && wrangler pages deploy ./public`, | ||
deploy: `${npm} run build && wrangler pages deploy ./build/client`, | ||
preview: `${npm} run build && wrangler pages dev ./build/client`, | ||
"build-cf-types": `wrangler types`, | ||
}, | ||
}), | ||
devScript: "dev", | ||
deployScript: "deploy", | ||
previewScript: "preview", | ||
testFlags: ["--typescript", "--no-install", "--no-git-init"], | ||
}; | ||
export default config; |
3 changes: 3 additions & 0 deletions
3
packages/create-cloudflare/templates/remix/templates/worker-configuration.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Generated by Wrangler on Fri Feb 16 2024 15:52:18 GMT-0600 (Central Standard Time) | ||
// After adding bindings to `wrangler.toml`, regenerate this interface via `npm build-cf-types` | ||
interface Env {} |
50 changes: 50 additions & 0 deletions
50
packages/create-cloudflare/templates/remix/templates/wrangler.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name = "<TBD>" | ||
compatibility_date = "<TBD>" | ||
|
||
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables) | ||
# Note: Use secrets to store sensitive data. | ||
# Docs: https://developers.cloudflare.com/workers/platform/environment-variables | ||
# [vars] | ||
# MY_VARIABLE = "production_value" | ||
|
||
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs. | ||
# Docs: https://developers.cloudflare.com/workers/runtime-apis/kv | ||
# [[kv_namespaces]] | ||
# binding = "MY_KV_NAMESPACE" | ||
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | ||
|
||
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files. | ||
# Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/ | ||
# [[r2_buckets]] | ||
# binding = "MY_BUCKET" | ||
# bucket_name = "my-bucket" | ||
|
||
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer. | ||
# Docs: https://developers.cloudflare.com/queues/get-started | ||
# [[queues.producers]] | ||
# binding = "MY_QUEUE" | ||
# queue = "my-queue" | ||
|
||
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them. | ||
# Docs: https://developers.cloudflare.com/queues/get-started | ||
# [[queues.consumers]] | ||
# queue = "my-queue" | ||
|
||
# Bind another Worker service. Use this binding to call another Worker without network overhead. | ||
# Docs: https://developers.cloudflare.com/workers/platform/services | ||
# [[services]] | ||
# binding = "MY_SERVICE" | ||
# service = "my-service" | ||
|
||
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model. | ||
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps. | ||
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects | ||
# [[durable_objects.bindings]] | ||
# name = "MY_DURABLE_OBJECT" | ||
# class_name = "MyDurableObject" | ||
|
||
# Durable Object migrations. | ||
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations | ||
# [[migrations]] | ||
# tag = "v1" | ||
# new_classes = ["MyDurableObject"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.