1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
diff --git a/packages/tailwindcss-intellisense/src/class-names/index.js b/packages/tailwindcss-intellisense/src/class-names/index.js
index e8034c45269416cd66518340886c3b7394a6de5d..06177bd14f57133c1098bfaabf1064c42dd7af42 100644
--- a/packages/tailwindcss-intellisense/src/class-names/index.js
+++ b/packages/tailwindcss-intellisense/src/class-names/index.js
@@ -16,6 +16,7 @@ import glob from 'fast-glob'
import normalizePath from 'normalize-path'
import { withUserEnvironment } from './environment'
import execa from 'execa'
+import { klona } from 'klona/full'
function arraysEqual(arr1, arr2) {
return (
@@ -71,7 +72,13 @@ let userPurge
let hook = Hook(fs.realpathSync(configPath), (exports) => {
userSeperator = dlv(exports, sepLocation)
userPurge = exports.purge
- dset(exports, sepLocation, '__TAILWIND_SEPARATOR__')
+ dset(
+ exports,
+ sepLocation,
+ `__TWSEP__${
+ typeof userSeperator === 'undefined' ? ':' : userSeperator
+ }__TWSEP__`
+ )
exports.purge = {}
return exports
})
@@ -89,15 +96,17 @@
hook.unwatch()
const {
- base,
- components,
- utilities,
+ postcssResult,
resolvedConfig,
browserslist,
postcss,
} = await withPackages(
- configDir,
- cwd,
+ {
+ configDir,
+ cwd,
+ userSeperator,
+ version,
+ },
async ({
postcss,
tailwindcss,
@@ -106,27 +115,23 @@ browserslistArgs,
}) => {
let postcssResult
try {
- postcssResult = await Promise.all(
+ postcssResult = await postcss([tailwindcss(configPath)]).process(
[
semver.gte(version, '0.99.0') ? 'base' : 'preflight',
'components',
'utilities',
- ].map((group) =>
- postcss([tailwindcss(configPath)]).process(
- `@tailwind ${group};`,
- {
- from: undefined,
- }
- )
- )
+ ]
+ .map((x) => `/*__tw_intellisense_layer_${x}__*/\n@tailwind ${x};`)
+ .join('\n'),
+ {
+ from: undefined,
+ }
)
} catch (error) {
throw error
} finally {
hook.unhook()
}
-
- const [base, components, utilities] = postcssResult
if (typeof userSeperator !== 'undefined') {
dset(config, sepLocation, userSeperator)
@@ -168,9 +173,7 @@ }
}
return {
- base,
- components,
- utilities,
+ postcssResult,
resolvedConfig,
postcss,
browserslist,
@@ -183,11 +186,7 @@ version,
configPath,
config: resolvedConfig,
separator: typeof userSeperator === 'undefined' ? ':' : userSeperator,
- classNames: await extractClassNames([
- { root: base.root, source: 'base' },
- { root: components.root, source: 'components' },
- { root: utilities.root, source: 'utilities' },
- ]),
+ classNames: await extractClassNames(postcssResult.root),
dependencies: hook.deps,
plugins: getPlugins(config),
variants: getVariants({ config, version, postcss, browserslist }),
@@ -262,10 +261,10 @@ return { version, featureFlags, tailwindBase }
})
}
-function withPackages(configDir, root, cb) {
+function withPackages({ configDir, cwd, userSeperator, version }, cb) {
return withUserEnvironment(
configDir,
- root,
+ cwd,
async ({ isPnp, require, resolve }) => {
const tailwindBase = path.dirname(resolve('tailwindcss/package.json'))
const postcss = require('postcss', tailwindBase)
@@ -289,6 +288,55 @@ browserslistCommand = process.execPath
browserslistArgs = [browserslistBin]
}
} catch (_) {}
+
+ if (semver.gte(version, '1.7.0')) {
+ const applyComplexClasses = semver.gte(version, '1.99.0')
+ ? require('./lib/lib/substituteClassApplyAtRules', tailwindBase)
+ : require('./lib/flagged/applyComplexClasses', tailwindBase)
+
+ if (!applyComplexClasses.default.__patched) {
+ let _applyComplexClasses = applyComplexClasses.default
+ applyComplexClasses.default = (config, ...args) => {
+ let configClone = klona(config)
+ configClone.separator =
+ typeof userSeperator === 'undefined' ? ':' : userSeperator
+
+ let fn = _applyComplexClasses(configClone, ...args)
+
+ return async (css) => {
+ css.walkRules((rule) => {
+ const newSelector = rule.selector.replace(
+ /__TWSEP__(.*?)__TWSEP__/g,
+ '$1'
+ )
+ if (newSelector !== rule.selector) {
+ rule.before(
+ postcss.comment({
+ text: '__ORIGINAL_SELECTOR__:' + rule.selector,
+ })
+ )
+ rule.selector = newSelector
+ }
+ })
+
+ await fn(css)
+
+ css.walkComments((comment) => {
+ if (comment.text.startsWith('__ORIGINAL_SELECTOR__:')) {
+ comment.next().selector = comment.text.replace(
+ /^__ORIGINAL_SELECTOR__:/,
+ ''
+ )
+ comment.remove()
+ }
+ })
+
+ return css
+ }
+ }
+ applyComplexClasses.default.__patched = true
+ }
+ }
return cb({ postcss, tailwindcss, browserslistCommand, browserslistArgs })
}
|