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

How to use Ngx-Charts in Angular ?

Charts helps us to visualize large amount of data in an easy to understand and interactive way. This helps businesses to grow more by taking important decisions from the data. For example, e-commerce can have charts or reports for product sales, with various categories like product type, year, etc. In angular, we have various charting libraries to create charts.  Ngx-charts  is one of them. Check out the list of  best angular chart libraries .  In this article, we will see data visualization with ngx-charts and how to use ngx-charts in angular application ? We will see, How to install ngx-charts in angular ? Create a vertical bar chart Create a pie chart, advanced pie chart and pie chart grid Introduction ngx-charts  is an open-source and declarative charting framework for angular2+. It is maintained by  Swimlane . It is using Angular to render and animate the SVG elements with all of its binding and speed goodness and uses d3 for the excellent math functio...

Understand Angular’s forRoot and forChild

  forRoot   /   forChild   is a pattern for singleton services that most of us know from routing. Routing is actually the main use case for it and as it is not commonly used outside of it, I wouldn’t be surprised if most Angular developers haven’t given it a second thought. However, as the official Angular documentation puts it: “Understanding how  forRoot()  works to make sure a service is a singleton will inform your development at a deeper level.” So let’s go. Providers & Injectors Angular comes with a dependency injection (DI) mechanism. When a component depends on a service, you don’t manually create an instance of the service. You  inject  the service and the dependency injection system takes care of providing an instance. import { Component, OnInit } from '@angular/core'; import { TestService } from 'src/app/services/test.service'; @Component({ selector: 'app-test', templateUrl: './test.component.html', styleUrls: ['./test.compon...

How to solve Puppeteer TimeoutError: Navigation timeout of 30000 ms exceeded

During the automation of multiple tasks on my job and personal projects, i decided to move on  Puppeteer  instead of the old school PhantomJS. One of the most usual problems with pages that contain a lot of content, because of the ads, images etc. is the load time, an exception is thrown (specifically the TimeoutError) after a page takes more than 30000ms (30 seconds) to load totally. To solve this problem, you will have 2 options, either to increase this timeout in the configuration or remove it at all. Personally, i prefer to remove the limit as i know that the pages that i work with will end up loading someday. In this article, i'll explain you briefly 2 ways to bypass this limitation. A. Globally on the tab The option that i prefer, as i browse multiple pages in the same tab, is to remove the timeout limit on the tab that i use to browse. For example, to remove the limit you should add: await page . setDefaultNavigationTimeout ( 0 ) ;  COPY SNIPPET The setDefaultNav...