Search code examples
versioningdeno

How to keep the version of packages in Deno


I don't quite understand how I can keep the version of packages in a Deno project.

I saw that it loads packages via urls directly without using package.json that I had in Nodejs project.

That's cool but how do I keep the versions of some libraries that I used in the project? My concern is if a library has updated some of its functions and then my server will be broken.

Actually I believe I must miss something that is very common.

Could anyone give me a hint on this question?


Solution

  • Use versioned imports from deno.land to make sure to always get the version with which you have developed your software. Deno.land caches releases and allow to import by version number.

    Instead of writing:

    import { validateJwt } from "https://deno.land/x/djwt/validate.ts";
    

    which would always import the current version of the package, you can add the version number as @<version> behind the package name to explicitely import that version (here version 1.7):

    import { validateJwt } from "https://deno.land/x/djwt@v1.7/validate.ts";
    

    To check for updates there's a third party module deno-check-updates that works with import maps. But please be aware that import maps is still marked as an unstable feature and deno-check-updates is also only on v0.3 yet and currently doesn't work due to changes on deno side.

    Just tried deno run -A --unstable https://deno.land/x/deno_check_updates/main.ts -f import_map.json and got an error.

    I'll check and update this answer as soon as I know more.