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

cecil

v3.1.0

Published

For running single-file NodeJS scripts with external dependencies

Downloads

14

Readme

cecil

When creating an entire NodeJs module is just too much work

What does it do?

cecil lets you run (and distribute) single-file NodeJS scripts that require external dependencies, without the need for maintaining an entire module and package.json

A REPL is also included, to give you a node-like repl that allows you to include (and automatically install) npm dependencies while in the shell

Quick Start

Write a quick testFile.js script like this:

// This is a simple script just to show that you can use functionality from an npm module.

// In Cecil scripts, there is a global "include" function provided to get npm packages.
// We can optionally provide a second argument to specify the specific version to use.
var _ = include('lodash');

var odd = _.filter([1, 2, 3], function(n) {
  return n % 2 === 1;
});

console.log(odd);

That's it!

Next, install cecil globally

npm install -g cecil

Now just invoke your script!

cecil ./testFile
> [ 1, 3 ]

You can even do some unix magic and make the scripts executable!

First, make sure the script is executable, of course

chmod a+x testFile.js

Next, add the correct shebang to the top of the file:

#! /usr/bin/env cecil
...

And then invoke the script

./testFile.js
> [ 1, 3 ]

REPL

A REPL is provided so you can interactively work with npm dependencies without setting up an entire project:

cecil-repl
> var lodash = include('lodash');
undefined
> lodash.filter([1,2,3], function(x) { return x % 2 == 1; });
[ 1, 3 ]

Why?

I wanted the ability to write small, lightweight, and self-contained scripts
  • Write self-contained gists of node code
  • You can put multiple scripts in the same folder without conflicting dependencies
  • You can distribute single files, instead of scripts with package.json files
  • You can experiment with new npm modules very easily. (Even compare different versions of the same module.)
  • I personally prefer scripting in Node rather than Perl/Bash/etc

How does it work?

  • It parses your code for calls to include(name [, version]); to find your dependencies
    • The name is required
    • The version is optional. It must be any valid NPM semver version. If latest, then NPM will be queried every time to get the latest version number.
  • It will use npm to install these modules into the .cecil directory in your home directory
  • It even supports concurrently loading different versions of the same module! (I have no idea why you'd want to do that but it was easy to implement.)
  • You still use require() for core modules, like path or fs

Caveats

  • Both name and version must be LITERAL values. IE: they must both be strings. (Of course, version is optional.)
    • (Dependency resolution is done before anything is run. Dynamic loading of modules would require everything to be async, and I didn't feel that was worth it.)
  • In the REPL, there is currently no support for multi-line commands. Need to figure out how best to handle that.
  • You can't require() other cecil scripts. Right now the best you can do is to use process.argv[0] (which is the cecil executable) to spawn a new process calling the other script. I plan to add support for include('./foo.js') in a future version of cecil.