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

@modular-rocks/slimfast-node

v0.1.9

Published

Slimfast puts your code base on a diet with automatic modularisation. This is Slimfast for NodeJS

Downloads

138

Readme

Slimfast Node

Automatically modularise your codebase! Put your codebase on a diet!

Installation

npm install @modular-rocks/slimfast-node

or

yarn add @modular-rocks/slimfast-node

Disclaimer

This is experimental and still very much WIP, but its also very customisable, so its already ready to use and customise.

Usage

Slimfast is built on top of Workspace, specifically workspace-node. Make sure you're familar with Workspace as its the Slimfast base (Its very simple!).

If you want to see its basic usage, take a look here.

    import Slimfast from '@modular-rocks/slimfast-node'

    const files: [string, string][] = [['/path/to/file', code]]; // example

    const opts: SlimFastOpts = {
      files, // optional, will use src and read the files if omitted
      src: '/path/to/directory',
      extensions: [],
      ignoredFiles: [],
      ignoredImports: [],
      packageContents: {},
    };

    const slimFast = new Slimfast(opts);
    await slimFast.run(); // wrap this in an async function if you want it to wait

It accepts the same options as a Workspace and uses Workspace to create a virtual copy of your codebase, called original and immediately creates a copy called refactored, which is changed when run is invoked.

Workspace pipeline

Workspace has a pipeline functionality of blocking functions that are invoked in order; none of the functions will begin until the last is complete.

Although the pipeline can be overridden in the options, the default pipeline for Slimfast is Extract, Name and Build, each of which can be overridden by passing a function under the corresponding name, placed directly in the main options hash:

| Option | Description | Type | | ------- | ----------------------------------------------------------------------------------------------------------- | -------- | | extract | Extracts AST PathNodes, invoking visitors | Function | | name | Adds a name and folder to each AST PathNode | Function | | build | Builds the new ASTs by wrappinng the PathNodes into functions and applying the relevant import statements | Function |

Name is very simple and in most cases should be overridden - modern LLMs like GPT do a great job at naming functions.

Extract invokes an array of visitors, more on that in the next section.

Build has default functionality but can be customised with the following options (which can be placed directly in the main options hash):

| Option | Description | Type | | ----------------- | ---------------------------------------------------------------------------------------------- | -------- | | wrap | Wraps the PathNode in an AST, with relevant import statements`` to be placed into a newfile | Function | | replace | Replaces the PathNodein the AST with a callee | Function | | functionGenerator | Wraps thePathNodeinsidewrapin a function | Function | | jsxGenerator | Wraps thePathNodeinsidewrapin a JSX component, if it contains JSX | Function | | functionReplacer | Replaces thePathNodein the AST with a callee function | Function | | jsxReplacer | Replaces thePathNode` in the AST with a callee component, if it contains JSX | Function |

Visitors

The Extract function invokes visitors in order. Each Visitor visits the code and extracts a PathNode from the AST that matches a criteria defined by its contraints.

By default, only the Expression Visitor is added to the pipeline. But in general, the idea is to start with a general visitor, like the Expression Visitor and then follow on with more specific visitors by including them later in the array.

Each visitor is unique, with unique constraints, hard coded, and must extend from Visitor.

The Visitors array can be overridden in the main options:

| Option | Description | Type | | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- | | visitors | An array of visitors, each extending from Visitor | Function[] |

Saving files after modularisation

After invoking the run method and the modularisation has taken place, you can run save on the refactored codebase to save the files.

slimfast.refactored.save();

Examples

Examples coming soon...

License

Apache 2.0