@@ -2,10 +2,11 @@ import type { UserConfig } from '../config'
2
2
import type { CacheStrategy , InternalCacheOptions , InternalPatchOptions , PackageInfo , TailwindcssClassCache , TailwindcssPatcherOptions , TailwindcssRuntimeContext } from '../types'
3
3
import { createRequire } from 'node:module'
4
4
import fs from 'fs-extra'
5
+ import { getPackageInfoSync } from 'local-pkg'
5
6
import path from 'pathe'
6
7
import { getPatchOptions } from '../defaults'
7
8
import logger from '../logger'
8
- import { getPackageInfoSync , isObject } from '../utils'
9
+ import { isObject } from '../utils'
9
10
import { CacheManager , getCacheOptions } from './cache'
10
11
import { processTailwindcss } from './postcss'
11
12
import { internalPatch } from './runtime'
@@ -17,7 +18,7 @@ export class TailwindcssPatcher {
17
18
public patchOptions : InternalPatchOptions
18
19
public patch : ( ) => void
19
20
public cacheManager : CacheManager
20
- public packageInfo ? : PackageInfo
21
+ public packageInfo : PackageInfo
21
22
public majorVersion ?: number
22
23
23
24
constructor ( options : TailwindcssPatcherOptions = { } ) {
@@ -26,10 +27,17 @@ export class TailwindcssPatcher {
26
27
this . patchOptions = getPatchOptions ( options . patch )
27
28
28
29
this . cacheManager = new CacheManager ( this . cacheOptions )
29
- this . packageInfo = getPackageInfoSync ( 'tailwindcss' , { basedir : this . patchOptions . basedir } )
30
- if ( this . packageInfo && this . packageInfo . version ) {
31
- this . majorVersion = Number . parseInt ( this . packageInfo . version [ 0 ] )
30
+
31
+ const packageInfo = getPackageInfoSync ( 'tailwindcss' )
32
+
33
+ if ( ! packageInfo ) {
34
+ throw new Error ( 'tailwindcss not found' )
32
35
}
36
+
37
+ if ( packageInfo . version ) {
38
+ this . majorVersion = Number . parseInt ( packageInfo . version [ 0 ] )
39
+ }
40
+ this . packageInfo = packageInfo
33
41
this . patch = ( ) => {
34
42
try {
35
43
return internalPatch ( this . packageInfo ?. packageJsonPath , this . patchOptions )
@@ -57,7 +65,7 @@ export class TailwindcssPatcher {
57
65
if ( this . majorVersion === 2 ) {
58
66
injectFilePath = path . join ( distPath , 'jit/index.js' )
59
67
}
60
- else {
68
+ else if ( this . majorVersion === 3 ) {
61
69
injectFilePath = path . join ( distPath , 'plugin.js' )
62
70
if ( ! fs . existsSync ( injectFilePath ) ) {
63
71
injectFilePath = path . join ( distPath , 'index.js' )
@@ -124,7 +132,10 @@ export class TailwindcssPatcher {
124
132
if ( output && tailwindcss ) {
125
133
const { removeUniversalSelector, filename, loose } = output
126
134
127
- await processTailwindcss ( tailwindcss )
135
+ await processTailwindcss ( {
136
+ ...tailwindcss ,
137
+ majorVersion : this . majorVersion ,
138
+ } )
128
139
129
140
const set = this . getClassSet ( {
130
141
removeUniversalSelector,
0 commit comments