Skip to content

Commit

Permalink
updating docs for JSR module management, and general module usage wit…
Browse files Browse the repository at this point in the history
…h deno
  • Loading branch information
thisisjofrank committed Jul 11, 2024
1 parent 514dd41 commit 7fda994
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 251 deletions.
6 changes: 2 additions & 4 deletions runtime/_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ export const sidebar = [
label: "Using & Publishing Modules",
items: [
"/runtime/manual/basics/modules/",
"/runtime/manual/basics/modules/remote_modules/",
"/runtime/manual/basics/modules/publishing_modules/",
"/runtime/manual/basics/modules/reloading_modules/",
"/runtime/manual/basics/modules/proxies/",
"/runtime/manual/basics/modules/integrity_checking/",
"/runtime/manual/advanced/publishing/",
"/runtime/manual/advanced/publishing/dnt/",
"/runtime/manual/advanced/private_repositories/",
],
},
Expand Down Expand Up @@ -299,7 +298,6 @@ export const sidebar = [
label: "Basic Examples",
items: [
"/runtime/tutorials/hello_world/",
"/runtime/tutorials/manage_dependencies/",
"/runtime/tutorials/fetch_data/",
"/runtime/tutorials/read_write_files/",
"/runtime/tutorials/hashbang/",
Expand Down
14 changes: 0 additions & 14 deletions runtime/manual/advanced/publishing/dnt.md

This file was deleted.

76 changes: 0 additions & 76 deletions runtime/manual/advanced/publishing/index.md

This file was deleted.

84 changes: 0 additions & 84 deletions runtime/manual/basics/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ title: "ECMAScript Modules in Deno"
- [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)
allows you to include and use modules held elsewhere, on your local file
system or remotely.
- Imports are URLs or file system paths.
- [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export)
allows you to specify which parts of your module are accessible to users who
import your module.
Expand Down Expand Up @@ -48,29 +47,6 @@ console.log(totalCost(19, 31, 1.2)); // 60
console.log(totalCost(45, 27, 1.15)); // 82.8
```

## Remote Import

In the local import example above an `add` and `multiply` method are imported
from a locally stored arithmetic module. The same functionality can be created
by importing `add` and `multiply` methods from a remote module too.

In this case the Ramda module is referenced, including the version number. Also
note a JavaScript module is imported directly into a TypeScript module, Deno has
no problem handling this.

**Command:** `deno run ./remote.ts`

```ts
import { add, multiply } from "https://deno.land/x/[email protected]/mod.ts";

function totalCost(outbound: number, inbound: number, tax: number): number {
return multiply(add(outbound, inbound), tax);
}

console.log(totalCost(19, 31, 1.2)); // 60
console.log(totalCost(45, 27, 1.15)); // 82.8
```

## Export

In the local import example above the `add` and `multiply` functions are
Expand All @@ -94,63 +70,3 @@ All functions, classes, constants and variables which need to be accessible
inside external modules must be exported. Either by prepending them with the
`export` keyword or including them in an export statement at the bottom of the
file.

## FAQ

### How do I import a specific version of a module?

Specify the version in the URL. For example, this URL fully specifies the code
being run: `https://unpkg.com/[email protected]/dist/liltest.js`.

### It seems unwieldy to import URLs everywhere.

> What if one of the URLs links to a subtly different version of a library?
> Isn't it error prone to maintain URLs everywhere in a large project?
The solution is to import and re-export your external libraries in a central
`deps.ts` file (which serves the same purpose as Node's `package.json` file).
For example, let's say you were using the above assertion library across a large
project. Rather than importing `"https://deno.land/std/assert/mod.ts"`
everywhere, you could create a `deps.ts` file that exports the third-party code:

**deps.ts**

```ts
export {
assert,
assertEquals,
assertStringIncludes,
} from "https://deno.land/[email protected]/assert/mod.ts";
```

And throughout the same project, you can import from the `deps.ts` and avoid
having many references to the same URL:

```ts
import { assertEquals, runTests, test } from "./deps.ts";
```

This design circumvents a plethora of complexity spawned by package management
software, centralized code repositories, and superfluous file formats.

### How can I trust a URL that may change?

By using a lock file (with the `--lock` command line flag), you can ensure that
the code pulled from a URL is the same as it was during initial development. You
can learn more about this [here](./integrity_checking.md).

### But what if the host of the URL goes down? The source won't be available.

This, like the above, is a problem faced by _any_ remote dependency system.
Relying on external servers is convenient for development but brittle in
production. Production software should always vendor its dependencies. In Node
this is done by checking `node_modules` into source control. In Deno this is
done by adding a [vendor field](/vendoring) to your `deno.json` file:

```bash
{
"vendor": true
}
```

before running your project.
73 changes: 0 additions & 73 deletions runtime/tutorials/manage_dependencies.md

This file was deleted.

0 comments on commit 7fda994

Please sign in to comment.