DEV Community

loading...

Discussion on: Write a small API using Deno

Collapse
kryz profile image
Kryz Author • 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
Steve 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 Author

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]