zephyr-codemod
A codemod tool that automatically adds the withZephyr plugin to bundler configurations in your project.
What is Zephyr?
Zephyr is a developer-first SaaS platform focused on Module Federation for building, deploying, and managing micro-frontend applications. It provides:
- 🚀 Edge-deployed micro-frontends with global CDN distribution
- 🔧 Universal bundler support - works with Webpack, Vite, Rollup, and more
- 📊 Real-time analytics and deployment insights
- 🛡️ Version management with rollback capabilities
- 🌐 Custom domains and environment management
Learn more at zephyr-cloud.io | Documentation | GitHub
Quick Start
Get your project Zephyr-ready in seconds:
npx zephyr-codemod --install
Supported Bundlers
This codemod supports 10+ bundlers with their respective Zephyr plugins:
Installation
No installation required! Use directly with your package manager:
npx zephyr-codemod
pnpm dlx zephyr-codemod
yarn dlx zephyr-codemod
bunx zephyr-codemod
💡 Tip: Using npx/dlx/bunx ensures you always get the latest version without cluttering your global packages.
Usage
Basic Usage
Run the codemod in your project directory:
npx zephyr-codemod
This will:
- Search for bundler configuration files in the current directory and subdirectories
- Detect which bundler each config file is for
- Add the appropriate
withZephyr plugin configuration
- Add the necessary import/require statements
Command Line Options
npx zephyr-codemod --dry-run
npx zephyr-codemod --install
npx zephyr-codemod ./my-project
npx zephyr-codemod --bundlers webpack vite
npx zephyr-codemod ./src --dry-run --bundlers rollup --install
pnpm dlx zephyr-codemod --install
yarn dlx zephyr-codemod --dry-run
bunx zephyr-codemod --bundlers vite rollup
Options
[directory] - Directory to search for config files (default: current directory)
-d, --dry-run - Show what would be changed without modifying files
-b, --bundlers <bundlers...> - Only process specific bundlers
-i, --install - Automatically install missing plugin packages
Examples
Before and After
Webpack Configuration
Before:
const { composePlugins, withNx, withReact } = require('@nx/webpack');
module.exports = composePlugins(
withNx(),
withReact(),
(config) => {
return config;
}
);
After:
const { withZephyr } = require('zephyr-webpack-plugin');
const { composePlugins, withNx, withReact } = require('@nx/webpack');
module.exports = composePlugins(
withNx(),
withReact(),
withZephyr(),
(config) => {
return config;
}
);
Vite Configuration
Before:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [
react(),
],
});
After:
import { withZephyr } from 'vite-plugin-zephyr';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
export default defineConfig({
plugins: [
react(),
withZephyr(),
],
});
Rollup Configuration
Before:
module.exports = (config) => {
return config;
};
After:
const { withZephyr } = require('rollup-plugin-zephyr');
module.exports = (config) => {
config.plugins.push(withZephyr());
return config;
};
Package Management
The codemod can automatically install missing Zephyr plugin packages using the --install flag.
Package Manager Detection
The tool automatically detects your package manager by checking for:
-
Lock files (in order of priority):
pnpm-lock.yaml → pnpm
yarn.lock → yarn
package-lock.json → npm
bun.lockb → bun
-
package.json packageManager field
-
Monorepo indicators (pnpm-workspace.yaml, lerna.json)
-
Environment variables (npm_config_user_agent)
Supported Package Managers
- npm:
npm install --save-dev <package>
- yarn:
yarn add --dev <package>
- pnpm:
pnpm add --save-dev <package>
- bun:
bun add --dev <package>
Usage with Package Installation
npx zephyr-codemod --install
npx zephyr-codemod --dry-run --install
npx zephyr-codemod
Configuration File Detection
The codemod automatically detects and processes these configuration files:
webpack.config.js/ts/mjs
rspack.config.js/ts/mjs
vite.config.js/ts/mjs
rollup.config.js/ts/mjs
rolldown.config.js/ts/mjs
modern.config.js/ts/mjs
rspress.config.js/ts/mjs
.parcelrc/.parcelrc.json
Integration Patterns
The codemod recognizes and handles various configuration patterns:
Webpack/Rspack
composePlugins() calls (Nx style)
plugins: [] arrays
- Direct
module.exports assignments
Vite/Rolldown
defineConfig() calls
plugins: [] arrays
Rollup
- Function-based configs with
config.plugins.push()
plugins: [] arrays
Modern.js/RSPress
defineConfig() calls with plugins: [] arrays
Parcel
- JSON configuration with
reporters array
Safety Features
- Dry run mode: Preview changes before applying them
- Duplicate detection: Skips files that already have
withZephyr configured
- Error handling: Continues processing other files if one fails
- Backup recommendation: Always commit your changes before running codemods
Troubleshooting
Common Issues
- "Could not parse file" - The configuration file has syntax errors or uses unsupported patterns
- "No suitable pattern found" - The codemod doesn't recognize the configuration structure
- "Already has withZephyr" - The plugin is already configured (this is expected behavior)
Manual Configuration
If the codemod doesn't work for your specific configuration, you can manually add the withZephyr plugin:
- Install the appropriate plugin package
- Import/require the
withZephyr function
- Add it to your bundler's plugin configuration
Refer to the individual plugin documentation for specific setup instructions.
Development
Building
The codemod is written in TypeScript and bundled with tsup:
pnpm install
pnpm run build
pnpm run dev
pnpm run typecheck
Project Structure
src/
├── index.ts # Main CLI entry point
├── types.ts # TypeScript type definitions
├── bundler-configs.ts # Bundler configuration definitions
├── transformers.ts # AST transformation functions
└── package-manager.ts # Package management utilities
Contributing
Found a configuration pattern that isn't supported? Please open an issue or submit a pull request!
License
MIT