Skip to content

Commit

Permalink
chore: update Deno import maps on release (#3225)
Browse files Browse the repository at this point in the history
* fix(templates/vercel): add `index.js.map` to `.gitignore` (#3216)

* Add `index.js.map` to `.gitignore`

In the Vercel template,  `/api/index.js.map` should also be ignored along with `/api/index.js`. Otherwise, that mapping file would be committed into version control, which is not desired.

* Sign CLA

* fix(scripts): Prevent publishing without a tag (#3223)

* move decisions

* docs: add `decisions/index.md` and frontmatter (#3226)

Co-authored-by: Pedro Cattori <[email protected]>
(cherry picked from commit e809206)

* docs(server-runtime): update link for deno server runtime package (#3228)

since it's now a proper package

* chore(templates): bring `deno` template in line with other templates (#3221)

* docs: fix links to decision docs (#3231)

* chore: update Deno import maps on release

Co-authored-by: Jiahao <[email protected]>
Co-authored-by: Chance Strickland <[email protected]>
Co-authored-by: Ryan Florence <[email protected]>
Co-authored-by: Logan McAnsh <[email protected]>
Co-authored-by: Pedro Cattori <[email protected]>
  • Loading branch information
6 people authored May 19, 2022
1 parent 8becc4a commit c28e179
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 29 deletions.
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
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
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) => {
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
*/
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

0 comments on commit c28e179

Please sign in to comment.