24

I am new to deno and currently exploring for a minimum viable project in deno. I want to like npm which downloads the npm packages inside the folder node_modules, similarly I want to see the deno packages in a directory. In my current project I do not see any downloaded packages. Please suggest me where to look for deno packages. If I write dep.ts file to mention all the deno packages, can I use the same deno packages for some other projects. My question is bit similar to what Maven or Gradle in java handles. It means I want to know whether deno maintains a single folder in OS so that all the packages are downloaded and used in many projects. I want to check the directory containing the deno packages in windows 10.

Timothy C. Quinn
  • 3,739
  • 1
  • 35
  • 47
Sambit
  • 7,625
  • 7
  • 34
  • 65

2 Answers2

22

The imports are cached in $DENO_DIR

From the docs:

Deno caches remote imports in a special directory specified by the $DENO_DIR environmental variable. It defaults to the system's cache directory if $DENO_DIR is not specified. The next time you run the program, no downloads will be made. If the program hasn't changed, it won't be recompiled either. The default directory is:

  • On Linux/Redox: $XDG_CACHE_HOME/deno or $HOME/.cache/deno
  • On Windows: %LOCALAPPDATA%/deno (%LOCALAPPDATA% = FOLDERID_LocalAppData)
  • On macOS: $HOME/Library/Caches/deno If something fails, it falls back to $HOME/.deno

Relying on external servers is convenient for development but brittle in production. Production software should always bundle its dependencies. In Deno this is done by checking the $DENO_DIR into your source control system, and specifying that path as the $DENO_DIR environmental variable at runtime.

You can see the information by running: deno info


what is the deno command to install all the dependencies mentioned in dep.ts file

To install just import dep.ts in one of your files and run:

deno run index.js
Marcos Casagrande
  • 37,983
  • 8
  • 84
  • 98
  • what is the deno command to install all the dependencies mentioned in dep.ts file ? – Sambit May 14 '20 at 14:17
  • 1
    I am checking constantly, Really Good and Great Answer. Again +1 and Accepted from my side. I may ask more questions, please bear with me. I am generating more interest on deno and it seems to be more promising than NodeJs. – Sambit May 14 '20 at 14:22
  • Thanks! No worries I'll be happy to answer any questions if I know the answer of course :). I don't know if more promising than Node.js, they're both great IMO. – Marcos Casagrande May 14 '20 at 14:26
  • I just mentioned `import * as logger from "https://deno.land/std/log/mod.ts";` in `dep.ts` file. When I tried to import in another class like this 'import {logger} from "./dep.ts";', it is not working, it says `error: TS2305 [ERROR]: Module '"https://deno.land/std/log/mod"' has no exported member 'logger'.` – Sambit May 14 '20 at 14:38
  • 1
    you have to `export` in `deps.ts`, check example: https://deno.land/manual/linking_to_external_code#it-seems-unwieldy-to-import-urls-everywhere – Marcos Casagrande May 14 '20 at 14:40
  • Please don't mind, I asked this question. https://stackoverflow.com/questions/61800486/unable-to-import-dependency-in-deno-dep-ts-file-in-another-class – Sambit May 14 '20 at 14:54
10

You can use deno info to get the cache directory of remote modules.

Sample output (Windows 10):
> deno info
DENO_DIR location: "C:\\Users\\ford\\AppData\\Local\\deno"
Remote modules cache: "C:\\Users\\ford\\AppData\\Local\\deno\\deps"
TypeScript compiler cache: "C:\\Users\\ford\\AppData\\Local\\deno\\gen"
To get info about a single (remote) module:
deno info --unstable https://deno.land/std/fs/mod.ts # --unstable needed as of 1.0.3
Sample output:
local: C:\Users\ford\AppData\Local\deno\deps\https\deno.land\434fe4a7...8f300799a073e0
type: TypeScript
compiled: C:\Users\ford\AppData\Local\deno\gen\https\deno.land\std\fs\mod.ts.js
map: C:\Users\ford\AppData\Local\deno\gen\https\deno.land\std\fs\mod.ts.js.map 
deps:
https://deno.land/std/fs/mod.ts
  ├─┬ https://deno.land/std/fs/empty_dir.ts
  ...

local: Local path of source file (TS or JS)
compiled: Local path of compiled source code (.js, for TS only)
map: Local path of source map (TS only)
deps: Dependency tree of source file

Community
  • 1
  • 1
ford04
  • 66,267
  • 20
  • 199
  • 171
  • Was it introduced in the latest version or from the inception ? – Sambit Jun 02 '20 at 13:28
  • The cache location output for `deno info` has been added in `v1.0.2`, see related [PR](https://github.com/denoland/deno/pull/5703). – ford04 Oct 24 '20 at 12:39