Skip to main content

GuPM to manage your Node/JS project

Introduction to GuPM

GuPM is a package manager written with the goal to unify the package management scene. Unifying doesn’t mean centralising: the point of GuPM is also ensuring a community-driven development scene by working with decentralised repositories, and a powerful scripting/plugin system for customising the behaviours of the tools.
This guide assumes you are familiar with NPM or equivalent (gem, yarn, maven, etc…).
In order to follow this article, you will need to have both GuPM and the NPM provider installed in your machine.
# Install GUPM
curl -fsSL https://azukaar.github.io/GuPM/install.sh | bash# Install the NPM Provider
g plugin install https://azukaar.github.io/GuPM-official/repo:provider-npm

What can it do

  • Dependency management (npm make / npm install) using more than one source (for exemple, instead of using NVM, simply set node to be a dependency of your project)

Getting started

Let’s start a cli in your project and type:
g b -p npm
# short-hand for g bootstrap --provider npm
It will ask you if you want to use gupm.json or package.json. If your project already exists, GuPM has the ability to import it into a gupm.json (see next paragraph for the benefit of the gupm.json). If you plan on publishing a lib to NPM for people to install it with NPM, then you will have no choice than skipping the import, and keep using the same package.json (Don’t worry, GuPM can also use the package.json!). If you choose that second path, GuPM will still create a gupm.json in your project allowing you to benefit from GuPM’s features.
Once done, GuPM will have generated a Readme containing basic instructions.
g make # Install your project's dependenciesg i webpack # shorthand for g install webpack
You might wonder: Tell me, if GuPM is a generic package manager, how does it know to install those dependencies from NPM? Let’s dive a bit deeper in the project to find out what it the scaffolding does!

Understanding GuPM

So what did we generate here? Most importantly, we generated a gupm.json .
{
    "author": "",
    "description": "",
    "licence": "ISC",
    "name": "test",
    "binaries": {},
    "cli": {
        "aliases": {}
    },
    "dependencies": {
        "default": {},
        "defaultProvider": "npm"
    },
    "publish": {
        "destination": "docs/repo",
        "source": []
    }
}
If you generated the project to use your package.json, you should see this instead :
{
    "author": "",
    "cli": {
        "defaultProviders": {
            "install": "npm",
            "make": "npm"
        }
    },
    "licence": "ISC",
    "name": "test"
}
If you are familiar with the package.json, there’s already a few things here that should be able to pick up. First of all, name/author/description/license are pretty self explainatory.
the cli option allow you to customise how different cli commands will work inside your project. We can for example set aliases (think of it as ‘scripts’ in your package.json).
"cli": {
  "aliases": {
    "start": "node index.js"
  }
},
You can also here tell GuPM to use specific providers when using specific commands using the defaultProvider. That’s how we get GuPM to use npm for make and install.
In the first example, you can notice that we haven’t set a defaultProvider in the cli options, but yet, we can still install webpack directly. That’s because in the dependencies we have another option to set a defaultProvider. The difference with that one, is that this is set to be the default provider at resolution stage. To understand better, let’s imagine we have set no config:
# First, let's try to install webpack 
# this will not use NPM 
# because no defaultProvider is set in gupm.jsong i webpack# We can tell GuPM to use NPM to INSTALL a dependency
# If you do this, NPM will take over the whole install process
# Meaning it will save the dependency to package.json
# This is what happens when you set cli.defaultProvidersg -p npm i webpack# A better way to do this, is to still use GuPM's default INSTALL
# But tell it to resolve the dependency from NPM
# Here, only the RESOLVE stage gets overwritten by NPM
# This is what happens when you set dependencies.defaultProviderg i npm://webpack
Next up, we have publish, which is easy to understand, if you decide to publish to a decentralised repo, it contains the source files and the destination of the repo to publish to.
The binaries is the strict equivalant to bin in a package.json.
One last file we need to look at, is make.gs . If you decided to keep a package.json, it will be generated alongside your gupm.json. This file is automatically executed by GuPM afteryou executed g make (you can also create install.gs, etc…). What it does, is tell GuPM “Once you are done installing GuPM’s dependencies, install the NPM ones”.
exec('g', ['make', '-p', 'npm']);

Conclusion

GuPM has been built with seamlessness in mind, for maximum flexibility and customisation around your projects. This article gave you a quick overview of how you can easily use it with NPM, but of course, feel free to check our github (and ⭐ it!) for the rest of the documentation on how to make you a GuPM ninja!

Comments

Popular posts from this blog

4 Ways to Communicate Across Browser Tabs in Realtime

1. Local Storage Events You might have already used LocalStorage, which is accessible across Tabs within the same application origin. But do you know that it also supports events? You can use this feature to communicate across Browser Tabs, where other Tabs will receive the event once the storage is updated. For example, let’s say in one Tab, we execute the following JavaScript code. window.localStorage.setItem("loggedIn", "true"); The other Tabs which listen to the event will receive it, as shown below. window.addEventListener('storage', (event) => { if (event.storageArea != localStorage) return; if (event.key === 'loggedIn') { // Do something with event.newValue } }); 2. Broadcast Channel API The Broadcast Channel API allows communication between Tabs, Windows, Frames, Iframes, and  Web Workers . One Tab can create and post to a channel as follows. const channel = new BroadcastChannel('app-data'); channel.postMessage(data); And oth...

Certbot SSL configuration in ubuntu

  Introduction Let’s Encrypt is a Certificate Authority (CA) that provides an easy way to obtain and install free  TLS/SSL certificates , thereby enabling encrypted HTTPS on web servers. It simplifies the process by providing a software client, Certbot, that attempts to automate most (if not all) of the required steps. Currently, the entire process of obtaining and installing a certificate is fully automated on both Apache and Nginx. In this tutorial, you will use Certbot to obtain a free SSL certificate for Apache on Ubuntu 18.04 and set up your certificate to renew automatically. This tutorial will use a separate Apache virtual host file instead of the default configuration file.  We recommend  creating new Apache virtual host files for each domain because it helps to avoid common mistakes and maintains the default files as a fallback configuration. Prerequisites To follow this tutorial, you will need: One Ubuntu 18.04 server set up by following this  initial ...

Working with Node.js streams

  Introduction Streams are one of the major features that most Node.js applications rely on, especially when handling HTTP requests, reading/writing files, and making socket communications. Streams are very predictable since we can always expect data, error, and end events when using streams. This article will teach Node developers how to use streams to efficiently handle large amounts of data. This is a typical real-world challenge faced by Node developers when they have to deal with a large data source, and it may not be feasible to process this data all at once. This article will cover the following topics: Types of streams When to adopt Node.js streams Batching Composing streams in Node.js Transforming data with transform streams Piping streams Error handling Node.js streams Types of streams The following are four main types of streams in Node.js: Readable streams: The readable stream is responsible for reading data from a source file Writable streams: The writable stream is re...