tailwindcss 0.0.0-insiders.eebf529 → 0.0.0-insiders.ef2ebb2
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/LICENSE +1 -2
- package/README.md +15 -7
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- package/index.css +5 -0
- package/lib/cli/build/index.js +57 -0
- package/lib/cli/build/plugin.js +433 -0
- package/lib/cli/build/utils.js +88 -0
- package/lib/cli/build/watching.js +182 -0
- package/lib/cli/help/index.js +73 -0
- package/lib/cli/index.js +231 -0
- package/lib/cli/init/index.js +63 -0
- package/lib/cli.js +1 -704
- package/lib/corePluginList.js +13 -3
- package/lib/corePlugins.js +2399 -1867
- package/lib/css/preflight.css +17 -9
- package/lib/featureFlags.js +50 -26
- package/lib/index.js +1 -31
- package/lib/lib/cacheInvalidation.js +92 -0
- package/lib/lib/collapseAdjacentRules.js +30 -10
- package/lib/lib/collapseDuplicateDeclarations.js +60 -4
- package/lib/lib/content.js +207 -0
- package/lib/lib/defaultExtractor.js +243 -0
- package/lib/lib/detectNesting.js +21 -10
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +467 -161
- package/lib/lib/expandTailwindAtRules.js +200 -133
- package/lib/lib/findAtConfigPath.js +46 -0
- package/lib/lib/generateRules.js +550 -200
- package/lib/lib/getModuleDependencies.js +88 -37
- package/lib/lib/handleImportAtRules.js +50 -0
- package/lib/lib/load-config.js +42 -0
- package/lib/lib/normalizeTailwindDirectives.js +36 -38
- package/lib/lib/offsets.js +306 -0
- package/lib/lib/partitionApplyAtRules.js +58 -0
- package/lib/lib/regex.js +74 -0
- package/lib/lib/remap-bitfield.js +89 -0
- package/lib/lib/resolveDefaultsAtRules.js +98 -58
- package/lib/lib/setupContextUtils.js +767 -325
- package/lib/lib/setupTrackingContext.js +71 -75
- package/lib/lib/sharedState.js +70 -10
- package/lib/lib/substituteScreenAtRules.js +14 -10
- package/lib/plugin.js +166 -0
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +21 -0
- package/lib/postcss-plugins/nesting/plugin.js +89 -0
- package/lib/processTailwindFeatures.js +39 -26
- package/lib/public/colors.js +272 -246
- package/lib/public/create-plugin.js +9 -5
- package/lib/public/default-config.js +10 -6
- package/lib/public/default-theme.js +10 -6
- package/lib/public/load-config.js +12 -0
- package/lib/public/resolve-config.js +11 -6
- package/lib/util/applyImportantSelector.js +36 -0
- package/lib/util/bigSign.js +6 -1
- package/lib/util/buildMediaQuery.js +13 -6
- package/lib/util/cloneDeep.js +9 -6
- package/lib/util/cloneNodes.js +23 -3
- package/lib/util/color.js +70 -38
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +7 -2
- package/lib/util/createPlugin.js +8 -6
- package/lib/util/createUtilityPlugin.js +16 -16
- package/lib/util/dataTypes.js +182 -111
- package/lib/util/defaults.js +14 -3
- package/lib/util/escapeClassName.js +13 -8
- package/lib/util/escapeCommas.js +7 -2
- package/lib/util/flattenColorPalette.js +11 -12
- package/lib/util/formatVariantSelector.js +228 -151
- package/lib/util/getAllConfigs.js +33 -12
- package/lib/util/hashConfig.js +9 -4
- package/lib/util/isKeyframeRule.js +7 -2
- package/lib/util/isPlainObject.js +7 -2
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +25 -15
- package/lib/util/log.js +44 -13
- package/lib/util/nameClass.js +27 -10
- package/lib/util/negateValue.js +25 -8
- package/lib/util/normalizeConfig.js +167 -67
- package/lib/util/normalizeScreens.js +128 -11
- package/lib/util/parseAnimationValue.js +44 -40
- package/lib/util/parseBoxShadowValue.js +34 -23
- package/lib/util/parseDependency.js +39 -55
- package/lib/util/parseGlob.js +36 -0
- package/lib/util/parseObjectStyles.js +15 -10
- package/lib/util/pluginUtils.js +157 -69
- package/lib/util/prefixSelector.js +30 -12
- package/lib/util/pseudoElements.js +209 -0
- package/lib/util/removeAlphaVariables.js +31 -0
- package/lib/util/resolveConfig.js +101 -79
- package/lib/util/resolveConfigPath.js +30 -12
- package/lib/util/responsive.js +11 -6
- package/lib/util/splitAtTopLevelOnly.js +51 -0
- package/lib/util/tap.js +6 -1
- package/lib/util/toColorValue.js +7 -3
- package/lib/util/toPath.js +26 -3
- package/lib/util/transformThemeValue.js +40 -30
- package/lib/util/validateConfig.js +48 -0
- package/lib/util/validateFormalSyntax.js +26 -0
- package/lib/util/withAlphaVariable.js +27 -15
- package/lib/value-parser/LICENSE +22 -0
- package/lib/value-parser/README.md +3 -0
- package/lib/value-parser/index.d.js +2 -0
- package/lib/value-parser/index.js +22 -0
- package/lib/value-parser/parse.js +259 -0
- package/lib/value-parser/stringify.js +38 -0
- package/lib/value-parser/unit.js +86 -0
- package/lib/value-parser/walk.js +16 -0
- package/loadConfig.d.ts +4 -0
- package/loadConfig.js +2 -0
- package/nesting/index.js +2 -12
- package/package.json +63 -62
- package/plugin.d.ts +11 -0
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +105 -0
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/scripts/type-utils.js +27 -0
- package/src/cli/build/index.js +53 -0
- package/src/cli/build/plugin.js +476 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +229 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +217 -0
- package/src/cli/init/index.js +79 -0
- package/src/cli.js +1 -766
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +800 -296
- package/src/css/preflight.css +17 -9
- package/src/featureFlags.js +20 -6
- package/src/index.js +1 -34
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +66 -1
- package/src/lib/content.js +240 -0
- package/src/lib/defaultExtractor.js +217 -0
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +83 -9
- package/src/lib/expandApplyAtRules.js +515 -153
- package/src/lib/expandTailwindAtRules.js +147 -86
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +541 -147
- package/src/lib/getModuleDependencies.js +70 -30
- package/src/lib/handleImportAtRules.js +34 -0
- package/src/lib/load-config.ts +31 -0
- package/src/lib/normalizeTailwindDirectives.js +5 -26
- package/src/lib/offsets.js +373 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +59 -17
- package/src/lib/setupContextUtils.js +693 -176
- package/src/lib/setupTrackingContext.js +52 -65
- package/src/lib/sharedState.js +54 -7
- package/src/plugin.js +141 -0
- package/src/postcss-plugins/nesting/README.md +42 -0
- package/src/postcss-plugins/nesting/index.js +13 -0
- package/src/postcss-plugins/nesting/plugin.js +80 -0
- package/src/processTailwindFeatures.js +12 -2
- package/src/public/colors.js +22 -0
- package/src/public/default-config.js +1 -1
- package/src/public/default-theme.js +2 -2
- package/src/public/load-config.js +2 -0
- package/src/util/applyImportantSelector.js +27 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +44 -12
- package/src/util/colorNames.js +150 -0
- package/src/util/dataTypes.js +67 -23
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +264 -144
- package/src/util/getAllConfigs.js +21 -2
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +35 -7
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +86 -7
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +4 -3
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +118 -23
- package/src/util/prefixSelector.js +30 -10
- package/src/util/pseudoElements.js +167 -0
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +74 -26
- package/src/util/resolveConfigPath.js +12 -1
- package/src/util/splitAtTopLevelOnly.js +52 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +13 -3
- package/src/util/validateConfig.js +36 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +1 -1
- package/src/value-parser/LICENSE +22 -0
- package/src/value-parser/README.md +3 -0
- package/src/value-parser/index.d.ts +177 -0
- package/src/value-parser/index.js +28 -0
- package/src/value-parser/parse.js +303 -0
- package/src/value-parser/stringify.js +41 -0
- package/src/value-parser/unit.js +118 -0
- package/src/value-parser/walk.js +18 -0
- package/stubs/.gitignore +1 -0
- package/stubs/.prettierrc.json +6 -0
- package/stubs/{defaultConfig.stub.js → config.full.js} +220 -167
- package/stubs/{simpleConfig.stub.js → config.simple.js} +1 -1
- package/stubs/{defaultPostCssConfig.stub.js → postcss.config.cjs} +0 -1
- package/stubs/postcss.config.js +5 -0
- package/stubs/tailwind.config.cjs +2 -0
- package/stubs/tailwind.config.js +2 -0
- package/stubs/tailwind.config.ts +3 -0
- package/types/config.d.ts +369 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +298 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +372 -0
- package/types/index.d.ts +7 -0
- package/CHANGELOG.md +0 -1853
- package/lib/cli-peer-dependencies.js +0 -15
- package/lib/constants.js +0 -37
- package/lib/lib/setupWatchingContext.js +0 -288
- package/nesting/plugin.js +0 -41
- package/peers/index.js +0 -76107
- package/scripts/install-integrations.js +0 -27
- package/scripts/rebuildFixtures.js +0 -68
- package/src/cli-peer-dependencies.js +0 -9
- package/src/constants.js +0 -17
- package/src/lib/setupWatchingContext.js +0 -311
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import path from 'path'
|
|
1
|
+
// @ts-check
|
|
3
2
|
|
|
4
|
-
import
|
|
5
|
-
import LRU from 'quick-lru'
|
|
6
|
-
import normalizePath from 'normalize-path'
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import LRU from '@alloc/quick-lru'
|
|
7
5
|
|
|
8
6
|
import hash from '../util/hashConfig'
|
|
9
|
-
import getModuleDependencies from '../lib/getModuleDependencies'
|
|
10
|
-
|
|
11
7
|
import resolveConfig from '../public/resolve-config'
|
|
12
|
-
|
|
13
8
|
import resolveConfigPath from '../util/resolveConfigPath'
|
|
14
|
-
|
|
15
|
-
import { env } from './sharedState'
|
|
16
|
-
|
|
17
9
|
import { getContext, getFileModifiedMap } from './setupContextUtils'
|
|
18
10
|
import parseDependency from '../util/parseDependency'
|
|
11
|
+
import { validateConfig } from '../util/validateConfig.js'
|
|
12
|
+
import { parseCandidateFiles, resolvedChangedContent } from './content.js'
|
|
13
|
+
import { loadConfig } from '../lib/load-config'
|
|
14
|
+
import getModuleDependencies from './getModuleDependencies'
|
|
19
15
|
|
|
20
16
|
let configPathCache = new LRU({ maxSize: 100 })
|
|
21
17
|
|
|
@@ -26,9 +22,7 @@ function getCandidateFiles(context, tailwindConfig) {
|
|
|
26
22
|
return candidateFilesCache.get(context)
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
let candidateFiles = tailwindConfig
|
|
30
|
-
.filter((item) => typeof item === 'string')
|
|
31
|
-
.map((contentPath) => normalizePath(contentPath))
|
|
25
|
+
let candidateFiles = parseCandidateFiles(context, tailwindConfig)
|
|
32
26
|
|
|
33
27
|
return candidateFilesCache.set(context, candidateFiles).get(context)
|
|
34
28
|
}
|
|
@@ -41,7 +35,7 @@ function getTailwindConfig(configOrPath) {
|
|
|
41
35
|
let [prevConfig, prevConfigHash, prevDeps, prevModified] =
|
|
42
36
|
configPathCache.get(userConfigPath) || []
|
|
43
37
|
|
|
44
|
-
let newDeps = getModuleDependencies(userConfigPath)
|
|
38
|
+
let newDeps = getModuleDependencies(userConfigPath)
|
|
45
39
|
|
|
46
40
|
let modified = false
|
|
47
41
|
let newModified = new Map()
|
|
@@ -62,48 +56,18 @@ function getTailwindConfig(configOrPath) {
|
|
|
62
56
|
for (let file of newDeps) {
|
|
63
57
|
delete require.cache[file]
|
|
64
58
|
}
|
|
65
|
-
let newConfig = resolveConfig(
|
|
59
|
+
let newConfig = validateConfig(resolveConfig(loadConfig(userConfigPath)))
|
|
66
60
|
let newHash = hash(newConfig)
|
|
67
61
|
configPathCache.set(userConfigPath, [newConfig, newHash, newDeps, newModified])
|
|
68
62
|
return [newConfig, userConfigPath, newHash, newDeps]
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
// It's a plain object, not a path
|
|
72
|
-
let newConfig = resolveConfig(
|
|
73
|
-
configOrPath.config === undefined ? configOrPath : configOrPath.config
|
|
74
|
-
)
|
|
66
|
+
let newConfig = resolveConfig(configOrPath?.config ?? configOrPath ?? {})
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
|
|
80
|
-
let changedContent = context.tailwindConfig.content.files
|
|
81
|
-
.filter((item) => typeof item.raw === 'string')
|
|
82
|
-
.map(({ raw, extension = 'html' }) => ({ content: raw, extension }))
|
|
83
|
-
|
|
84
|
-
for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)) {
|
|
85
|
-
let content = fs.readFileSync(changedFile, 'utf8')
|
|
86
|
-
let extension = path.extname(changedFile).slice(1)
|
|
87
|
-
changedContent.push({ content, extension })
|
|
88
|
-
}
|
|
89
|
-
return changedContent
|
|
90
|
-
}
|
|
68
|
+
newConfig = validateConfig(newConfig)
|
|
91
69
|
|
|
92
|
-
|
|
93
|
-
let changedFiles = new Set()
|
|
94
|
-
env.DEBUG && console.time('Finding changed files')
|
|
95
|
-
let files = fastGlob.sync(candidateFiles)
|
|
96
|
-
for (let file of files) {
|
|
97
|
-
let prevModified = fileModifiedMap.has(file) ? fileModifiedMap.get(file) : -Infinity
|
|
98
|
-
let modified = fs.statSync(file).mtimeMs
|
|
99
|
-
|
|
100
|
-
if (modified > prevModified) {
|
|
101
|
-
changedFiles.add(file)
|
|
102
|
-
fileModifiedMap.set(file, modified)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
env.DEBUG && console.timeEnd('Finding changed files')
|
|
106
|
-
return changedFiles
|
|
70
|
+
return [newConfig, null, hash(newConfig), []]
|
|
107
71
|
}
|
|
108
72
|
|
|
109
73
|
// DISABLE_TOUCH = TRUE
|
|
@@ -119,11 +83,12 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
119
83
|
|
|
120
84
|
let contextDependencies = new Set(configDependencies)
|
|
121
85
|
|
|
122
|
-
// If there are no @tailwind rules, we don't consider this CSS
|
|
123
|
-
// to be dependencies of the context. Can reuse
|
|
124
|
-
// We may want to think about `@layer`
|
|
125
|
-
//
|
|
126
|
-
// in
|
|
86
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS
|
|
87
|
+
// file or its dependencies to be dependencies of the context. Can reuse
|
|
88
|
+
// the context even if they change. We may want to think about `@layer`
|
|
89
|
+
// being part of this trigger too, but it's tough because it's impossible
|
|
90
|
+
// for a layer in one file to end up in the actual @tailwind rule in
|
|
91
|
+
// another file since independent sources are effectively isolated.
|
|
127
92
|
if (tailwindDirectives.size > 0) {
|
|
128
93
|
// Add current css file as a context dependencies.
|
|
129
94
|
contextDependencies.add(result.opts.from)
|
|
@@ -136,7 +101,7 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
136
101
|
}
|
|
137
102
|
}
|
|
138
103
|
|
|
139
|
-
let [context] = getContext(
|
|
104
|
+
let [context, , mTimesToCommit] = getContext(
|
|
140
105
|
root,
|
|
141
106
|
result,
|
|
142
107
|
tailwindConfig,
|
|
@@ -145,30 +110,45 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
145
110
|
contextDependencies
|
|
146
111
|
)
|
|
147
112
|
|
|
113
|
+
let fileModifiedMap = getFileModifiedMap(context)
|
|
114
|
+
|
|
148
115
|
let candidateFiles = getCandidateFiles(context, tailwindConfig)
|
|
149
116
|
|
|
150
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's
|
|
151
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
117
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
|
|
118
|
+
// dependencies to be dependencies of the context. Can reuse the context even if they change.
|
|
152
119
|
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
153
120
|
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
154
121
|
// in another file since independent sources are effectively isolated.
|
|
155
122
|
if (tailwindDirectives.size > 0) {
|
|
156
|
-
let fileModifiedMap = getFileModifiedMap(context)
|
|
157
|
-
|
|
158
123
|
// Add template paths as postcss dependencies.
|
|
159
|
-
for (let
|
|
160
|
-
let dependency
|
|
161
|
-
if (dependency) {
|
|
124
|
+
for (let contentPath of candidateFiles) {
|
|
125
|
+
for (let dependency of parseDependency(contentPath)) {
|
|
162
126
|
registerDependency(dependency)
|
|
163
127
|
}
|
|
164
128
|
}
|
|
165
129
|
|
|
166
|
-
|
|
130
|
+
let [changedContent, contentMTimesToCommit] = resolvedChangedContent(
|
|
167
131
|
context,
|
|
168
132
|
candidateFiles,
|
|
169
133
|
fileModifiedMap
|
|
170
|
-
)
|
|
171
|
-
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
for (let content of changedContent) {
|
|
137
|
+
context.changedContent.push(content)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Add the mtimes of the content files to the commit list
|
|
141
|
+
// We can overwrite the existing values because unconditionally
|
|
142
|
+
// This is because:
|
|
143
|
+
// 1. Most of the files here won't be in the map yet
|
|
144
|
+
// 2. If they are that means it's a context dependency
|
|
145
|
+
// and we're reading this after the context. This means
|
|
146
|
+
// that the mtime we just read is strictly >= the context
|
|
147
|
+
// mtime. Unless the user / os is doing something weird
|
|
148
|
+
// in which the mtime would be going backwards. If that
|
|
149
|
+
// happens there's already going to be problems.
|
|
150
|
+
for (let [path, mtime] of contentMTimesToCommit.entries()) {
|
|
151
|
+
mTimesToCommit.set(path, mtime)
|
|
172
152
|
}
|
|
173
153
|
}
|
|
174
154
|
|
|
@@ -176,6 +156,13 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
176
156
|
registerDependency({ type: 'dependency', file })
|
|
177
157
|
}
|
|
178
158
|
|
|
159
|
+
// "commit" the new modified time for all context deps
|
|
160
|
+
// We do this here because we want content tracking to
|
|
161
|
+
// read the "old" mtime even when it's a context dependency.
|
|
162
|
+
for (let [path, mtime] of mTimesToCommit.entries()) {
|
|
163
|
+
fileModifiedMap.set(path, mtime)
|
|
164
|
+
}
|
|
165
|
+
|
|
179
166
|
return context
|
|
180
167
|
}
|
|
181
168
|
}
|
package/src/lib/sharedState.js
CHANGED
|
@@ -1,10 +1,57 @@
|
|
|
1
|
-
export const env =
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export const env =
|
|
2
|
+
typeof process !== 'undefined'
|
|
3
|
+
? {
|
|
4
|
+
NODE_ENV: process.env.NODE_ENV,
|
|
5
|
+
DEBUG: resolveDebug(process.env.DEBUG),
|
|
6
|
+
}
|
|
7
|
+
: {
|
|
8
|
+
NODE_ENV: 'production',
|
|
9
|
+
DEBUG: false,
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export const contextMap = new Map()
|
|
9
13
|
export const configContextMap = new Map()
|
|
10
14
|
export const contextSourcesMap = new Map()
|
|
15
|
+
export const sourceHashMap = new Map()
|
|
16
|
+
export const NOT_ON_DEMAND = new String('*')
|
|
17
|
+
|
|
18
|
+
export const NONE = Symbol('__NONE__')
|
|
19
|
+
|
|
20
|
+
export function resolveDebug(debug) {
|
|
21
|
+
if (debug === undefined) {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Environment variables are strings, so convert to boolean
|
|
26
|
+
if (debug === 'true' || debug === '1') {
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (debug === 'false' || debug === '0') {
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Keep the debug convention into account:
|
|
35
|
+
// DEBUG=* -> This enables all debug modes
|
|
36
|
+
// DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
|
|
37
|
+
// DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
|
|
38
|
+
// DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
|
|
39
|
+
|
|
40
|
+
if (debug === '*') {
|
|
41
|
+
return true
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let debuggers = debug.split(',').map((d) => d.split(':')[0])
|
|
45
|
+
|
|
46
|
+
// Ignoring tailwindcss
|
|
47
|
+
if (debuggers.includes('-tailwindcss')) {
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Including tailwindcss
|
|
52
|
+
if (debuggers.includes('tailwindcss')) {
|
|
53
|
+
return true
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false
|
|
57
|
+
}
|
package/src/plugin.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import postcss from 'postcss'
|
|
2
|
+
import lightningcss, { Features } from 'lightningcss'
|
|
3
|
+
import browserslist from 'browserslist'
|
|
4
|
+
import setupTrackingContext from './lib/setupTrackingContext'
|
|
5
|
+
import processTailwindFeatures from './processTailwindFeatures'
|
|
6
|
+
import { env } from './lib/sharedState'
|
|
7
|
+
import { findAtConfigPath } from './lib/findAtConfigPath'
|
|
8
|
+
import { handleImportAtRules } from './lib/handleImportAtRules'
|
|
9
|
+
|
|
10
|
+
module.exports = function tailwindcss(configOrPath) {
|
|
11
|
+
return {
|
|
12
|
+
postcssPlugin: 'tailwindcss',
|
|
13
|
+
plugins: [
|
|
14
|
+
env.DEBUG &&
|
|
15
|
+
function (root) {
|
|
16
|
+
console.log('\n')
|
|
17
|
+
console.time('JIT TOTAL')
|
|
18
|
+
return root
|
|
19
|
+
},
|
|
20
|
+
...handleImportAtRules(),
|
|
21
|
+
function (root, result) {
|
|
22
|
+
// Use the path for the `@config` directive if it exists, otherwise use the
|
|
23
|
+
// path for the file being processed
|
|
24
|
+
configOrPath = findAtConfigPath(root, result) ?? configOrPath
|
|
25
|
+
|
|
26
|
+
let context = setupTrackingContext(configOrPath)
|
|
27
|
+
|
|
28
|
+
if (root.type === 'document') {
|
|
29
|
+
let roots = root.nodes.filter((node) => node.type === 'root')
|
|
30
|
+
|
|
31
|
+
for (const root of roots) {
|
|
32
|
+
if (root.type === 'root') {
|
|
33
|
+
processTailwindFeatures(context)(root, result)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
processTailwindFeatures(context)(root, result)
|
|
41
|
+
},
|
|
42
|
+
function lightningCssPlugin(_root, result) {
|
|
43
|
+
let map = result.map ?? result.opts.map
|
|
44
|
+
|
|
45
|
+
let intermediateResult = result.root.toResult({
|
|
46
|
+
map: map ? { inline: true } : false,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
let intermediateMap = intermediateResult.map?.toJSON?.() ?? map
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
let includeFeatures = Features.Nesting
|
|
53
|
+
let excludeFeatures = 0
|
|
54
|
+
|
|
55
|
+
let resolvedBrowsersListConfig = browserslist.findConfig(
|
|
56
|
+
result.opts.from ?? process.cwd()
|
|
57
|
+
)?.defaults
|
|
58
|
+
let defaultBrowsersListConfig = require('../package.json').browserslist
|
|
59
|
+
let browsersListConfig = resolvedBrowsersListConfig ?? defaultBrowsersListConfig
|
|
60
|
+
|
|
61
|
+
if (browsersListConfig.join(',') === defaultBrowsersListConfig.join(',')) {
|
|
62
|
+
includeFeatures |=
|
|
63
|
+
Features.ColorFunction | Features.OklabColors | Features.LabColors | Features.P3Colors
|
|
64
|
+
|
|
65
|
+
excludeFeatures |=
|
|
66
|
+
Features.HexAlphaColors |
|
|
67
|
+
Features.LogicalProperties |
|
|
68
|
+
Features.SpaceSeparatedColorNotation
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let transformed = lightningcss.transform({
|
|
72
|
+
filename: result.opts.from,
|
|
73
|
+
code: Buffer.from(intermediateResult.css),
|
|
74
|
+
minify: false,
|
|
75
|
+
sourceMap: !!intermediateMap,
|
|
76
|
+
targets: lightningcss.browserslistToTargets(browserslist(browsersListConfig)),
|
|
77
|
+
drafts: {
|
|
78
|
+
nesting: true,
|
|
79
|
+
customMedia: true,
|
|
80
|
+
},
|
|
81
|
+
nonStandard: {
|
|
82
|
+
deepSelectorCombinator: true,
|
|
83
|
+
},
|
|
84
|
+
include: includeFeatures,
|
|
85
|
+
exclude: excludeFeatures,
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
let code = transformed.code.toString()
|
|
89
|
+
|
|
90
|
+
// https://postcss.org/api/#sourcemapoptions
|
|
91
|
+
if (intermediateMap && transformed.map != null) {
|
|
92
|
+
let prev = transformed.map.toString()
|
|
93
|
+
|
|
94
|
+
if (typeof intermediateMap === 'object') {
|
|
95
|
+
intermediateMap.prev = prev
|
|
96
|
+
} else {
|
|
97
|
+
code = `${code}\n/*# sourceMappingURL=data:application/json;base64,${Buffer.from(
|
|
98
|
+
prev
|
|
99
|
+
).toString('base64')} */`
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
result.root = postcss.parse(code, {
|
|
104
|
+
...result.opts,
|
|
105
|
+
map: intermediateMap,
|
|
106
|
+
})
|
|
107
|
+
} catch (err) {
|
|
108
|
+
if (err.source && typeof process !== 'undefined' && process.env.JEST_WORKER_ID) {
|
|
109
|
+
let lines = err.source.split('\n')
|
|
110
|
+
err = new Error(
|
|
111
|
+
[
|
|
112
|
+
'Error formatting using Lightning CSS:',
|
|
113
|
+
'',
|
|
114
|
+
...[
|
|
115
|
+
'```css',
|
|
116
|
+
...lines.slice(Math.max(err.loc.line - 3, 0), err.loc.line),
|
|
117
|
+
' '.repeat(err.loc.column - 1) + '^-- ' + err.toString(),
|
|
118
|
+
...lines.slice(err.loc.line, err.loc.line + 2),
|
|
119
|
+
'```',
|
|
120
|
+
],
|
|
121
|
+
].join('\n')
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (Error.captureStackTrace) {
|
|
126
|
+
Error.captureStackTrace(err, lightningCssPlugin)
|
|
127
|
+
}
|
|
128
|
+
throw err
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
env.DEBUG &&
|
|
132
|
+
function (root) {
|
|
133
|
+
console.timeEnd('JIT TOTAL')
|
|
134
|
+
console.log('\n')
|
|
135
|
+
return root
|
|
136
|
+
},
|
|
137
|
+
].filter(Boolean),
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
module.exports.postcss = true
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# tailwindcss/nesting
|
|
2
|
+
|
|
3
|
+
This is a PostCSS plugin that wraps [postcss-nested](https://github.com/postcss/postcss-nested) or [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) and acts as a compatibility layer to make sure your nesting plugin of choice properly understands Tailwind's custom syntax like `@apply` and `@screen`.
|
|
4
|
+
|
|
5
|
+
Add it to your PostCSS configuration, somewhere before Tailwind itself:
|
|
6
|
+
|
|
7
|
+
```js
|
|
8
|
+
// postcss.config.js
|
|
9
|
+
module.exports = {
|
|
10
|
+
plugins: [
|
|
11
|
+
require('postcss-import'),
|
|
12
|
+
require('tailwindcss/nesting'),
|
|
13
|
+
require('tailwindcss'),
|
|
14
|
+
require('autoprefixer'),
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
By default, it uses the [postcss-nested](https://github.com/postcss/postcss-nested) plugin under the hood, which uses a Sass-like syntax and is the plugin that powers nesting support in the [Tailwind CSS plugin API](https://tailwindcss.com/docs/plugins#css-in-js-syntax).
|
|
20
|
+
|
|
21
|
+
If you'd rather use [postcss-nesting](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-nesting) (which is based on the work-in-progress [CSS Nesting](https://drafts.csswg.org/css-nesting-1/) specification), first install the plugin alongside:
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
npm install postcss-nesting
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Then pass the plugin itself as an argument to `tailwindcss/nesting` in your PostCSS configuration:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
// postcss.config.js
|
|
31
|
+
module.exports = {
|
|
32
|
+
plugins: [
|
|
33
|
+
require('postcss-import'),
|
|
34
|
+
require('tailwindcss/nesting')(require('postcss-nesting')),
|
|
35
|
+
require('tailwindcss'),
|
|
36
|
+
require('autoprefixer'),
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
This can also be helpful if for whatever reason you need to use a very specific version of `postcss-nested` and want to override the version we bundle with `tailwindcss/nesting` itself.
|
|
42
|
+
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import postcss from 'postcss'
|
|
2
|
+
import postcssNested from 'postcss-nested'
|
|
3
|
+
|
|
4
|
+
export function nesting(opts = postcssNested) {
|
|
5
|
+
return (root, result) => {
|
|
6
|
+
root.walkAtRules('screen', (rule) => {
|
|
7
|
+
rule.name = 'media'
|
|
8
|
+
rule.params = `screen(${rule.params})`
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
root.walkAtRules('apply', (rule) => {
|
|
12
|
+
rule.before(postcss.decl({ prop: '__apply', value: rule.params, source: rule.source }))
|
|
13
|
+
rule.remove()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
let plugin = (() => {
|
|
17
|
+
if (
|
|
18
|
+
typeof opts === 'function' ||
|
|
19
|
+
(typeof opts === 'object' && opts?.hasOwnProperty?.('postcssPlugin'))
|
|
20
|
+
) {
|
|
21
|
+
return opts
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof opts === 'string') {
|
|
25
|
+
return require(opts)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (Object.keys(opts).length <= 0) {
|
|
29
|
+
return postcssNested
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
throw new Error('tailwindcss/nesting should be loaded with a nesting plugin.')
|
|
33
|
+
})()
|
|
34
|
+
|
|
35
|
+
postcss([plugin]).process(root, result.opts).sync()
|
|
36
|
+
|
|
37
|
+
root.walkDecls('__apply', (decl) => {
|
|
38
|
+
decl.before(postcss.atRule({ name: 'apply', params: decl.value, source: decl.source }))
|
|
39
|
+
decl.remove()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Use a private PostCSS API to remove the "clean" flag from the entire AST.
|
|
44
|
+
* This is done because running process() on the AST will set the "clean"
|
|
45
|
+
* flag on all nodes, which we don't want.
|
|
46
|
+
*
|
|
47
|
+
* This causes downstream plugins using the visitor API to be skipped.
|
|
48
|
+
*
|
|
49
|
+
* This is guarded because the PostCSS API is not public
|
|
50
|
+
* and may change in future versions of PostCSS.
|
|
51
|
+
*
|
|
52
|
+
* See https://github.com/postcss/postcss/issues/1712 for more details
|
|
53
|
+
*
|
|
54
|
+
* @param {import('postcss').Node} node
|
|
55
|
+
*/
|
|
56
|
+
function markDirty(node) {
|
|
57
|
+
if (!('markDirty' in node)) {
|
|
58
|
+
return
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Traverse the tree down to the leaf nodes
|
|
62
|
+
if (node.nodes) {
|
|
63
|
+
node.nodes.forEach((n) => markDirty(n))
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// If it's a leaf node mark it as dirty
|
|
67
|
+
// We do this here because marking a node as dirty
|
|
68
|
+
// will walk up the tree and mark all parents as dirty
|
|
69
|
+
// resulting in a lot of unnecessary work if we did this
|
|
70
|
+
// for every single node
|
|
71
|
+
if (!node.nodes) {
|
|
72
|
+
node.markDirty()
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
markDirty(root)
|
|
77
|
+
|
|
78
|
+
return root
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -6,16 +6,24 @@ import substituteScreenAtRules from './lib/substituteScreenAtRules'
|
|
|
6
6
|
import resolveDefaultsAtRules from './lib/resolveDefaultsAtRules'
|
|
7
7
|
import collapseAdjacentRules from './lib/collapseAdjacentRules'
|
|
8
8
|
import collapseDuplicateDeclarations from './lib/collapseDuplicateDeclarations'
|
|
9
|
+
import partitionApplyAtRules from './lib/partitionApplyAtRules'
|
|
9
10
|
import detectNesting from './lib/detectNesting'
|
|
10
11
|
import { createContext } from './lib/setupContextUtils'
|
|
11
12
|
import { issueFlagNotices } from './featureFlags'
|
|
12
13
|
|
|
13
14
|
export default function processTailwindFeatures(setupContext) {
|
|
14
15
|
return function (root, result) {
|
|
15
|
-
let tailwindDirectives = normalizeTailwindDirectives(root)
|
|
16
|
+
let { tailwindDirectives, applyDirectives } = normalizeTailwindDirectives(root)
|
|
17
|
+
|
|
18
|
+
detectNesting()(root, result)
|
|
19
|
+
|
|
20
|
+
// Partition apply rules that are found in the css
|
|
21
|
+
// itself.
|
|
22
|
+
partitionApplyAtRules()(root, result)
|
|
16
23
|
|
|
17
24
|
let context = setupContext({
|
|
18
25
|
tailwindDirectives,
|
|
26
|
+
applyDirectives,
|
|
19
27
|
registerDependency(dependency) {
|
|
20
28
|
result.messages.push({
|
|
21
29
|
plugin: 'tailwindcss',
|
|
@@ -36,8 +44,10 @@ export default function processTailwindFeatures(setupContext) {
|
|
|
36
44
|
|
|
37
45
|
issueFlagNotices(context.tailwindConfig)
|
|
38
46
|
|
|
39
|
-
detectNesting(context)(root, result)
|
|
40
47
|
expandTailwindAtRules(context)(root, result)
|
|
48
|
+
// Partition apply rules that are generated by
|
|
49
|
+
// addComponents, addUtilities and so on.
|
|
50
|
+
partitionApplyAtRules()(root, result)
|
|
41
51
|
expandApplyAtRules(context)(root, result)
|
|
42
52
|
evaluateTailwindFunctions(context)(root, result)
|
|
43
53
|
substituteScreenAtRules(context)(root, result)
|