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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@soda-gql/metro-plugin

v0.11.10

Published

Metro plugin for soda-gql (React Native)

Readme

@soda-gql/metro-plugin

Metro bundler plugin for soda-gql with support for Expo and React Native projects.

Installation

npm install @soda-gql/metro-plugin
# or
yarn add @soda-gql/metro-plugin
# or
bun add @soda-gql/metro-plugin

Usage

Expo Projects

// metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withSodaGql } = require("@soda-gql/metro-plugin");

const config = getDefaultConfig(__dirname);
module.exports = withSodaGql(config);

React Native (bare) Projects

// metro.config.js
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
const { withSodaGql } = require("@soda-gql/metro-plugin");

const config = getDefaultConfig(__dirname);
module.exports = withSodaGql(config);

With Options

// metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withSodaGql } = require("@soda-gql/metro-plugin");

const config = getDefaultConfig(__dirname);
module.exports = withSodaGql(config, {
  // Optional: Path to soda-gql config file
  configPath: "./soda-gql.config.ts",

  // Optional: Enable/disable the plugin (default: true)
  enabled: process.env.NODE_ENV !== "test",

  // Optional: Enable debug logging (default: false)
  debug: process.env.DEBUG === "true",
});

How It Works

  1. Transformer Wrapping: The plugin wraps Metro's default Babel transformer.

  2. Build-Time Transformation: When Metro processes a file:

    • Checks if the file contains soda-gql elements
    • If yes, applies the soda-gql Babel transformation
    • Passes the result to the upstream transformer for final processing
  3. Cache Invalidation: The transformer includes a getCacheKey() function that:

    • Incorporates the artifact generation number
    • Ensures Metro invalidates cache when soda-gql models change

Upstream Transformer Detection

The plugin automatically detects and uses the appropriate upstream transformer:

  1. Expo: @expo/metro-config/babel-transformer
  2. React Native 0.73+: @react-native/metro-babel-transformer
  3. Legacy React Native: metro-react-native-babel-transformer

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | configPath | string | undefined | Path to soda-gql config file | | enabled | boolean | true | Enable/disable the plugin | | debug | boolean | false | Enable verbose logging | | upstreamTransformer | string | undefined | Explicit path to upstream transformer to chain |

Watch Mode Considerations

Metro's watch mode behavior differs from webpack:

  • Cache Key Based: When soda-gql files change, the transformer's cache key changes, triggering re-transformation of affected files.

  • Development Server: During active development, if you modify model files and don't see changes reflected:

    1. Save the file again to trigger a rebuild
    2. If needed, restart Metro with --reset-cache flag
# Expo
npx expo start --clear

# React Native
npx react-native start --reset-cache

Chaining with Other Transformers

When using other Metro transformers (e.g., react-native-svg-transformer), soda-gql automatically detects and chains with them.

How Chaining Works

When an upstream transformer is detected, soda-gql generates a wrapper transformer file in node_modules/.cache/soda-gql/. This wrapper:

  1. Hardcodes the upstream transformer path at build time
  2. Enables reliable chaining in Metro worker processes
  3. Is automatically regenerated when the upstream path changes

Automatic Chaining (Recommended)

If you set babelTransformerPath before calling withSodaGql, it will be automatically preserved and chained:

// metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withSodaGql } = require("@soda-gql/metro-plugin");

const config = getDefaultConfig(__dirname);

// Set the other transformer first
config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");

// soda-gql will automatically chain with it
module.exports = withSodaGql(config);

Explicit Upstream Transformer

You can also explicitly specify the upstream transformer via options:

// metro.config.js
const { getDefaultConfig } = require("expo/metro-config");
const { withSodaGql } = require("@soda-gql/metro-plugin");

const config = getDefaultConfig(__dirname);
module.exports = withSodaGql(config, {
  upstreamTransformer: require.resolve("react-native-svg-transformer"),
});

Troubleshooting

"No compatible Metro Babel transformer found"

This error occurs when none of the supported upstream transformers are installed. Ensure you have one of:

  • @expo/metro-config (Expo projects)
  • @react-native/metro-babel-transformer (React Native 0.73+)
  • metro-react-native-babel-transformer (Legacy React Native)

Changes not reflected in development

  1. Try saving the file again
  2. Restart Metro with cache clearing:
    npx expo start --clear
    # or
    npx react-native start --reset-cache

Type errors in metro.config.js

If using TypeScript for your Metro config, you may need to add type annotations:

// metro.config.ts
import { getDefaultConfig } from "expo/metro-config";
import { withSodaGql } from "@soda-gql/metro-plugin";

const config = getDefaultConfig(__dirname);
export default withSodaGql(config);

License

MIT