1
+ import path from 'node:path'
1
2
import { isRepoDirty } from '../../packages/@tailwindcss-upgrade/src/utils/git'
2
- import { candidate , css , html , js , json , test , ts } from '../utils'
3
+ import { candidate , css , html , js , json , test , ts , yaml } from '../utils'
3
4
4
5
test (
5
6
'error when no CSS file with @tailwind is used' ,
@@ -2967,6 +2968,155 @@ test(
2967
2968
} ,
2968
2969
)
2969
2970
2971
+ test (
2972
+ 'upgrades can run in a pnpm workspace' ,
2973
+ {
2974
+ fs : {
2975
+ 'package.json' : json `{}` ,
2976
+ 'pnpm-workspace.yaml' : yaml `
2977
+ #
2978
+ packages :
2979
+ - project- a
2980
+ ` ,
2981
+ 'project-a/package.json' : json `
2982
+ {
2983
+ "dependencies" : {
2984
+ "tailwindcss" : "^4"
2985
+ },
2986
+ "devDependencies" : {
2987
+ "@tailwindcss/upgrade" : "workspace:^"
2988
+ }
2989
+ }
2990
+ ` ,
2991
+ 'project-a/src/index.html' : html `
2992
+ <!- - Migrating 'ring' , 'rounded' and 'outline-none' are unsafe in v4 - > v4 migrations -- >
2993
+ <div class= "ring rounded outline" > </ div>
2994
+
2995
+ <!- - Variant or der is also unsafe to change in v4 projects - - >
2996
+ <div class= "file:hover:flex *:hover:flex" > </ div>
2997
+ <div class= "hover:file:flex hover:*:flex" > </ div>
2998
+
2999
+ <!- - These are safe to migrate: - - >
3000
+ <div
3001
+ class= "!flex bg-red-500/[var(--my-opacity)] [@media(pointer:fine)]:flex bg-right-bottom object-left-top"
3002
+ > </ div>
3003
+ ` ,
3004
+ 'project-a/src/input.css' : css `
3005
+ @import 'tailwindcss' ;
3006
+
3007
+ .foo {
3008
+ @apply !bg- [var (- - my- color )];
3009
+ }
3010
+ ` ,
3011
+ } ,
3012
+ } ,
3013
+ async ( { root, exec, fs, expect } ) => {
3014
+ let stdout = await exec ( 'npx @tailwindcss/upgrade' , {
3015
+ cwd : path . join ( root , 'project-a' ) ,
3016
+ } )
3017
+
3018
+ expect ( / P a t h .* ? i s n o t i n c w d / . test ( stdout ) ) . toBe ( false )
3019
+
3020
+ expect ( await fs . dumpFiles ( './project-a/src/**/*.{css,html}' ) ) . toMatchInlineSnapshot ( `
3021
+ "
3022
+ --- ./project-a/src/index.html ---
3023
+ <!-- Migrating 'ring', 'rounded' and 'outline-none' are unsafe in v4 -> v4 migrations -->
3024
+ <div class="ring rounded outline"></div>
3025
+
3026
+ <!-- Variant order is also unsafe to change in v4 projects -->
3027
+ <div class="file:hover:flex *:hover:flex"></div>
3028
+ <div class="hover:file:flex hover:*:flex"></div>
3029
+
3030
+ <!-- These are safe to migrate: -->
3031
+ <div
3032
+ class="flex! bg-red-500/(--my-opacity) pointer-fine:flex bg-bottom-right object-top-left"
3033
+ ></div>
3034
+
3035
+ --- ./project-a/src/input.css ---
3036
+ @import 'tailwindcss';
3037
+
3038
+ .foo {
3039
+ @apply bg-(--my-color)!;
3040
+ }
3041
+ "
3042
+ ` )
3043
+ } ,
3044
+ )
3045
+
3046
+ test (
3047
+ 'upgrades can run in a pnpm workspace root' ,
3048
+ {
3049
+ fs : {
3050
+ 'pnpm-workspace.yaml' : yaml `
3051
+ #
3052
+ packages :
3053
+ - .
3054
+ ` ,
3055
+ 'package.json' : json `
3056
+ {
3057
+ "dependencies" : {
3058
+ "tailwindcss" : "^4"
3059
+ },
3060
+ "devDependencies" : {
3061
+ "@tailwindcss/upgrade" : "workspace:^"
3062
+ }
3063
+ }
3064
+ ` ,
3065
+ 'src/index.html' : html `
3066
+ <!- - Migrating 'ring' , 'rounded' and 'outline-none' are unsafe in v4 - > v4 migrations -- >
3067
+ <div class= "ring rounded outline" > </ div>
3068
+
3069
+ <!- - Variant or der is also unsafe to change in v4 projects - - >
3070
+ <div class= "file:hover:flex *:hover:flex" > </ div>
3071
+ <div class= "hover:file:flex hover:*:flex" > </ div>
3072
+
3073
+ <!- - These are safe to migrate: - - >
3074
+ <div
3075
+ class= "!flex bg-red-500/[var(--my-opacity)] [@media(pointer:fine)]:flex bg-right-bottom object-left-top"
3076
+ > </ div>
3077
+ ` ,
3078
+ 'src/input.css' : css `
3079
+ @import 'tailwindcss' ;
3080
+
3081
+ .foo {
3082
+ @apply !bg- [var (- - my- color )];
3083
+ }
3084
+ ` ,
3085
+ } ,
3086
+ } ,
3087
+ async ( { exec, fs, expect } ) => {
3088
+ let stdout = await exec ( 'npx @tailwindcss/upgrade' )
3089
+
3090
+ expect ( stdout ) . not . toContain (
3091
+ 'Running this command will add the dependency to the workspace root' ,
3092
+ )
3093
+
3094
+ expect ( await fs . dumpFiles ( './src/**/*.{css,html}' ) ) . toMatchInlineSnapshot ( `
3095
+ "
3096
+ --- ./src/index.html ---
3097
+ <!-- Migrating 'ring', 'rounded' and 'outline-none' are unsafe in v4 -> v4 migrations -->
3098
+ <div class="ring rounded outline"></div>
3099
+
3100
+ <!-- Variant order is also unsafe to change in v4 projects -->
3101
+ <div class="file:hover:flex *:hover:flex"></div>
3102
+ <div class="hover:file:flex hover:*:flex"></div>
3103
+
3104
+ <!-- These are safe to migrate: -->
3105
+ <div
3106
+ class="flex! bg-red-500/(--my-opacity) pointer-fine:flex bg-bottom-right object-top-left"
3107
+ ></div>
3108
+
3109
+ --- ./src/input.css ---
3110
+ @import 'tailwindcss';
3111
+
3112
+ .foo {
3113
+ @apply bg-(--my-color)!;
3114
+ }
3115
+ "
3116
+ ` )
3117
+ } ,
3118
+ )
3119
+
2970
3120
test (
2971
3121
'upgrade <style> blocks carefully' ,
2972
3122
{
@@ -2980,21 +3130,21 @@ test(
2980
3130
}
2981
3131
` ,
2982
3132
'src/index.vue' : html `
2983
- <template
3133
+ <template>
2984
3134
<div class= "!flex" > </ div>
2985
3135
</ template>
2986
3136
2987
3137
<style>
2988
- @reference "./input.css" ;
3138
+ @reference "./input.css" ;
2989
3139
2990
- .foo {
2991
- @apply !bg- red-500 ;
2992
- }
3140
+ .foo {
3141
+ @apply !bg- red-500 ;
3142
+ }
2993
3143
2994
- .bar {
2995
- /* Do not upgrade the key: */
2996
- flex-shrink : 0 ;
2997
- }
3144
+ .bar {
3145
+ /* Do not upgrade the key: */
3146
+ flex-shrink : 0 ;
3147
+ }
2998
3148
</ style>
2999
3149
` ,
3000
3150
'src/input.css' : css `
@@ -3016,21 +3166,21 @@ test(
3016
3166
expect ( await fs . dumpFiles ( './src/**/*.{css,vue}' ) ) . toMatchInlineSnapshot ( `
3017
3167
"
3018
3168
--- ./src/index.vue ---
3019
- <template
3169
+ <template>
3020
3170
<div class="flex!"></div>
3021
3171
</template>
3022
3172
3023
3173
<style>
3024
- @reference "./input.css";
3174
+ @reference "./input.css";
3025
3175
3026
- .foo {
3027
- @apply !bg-red-500;
3028
- }
3176
+ .foo {
3177
+ @apply !bg-red-500;
3178
+ }
3029
3179
3030
- .bar {
3031
- /* Do not upgrade the key: */
3032
- flex-shrink: 0;
3033
- }
3180
+ .bar {
3181
+ /* Do not upgrade the key: */
3182
+ flex-shrink: 0;
3183
+ }
3034
3184
</style>
3035
3185
3036
3186
--- ./src/input.css ---
0 commit comments