with-zephyr 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +39 -0
  2. package/README.md +334 -0
  3. package/package.json +14 -0
package/LICENSE ADDED
@@ -0,0 +1,39 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ ...
13
+
14
+ END OF TERMS AND CONDITIONS
15
+
16
+ APPENDIX: How to apply the Apache License to your work.
17
+
18
+ To apply the Apache License to your work, attach the following
19
+ boilerplate notice, with the fields enclosed by brackets "[]"
20
+ replaced with your own identifying information. (Don't include
21
+ the brackets!) The text should be enclosed in the appropriate
22
+ comment syntax for the file format. We also recommend that a
23
+ file or class name and description of purpose be included on the
24
+ same line as the copyright notice for each file. The "copyright"
25
+ word should be left as is (without quotes).
26
+
27
+ Copyright [2023] [Zephyr Cloud]
28
+
29
+ Licensed under the Apache License, Version 2.0 (the "License");
30
+ you may not use this file except in compliance with the License.
31
+ You may obtain a copy of the License at
32
+
33
+ http://www.apache.org/licenses/LICENSE-2.0
34
+
35
+ Unless required by applicable law or agreed to in writing, software
36
+ distributed under the License is distributed on an "AS IS" BASIS,
37
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
+ See the License for the specific language governing permissions and
39
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,334 @@
1
+ # zephyr-codemod
2
+
3
+ A codemod tool that automatically adds the `withZephyr` plugin to bundler configurations in your project.
4
+
5
+ ## What is Zephyr?
6
+
7
+ [**Zephyr**](https://zephyr-cloud.io) is a developer-first SaaS platform focused on **Module Federation** for building, deploying, and managing micro-frontend applications. It provides:
8
+
9
+ - 🚀 **Edge-deployed micro-frontends** with global CDN distribution
10
+ - 🔧 **Universal bundler support** - works with Webpack, Vite, Rollup, and more
11
+ - 📊 **Real-time analytics** and deployment insights
12
+ - 🛡️ **Version management** with rollback capabilities
13
+ - 🌐 **Custom domains** and environment management
14
+
15
+ Learn more at [**zephyr-cloud.io**](https://zephyr-cloud.io) | [**Documentation**](https://docs.zephyr-cloud.io) | [**GitHub**](https://github.com/zephyr-cloud)
16
+
17
+ ## Quick Start
18
+
19
+ Get your project Zephyr-ready in seconds:
20
+
21
+ ```bash
22
+ # 1. Run the codemod to add Zephyr plugins to your bundler configs
23
+ npx zephyr-codemod --install
24
+ # or: pnpm dlx zephyr-codemod --install
25
+ # or: yarn dlx zephyr-codemod --install
26
+ # or: bunx zephyr-codemod --install
27
+
28
+ # 2. That's it! Your bundler is now configured for Zephyr deployments
29
+ # Visit https://app.zephyr-cloud.io to deploy your micro-frontends
30
+ ```
31
+
32
+ ## Supported Bundlers
33
+
34
+ This codemod supports **10+ bundlers** with their respective Zephyr plugins:
35
+
36
+ - **Webpack** ([`zephyr-webpack-plugin`](https://www.npmjs.com/package/zephyr-webpack-plugin))
37
+ - **Rspack** ([`zephyr-rspack-plugin`](https://www.npmjs.com/package/zephyr-rspack-plugin))
38
+ - **Vite** ([`vite-plugin-zephyr`](https://www.npmjs.com/package/vite-plugin-zephyr))
39
+ - **Rollup** ([`rollup-plugin-zephyr`](https://www.npmjs.com/package/rollup-plugin-zephyr))
40
+ - **Rolldown** ([`zephyr-rolldown-plugin`](https://www.npmjs.com/package/zephyr-rolldown-plugin))
41
+ - **Modern.js** ([`zephyr-modernjs-plugin`](https://www.npmjs.com/package/zephyr-modernjs-plugin))
42
+ - **RSPress** ([`zephyr-rspress-plugin`](https://www.npmjs.com/package/zephyr-rspress-plugin))
43
+ - **Parcel** ([`parcel-reporter-zephyr`](https://www.npmjs.com/package/parcel-reporter-zephyr))
44
+ - **RSBuild** ([`zephyr-rspack-plugin`](https://www.npmjs.com/package/zephyr-rspack-plugin))
45
+ - **Re.Pack** (React Native) ([`zephyr-repack-plugin`](https://www.npmjs.com/package/zephyr-repack-plugin))
46
+
47
+ ## Installation
48
+
49
+ **No installation required!** Use directly with your package manager:
50
+
51
+ ```bash
52
+ # npm
53
+ npx zephyr-codemod
54
+
55
+ # pnpm
56
+ pnpm dlx zephyr-codemod
57
+
58
+ # yarn
59
+ yarn dlx zephyr-codemod
60
+
61
+ # bun
62
+ bunx zephyr-codemod
63
+ ```
64
+
65
+ > **💡 Tip:** Using `npx`/`dlx`/`bunx` ensures you always get the latest version without cluttering your global packages.
66
+
67
+ ## Usage
68
+
69
+ ### Basic Usage
70
+
71
+ Run the codemod in your project directory:
72
+
73
+ ```bash
74
+ npx zephyr-codemod
75
+ ```
76
+
77
+ This will:
78
+ 1. Search for bundler configuration files in the current directory and subdirectories
79
+ 2. Detect which bundler each config file is for
80
+ 3. Add the appropriate `withZephyr` plugin configuration
81
+ 4. Add the necessary import/require statements
82
+
83
+ ### Command Line Options
84
+
85
+ ```bash
86
+ # Show what would be changed without modifying files
87
+ npx zephyr-codemod --dry-run
88
+
89
+ # Automatically install missing plugin packages
90
+ npx zephyr-codemod --install
91
+
92
+ # Specify a different directory
93
+ npx zephyr-codemod ./my-project
94
+
95
+ # Only process specific bundlers
96
+ npx zephyr-codemod --bundlers webpack vite
97
+
98
+ # Combine options
99
+ npx zephyr-codemod ./src --dry-run --bundlers rollup --install
100
+
101
+ # Use with other package managers
102
+ pnpm dlx zephyr-codemod --install
103
+ yarn dlx zephyr-codemod --dry-run
104
+ bunx zephyr-codemod --bundlers vite rollup
105
+ ```
106
+
107
+ ### Options
108
+
109
+ - `[directory]` - Directory to search for config files (default: current directory)
110
+ - `-d, --dry-run` - Show what would be changed without modifying files
111
+ - `-b, --bundlers <bundlers...>` - Only process specific bundlers
112
+ - `-i, --install` - Automatically install missing plugin packages
113
+
114
+ ## Examples
115
+
116
+ ### Before and After
117
+
118
+ #### Webpack Configuration
119
+
120
+ **Before:**
121
+ ```javascript
122
+ const { composePlugins, withNx, withReact } = require('@nx/webpack');
123
+
124
+ module.exports = composePlugins(
125
+ withNx(),
126
+ withReact(),
127
+ (config) => {
128
+ return config;
129
+ }
130
+ );
131
+ ```
132
+
133
+ **After:**
134
+ ```javascript
135
+ const { withZephyr } = require('zephyr-webpack-plugin');
136
+ const { composePlugins, withNx, withReact } = require('@nx/webpack');
137
+
138
+ module.exports = composePlugins(
139
+ withNx(),
140
+ withReact(),
141
+ withZephyr(),
142
+ (config) => {
143
+ return config;
144
+ }
145
+ );
146
+ ```
147
+
148
+ #### Vite Configuration
149
+
150
+ **Before:**
151
+ ```typescript
152
+ import { defineConfig } from 'vite';
153
+ import react from '@vitejs/plugin-react';
154
+
155
+ export default defineConfig({
156
+ plugins: [
157
+ react(),
158
+ ],
159
+ });
160
+ ```
161
+
162
+ **After:**
163
+ ```typescript
164
+ import { withZephyr } from 'vite-plugin-zephyr';
165
+ import { defineConfig } from 'vite';
166
+ import react from '@vitejs/plugin-react';
167
+
168
+ export default defineConfig({
169
+ plugins: [
170
+ react(),
171
+ withZephyr(),
172
+ ],
173
+ });
174
+ ```
175
+
176
+ #### Rollup Configuration
177
+
178
+ **Before:**
179
+ ```javascript
180
+ module.exports = (config) => {
181
+ return config;
182
+ };
183
+ ```
184
+
185
+ **After:**
186
+ ```javascript
187
+ const { withZephyr } = require('rollup-plugin-zephyr');
188
+
189
+ module.exports = (config) => {
190
+ config.plugins.push(withZephyr());
191
+ return config;
192
+ };
193
+ ```
194
+
195
+ ## Package Management
196
+
197
+ The codemod can automatically install missing Zephyr plugin packages using the `--install` flag.
198
+
199
+ ### Package Manager Detection
200
+
201
+ The tool automatically detects your package manager by checking for:
202
+
203
+ 1. **Lock files** (in order of priority):
204
+ - `pnpm-lock.yaml` → pnpm
205
+ - `yarn.lock` → yarn
206
+ - `package-lock.json` → npm
207
+ - `bun.lockb` → bun
208
+
209
+ 2. **package.json `packageManager` field**
210
+ 3. **Monorepo indicators** (`pnpm-workspace.yaml`, `lerna.json`)
211
+ 4. **Environment variables** (`npm_config_user_agent`)
212
+
213
+ ### Supported Package Managers
214
+
215
+ - **npm**: `npm install --save-dev <package>`
216
+ - **yarn**: `yarn add --dev <package>`
217
+ - **pnpm**: `pnpm add --save-dev <package>`
218
+ - **bun**: `bun add --dev <package>`
219
+
220
+ ### Usage with Package Installation
221
+
222
+ ```bash
223
+ # Install packages and update configs in one command
224
+ npx zephyr-codemod --install
225
+
226
+ # Preview what packages would be installed
227
+ npx zephyr-codemod --dry-run --install
228
+
229
+ # The tool will show you which packages need to be installed if you don't use --install
230
+ npx zephyr-codemod
231
+ # Output: 💡 Tip: Use --install to automatically install missing packages:
232
+ # vite-plugin-zephyr
233
+ # zephyr-webpack-plugin
234
+ ```
235
+
236
+ ## Configuration File Detection
237
+
238
+ The codemod automatically detects and processes these configuration files:
239
+
240
+ - `webpack.config.js/ts/mjs`
241
+ - `rspack.config.js/ts/mjs`
242
+ - `vite.config.js/ts/mjs`
243
+ - `rollup.config.js/ts/mjs`
244
+ - `rolldown.config.js/ts/mjs`
245
+ - `modern.config.js/ts/mjs`
246
+ - `rspress.config.js/ts/mjs`
247
+ - `.parcelrc/.parcelrc.json`
248
+
249
+ ## Integration Patterns
250
+
251
+ The codemod recognizes and handles various configuration patterns:
252
+
253
+ ### Webpack/Rspack
254
+ - `composePlugins()` calls (Nx style)
255
+ - `plugins: []` arrays
256
+ - Direct `module.exports` assignments
257
+
258
+ ### Vite/Rolldown
259
+ - `defineConfig()` calls
260
+ - `plugins: []` arrays
261
+
262
+ ### Rollup
263
+ - Function-based configs with `config.plugins.push()`
264
+ - `plugins: []` arrays
265
+
266
+ ### Modern.js/RSPress
267
+ - `defineConfig()` calls with `plugins: []` arrays
268
+
269
+ ### Parcel
270
+ - JSON configuration with `reporters` array
271
+
272
+ ## Safety Features
273
+
274
+ - **Dry run mode**: Preview changes before applying them
275
+ - **Duplicate detection**: Skips files that already have `withZephyr` configured
276
+ - **Error handling**: Continues processing other files if one fails
277
+ - **Backup recommendation**: Always commit your changes before running codemods
278
+
279
+ ## Troubleshooting
280
+
281
+ ### Common Issues
282
+
283
+ 1. **"Could not parse file"** - The configuration file has syntax errors or uses unsupported patterns
284
+ 2. **"No suitable pattern found"** - The codemod doesn't recognize the configuration structure
285
+ 3. **"Already has withZephyr"** - The plugin is already configured (this is expected behavior)
286
+
287
+ ### Manual Configuration
288
+
289
+ If the codemod doesn't work for your specific configuration, you can manually add the withZephyr plugin:
290
+
291
+ 1. Install the appropriate plugin package
292
+ 2. Import/require the `withZephyr` function
293
+ 3. Add it to your bundler's plugin configuration
294
+
295
+ Refer to the individual plugin documentation for specific setup instructions.
296
+
297
+ ## Development
298
+
299
+ ### Building
300
+
301
+ The codemod is written in TypeScript and bundled with tsup:
302
+
303
+ ```bash
304
+ # Install dependencies
305
+ pnpm install
306
+
307
+ # Build the project
308
+ pnpm run build
309
+
310
+ # Development mode with watch
311
+ pnpm run dev
312
+
313
+ # Type checking
314
+ pnpm run typecheck
315
+ ```
316
+
317
+ ### Project Structure
318
+
319
+ ```
320
+ src/
321
+ ├── index.ts # Main CLI entry point
322
+ ├── types.ts # TypeScript type definitions
323
+ ├── bundler-configs.ts # Bundler configuration definitions
324
+ ├── transformers.ts # AST transformation functions
325
+ └── package-manager.ts # Package management utilities
326
+ ```
327
+
328
+ ## Contributing
329
+
330
+ Found a configuration pattern that isn't supported? Please open an issue or submit a pull request!
331
+
332
+ ## License
333
+
334
+ Apache-2.0
package/package.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "with-zephyr",
3
+ "version": "0.0.1",
4
+ "description": "Zephyr Codemod",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "ZephyrCloudIO",
8
+ "url": "https://github.com/ZephyrCloudIO"
9
+ },
10
+ "publishConfig": {
11
+ "access": "public",
12
+ "provenance": true
13
+ }
14
+ }