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

chore(templates): integrate v2_dev #6650

Merged
merged 9 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
4 changes: 3 additions & 1 deletion templates/arc/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.DS_Store
node_modules

/.cache
/server/index.js
/server/index.mjs
/server/index.mjs.map
/public/build
preferences.arc
sam.json
Expand Down
12 changes: 12 additions & 0 deletions templates/arc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

## Development

Create a `preferences.arc` file in the root with the following contents:

```
@sandbox
livereload false

# NODE_ENV development is required when running the dev server
@env
testing
NODE_ENV development
```

The following command will run two processes during development when using Architect as your server.

- Your Architect server sandbox
Expand Down
4 changes: 4 additions & 0 deletions templates/arc/app.arc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ remix-architect-app

@static

@plugins
plugin-remix
src plugin-remix.js

# @aws
# profile default
# region us-west-1
Expand Down
1 change: 1 addition & 0 deletions templates/arc/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default function App() {
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" href="/_static/favicon.ico" />
<Meta />
<Links />
</head>
Expand Down
8 changes: 3 additions & 5 deletions templates/arc/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix build",
"dev:remix": "remix watch",
"dev:arc": "cross-env NODE_ENV=development arc sandbox",
"dev": "npm-run-all build --parallel \"dev:*\"",
"dev": "remix dev -c \"arc sandbox -e testing\"",
"start": "cross-env NODE_ENV=production arc sandbox",
"typecheck": "tsc"
},
Expand All @@ -20,13 +19,12 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@architect/architect": "^10.11.2",
"@architect/architect": "^10.12.1",
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"eslint": "^8.38.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.0.4"
},
"engines": {
Expand Down
37 changes: 37 additions & 0 deletions templates/arc/plugin-remix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// This should eventually be a npm package, but for now it lives here.
// It's job is to notify the remix dev server of the version of the running
// app to trigger HMR / HDR.

import * as fs from "node:fs";
import * as path from "node:path";
import { logDevReady } from "@remix-run/node";

const buildPath = "server/index.mjs";

let lastTimeout;

export default {
sandbox: {
async watcher() {
if (lastTimeout) {
clearTimeout(lastTimeout);
}

lastTimeout = setTimeout(async () => {
const contents = fs.readFileSync(
path.resolve(process.cwd(), buildPath),
"utf8"
);
const manifestMatches = contents.matchAll(/manifest-([A-f0-9]+)\.js/g);
const sent = new Set();
for (const match of manifestMatches) {
const buildHash = match[1];
if (!sent.has(buildHash)) {
sent.add(buildHash);
logDevReady({ assets: { version: buildHash } });
}
}
}, 300);
},
},
};
8 changes: 5 additions & 3 deletions templates/arc/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
export default {
ignoredRouteFiles: ["**/.*"],
publicPath: "/_static/build/",
server: "./server.ts",
serverBuildPath: "server/index.js",
server: "server.ts",
serverBuildPath: "server/index.mjs",
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
serverModuleFormat: "esm",
future: {
v2_dev: true,
v2_errorBoundary: true,
v2_headers: true,
v2_meta: true,
Expand Down
2 changes: 1 addition & 1 deletion templates/arc/server/config.arc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@aws
runtime nodejs14.x
runtime nodejs16.x
# memory 1152
# timeout 30
# concurrency 1
1 change: 1 addition & 0 deletions templates/cloudflare-pages/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules

/.cache
Expand Down
14 changes: 5 additions & 9 deletions templates/cloudflare-pages/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix build",
"dev:remix": "remix watch",
"dev:wrangler": "cross-env NODE_ENV=development npm run wrangler",
"dev": "npm-run-all build --parallel \"dev:*\"",
"start": "cross-env NODE_ENV=production npm run wrangler",
"typecheck": "tsc",
"wrangler": "wrangler pages dev ./public"
"dev": "remix dev --no-restart -c \"npm run start\"",
"start": "wrangler pages dev --compatibility-date=2023-06-21 ./public",
"typecheck": "tsc"
},
"dependencies": {
"@remix-run/cloudflare": "*",
"@remix-run/cloudflare-pages": "*",
"@remix-run/css-bundle": "*",
"@remix-run/react": "*",
"cross-env": "^7.0.3",
"isbot": "^3.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand All @@ -27,9 +24,8 @@
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"eslint": "^8.38.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.0.4",
"wrangler": "^2.15.1"
"wrangler": "^3.1.1"
},
"engines": {
"node": ">=16.13.0"
Expand Down
2 changes: 2 additions & 0 deletions templates/cloudflare-pages/public/_headers
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/favicon.ico
Cache-Control: public, max-age=3600, s-maxage=3600
/build/*
Cache-Control: public, max-age=31536000, immutable
2 changes: 1 addition & 1 deletion templates/cloudflare-pages/public/_routes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": 1,
"include": ["/*"],
"exclude": ["/build/*"]
"exclude": ["/favicon.ico", "/build/*"]
}
3 changes: 2 additions & 1 deletion templates/cloudflare-pages/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
export default {
devServerBroadcastDelay: 1000,
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
Expand All @@ -14,6 +14,7 @@ module.exports = {
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
future: {
v2_dev: true,
v2_errorBoundary: true,
v2_headers: true,
v2_meta: true,
Expand Down
7 changes: 6 additions & 1 deletion templates/cloudflare-pages/server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { logDevReady } from "@remix-run/cloudflare";
import { createPagesFunctionHandler } from "@remix-run/cloudflare-pages";
import * as build from "@remix-run/dev/server-build";

if (process.env.NODE_ENV === "development") {
logDevReady(build);
}

export const onRequest = createPagesFunctionHandler({
build,
getLoadContext: (context) => context.env,
getLoadContext: (context) => ({ env: context.env }),
mode: process.env.NODE_ENV,
});
2 changes: 0 additions & 2 deletions templates/cloudflare-pages/wrangler.toml

This file was deleted.

1 change: 1 addition & 0 deletions templates/cloudflare-workers/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules

/.cache
Expand Down
15 changes: 5 additions & 10 deletions templates/cloudflare-workers/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
{
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix build",
"deploy": "wrangler publish",
"dev:remix": "remix watch",
"dev:miniflare": "cross-env NODE_ENV=development miniflare ./build/index.js --watch",
"dev": "npm-run-all build --parallel \"dev:*\"",
"start": "cross-env NODE_ENV=production miniflare ./build/index.js",
"deploy": "remix build && wrangler publish",
"dev": "remix dev --no-restart -c \"npm start\"",
"start": "wrangler dev ./build/index.js",
"typecheck": "tsc"
},
"dependencies": {
"@remix-run/cloudflare": "*",
"@remix-run/cloudflare-workers": "*",
"@remix-run/css-bundle": "*",
"@remix-run/react": "*",
"cross-env": "^7.0.3",
"isbot": "^3.6.8",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand All @@ -27,10 +24,8 @@
"@types/react": "^18.0.35",
"@types/react-dom": "^18.0.11",
"eslint": "^8.38.0",
"miniflare": "^2.13.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.0.4",
"wrangler": "^2.15.1"
"wrangler": "^3.1.1"
},
"engines": {
"node": ">=16.13.0"
Expand Down
9 changes: 6 additions & 3 deletions templates/cloudflare-workers/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
devServerBroadcastDelay: 1000,
export default {
ignoredRouteFiles: ["**/.*"],
server: "./server.ts",
serverConditions: ["worker"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment I left on the last one—IMHO this should be ["workerd", "worker", "browser"]

serverDependenciesToBundle: "all",
serverDependenciesToBundle: [
// bundle verything except the virtual module for the static content manifest provided by wrangler
/^(?!.*\b__STATIC_CONTENT_MANIFEST\b).*$/,
],
serverMainFields: ["browser", "module", "main"],
serverMinify: true,
serverModuleFormat: "esm",
Expand All @@ -14,6 +16,7 @@ module.exports = {
// serverBuildPath: "build/index.js",
// publicPath: "/build/",
future: {
v2_dev: true,
v2_errorBoundary: true,
v2_headers: true,
v2_meta: true,
Expand Down
5 changes: 5 additions & 0 deletions templates/cloudflare-workers/remix.env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/// <reference types="@remix-run/dev" />
/// <reference types="@remix-run/cloudflare" />
/// <reference types="@cloudflare/workers-types" />

declare module "__STATIC_CONTENT_MANIFEST" {
const manifest: string;
export default manifest;
}
56 changes: 51 additions & 5 deletions templates/cloudflare-workers/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,53 @@
import { createEventHandler } from "@remix-run/cloudflare-workers";
import { getAssetFromKV } from "@cloudflare/kv-asset-handler";
import type { AppLoadContext } from "@remix-run/cloudflare";
import { createRequestHandler, logDevReady } from "@remix-run/cloudflare";
import * as build from "@remix-run/dev/server-build";
import __STATIC_CONTENT_MANIFEST from "__STATIC_CONTENT_MANIFEST";

addEventListener(
"fetch",
createEventHandler({ build, mode: process.env.NODE_ENV })
);
const MANIFEST = JSON.parse(__STATIC_CONTENT_MANIFEST);
const handleRemixRequest = createRequestHandler(build, process.env.NODE_ENV);

if (build.dev) {
logDevReady(build);
}

export default {
async fetch(
request: Request,
env: {
__STATIC_CONTENT: Fetcher;
},
ctx: ExecutionContext
): Promise<Response> {
try {
const url = new URL(request.url);
const ttl = url.pathname.startsWith("/build/")
? 60 * 60 * 24 * 365 // 1 year
: 60 * 5; // 5 minutes
return await getAssetFromKV(
{
request,
waitUntil: ctx.waitUntil.bind(ctx),
} as FetchEvent,
{
ASSET_NAMESPACE: env.__STATIC_CONTENT,
ASSET_MANIFEST: MANIFEST,
cacheControl: {
browserTTL: ttl,
edgeTTL: ttl,
},
}
);
} catch (error) {}

try {
const loadContext: AppLoadContext = {
env,
};
return await handleRemixRequest(request, loadContext);
} catch (error) {
console.log(error);
return new Response("An unexpected error occurred", { status: 500 });
}
},
};
7 changes: 1 addition & 6 deletions templates/cloudflare-workers/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ name = "remix-cloudflare-workers"
workers_dev = true
main = "./build/index.js"
# https://developers.cloudflare.com/workers/platform/compatibility-dates
compatibility_date = "2022-04-05"
compatibility_flags = ["streams_enable_constructors"]
compatibility_date = "2023-04-20"

[site]
bucket = "./public"

[build]
command = "npm run build"

File renamed without changes.