tailwindcss 0.0.0-insiders.7c337f2 → 0.0.0-insiders.7d8eb21
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 +246 -6
- package/README.md +13 -9
- package/defaultTheme.d.ts +2 -1
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +48 -0
- package/lib/cli/build/plugin.js +362 -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 +12 -0
- package/lib/cli-peer-dependencies.js +18 -5
- package/lib/cli.js +62 -592
- package/lib/constants.js +19 -12
- package/lib/corePluginList.js +5 -3
- package/lib/corePlugins.js +619 -347
- package/lib/css/preflight.css +7 -0
- package/lib/featureFlags.js +34 -22
- package/lib/index.js +16 -9
- package/lib/lib/cacheInvalidation.js +42 -21
- package/lib/lib/collapseAdjacentRules.js +16 -14
- package/lib/lib/collapseDuplicateDeclarations.js +13 -10
- package/lib/lib/content.js +177 -0
- package/lib/lib/defaultExtractor.js +230 -33
- package/lib/lib/detectNesting.js +13 -4
- package/lib/lib/evaluateTailwindFunctions.js +105 -42
- package/lib/lib/expandApplyAtRules.js +151 -92
- package/lib/lib/expandTailwindAtRules.js +134 -149
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +404 -185
- package/lib/lib/getModuleDependencies.js +21 -18
- package/lib/lib/normalizeTailwindDirectives.js +11 -8
- package/lib/lib/offsets.js +285 -0
- package/lib/lib/partitionApplyAtRules.js +14 -11
- package/lib/lib/regex.js +60 -0
- package/lib/lib/remap-bitfield.js +87 -0
- package/lib/lib/resolveDefaultsAtRules.js +97 -79
- package/lib/lib/setupContextUtils.js +567 -242
- package/lib/lib/setupTrackingContext.js +77 -106
- package/lib/lib/sharedState.js +18 -10
- package/lib/lib/substituteScreenAtRules.js +9 -7
- package/lib/postcss-plugins/nesting/index.js +7 -5
- package/lib/postcss-plugins/nesting/plugin.js +10 -8
- package/lib/processTailwindFeatures.js +34 -31
- package/lib/public/colors.js +7 -5
- 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 +13 -10
- package/lib/util/bigSign.js +4 -1
- package/lib/util/buildMediaQuery.js +10 -5
- package/lib/util/cloneDeep.js +6 -5
- package/lib/util/cloneNodes.js +9 -2
- package/lib/util/color.js +20 -17
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -5
- package/lib/util/createUtilityPlugin.js +15 -13
- package/lib/util/dataTypes.js +75 -51
- package/lib/util/defaults.js +8 -5
- package/lib/util/escapeClassName.js +13 -10
- package/lib/util/escapeCommas.js +4 -1
- package/lib/util/flattenColorPalette.js +7 -8
- package/lib/util/formatVariantSelector.js +270 -103
- package/lib/util/getAllConfigs.js +34 -15
- package/lib/util/hashConfig.js +10 -7
- package/lib/util/isKeyframeRule.js +4 -1
- package/lib/util/isPlainObject.js +4 -1
- package/lib/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +34 -26
- package/lib/util/log.js +14 -8
- package/lib/util/nameClass.js +19 -8
- package/lib/util/negateValue.js +20 -5
- package/lib/util/normalizeConfig.js +94 -53
- package/lib/util/normalizeScreens.js +115 -4
- package/lib/util/parseAnimationValue.js +43 -41
- package/lib/util/parseBoxShadowValue.js +12 -45
- package/lib/util/parseDependency.js +37 -55
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +15 -12
- package/lib/util/pluginUtils.js +146 -42
- package/lib/util/prefixSelector.js +26 -9
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +104 -105
- package/lib/util/resolveConfigPath.js +20 -17
- package/lib/util/responsive.js +12 -9
- package/lib/util/splitAtTopLevelOnly.js +43 -0
- package/lib/util/tap.js +4 -1
- package/lib/util/toColorValue.js +4 -1
- package/lib/util/toPath.js +18 -2
- package/lib/util/transformThemeValue.js +23 -11
- package/lib/util/validateConfig.js +24 -0
- package/lib/util/validateFormalSyntax.js +24 -0
- package/lib/util/withAlphaVariable.js +32 -24
- package/package.json +32 -29
- package/peers/index.js +6693 -3036
- package/plugin.d.ts +10 -5
- package/resolveConfig.d.ts +12 -0
- package/scripts/generate-types.js +53 -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 +434 -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 +5 -0
- package/src/cli-peer-dependencies.js +7 -1
- package/src/cli.js +46 -659
- package/src/corePlugins.js +346 -79
- package/src/css/preflight.css +7 -0
- package/src/featureFlags.js +12 -2
- package/src/index.js +5 -0
- package/src/lib/content.js +213 -0
- package/src/lib/defaultExtractor.js +202 -35
- package/src/lib/detectNesting.js +9 -1
- package/src/lib/evaluateTailwindFunctions.js +78 -7
- package/src/lib/expandApplyAtRules.js +129 -34
- package/src/lib/expandTailwindAtRules.js +12 -50
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +379 -126
- package/src/lib/offsets.js +351 -0
- package/src/lib/regex.js +74 -0
- package/src/lib/remap-bitfield.js +82 -0
- package/src/lib/resolveDefaultsAtRules.js +53 -36
- package/src/lib/setupContextUtils.js +510 -120
- package/src/lib/setupTrackingContext.js +8 -45
- package/src/lib/sharedState.js +2 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +5 -1
- package/src/util/dataTypes.js +51 -26
- package/src/util/formatVariantSelector.js +317 -101
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +1 -1
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +10 -2
- package/src/util/normalizeConfig.js +40 -10
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +3 -50
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +132 -10
- package/src/util/prefixSelector.js +28 -10
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -62
- package/src/util/splitAtTopLevelOnly.js +45 -0
- package/src/util/toPath.js +1 -1
- package/src/util/transformThemeValue.js +13 -3
- 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 +165 -164
- package/stubs/simpleConfig.stub.js +1 -0
- package/types/config.d.ts +77 -37
- package/types/generated/default-theme.d.ts +342 -0
- package/types/index.d.ts +7 -1
- package/types.d.ts +0 -1
package/plugin.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { Config, PluginCreator } from './types/config'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
type Plugin = {
|
|
3
|
+
withOptions<T>(
|
|
4
|
+
plugin: (options: T) => PluginCreator,
|
|
5
|
+
config?: (options: T) => Partial<Config>
|
|
6
|
+
): { (options: T): { handler: PluginCreator; config?: Partial<Config> }; __isOptionsFunction: true }
|
|
7
|
+
(plugin: PluginCreator, config?: Partial<Config>): { handler: PluginCreator; config?: Partial<Config> }
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
declare const plugin: Plugin
|
|
11
|
+
export = plugin
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Config, ResolvableTo } from './types/config'
|
|
2
|
+
|
|
3
|
+
type UnwrapResolvables<T> = {
|
|
4
|
+
[K in keyof T]: T[K] extends ResolvableTo<infer R> ? R : T[K]
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
type ResolvedConfig<T extends Config> = Omit<T, 'theme'> & {
|
|
8
|
+
theme: UnwrapResolvables<T['theme']>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare function resolveConfig<T extends Config>(config: T): ResolvedConfig<T>
|
|
12
|
+
export = resolveConfig
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import prettier from 'prettier'
|
|
2
2
|
import { corePlugins } from '../src/corePlugins'
|
|
3
3
|
import colors from '../src/public/colors'
|
|
4
|
+
import defaultTheme from '../src/public/default-theme'
|
|
4
5
|
import fs from 'fs'
|
|
5
6
|
import path from 'path'
|
|
7
|
+
import * as types from './type-utils'
|
|
6
8
|
|
|
7
9
|
fs.writeFileSync(
|
|
8
10
|
path.join(process.cwd(), 'types', 'generated', 'corePluginList.d.ts'),
|
|
@@ -50,3 +52,54 @@ fs.writeFileSync(
|
|
|
50
52
|
}
|
|
51
53
|
)
|
|
52
54
|
)
|
|
55
|
+
|
|
56
|
+
const defaultThemeTypes = Object.entries(defaultTheme)
|
|
57
|
+
.map(([name, value]) => {
|
|
58
|
+
// Special cases for slightly more accurate types
|
|
59
|
+
if (name === 'keyframes') {
|
|
60
|
+
return [name, `Record<${types.forKeys(value)}, Record<string, CSSDeclarationList>>`]
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (name === 'fontSize') {
|
|
64
|
+
return [name, `Record<${types.forKeys(value)}, [string, { lineHeight: string }]>`]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// General cases
|
|
68
|
+
if (typeof value === 'string') {
|
|
69
|
+
return [name, `string`]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (typeof value === 'function') {
|
|
73
|
+
return [name, null]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof value === 'object') {
|
|
77
|
+
if (Object.keys(value).length === 0) {
|
|
78
|
+
return [name, null]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return [name, types.forValue(value)]
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return [name, `unknown`]
|
|
85
|
+
})
|
|
86
|
+
.filter(([, type]) => type !== null)
|
|
87
|
+
.map(([name, type]) => `${name}: ${type}`)
|
|
88
|
+
.join('\n')
|
|
89
|
+
|
|
90
|
+
fs.writeFileSync(
|
|
91
|
+
path.join(process.cwd(), 'types', 'generated', 'default-theme.d.ts'),
|
|
92
|
+
prettier.format(
|
|
93
|
+
`
|
|
94
|
+
import { Config } from '../../types'
|
|
95
|
+
type CSSDeclarationList = Record<string, string>
|
|
96
|
+
export type DefaultTheme = Config['theme'] & { ${defaultThemeTypes} }
|
|
97
|
+
`,
|
|
98
|
+
{
|
|
99
|
+
semi: false,
|
|
100
|
+
singleQuote: true,
|
|
101
|
+
printWidth: 100,
|
|
102
|
+
parser: 'typescript',
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Given a version, figure out what the release channel is so that we can publish to the correct
|
|
2
|
+
// channel on npm.
|
|
3
|
+
//
|
|
4
|
+
// E.g.:
|
|
5
|
+
//
|
|
6
|
+
// 1.2.3 -> latest (default)
|
|
7
|
+
// 0.0.0-insiders.ffaa88 -> insiders
|
|
8
|
+
// 4.1.0-alpha.4 -> alpha
|
|
9
|
+
|
|
10
|
+
let version =
|
|
11
|
+
process.argv[2] || process.env.npm_package_version || require('../package.json').version
|
|
12
|
+
|
|
13
|
+
let match = /\d+\.\d+\.\d+-(.*)\.\d+/g.exec(version)
|
|
14
|
+
if (match) {
|
|
15
|
+
console.log(match[1])
|
|
16
|
+
} else {
|
|
17
|
+
console.log('latest')
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Given a version, figure out what the release notes are so that we can use this to pre-fill the
|
|
2
|
+
// relase notes on a GitHub release for the current version.
|
|
3
|
+
|
|
4
|
+
let path = require('path')
|
|
5
|
+
let fs = require('fs')
|
|
6
|
+
|
|
7
|
+
let version =
|
|
8
|
+
process.argv[2] || process.env.npm_package_version || require('../package.json').version
|
|
9
|
+
|
|
10
|
+
let changelog = fs.readFileSync(path.resolve(__dirname, '..', 'CHANGELOG.md'), 'utf8')
|
|
11
|
+
let match = new RegExp(
|
|
12
|
+
`## \\[${version}\\] - (.*)\\n\\n([\\s\\S]*?)\\n(?:(?:##\\s)|(?:\\[))`,
|
|
13
|
+
'g'
|
|
14
|
+
).exec(changelog)
|
|
15
|
+
|
|
16
|
+
if (match) {
|
|
17
|
+
let [, , notes] = match
|
|
18
|
+
console.log(notes.trim())
|
|
19
|
+
} else {
|
|
20
|
+
console.log(`Placeholder release notes for version: v${version}`)
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function union(types) {
|
|
2
|
+
return [...new Set(types)].join(' | ')
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function unionValues(values) {
|
|
6
|
+
return union(values.map(forValue))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function forKeys(value) {
|
|
10
|
+
return union(Object.keys(value).map((key) => `'${key}'`))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function forValue(value) {
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return `(${unionValues(value)})[]`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (typeof value === 'object') {
|
|
19
|
+
return `Record<${forKeys(value)}, ${unionValues(Object.values(value))}>`
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (typeof value === 'string') {
|
|
23
|
+
return `string`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return `any`
|
|
27
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
lazyPostcss,
|
|
6
|
+
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
lazyPostcssImport,
|
|
9
|
+
|
|
10
|
+
// @ts-ignore
|
|
11
|
+
lazyCssnano,
|
|
12
|
+
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
lazyAutoprefixer,
|
|
15
|
+
} from '../../../peers/index.js'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns {import('postcss')}
|
|
19
|
+
*/
|
|
20
|
+
export function loadPostcss() {
|
|
21
|
+
// Try to load a local `postcss` version first
|
|
22
|
+
try {
|
|
23
|
+
return require('postcss')
|
|
24
|
+
} catch {}
|
|
25
|
+
|
|
26
|
+
return lazyPostcss()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function loadPostcssImport() {
|
|
30
|
+
// Try to load a local `postcss-import` version first
|
|
31
|
+
try {
|
|
32
|
+
return require('postcss-import')
|
|
33
|
+
} catch {}
|
|
34
|
+
|
|
35
|
+
return lazyPostcssImport()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function loadCssNano() {
|
|
39
|
+
let options = { preset: ['default', { cssDeclarationSorter: false }] }
|
|
40
|
+
|
|
41
|
+
// Try to load a local `cssnano` version first
|
|
42
|
+
try {
|
|
43
|
+
return require('cssnano')
|
|
44
|
+
} catch {}
|
|
45
|
+
|
|
46
|
+
return lazyCssnano()(options)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function loadAutoprefixer() {
|
|
50
|
+
// Try to load a local `autoprefixer` version first
|
|
51
|
+
try {
|
|
52
|
+
return require('autoprefixer')
|
|
53
|
+
} catch {}
|
|
54
|
+
|
|
55
|
+
return lazyAutoprefixer()
|
|
56
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import fs from 'fs'
|
|
4
|
+
import path from 'path'
|
|
5
|
+
import { createProcessor } from './plugin.js'
|
|
6
|
+
|
|
7
|
+
export async function build(args, configs) {
|
|
8
|
+
let input = args['--input']
|
|
9
|
+
let shouldWatch = args['--watch']
|
|
10
|
+
|
|
11
|
+
// TODO: Deprecate this in future versions
|
|
12
|
+
if (!input && args['_'][1]) {
|
|
13
|
+
console.error('[deprecation] Running tailwindcss without -i, please provide an input file.')
|
|
14
|
+
input = args['--input'] = args['_'][1]
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (input && input !== '-' && !fs.existsSync((input = path.resolve(input)))) {
|
|
18
|
+
console.error(`Specified input file ${args['--input']} does not exist.`)
|
|
19
|
+
process.exit(9)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (args['--config'] && !fs.existsSync((args['--config'] = path.resolve(args['--config'])))) {
|
|
23
|
+
console.error(`Specified config file ${args['--config']} does not exist.`)
|
|
24
|
+
process.exit(9)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// TODO: Reference the @config path here if exists
|
|
28
|
+
let configPath = args['--config']
|
|
29
|
+
? args['--config']
|
|
30
|
+
: ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))(
|
|
31
|
+
path.resolve(`./${configs.tailwind}`)
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
let processor = await createProcessor(args, configPath)
|
|
35
|
+
|
|
36
|
+
if (shouldWatch) {
|
|
37
|
+
// Abort the watcher if stdin is closed to avoid zombie processes
|
|
38
|
+
// You can disable this behavior with --watch=always
|
|
39
|
+
if (args['--watch'] !== 'always') {
|
|
40
|
+
process.stdin.on('end', () => process.exit(0))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
process.stdin.resume()
|
|
44
|
+
|
|
45
|
+
await processor.watch()
|
|
46
|
+
} else {
|
|
47
|
+
await processor.build()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import postcssrc from 'postcss-load-config'
|
|
6
|
+
import { lilconfig } from 'lilconfig'
|
|
7
|
+
import loadPlugins from 'postcss-load-config/src/plugins' // Little bit scary, looking at private/internal API
|
|
8
|
+
import loadOptions from 'postcss-load-config/src/options' // Little bit scary, looking at private/internal API
|
|
9
|
+
|
|
10
|
+
import tailwind from '../../processTailwindFeatures'
|
|
11
|
+
import { loadAutoprefixer, loadCssNano, loadPostcss, loadPostcssImport } from './deps'
|
|
12
|
+
import { formatNodes, drainStdin, outputFile } from './utils'
|
|
13
|
+
import { env } from '../shared'
|
|
14
|
+
import resolveConfig from '../../../resolveConfig.js'
|
|
15
|
+
import getModuleDependencies from '../../lib/getModuleDependencies.js'
|
|
16
|
+
import { parseCandidateFiles } from '../../lib/content.js'
|
|
17
|
+
import { createWatcher } from './watching.js'
|
|
18
|
+
import fastGlob from 'fast-glob'
|
|
19
|
+
import { findAtConfigPath } from '../../lib/findAtConfigPath.js'
|
|
20
|
+
import log from '../../util/log'
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {string} [customPostCssPath ]
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
async function loadPostCssPlugins(customPostCssPath) {
|
|
28
|
+
let config = customPostCssPath
|
|
29
|
+
? await (async () => {
|
|
30
|
+
let file = path.resolve(customPostCssPath)
|
|
31
|
+
|
|
32
|
+
// Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
let { config = {} } = await lilconfig('postcss').load(file)
|
|
35
|
+
if (typeof config === 'function') {
|
|
36
|
+
config = config()
|
|
37
|
+
} else {
|
|
38
|
+
config = Object.assign({}, config)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (!config.plugins) {
|
|
42
|
+
config.plugins = []
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
file,
|
|
47
|
+
plugins: loadPlugins(config, file),
|
|
48
|
+
options: loadOptions(config, file),
|
|
49
|
+
}
|
|
50
|
+
})()
|
|
51
|
+
: await postcssrc()
|
|
52
|
+
|
|
53
|
+
let configPlugins = config.plugins
|
|
54
|
+
|
|
55
|
+
let configPluginTailwindIdx = configPlugins.findIndex((plugin) => {
|
|
56
|
+
if (typeof plugin === 'function' && plugin.name === 'tailwindcss') {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (typeof plugin === 'object' && plugin !== null && plugin.postcssPlugin === 'tailwindcss') {
|
|
61
|
+
return true
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return false
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
let beforePlugins =
|
|
68
|
+
configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx)
|
|
69
|
+
let afterPlugins =
|
|
70
|
+
configPluginTailwindIdx === -1
|
|
71
|
+
? configPlugins
|
|
72
|
+
: configPlugins.slice(configPluginTailwindIdx + 1)
|
|
73
|
+
|
|
74
|
+
return [beforePlugins, afterPlugins, config.options]
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function loadBuiltinPostcssPlugins() {
|
|
78
|
+
let postcss = loadPostcss()
|
|
79
|
+
let IMPORT_COMMENT = '__TAILWIND_RESTORE_IMPORT__: '
|
|
80
|
+
return [
|
|
81
|
+
[
|
|
82
|
+
(root) => {
|
|
83
|
+
root.walkAtRules('import', (rule) => {
|
|
84
|
+
if (rule.params.slice(1).startsWith('tailwindcss/')) {
|
|
85
|
+
rule.after(postcss.comment({ text: IMPORT_COMMENT + rule.params }))
|
|
86
|
+
rule.remove()
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
},
|
|
90
|
+
loadPostcssImport(),
|
|
91
|
+
(root) => {
|
|
92
|
+
root.walkComments((rule) => {
|
|
93
|
+
if (rule.text.startsWith(IMPORT_COMMENT)) {
|
|
94
|
+
rule.after(
|
|
95
|
+
postcss.atRule({
|
|
96
|
+
name: 'import',
|
|
97
|
+
params: rule.text.replace(IMPORT_COMMENT, ''),
|
|
98
|
+
})
|
|
99
|
+
)
|
|
100
|
+
rule.remove()
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
[],
|
|
106
|
+
{},
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let state = {
|
|
111
|
+
/** @type {any} */
|
|
112
|
+
context: null,
|
|
113
|
+
|
|
114
|
+
/** @type {ReturnType<typeof createWatcher> | null} */
|
|
115
|
+
watcher: null,
|
|
116
|
+
|
|
117
|
+
/** @type {{content: string, extension: string}[]} */
|
|
118
|
+
changedContent: [],
|
|
119
|
+
|
|
120
|
+
configDependencies: new Set(),
|
|
121
|
+
contextDependencies: new Set(),
|
|
122
|
+
|
|
123
|
+
/** @type {import('../../lib/content.js').ContentPath[]} */
|
|
124
|
+
contentPaths: [],
|
|
125
|
+
|
|
126
|
+
refreshContentPaths() {
|
|
127
|
+
this.contentPaths = parseCandidateFiles(this.context, this.context?.tailwindConfig)
|
|
128
|
+
},
|
|
129
|
+
|
|
130
|
+
get config() {
|
|
131
|
+
return this.context.tailwindConfig
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
get contentPatterns() {
|
|
135
|
+
return {
|
|
136
|
+
all: this.contentPaths.map((contentPath) => contentPath.pattern),
|
|
137
|
+
dynamic: this.contentPaths
|
|
138
|
+
.filter((contentPath) => contentPath.glob !== undefined)
|
|
139
|
+
.map((contentPath) => contentPath.pattern),
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
|
|
143
|
+
loadConfig(configPath, content) {
|
|
144
|
+
if (this.watcher && configPath) {
|
|
145
|
+
this.refreshConfigDependencies(configPath)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let config = configPath ? require(configPath) : {}
|
|
149
|
+
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
config = resolveConfig(config, { content: { files: [] } })
|
|
152
|
+
|
|
153
|
+
// Override content files if `--content` has been passed explicitly
|
|
154
|
+
if (content?.length > 0) {
|
|
155
|
+
config.content.files = content
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return config
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
refreshConfigDependencies(configPath) {
|
|
162
|
+
env.DEBUG && console.time('Module dependencies')
|
|
163
|
+
|
|
164
|
+
for (let file of this.configDependencies) {
|
|
165
|
+
delete require.cache[require.resolve(file)]
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (configPath) {
|
|
169
|
+
let deps = getModuleDependencies(configPath).map(({ file }) => file)
|
|
170
|
+
|
|
171
|
+
for (let dependency of deps) {
|
|
172
|
+
this.configDependencies.add(dependency)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
env.DEBUG && console.timeEnd('Module dependencies')
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
readContentPaths() {
|
|
180
|
+
let content = []
|
|
181
|
+
|
|
182
|
+
// Resolve globs from the content config
|
|
183
|
+
// TODO: When we make the postcss plugin async-capable this can become async
|
|
184
|
+
let files = fastGlob.sync(this.contentPatterns.all)
|
|
185
|
+
|
|
186
|
+
for (let file of files) {
|
|
187
|
+
content.push({
|
|
188
|
+
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
189
|
+
extension: path.extname(file).slice(1),
|
|
190
|
+
})
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Resolve raw content in the tailwind config
|
|
194
|
+
let rawContent = this.config.content.files.filter((file) => {
|
|
195
|
+
return file !== null && typeof file === 'object'
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
for (let { raw: htmlContent, extension = 'html' } of rawContent) {
|
|
199
|
+
content.push({ content: htmlContent, extension })
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return content
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
getContext({ createContext, cliConfigPath, root, result, content }) {
|
|
206
|
+
if (this.context) {
|
|
207
|
+
this.context.changedContent = this.changedContent.splice(0)
|
|
208
|
+
|
|
209
|
+
return this.context
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
env.DEBUG && console.time('Searching for config')
|
|
213
|
+
let configPath = findAtConfigPath(root, result) ?? cliConfigPath
|
|
214
|
+
env.DEBUG && console.timeEnd('Searching for config')
|
|
215
|
+
|
|
216
|
+
env.DEBUG && console.time('Loading config')
|
|
217
|
+
let config = this.loadConfig(configPath, content)
|
|
218
|
+
env.DEBUG && console.timeEnd('Loading config')
|
|
219
|
+
|
|
220
|
+
env.DEBUG && console.time('Creating context')
|
|
221
|
+
this.context = createContext(config, [])
|
|
222
|
+
Object.assign(this.context, {
|
|
223
|
+
userConfigPath: configPath,
|
|
224
|
+
})
|
|
225
|
+
env.DEBUG && console.timeEnd('Creating context')
|
|
226
|
+
|
|
227
|
+
env.DEBUG && console.time('Resolving content paths')
|
|
228
|
+
this.refreshContentPaths()
|
|
229
|
+
env.DEBUG && console.timeEnd('Resolving content paths')
|
|
230
|
+
|
|
231
|
+
if (this.watcher) {
|
|
232
|
+
env.DEBUG && console.time('Watch new files')
|
|
233
|
+
this.watcher.refreshWatchedFiles()
|
|
234
|
+
env.DEBUG && console.timeEnd('Watch new files')
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
env.DEBUG && console.time('Reading content files')
|
|
238
|
+
for (let file of this.readContentPaths()) {
|
|
239
|
+
this.context.changedContent.push(file)
|
|
240
|
+
}
|
|
241
|
+
env.DEBUG && console.timeEnd('Reading content files')
|
|
242
|
+
|
|
243
|
+
return this.context
|
|
244
|
+
},
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export async function createProcessor(args, cliConfigPath) {
|
|
248
|
+
let postcss = loadPostcss()
|
|
249
|
+
|
|
250
|
+
let input = args['--input']
|
|
251
|
+
let output = args['--output']
|
|
252
|
+
let includePostCss = args['--postcss']
|
|
253
|
+
let customPostCssPath = typeof args['--postcss'] === 'string' ? args['--postcss'] : undefined
|
|
254
|
+
|
|
255
|
+
let [beforePlugins, afterPlugins, postcssOptions] = includePostCss
|
|
256
|
+
? await loadPostCssPlugins(customPostCssPath)
|
|
257
|
+
: loadBuiltinPostcssPlugins()
|
|
258
|
+
|
|
259
|
+
if (args['--purge']) {
|
|
260
|
+
log.warn('purge-flag-deprecated', [
|
|
261
|
+
'The `--purge` flag has been deprecated.',
|
|
262
|
+
'Please use `--content` instead.',
|
|
263
|
+
])
|
|
264
|
+
|
|
265
|
+
if (!args['--content']) {
|
|
266
|
+
args['--content'] = args['--purge']
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let content = args['--content']?.split(/(?<!{[^}]+),/) ?? []
|
|
271
|
+
|
|
272
|
+
let tailwindPlugin = () => {
|
|
273
|
+
return {
|
|
274
|
+
postcssPlugin: 'tailwindcss',
|
|
275
|
+
Once(root, { result }) {
|
|
276
|
+
env.DEBUG && console.time('Compiling CSS')
|
|
277
|
+
tailwind(({ createContext }) => {
|
|
278
|
+
console.error()
|
|
279
|
+
console.error('Rebuilding...')
|
|
280
|
+
|
|
281
|
+
return () => {
|
|
282
|
+
return state.getContext({
|
|
283
|
+
createContext,
|
|
284
|
+
cliConfigPath,
|
|
285
|
+
root,
|
|
286
|
+
result,
|
|
287
|
+
content,
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
})(root, result)
|
|
291
|
+
env.DEBUG && console.timeEnd('Compiling CSS')
|
|
292
|
+
},
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
tailwindPlugin.postcss = true
|
|
297
|
+
|
|
298
|
+
let plugins = [
|
|
299
|
+
...beforePlugins,
|
|
300
|
+
tailwindPlugin,
|
|
301
|
+
!args['--minify'] && formatNodes,
|
|
302
|
+
...afterPlugins,
|
|
303
|
+
!args['--no-autoprefixer'] && loadAutoprefixer(),
|
|
304
|
+
args['--minify'] && loadCssNano(),
|
|
305
|
+
].filter(Boolean)
|
|
306
|
+
|
|
307
|
+
/** @type {import('postcss').Processor} */
|
|
308
|
+
// @ts-ignore
|
|
309
|
+
let processor = postcss(plugins)
|
|
310
|
+
|
|
311
|
+
async function readInput() {
|
|
312
|
+
// Piping in data, let's drain the stdin
|
|
313
|
+
if (input === '-') {
|
|
314
|
+
return drainStdin()
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// Input file has been provided
|
|
318
|
+
if (input) {
|
|
319
|
+
return fs.promises.readFile(path.resolve(input), 'utf8')
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
// No input file provided, fallback to default atrules
|
|
323
|
+
return '@tailwind base; @tailwind components; @tailwind utilities'
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function build() {
|
|
327
|
+
let start = process.hrtime.bigint()
|
|
328
|
+
|
|
329
|
+
return readInput()
|
|
330
|
+
.then((css) => processor.process(css, { ...postcssOptions, from: input, to: output }))
|
|
331
|
+
.then((result) => {
|
|
332
|
+
if (!state.watcher) {
|
|
333
|
+
return result
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
env.DEBUG && console.time('Recording PostCSS dependencies')
|
|
337
|
+
for (let message of result.messages) {
|
|
338
|
+
if (message.type === 'dependency') {
|
|
339
|
+
state.contextDependencies.add(message.file)
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
env.DEBUG && console.timeEnd('Recording PostCSS dependencies')
|
|
343
|
+
|
|
344
|
+
// TODO: This needs to be in a different spot
|
|
345
|
+
env.DEBUG && console.time('Watch new files')
|
|
346
|
+
state.watcher.refreshWatchedFiles()
|
|
347
|
+
env.DEBUG && console.timeEnd('Watch new files')
|
|
348
|
+
|
|
349
|
+
return result
|
|
350
|
+
})
|
|
351
|
+
.then((result) => {
|
|
352
|
+
if (!output) {
|
|
353
|
+
process.stdout.write(result.css)
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return Promise.all([
|
|
358
|
+
outputFile(result.opts.to, result.css),
|
|
359
|
+
result.map && outputFile(result.opts.to + '.map', result.map.toString()),
|
|
360
|
+
])
|
|
361
|
+
})
|
|
362
|
+
.then(() => {
|
|
363
|
+
let end = process.hrtime.bigint()
|
|
364
|
+
console.error()
|
|
365
|
+
console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
|
|
366
|
+
})
|
|
367
|
+
.then(
|
|
368
|
+
() => {},
|
|
369
|
+
(err) => {
|
|
370
|
+
// TODO: If an initial build fails we can't easily pick up any PostCSS dependencies
|
|
371
|
+
// that were collected before the error occurred
|
|
372
|
+
// The result is not stored on the error so we have to store it externally
|
|
373
|
+
// and pull the messages off of it here somehow
|
|
374
|
+
|
|
375
|
+
// This results in a less than ideal DX because the watcher will not pick up
|
|
376
|
+
// changes to imported CSS if one of them caused an error during the initial build
|
|
377
|
+
// If you fix it and then save the main CSS file so there's no error
|
|
378
|
+
// The watcher will start watching the imported CSS files and will be
|
|
379
|
+
// resilient to future errors.
|
|
380
|
+
|
|
381
|
+
console.error(err)
|
|
382
|
+
}
|
|
383
|
+
)
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* @param {{file: string, content(): Promise<string>, extension: string}[]} changes
|
|
388
|
+
*/
|
|
389
|
+
async function parseChanges(changes) {
|
|
390
|
+
return Promise.all(
|
|
391
|
+
changes.map(async (change) => ({
|
|
392
|
+
content: await change.content(),
|
|
393
|
+
extension: change.extension,
|
|
394
|
+
}))
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
if (input !== undefined && input !== '-') {
|
|
399
|
+
state.contextDependencies.add(path.resolve(input))
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
return {
|
|
403
|
+
build,
|
|
404
|
+
watch: async () => {
|
|
405
|
+
state.watcher = createWatcher(args, {
|
|
406
|
+
state,
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* @param {{file: string, content(): Promise<string>, extension: string}[]} changes
|
|
410
|
+
*/
|
|
411
|
+
async rebuild(changes) {
|
|
412
|
+
let needsNewContext = changes.some((change) => {
|
|
413
|
+
return (
|
|
414
|
+
state.configDependencies.has(change.file) ||
|
|
415
|
+
state.contextDependencies.has(change.file)
|
|
416
|
+
)
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
if (needsNewContext) {
|
|
420
|
+
state.context = null
|
|
421
|
+
} else {
|
|
422
|
+
for (let change of await parseChanges(changes)) {
|
|
423
|
+
state.changedContent.push(change)
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
return build()
|
|
428
|
+
},
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
await build()
|
|
432
|
+
},
|
|
433
|
+
}
|
|
434
|
+
}
|