Skip to content

0.2.0: The npm Update

Choose a tag to compare

@Cykelero Cykelero released this 19 Aug 16:09

So. You're busy writing a small, handy script, when you realize you could really use a juicy npm package right now. But you can't indulge and create a package.json file—there are other scripts in this folder! What do you do?

Well, you just type in const randomPun = npm.devpun.random(), of course. What was that about a package file?

Using an npm package in Tasklemon is absurdly easy: every single npm package is available on the npm global you'll find already injected in your Tasklemon script. So all you have to do is something like this:

const friendNames = await cli.ask('What are your friends called?', Array);
const uniqueFriendNames = npm.dedupe(friendNames); // let's use the “dedupe” package

cli.tell('Total count of unique friend names: ' + uniqueFriendNames.length);

And voilà: run your script, and it all just works. No declaring, no importing, and certainly no installing. Tasklemon proactively discovers what packages you need, and installs them in the background when your script runs. Everything is neatly cached, so that subsequent runs can invoke the packages instantly.

In addition to being almost magical, npm support is also very resilient, and knows of a lot of back-up plans for when things go askew—which means it basically always succeeds. And if you do want more control, Tasklemon exposes a few commands to manage the package cache and to remind it of who's the boss (you).

One very important goal of Tasklemon is to make sure everything you need is within reach. With the new addition of about one million npm packages, your reach is looking pretty good.

New

  • Add npm support
    • Use any npm package without needing to declare, install or import it
    • Robust automatic download and installation
    • Smart caching and prefetching avoid any performance hit
    • Manual version pinning and cache management commands allow for finer control
  • Add scriptFile and scriptFolder, as File/Folder equivalents to __filename and __dirname
  • Automatically add shebang to new scripts when running them
    • Also includes the runtime version number, to prepare for backward compatibility

Improvements

  • Don't show call stack if exiting because of an argument error

Fixes

  • Set default argument type in cli.accept() to String, instead of Boolean
  • When parsing an item as a script argument, detect its type using the filesystem, rather than relying on its path
  • Throw if cli.accept() is called more than once
  • Clean up execution stage after running
  • Properly set exit code when using --inspect
  • Windows: Improve reliability when debugging
  • Tests: Clean up test site after running