@volue/wave-codemod__react 0.3.0 → 0.4.1-next.0

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/CHANGELOG.md CHANGED
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. See [Conven
4
4
 
5
5
  <!-- MONOWEAVE:BELOW -->
6
6
 
7
+ ## [0.4.0](https://github.com/Volue/wave/compare/@volue/wave-codemod__react@0.3.0...@volue/wave-codemod__react@0.4.0) "@volue/wave-codemod__react" (2026-04-29)
8
+
9
+
10
+ ### Features
11
+
12
+ * **codemods:** v1.9 codemod migrates Button color="accent" ([a372981](https://github.com/Volue/wave/commit/a3729818c08a14f1b245a3b2bda566a97de3ca10)), closes [benjamn/recast#171](https://github.com/benjamn/recast/issues/171)
13
+
14
+
15
+
16
+
7
17
  ## [0.3.0](https://github.com/Volue/wave/compare/@volue/wave-codemod__react@0.2.10...@volue/wave-codemod__react@0.3.0) "@volue/wave-codemod__react" (2026-04-28)
8
18
 
9
19
 
package/dist/index.cjs CHANGED
@@ -185,6 +185,58 @@ function transformer$1(file, api, options) {
185
185
  return ast.toSource(options.printOptions);
186
186
  }
187
187
 
188
+ function replaceStringLiteralValue(j, path, newValue) {
189
+ const quote = path.node.extra?.raw?.[0] === '"' ? '"' : "'";
190
+ const replacement = j.literal(newValue);
191
+ replacement.extra = {
192
+ raw: `${quote}${newValue}${quote}`,
193
+ rawValue: newValue
194
+ };
195
+ path.replace(replacement);
196
+ }
197
+
198
+ const isAccentLiteral = (node) => !!node && (node.type === "Literal" || node.type === "StringLiteral") && node.value === "accent";
199
+ function migrateAccentColorOnButton(j, ast) {
200
+ const waveImports = ast.find(j.ImportDeclaration, {
201
+ source: { value: "@volue/wave-react" }
202
+ });
203
+ const buttonImports = waveImports.find(j.ImportSpecifier, {
204
+ imported: { name: "Button" }
205
+ });
206
+ if (buttonImports.size() === 0) {
207
+ return;
208
+ }
209
+ ast.find(j.JSXOpeningElement, {
210
+ name: { type: "JSXIdentifier", name: "Button" }
211
+ }).forEach((buttonPath) => {
212
+ const attributes = buttonPath.node.attributes;
213
+ if (!attributes) {
214
+ return;
215
+ }
216
+ buttonPath.node.attributes = attributes.flatMap((attr) => {
217
+ if (attr.type !== "JSXAttribute" || attr.name.type !== "JSXIdentifier" || attr.name.name !== "color" || !attr.value) {
218
+ return [attr];
219
+ }
220
+ if (isAccentLiteral(attr.value)) {
221
+ return [];
222
+ }
223
+ if (attr.value.type === "JSXExpressionContainer" && isAccentLiteral(attr.value.expression)) {
224
+ return [];
225
+ }
226
+ if (attr.value.type === "JSXExpressionContainer") {
227
+ const container = j(attr.value);
228
+ container.find(j.Literal).filter((path) => isAccentLiteral(path.node)).forEach((path) => {
229
+ replaceStringLiteralValue(j, path, "default");
230
+ });
231
+ container.find(j.StringLiteral).filter((path) => isAccentLiteral(path.node)).forEach((path) => {
232
+ replaceStringLiteralValue(j, path, "default");
233
+ });
234
+ }
235
+ return [attr];
236
+ });
237
+ });
238
+ }
239
+
188
240
  function renameLogoInSidebarHeader(j, ast) {
189
241
  const waveImports = ast.find(j.ImportDeclaration, {
190
242
  source: { value: "@volue/wave-react" }
@@ -262,7 +314,7 @@ function transformer(file, api, options) {
262
314
  if (!utils.hasImportDeclaration(j, ast, "@volue/wave-react")) {
263
315
  return file.source;
264
316
  }
265
- utils.applyMotions(j, ast, [renameLogoInSidebarHeader]);
317
+ utils.applyMotions(j, ast, [renameLogoInSidebarHeader, migrateAccentColorOnButton]);
266
318
  return ast.toSource(options.printOptions);
267
319
  }
268
320
 
package/dist/index.mjs CHANGED
@@ -183,6 +183,58 @@ function transformer$1(file, api, options) {
183
183
  return ast.toSource(options.printOptions);
184
184
  }
185
185
 
186
+ function replaceStringLiteralValue(j, path, newValue) {
187
+ const quote = path.node.extra?.raw?.[0] === '"' ? '"' : "'";
188
+ const replacement = j.literal(newValue);
189
+ replacement.extra = {
190
+ raw: `${quote}${newValue}${quote}`,
191
+ rawValue: newValue
192
+ };
193
+ path.replace(replacement);
194
+ }
195
+
196
+ const isAccentLiteral = (node) => !!node && (node.type === "Literal" || node.type === "StringLiteral") && node.value === "accent";
197
+ function migrateAccentColorOnButton(j, ast) {
198
+ const waveImports = ast.find(j.ImportDeclaration, {
199
+ source: { value: "@volue/wave-react" }
200
+ });
201
+ const buttonImports = waveImports.find(j.ImportSpecifier, {
202
+ imported: { name: "Button" }
203
+ });
204
+ if (buttonImports.size() === 0) {
205
+ return;
206
+ }
207
+ ast.find(j.JSXOpeningElement, {
208
+ name: { type: "JSXIdentifier", name: "Button" }
209
+ }).forEach((buttonPath) => {
210
+ const attributes = buttonPath.node.attributes;
211
+ if (!attributes) {
212
+ return;
213
+ }
214
+ buttonPath.node.attributes = attributes.flatMap((attr) => {
215
+ if (attr.type !== "JSXAttribute" || attr.name.type !== "JSXIdentifier" || attr.name.name !== "color" || !attr.value) {
216
+ return [attr];
217
+ }
218
+ if (isAccentLiteral(attr.value)) {
219
+ return [];
220
+ }
221
+ if (attr.value.type === "JSXExpressionContainer" && isAccentLiteral(attr.value.expression)) {
222
+ return [];
223
+ }
224
+ if (attr.value.type === "JSXExpressionContainer") {
225
+ const container = j(attr.value);
226
+ container.find(j.Literal).filter((path) => isAccentLiteral(path.node)).forEach((path) => {
227
+ replaceStringLiteralValue(j, path, "default");
228
+ });
229
+ container.find(j.StringLiteral).filter((path) => isAccentLiteral(path.node)).forEach((path) => {
230
+ replaceStringLiteralValue(j, path, "default");
231
+ });
232
+ }
233
+ return [attr];
234
+ });
235
+ });
236
+ }
237
+
186
238
  function renameLogoInSidebarHeader(j, ast) {
187
239
  const waveImports = ast.find(j.ImportDeclaration, {
188
240
  source: { value: "@volue/wave-react" }
@@ -260,7 +312,7 @@ function transformer(file, api, options) {
260
312
  if (!hasImportDeclaration(j, ast, "@volue/wave-react")) {
261
313
  return file.source;
262
314
  }
263
- applyMotions(j, ast, [renameLogoInSidebarHeader]);
315
+ applyMotions(j, ast, [renameLogoInSidebarHeader, migrateAccentColorOnButton]);
264
316
  return ast.toSource(options.printOptions);
265
317
  }
266
318
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volue/wave-codemod__react",
3
- "version": "0.3.0",
3
+ "version": "0.4.1-next.0",
4
4
  "description": "Codemods for Wave React library",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -51,7 +51,7 @@
51
51
  "@types/jest": "30.0.0",
52
52
  "@volue/eslint-config": "1.3.12",
53
53
  "eslint": "9.39.4",
54
- "jest": "30.3.0",
54
+ "jest": "30.4.1",
55
55
  "npm-run-all2": "8.0.4",
56
56
  "pkgroll": "2.27.0",
57
57
  "premove": "4.0.0",