@@ -64,7 +64,10 @@ export const codemodCamelToKebab = async ({ cwd }: { cwd: string }) => {
6464 const name = path . basename ( seg , ext )
6565 // skip ALL_CAPS files like README.md, LICENSE, CLAUDE.md
6666 if ( / ^ [ A - Z 0 - 9 _ ] + $ / . test ( name ) ) return seg
67- const kebab = name . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1-$2" ) . toLowerCase ( )
67+ const kebab = name
68+ . replace ( / ( [ A - Z ] + ) ( [ A - Z ] [ a - z ] ) / g, "$1-$2" )
69+ . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1-$2" )
70+ . toLowerCase ( )
6871 return `${ kebab } ${ ext } `
6972 } )
7073 const newRel = transformed . join ( "/" )
@@ -84,7 +87,10 @@ export const codemodCamelToKebab = async ({ cwd }: { cwd: string }) => {
8487 if ( i === 0 && seg . startsWith ( "@" ) ) return seg
8588 // skip ALL_CAPS segments in imports too
8689 if ( / ^ [ A - Z 0 - 9 _ ] + $ / . test ( seg ) ) return seg
87- return seg . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1-$2" ) . toLowerCase ( )
90+ return seg
91+ . replace ( / ( [ A - Z ] + ) ( [ A - Z ] [ a - z ] ) / g, "$1-$2" )
92+ . replace ( / ( [ a - z ] ) ( [ A - Z ] ) / g, "$1-$2" )
93+ . toLowerCase ( )
8894 } )
8995 . join ( "/" )
9096 }
@@ -101,19 +107,31 @@ export const codemodCamelToKebab = async ({ cwd }: { cwd: string }) => {
101107 // a1) update real imports: from "…"
102108 content = content . replace (
103109 / ( f r o m \s + [ ' " ` ] ) ( [ ^ ' " ` ] + ) ( [ ' " ` ] ) / g,
104- ( _full , p1 , p2 , p3 ) => `${ p1 } ${ kebabifyPath ( p2 ) } ${ p3 } ` ,
110+ ( _full , p1 , p2 , p3 ) => {
111+ const newPath = kebabifyPath ( p2 )
112+ if ( p2 !== newPath ) console . log ( ` Fix: ${ p2 } -> ${ newPath } ` )
113+ return `${ p1 } ${ newPath } ${ p3 } `
114+ } ,
105115 )
106116
107117 // a2) update side-effect imports: import "…"
108118 content = content . replace (
109119 / ( i m p o r t \s + [ ' " ` ] ) ( [ ^ ' " ` ] + ) ( [ ' " ` ] ) / g,
110- ( _full , p1 , p2 , p3 ) => `${ p1 } ${ kebabifyPath ( p2 ) } ${ p3 } ` ,
120+ ( _full , p1 , p2 , p3 ) => {
121+ const newPath = kebabifyPath ( p2 )
122+ if ( p2 !== newPath ) console . log ( ` Fix: ${ p2 } -> ${ newPath } ` )
123+ return `${ p1 } ${ newPath } ${ p3 } `
124+ } ,
111125 )
112126
113127 // a3) update dynamic imports & require: import("…"), require("…")
114128 content = content . replace (
115129 / ( (?: i m p o r t | r e q u i r e ) \s * \( \s * [ ' " ` ] ) ( [ ^ ' " ` ] + ) ( [ ' " ` ] \s * \) ) / g,
116- ( _full , p1 , p2 , p3 ) => `${ p1 } ${ kebabifyPath ( p2 ) } ${ p3 } ` ,
130+ ( _full , p1 , p2 , p3 ) => {
131+ const newPath = kebabifyPath ( p2 )
132+ if ( p2 !== newPath ) console . log ( ` Fix: ${ p2 } -> ${ newPath } ` )
133+ return `${ p1 } ${ newPath } ${ p3 } `
134+ } ,
117135 )
118136
119137 // b) update Vitest/Jest mock imports: vi.mock("…"), jest.mock("…")
0 commit comments