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

a-kind-of-magic

v0.5.1

Published

Automatic dependency resolution for Javascript

Downloads

45

Readme

A Kind of Magic

Build Status Automatic dependency resolution for Javascript. Also akom for short.

IMPORTANT NOTE: I practice Readme Driven Development -- this project is not yet completed!

Currently, the resolver isn't hooked up to the public API, and the only provide/require gathering implemented is the hardcoded stuff described at the bottom of this readme. Docs are also a little lacking, I'm sure you'll agree.

What it do

This scans all the Javascript files in a directory, and outputs information about what depends on what, along with a suggested inclusion order. It's both a library and a command-line tool.

Why it do

You're not a compiler.

Assuming you're the average Javascript programmer like me, you follow a sane pattern for assigning to globals and the like -- a pattern that can be recognized and used by a compiler to do your dependency management for you.

How it do

Javascript files are parsed, and global assignments/accesses are recorded. For example, if a file does

window.bar = window.foo + 123;

Then the file is known to require foo and provide bar. Pretty simple example, but akom goes further: it understands scope, immediately-invoked functions, and all that jazz.

Installation

npm install a-kind-of-magic

Usage

You've got two ways to use akom: via command line, or as a library. The library approach is way more powerful.

Command Line

This isn't even implemented yet...

Library

A quick sample:

var akom = require('a-kind-of-magic');
akom.scan('some/path', function(err, files) {

});

Avoiding Problems

Provided you always access globals by their fully-namespaced identifiers, you're good.

Good:

my.oh.so.deeply.nested.module.doSomething();

Bad:

var saveTime = my.oh.so.deeply.nested.module.
saveTime.doSomething();

Something worth noting as well: conditional blocks (and, well, anything that may or may not execute) are considered to always pass. So if you assign to something in an if statement, we're going to assume it always passes. Same with switch statements, while loops, etc.

Fixing Problems

Alas, sometimes you just have to do something obscene that's gonna confuse the analyzer. So, to work around this problem you can explicitly declare exports/requirements by putting them in string expressions at the root of a file. Like so:

'akom require: foo bar baz.bam';
'akom provide: shoo foo.zap';
'akom no-provide: zing';
'akom no-require: zam';

The first two statements explicitly add exports/requirements. The last two statements can be used to correct akom when it doesn't get things right.

Skipping Files

If you want to skip a file from being processed include the following at the root of the file:

'akom pass'

Note that other AKOM directives like 'akom require: foo bar' will still be processed and used for resolving dependencies. Using 'akom pass' just turns off the automagic checking.