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

sources

v0.1.0

Published

fetches sources from the web

Downloads

203

Readme

sources

sources is a simple command-line tool that can fetch resources from the web and save them to your local file system.

It's a poor man's package manager in that it can download and extract packages for me when creating a new project.

If you prefer a real package manager, please see any of the following:

Those all seem very useful, but I like being in control of exactly what files I add to my projects and I don't like not being able to use a package manager because the project I need doesn't have the magic JSON file in its repository.

With sources, I can define the sources for packages on my machine. I don't have to wait for a project to adopt any conventions and I can select the exact files I need.

Sources are defined in a file called sources.json:

{
    "jquery": "http://code.jquery.com/jquery.js",
    "bootstrap": [
        "jquery",
        "http://twitter.github.com/bootstrap/assets/bootstrap.zip"
    ],
    "qunit": [
        "http://code.jquery.com/qunit/qunit-1.11.0.js",
        "http://code.jquery.com/qunit/qunit-1.11.0.css"
    ]
}

With something like that in my current or home directory I can type:

sources bootstrap

and the latest jQuery and Bootstrap files will be fetched and extracted into the current directory.

Later on, if I decide I need to write some tests, I can type:

sources qunit

to fetch the QUnit files.

That's really all there is to it.

Yes, it kind of resolves dependencies for me, but only if I define those dependencies myself.

Yes, it fetches the latest versions of jQuery and Bootstrap, but only because URLs exist for the latest versions. If a new version of QUnit is released, I won't get that because I don't know of a URL for the latest version of QUnit.

Finding Sources

The sources for packages are defined in files named sources.json.

sources will look in the following locations for sources.json files:

  • the current directory
  • all parent directories of the current directory
  • the home directory
  • the sources script's directory

Locations higher on that list override locations lower on that list.

The contents of sources.json files are a JSON object like this:

{
    "jquery": "http://code.jquery.com/jquery.js",
    "bootstrap": [
        "jquery",
        "http://twitter.github.com/bootstrap/assets/bootstrap.zip"
    ],
    "qunit": [
        "http://code.jquery.com/qunit/qunit-1.11.0.js",
        "http://code.jquery.com/qunit/qunit-1.11.0.css"
    ]
}

The keys in those objects are the names of the packages as I've defined them.

The values can be URLs or arrays of URLs to fetch from.

If a URL references an archive, that archive is extracted into the current directory and then the archive is deleted.

If a URL is the name of another package, that other package is fetched, too.

TODO:

  • write to lib folder?

  • look for sources.json inside lib folders, too?

  • look for lib folder up path?

  • caching?

  • other archive formats?

  • extract specific files from archives? (to exclude minified files, docs, tests, etc)

    "bootstrap": [ "jquery", { "http://twitter.github.com/bootstrap/assets/bootstrap.zip": [ "css/bootstrap.css", "css/bootstrap-responsive.css", "img/*", "js/bootstrap.js" ] } ]

  • rename files?

    "qunit": [ "http://code.jquery.com/qunit/qunit-1.11.0.js => qunit.js", "http://code.jquery.com/qunit/qunit-1.11.0.css => qunit.css" ]