Imported deno thirdparties in production

Viewed 166

Deno does not use any package manager like npm, it only imports the thirdparty dependencies with a URL. Lets see an example below:

import { Application } from "https://deno.land/x/abc@v1.0.0-rc8/mod.ts";

Does the deployed code in production contain the content of https://deno.land/x/abc@v1.0.0-rc8/mod.ts or the server in production has to send a request to the URL to get the thirdparty code?

1 Answers

For production, deno recommends saving your dependencies to git, if you follow that recommendation, then your server won't need to download anything since it will already be cached.

In order to do that you have to set the environment variable DENO_DIR to specify where do you want to download dependencies.

DENO_DIR=$PWD/vendor deno cache server.ts
# DENO_DIR=$PWD/vendor deno run server.ts

With the above command, all dependencies for server.ts will be downloaded into your project, inside vendor/ directory, which you can commit to git.

Then on the production server, you'll have to set DENO_DIR to read from vendor/ and not for the default path, which can be obtained by issuing:

deno info

If you don't store the dependencies on your version control system, then deno will download the dependencies once, and store them into DENO_DIR directory.


Taken from deno manual:

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 pointing $DENO_DIR to some project-local directory at runtime, and similarly checking that into source control:

# Download the dependencies.
DENO_DIR=./deno_dir deno cache src/deps.ts

# Make sure the variable is set for any command which invokes the cache.
DENO_DIR=./deno_dir deno test src

# Check the directory into source control.
git add -u deno_dir
git commit
Related