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

soori

v0.0.5

Published

Soori allows you to build compile-time libraries.

Downloads

6

Readme

🪄 Soori

Soori allows you to build compile-time libraries.

(copy copied from babel-plugin-macros)

Problem

pages/
  ㄴapi/
    ㄴfunction1.js
    ㄴfunction2.js
    ㄴfunction3.js

A quick quiz: If your repository looks like the example above, how can you create an array containing the names of those files?

const functions = ['function1.js', 'function2.js', 'function3.js']; // <- How?

Off the top of your head, you might think about using fs.readdir() but once it's bundled and deployed, you won't be able to do that. It's better if you can handle it before bundling and deploying starts, during compile-time.

What if Soori gives you something like this?

import functions from 'soori/my-functions';

console.log(functions); // ['function1.js', 'function2.js', 'function3.js']

But, why?

Okay, let's imagine:

  • Your website needs to fetch a big chunk of data from an API and renders it.
  • But you don't need to do it at runtime.
  • It's okay to fetch it once at compile-time.

How would you implement this? You can write a Soori config that provides you soori/something module at compile-time.

Or, what if you could write something similar to tRPC on your own?

pages/
  ㄴapi/
    ㄴfunction1.js
    ㄴfunction2.js
    ㄴfunction3.js

No need to repeat this:

try {
  const response = await fetch('/api/function1?hello=world');
  const json = await response.json();
} catch (e) {
  // deal with it
}

But import methods like this:

import { function1 } from 'soori/my-nextjs-apis';

await function1({ hello: 'world' });

"Wait, what's the difference between writing a helper method that wraps a fetch request and handles errors?"

You're almost there. But you would have to do something like this:

// src/server/index.js

const requester = (...) => { ... }

export const function1 = requester({ path: '/api/function1', method: 'GET' })
export const function2 = requester({ path: '/api/function2', method: 'GET' })
export const function3 = ...

And, each time you add an additional API endpoint, you must perform this task manually.

Is it production-ready?

This is still a proof of concept. Never use it for production. However, the beauty of Soori is that it offers submodules during compile-time. If there are any issues, they will arise during compile-time. You can also view the generated code under node_modules/soori/submodules/.

Configuration

There is no proper documentation available as things are still unstable. Instead, please refer to this this demo configuration and its usage.

How to generate submodules based on the config?

You can run soori build.

If you're using Vite, you can utilize Soori's Vite plugin for live watching and on-the-fly building for dev mode.

import { vite } from 'soori';

export default defineConfig({
  plugins: [vite()],
});