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.json g 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.defaultProviders g -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.defaultProvider g 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 after you 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!

Don’t hesitate to also visit me on Twitter:

Thanks for reading!