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

react-native-module-paths

v1.0.7

Published

A small dev server to automatically sync your module paths for RAM bundling

Downloads

249

Readme

React Native Module Paths

A utility for synchronizing your RAM Bundle's preloaded module paths in real time.

When working with React Native RAM Bundles, your metro config consumes your preloaded module paths to optimize your production build.

The process of manually synchronizing the module paths during development became a bit tedious - and difficult to properly verify for large teams.

Using this package, you can spin up a simple CLI that will update your module paths each time a new critical file is added, removed, or renamed.

Installation

yarn add react-native-module-paths
# or 
npm i -D react-native-module-paths

npm link

Curl

# Mac
brew install curl
# Linux 
sudo apt-get install curl
# Windows
choco install curl

Ngrok

Next, sign up for a free account at https://ngrok.com then click on "Set Up and Installation".

Ngrok is going to ensure that any physical device you may be testing your code on can send your preloaded module paths back to your local repository.

Your setup steps should look like the following:

brew install ngrok
# or for Windows
choco install ngrok
# Then add your auth token using the CLI
ngrok config add-authtoken <your-token>
# Your token can be found here: "https://dashboard.ngrok.com/get-started/setup/"

Registering your Module Paths

In the entrypoint of your application, add the following two lines:

if (__DEV__) {
  const { RNModulePaths } = require("react-native-module-paths");
  RNModulePaths.registerAssets();
}

Now you can now spin up the react-native-module-paths CLI when developing your app:

npx react-native-module-paths

With this running, anytime you add, delete, or rename a critical file in your application it'll appear in your modulePaths.js file!

CLI Options

--port | -p

An option to override the default port number (4321)

--path | -w

A path to your modulePaths.js file. It will default to process.cwd()/modulePaths.js

--format | -f

Whether or not to format your module paths file for legibility when it's updated. This options defaults to true and runs prettier directly on the file.

Dev Loop Tips

When using this package, my development setup for React Native projects looks like the following:

// DevServer.ts
import { ChildProcess } from "@figliolia/child-process";

export class DevServer extends ChildProcess {
  static CPs: ChildProcess[] = [];

  public static async run() {
    this.bindToExit();
    this.CPs = [
      new ChildProcess("npx react-native-module-paths"),
      new ChildProcess("npx react-native start"),
    ];
    try {
      this.bindExits(this.CPs.map(CP => CP.process));
      await Promise.all(this.CPs.map(CP => CP.handler));
    } catch (error) {
      this.tearDown();
    }
  }

  private static bindToExit() {
    process.on("SIGINT", () => {
      this.tearDown();
    });
  }

  private static tearDown() {
    this.CPs.forEach(CP => CP.process.kill());
    this.CPs = [];
  }
}

(async () => {
  await DevServer.run();
})().catch(console.log);

I can then simply run ts-node DevServer.ts to run both react-native and react-native-module-paths CLI's at once without having to spin up two shells.

I'll often create devloop scripts such as this one so that I can easily add more tools into my workflow without flooding my package.json's scripts object.

Happy hacking :)