tailwindcss 0.0.0-insiders.fda68f7 → 0.0.0-oxide.6bf5e56
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/CHANGELOG.md +603 -2
- package/LICENSE +1 -2
- package/README.md +14 -6
- package/colors.d.ts +3 -0
- package/colors.js +2 -304
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -4
- package/defaultTheme.d.ts +4 -0
- package/defaultTheme.js +2 -4
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +48 -0
- package/lib/cli/build/plugin.js +367 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +178 -0
- package/lib/cli/help/index.js +71 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli/shared.js +13 -0
- package/lib/cli-peer-dependencies.js +22 -14
- package/lib/cli.js +217 -743
- package/lib/constants.js +41 -34
- package/lib/corePluginList.js +178 -5
- package/lib/corePlugins.js +3879 -2941
- package/lib/css/preflight.css +22 -9
- package/lib/featureFlags.js +61 -50
- package/lib/index.js +45 -28
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +52 -36
- package/lib/lib/collapseDuplicateDeclarations.js +83 -0
- package/lib/lib/content.js +176 -0
- package/lib/lib/defaultExtractor.js +236 -0
- package/lib/lib/detectNesting.js +37 -0
- package/lib/lib/evaluateTailwindFunctions.js +203 -161
- package/lib/lib/expandApplyAtRules.js +502 -221
- package/lib/lib/expandTailwindAtRules.js +258 -243
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +775 -320
- package/lib/lib/getModuleDependencies.js +44 -46
- package/lib/lib/normalizeTailwindDirectives.js +79 -60
- package/lib/lib/offsets.js +217 -0
- package/lib/lib/partitionApplyAtRules.js +56 -0
- package/lib/lib/regex.js +60 -0
- package/lib/lib/resolveDefaultsAtRules.js +150 -94
- package/lib/lib/setupContextUtils.js +1146 -599
- package/lib/lib/setupTrackingContext.js +129 -177
- package/lib/lib/sharedState.js +53 -21
- package/lib/lib/substituteScreenAtRules.js +26 -28
- package/{nesting → lib/postcss-plugins/nesting}/README.md +2 -2
- package/lib/postcss-plugins/nesting/index.js +19 -0
- package/lib/postcss-plugins/nesting/plugin.js +87 -0
- package/lib/processTailwindFeatures.js +58 -53
- package/lib/public/colors.js +331 -0
- package/lib/public/create-plugin.js +15 -0
- package/lib/public/default-config.js +16 -0
- package/lib/public/default-theme.js +16 -0
- package/lib/public/resolve-config.js +22 -0
- package/lib/util/bigSign.js +7 -6
- package/lib/util/buildMediaQuery.js +21 -32
- package/lib/util/cloneDeep.js +16 -14
- package/lib/util/cloneNodes.js +29 -15
- package/lib/util/color.js +90 -66
- package/lib/util/configurePlugins.js +17 -15
- package/lib/util/createPlugin.js +23 -26
- package/lib/util/createUtilityPlugin.js +46 -46
- package/lib/util/dataTypes.js +242 -0
- package/lib/util/defaults.js +20 -15
- package/lib/util/escapeClassName.js +18 -17
- package/lib/util/escapeCommas.js +7 -6
- package/lib/util/flattenColorPalette.js +13 -12
- package/lib/util/formatVariantSelector.js +285 -0
- package/lib/util/getAllConfigs.js +44 -18
- package/lib/util/hashConfig.js +15 -12
- package/lib/util/isKeyframeRule.js +7 -6
- package/lib/util/isPlainObject.js +11 -11
- package/lib/util/isSyntacticallyValidPropertyValue.js +72 -0
- package/lib/util/log.js +52 -33
- package/lib/util/nameClass.js +37 -26
- package/lib/util/negateValue.js +31 -17
- package/lib/util/normalizeConfig.js +281 -0
- package/lib/util/normalizeScreens.js +170 -0
- package/lib/util/parseAnimationValue.js +85 -54
- package/lib/util/parseBoxShadowValue.js +84 -0
- package/lib/util/parseDependency.js +41 -70
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +30 -24
- package/lib/util/pluginUtils.js +252 -287
- package/lib/util/prefixSelector.js +20 -20
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +221 -256
- package/lib/util/resolveConfigPath.js +43 -48
- package/lib/util/responsive.js +18 -14
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +8 -7
- package/lib/util/toColorValue.js +7 -6
- package/lib/util/toPath.js +27 -8
- package/lib/util/transformThemeValue.js +67 -28
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +67 -57
- package/nesting/index.js +2 -12
- package/package.json +60 -65
- package/peers/index.js +76445 -84221
- package/plugin.d.ts +11 -0
- package/plugin.js +1 -2
- package/resolveConfig.d.ts +12 -0
- package/resolveConfig.js +2 -7
- package/scripts/create-plugin-list.js +2 -2
- 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/deps.js +56 -0
- package/src/cli/build/index.js +49 -0
- package/src/cli/build/plugin.js +439 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +227 -0
- package/src/cli/help/index.js +70 -0
- package/src/cli/index.js +3 -0
- package/src/cli/init/index.js +50 -0
- package/src/cli/shared.js +6 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +50 -575
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +2405 -1948
- package/src/css/preflight.css +22 -9
- package/src/featureFlags.js +26 -10
- package/src/index.js +19 -6
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/collapseDuplicateDeclarations.js +93 -0
- package/src/lib/content.js +212 -0
- package/src/lib/defaultExtractor.js +211 -0
- package/src/lib/detectNesting.js +39 -0
- package/src/lib/evaluateTailwindFunctions.js +84 -10
- package/src/lib/expandApplyAtRules.js +508 -153
- package/src/lib/expandTailwindAtRules.js +130 -104
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +596 -70
- package/src/lib/normalizeTailwindDirectives.js +10 -3
- package/src/lib/offsets.js +270 -0
- package/src/lib/partitionApplyAtRules.js +52 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/resolveDefaultsAtRules.js +105 -47
- package/src/lib/setupContextUtils.js +828 -196
- package/src/lib/setupTrackingContext.js +19 -54
- package/src/lib/sharedState.js +45 -7
- package/src/lib/substituteScreenAtRules.js +6 -3
- 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 +19 -2
- package/src/public/colors.js +300 -0
- package/src/public/create-plugin.js +2 -0
- package/src/public/default-config.js +4 -0
- package/src/public/default-theme.js +4 -0
- package/src/public/resolve-config.js +7 -0
- package/src/util/buildMediaQuery.js +14 -16
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +31 -14
- package/src/util/createUtilityPlugin.js +2 -11
- package/src/util/dataTypes.js +256 -0
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +319 -0
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/isSyntacticallyValidPropertyValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +14 -6
- package/src/util/negateValue.js +15 -5
- package/src/util/normalizeConfig.js +300 -0
- package/src/util/normalizeScreens.js +140 -0
- package/src/util/parseAnimationValue.js +7 -1
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/parseDependency.js +37 -38
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +216 -197
- package/src/util/prefixSelector.js +7 -8
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +86 -91
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +23 -1
- package/src/util/transformThemeValue.js +33 -8
- package/src/util/validateConfig.js +13 -0
- package/src/util/validateFormalSyntax.js +34 -0
- package/src/util/withAlphaVariable.js +14 -9
- package/stubs/defaultConfig.stub.js +186 -117
- package/stubs/simpleConfig.stub.js +1 -1
- package/types/config.d.ts +362 -0
- package/types/generated/.gitkeep +0 -0
- package/types/generated/colors.d.ts +276 -0
- package/types/generated/corePluginList.d.ts +1 -0
- package/types/generated/default-theme.d.ts +342 -0
- package/types/index.d.ts +7 -0
- package/lib/lib/setupWatchingContext.js +0 -331
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
|
-
import path from 'path'
|
|
3
|
-
|
|
4
|
-
import fastGlob from 'fast-glob'
|
|
5
2
|
import LRU from 'quick-lru'
|
|
6
|
-
import normalizePath from 'normalize-path'
|
|
7
3
|
|
|
8
4
|
import hash from '../util/hashConfig'
|
|
9
5
|
import getModuleDependencies from '../lib/getModuleDependencies'
|
|
10
|
-
|
|
11
|
-
import resolveConfig from '../../resolveConfig'
|
|
12
|
-
|
|
6
|
+
import resolveConfig from '../public/resolve-config'
|
|
13
7
|
import resolveConfigPath from '../util/resolveConfigPath'
|
|
14
|
-
|
|
15
|
-
import { env } from './sharedState'
|
|
16
|
-
|
|
17
8
|
import { getContext, getFileModifiedMap } from './setupContextUtils'
|
|
18
9
|
import parseDependency from '../util/parseDependency'
|
|
10
|
+
import { validateConfig } from '../util/validateConfig.js'
|
|
11
|
+
import { parseCandidateFiles, resolvedChangedContent } from './content.js'
|
|
19
12
|
|
|
20
13
|
let configPathCache = new LRU({ maxSize: 100 })
|
|
21
14
|
|
|
@@ -26,9 +19,7 @@ function getCandidateFiles(context, tailwindConfig) {
|
|
|
26
19
|
return candidateFilesCache.get(context)
|
|
27
20
|
}
|
|
28
21
|
|
|
29
|
-
let candidateFiles = tailwindConfig
|
|
30
|
-
.filter((item) => typeof item === 'string')
|
|
31
|
-
.map((contentPath) => normalizePath(path.resolve(contentPath)))
|
|
22
|
+
let candidateFiles = parseCandidateFiles(context, tailwindConfig)
|
|
32
23
|
|
|
33
24
|
return candidateFilesCache.set(context, candidateFiles).get(context)
|
|
34
25
|
}
|
|
@@ -63,6 +54,7 @@ function getTailwindConfig(configOrPath) {
|
|
|
63
54
|
delete require.cache[file]
|
|
64
55
|
}
|
|
65
56
|
let newConfig = resolveConfig(require(userConfigPath))
|
|
57
|
+
newConfig = validateConfig(newConfig)
|
|
66
58
|
let newHash = hash(newConfig)
|
|
67
59
|
configPathCache.set(userConfigPath, [newConfig, newHash, newDeps, newModified])
|
|
68
60
|
return [newConfig, userConfigPath, newHash, newDeps]
|
|
@@ -73,38 +65,9 @@ function getTailwindConfig(configOrPath) {
|
|
|
73
65
|
configOrPath.config === undefined ? configOrPath : configOrPath.config
|
|
74
66
|
)
|
|
75
67
|
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
|
|
80
|
-
let changedContent = context.tailwindConfig.content.content
|
|
81
|
-
.filter((item) => typeof item.raw === 'string')
|
|
82
|
-
.concat(context.tailwindConfig.content.safelist)
|
|
83
|
-
.map(({ raw, extension }) => ({ content: raw, extension }))
|
|
84
|
-
|
|
85
|
-
for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)) {
|
|
86
|
-
let content = fs.readFileSync(changedFile, 'utf8')
|
|
87
|
-
let extension = path.extname(changedFile).slice(1)
|
|
88
|
-
changedContent.push({ content, extension })
|
|
89
|
-
}
|
|
90
|
-
return changedContent
|
|
91
|
-
}
|
|
68
|
+
newConfig = validateConfig(newConfig)
|
|
92
69
|
|
|
93
|
-
|
|
94
|
-
let changedFiles = new Set()
|
|
95
|
-
env.DEBUG && console.time('Finding changed files')
|
|
96
|
-
let files = fastGlob.sync(candidateFiles)
|
|
97
|
-
for (let file of files) {
|
|
98
|
-
let prevModified = fileModifiedMap.has(file) ? fileModifiedMap.get(file) : -Infinity
|
|
99
|
-
let modified = fs.statSync(file).mtimeMs
|
|
100
|
-
|
|
101
|
-
if (modified > prevModified) {
|
|
102
|
-
changedFiles.add(file)
|
|
103
|
-
fileModifiedMap.set(file, modified)
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
env.DEBUG && console.timeEnd('Finding changed files')
|
|
107
|
-
return changedFiles
|
|
70
|
+
return [newConfig, null, hash(newConfig), []]
|
|
108
71
|
}
|
|
109
72
|
|
|
110
73
|
// DISABLE_TOUCH = TRUE
|
|
@@ -120,11 +83,12 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
120
83
|
|
|
121
84
|
let contextDependencies = new Set(configDependencies)
|
|
122
85
|
|
|
123
|
-
// If there are no @tailwind rules, we don't consider this CSS
|
|
124
|
-
// to be dependencies of the context. Can reuse
|
|
125
|
-
// We may want to think about `@layer`
|
|
126
|
-
//
|
|
127
|
-
// 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.
|
|
128
92
|
if (tailwindDirectives.size > 0) {
|
|
129
93
|
// Add current css file as a context dependencies.
|
|
130
94
|
contextDependencies.add(result.opts.from)
|
|
@@ -138,7 +102,6 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
138
102
|
}
|
|
139
103
|
|
|
140
104
|
let [context] = getContext(
|
|
141
|
-
tailwindDirectives,
|
|
142
105
|
root,
|
|
143
106
|
result,
|
|
144
107
|
tailwindConfig,
|
|
@@ -149,8 +112,8 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
149
112
|
|
|
150
113
|
let candidateFiles = getCandidateFiles(context, tailwindConfig)
|
|
151
114
|
|
|
152
|
-
// If there are no @tailwind rules, we don't consider this CSS file or it's
|
|
153
|
-
// to be dependencies of the context. Can reuse the context even if they change.
|
|
115
|
+
// If there are no @tailwind or @apply rules, we don't consider this CSS file or it's
|
|
116
|
+
// dependencies to be dependencies of the context. Can reuse the context even if they change.
|
|
154
117
|
// We may want to think about `@layer` being part of this trigger too, but it's tough
|
|
155
118
|
// because it's impossible for a layer in one file to end up in the actual @tailwind rule
|
|
156
119
|
// in another file since independent sources are effectively isolated.
|
|
@@ -158,8 +121,10 @@ export default function setupTrackingContext(configOrPath) {
|
|
|
158
121
|
let fileModifiedMap = getFileModifiedMap(context)
|
|
159
122
|
|
|
160
123
|
// Add template paths as postcss dependencies.
|
|
161
|
-
for (let
|
|
162
|
-
|
|
124
|
+
for (let contentPath of candidateFiles) {
|
|
125
|
+
for (let dependency of parseDependency(contentPath)) {
|
|
126
|
+
registerDependency(dependency)
|
|
127
|
+
}
|
|
163
128
|
}
|
|
164
129
|
|
|
165
130
|
for (let changedContent of resolvedChangedContent(
|
package/src/lib/sharedState.js
CHANGED
|
@@ -1,13 +1,51 @@
|
|
|
1
|
-
import LRU from 'quick-lru'
|
|
2
|
-
|
|
3
1
|
export const env = {
|
|
4
|
-
TAILWIND_MODE: process.env.TAILWIND_MODE,
|
|
5
2
|
NODE_ENV: process.env.NODE_ENV,
|
|
6
|
-
DEBUG: process.env.DEBUG
|
|
7
|
-
|
|
8
|
-
TAILWIND_TOUCH_DIR: process.env.TAILWIND_TOUCH_DIR,
|
|
3
|
+
DEBUG: resolveDebug(process.env.DEBUG),
|
|
4
|
+
OXIDE: process.env.OXIDE,
|
|
9
5
|
}
|
|
10
6
|
export const contextMap = new Map()
|
|
11
7
|
export const configContextMap = new Map()
|
|
12
8
|
export const contextSourcesMap = new Map()
|
|
13
|
-
export const
|
|
9
|
+
export const sourceHashMap = new Map()
|
|
10
|
+
export const NOT_ON_DEMAND = new String('*')
|
|
11
|
+
|
|
12
|
+
export const NONE = Symbol('__NONE__')
|
|
13
|
+
|
|
14
|
+
export function resolveDebug(debug) {
|
|
15
|
+
if (debug === undefined) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Environment variables are strings, so convert to boolean
|
|
20
|
+
if (debug === 'true' || debug === '1') {
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (debug === 'false' || debug === '0') {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Keep the debug convention into account:
|
|
29
|
+
// DEBUG=* -> This enables all debug modes
|
|
30
|
+
// DEBUG=projectA,projectB,projectC -> This enables debug for projectA, projectB and projectC
|
|
31
|
+
// DEBUG=projectA:* -> This enables all debug modes for projectA (if you have sub-types)
|
|
32
|
+
// DEBUG=projectA,-projectB -> This enables debug for projectA and explicitly disables it for projectB
|
|
33
|
+
|
|
34
|
+
if (debug === '*') {
|
|
35
|
+
return true
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let debuggers = debug.split(',').map((d) => d.split(':')[0])
|
|
39
|
+
|
|
40
|
+
// Ignoring tailwindcss
|
|
41
|
+
if (debuggers.includes('-tailwindcss')) {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Including tailwindcss
|
|
46
|
+
if (debuggers.includes('tailwindcss')) {
|
|
47
|
+
return true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import { normalizeScreens } from '../util/normalizeScreens'
|
|
1
2
|
import buildMediaQuery from '../util/buildMediaQuery'
|
|
2
3
|
|
|
3
4
|
export default function ({ tailwindConfig: { theme } }) {
|
|
4
5
|
return function (css) {
|
|
5
6
|
css.walkAtRules('screen', (atRule) => {
|
|
6
|
-
|
|
7
|
+
let screen = atRule.params
|
|
8
|
+
let screens = normalizeScreens(theme.screens)
|
|
9
|
+
let screenDefinition = screens.find(({ name }) => name === screen)
|
|
7
10
|
|
|
8
|
-
if (!
|
|
11
|
+
if (!screenDefinition) {
|
|
9
12
|
throw atRule.error(`No \`${screen}\` screen found.`)
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
atRule.name = 'media'
|
|
13
|
-
atRule.params = buildMediaQuery(
|
|
16
|
+
atRule.params = buildMediaQuery(screenDefinition)
|
|
14
17
|
})
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -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
|
+
}
|
|
@@ -5,14 +5,25 @@ import evaluateTailwindFunctions from './lib/evaluateTailwindFunctions'
|
|
|
5
5
|
import substituteScreenAtRules from './lib/substituteScreenAtRules'
|
|
6
6
|
import resolveDefaultsAtRules from './lib/resolveDefaultsAtRules'
|
|
7
7
|
import collapseAdjacentRules from './lib/collapseAdjacentRules'
|
|
8
|
+
import collapseDuplicateDeclarations from './lib/collapseDuplicateDeclarations'
|
|
9
|
+
import partitionApplyAtRules from './lib/partitionApplyAtRules'
|
|
10
|
+
import detectNesting from './lib/detectNesting'
|
|
8
11
|
import { createContext } from './lib/setupContextUtils'
|
|
12
|
+
import { issueFlagNotices } from './featureFlags'
|
|
9
13
|
|
|
10
14
|
export default function processTailwindFeatures(setupContext) {
|
|
11
15
|
return function (root, result) {
|
|
12
|
-
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)
|
|
13
23
|
|
|
14
24
|
let context = setupContext({
|
|
15
25
|
tailwindDirectives,
|
|
26
|
+
applyDirectives,
|
|
16
27
|
registerDependency(dependency) {
|
|
17
28
|
result.messages.push({
|
|
18
29
|
plugin: 'tailwindcss',
|
|
@@ -21,7 +32,7 @@ export default function processTailwindFeatures(setupContext) {
|
|
|
21
32
|
})
|
|
22
33
|
},
|
|
23
34
|
createContext(tailwindConfig, changedContent) {
|
|
24
|
-
return createContext(tailwindConfig, changedContent,
|
|
35
|
+
return createContext(tailwindConfig, changedContent, root)
|
|
25
36
|
},
|
|
26
37
|
})(root, result)
|
|
27
38
|
|
|
@@ -31,11 +42,17 @@ export default function processTailwindFeatures(setupContext) {
|
|
|
31
42
|
)
|
|
32
43
|
}
|
|
33
44
|
|
|
45
|
+
issueFlagNotices(context.tailwindConfig)
|
|
46
|
+
|
|
34
47
|
expandTailwindAtRules(context)(root, result)
|
|
48
|
+
// Partition apply rules that are generated by
|
|
49
|
+
// addComponents, addUtilities and so on.
|
|
50
|
+
partitionApplyAtRules()(root, result)
|
|
35
51
|
expandApplyAtRules(context)(root, result)
|
|
36
52
|
evaluateTailwindFunctions(context)(root, result)
|
|
37
53
|
substituteScreenAtRules(context)(root, result)
|
|
38
54
|
resolveDefaultsAtRules(context)(root, result)
|
|
39
55
|
collapseAdjacentRules(context)(root, result)
|
|
56
|
+
collapseDuplicateDeclarations(context)(root, result)
|
|
40
57
|
}
|
|
41
58
|
}
|