npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

repkg

v0.1.1

Published

replace-package utility

Downloads

3

Readme

                __       
  _______ ___  / /_____ _
 / __/ -_) _ \/  '_/ _ `/
/_/  \__/ .__/_/\_\\_, / 
       /_/        /___/  

repkg

repkg - replace package utility

the problem

I needed to be able to swap configuration files and other files on the fly without having to constantly mess with git branches. The files that needed to be changed were static and could not be easily altered using environment variables.

the solution

repkg is a simple, zero-dependency utility that collects a group of files (called packages) and can load/unload them on the fly. The goal is to make something simple, and light. repkg works by copying files to a hidden .repkg/ folder under a package name. The directory structure of all copied files is preserved. When a package is loaded, its files are symbolically linked to the working directory. repkg doesn't track version changes as git is more than adequate for that.

NOTE: make sure you commit the .repkg directory to version control.

WARNING: not tested on Windows (this uses symlinks, so it'll probably not work).

how it works

Inspired by git, repkg has 4 main functions:

  • add: stages a file in the working directory for adding to/creating a package
  • commit: adds the staged files to a new or existing package
  • load: loads a package by symbolically-linking package files to the working directory
  • unload: unloads a package by unlinking package in the working directory

To use it, first add the files that will make up the package.

repkg add src/config.json src/static.html src/image.png

Then commit the files to create a package (package names must be a valid folder names)

repkg commit a

The added files have been copied to the repkg store (.repkg/a/ in the cwd). It is now safe to modify them to the next variant and repeat the above steps to create another package b. To apply the package a, use the load command:

repkg load a

If you haven't deleted the files in the working directory, you will be prompted to replace them. Once complete, the files will have been replaced with symbolic links to the .repkg/a/ directory.

NOTE: Any changes made to loaded package files will update the files in package.

To remove the symbolically linked package files, use unload:

repkg unload

When you load a package, the previous one is unloaded first to prevent conflicts.

under the hood

repkg is designed to be simple and easy to debug if something goes wrong. The .repkg folder has the following structure:

.repkg/
├── <package>/
│   └── .repkg_index         (JSON) List of all files in the package
│   └── <files>             Files that were added to the package and committed
└── .repkg_state             (JSON) Current state

The .repkg_state file is an object with current (package name), packages (array of package names), and added (array of added files).

While you are welcome to change files directly in the .repkg/ folder, it is preferred to load a package, make changes, and then unload or switch to another package.

faqs

  • why is this not tested?!?!
    • well it works on my machine.
    • No but seriously, it's working for me across multiple environments. If that's not good enough, PRs are always welcome!

alternatives

  • make: if you have experience with it, GNU Make is probably going to be the most powerful and versatile solution
  • .env: if all you need is variable swapping, dot-env or a similar configuration manager is probably your best bet.
  • git: branch and then apply changes. When the upstream branch changes, rebase? Someone smarter can probably show a better way and explain why this utility is useless but oh well I had fun writing it.