tailwindcss 0.0.0-insiders.ca1dfd6 → 0.0.0-insiders.cb6e45a
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 +526 -2
- package/LICENSE +1 -2
- package/README.md +13 -6
- package/colors.d.ts +3 -0
- package/colors.js +2 -1
- package/defaultConfig.d.ts +3 -0
- package/defaultConfig.js +2 -1
- package/defaultTheme.d.ts +4 -0
- package/defaultTheme.js +2 -1
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +44 -0
- package/lib/cli/build/plugin.js +335 -0
- package/lib/cli/build/utils.js +78 -0
- package/lib/cli/build/watching.js +113 -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 +12 -0
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +91 -569
- package/lib/constants.js +27 -20
- package/lib/corePluginList.js +16 -4
- package/lib/corePlugins.js +2247 -1873
- package/lib/css/preflight.css +20 -9
- package/lib/featureFlags.js +37 -23
- package/lib/index.js +28 -12
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +27 -9
- package/lib/lib/collapseDuplicateDeclarations.js +83 -0
- package/lib/lib/content.js +167 -0
- package/lib/lib/defaultExtractor.js +236 -0
- package/lib/lib/detectNesting.js +21 -3
- package/lib/lib/evaluateTailwindFunctions.js +117 -50
- package/lib/lib/expandApplyAtRules.js +439 -160
- package/lib/lib/expandTailwindAtRules.js +141 -151
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +572 -105
- package/lib/lib/getModuleDependencies.js +11 -8
- package/lib/lib/normalizeTailwindDirectives.js +45 -33
- 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 +114 -81
- package/lib/lib/setupContextUtils.js +777 -385
- package/lib/lib/setupTrackingContext.js +43 -71
- package/lib/lib/sharedState.js +49 -18
- package/lib/lib/substituteScreenAtRules.js +13 -8
- 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 +36 -21
- package/lib/public/colors.js +250 -252
- package/lib/public/create-plugin.js +6 -4
- package/lib/public/default-config.js +7 -5
- package/lib/public/default-theme.js +7 -5
- package/lib/public/resolve-config.js +8 -5
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +18 -24
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +21 -3
- package/lib/util/color.js +54 -40
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -6
- package/lib/util/createUtilityPlugin.js +11 -13
- package/lib/util/dataTypes.js +137 -100
- package/lib/util/defaults.js +10 -1
- package/lib/util/escapeClassName.js +7 -4
- package/lib/util/escapeCommas.js +5 -2
- package/lib/util/flattenColorPalette.js +9 -12
- package/lib/util/formatVariantSelector.js +285 -0
- package/lib/util/getAllConfigs.js +27 -8
- package/lib/util/hashConfig.js +6 -3
- package/lib/util/isKeyframeRule.js +5 -2
- package/lib/util/isPlainObject.js +5 -2
- package/lib/util/isValidArbitraryValue.js +72 -0
- package/lib/util/log.js +44 -22
- package/lib/util/nameClass.js +20 -8
- package/lib/util/negateValue.js +23 -6
- package/lib/util/normalizeConfig.js +267 -0
- package/lib/util/normalizeScreens.js +170 -0
- package/lib/util/parseAnimationValue.js +42 -40
- package/lib/util/parseBoxShadowValue.js +84 -0
- package/lib/util/parseDependency.js +38 -56
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +11 -8
- package/lib/util/pluginUtils.js +171 -189
- package/lib/util/prefixSelector.js +10 -10
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +92 -126
- package/lib/util/resolveConfigPath.js +11 -9
- package/lib/util/responsive.js +8 -5
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +5 -3
- package/lib/util/toPath.js +24 -3
- package/lib/util/transformThemeValue.js +49 -31
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +23 -15
- package/nesting/index.js +2 -12
- package/package.json +48 -46
- package/peers/index.js +14817 -12471
- package/plugin.d.ts +11 -0
- package/plugin.js +2 -1
- package/resolveConfig.d.ts +3 -0
- package/resolveConfig.js +2 -1
- 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 +45 -0
- package/src/cli/build/plugin.js +397 -0
- package/src/cli/build/utils.js +76 -0
- package/src/cli/build/watching.js +134 -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 +5 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +26 -565
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +905 -615
- package/src/css/preflight.css +20 -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 +205 -0
- package/src/lib/defaultExtractor.js +211 -0
- package/src/lib/detectNesting.js +22 -3
- package/src/lib/evaluateTailwindFunctions.js +84 -10
- package/src/lib/expandApplyAtRules.js +488 -153
- package/src/lib/expandTailwindAtRules.js +94 -106
- package/src/lib/findAtConfigPath.js +50 -0
- package/src/lib/generateRules.js +589 -67
- 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 +98 -60
- package/src/lib/setupContextUtils.js +737 -246
- package/src/lib/setupTrackingContext.js +16 -54
- package/src/lib/sharedState.js +44 -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 +17 -2
- package/src/public/colors.js +4 -9
- 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 -2
- package/src/util/dataTypes.js +57 -21
- package/src/util/defaults.js +6 -0
- package/src/util/formatVariantSelector.js +319 -0
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/isValidArbitraryValue.js +61 -0
- package/src/util/log.js +23 -22
- package/src/util/nameClass.js +6 -2
- package/src/util/negateValue.js +14 -4
- package/src/util/normalizeConfig.js +282 -0
- package/src/util/normalizeScreens.js +140 -0
- package/src/util/parseBoxShadowValue.js +72 -0
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +144 -152
- package/src/util/prefixSelector.js +7 -8
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +82 -81
- 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 +1 -1
- package/stubs/defaultConfig.stub.js +173 -93
- package/stubs/simpleConfig.stub.js +1 -1
- package/types/config.d.ts +361 -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 -284
- package/nesting/plugin.js +0 -41
- package/src/lib/setupWatchingContext.js +0 -306
package/src/css/preflight.css
CHANGED
|
@@ -9,7 +9,12 @@
|
|
|
9
9
|
box-sizing: border-box; /* 1 */
|
|
10
10
|
border-width: 0; /* 2 */
|
|
11
11
|
border-style: solid; /* 2 */
|
|
12
|
-
border-color: currentColor; /* 2 */
|
|
12
|
+
border-color: theme('borderColor.DEFAULT', currentColor); /* 2 */
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
::before,
|
|
16
|
+
::after {
|
|
17
|
+
--tw-content: '';
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
/*
|
|
@@ -53,7 +58,7 @@ hr {
|
|
|
53
58
|
Add the correct text decoration in Chrome, Edge, and Safari.
|
|
54
59
|
*/
|
|
55
60
|
|
|
56
|
-
abbr[title] {
|
|
61
|
+
abbr:where([title]) {
|
|
57
62
|
text-decoration: underline dotted;
|
|
58
63
|
}
|
|
59
64
|
|
|
@@ -139,7 +144,7 @@ sup {
|
|
|
139
144
|
table {
|
|
140
145
|
text-indent: 0; /* 1 */
|
|
141
146
|
border-color: inherit; /* 2 */
|
|
142
|
-
border-collapse: collapse;
|
|
147
|
+
border-collapse: collapse; /* 3 */
|
|
143
148
|
}
|
|
144
149
|
|
|
145
150
|
/*
|
|
@@ -155,6 +160,7 @@ select,
|
|
|
155
160
|
textarea {
|
|
156
161
|
font-family: inherit; /* 1 */
|
|
157
162
|
font-size: 100%; /* 1 */
|
|
163
|
+
font-weight: inherit; /* 1 */
|
|
158
164
|
line-height: inherit; /* 1 */
|
|
159
165
|
color: inherit; /* 1 */
|
|
160
166
|
margin: 0; /* 2 */
|
|
@@ -283,7 +289,8 @@ legend {
|
|
|
283
289
|
}
|
|
284
290
|
|
|
285
291
|
ol,
|
|
286
|
-
ul
|
|
292
|
+
ul,
|
|
293
|
+
menu {
|
|
287
294
|
list-style: none;
|
|
288
295
|
margin: 0;
|
|
289
296
|
padding: 0;
|
|
@@ -304,7 +311,7 @@ textarea {
|
|
|
304
311
|
|
|
305
312
|
input::placeholder,
|
|
306
313
|
textarea::placeholder {
|
|
307
|
-
opacity: 1;
|
|
314
|
+
opacity: 1; /* 1 */
|
|
308
315
|
color: theme('colors.gray.400', #9ca3af); /* 2 */
|
|
309
316
|
}
|
|
310
317
|
|
|
@@ -317,6 +324,13 @@ button,
|
|
|
317
324
|
cursor: pointer;
|
|
318
325
|
}
|
|
319
326
|
|
|
327
|
+
/*
|
|
328
|
+
Make sure disabled buttons don't get the pointer cursor.
|
|
329
|
+
*/
|
|
330
|
+
:disabled {
|
|
331
|
+
cursor: default;
|
|
332
|
+
}
|
|
333
|
+
|
|
320
334
|
/*
|
|
321
335
|
1. Make replaced elements `display: block` by default. (https://github.com/mozdevs/cssremedy/issues/14)
|
|
322
336
|
2. Add `vertical-align: middle` to align replaced elements more sensibly by default. (https://github.com/jensimmons/cssremedy/issues/14#issuecomment-634934210)
|
|
@@ -345,10 +359,7 @@ video {
|
|
|
345
359
|
height: auto;
|
|
346
360
|
}
|
|
347
361
|
|
|
348
|
-
/*
|
|
349
|
-
Ensure the default browser behavior of the `hidden` attribute.
|
|
350
|
-
*/
|
|
351
|
-
|
|
362
|
+
/* Make elements with the HTML hidden attribute stay hidden by default */
|
|
352
363
|
[hidden] {
|
|
353
364
|
display: none;
|
|
354
365
|
}
|
package/src/featureFlags.js
CHANGED
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import
|
|
1
|
+
import colors from 'picocolors'
|
|
2
2
|
import log from './util/log'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
let defaults = {
|
|
5
|
+
optimizeUniversalDefaults: false,
|
|
6
|
+
generalizedModifiers: true,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let featureFlags = {
|
|
10
|
+
future: [
|
|
11
|
+
'hoverOnlyWhenSupported',
|
|
12
|
+
'respectDefaultRingColorOpacity',
|
|
13
|
+
'disableColorOpacityUtilitiesByDefault',
|
|
14
|
+
'relativeContentPathsByDefault',
|
|
15
|
+
],
|
|
16
|
+
experimental: [
|
|
17
|
+
'optimizeUniversalDefaults',
|
|
18
|
+
'generalizedModifiers',
|
|
19
|
+
// 'variantGrouping',
|
|
20
|
+
],
|
|
7
21
|
}
|
|
8
22
|
|
|
9
23
|
export function flagEnabled(config, flag) {
|
|
10
24
|
if (featureFlags.future.includes(flag)) {
|
|
11
|
-
return config.future === 'all' || (config?.future?.[flag] ?? false)
|
|
25
|
+
return config.future === 'all' || (config?.future?.[flag] ?? defaults[flag] ?? false)
|
|
12
26
|
}
|
|
13
27
|
|
|
14
28
|
if (featureFlags.experimental.includes(flag)) {
|
|
15
|
-
return
|
|
29
|
+
return (
|
|
30
|
+
config.experimental === 'all' || (config?.experimental?.[flag] ?? defaults[flag] ?? false)
|
|
31
|
+
)
|
|
16
32
|
}
|
|
17
33
|
|
|
18
34
|
return false
|
|
@@ -34,13 +50,13 @@ export function issueFlagNotices(config) {
|
|
|
34
50
|
}
|
|
35
51
|
|
|
36
52
|
if (experimentalFlagsEnabled(config).length > 0) {
|
|
37
|
-
|
|
38
|
-
.map((s) =>
|
|
53
|
+
let changes = experimentalFlagsEnabled(config)
|
|
54
|
+
.map((s) => colors.yellow(s))
|
|
39
55
|
.join(', ')
|
|
40
56
|
|
|
41
|
-
log.warn([
|
|
57
|
+
log.warn('experimental-flags-enabled', [
|
|
42
58
|
`You have enabled experimental features: ${changes}`,
|
|
43
|
-
'Experimental features are not covered by semver, may introduce breaking changes, and can change at any time.',
|
|
59
|
+
'Experimental features in Tailwind CSS are not covered by semver, may introduce breaking changes, and can change at any time.',
|
|
44
60
|
])
|
|
45
61
|
}
|
|
46
62
|
}
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import setupTrackingContext from './lib/setupTrackingContext'
|
|
2
|
-
import setupWatchingContext from './lib/setupWatchingContext'
|
|
3
2
|
import processTailwindFeatures from './processTailwindFeatures'
|
|
4
3
|
import { env } from './lib/sharedState'
|
|
4
|
+
import { findAtConfigPath } from './lib/findAtConfigPath'
|
|
5
5
|
|
|
6
6
|
module.exports = function tailwindcss(configOrPath) {
|
|
7
7
|
return {
|
|
@@ -14,12 +14,25 @@ module.exports = function tailwindcss(configOrPath) {
|
|
|
14
14
|
return root
|
|
15
15
|
},
|
|
16
16
|
function (root, result) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
: setupTrackingContext(configOrPath)
|
|
17
|
+
// Use the path for the `@config` directive if it exists, otherwise use the
|
|
18
|
+
// path for the file being processed
|
|
19
|
+
configOrPath = findAtConfigPath(root, result) ?? configOrPath
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
let context = setupTrackingContext(configOrPath)
|
|
22
|
+
|
|
23
|
+
if (root.type === 'document') {
|
|
24
|
+
let roots = root.nodes.filter((node) => node.type === 'root')
|
|
25
|
+
|
|
26
|
+
for (const root of roots) {
|
|
27
|
+
if (root.type === 'root') {
|
|
28
|
+
processTailwindFeatures(context)(root, result)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
processTailwindFeatures(context)(root, result)
|
|
23
36
|
},
|
|
24
37
|
env.DEBUG &&
|
|
25
38
|
function (root) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
import * as sharedState from './sharedState'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculate the hash of a string.
|
|
6
|
+
*
|
|
7
|
+
* This doesn't need to be cryptographically secure or
|
|
8
|
+
* anything like that since it's used only to detect
|
|
9
|
+
* when the CSS changes to invalidate the context.
|
|
10
|
+
*
|
|
11
|
+
* This is wrapped in a try/catch because it's really dependent
|
|
12
|
+
* on how Node itself is build and the environment and OpenSSL
|
|
13
|
+
* version / build that is installed on the user's machine.
|
|
14
|
+
*
|
|
15
|
+
* Based on the environment this can just outright fail.
|
|
16
|
+
*
|
|
17
|
+
* See https://github.com/nodejs/node/issues/40455
|
|
18
|
+
*
|
|
19
|
+
* @param {string} str
|
|
20
|
+
*/
|
|
21
|
+
function getHash(str) {
|
|
22
|
+
try {
|
|
23
|
+
return crypto.createHash('md5').update(str, 'utf-8').digest('binary')
|
|
24
|
+
} catch (err) {
|
|
25
|
+
return ''
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Determine if the CSS tree is different from the
|
|
31
|
+
* previous version for the given `sourcePath`.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} sourcePath
|
|
34
|
+
* @param {import('postcss').Node} root
|
|
35
|
+
*/
|
|
36
|
+
export function hasContentChanged(sourcePath, root) {
|
|
37
|
+
let css = root.toString()
|
|
38
|
+
|
|
39
|
+
// We only care about files with @tailwind directives
|
|
40
|
+
// Other files use an existing context
|
|
41
|
+
if (!css.includes('@tailwind')) {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let existingHash = sharedState.sourceHashMap.get(sourcePath)
|
|
46
|
+
let rootHash = getHash(css)
|
|
47
|
+
let didChange = existingHash !== rootHash
|
|
48
|
+
|
|
49
|
+
sharedState.sourceHashMap.set(sourcePath, rootHash)
|
|
50
|
+
|
|
51
|
+
return didChange
|
|
52
|
+
}
|
|
@@ -5,7 +5,7 @@ let comparisonMap = {
|
|
|
5
5
|
let types = new Set(Object.keys(comparisonMap))
|
|
6
6
|
|
|
7
7
|
export default function collapseAdjacentRules() {
|
|
8
|
-
|
|
8
|
+
function collapseRulesIn(root) {
|
|
9
9
|
let currentRule = null
|
|
10
10
|
root.each((node) => {
|
|
11
11
|
if (!types.has(node.type)) {
|
|
@@ -29,11 +29,30 @@ export default function collapseAdjacentRules() {
|
|
|
29
29
|
(currentRule[property] ?? '').replace(/\s+/g, ' ')
|
|
30
30
|
)
|
|
31
31
|
) {
|
|
32
|
-
|
|
32
|
+
// An AtRule may not have children (for example if we encounter duplicate @import url(…) rules)
|
|
33
|
+
if (node.nodes) {
|
|
34
|
+
currentRule.append(node.nodes)
|
|
35
|
+
}
|
|
36
|
+
|
|
33
37
|
node.remove()
|
|
34
38
|
} else {
|
|
35
39
|
currentRule = node
|
|
36
40
|
}
|
|
37
41
|
})
|
|
42
|
+
|
|
43
|
+
// After we've collapsed adjacent rules & at-rules, we need to collapse
|
|
44
|
+
// adjacent rules & at-rules that are children of at-rules.
|
|
45
|
+
// We do not care about nesting rules because Tailwind CSS
|
|
46
|
+
// explicitly does not handle rule nesting on its own as
|
|
47
|
+
// the user is expected to use a nesting plugin
|
|
48
|
+
root.each((node) => {
|
|
49
|
+
if (node.type === 'atrule') {
|
|
50
|
+
collapseRulesIn(node)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return (root) => {
|
|
56
|
+
collapseRulesIn(root)
|
|
38
57
|
}
|
|
39
58
|
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export default function collapseDuplicateDeclarations() {
|
|
2
|
+
return (root) => {
|
|
3
|
+
root.walkRules((node) => {
|
|
4
|
+
let seen = new Map()
|
|
5
|
+
let droppable = new Set([])
|
|
6
|
+
let byProperty = new Map()
|
|
7
|
+
|
|
8
|
+
node.walkDecls((decl) => {
|
|
9
|
+
// This could happen if we have nested selectors. In that case the
|
|
10
|
+
// parent will loop over all its declarations but also the declarations
|
|
11
|
+
// of nested rules. With this we ensure that we are shallowly checking
|
|
12
|
+
// declarations.
|
|
13
|
+
if (decl.parent !== node) {
|
|
14
|
+
return
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (seen.has(decl.prop)) {
|
|
18
|
+
// Exact same value as what we have seen so far
|
|
19
|
+
if (seen.get(decl.prop).value === decl.value) {
|
|
20
|
+
// Keep the last one, drop the one we've seen so far
|
|
21
|
+
droppable.add(seen.get(decl.prop))
|
|
22
|
+
// Override the existing one with the new value. This is necessary
|
|
23
|
+
// so that if we happen to have more than one declaration with the
|
|
24
|
+
// same value, that we keep removing the previous one. Otherwise we
|
|
25
|
+
// will only remove the *first* one.
|
|
26
|
+
seen.set(decl.prop, decl)
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Not the same value, so we need to check if we can merge it so
|
|
31
|
+
// let's collect it first.
|
|
32
|
+
if (!byProperty.has(decl.prop)) {
|
|
33
|
+
byProperty.set(decl.prop, new Set())
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
byProperty.get(decl.prop).add(seen.get(decl.prop))
|
|
37
|
+
byProperty.get(decl.prop).add(decl)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
seen.set(decl.prop, decl)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
// Drop all the duplicate declarations with the exact same value we've
|
|
44
|
+
// already seen so far.
|
|
45
|
+
for (let decl of droppable) {
|
|
46
|
+
decl.remove()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Analyze the declarations based on its unit, drop all the declarations
|
|
50
|
+
// with the same unit but the last one in the list.
|
|
51
|
+
for (let declarations of byProperty.values()) {
|
|
52
|
+
let byUnit = new Map()
|
|
53
|
+
|
|
54
|
+
for (let decl of declarations) {
|
|
55
|
+
let unit = resolveUnit(decl.value)
|
|
56
|
+
if (unit === null) {
|
|
57
|
+
// We don't have a unit, so should never try and collapse this
|
|
58
|
+
// value. This is because we can't know how to do it in a correct
|
|
59
|
+
// way (e.g.: overrides for older browsers)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!byUnit.has(unit)) {
|
|
64
|
+
byUnit.set(unit, new Set())
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
byUnit.get(unit).add(decl)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (let declarations of byUnit.values()) {
|
|
71
|
+
// Get all but the last one
|
|
72
|
+
let removableDeclarations = Array.from(declarations).slice(0, -1)
|
|
73
|
+
|
|
74
|
+
for (let decl of removableDeclarations) {
|
|
75
|
+
decl.remove()
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let UNITLESS_NUMBER = Symbol('unitless-number')
|
|
84
|
+
|
|
85
|
+
function resolveUnit(input) {
|
|
86
|
+
let result = /^-?\d*.?\d+([\w%]+)?$/g.exec(input)
|
|
87
|
+
|
|
88
|
+
if (result) {
|
|
89
|
+
return result[1] ?? UNITLESS_NUMBER
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return null
|
|
93
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import isGlob from 'is-glob'
|
|
6
|
+
import fastGlob from 'fast-glob'
|
|
7
|
+
import normalizePath from 'normalize-path'
|
|
8
|
+
import { parseGlob } from '../util/parseGlob'
|
|
9
|
+
import { env } from './sharedState'
|
|
10
|
+
|
|
11
|
+
/** @typedef {import('../../types/config.js').RawFile} RawFile */
|
|
12
|
+
/** @typedef {import('../../types/config.js').FilePath} FilePath */
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} ContentPath
|
|
16
|
+
* @property {string} original
|
|
17
|
+
* @property {string} base
|
|
18
|
+
* @property {string | null} glob
|
|
19
|
+
* @property {boolean} ignore
|
|
20
|
+
* @property {string} pattern
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Turn a list of content paths (absolute or not; glob or not) into a list of
|
|
25
|
+
* absolute file paths that exist on the filesystem
|
|
26
|
+
*
|
|
27
|
+
* If there are symlinks in the path then multiple paths will be returned
|
|
28
|
+
* one for the symlink and one for the actual file
|
|
29
|
+
*
|
|
30
|
+
* @param {*} context
|
|
31
|
+
* @param {import('tailwindcss').Config} tailwindConfig
|
|
32
|
+
* @returns {ContentPath[]}
|
|
33
|
+
*/
|
|
34
|
+
export function parseCandidateFiles(context, tailwindConfig) {
|
|
35
|
+
let files = tailwindConfig.content.files
|
|
36
|
+
|
|
37
|
+
// Normalize the file globs
|
|
38
|
+
files = files.filter((filePath) => typeof filePath === 'string')
|
|
39
|
+
files = files.map(normalizePath)
|
|
40
|
+
|
|
41
|
+
// Split into included and excluded globs
|
|
42
|
+
let tasks = fastGlob.generateTasks(files)
|
|
43
|
+
|
|
44
|
+
/** @type {ContentPath[]} */
|
|
45
|
+
let included = []
|
|
46
|
+
|
|
47
|
+
/** @type {ContentPath[]} */
|
|
48
|
+
let excluded = []
|
|
49
|
+
|
|
50
|
+
for (const task of tasks) {
|
|
51
|
+
included.push(...task.positive.map((filePath) => parseFilePath(filePath, false)))
|
|
52
|
+
excluded.push(...task.negative.map((filePath) => parseFilePath(filePath, true)))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
let paths = [...included, ...excluded]
|
|
56
|
+
|
|
57
|
+
// Resolve paths relative to the config file or cwd
|
|
58
|
+
paths = resolveRelativePaths(context, paths)
|
|
59
|
+
|
|
60
|
+
// Resolve symlinks if possible
|
|
61
|
+
paths = paths.flatMap(resolvePathSymlinks)
|
|
62
|
+
|
|
63
|
+
// Update cached patterns
|
|
64
|
+
paths = paths.map(resolveGlobPattern)
|
|
65
|
+
|
|
66
|
+
return paths
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {string} filePath
|
|
72
|
+
* @param {boolean} ignore
|
|
73
|
+
* @returns {ContentPath}
|
|
74
|
+
*/
|
|
75
|
+
function parseFilePath(filePath, ignore) {
|
|
76
|
+
let contentPath = {
|
|
77
|
+
original: filePath,
|
|
78
|
+
base: filePath,
|
|
79
|
+
ignore,
|
|
80
|
+
pattern: filePath,
|
|
81
|
+
glob: null,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (isGlob(filePath)) {
|
|
85
|
+
Object.assign(contentPath, parseGlob(filePath))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return contentPath
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
*
|
|
93
|
+
* @param {ContentPath} contentPath
|
|
94
|
+
* @returns {ContentPath}
|
|
95
|
+
*/
|
|
96
|
+
function resolveGlobPattern(contentPath) {
|
|
97
|
+
contentPath.pattern = contentPath.glob
|
|
98
|
+
? `${contentPath.base}/${contentPath.glob}`
|
|
99
|
+
: contentPath.base
|
|
100
|
+
|
|
101
|
+
contentPath.pattern = contentPath.ignore ? `!${contentPath.pattern}` : contentPath.pattern
|
|
102
|
+
|
|
103
|
+
// This is required for Windows support to properly pick up Glob paths.
|
|
104
|
+
// Afaik, this technically shouldn't be needed but there's probably
|
|
105
|
+
// some internal, direct path matching with a normalized path in
|
|
106
|
+
// a package which can't handle mixed directory separators
|
|
107
|
+
contentPath.pattern = normalizePath(contentPath.pattern)
|
|
108
|
+
|
|
109
|
+
return contentPath
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Resolve each path relative to the config file (when possible) if the experimental flag is enabled
|
|
114
|
+
* Otherwise, resolve relative to the current working directory
|
|
115
|
+
*
|
|
116
|
+
* @param {any} context
|
|
117
|
+
* @param {ContentPath[]} contentPaths
|
|
118
|
+
* @returns {ContentPath[]}
|
|
119
|
+
*/
|
|
120
|
+
function resolveRelativePaths(context, contentPaths) {
|
|
121
|
+
let resolveFrom = []
|
|
122
|
+
|
|
123
|
+
// Resolve base paths relative to the config file (when possible) if the experimental flag is enabled
|
|
124
|
+
if (context.userConfigPath && context.tailwindConfig.content.relative) {
|
|
125
|
+
resolveFrom = [path.dirname(context.userConfigPath)]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return contentPaths.map((contentPath) => {
|
|
129
|
+
contentPath.base = path.resolve(...resolveFrom, contentPath.base)
|
|
130
|
+
|
|
131
|
+
return contentPath
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Resolve the symlink for the base directory / file in each path
|
|
137
|
+
* These are added as additional dependencies to watch for changes because
|
|
138
|
+
* some tools (like webpack) will only watch the actual file or directory
|
|
139
|
+
* but not the symlink itself even in projects that use monorepos.
|
|
140
|
+
*
|
|
141
|
+
* @param {ContentPath} contentPath
|
|
142
|
+
* @returns {ContentPath[]}
|
|
143
|
+
*/
|
|
144
|
+
function resolvePathSymlinks(contentPath) {
|
|
145
|
+
let paths = [contentPath]
|
|
146
|
+
|
|
147
|
+
try {
|
|
148
|
+
let resolvedPath = fs.realpathSync(contentPath.base)
|
|
149
|
+
if (resolvedPath !== contentPath.base) {
|
|
150
|
+
paths.push({
|
|
151
|
+
...contentPath,
|
|
152
|
+
base: resolvedPath,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
} catch {
|
|
156
|
+
// TODO: log this?
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return paths
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @param {any} context
|
|
164
|
+
* @param {ContentPath[]} candidateFiles
|
|
165
|
+
* @param {Map<string, number>} fileModifiedMap
|
|
166
|
+
* @returns {{ content: string, extension: string }[]}
|
|
167
|
+
*/
|
|
168
|
+
export function resolvedChangedContent(context, candidateFiles, fileModifiedMap) {
|
|
169
|
+
let changedContent = context.tailwindConfig.content.files
|
|
170
|
+
.filter((item) => typeof item.raw === 'string')
|
|
171
|
+
.map(({ raw, extension = 'html' }) => ({ content: raw, extension }))
|
|
172
|
+
|
|
173
|
+
for (let changedFile of resolveChangedFiles(candidateFiles, fileModifiedMap)) {
|
|
174
|
+
let content = fs.readFileSync(changedFile, 'utf8')
|
|
175
|
+
let extension = path.extname(changedFile).slice(1)
|
|
176
|
+
changedContent.push({ content, extension })
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return changedContent
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @param {ContentPath[]} candidateFiles
|
|
185
|
+
* @param {Map<string, number>} fileModifiedMap
|
|
186
|
+
* @returns {Set<string>}
|
|
187
|
+
*/
|
|
188
|
+
function resolveChangedFiles(candidateFiles, fileModifiedMap) {
|
|
189
|
+
let paths = candidateFiles.map((contentPath) => contentPath.pattern)
|
|
190
|
+
|
|
191
|
+
let changedFiles = new Set()
|
|
192
|
+
env.DEBUG && console.time('Finding changed files')
|
|
193
|
+
let files = fastGlob.sync(paths, { absolute: true })
|
|
194
|
+
for (let file of files) {
|
|
195
|
+
let prevModified = fileModifiedMap.has(file) ? fileModifiedMap.get(file) : -Infinity
|
|
196
|
+
let modified = fs.statSync(file).mtimeMs
|
|
197
|
+
|
|
198
|
+
if (modified > prevModified) {
|
|
199
|
+
changedFiles.add(file)
|
|
200
|
+
fileModifiedMap.set(file, modified)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
env.DEBUG && console.timeEnd('Finding changed files')
|
|
204
|
+
return changedFiles
|
|
205
|
+
}
|