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

@lacrypta/liskov-semver

v0.6.0

Published

A SemVer checker using Liskov's Substitution Principle

Downloads

3

Readme

Liskov SemVer

A SemVer checker using Liskov's Substitution Principle.

TL;DR

Simply run npx @lacrypta/liskov-semver on a TypeScript project to get the smallest SemVer you'll need to use during publishing.

How does it work?

This script will first clone two different versions of your package: the latest tag with a SemVer-like name, and the current branch. Once cloned, it will install their dependencies, build them, pack them, and install them both side-by-side (under different names) on a scratch directory.

In said scratch directory, a new package is created, that declares both of these as dependencies. They will be installed, and two TypeScript files will be created therein:

// newToOld.ts
import * as oldVersion from "./oldVersion";
import * as newVersion from "./newVersion";

((_: typeof oldVersion): void => {})(newVersion);

and

// oldToNew.ts
import * as oldVersion from "./oldVersion";
import * as newVersion from "./newVersion";

((_: typeof newVersion): void => {})(oldVersion);

Of course, the actual TypeScript files used will be somewhat more involved (in order to deal with multiple entry points, for example), but these will do by way of example.

Although somewhat strange, what these files do is effective check whether the "new" version's API is Liskov-compatible with the "old" one, and vice-versa.

We then simply call tsc in order to type-check each of these files. This may yield different results, according to the table below:

| tsc newToOld.ts | tsc oldToNew.ts | Result | Bump | | :---------------: | :---------------: | :------------------------------------ | :---: | | OK | OK | Versions are mutually compatible | patch | | OK | FAIL | New version is backwards-compatible | minor | | FAIL | -- | New version is backwards-incompatible | major |

Based off of the value of version in the package.json file for the "old" version, this script will bump the appropriate version segment, and print it on stdout, provided this is larger than the value of version in the package.json file for the "new" version.

Major Version Handling

This tool will never update the major version when it is 0, updating the minor version instead. The rationale behind this is that 0 major versions indicate unstable development, and as such, it should be manually bumped to the first production version.

Usage

Call npx @lacrypta/liskov-semver --help for usage info:

$ npx @lacrypta/liskov-semver --help
Options:
      --version               Show version number                         [boolean]
  -h, -?, --help              Show help                                   [boolean]
      --error-on-dirty        show error if the working directory is not clean
                                                          [boolean] [default: true]

Boolean options have "opposites" starting with a "--no-" prefix, eg.
"--no-error-on-dirty".

Copyright (C) 2024  La Crypta
Released under the AGPLv3+ License <https://www.gnu.org/licenses/agpl-3.0.html>

Testing

You may run tests like so:

$ tests/test
Testing "Initial commit" ... passed!
Testing "Make an inconsequential change" ... passed!
Testing "Make a minor change" ... passed!
Testing "Make a major change" ... passed!
Testing "Make yet another inconsequential change" ... passed!
Testing "Make yet another minor change" ... passed!
Testing "Make yet another major change" ... passed!
All tests passed! :D

What can you use it for?

Running this script prior to publishing will ensure the package is published with a semantically-correct SemVer number (at least as far as the TypeScript public API goes).

One way of doing this is:

// package.json
{
  ...,
  "scripts": {
    ...,
    "prepublishOnly": "npm pkg set version=$(npx @lacrypta/liskov-semver)",
    ...
  },
  ...
}

This will ensure the package.json's version field is updated prior to publishing.

Is this enough for my versioning needs?

No.

This tool will deal with "structural" changes in your public API, it has no way of detecting "semantic" changes introduced without modifying the API's structure.

There are, of course, techniques and practices that can alleviate this problem, and most of them consist of turning "semantic" changes into "structural" changes (ie. interface tagging, entry points versioning, etc.), and if you're using one of these, this tool will pick up on those changes just as well.