Using Packages from GitHub in Deno

May 16, 2020

The easiest way to import a package which is on GitHub into a Deno script is to import that URL:

import { opn } from 'https://raw.githubusercontent.com/hashrock/deno-opn/master/opn.ts'

opn('https://example.com')

However, this has no version control built in. Unless a cached version is used, it will always gets the latest version from that URL. This may not be what you want to do.

A very easy work around is to use https://denopkg.com/

The above is equivalent to:

import { opn } from 'https://denopkg.com/hashrock/deno-opn/opn.ts'

opn('https://example.com')

But you can also add @{BRANCH_OR_TAG} to the end of the URL to use a specific branch or a tagged release.

import { opn } from 'https://denopkg.com/hashrock/deno-opn@master/opn.ts'

opn('https://example.com')

Entry files (mod.ts)

If you use denopkg.com with a base github repo url (such as https://denopkg.com/hashrock/deno-opn) then it will redirect to mod.ts on the master branch.