Skip to content

Immutable NPM - Hack as part of the New York Blockchain Week Hackathon

Notifications You must be signed in to change notification settings

wildcards-world/immutable-npm

Repository files navigation

inpm cli tool

A cli tool for managing immutable node packages using arweave (backwards compatibale with npm)

Under active development as part of the New York Blockchain Week Hackathon

Table of Contents

How it works

Problem

Npm packages are mutable which means they can be changed and thus break existing software.

Software can be explained like a lego castle, each piece of lego is put together to build the castle much like pieces of code ,or packages, can be put together to build a software application.

If we remove a block of lego from the base of the castle we jeopardize the structural integrity of the castle and it may break and fall.

The same occurs with software, if we change or remove a package from the software application it may break or stop running.

This article unpacks an example of how this small problem can break most of modern day JavaScript.

Solution

Insert Immutable Node Package Manager 🤯

A dead simple npm wrapper that installs the package from arweave an immutable data storage solution leveraging blockchain technology. This tool understands the market adoption of the public npm registry and so is not a replacement but acts as an improvement where by it downloads the package from arweave first and if the package is not found in arweave it falls back to a regular npm request.

The developer ux is focussed around being an improvement that doesn't require any switching costs (apart from the getting started part). The developer can use similar (and all the same) commands to npm but rather using inpm. npm being a tool most developers are already familiar with, while incrementally improving their code base through immutability.

Example usage inpm install arql-ops

Under the hood

The cli tool is built using react - ink as the cli, arweave as the immutable package storage registry, orbitDB as the decentralized key value storage (mapping packages to arweave endpoints), and where a command is not know falls back to npm.

Getting started

*RED FLAG - wallet is in the repo to ensure doesnt break on submission with a minute to go - not ideal but wont keep wallet after this

  1. Assumes nodejs & npm is already installed

  2. Clone the repo ⤴️

  3. Build the program

npm run babel
  1. Make the package executable (babel generated file executable)
chmod +x ./bin/cli.js
  1. Add the package to your system (equivalent to npm i -g ...)
npm link
  1. Test by installing some package
  • Mutable
inpm install leftpad
  • Immutable
inpm install arql-ops

** Side note: Adding --no-warnings to line 1 of cli improves the output experience although causes to break on some systems

Usage

inpm --help
inpm install leftpad

inpm install - Currently requires ctrl + c once warnings appear (still succeeded)

inpm install arql-ops
inpm login
inpm zip package-name.tar.gz path-to-package-folder       (note: not packages larger than 10mb)
inpm publish package-name path-to-tar.gz-package
inpm {any other normal npm command}
inpm --version

Demo of login and publish

Further work

  • Refactor into ReasonML (Functional typed language I would like to get more familiar with) - binding

  • Expand on npm functionality

  • Add functionality for installing package versions eg inpm i [email protected]

  • Autocomplete commands (speed improvement)

  • Allow configurable underlying package manager so that users can switch between yarn and npm as the underlying tool

  • Change the name to something that is equally simple and doesn't conflict with inpm. Part of me wishes I could contact the developer of inpm (npm registry version) and ask to take the name but that would truly go against exactly the problem this package solves 😂

  • Have a script that maps npm registry packages onto arweave

Resources used to build this tool

creating a node js cli tool

Another tut on creating a nodejs cli tool

React for command line lib

Arweave JS Docs

Arweave Block Explorer

Publishing a package to npm

TOC tool

Console to svg tool

Debugging helper commands

tar -zcvf my-package.tar.gz my-package

npm unlink --no-save inpm

npm unlink

About

Immutable NPM - Hack as part of the New York Blockchain Week Hackathon

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages