DEV Community

Discussion on: Write a small API using Deno

Collapse
 
dels07 profile image
Deli Soetiawan • Edited

I'm a bit of mixed that Deno doesn't have some kind of package manager, if you import module from master your code will break so soon... if you import using version number you must replace it in all places when you want to update the dependency.

I remember that golang decided to implement dep & modules due former problem.

I think more and more people with use some kind of workaround like this:
github.com/crookse/deno-drash/blob...
github.com/oakserver/oak/blob/mast...

Collapse
 
mikevb3 profile image
Miguel Villarreal

im yet to test it, but you can make a import map.

deno.land/std/manual.md#import-maps

Collapse
 
kryz profile image
Kryz • Edited

Hello Deli,
thank you for your comment. I understand your doubts. In my examples I import dependencies directly from master for simplicity, but there is a solution for the problem you described:

Step 1. Import a specific version instead of master (don't forget to add "v" before the version number):

import { v4 as uuid } from "https://deno.land/std@v0.22.0/uuid/mod.ts";

Step 2. Put this import and all external dependencies into a separate file and re-export them (change "import" from the code above to "export"):

imports.ts

export { v4 as uuid } from "https://deno.land/std@v0.22.0/uuid/mod.ts";

3. Import from imports.ts and not directly from the internet:

import { uuid } from "../imports.ts";

Advantages:

  • Easy management - all your external dependencies are listed in one file
  • You don't need to update many files when you update the version of your dependency
  • You can simply replace an external implementation, but still use the same module name (because of "as uuid")
Collapse
 
steveblue profile image
Stephen Belovarich • Edited

Easy management from the perspective of the person authoring the code, but how is this easily manageable from the perspective of a monorepo where dependencies need to be updated en masse?

Collapse
 
opensas profile image
opensas

great answer, I think it should be added to the article

Collapse
 
dels07 profile image
Deli Soetiawan • Edited

I already know your method beforehand, but it would be great if there's cli tool to manage deps.ts to keep things standard.

Thread Thread
 
kryz profile image
Kryz

I think a separate tool like npm won't be added because as the deno docs state: "Deno explicitly takes on the role of both runtime and package manager"

Another solution supported by Deno are file maps: [deno.land/std/manual.md#import-maps]