Skip to content

Commit

Permalink
update the migrate page and the cheatsheet for deno future (#687)
Browse files Browse the repository at this point in the history
Co-authored-by: Marvin Hagemeister <[email protected]>
Co-authored-by: Josh Collinsworth <[email protected]>
  • Loading branch information
3 people authored Aug 8, 2024
1 parent 83889e5 commit 50100d6
Show file tree
Hide file tree
Showing 13 changed files with 480 additions and 482 deletions.
12 changes: 5 additions & 7 deletions runtime/_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const sidebar = [
"/runtime/manual/basics/env_variables/",
"/runtime/manual/basics/debugging_your_code/",
"/runtime/manual/basics/connecting_to_databases/",
"/runtime/manual/node/",
"/runtime/manual/basics/react/",
"/runtime/manual/getting_started/installation/",
],
Expand All @@ -40,6 +39,7 @@ export const sidebar = [
"/runtime/manual/basics/modules/reloading_modules/",
"/runtime/manual/basics/modules/integrity_checking/",
"/runtime/manual/advanced/private_repositories/",
"/runtime/manual/advanced/http_imports/",
],
},
{
Expand All @@ -66,14 +66,11 @@ export const sidebar = [
{
label: "Interop with Node & npm",
items: [
"/runtime/manual/node/npm_specifiers/",
"/runtime/manual/node/node_specifiers/",
"/runtime/manual/node/package_json/",
"/runtime/manual/node/cdns/",
"/runtime/manual/node/faqs/",
"/runtime/manual/node/",
"/runtime/manual/node/migrate/",
"/runtime/manual/node/npm_specifiers/",
"/runtime/manual/node/private_registries/",
"/runtime/manual/references/cheatsheet/",
"/runtime/manual/node/cheatsheet/",
{
label: "Supported Node APIs and globals",
id: "/runtime/manual/node/compatibility/",
Expand All @@ -90,6 +87,7 @@ export const sidebar = [
"/runtime/manual/advanced/jsx_dom/jsdom/",
"/runtime/manual/advanced/jsx_dom/deno_dom/",
"/runtime/manual/advanced/jsx_dom/linkedom/",
"/runtime/manual/advanced/faqs/",
],
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
title: "Frequently Asked Questions"
oldUrl:
- /runtime/manual/node/faqs
---

## Getting type errors like cannot find `document` or `HTMLElement`
Expand Down
38 changes: 38 additions & 0 deletions runtime/manual/advanced/http_imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "Importing modules from HTTP URLs"
oldUrl:
- runtime/manual/node/cdns.md
---

Deno supports importing modules from HTTP URLs. This is useful for importing
modules from a CDN or from a server that serves JavaScript modules. Note that
npm packages can be directly imported via the
[`npm:` specifier](../../manual/node/npm_specifiers).

```typescript
import { render } from "https://esm.sh/preact";
```

You can also import modules from a URL by adding it to your `deno.json` import
map:

```json
{
"imports": {
"preact": "https://esm.sh/preact"
}
}
```

Supporting URL imports enables us to support the following JavaScript CDNs, as
they provide URL access to JavaScript modules:

- [esm.sh](https://esm.sh/) (recommended)
- [jspm.io](https://jspm.io/)

URL imports should be used with caution, as they can introduce security risks.
When importing modules from a URL, you are trusting the server to serve the
correct code. If the server is compromised, it could serve malicious code to
your application. For this reason, it is recommended to use URL imports only
from trusted sources. They can also cause versioning issues if you import
different versions in different files.
Binary file added runtime/manual/images/quick-fix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 0 additions & 91 deletions runtime/manual/node/cdns.md

This file was deleted.

58 changes: 58 additions & 0 deletions runtime/manual/node/cheatsheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "Node → Deno cheatsheet"
oldUrl:
- /runtime/manual/references/cheatsheet/
---

| Node.js | Deno |
| -------------------------------------- | ----------------------------- |
| `node file.js` | `deno run file.js` |
| `ts-node file.ts` | `deno run file.ts` |
| `nodemon` | `deno run --watch` |
| `node -e` | `deno eval` |
| `npm i` / `npm install` | `deno install` |
| `npm install -g` | `deno install -g` |
| `npm run` | `deno task` |
| `eslint` | `deno lint` |
| `prettier` | `deno fmt` |
| `package.json` | `deno.json` or `package.json` |
| `tsc` | `deno check` ¹ |
| `typedoc` | `deno doc` |
| `jest` / `ava` / `mocha` / `tap` / etc | `deno test` |
| `nexe` / `pkg` | `deno compile` |
| `npm explain` | `deno info` |
| `nvm` / `n` / `fnm` | `deno upgrade` |
| `tsserver` | `deno lsp` |
| `nyc` / `c8` / `istanbul` | `deno coverage` |
| benchmarks | `deno bench` |

¹ Type checking happens automatically, TypeScript compiler is built into the
`deno` binary.

## Built-in Node.js globals

Deno provides a similar set of built-in globals as Node.js, but with some
differences. Here are some common ones:

| Node.js | Deno |
| ---------------------------- | ------------------------------- |
| `process.cwd()` | `Deno.cwd()` |
| `process.env.MY_ENV` | `Deno.env.get("MY_ENV")` |
| `process.env.MY_ENV = "foo"` | `Deno.env.set("MY_ENV", "foo")` |
| `process.platform` | `Deno.build.os` |
| `process.arch` | `Deno.build.arch` |
| `process.execPath()` | `Deno.execPath()` |
| `process.exist(code)` | `Deno.exit(code)` |

It is also possible to import Node.js modules into your project using the
`node:` specifier. For example:

```js
import process from "node:process";
```

### APIs

| Node.js | Deno |
| ---------------------------------------- | ----------------------------- |
| `fsPromises.readFile(filePath, "utf-8")` | `Deno.readTextFile(filePath)` |
Loading

0 comments on commit 50100d6

Please sign in to comment.