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

docs: update deno_std and import map docs #459

Merged
merged 2 commits into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions runtime/manual/basics/import_maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,30 @@ written something similar in our `deno.json` configuration file:
}
```

## Example - Using deno_std's fmt module via `fmt/`
## Example - Using the Deno Standard Library

Running the following:

```bash
deno add @std/foo
```

Produces the following:

```json title="deno.json"
{
"imports": {
"fmt/": "https://deno.land/std@$STD_VERSION/fmt/"
"@std/foo": "jsr:@std/foo@^1.2.3"
}
}
```

```ts title="color.ts"
import { red } from "fmt/colors.ts";
The import can then be used in your script:

```ts title="bar.ts"
import { bar } from "@std/foo";

console.log(red("hello world"));
bar(1, 2);
```

## Example - Using project root for absolute imports
Expand Down Expand Up @@ -79,19 +89,20 @@ import map's URL or file path.
The other situation where import maps can be very useful is to override imports
in specific modules.

Let's say you want to override the deno_std import from 0.177.0 to the latest in
all of your imported modules, but for the `https://deno.land/x/example/` module
you want to use files in a local `patched` directory. You can do this by using a
scope in the import map that looks something like this:
Let's say you want to override a Deno Standard Library package import from
^1.2.3 to the latest in all of your imported modules, but for the
`https://deno.land/x/example/` module you want to use files in a local `patched`
directory. You can do this by using a scope in the import map that looks
something like this:

```json
{
"imports": {
"https://deno.land/[email protected]/": "https://deno.land/std@$STD_VERSION/"
"@std/foo": "jsr:@std/foo@^1.2.3"
},
"scopes": {
"https://deno.land/x/example/": {
"https://deno.land/[email protected]/": "./patched/"
"@std/foo": "./patched/mod.ts"
}
}
}
Expand Down
Loading