diff --git a/.vscode/deno_resolve_npm_imports.json b/.vscode/deno_resolve_npm_imports.json index 8444a962762..8917f882799 100644 --- a/.vscode/deno_resolve_npm_imports.json +++ b/.vscode/deno_resolve_npm_imports.json @@ -7,7 +7,7 @@ "// Deno-only dependencies may be imported via URL imports (without using import maps).": "", "imports": { - "mime": "https://esm.sh/mime@3.0.0", - "@remix-run/server-runtime": "https://esm.sh/@remix-run/server-runtime@1.4.3" + "@remix-run/server-runtime": "https://esm.sh/@remix-run/server-runtime@1.5.0", + "mime": "https://esm.sh/mime@3.0.0" } } diff --git a/contributors.yml b/contributors.yml index a00b6884246..bfb5eb0f5c7 100644 --- a/contributors.yml +++ b/contributors.yml @@ -155,6 +155,7 @@ - jesse-deboer - jesseflorig - jgarrow +- jiahao-c - jkup - jmasson - jo-ninja diff --git a/packages/remix-deno/README.md b/packages/remix-deno/README.md index 91fea4a8312..3d505adbd12 100644 --- a/packages/remix-deno/README.md +++ b/packages/remix-deno/README.md @@ -7,7 +7,7 @@ For more, see the [Remix docs](https://remix.run/docs/). ## Install Installation is done via `npm`, but the code itself is Deno source code. -Read more about [why we use `npm` to manage dependencies for Deno projects](https://github.com/remix-run/remix/blob/main/docs/decisions/0001-use-npm-to-manage-npm-dependencies-for-deno-projects.md) in Remix. +Read more about [why we use `npm` to manage dependencies for Deno projects](https://github.com/remix-run/remix/blob/main/decisions/0001-use-npm-to-manage-npm-dependencies-for-deno-projects.md) in Remix. ```sh npm install @remix-run/deno diff --git a/packages/remix-server-runtime/README.md b/packages/remix-server-runtime/README.md index 97d479b23de..fcbe3a7c0d3 100644 --- a/packages/remix-server-runtime/README.md +++ b/packages/remix-server-runtime/README.md @@ -10,7 +10,7 @@ Support for each runtime is provided by a corresponding Remix package: - [`@remix-run/node`](https://github.com/remix-run/remix/tree/main/packages/remix-node) - [`@remix-run/cloudflare`](https://github.com/remix-run/remix/tree/main/packages/remix-cloudflare) -- [`remix-deno`](https://github.com/remix-run/remix/tree/main/templates/deno/remix-deno) (will be renamed to `@remix-run/deno` when Deno support is stable) +- [`@remix-run/deno`](https://github.com/remix-run/remix/tree/main/packages/remix-deno) This package defines a "Remix server runtime interface" that each runtime package must conform to. diff --git a/scripts/utils.js b/scripts/utils.js index 6c58735ad90..cd46b3b636b 100644 --- a/scripts/utils.js +++ b/scripts/utils.js @@ -176,6 +176,52 @@ async function updateDeploymentScriptVersion(nextVersion) { ); } +/** + * @param {string} importSpecifier + * @returns {[string, string]} [packageName, importPath] + */ +const getPackageNameFromImportSpecifier = (importSpecifier) => { + if (importSpecifier.startsWith("@")) { + let [scope, pkg, ...path] = importSpecifier.split("/"); + return [`${scope}/${pkg}`, path.join("/")]; + } + + let [pkg, ...path] = importSpecifier.split("/"); + return [pkg, path.join("/")]; +}; +/** + * @param {string} importMapPath + * @param {string} nextVersion + */ +const updateDenoImportMap = async (importMapPath, nextVersion) => { + let { imports, ...json } = await jsonfile.readFile(importMapPath); + let remixPackagesFull = remixPackages.all.map( + (remixPackage) => `@remix-run/${remixPackage}` + ); + + let newImports = Object.fromEntries( + Object.entries(imports).map(([importName, path]) => { + let [packageName, importPath] = + getPackageNameFromImportSpecifier(importName); + + return remixPackagesFull.includes(packageName) + ? [ + importName, + `https://esm.sh/${packageName}@${nextVersion}${ + importPath ? `/${importPath}` : "" + }`, + ] + : [importName, path]; + }) + ); + + return jsonfile.writeFile( + importMapPath, + { ...json, imports: newImports }, + { spaces: 2 } + ); +}; + /** * @param {string} nextVersion */ @@ -187,6 +233,16 @@ async function incrementRemixVersion(nextVersion) { await updateRemixVersion(`remix-${name}`, nextVersion); } + // Update version numbers in Deno's import maps + await Promise.all( + [ + path.join(".vscode", "deno_resolve_npm_imports.json"), + path.join("templates", "deno", ".vscode", "resolve_npm_imports.json"), + ].map((importMapPath) => + updateDenoImportMap(path.join(rootDir, importMapPath), nextVersion) + ) + ); + // Update versions in the examples await updateExamplesRemixVersion(nextVersion); diff --git a/templates/deno/.gitignore b/templates/deno/.gitignore index 2b5c2c32959..3f7bf98da3e 100644 --- a/templates/deno/.gitignore +++ b/templates/deno/.gitignore @@ -1,5 +1,6 @@ -/node_modules/ +node_modules /.cache /build -/public/build \ No newline at end of file +/public/build +.env diff --git a/templates/deno/.vscode/resolve_npm_imports.json b/templates/deno/.vscode/resolve_npm_imports.json index 2a7dcfdd408..cc8c5120409 100644 --- a/templates/deno/.vscode/resolve_npm_imports.json +++ b/templates/deno/.vscode/resolve_npm_imports.json @@ -5,11 +5,11 @@ "// Deno-only dependencies may be imported via URL imports (without using import maps).": "", "imports": { - "react": "https://esm.sh/react@18.0.0", - "react-dom": "https://esm.sh/react-dom@18.0.0", - "react-dom/server": "https://esm.sh/react-dom@18.0.0/server", - "@remix-run/dev/server-build": "https://esm.sh/@remix-run/dev@1.4.3/server-build", - "@remix-run/deno": "https://esm.sh/@remix-run/deno@1.4.3", - "@remix-run/react": "https://esm.sh/@remix-run/react@1.4.3" + "@remix-run/deno": "https://esm.sh/@remix-run/deno@1.5.0", + "@remix-run/dev/server-build": "https://esm.sh/@remix-run/dev@1.5.0/server-build", + "@remix-run/react": "https://esm.sh/@remix-run/react@1.5.0", + "react": "https://esm.sh/react@17.0.2", + "react-dom": "https://esm.sh/react-dom@17.0.2", + "react-dom/server": "https://esm.sh/react-dom@17.0.2/server" } } diff --git a/templates/deno/.vscode/settings.json b/templates/deno/.vscode/settings.json index c58c9450882..2fe1308e465 100644 --- a/templates/deno/.vscode/settings.json +++ b/templates/deno/.vscode/settings.json @@ -1,5 +1,5 @@ { "deno.enable": true, - "deno.lint": true, - "deno.importMap": "./.vscode/resolve_npm_imports.json" + "deno.importMap": "./.vscode/resolve_npm_imports.json", + "deno.lint": true } diff --git a/templates/deno/README.md b/templates/deno/README.md index 27676ec9e9a..a5e11fc3ee9 100644 --- a/templates/deno/README.md +++ b/templates/deno/README.md @@ -12,8 +12,7 @@ npx create-remix@latest --template deno ## Managing dependencies -Read about [how we recommend to manage dependencies for Remix projects using Deno](https://github.com/remix-run/remix/blob/main/docs/decisions/0001-use-npm-to-manage-npm-dependencies-for-deno-projects.md -). +Read about [how we recommend to manage dependencies for Remix projects using Deno](https://github.com/remix-run/remix/blob/main/decisions/0001-use-npm-to-manage-npm-dependencies-for-deno-projects.md). - ✅ You should use `npm` to install NPM packages ```sh diff --git a/templates/deno/app/entry.client.tsx b/templates/deno/app/entry.client.tsx index 62a6a81634d..fa091046ff3 100644 --- a/templates/deno/app/entry.client.tsx +++ b/templates/deno/app/entry.client.tsx @@ -1,5 +1,5 @@ -import React from "react"; -import ReactDOM from "react-dom"; import { RemixBrowser } from "@remix-run/react"; +import * as React from "react"; +import { hydrate } from "react-dom"; -ReactDOM.hydrate(, document); +hydrate(, document); diff --git a/templates/deno/app/entry.server.tsx b/templates/deno/app/entry.server.tsx index 5aff7ec014f..24bf2d741d5 100644 --- a/templates/deno/app/entry.server.tsx +++ b/templates/deno/app/entry.server.tsx @@ -1,7 +1,7 @@ -import React from "react"; -import { renderToString } from "react-dom/server"; -import { RemixServer } from "@remix-run/react"; import type { EntryContext } from "@remix-run/deno"; +import { RemixServer } from "@remix-run/react"; +import * as React from "react"; +import { renderToString } from "react-dom/server"; export default function handleRequest( request: Request, diff --git a/templates/deno/app/root.tsx b/templates/deno/app/root.tsx index a74cc0195c0..9171cb50f31 100644 --- a/templates/deno/app/root.tsx +++ b/templates/deno/app/root.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import type { MetaFunction } from "@remix-run/deno"; import { Links, LiveReload, @@ -7,7 +7,7 @@ import { Scripts, ScrollRestoration, } from "@remix-run/react"; -import type { MetaFunction } from "@remix-run/deno"; +import * as React from "react"; export const meta: MetaFunction = () => ({ charset: "utf-8", diff --git a/templates/deno/app/routes/index.tsx b/templates/deno/app/routes/index.tsx index f2280e0a045..7c22c07c9c4 100644 --- a/templates/deno/app/routes/index.tsx +++ b/templates/deno/app/routes/index.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import * as React from "react"; export default function Index() { return ( diff --git a/templates/deno/package.json b/templates/deno/package.json index fc89fb07dde..7c9e26b23c9 100644 --- a/templates/deno/package.json +++ b/templates/deno/package.json @@ -5,11 +5,11 @@ "scripts": { "build": "remix build", "dev": "remix build && run-p dev:*", - "dev:remix": "remix watch", "dev:deno": "cross-env NODE_ENV=development deno run --unstable --watch --allow-net --allow-read --allow-env ./build/index.js", - "start": "cross-env NODE_ENV=production deno run --unstable --allow-net --allow-read --allow-env ./build/index.js", + "dev:remix": "remix watch", + "format": "deno fmt --ignore=node_modules", "lint": "deno lint --ignore=node_modules", - "format": "deno fmt --ignore=node_modules" + "start": "cross-env NODE_ENV=production deno run --unstable --allow-net --allow-read --allow-env ./build/index.js" }, "dependencies": { "@remix-run/deno": "*", diff --git a/templates/deno/remix.config.js b/templates/deno/remix.config.js index 625a152107a..4dde611cb5c 100644 --- a/templates/deno/remix.config.js +++ b/templates/deno/remix.config.js @@ -1,7 +1,6 @@ module.exports = { serverBuildTarget: "deno", server: "./server.ts", - /* If live reload causes page to re-render without changes (live reload is too fast), increase the dev server broadcast delay. @@ -9,4 +8,9 @@ module.exports = { If live reload seems slow, try to decrease the dev server broadcast delay. */ devServerBroadcastDelay: 300, + ignoredRouteFiles: ["**/.*"], + // appDirectory: "app", + // assetsBuildDirectory: "public/build", + // serverBuildPath: "build/index.js", + // publicPath: "/build/", }; diff --git a/templates/vercel/.gitignore b/templates/vercel/.gitignore index 67dd546d779..5d6a1751325 100644 --- a/templates/vercel/.gitignore +++ b/templates/vercel/.gitignore @@ -8,3 +8,4 @@ node_modules /build/ /public/build /api/index.js +/api/index.js.map