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

hotato

v0.6.1

Published

Developer tool for hot module reloading and snippet rerunning.

Downloads

28

Readme

hotato

npm standard code style

requires node v4 or newer

Hotato attempts to provide a solution for the problem of having to restart your program and having to wait until your code gets to the point where the file you made changes to gets tested. This is strictly meant for development, never use this in your production code! (although that could change in later versions)

Uses the keypress module for input awaiting. Hotato runs this code on the tty ReadStream, so make sure this won't affect your code before using this module:

// As soon as it gets require()d
keypress(process.stdin)

// When awaiting input:
process.stdin.resume()

// When received input:
process.stdin.pause()

Example

import hotato from 'hotato'

async function doThings () {
    const stuff = await downloadSomething()
    const hotModules = ['./process-stuff', './do-thing'].map((name) => require.resolve(name))
    const number = await hotato(hotModules, async (processStuff, doThing) => {
        console.log(processStuff)
        const thing = await processStuff(stuff)
        doThing(thing)
        return {nice: 5}
    })
    console.log(`got number: ${number.nice}`)
}

in the console

$ node hotato-example.js
downloading stuff
[hotato] Running loop with reloaded modules: [ '/home/ivan/code/__/playground/process-stuff.js',
  '/home/ivan/code/__/playground/do-thing.js' ]
[hotato] Loop rejected: Error: could not process stuff
    at process-stuff.js:4:12
    at module.exports (process-stuff.js:2:10)
    at test-hotato.js:18:29
    at test-hotato.js:11:16
    at Function.<anonymous> (test-hotato.js:15:45)
    at test-hotato.js:15:26
[hotato] Awaiting input. Enter "r" to re-run loop, or "c" to continue.
[hotato>

Make changes and fixes to your process-stuff.js file, and...

[hotato> r
[hotato] Re-running loop.
[hotato] Running loop with reloaded modules: [ '/home/ivan/code/__/playground/process-stuff.js',
  '/home/ivan/code/__/playground/do-thing.js' ]
doing thing
[hotato] Loop run OK, with returned value: { nice: 5 }
[hotato] Awaiting input. Enter "r" to re-run loop, or "c" to continue.
[hotato> c
got number: 5

hotato(resolvedNames, loopFn)

  • Array[String] resolved module paths
  • Function loop function that returns a Promise

Uncache and then require() the array of resolved names, and pass them to the loop function. Once the loop function is done, regardless of its resolution or rejection, hotato will await your input, which will be to either continue (rejects its own Promise if the loop function rejected or resolves its own Promise if the loop function resolved), or re-run the loop, in which the modules get uncached and required again, with the loop function being called with the modules as arguments.

Returns a Promise, which rejects or resolves however the loop function rejects or resolves on its last run.


Possible caveats

  • You probably don't want to run multiple hotato functions simultaneously, due to duplicate keyboard input listeners.
  • Hotato could mess with your code, if it listens for keyboard input.
  • Hotato could mess with your code, if the modules you want to recache store internal state (especially if they store crucial state before you run hotato).
  • You might not see the prompt in time if your code logs to console other things after the loop finished its run.