Deno: Idiomatic way of managing project's version ?

Created on 29 May 2020  路  5Comments  路  Source: denoland/deno

Say that I am the author of an open source project and I want to keep track of the release version for my project. For node, we have a package.json which keeps track the current version of the project. What is the idiomatic way of managing project version in a Deno project ?

I've seen some third party project version managing tool like

In other words, what is the equivalent of package.json's version for Deno ?

Most helpful comment

AFAIK there is no equivalent. Instead you use Git tags for version and then put the tag / branch in the URL from which your module is imported. IMO keeping versioning to Git is much more natural than having to increment a number in an arbitrary file.

Btw. The URLs provided by deno.land/x/ already offer this, e.g.

https://deno.land/x/[email protected]/mod.ts

All 5 comments

AFAIK there is no equivalent. Instead you use Git tags for version and then put the tag / branch in the URL from which your module is imported. IMO keeping versioning to Git is much more natural than having to increment a number in an arbitrary file.

Btw. The URLs provided by deno.land/x/ already offer this, e.g.

https://deno.land/x/[email protected]/mod.ts

The idiomatic way is a git tag. While deno.land/x/ supports only commitish references, supporting something like semver resolution to a git tag.

Interesting. I am already using git tag for semver but the problem comes in when I need to reference the version in my source code. For instance prepending the module's version in the User-Agent string.

const headers = new Headers();
headers.append('User-Agent', `onewaysms-sdk-deno/${CURRENT_VERSION}`); // how do I reference the project version here? 
... 

For node we can do something like

import { version } from '/package.json';

Hard coding the version in the string doesn't feel right. Or is creating a variable VERSION and update it everytime the project version is updated is the correct way?

Hard coding the version in the string doesn't feel right.

From a technical perspective, I don't see a difference between hard-coding the version number in a file called package.json compared to hard-coding it in a file called mod.ts (or whatever name you choose). At the end of the day, it's a version number in a file.

If you already tag your version using git and you don't want to sync it, you could run git describe (or similar git commands, or even read the files in your .git directory) to retrieve your last tag - but that's far more complicated than hard-coding, plus it breaks when the code is being used in another project.

So a third option would be to have a build script that retrieves the last tag from git and replaces your const VERSION = "..."; variable so they are always in sync. But again, that's automation effort that may not be necessary.

I see, thanks for the advises. Will create a mod.json file to store the version number there and will update it every time new version is released.

Closing this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

benjamingr picture benjamingr  路  3Comments

xueqingxiao picture xueqingxiao  路  3Comments

kyeotic picture kyeotic  路  3Comments

ry picture ry  路  3Comments

JosephAkayesi picture JosephAkayesi  路  3Comments