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: update Deno import maps on release #3225

Merged
merged 11 commits into from
May 19, 2022
4 changes: 2 additions & 2 deletions .vscode/deno_resolve_npm_imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"// Deno-only dependencies may be imported via URL imports (without using import maps).": "",

"imports": {
"mime": "https://esm.sh/[email protected].0",
"@remix-run/server-runtime": "https://esm.sh/@remix-run/[email protected]"
"@remix-run/server-runtime": "https://esm.sh/@remix-run/[email protected].0",
"mime": "https://esm.sh/[email protected]"
}
}
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
- jesse-deboer
- jesseflorig
- jgarrow
- jiahao-c
- jkup
- jmasson
- jo-ninja
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: 0001 - Use npm to manage NPM dependencies for Deno projects
---

# Use `npm` to manage NPM dependencies for Deno projects

Date: 2022-05-10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: 0002 - Do not clone request
---

# Do not clone request

Date: 2022-05-13
Expand Down
3 changes: 3 additions & 0 deletions decisions/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
title: Decisions
---
4 changes: 4 additions & 0 deletions docs/decisions/template.md → decisions/template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
title: Title
---

# Title

Date: YYYY-MM-DD
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/remix-server-runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
13 changes: 12 additions & 1 deletion scripts/publish-private.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ function getTaggedVersion() {
return output.replace(/^v/g, "");
}

/**
* @param {string} dir
* @param {string} tag
*/
function publish(dir, tag) {
execSync(`npm publish --tag ${tag} ${dir}`, { stdio: "inherit" });
}
Expand All @@ -23,7 +27,14 @@ async function run() {
}

let prerelease = semver.prerelease(taggedVersion);
let tag = prerelease ? prerelease[0] : "latest";
let prereleaseTag = prerelease ? String(prerelease[0]) : undefined;
let tag = prereleaseTag
? prereleaseTag.includes("nightly")
? "nightly"
: prereleaseTag.includes("experimental")
? "experimental"
: prereleaseTag
: "latest";

// Publish all @remix-run/* packages
for (let name of [
Expand Down
13 changes: 8 additions & 5 deletions scripts/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ function getTaggedVersion() {
return output.replace(/^v/g, "");
}

/**
* @param {string} dir
* @param {string} tag
*/
function publish(dir, tag) {
execSync(
`npm publish --access public${tag != null ? ` --tag ${tag}` : ""} ${dir}`,
{ stdio: "inherit" }
);
execSync(`npm publish --access public --tag ${tag} ${dir}`, {
stdio: "inherit",
});
}

async function run() {
Expand All @@ -31,7 +34,7 @@ async function run() {
? prereleaseTag.includes("nightly")
? "nightly"
: prereleaseTag.includes("experimental")
? null
? "experimental"
: prereleaseTag
: "latest";

Expand Down
56 changes: 56 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
MichaelDeBoey marked this conversation as resolved.
Show resolved Hide resolved
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}` : ""
MichaelDeBoey marked this conversation as resolved.
Show resolved Hide resolved
}`,
]
: [importName, path];
})
);

return jsonfile.writeFile(
importMapPath,
{ ...json, imports: newImports },
{ spaces: 2 }
);
};

/**
* @param {string} nextVersion
*/
Expand All @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions templates/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/node_modules/
node_modules

/.cache
/build
/public/build
/public/build
.env
12 changes: 6 additions & 6 deletions templates/deno/.vscode/resolve_npm_imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"// Deno-only dependencies may be imported via URL imports (without using import maps).": "",

"imports": {
"react": "https://esm.sh/[email protected].0",
"react-dom": "https://esm.sh/[email protected]",
"react-dom/server": "https://esm.sh/[email protected]/server",
"@remix-run/dev/server-build": "https://esm.sh/@remix-run/[email protected]/server-build",
"@remix-run/deno": "https://esm.sh/@remix-run/[email protected]",
"@remix-run/react": "https://esm.sh/@remix-run/react@1.4.3"
"@remix-run/deno": "https://esm.sh/@remix-run/[email protected].0",
"@remix-run/dev/server-build": "https://esm.sh/@remix-run/[email protected]/server-build",
"@remix-run/react": "https://esm.sh/@remix-run/[email protected]",
"react": "https://esm.sh/[email protected]",
"react-dom": "https://esm.sh/[email protected]",
"react-dom/server": "https://esm.sh/react[email protected]/server"
}
}
4 changes: 2 additions & 2 deletions templates/deno/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 1 addition & 2 deletions templates/deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions templates/deno/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -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(<RemixBrowser />, document);
hydrate(<RemixBrowser />, document);
6 changes: 3 additions & 3 deletions templates/deno/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions templates/deno/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import type { MetaFunction } from "@remix-run/deno";
import {
Links,
LiveReload,
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion templates/deno/app/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import * as React from "react";

export default function Index() {
return (
Expand Down
6 changes: 3 additions & 3 deletions templates/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
6 changes: 5 additions & 1 deletion templates/deno/remix.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
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.

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/",
};
1 change: 1 addition & 0 deletions templates/vercel/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ node_modules
/build/
/public/build
/api/index.js
/api/index.js.map