with-zephyr 0.0.0-canary.2 → 0.0.0-canary.20

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.
package/README.md CHANGED
@@ -34,13 +34,14 @@ bunx with-zephyr
34
34
 
35
35
  ## Supported Bundlers
36
36
 
37
- This codemod supports **11+ bundlers** with their respective Zephyr plugins:
37
+ This codemod supports **12+ bundlers** with their respective Zephyr plugins:
38
38
 
39
39
  - **Webpack** ([`zephyr-webpack-plugin`](https://www.npmjs.com/package/zephyr-webpack-plugin))
40
40
  - **Rspack** ([`zephyr-rspack-plugin`](https://www.npmjs.com/package/zephyr-rspack-plugin))
41
41
  - **Vite** ([`vite-plugin-zephyr`](https://www.npmjs.com/package/vite-plugin-zephyr))
42
42
  - **Rollup** ([`rollup-plugin-zephyr`](https://www.npmjs.com/package/rollup-plugin-zephyr))
43
43
  - **Rolldown** ([`zephyr-rolldown-plugin`](https://www.npmjs.com/package/zephyr-rolldown-plugin))
44
+ - **Astro** ([`zephyr-astro-integration`](https://www.npmjs.com/package/zephyr-astro-integration))
44
45
  - **Modern.js** ([`zephyr-modernjs-plugin`](https://www.npmjs.com/package/zephyr-modernjs-plugin))
45
46
  - **RSPress** ([`zephyr-rspress-plugin`](https://www.npmjs.com/package/zephyr-rspress-plugin))
46
47
  - **Parcel** ([`parcel-reporter-zephyr`](https://www.npmjs.com/package/parcel-reporter-zephyr))
@@ -92,9 +93,6 @@ This will:
92
93
  # Show what would be changed without modifying files
93
94
  npx with-zephyr --dry-run
94
95
 
95
- # Automatically install missing plugin packages
96
- npx with-zephyr --install
97
-
98
96
  # Specify a different directory
99
97
  npx with-zephyr ./my-project
100
98
 
@@ -102,10 +100,10 @@ npx with-zephyr ./my-project
102
100
  npx with-zephyr --bundlers webpack vite
103
101
 
104
102
  # Combine options
105
- npx with-zephyr ./src --dry-run --bundlers rollup --install
103
+ npx with-zephyr ./src --dry-run --bundlers rollup
106
104
 
107
105
  # Use with other package managers
108
- pnpm dlx with-zephyr --install
106
+ pnpm dlx with-zephyr
109
107
  yarn dlx with-zephyr --dry-run
110
108
  bunx with-zephyr --bundlers vite rollup
111
109
  ```
@@ -115,7 +113,8 @@ bunx with-zephyr --bundlers vite rollup
115
113
  - `[directory]` - Directory to search for config files (default: current directory)
116
114
  - `-d, --dry-run` - Show what would be changed without modifying files
117
115
  - `-b, --bundlers <bundlers...>` - Only process specific bundlers
118
- - `-i, --install` - Automatically install missing plugin packages
116
+
117
+ > The codemod automatically installs missing Zephyr plugins using your detected package manager (npm/yarn/pnpm/bun). In `--dry-run` it will only list what would be installed.
119
118
 
120
119
  ## Examples
121
120
 
@@ -192,7 +191,7 @@ module.exports = (config) => {
192
191
 
193
192
  ## Package Management
194
193
 
195
- The codemod can automatically install missing Zephyr plugin packages using the `--install` flag.
194
+ The codemod automatically installs missing Zephyr plugin packages when not running in `--dry-run` mode.
196
195
 
197
196
  ### Package Manager Detection
198
197
 
@@ -216,21 +215,10 @@ The tool automatically detects your package manager by checking for:
216
215
  - **pnpm**: `pnpm add --save-dev <package>`
217
216
  - **bun**: `bun add --dev <package>`
218
217
 
219
- ### Usage with Package Installation
220
-
221
- ```bash
222
- # Install packages and update configs in one command
223
- npx with-zephyr --install
218
+ ### Package Installation Behavior
224
219
 
225
- # Preview what packages would be installed
226
- npx with-zephyr --dry-run --install
227
-
228
- # The tool will show you which packages need to be installed if you don't use --install
229
- npx with-zephyr
230
- # Output: 💡 Tip: Use --install to automatically install missing packages:
231
- # vite-plugin-zephyr
232
- # zephyr-webpack-plugin
233
- ```
220
+ - `npx with-zephyr` will install any required Zephyr plugins that are missing.
221
+ - `npx with-zephyr --dry-run` will list the packages it would install without making changes.
234
222
 
235
223
  ## Configuration File Detection
236
224
 
@@ -241,6 +229,7 @@ The codemod automatically detects and processes these configuration files:
241
229
  - `vite.config.js/ts/mjs`
242
230
  - `rollup.config.js/ts/mjs`
243
231
  - `rolldown.config.js/ts/mjs`
232
+ - `astro.config.js/ts/mjs/mts`
244
233
  - `modern.config.js/ts/mjs`
245
234
  - `rspress.config.js/ts/mjs`
246
235
  - `rsbuild.config.js/ts/mjs`
@@ -304,7 +293,7 @@ Refer to the individual plugin documentation for specific setup instructions.
304
293
 
305
294
  ### Building
306
295
 
307
- The codemod is written in TypeScript and bundled with tsup:
296
+ The codemod is written in TypeScript and built with Rspack/RSLib:
308
297
 
309
298
  ```bash
310
299
  # Install dependencies
@@ -318,17 +307,22 @@ pnpm run dev
318
307
 
319
308
  # Type checking
320
309
  pnpm run typecheck
310
+
311
+ # Run the locally built CLI (no publish needed)
312
+ pnpm nx build with-zephyr
313
+ node ./libs/with-zephyr/dist/index.js --bundlers rspack /path/to/project
314
+ node ./libs/with-zephyr/dist/index.js --bundlers repack /path/to/react-native-project
321
315
  ```
322
316
 
323
317
  ### Project Structure
324
318
 
325
319
  ```
326
320
  src/
327
- ├── index.ts # Main CLI entry point
328
- ├── types.ts # TypeScript type definitions
329
- ├── bundler-configs.ts # Bundler configuration definitions
330
- ├── transformers.ts # AST transformation functions
331
- └── package-manager.ts # Package management utilities
321
+ ├── bundlers/ # Per-bundler configs + registry
322
+ ├── transformers/ # AST transforms (imports, plugin arrays, wrappers, etc.)
323
+ ├── package-manager.ts # Package management utilities
324
+ ├── index.ts # CLI entry point and orchestration
325
+ └── types.ts # Shared types
332
326
  ```
333
327
 
334
328
  ## Contributing
package/dist/index.js CHANGED
@@ -43515,7 +43515,10 @@ const parseClass = (glob, position)=>{
43515
43515
  true
43516
43516
  ];
43517
43517
  };
43518
- const unescape_unescape = (s, { windowsPathsNoEscape = false } = {})=>windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, '$1') : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1');
43518
+ const unescape_unescape = (s, { windowsPathsNoEscape = false, magicalBraces = true } = {})=>{
43519
+ if (magicalBraces) return windowsPathsNoEscape ? s.replace(/\[([^\/\\])\]/g, '$1') : s.replace(/((?!\\).|^)\[([^\/\\])\]/g, '$1$2').replace(/\\([^\/])/g, '$1');
43520
+ return windowsPathsNoEscape ? s.replace(/\[([^\/\\{}])\]/g, '$1') : s.replace(/((?!\\).|^)\[([^\/\\{}])\]/g, '$1$2').replace(/\\([^\/{}])/g, '$1');
43521
+ };
43519
43522
  const types = new Set([
43520
43523
  '!',
43521
43524
  '?',
@@ -43760,7 +43763,7 @@ class ast_AST {
43760
43763
  const dot = allowDot ?? !!this.#options.dot;
43761
43764
  if (this.#root === this) this.#fillNegs();
43762
43765
  if (!this.type) {
43763
- const noEmpty = this.isStart() && this.isEnd();
43766
+ const noEmpty = this.isStart() && this.isEnd() && !this.#parts.some((s)=>'string' != typeof s);
43764
43767
  const src = this.#parts.map((p)=>{
43765
43768
  const [re, _, hasMagic, uflag] = 'string' == typeof p ? ast_AST.#parseGlob(p, this.#hasMagic, noEmpty) : p.toRegExpSource(allowDot);
43766
43769
  this.#hasMagic = this.#hasMagic || hasMagic;
@@ -43857,8 +43860,7 @@ class ast_AST {
43857
43860
  }
43858
43861
  }
43859
43862
  if ('*' === c) {
43860
- if (noEmpty && '*' === glob) re += starNoEmpty;
43861
- else re += star;
43863
+ re += noEmpty && '*' === glob ? starNoEmpty : star;
43862
43864
  hasMagic = true;
43863
43865
  continue;
43864
43866
  }
@@ -43877,7 +43879,10 @@ class ast_AST {
43877
43879
  ];
43878
43880
  }
43879
43881
  }
43880
- const escape_escape = (s, { windowsPathsNoEscape = false } = {})=>windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, '[$&]') : s.replace(/[?*()[\]\\]/g, '\\$&');
43882
+ const escape_escape = (s, { windowsPathsNoEscape = false, magicalBraces = false } = {})=>{
43883
+ if (magicalBraces) return windowsPathsNoEscape ? s.replace(/[?*()[\]{}]/g, '[$&]') : s.replace(/[?*()[\]\\{}]/g, '\\$&');
43884
+ return windowsPathsNoEscape ? s.replace(/[?*()[\]]/g, '[$&]') : s.replace(/[?*()[\]\\]/g, '\\$&');
43885
+ };
43881
43886
  const minimatch = (p, pattern, options = {})=>{
43882
43887
  assertValidPattern(pattern);
43883
43888
  if (!options.nocomment && '#' === pattern.charAt(0)) return false;
@@ -44413,13 +44418,19 @@ class esm_Minimatch {
44413
44418
  if (p !== GLOBSTAR || prev === GLOBSTAR) return;
44414
44419
  if (void 0 === prev) if (void 0 !== next && next !== GLOBSTAR) pp[i + 1] = '(?:\\/|' + twoStar + '\\/)?' + next;
44415
44420
  else pp[i] = twoStar;
44416
- else if (void 0 === next) pp[i - 1] = prev + '(?:\\/|' + twoStar + ')?';
44421
+ else if (void 0 === next) pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + ')?';
44417
44422
  else if (next !== GLOBSTAR) {
44418
44423
  pp[i - 1] = prev + '(?:\\/|\\/' + twoStar + '\\/)' + next;
44419
44424
  pp[i + 1] = GLOBSTAR;
44420
44425
  }
44421
44426
  });
44422
- return pp.filter((p)=>p !== GLOBSTAR).join('/');
44427
+ const filtered = pp.filter((p)=>p !== GLOBSTAR);
44428
+ if (this.partial && filtered.length >= 1) {
44429
+ const prefixes = [];
44430
+ for(let i = 1; i <= filtered.length; i++)prefixes.push(filtered.slice(0, i).join('/'));
44431
+ return '(?:' + prefixes.join('|') + ')';
44432
+ }
44433
+ return filtered.join('/');
44423
44434
  }).join('|');
44424
44435
  const [open, close] = set.length > 1 ? [
44425
44436
  '(?:',
@@ -44429,6 +44440,7 @@ class esm_Minimatch {
44429
44440
  ''
44430
44441
  ];
44431
44442
  re = '^' + open + re + close + '$';
44443
+ if (this.partial) re = '^(?:\\/|' + open + re.slice(1, -1) + close + ')$';
44432
44444
  if (this.negate) re = '^(?!' + re + ').+$';
44433
44445
  try {
44434
44446
  this.regexp = new RegExp(re, [
@@ -47910,280 +47922,307 @@ const esm_glob = Object.assign(glob_, {
47910
47922
  unescape: unescape_unescape
47911
47923
  });
47912
47924
  esm_glob.glob = esm_glob;
47913
- const BUNDLER_CONFIGS = {
47914
- webpack: {
47915
- files: [
47916
- 'webpack.config.js',
47917
- 'webpack.config.ts',
47918
- 'webpack.config.mjs'
47919
- ],
47920
- plugin: 'zephyr-webpack-plugin',
47921
- importName: 'withZephyr',
47922
- patterns: [
47923
- {
47924
- type: 'compose-plugins',
47925
- matcher: /composePlugins\s*\(/,
47926
- transform: 'addToComposePlugins'
47927
- },
47928
- {
47929
- type: 'plugins-array',
47930
- matcher: /plugins\s*:\s*\[/,
47931
- transform: 'addToPluginsArray'
47932
- },
47933
- {
47934
- type: 'module-exports',
47935
- matcher: /module\.exports\s*=/,
47936
- transform: 'wrapModuleExports'
47937
- }
47938
- ]
47939
- },
47940
- rspack: {
47941
- files: [
47942
- 'rspack.config.js',
47943
- 'rspack.config.ts',
47944
- 'rspack.config.mjs'
47945
- ],
47946
- plugin: 'zephyr-rspack-plugin',
47947
- importName: 'withZephyr',
47948
- patterns: [
47949
- {
47950
- type: 'export-wrapped-call',
47951
- matcher: /export\s+default\s+withZephyr\s*\(\s*\)\s*\(/,
47952
- transform: 'skipAlreadyWrapped'
47953
- },
47954
- {
47955
- type: 'compose-plugins',
47956
- matcher: /composePlugins\s*\(/,
47957
- transform: 'addToComposePlugins'
47958
- },
47959
- {
47960
- type: 'export-default-object',
47961
- matcher: /export\s+default\s+\{/,
47962
- transform: 'wrapExportDefault'
47963
- },
47964
- {
47965
- type: 'plugins-array',
47966
- matcher: /plugins\s*:\s*\[/,
47967
- transform: 'addToPluginsArray'
47968
- },
47969
- {
47970
- type: 'module-exports',
47971
- matcher: /module\.exports\s*=/,
47972
- transform: 'wrapModuleExports'
47973
- }
47974
- ]
47975
- },
47976
- vite: {
47977
- files: [
47978
- 'vite.config.js',
47979
- 'vite.config.ts',
47980
- 'vite.config.mjs',
47981
- 'vite.config.mts'
47982
- ],
47983
- plugin: 'vite-plugin-zephyr',
47984
- importName: 'withZephyr',
47985
- patterns: [
47986
- {
47987
- type: 'define-config-function',
47988
- matcher: /defineConfig\s*\(\s*\(\s*\)\s*=>\s*\(\s*\{/,
47989
- transform: 'addToVitePluginsInFunction'
47990
- },
47991
- {
47992
- type: 'define-config',
47993
- matcher: /defineConfig\s*\(\s*\{/,
47994
- transform: 'addToVitePlugins'
47995
- },
47996
- {
47997
- type: 'export-default',
47998
- matcher: /export\s+default\s+\{/,
47999
- transform: 'addToVitePlugins'
48000
- }
48001
- ]
48002
- },
48003
- rollup: {
48004
- files: [
48005
- 'rollup.config.js',
48006
- 'rollup.config.ts',
48007
- 'rollup.config.mjs'
48008
- ],
48009
- plugin: 'rollup-plugin-zephyr',
48010
- importName: 'withZephyr',
48011
- patterns: [
48012
- {
48013
- type: 'export-array',
48014
- matcher: /export\s+default\s+\[/,
48015
- transform: 'addToRollupArrayConfig'
48016
- },
48017
- {
48018
- type: 'module-exports-function',
48019
- matcher: /module\.exports\s*=\s*\(\s*config\s*\)\s*=>/,
48020
- transform: 'addToRollupFunction'
48021
- },
48022
- {
48023
- type: 'plugins-array',
48024
- matcher: /plugins\s*:\s*\[/,
48025
- transform: 'addToPluginsArray'
48026
- }
48027
- ]
48028
- },
48029
- rolldown: {
48030
- files: [
48031
- 'rolldown.config.js',
48032
- 'rolldown.config.ts',
48033
- 'rolldown.config.mjs'
48034
- ],
48035
- plugin: 'zephyr-rolldown-plugin',
48036
- importName: 'withZephyr',
48037
- patterns: [
48038
- {
48039
- type: 'define-config',
48040
- matcher: /defineConfig\s*\(\s*\{/,
48041
- transform: 'addToRolldownPlugins'
48042
- },
48043
- {
48044
- type: 'plugins-array',
48045
- matcher: /plugins\s*:\s*\[/,
48046
- transform: 'addToPluginsArray'
48047
- }
48048
- ]
48049
- },
48050
- modernjs: {
48051
- files: [
48052
- 'modern.config.js',
48053
- 'modern.config.ts',
48054
- 'modern.config.mjs'
48055
- ],
48056
- plugin: 'zephyr-modernjs-plugin',
48057
- importName: 'withZephyr',
48058
- patterns: [
48059
- {
48060
- type: 'define-config',
48061
- matcher: /defineConfig\s*\(\s*\{/,
48062
- transform: 'addToModernJSPlugins'
48063
- },
48064
- {
48065
- type: 'plugins-array',
48066
- matcher: /plugins\s*:\s*\[/,
48067
- transform: 'addToPluginsArray'
48068
- }
48069
- ]
48070
- },
48071
- rspress: {
48072
- files: [
48073
- 'rspress.config.js',
48074
- 'rspress.config.ts',
48075
- 'rspress.config.mjs'
48076
- ],
48077
- plugin: 'zephyr-rspress-plugin',
48078
- importName: 'withZephyr',
48079
- patterns: [
48080
- {
48081
- type: 'define-config',
48082
- matcher: /defineConfig\s*\(\s*\{/,
48083
- transform: 'addToRSPressPlugins'
48084
- },
48085
- {
48086
- type: 'plugins-array',
48087
- matcher: /plugins\s*:\s*\[/,
48088
- transform: 'addToPluginsArray'
48089
- }
48090
- ]
48091
- },
48092
- parcel: {
48093
- files: [
48094
- '.parcelrc',
48095
- '.parcelrc.json'
48096
- ],
48097
- plugin: 'parcel-reporter-zephyr',
48098
- importName: null,
48099
- patterns: [
48100
- {
48101
- type: 'parcel-reporters',
48102
- matcher: /"reporters"\s*:\s*\[/,
48103
- transform: 'addToParcelReporters'
48104
- }
48105
- ]
48106
- },
48107
- repack: {
48108
- files: [
48109
- 'rspack.config.js',
48110
- 'rspack.config.ts',
48111
- 'rspack.config.mjs'
48112
- ],
48113
- plugin: 'zephyr-repack-plugin',
48114
- importName: 'withZephyr',
48115
- patterns: [
48116
- {
48117
- type: 'export-conditional-withzephyr',
48118
- matcher: /export\s+default\s+.*\?\s*withZephyr\s*\(\s*\)\s*\(/,
48119
- transform: 'skipAlreadyWrapped'
48120
- },
48121
- {
48122
- type: 'export-function-variable',
48123
- matcher: /export\s+default\s+(\w+)\s*;?\s*$/,
48124
- transform: 'wrapExportedFunction'
48125
- },
48126
- {
48127
- type: 'const-function-export',
48128
- matcher: /const\s+\w+\s*=\s*\w+\s*=>/,
48129
- transform: 'wrapExportedFunction'
48130
- }
48131
- ]
48132
- },
48133
- rsbuild: {
48134
- files: [
48135
- 'rsbuild.config.js',
48136
- 'rsbuild.config.ts',
48137
- 'rsbuild.config.mjs'
48138
- ],
48139
- plugin: 'zephyr-rsbuild-plugin',
48140
- importName: 'withZephyr',
48141
- patterns: [
48142
- {
48143
- type: 'zephyr-rsbuild-plugin-exists',
48144
- matcher: /zephyrRSbuildPlugin/,
48145
- transform: 'skipAlreadyWrapped'
48146
- },
48147
- {
48148
- type: 'define-config',
48149
- matcher: /defineConfig\s*\(\s*\{/,
48150
- transform: 'addZephyrRSbuildPlugin'
48151
- },
48152
- {
48153
- type: 'plugins-array',
48154
- matcher: /plugins\s*:\s*\[/,
48155
- transform: 'addZephyrRSbuildPlugin'
48156
- }
48157
- ]
48158
- },
48159
- rslib: {
48160
- files: [
48161
- 'rslib.config.js',
48162
- 'rslib.config.ts',
48163
- 'rslib.config.mjs'
48164
- ],
48165
- plugin: 'zephyr-rsbuild-plugin',
48166
- importName: 'withZephyr',
48167
- patterns: [
48168
- {
48169
- type: 'zephyr-rsbuild-plugin-exists',
48170
- matcher: /zephyrRSbuildPlugin/,
48171
- transform: 'skipAlreadyWrapped'
48172
- },
48173
- {
48174
- type: 'define-config',
48175
- matcher: /defineConfig\s*\(\s*\{/,
48176
- transform: 'addZephyrRSbuildPlugin'
48177
- },
48178
- {
48179
- type: 'plugins-array',
48180
- matcher: /plugins\s*:\s*\[/,
48181
- transform: 'addZephyrRSbuildPlugin'
48182
- }
48183
- ]
48184
- }
47925
+ const astro_astroConfig = {
47926
+ files: [
47927
+ 'astro.config.js',
47928
+ 'astro.config.ts',
47929
+ 'astro.config.mjs',
47930
+ 'astro.config.mts'
47931
+ ],
47932
+ plugin: 'zephyr-astro-integration',
47933
+ importName: 'withZephyr',
47934
+ patterns: [
47935
+ {
47936
+ type: 'define-config-function',
47937
+ matcher: /defineConfig\s*\(\s*\(\s*\)\s*=>\s*\(\s*\{/,
47938
+ transform: 'addToAstroIntegrationsInFunctionOrCreate'
47939
+ },
47940
+ {
47941
+ type: 'define-config',
47942
+ matcher: /defineConfig\s*\(\s*\{/,
47943
+ transform: 'addToAstroIntegrationsOrCreate'
47944
+ },
47945
+ {
47946
+ type: 'export-default',
47947
+ matcher: /export\s+default\s+\{/,
47948
+ transform: 'addToAstroIntegrationsOrCreate'
47949
+ }
47950
+ ]
47951
+ };
47952
+ const modernjs_modernjsConfig = {
47953
+ files: [
47954
+ 'modern.config.js',
47955
+ 'modern.config.ts',
47956
+ 'modern.config.mjs'
47957
+ ],
47958
+ plugin: 'zephyr-modernjs-plugin',
47959
+ importName: 'withZephyr',
47960
+ patterns: [
47961
+ {
47962
+ type: 'define-config',
47963
+ matcher: /defineConfig\s*\(\s*\{/,
47964
+ transform: 'addToPluginsArrayOrCreate'
47965
+ },
47966
+ {
47967
+ type: 'plugins-array',
47968
+ matcher: /plugins\s*:\s*\[/,
47969
+ transform: 'addToPluginsArray'
47970
+ }
47971
+ ]
47972
+ };
47973
+ const parcel_parcelConfig = {
47974
+ files: [
47975
+ '.parcelrc',
47976
+ '.parcelrc.json'
47977
+ ],
47978
+ plugin: 'parcel-reporter-zephyr',
47979
+ importName: null,
47980
+ patterns: [
47981
+ {
47982
+ type: 'parcel-reporters',
47983
+ matcher: /"reporters"\s*:\s*\[/,
47984
+ transform: 'addToParcelReporters'
47985
+ }
47986
+ ]
47987
+ };
47988
+ const repack_repackConfig = {
47989
+ files: [
47990
+ 'rspack.config.js',
47991
+ 'rspack.config.ts',
47992
+ 'rspack.config.mjs'
47993
+ ],
47994
+ plugin: 'zephyr-repack-plugin',
47995
+ importName: 'withZephyr',
47996
+ patterns: [
47997
+ {
47998
+ type: 'export-conditional-withzephyr',
47999
+ matcher: /export\s+default\s+.*\?\s*withZephyr\s*\(\s*\)\s*\(/,
48000
+ transform: 'skipAlreadyWrapped'
48001
+ },
48002
+ {
48003
+ type: 'export-function-variable',
48004
+ matcher: /export\s+default\s+(\w+)\s*;?\s*$/,
48005
+ transform: 'wrapExportedFunction'
48006
+ },
48007
+ {
48008
+ type: 'const-function-export',
48009
+ matcher: /const\s+\w+\s*=\s*\w+\s*=>/,
48010
+ transform: 'wrapExportedFunction'
48011
+ }
48012
+ ]
48013
+ };
48014
+ const rolldown_rolldownConfig = {
48015
+ files: [
48016
+ 'rolldown.config.js',
48017
+ 'rolldown.config.ts',
48018
+ 'rolldown.config.mjs'
48019
+ ],
48020
+ plugin: 'zephyr-rolldown-plugin',
48021
+ importName: 'withZephyr',
48022
+ patterns: [
48023
+ {
48024
+ type: 'define-config',
48025
+ matcher: /defineConfig\s*\(\s*\{/,
48026
+ transform: 'addToPluginsArrayOrCreate'
48027
+ },
48028
+ {
48029
+ type: 'plugins-array',
48030
+ matcher: /plugins\s*:\s*\[/,
48031
+ transform: 'addToPluginsArray'
48032
+ }
48033
+ ]
48034
+ };
48035
+ const rollup_rollupConfig = {
48036
+ files: [
48037
+ 'rollup.config.js',
48038
+ 'rollup.config.ts',
48039
+ 'rollup.config.mjs'
48040
+ ],
48041
+ plugin: 'rollup-plugin-zephyr',
48042
+ importName: 'withZephyr',
48043
+ patterns: [
48044
+ {
48045
+ type: 'export-array',
48046
+ matcher: /export\s+default\s+\[/,
48047
+ transform: 'addToRollupArrayConfig'
48048
+ },
48049
+ {
48050
+ type: 'module-exports-function',
48051
+ matcher: /module\.exports\s*=\s*\(\s*config\s*\)\s*=>/,
48052
+ transform: 'addToRollupFunction'
48053
+ },
48054
+ {
48055
+ type: 'plugins-array',
48056
+ matcher: /plugins\s*:\s*\[/,
48057
+ transform: 'addToPluginsArray'
48058
+ }
48059
+ ]
48060
+ };
48061
+ const rsbuild_rsbuildConfig = {
48062
+ files: [
48063
+ 'rsbuild.config.js',
48064
+ 'rsbuild.config.ts',
48065
+ 'rsbuild.config.mjs'
48066
+ ],
48067
+ plugin: 'zephyr-rsbuild-plugin',
48068
+ importName: 'withZephyr',
48069
+ patterns: [
48070
+ {
48071
+ type: 'define-config',
48072
+ matcher: /defineConfig\s*\(\s*\{/,
48073
+ transform: 'addToPluginsArray'
48074
+ },
48075
+ {
48076
+ type: 'plugins-array',
48077
+ matcher: /plugins\s*:\s*\[/,
48078
+ transform: 'addToPluginsArray'
48079
+ }
48080
+ ]
48081
+ };
48082
+ const rslib_rslibConfig = {
48083
+ files: [
48084
+ 'rslib.config.js',
48085
+ 'rslib.config.ts',
48086
+ 'rslib.config.mjs'
48087
+ ],
48088
+ plugin: 'zephyr-rsbuild-plugin',
48089
+ importName: 'withZephyr',
48090
+ patterns: [
48091
+ {
48092
+ type: 'define-config',
48093
+ matcher: /defineConfig\s*\(\s*\{/,
48094
+ transform: 'addToPluginsArray'
48095
+ },
48096
+ {
48097
+ type: 'plugins-array',
48098
+ matcher: /plugins\s*:\s*\[/,
48099
+ transform: 'addToPluginsArray'
48100
+ }
48101
+ ]
48102
+ };
48103
+ const rspack_rspackConfig = {
48104
+ files: [
48105
+ 'rspack.config.js',
48106
+ 'rspack.config.ts',
48107
+ 'rspack.config.mjs'
48108
+ ],
48109
+ plugin: 'zephyr-rspack-plugin',
48110
+ importName: 'withZephyr',
48111
+ patterns: [
48112
+ {
48113
+ type: 'export-wrapped-call',
48114
+ matcher: /export\s+default\s+withZephyr\s*\(\s*\)\s*\(/,
48115
+ transform: 'skipAlreadyWrapped'
48116
+ },
48117
+ {
48118
+ type: 'define-config',
48119
+ matcher: /export\s+default\s+defineConfig\s*\(/,
48120
+ transform: 'wrapExportDefault'
48121
+ },
48122
+ {
48123
+ type: 'compose-plugins',
48124
+ matcher: /composePlugins\s*\(/,
48125
+ transform: 'addToComposePlugins'
48126
+ },
48127
+ {
48128
+ type: 'export-default-object',
48129
+ matcher: /export\s+default\s+\{/,
48130
+ transform: 'wrapExportDefault'
48131
+ },
48132
+ {
48133
+ type: 'plugins-array',
48134
+ matcher: /plugins\s*:\s*\[/,
48135
+ transform: 'addToPluginsArray'
48136
+ },
48137
+ {
48138
+ type: 'module-exports',
48139
+ matcher: /module\.exports\s*=/,
48140
+ transform: 'wrapModuleExports'
48141
+ }
48142
+ ]
48143
+ };
48144
+ const rspress_rspressConfig = {
48145
+ files: [
48146
+ 'rspress.config.js',
48147
+ 'rspress.config.ts',
48148
+ 'rspress.config.mjs'
48149
+ ],
48150
+ plugin: 'zephyr-rspress-plugin',
48151
+ importName: 'withZephyr',
48152
+ patterns: [
48153
+ {
48154
+ type: 'define-config',
48155
+ matcher: /defineConfig\s*\(\s*\{/,
48156
+ transform: 'addToPluginsArrayOrCreate'
48157
+ },
48158
+ {
48159
+ type: 'plugins-array',
48160
+ matcher: /plugins\s*:\s*\[/,
48161
+ transform: 'addToPluginsArray'
48162
+ }
48163
+ ]
48164
+ };
48165
+ const vite_viteConfig = {
48166
+ files: [
48167
+ 'vite.config.js',
48168
+ 'vite.config.ts',
48169
+ 'vite.config.mjs',
48170
+ 'vite.config.mts'
48171
+ ],
48172
+ plugin: 'vite-plugin-zephyr',
48173
+ importName: 'withZephyr',
48174
+ patterns: [
48175
+ {
48176
+ type: 'define-config-function',
48177
+ matcher: /defineConfig\s*\(\s*\(\s*\)\s*=>\s*\(\s*\{/,
48178
+ transform: 'addToVitePluginsInFunction'
48179
+ },
48180
+ {
48181
+ type: 'define-config',
48182
+ matcher: /defineConfig\s*\(\s*\{/,
48183
+ transform: 'addToVitePlugins'
48184
+ },
48185
+ {
48186
+ type: 'export-default',
48187
+ matcher: /export\s+default\s+\{/,
48188
+ transform: 'addToVitePlugins'
48189
+ }
48190
+ ]
48191
+ };
48192
+ const webpack_webpackConfig = {
48193
+ files: [
48194
+ 'webpack.config.js',
48195
+ 'webpack.config.ts',
48196
+ 'webpack.config.mjs'
48197
+ ],
48198
+ plugin: 'zephyr-webpack-plugin',
48199
+ importName: 'withZephyr',
48200
+ patterns: [
48201
+ {
48202
+ type: 'compose-plugins',
48203
+ matcher: /composePlugins\s*\(/,
48204
+ transform: 'addToComposePlugins'
48205
+ },
48206
+ {
48207
+ type: 'plugins-array',
48208
+ matcher: /plugins\s*:\s*\[/,
48209
+ transform: 'addToPluginsArray'
48210
+ },
48211
+ {
48212
+ type: 'module-exports',
48213
+ matcher: /module\.exports\s*=/,
48214
+ transform: 'wrapModuleExports'
48215
+ }
48216
+ ]
48185
48217
  };
48186
48218
  function detectPackageManager(directory = process.cwd()) {
48219
+ if (process.env.npm_config_user_agent) {
48220
+ const userAgent = process.env.npm_config_user_agent.toLowerCase();
48221
+ if (userAgent.includes('pnpm')) return 'pnpm';
48222
+ if (userAgent.includes('yarn')) return 'yarn';
48223
+ if (userAgent.includes('bun')) return 'bun';
48224
+ if (userAgent.includes('npm')) return 'npm';
48225
+ }
48187
48226
  const lockFiles = {
48188
48227
  'pnpm-lock.yaml': 'pnpm',
48189
48228
  'yarn.lock': 'yarn',
@@ -48216,12 +48255,6 @@ function detectPackageManager(directory = process.cwd()) {
48216
48255
  if (fs_0.existsSync(path_0.join(rootDir, 'lerna.json')) || fs_0.existsSync(path_0.join(rootDir, 'yarn.lock')) && rootDir === directory) return 'yarn';
48217
48256
  }
48218
48257
  } catch {}
48219
- if (process.env.npm_config_user_agent) {
48220
- const userAgent = process.env.npm_config_user_agent.toLowerCase();
48221
- if (userAgent.includes('pnpm')) return 'pnpm';
48222
- if (userAgent.includes('yarn')) return 'yarn';
48223
- if (userAgent.includes('bun')) return 'bun';
48224
- }
48225
48258
  return 'npm';
48226
48259
  }
48227
48260
  function isPackageInstalled(packageName, directory = process.cwd()) {
@@ -48257,8 +48290,8 @@ function installPackage(directory, packageName, packageManager, isDev = true) {
48257
48290
  }
48258
48291
  }
48259
48292
  var lib = __webpack_require__("../../node_modules/.pnpm/@babel+parser@7.28.4/node_modules/@babel/parser/lib/index.js");
48260
- var traverse_lib = __webpack_require__("../../node_modules/.pnpm/@babel+traverse@7.28.4_supports-color@5.5.0/node_modules/@babel/traverse/lib/index.js");
48261
48293
  var generator_lib = __webpack_require__("../../node_modules/.pnpm/@babel+generator@7.28.3/node_modules/@babel/generator/lib/index.js");
48294
+ var traverse_lib = __webpack_require__("../../node_modules/.pnpm/@babel+traverse@7.28.4_supports-color@5.5.0/node_modules/@babel/traverse/lib/index.js");
48262
48295
  var types_lib = __webpack_require__("../../node_modules/.pnpm/@babel+types@7.28.4/node_modules/@babel/types/lib/index.js");
48263
48296
  function parseFile(filePath) {
48264
48297
  const content = fs_0.readFileSync(filePath, 'utf8');
@@ -48300,6 +48333,18 @@ function writeFile(filePath, ast) {
48300
48333
  });
48301
48334
  fs_0.writeFileSync(filePath, output.code);
48302
48335
  }
48336
+ function hasZephyrPlugin(ast) {
48337
+ let hasPlugin = false;
48338
+ (0, traverse_lib["default"])(ast, {
48339
+ CallExpression (path) {
48340
+ if (types_lib.isIdentifier(path.node.callee, {
48341
+ name: 'withZephyr'
48342
+ })) hasPlugin = true;
48343
+ }
48344
+ });
48345
+ return hasPlugin;
48346
+ }
48347
+ function skipAlreadyWrapped(_ast) {}
48303
48348
  function addZephyrImport(ast, pluginName, importName) {
48304
48349
  if (!importName) return;
48305
48350
  let hasImport = false;
@@ -48348,19 +48393,44 @@ function addZephyrRequire(ast, pluginName, importName) {
48348
48393
  });
48349
48394
  }
48350
48395
  }
48351
- function transformers_hasZephyrPlugin(ast) {
48352
- let hasPlugin = false;
48396
+ function addToPluginsArray(ast) {
48397
+ (0, traverse_lib["default"])(ast, {
48398
+ ObjectProperty (path) {
48399
+ if (types_lib.isIdentifier(path.node.key, {
48400
+ name: 'plugins'
48401
+ }) && types_lib.isArrayExpression(path.node.value)) path.node.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48402
+ }
48403
+ });
48404
+ }
48405
+ function addToPluginsArrayOrCreate(ast) {
48406
+ let pluginAdded = false;
48353
48407
  (0, traverse_lib["default"])(ast, {
48354
48408
  CallExpression (path) {
48355
48409
  if (types_lib.isIdentifier(path.node.callee, {
48356
- name: 'withZephyr'
48357
- })) hasPlugin = true;
48358
- },
48359
- Identifier (path) {
48360
- if ('withZephyr' === path.node.name && types_lib.isCallExpression(path.parent) && path.parent.callee === path.node) hasPlugin = true;
48410
+ name: 'defineConfig'
48411
+ }) && 1 === path.node.arguments.length && types_lib.isObjectExpression(path.node.arguments[0])) {
48412
+ const configObject = path.node.arguments[0];
48413
+ let pluginsProperty = null;
48414
+ for (const prop of configObject.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48415
+ name: 'plugins'
48416
+ }) && types_lib.isArrayExpression(prop.value)) {
48417
+ pluginsProperty = prop;
48418
+ break;
48419
+ }
48420
+ if (pluginsProperty && types_lib.isArrayExpression(pluginsProperty.value)) {
48421
+ pluginsProperty.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48422
+ pluginAdded = true;
48423
+ } else if (!pluginsProperty) {
48424
+ const newPluginsProperty = types_lib.objectProperty(types_lib.identifier('plugins'), types_lib.arrayExpression([
48425
+ types_lib.callExpression(types_lib.identifier('withZephyr'), [])
48426
+ ]));
48427
+ configObject.properties.push(newPluginsProperty);
48428
+ pluginAdded = true;
48429
+ }
48430
+ }
48361
48431
  }
48362
48432
  });
48363
- return hasPlugin;
48433
+ if (!pluginAdded) addToPluginsArray(ast);
48364
48434
  }
48365
48435
  function addToComposePlugins(ast) {
48366
48436
  (0, traverse_lib["default"])(ast, {
@@ -48376,15 +48446,6 @@ function addToComposePlugins(ast) {
48376
48446
  }
48377
48447
  });
48378
48448
  }
48379
- function addToPluginsArray(ast) {
48380
- (0, traverse_lib["default"])(ast, {
48381
- ObjectProperty (path) {
48382
- if (types_lib.isIdentifier(path.node.key, {
48383
- name: 'plugins'
48384
- }) && types_lib.isArrayExpression(path.node.value)) path.node.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48385
- }
48386
- });
48387
- }
48388
48449
  function addToVitePlugins(ast) {
48389
48450
  addToPluginsArray(ast);
48390
48451
  }
@@ -48410,13 +48471,112 @@ function addToVitePluginsInFunction(ast) {
48410
48471
  }
48411
48472
  });
48412
48473
  }
48474
+ function addToAstroIntegrations(ast) {
48475
+ (0, traverse_lib["default"])(ast, {
48476
+ ObjectExpression (path) {
48477
+ for (const prop of path.node.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48478
+ name: 'integrations'
48479
+ }) && types_lib.isArrayExpression(prop.value)) {
48480
+ prop.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48481
+ path.stop();
48482
+ return;
48483
+ }
48484
+ }
48485
+ });
48486
+ }
48487
+ function addToAstroIntegrationsInFunction(ast) {
48488
+ (0, traverse_lib["default"])(ast, {
48489
+ CallExpression (path) {
48490
+ if (types_lib.isIdentifier(path.node.callee, {
48491
+ name: 'defineConfig'
48492
+ }) && 1 === path.node.arguments.length && types_lib.isArrowFunctionExpression(path.node.arguments[0])) {
48493
+ const arrowFunc = path.node.arguments[0];
48494
+ let objExpr = null;
48495
+ if (types_lib.isParenthesizedExpression(arrowFunc.body) && types_lib.isObjectExpression(arrowFunc.body.expression)) objExpr = arrowFunc.body.expression;
48496
+ else if (types_lib.isObjectExpression(arrowFunc.body)) objExpr = arrowFunc.body;
48497
+ if (objExpr) {
48498
+ for (const prop of objExpr.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48499
+ name: 'integrations'
48500
+ }) && types_lib.isArrayExpression(prop.value)) {
48501
+ prop.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48502
+ break;
48503
+ }
48504
+ }
48505
+ }
48506
+ }
48507
+ });
48508
+ }
48509
+ function addToAstroIntegrationsOrCreate(ast) {
48510
+ let integrationAdded = false;
48511
+ (0, traverse_lib["default"])(ast, {
48512
+ CallExpression (path) {
48513
+ if (types_lib.isIdentifier(path.node.callee, {
48514
+ name: 'defineConfig'
48515
+ }) && 1 === path.node.arguments.length && types_lib.isObjectExpression(path.node.arguments[0])) {
48516
+ const configObject = path.node.arguments[0];
48517
+ let integrationsProperty = null;
48518
+ for (const prop of configObject.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48519
+ name: 'integrations'
48520
+ }) && types_lib.isArrayExpression(prop.value)) {
48521
+ integrationsProperty = prop;
48522
+ break;
48523
+ }
48524
+ if (integrationsProperty && types_lib.isArrayExpression(integrationsProperty.value)) {
48525
+ integrationsProperty.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48526
+ integrationAdded = true;
48527
+ } else if (!integrationsProperty) {
48528
+ const newIntegrationsProperty = types_lib.objectProperty(types_lib.identifier('integrations'), types_lib.arrayExpression([
48529
+ types_lib.callExpression(types_lib.identifier('withZephyr'), [])
48530
+ ]));
48531
+ configObject.properties.push(newIntegrationsProperty);
48532
+ integrationAdded = true;
48533
+ }
48534
+ }
48535
+ }
48536
+ });
48537
+ if (!integrationAdded) addToAstroIntegrations(ast);
48538
+ }
48539
+ function addToAstroIntegrationsInFunctionOrCreate(ast) {
48540
+ let integrationAdded = false;
48541
+ (0, traverse_lib["default"])(ast, {
48542
+ CallExpression (path) {
48543
+ if (types_lib.isIdentifier(path.node.callee, {
48544
+ name: 'defineConfig'
48545
+ }) && 1 === path.node.arguments.length && types_lib.isArrowFunctionExpression(path.node.arguments[0])) {
48546
+ const arrowFunc = path.node.arguments[0];
48547
+ let objExpr = null;
48548
+ if (types_lib.isParenthesizedExpression(arrowFunc.body) && types_lib.isObjectExpression(arrowFunc.body.expression)) objExpr = arrowFunc.body.expression;
48549
+ else if (types_lib.isObjectExpression(arrowFunc.body)) objExpr = arrowFunc.body;
48550
+ if (objExpr) {
48551
+ let integrationsProperty = null;
48552
+ for (const prop of objExpr.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48553
+ name: 'integrations'
48554
+ }) && types_lib.isArrayExpression(prop.value)) {
48555
+ integrationsProperty = prop;
48556
+ break;
48557
+ }
48558
+ if (integrationsProperty && types_lib.isArrayExpression(integrationsProperty.value)) {
48559
+ integrationsProperty.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48560
+ integrationAdded = true;
48561
+ } else if (!integrationsProperty) {
48562
+ const newIntegrationsProperty = types_lib.objectProperty(types_lib.identifier('integrations'), types_lib.arrayExpression([
48563
+ types_lib.callExpression(types_lib.identifier('withZephyr'), [])
48564
+ ]));
48565
+ objExpr.properties.push(newIntegrationsProperty);
48566
+ integrationAdded = true;
48567
+ }
48568
+ }
48569
+ }
48570
+ }
48571
+ });
48572
+ if (!integrationAdded) addToAstroIntegrationsInFunction(ast);
48573
+ }
48413
48574
  function addToRollupFunction(ast) {
48414
48575
  (0, traverse_lib["default"])(ast, {
48415
48576
  ArrowFunctionExpression (path) {
48416
- if (1 === path.node.params.length && types_lib.isIdentifier(path.node.params[0], {
48417
- name: 'config'
48418
- })) {
48419
- const pushStatement = types_lib.expressionStatement(types_lib.callExpression(types_lib.memberExpression(types_lib.memberExpression(types_lib.identifier('config'), types_lib.identifier('plugins')), types_lib.identifier('push')), [
48577
+ if (1 === path.node.params.length && types_lib.isIdentifier(path.node.params[0])) {
48578
+ const paramName = path.node.params[0].name;
48579
+ const pushStatement = types_lib.expressionStatement(types_lib.callExpression(types_lib.memberExpression(types_lib.memberExpression(types_lib.identifier(paramName), types_lib.identifier('plugins')), types_lib.identifier('push')), [
48420
48580
  types_lib.callExpression(types_lib.identifier('withZephyr'), [])
48421
48581
  ]));
48422
48582
  if (types_lib.isBlockStatement(path.node.body)) {
@@ -48428,21 +48588,18 @@ function addToRollupFunction(ast) {
48428
48588
  }
48429
48589
  });
48430
48590
  }
48431
- function addToRolldownPlugins(ast) {
48432
- addToPluginsArray(ast);
48433
- }
48434
- function addToModernJSPlugins(ast) {
48435
- addToPluginsArray(ast);
48436
- }
48437
- function addToRSPressPlugins(ast) {
48438
- addToPluginsArray(ast);
48439
- }
48440
- function addToParcelReporters(filePath, pluginName) {
48441
- const content = fs_0.readFileSync(filePath, 'utf8');
48442
- const config = JSON.parse(content);
48443
- if (!config.reporters) config.reporters = [];
48444
- if (!config.reporters.includes(pluginName)) config.reporters.push(pluginName);
48445
- fs_0.writeFileSync(filePath, JSON.stringify(config, null, 2));
48591
+ function addToRollupArrayConfig(ast) {
48592
+ (0, traverse_lib["default"])(ast, {
48593
+ ExportDefaultDeclaration (path) {
48594
+ if (types_lib.isArrayExpression(path.node.declaration)) {
48595
+ for (const element of path.node.declaration.elements)if (types_lib.isObjectExpression(element)) {
48596
+ for (const prop of element.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48597
+ name: 'plugins'
48598
+ }) && types_lib.isArrayExpression(prop.value)) return void prop.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48599
+ }
48600
+ }
48601
+ }
48602
+ });
48446
48603
  }
48447
48604
  function wrapModuleExports(ast) {
48448
48605
  (0, traverse_lib["default"])(ast, {
@@ -48451,33 +48608,22 @@ function wrapModuleExports(ast) {
48451
48608
  name: 'module'
48452
48609
  }) && types_lib.isIdentifier(path.node.left.property, {
48453
48610
  name: 'exports'
48454
- })) path.node.right = types_lib.callExpression(types_lib.identifier('withZephyr'), []);
48611
+ })) path.node.right = types_lib.callExpression(types_lib.callExpression(types_lib.identifier('withZephyr'), []), [
48612
+ path.node.right
48613
+ ]);
48455
48614
  }
48456
48615
  });
48457
48616
  }
48458
48617
  function wrapExportDefault(ast) {
48459
48618
  (0, traverse_lib["default"])(ast, {
48460
48619
  ExportDefaultDeclaration (path) {
48461
- if (types_lib.isObjectExpression(path.node.declaration)) path.node.declaration = types_lib.callExpression(types_lib.callExpression(types_lib.identifier('withZephyr'), []), [
48462
- path.node.declaration
48620
+ const declaration = path.node.declaration;
48621
+ if (types_lib.isObjectExpression(declaration) || types_lib.isCallExpression(declaration) || types_lib.isAwaitExpression(declaration)) path.node.declaration = types_lib.callExpression(types_lib.callExpression(types_lib.identifier('withZephyr'), []), [
48622
+ declaration
48463
48623
  ]);
48464
48624
  }
48465
48625
  });
48466
48626
  }
48467
- function addToRollupArrayConfig(ast) {
48468
- (0, traverse_lib["default"])(ast, {
48469
- ExportDefaultDeclaration (path) {
48470
- if (types_lib.isArrayExpression(path.node.declaration)) {
48471
- for (const element of path.node.declaration.elements)if (types_lib.isObjectExpression(element)) {
48472
- for (const prop of element.properties)if (types_lib.isObjectProperty(prop) && types_lib.isIdentifier(prop.key, {
48473
- name: 'plugins'
48474
- }) && types_lib.isArrayExpression(prop.value)) return void prop.value.elements.push(types_lib.callExpression(types_lib.identifier('withZephyr'), []));
48475
- }
48476
- }
48477
- }
48478
- });
48479
- }
48480
- function skipAlreadyWrapped(_ast) {}
48481
48627
  function wrapExportedFunction(ast) {
48482
48628
  (0, traverse_lib["default"])(ast, {
48483
48629
  ExportDefaultDeclaration (path) {
@@ -48498,122 +48644,50 @@ function wrapExportedFunction(ast) {
48498
48644
  }
48499
48645
  });
48500
48646
  }
48501
- function addZephyrRSbuildPlugin(ast) {
48502
- let hasWithZephyrImport = false;
48503
- (0, traverse_lib["default"])(ast, {
48504
- ImportDeclaration (path) {
48505
- if ('zephyr-rspack-plugin' === path.node.source.value) {
48506
- const specifiers = path.node.specifiers;
48507
- for (const spec of specifiers)if (types_lib.isImportSpecifier(spec) && types_lib.isIdentifier(spec.imported, {
48508
- name: 'withZephyr'
48509
- })) hasWithZephyrImport = true;
48510
- }
48511
- }
48512
- });
48513
- if (!hasWithZephyrImport) {
48514
- const importDeclaration = types_lib.importDeclaration([
48515
- types_lib.importSpecifier(types_lib.identifier('withZephyr'), types_lib.identifier('withZephyr'))
48516
- ], types_lib.stringLiteral('zephyr-rspack-plugin'));
48517
- (0, traverse_lib["default"])(ast, {
48518
- Program (path) {
48519
- const firstImportIndex = path.node.body.findIndex((node)=>types_lib.isImportDeclaration(node));
48520
- if (firstImportIndex >= 0) path.node.body.splice(firstImportIndex + 1, 0, importDeclaration);
48521
- else path.node.body.unshift(importDeclaration);
48522
- path.stop();
48523
- }
48524
- });
48525
- }
48526
- let hasZephyrPlugin = false;
48527
- (0, traverse_lib["default"])(ast, {
48528
- VariableDeclarator (path) {
48529
- if (types_lib.isIdentifier(path.node.id, {
48530
- name: 'zephyrRSbuildPlugin'
48531
- })) hasZephyrPlugin = true;
48532
- }
48533
- });
48534
- if (!hasZephyrPlugin) {
48535
- const zephyrPluginFunction = types_lib.variableDeclaration('const', [
48536
- types_lib.variableDeclarator(types_lib.identifier('zephyrRSbuildPlugin'), types_lib.arrowFunctionExpression([], types_lib.objectExpression([
48537
- types_lib.objectProperty(types_lib.identifier('name'), types_lib.stringLiteral('zephyr-rsbuild-plugin')),
48538
- types_lib.objectMethod('method', types_lib.identifier('setup'), [
48539
- types_lib.identifier('api')
48540
- ], types_lib.blockStatement([
48541
- types_lib.expressionStatement(types_lib.callExpression(types_lib.memberExpression(types_lib.identifier('api'), types_lib.identifier('modifyRspackConfig')), [
48542
- types_lib.arrowFunctionExpression([
48543
- types_lib.identifier('config')
48544
- ], types_lib.blockStatement([
48545
- types_lib.variableDeclaration('const', [
48546
- types_lib.variableDeclarator(types_lib.identifier('zephyrConfig'), types_lib.awaitExpression(types_lib.callExpression(types_lib.callExpression(types_lib.identifier('withZephyr'), []), [
48547
- types_lib.identifier('config')
48548
- ])))
48549
- ]),
48550
- types_lib.expressionStatement(types_lib.assignmentExpression('=', types_lib.identifier('config'), types_lib.identifier('zephyrConfig')))
48551
- ]), true)
48552
- ]))
48553
- ]))
48554
- ])))
48555
- ]);
48556
- (0, traverse_lib["default"])(ast, {
48557
- Program (path) {
48558
- let insertIndex = 0;
48559
- for(let i = 0; i < path.node.body.length; i++)if (types_lib.isImportDeclaration(path.node.body[i])) insertIndex = i + 1;
48560
- else break;
48561
- path.node.body.splice(insertIndex, 0, zephyrPluginFunction);
48562
- path.stop();
48563
- }
48564
- });
48565
- let hasRsbuildPluginImport = false;
48566
- (0, traverse_lib["default"])(ast, {
48567
- ImportDeclaration (path) {
48568
- if ('@rsbuild/core' === path.node.source.value) {
48569
- const specifiers = path.node.specifiers;
48570
- for (const spec of specifiers)if (types_lib.isImportSpecifier(spec) && types_lib.isIdentifier(spec.imported, {
48571
- name: 'RsbuildPlugin'
48572
- })) hasRsbuildPluginImport = true;
48573
- if (!hasRsbuildPluginImport) specifiers.push(types_lib.importSpecifier(types_lib.identifier('RsbuildPlugin'), types_lib.identifier('RsbuildPlugin')));
48574
- }
48575
- }
48576
- });
48577
- }
48578
- (0, traverse_lib["default"])(ast, {
48579
- ObjectProperty (path) {
48580
- if (types_lib.isIdentifier(path.node.key, {
48581
- name: 'plugins'
48582
- }) && types_lib.isArrayExpression(path.node.value)) {
48583
- let hasZephyrInPlugins = false;
48584
- for (const element of path.node.value.elements)if (types_lib.isCallExpression(element) && types_lib.isIdentifier(element.callee, {
48585
- name: 'zephyrRSbuildPlugin'
48586
- })) {
48587
- hasZephyrInPlugins = true;
48588
- break;
48589
- }
48590
- if (!hasZephyrInPlugins) path.node.value.elements.push(types_lib.callExpression(types_lib.identifier('zephyrRSbuildPlugin'), []));
48591
- }
48592
- }
48593
- });
48647
+ function addToParcelReporters(filePath, pluginName) {
48648
+ const content = fs_0.readFileSync(filePath, 'utf8');
48649
+ const config = JSON.parse(content);
48650
+ if (!config.reporters) config.reporters = [];
48651
+ if (!config.reporters.includes(pluginName)) config.reporters.push(pluginName);
48652
+ fs_0.writeFileSync(filePath, JSON.stringify(config, null, 2));
48594
48653
  }
48654
+ const src_BUNDLER_CONFIGS = {
48655
+ webpack: webpack_webpackConfig,
48656
+ rspack: rspack_rspackConfig,
48657
+ vite: vite_viteConfig,
48658
+ rollup: rollup_rollupConfig,
48659
+ rolldown: rolldown_rolldownConfig,
48660
+ rsbuild: rsbuild_rsbuildConfig,
48661
+ rslib: rslib_rslibConfig,
48662
+ parcel: parcel_parcelConfig,
48663
+ astro: astro_astroConfig,
48664
+ modernjs: modernjs_modernjsConfig,
48665
+ rspress: rspress_rspressConfig,
48666
+ repack: repack_repackConfig
48667
+ };
48595
48668
  const TRANSFORMERS = {
48596
48669
  addToComposePlugins: addToComposePlugins,
48597
48670
  addToPluginsArray: addToPluginsArray,
48671
+ addToPluginsArrayOrCreate: addToPluginsArrayOrCreate,
48598
48672
  addToVitePlugins: addToVitePlugins,
48599
48673
  addToVitePluginsInFunction: addToVitePluginsInFunction,
48674
+ addToAstroIntegrations: addToAstroIntegrations,
48675
+ addToAstroIntegrationsInFunction: addToAstroIntegrationsInFunction,
48676
+ addToAstroIntegrationsOrCreate: addToAstroIntegrationsOrCreate,
48677
+ addToAstroIntegrationsInFunctionOrCreate: addToAstroIntegrationsInFunctionOrCreate,
48600
48678
  addToRollupFunction: addToRollupFunction,
48601
48679
  addToRollupArrayConfig: addToRollupArrayConfig,
48602
- addToRolldownPlugins: addToRolldownPlugins,
48603
- addToModernJSPlugins: addToModernJSPlugins,
48604
- addToRSPressPlugins: addToRSPressPlugins,
48605
48680
  wrapModuleExports: wrapModuleExports,
48606
48681
  wrapExportDefault: wrapExportDefault,
48607
48682
  skipAlreadyWrapped: skipAlreadyWrapped,
48608
- wrapExportedFunction: wrapExportedFunction,
48609
- addZephyrRSbuildPlugin: addZephyrRSbuildPlugin
48683
+ wrapExportedFunction: wrapExportedFunction
48610
48684
  };
48611
48685
  function normalizePathForOutput(filePath) {
48612
48686
  return filePath.replace(/\\/g, '/');
48613
48687
  }
48614
48688
  function findConfigFiles(directory) {
48615
48689
  const configFiles = [];
48616
- for (const [bundlerName, config] of Object.entries(BUNDLER_CONFIGS))for (const fileName of config.files){
48690
+ for (const [bundlerName, config] of Object.entries(src_BUNDLER_CONFIGS))for (const fileName of config.files){
48617
48691
  const pattern = `${directory}/**/${fileName}`.replace(/\\/g, '/');
48618
48692
  const matches = esm_glob.sync(pattern, {
48619
48693
  ignore: [
@@ -48656,7 +48730,7 @@ function checkHasZephyr(filePath, config) {
48656
48730
  }
48657
48731
  {
48658
48732
  const ast = parseFile(filePath);
48659
- return transformers_hasZephyrPlugin(ast);
48733
+ return hasZephyrPlugin(ast);
48660
48734
  }
48661
48735
  } catch (error) {
48662
48736
  console.warn(source.yellow(`Warning: Could not parse ${normalizePathForOutput(filePath)}: ${error.message}`));
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "version": "1.0.0",
3
- "timestamp": "2025-09-26T21:08:22.949Z",
3
+ "timestamp": "2025-12-01T16:09:14.657Z",
4
4
  "dependencies": {},
5
5
  "zeVars": {}
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "with-zephyr",
3
- "version": "0.0.0-canary.2",
3
+ "version": "0.0.0-canary.20",
4
4
  "description": "A codemod to automatically add withZephyr plugin to bundler configurations",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -38,7 +38,7 @@
38
38
  "@types/node": "^24.5.2",
39
39
  "@rslib/core": "^0.13.3",
40
40
  "typescript": "^5.9.2",
41
- "zephyr-rsbuild-plugin": "0.0.0-canary.2"
41
+ "zephyr-rsbuild-plugin": "0.0.0-canary.20"
42
42
  },
43
43
  "keywords": [
44
44
  "zephyr",
@@ -50,6 +50,7 @@
50
50
  "rspack",
51
51
  "rsbuild",
52
52
  "rslib",
53
+ "astro",
53
54
  "modernjs",
54
55
  "rolldown",
55
56
  "rspress"