tailwindcss 0.0.0-insiders.fe08e91 → 0.0.0-oxide.6d7c311
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 +384 -3
- package/LICENSE +1 -2
- package/README.md +12 -8
- package/colors.d.ts +3 -0
- package/defaultConfig.d.ts +3 -0
- package/defaultTheme.d.ts +4 -0
- 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 +239 -0
- package/lib/cli/init/index.js +46 -0
- package/lib/cli/shared.js +13 -0
- package/lib/cli-peer-dependencies.js +20 -7
- package/lib/cli.js +4 -740
- package/lib/constants.js +27 -20
- package/lib/corePluginList.js +6 -3
- package/lib/corePlugins.js +2064 -1811
- package/lib/css/preflight.css +5 -5
- package/lib/featureFlags.js +31 -22
- package/lib/index.js +4 -28
- package/lib/lib/cacheInvalidation.js +90 -0
- package/lib/lib/collapseAdjacentRules.js +27 -9
- package/lib/lib/collapseDuplicateDeclarations.js +12 -9
- package/lib/lib/content.js +176 -0
- package/lib/lib/defaultExtractor.js +225 -31
- package/lib/lib/detectNesting.js +13 -10
- package/lib/lib/evaluateTailwindFunctions.js +118 -55
- package/lib/lib/expandApplyAtRules.js +439 -190
- package/lib/lib/expandTailwindAtRules.js +151 -134
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +454 -187
- package/lib/lib/getModuleDependencies.js +11 -8
- package/lib/lib/normalizeTailwindDirectives.js +36 -32
- 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 +89 -67
- package/lib/lib/setupContextUtils.js +667 -376
- package/lib/lib/setupTrackingContext.js +38 -67
- package/lib/lib/sharedState.js +27 -14
- package/lib/lib/substituteScreenAtRules.js +11 -9
- package/lib/oxide/cli.d.js +1 -0
- package/lib/oxide/cli.js +2 -0
- package/lib/oxide/postcss-plugin.d.js +1 -0
- package/lib/oxide/postcss-plugin.js +2 -0
- package/lib/plugin.js +48 -0
- 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 +35 -25
- package/lib/public/colors.js +247 -245
- 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 +11 -6
- package/lib/util/cloneDeep.js +7 -6
- package/lib/util/cloneNodes.js +21 -3
- package/lib/util/color.js +53 -54
- package/lib/util/configurePlugins.js +5 -2
- package/lib/util/createPlugin.js +6 -6
- package/lib/util/createUtilityPlugin.js +12 -14
- package/lib/util/dataTypes.js +119 -110
- package/lib/util/defaults.js +4 -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 +184 -85
- 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 → isSyntacticallyValidPropertyValue.js} +23 -15
- package/lib/util/log.js +20 -14
- package/lib/util/nameClass.js +20 -9
- package/lib/util/negateValue.js +23 -8
- package/lib/util/normalizeConfig.js +116 -72
- package/lib/util/normalizeScreens.js +120 -11
- package/lib/util/parseAnimationValue.js +42 -40
- package/lib/util/parseBoxShadowValue.js +30 -23
- 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 +147 -50
- package/lib/util/prefixSelector.js +10 -8
- package/lib/util/removeAlphaVariables.js +29 -0
- package/lib/util/resolveConfig.js +97 -85
- 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 +20 -4
- package/lib/util/transformThemeValue.js +37 -29
- 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 +52 -46
- package/peers/index.js +11381 -7950
- 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/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 +234 -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 +4 -810
- package/src/corePluginList.js +1 -1
- package/src/corePlugins.js +532 -217
- package/src/css/preflight.css +5 -5
- package/src/featureFlags.js +15 -9
- package/src/index.js +4 -27
- package/src/lib/cacheInvalidation.js +52 -0
- package/src/lib/collapseAdjacentRules.js +21 -2
- package/src/lib/content.js +212 -0
- package/src/lib/defaultExtractor.js +196 -33
- package/src/lib/evaluateTailwindFunctions.js +78 -7
- package/src/lib/expandApplyAtRules.js +482 -183
- package/src/lib/expandTailwindAtRules.js +106 -85
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +418 -129
- package/src/lib/normalizeTailwindDirectives.js +1 -0
- 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 +51 -30
- package/src/lib/setupContextUtils.js +556 -208
- package/src/lib/setupTrackingContext.js +11 -48
- package/src/lib/sharedState.js +5 -0
- package/src/oxide/cli.d.ts +0 -0
- package/src/oxide/cli.ts +1 -0
- package/src/oxide/postcss-plugin.d.ts +0 -0
- package/src/oxide/postcss-plugin.ts +1 -0
- package/src/plugin.js +47 -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 +8 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/cloneNodes.js +19 -2
- package/src/util/color.js +25 -21
- package/src/util/dataTypes.js +29 -21
- package/src/util/formatVariantSelector.js +184 -61
- package/src/util/getAllConfigs.js +19 -0
- package/src/util/{isValidArbitraryValue.js → isSyntacticallyValidPropertyValue.js} +1 -1
- package/src/util/log.js +8 -8
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +11 -3
- package/src/util/normalizeConfig.js +44 -6
- 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 +132 -10
- package/src/util/prefixSelector.js +7 -5
- package/src/util/removeAlphaVariables.js +24 -0
- package/src/util/resolveConfig.js +70 -32
- 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 +167 -164
- package/stubs/simpleConfig.stub.js +1 -0
- 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/nesting/plugin.js +0 -41
package/src/cli.js
CHANGED
|
@@ -1,813 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import arg from 'arg'
|
|
8
|
-
import fs from 'fs'
|
|
9
|
-
import postcssrc from 'postcss-load-config'
|
|
10
|
-
import { cosmiconfig } from 'cosmiconfig'
|
|
11
|
-
import loadPlugins from 'postcss-load-config/src/plugins' // Little bit scary, looking at private/internal API
|
|
12
|
-
import tailwind from './processTailwindFeatures'
|
|
13
|
-
import resolveConfigInternal from '../resolveConfig'
|
|
14
|
-
import fastGlob from 'fast-glob'
|
|
15
|
-
import getModuleDependencies from './lib/getModuleDependencies'
|
|
16
|
-
import log from './util/log'
|
|
17
|
-
import packageJson from '../package.json'
|
|
18
|
-
import normalizePath from 'normalize-path'
|
|
19
|
-
|
|
20
|
-
let env = {
|
|
21
|
-
DEBUG: process.env.DEBUG !== undefined && process.env.DEBUG !== '0',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ---
|
|
25
|
-
|
|
26
|
-
function indentRecursive(node, indent = 0) {
|
|
27
|
-
node.each &&
|
|
28
|
-
node.each((child, i) => {
|
|
29
|
-
if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes('\n')) {
|
|
30
|
-
child.raws.before = `\n${node.type !== 'rule' && i > 0 ? '\n' : ''}${' '.repeat(indent)}`
|
|
31
|
-
}
|
|
32
|
-
child.raws.after = `\n${' '.repeat(indent)}`
|
|
33
|
-
indentRecursive(child, indent + 1)
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function formatNodes(root) {
|
|
38
|
-
indentRecursive(root)
|
|
39
|
-
if (root.first) {
|
|
40
|
-
root.first.raws.before = ''
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function outputFile(file, contents) {
|
|
45
|
-
if (fs.existsSync(file) && (await fs.promises.readFile(file, 'utf8')) === contents) {
|
|
46
|
-
return // Skip writing the file
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Write the file
|
|
50
|
-
await fs.promises.writeFile(file, contents, 'utf8')
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function drainStdin() {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
let result = ''
|
|
56
|
-
process.stdin.on('data', (chunk) => {
|
|
57
|
-
result += chunk
|
|
58
|
-
})
|
|
59
|
-
process.stdin.on('end', () => resolve(result))
|
|
60
|
-
process.stdin.on('error', (err) => reject(err))
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function help({ message, usage, commands, options }) {
|
|
65
|
-
let indent = 2
|
|
66
|
-
|
|
67
|
-
// Render header
|
|
68
|
-
console.log()
|
|
69
|
-
console.log(`${packageJson.name} v${packageJson.version}`)
|
|
70
|
-
|
|
71
|
-
// Render message
|
|
72
|
-
if (message) {
|
|
73
|
-
console.log()
|
|
74
|
-
for (let msg of message.split('\n')) {
|
|
75
|
-
console.log(msg)
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Render usage
|
|
80
|
-
if (usage && usage.length > 0) {
|
|
81
|
-
console.log()
|
|
82
|
-
console.log('Usage:')
|
|
83
|
-
for (let example of usage) {
|
|
84
|
-
console.log(' '.repeat(indent), example)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Render commands
|
|
89
|
-
if (commands && commands.length > 0) {
|
|
90
|
-
console.log()
|
|
91
|
-
console.log('Commands:')
|
|
92
|
-
for (let command of commands) {
|
|
93
|
-
console.log(' '.repeat(indent), command)
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Render options
|
|
98
|
-
if (options) {
|
|
99
|
-
let groupedOptions = {}
|
|
100
|
-
for (let [key, value] of Object.entries(options)) {
|
|
101
|
-
if (typeof value === 'object') {
|
|
102
|
-
groupedOptions[key] = { ...value, flags: [key] }
|
|
103
|
-
} else {
|
|
104
|
-
groupedOptions[value].flags.push(key)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
console.log()
|
|
109
|
-
console.log('Options:')
|
|
110
|
-
for (let { flags, description, deprecated } of Object.values(groupedOptions)) {
|
|
111
|
-
if (deprecated) continue
|
|
112
|
-
|
|
113
|
-
if (flags.length === 1) {
|
|
114
|
-
console.log(
|
|
115
|
-
' '.repeat(indent + 4 /* 4 = "-i, ".length */),
|
|
116
|
-
flags.slice().reverse().join(', ').padEnd(20, ' '),
|
|
117
|
-
description
|
|
118
|
-
)
|
|
119
|
-
} else {
|
|
120
|
-
console.log(
|
|
121
|
-
' '.repeat(indent),
|
|
122
|
-
flags.slice().reverse().join(', ').padEnd(24, ' '),
|
|
123
|
-
description
|
|
124
|
-
)
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
console.log()
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function oneOf(...options) {
|
|
133
|
-
return Object.assign(
|
|
134
|
-
(value = true) => {
|
|
135
|
-
for (let option of options) {
|
|
136
|
-
let parsed = option(value)
|
|
137
|
-
if (parsed === value) {
|
|
138
|
-
return parsed
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
throw new Error('...')
|
|
143
|
-
},
|
|
144
|
-
{ manualParsing: true }
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
let commands = {
|
|
149
|
-
init: {
|
|
150
|
-
run: init,
|
|
151
|
-
args: {
|
|
152
|
-
'--full': { type: Boolean, description: 'Initialize a full `tailwind.config.js` file' },
|
|
153
|
-
'--postcss': { type: Boolean, description: 'Initialize a `postcss.config.js` file' },
|
|
154
|
-
'-f': '--full',
|
|
155
|
-
'-p': '--postcss',
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
build: {
|
|
159
|
-
run: build,
|
|
160
|
-
args: {
|
|
161
|
-
'--input': { type: String, description: 'Input file' },
|
|
162
|
-
'--output': { type: String, description: 'Output file' },
|
|
163
|
-
'--watch': { type: Boolean, description: 'Watch for changes and rebuild as needed' },
|
|
164
|
-
'--content': {
|
|
165
|
-
type: String,
|
|
166
|
-
description: 'Content paths to use for removing unused classes',
|
|
167
|
-
},
|
|
168
|
-
'--purge': {
|
|
169
|
-
type: String,
|
|
170
|
-
deprecated: true,
|
|
171
|
-
},
|
|
172
|
-
'--postcss': {
|
|
173
|
-
type: oneOf(String, Boolean),
|
|
174
|
-
description: 'Load custom PostCSS configuration',
|
|
175
|
-
},
|
|
176
|
-
'--minify': { type: Boolean, description: 'Minify the output' },
|
|
177
|
-
'--config': {
|
|
178
|
-
type: String,
|
|
179
|
-
description: 'Path to a custom config file',
|
|
180
|
-
},
|
|
181
|
-
'--no-autoprefixer': {
|
|
182
|
-
type: Boolean,
|
|
183
|
-
description: 'Disable autoprefixer',
|
|
184
|
-
},
|
|
185
|
-
'-c': '--config',
|
|
186
|
-
'-i': '--input',
|
|
187
|
-
'-o': '--output',
|
|
188
|
-
'-m': '--minify',
|
|
189
|
-
'-w': '--watch',
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
let sharedFlags = {
|
|
195
|
-
'--help': { type: Boolean, description: 'Display usage information' },
|
|
196
|
-
'-h': '--help',
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
process.stdout.isTTY /* Detect redirecting output to a file */ &&
|
|
201
|
-
(process.argv[2] === undefined ||
|
|
202
|
-
process.argv.slice(2).every((flag) => sharedFlags[flag] !== undefined))
|
|
203
|
-
) {
|
|
204
|
-
help({
|
|
205
|
-
usage: [
|
|
206
|
-
'tailwindcss [--input input.css] [--output output.css] [--watch] [options...]',
|
|
207
|
-
'tailwindcss init [--full] [--postcss] [options...]',
|
|
208
|
-
],
|
|
209
|
-
commands: Object.keys(commands)
|
|
210
|
-
.filter((command) => command !== 'build')
|
|
211
|
-
.map((command) => `${command} [options]`),
|
|
212
|
-
options: { ...commands.build.args, ...sharedFlags },
|
|
213
|
-
})
|
|
214
|
-
process.exit(0)
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
let command = ((arg = '') => (arg.startsWith('-') ? undefined : arg))(process.argv[2]) || 'build'
|
|
218
|
-
|
|
219
|
-
if (commands[command] === undefined) {
|
|
220
|
-
if (fs.existsSync(path.resolve(command))) {
|
|
221
|
-
// TODO: Deprecate this in future versions
|
|
222
|
-
// Check if non-existing command, might be a file.
|
|
223
|
-
command = 'build'
|
|
224
|
-
} else {
|
|
225
|
-
help({
|
|
226
|
-
message: `Invalid command: ${command}`,
|
|
227
|
-
usage: ['tailwindcss <command> [options]'],
|
|
228
|
-
commands: Object.keys(commands)
|
|
229
|
-
.filter((command) => command !== 'build')
|
|
230
|
-
.map((command) => `${command} [options]`),
|
|
231
|
-
options: sharedFlags,
|
|
232
|
-
})
|
|
233
|
-
process.exit(1)
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// Execute command
|
|
238
|
-
let { args: flags, run } = commands[command]
|
|
239
|
-
let args = (() => {
|
|
240
|
-
try {
|
|
241
|
-
let result = arg(
|
|
242
|
-
Object.fromEntries(
|
|
243
|
-
Object.entries({ ...flags, ...sharedFlags })
|
|
244
|
-
.filter(([_key, value]) => !value?.type?.manualParsing)
|
|
245
|
-
.map(([key, value]) => [key, typeof value === 'object' ? value.type : value])
|
|
246
|
-
),
|
|
247
|
-
{ permissive: true }
|
|
248
|
-
)
|
|
249
|
-
|
|
250
|
-
// Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
|
|
251
|
-
for (let i = result['_'].length - 1; i >= 0; --i) {
|
|
252
|
-
let flag = result['_'][i]
|
|
253
|
-
if (!flag.startsWith('-')) continue
|
|
254
|
-
|
|
255
|
-
let flagName = flag
|
|
256
|
-
let handler = flags[flag]
|
|
257
|
-
|
|
258
|
-
// Resolve flagName & handler
|
|
259
|
-
while (typeof handler === 'string') {
|
|
260
|
-
flagName = handler
|
|
261
|
-
handler = flags[handler]
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (!handler) continue
|
|
265
|
-
|
|
266
|
-
let args = []
|
|
267
|
-
let offset = i + 1
|
|
268
|
-
|
|
269
|
-
// Parse args for current flag
|
|
270
|
-
while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
|
|
271
|
-
args.push(result['_'][offset++])
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// Cleanup manually parsed flags + args
|
|
275
|
-
result['_'].splice(i, 1 + args.length)
|
|
276
|
-
|
|
277
|
-
// Set the resolved value in the `result` object
|
|
278
|
-
result[flagName] = handler.type(
|
|
279
|
-
args.length === 0 ? undefined : args.length === 1 ? args[0] : args,
|
|
280
|
-
flagName
|
|
281
|
-
)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// Ensure that the `command` is always the first argument in the `args`.
|
|
285
|
-
// This is important so that we don't have to check if a default command
|
|
286
|
-
// (build) was used or not from within each plugin.
|
|
287
|
-
//
|
|
288
|
-
// E.g.: tailwindcss input.css -> _: ['build', 'input.css']
|
|
289
|
-
// E.g.: tailwindcss build input.css -> _: ['build', 'input.css']
|
|
290
|
-
if (result['_'][0] !== command) {
|
|
291
|
-
result['_'].unshift(command)
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return result
|
|
295
|
-
} catch (err) {
|
|
296
|
-
if (err.code === 'ARG_UNKNOWN_OPTION') {
|
|
297
|
-
help({
|
|
298
|
-
message: err.message,
|
|
299
|
-
usage: ['tailwindcss <command> [options]'],
|
|
300
|
-
options: sharedFlags,
|
|
301
|
-
})
|
|
302
|
-
process.exit(1)
|
|
303
|
-
}
|
|
304
|
-
throw err
|
|
305
|
-
}
|
|
306
|
-
})()
|
|
307
|
-
|
|
308
|
-
if (args['--help']) {
|
|
309
|
-
help({
|
|
310
|
-
options: { ...flags, ...sharedFlags },
|
|
311
|
-
usage: [`tailwindcss ${command} [options]`],
|
|
312
|
-
})
|
|
313
|
-
process.exit(0)
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
run()
|
|
317
|
-
|
|
318
|
-
// ---
|
|
319
|
-
|
|
320
|
-
function init() {
|
|
321
|
-
let messages = []
|
|
322
|
-
|
|
323
|
-
let tailwindConfigLocation = path.resolve(args['_'][1] ?? './tailwind.config.js')
|
|
324
|
-
if (fs.existsSync(tailwindConfigLocation)) {
|
|
325
|
-
messages.push(`${path.basename(tailwindConfigLocation)} already exists.`)
|
|
326
|
-
} else {
|
|
327
|
-
let stubFile = fs.readFileSync(
|
|
328
|
-
args['--full']
|
|
329
|
-
? path.resolve(__dirname, '../stubs/defaultConfig.stub.js')
|
|
330
|
-
: path.resolve(__dirname, '../stubs/simpleConfig.stub.js'),
|
|
331
|
-
'utf8'
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
// Change colors import
|
|
335
|
-
stubFile = stubFile.replace('../colors', 'tailwindcss/colors')
|
|
336
|
-
|
|
337
|
-
fs.writeFileSync(tailwindConfigLocation, stubFile, 'utf8')
|
|
338
|
-
|
|
339
|
-
messages.push(`Created Tailwind CSS config file: ${path.basename(tailwindConfigLocation)}`)
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (args['--postcss']) {
|
|
343
|
-
let postcssConfigLocation = path.resolve('./postcss.config.js')
|
|
344
|
-
if (fs.existsSync(postcssConfigLocation)) {
|
|
345
|
-
messages.push(`${path.basename(postcssConfigLocation)} already exists.`)
|
|
346
|
-
} else {
|
|
347
|
-
let stubFile = fs.readFileSync(
|
|
348
|
-
path.resolve(__dirname, '../stubs/defaultPostCssConfig.stub.js'),
|
|
349
|
-
'utf8'
|
|
350
|
-
)
|
|
351
|
-
|
|
352
|
-
fs.writeFileSync(postcssConfigLocation, stubFile, 'utf8')
|
|
353
|
-
|
|
354
|
-
messages.push(`Created PostCSS config file: ${path.basename(postcssConfigLocation)}`)
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (messages.length > 0) {
|
|
359
|
-
console.log()
|
|
360
|
-
for (let message of messages) {
|
|
361
|
-
console.log(message)
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
async function build() {
|
|
367
|
-
let input = args['--input']
|
|
368
|
-
let output = args['--output']
|
|
369
|
-
let shouldWatch = args['--watch']
|
|
370
|
-
let includePostCss = args['--postcss']
|
|
371
|
-
|
|
372
|
-
// TODO: Deprecate this in future versions
|
|
373
|
-
if (!input && args['_'][1]) {
|
|
374
|
-
console.error('[deprecation] Running tailwindcss without -i, please provide an input file.')
|
|
375
|
-
input = args['--input'] = args['_'][1]
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
if (input && input !== '-' && !fs.existsSync((input = path.resolve(input)))) {
|
|
379
|
-
console.error(`Specified input file ${args['--input']} does not exist.`)
|
|
380
|
-
process.exit(9)
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (args['--config'] && !fs.existsSync((args['--config'] = path.resolve(args['--config'])))) {
|
|
384
|
-
console.error(`Specified config file ${args['--config']} does not exist.`)
|
|
385
|
-
process.exit(9)
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
let configPath = args['--config']
|
|
389
|
-
? args['--config']
|
|
390
|
-
: ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))(
|
|
391
|
-
path.resolve('./tailwind.config.js')
|
|
392
|
-
)
|
|
393
|
-
|
|
394
|
-
async function loadPostCssPlugins() {
|
|
395
|
-
let customPostCssPath = typeof args['--postcss'] === 'string' ? args['--postcss'] : undefined
|
|
396
|
-
let { plugins: configPlugins } = customPostCssPath
|
|
397
|
-
? await (async () => {
|
|
398
|
-
let file = path.resolve(customPostCssPath)
|
|
399
|
-
|
|
400
|
-
// Implementation, see: https://unpkg.com/browse/postcss-load-config@3.0.1/src/index.js
|
|
401
|
-
let { config = {} } = await cosmiconfig('postcss').load(file)
|
|
402
|
-
if (typeof config === 'function') {
|
|
403
|
-
config = config()
|
|
404
|
-
} else {
|
|
405
|
-
config = Object.assign({}, config)
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
if (!config.plugins) {
|
|
409
|
-
config.plugins = []
|
|
410
|
-
}
|
|
411
|
-
|
|
412
|
-
return { plugins: loadPlugins(config, file) }
|
|
413
|
-
})()
|
|
414
|
-
: await postcssrc()
|
|
415
|
-
|
|
416
|
-
let configPluginTailwindIdx = configPlugins.findIndex((plugin) => {
|
|
417
|
-
if (typeof plugin === 'function' && plugin.name === 'tailwindcss') {
|
|
418
|
-
return true
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (typeof plugin === 'object' && plugin !== null && plugin.postcssPlugin === 'tailwindcss') {
|
|
422
|
-
return true
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
return false
|
|
426
|
-
})
|
|
427
|
-
|
|
428
|
-
let beforePlugins =
|
|
429
|
-
configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx)
|
|
430
|
-
let afterPlugins =
|
|
431
|
-
configPluginTailwindIdx === -1
|
|
432
|
-
? configPlugins
|
|
433
|
-
: configPlugins.slice(configPluginTailwindIdx + 1)
|
|
434
|
-
|
|
435
|
-
return [beforePlugins, afterPlugins]
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
function resolveConfig() {
|
|
439
|
-
let config = configPath ? require(configPath) : {}
|
|
440
|
-
let resolvedConfig = resolveConfigInternal(config)
|
|
441
|
-
|
|
442
|
-
if (args['--purge']) {
|
|
443
|
-
log.warn('purge-flag-deprecated', [
|
|
444
|
-
'The `--purge` flag has been deprecated.',
|
|
445
|
-
'Please use `--content` instead.',
|
|
446
|
-
])
|
|
447
|
-
if (!args['--content']) {
|
|
448
|
-
args['--content'] = args['--purge']
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
if (args['--content']) {
|
|
453
|
-
resolvedConfig.content.files = args['--content'].split(/(?<!{[^}]+),/)
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
return resolvedConfig
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function extractFileGlobs(config) {
|
|
460
|
-
return config.content.files
|
|
461
|
-
.filter((file) => {
|
|
462
|
-
// Strings in this case are files / globs. If it is something else,
|
|
463
|
-
// like an object it's probably a raw content object. But this object
|
|
464
|
-
// is not watchable, so let's remove it.
|
|
465
|
-
return typeof file === 'string'
|
|
466
|
-
})
|
|
467
|
-
.map((glob) => normalizePath(glob))
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function extractRawContent(config) {
|
|
471
|
-
return config.content.files.filter((file) => {
|
|
472
|
-
return typeof file === 'object' && file !== null
|
|
473
|
-
})
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
function getChangedContent(config) {
|
|
477
|
-
let changedContent = []
|
|
478
|
-
|
|
479
|
-
// Resolve globs from the content config
|
|
480
|
-
let globs = extractFileGlobs(config)
|
|
481
|
-
let files = fastGlob.sync(globs)
|
|
482
|
-
|
|
483
|
-
for (let file of files) {
|
|
484
|
-
changedContent.push({
|
|
485
|
-
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
486
|
-
extension: path.extname(file).slice(1),
|
|
487
|
-
})
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Resolve raw content in the tailwind config
|
|
491
|
-
for (let { raw: content, extension = 'html' } of extractRawContent(config)) {
|
|
492
|
-
changedContent.push({ content, extension })
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
return changedContent
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
async function buildOnce() {
|
|
499
|
-
let config = resolveConfig()
|
|
500
|
-
let changedContent = getChangedContent(config)
|
|
501
|
-
|
|
502
|
-
let tailwindPlugin = () => {
|
|
503
|
-
return {
|
|
504
|
-
postcssPlugin: 'tailwindcss',
|
|
505
|
-
Once(root, { result }) {
|
|
506
|
-
tailwind(({ createContext }) => {
|
|
507
|
-
return () => {
|
|
508
|
-
return createContext(config, changedContent)
|
|
509
|
-
}
|
|
510
|
-
})(root, result)
|
|
511
|
-
},
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
tailwindPlugin.postcss = true
|
|
516
|
-
|
|
517
|
-
let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [[], []]
|
|
518
|
-
|
|
519
|
-
let plugins = [
|
|
520
|
-
...beforePlugins,
|
|
521
|
-
tailwindPlugin,
|
|
522
|
-
!args['--minify'] && formatNodes,
|
|
523
|
-
...afterPlugins,
|
|
524
|
-
!args['--no-autoprefixer'] &&
|
|
525
|
-
(() => {
|
|
526
|
-
// Try to load a local `autoprefixer` version first
|
|
527
|
-
try {
|
|
528
|
-
return require('autoprefixer')
|
|
529
|
-
} catch {}
|
|
530
|
-
|
|
531
|
-
return lazyAutoprefixer()
|
|
532
|
-
})(),
|
|
533
|
-
args['--minify'] &&
|
|
534
|
-
(() => {
|
|
535
|
-
let options = { preset: ['default', { cssDeclarationSorter: false }] }
|
|
536
|
-
|
|
537
|
-
// Try to load a local `cssnano` version first
|
|
538
|
-
try {
|
|
539
|
-
return require('cssnano')
|
|
540
|
-
} catch {}
|
|
541
|
-
|
|
542
|
-
return lazyCssnano()(options)
|
|
543
|
-
})(),
|
|
544
|
-
].filter(Boolean)
|
|
545
|
-
|
|
546
|
-
let processor = postcss(plugins)
|
|
547
|
-
|
|
548
|
-
function processCSS(css) {
|
|
549
|
-
let start = process.hrtime.bigint()
|
|
550
|
-
return Promise.resolve()
|
|
551
|
-
.then(() => (output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null))
|
|
552
|
-
.then(() => processor.process(css, { from: input, to: output }))
|
|
553
|
-
.then((result) => {
|
|
554
|
-
if (!output) {
|
|
555
|
-
return process.stdout.write(result.css)
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return Promise.all(
|
|
559
|
-
[
|
|
560
|
-
outputFile(output, result.css),
|
|
561
|
-
result.map && outputFile(output + '.map', result.map.toString()),
|
|
562
|
-
].filter(Boolean)
|
|
563
|
-
)
|
|
564
|
-
})
|
|
565
|
-
.then(() => {
|
|
566
|
-
let end = process.hrtime.bigint()
|
|
567
|
-
console.error()
|
|
568
|
-
console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
|
|
569
|
-
})
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
let css = await (() => {
|
|
573
|
-
// Piping in data, let's drain the stdin
|
|
574
|
-
if (input === '-') {
|
|
575
|
-
return drainStdin()
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
// Input file has been provided
|
|
579
|
-
if (input) {
|
|
580
|
-
return fs.readFileSync(path.resolve(input), 'utf8')
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// No input file provided, fallback to default atrules
|
|
584
|
-
return '@tailwind base; @tailwind components; @tailwind utilities'
|
|
585
|
-
})()
|
|
586
|
-
|
|
587
|
-
return processCSS(css)
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
let context = null
|
|
591
|
-
|
|
592
|
-
async function startWatcher() {
|
|
593
|
-
let changedContent = []
|
|
594
|
-
let configDependencies = []
|
|
595
|
-
let contextDependencies = new Set()
|
|
596
|
-
let watcher = null
|
|
597
|
-
|
|
598
|
-
function refreshConfig() {
|
|
599
|
-
env.DEBUG && console.time('Module dependencies')
|
|
600
|
-
for (let file of configDependencies) {
|
|
601
|
-
delete require.cache[require.resolve(file)]
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
if (configPath) {
|
|
605
|
-
configDependencies = getModuleDependencies(configPath).map(({ file }) => file)
|
|
606
|
-
|
|
607
|
-
for (let dependency of configDependencies) {
|
|
608
|
-
contextDependencies.add(dependency)
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
env.DEBUG && console.timeEnd('Module dependencies')
|
|
612
|
-
|
|
613
|
-
return resolveConfig()
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
let [beforePlugins, afterPlugins] = includePostCss ? await loadPostCssPlugins() : [[], []]
|
|
617
|
-
|
|
618
|
-
let plugins = [
|
|
619
|
-
...beforePlugins,
|
|
620
|
-
'__TAILWIND_PLUGIN_POSITION__',
|
|
621
|
-
!args['--minify'] && formatNodes,
|
|
622
|
-
...afterPlugins,
|
|
623
|
-
!args['--no-autoprefixer'] &&
|
|
624
|
-
(() => {
|
|
625
|
-
// Try to load a local `autoprefixer` version first
|
|
626
|
-
try {
|
|
627
|
-
return require('autoprefixer')
|
|
628
|
-
} catch {}
|
|
629
|
-
|
|
630
|
-
return lazyAutoprefixer()
|
|
631
|
-
})(),
|
|
632
|
-
args['--minify'] &&
|
|
633
|
-
(() => {
|
|
634
|
-
let options = { preset: ['default', { cssDeclarationSorter: false }] }
|
|
635
|
-
|
|
636
|
-
// Try to load a local `cssnano` version first
|
|
637
|
-
try {
|
|
638
|
-
return require('cssnano')
|
|
639
|
-
} catch {}
|
|
640
|
-
|
|
641
|
-
return lazyCssnano()(options)
|
|
642
|
-
})(),
|
|
643
|
-
].filter(Boolean)
|
|
644
|
-
|
|
645
|
-
async function rebuild(config) {
|
|
646
|
-
env.DEBUG && console.time('Finished in')
|
|
647
|
-
|
|
648
|
-
let tailwindPlugin = () => {
|
|
649
|
-
return {
|
|
650
|
-
postcssPlugin: 'tailwindcss',
|
|
651
|
-
Once(root, { result }) {
|
|
652
|
-
env.DEBUG && console.time('Compiling CSS')
|
|
653
|
-
tailwind(({ createContext }) => {
|
|
654
|
-
console.error()
|
|
655
|
-
console.error('Rebuilding...')
|
|
656
|
-
|
|
657
|
-
return () => {
|
|
658
|
-
if (context !== null) {
|
|
659
|
-
context.changedContent = changedContent.splice(0)
|
|
660
|
-
return context
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
env.DEBUG && console.time('Creating context')
|
|
664
|
-
context = createContext(config, changedContent.splice(0))
|
|
665
|
-
env.DEBUG && console.timeEnd('Creating context')
|
|
666
|
-
return context
|
|
667
|
-
}
|
|
668
|
-
})(root, result)
|
|
669
|
-
env.DEBUG && console.timeEnd('Compiling CSS')
|
|
670
|
-
},
|
|
671
|
-
}
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
tailwindPlugin.postcss = true
|
|
675
|
-
|
|
676
|
-
let tailwindPluginIdx = plugins.indexOf('__TAILWIND_PLUGIN_POSITION__')
|
|
677
|
-
let copy = plugins.slice()
|
|
678
|
-
copy.splice(tailwindPluginIdx, 1, tailwindPlugin)
|
|
679
|
-
let processor = postcss(copy)
|
|
680
|
-
|
|
681
|
-
function processCSS(css) {
|
|
682
|
-
let start = process.hrtime.bigint()
|
|
683
|
-
return Promise.resolve()
|
|
684
|
-
.then(() =>
|
|
685
|
-
output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null
|
|
686
|
-
)
|
|
687
|
-
.then(() => processor.process(css, { from: input, to: output }))
|
|
688
|
-
.then(async (result) => {
|
|
689
|
-
for (let message of result.messages) {
|
|
690
|
-
if (message.type === 'dependency') {
|
|
691
|
-
contextDependencies.add(message.file)
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
watcher.add([...contextDependencies])
|
|
695
|
-
|
|
696
|
-
if (!output) {
|
|
697
|
-
return process.stdout.write(result.css)
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
return Promise.all(
|
|
701
|
-
[
|
|
702
|
-
outputFile(output, result.css),
|
|
703
|
-
result.map && outputFile(output + '.map', result.map.toString()),
|
|
704
|
-
].filter(Boolean)
|
|
705
|
-
)
|
|
706
|
-
})
|
|
707
|
-
.then(() => {
|
|
708
|
-
let end = process.hrtime.bigint()
|
|
709
|
-
console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
|
|
710
|
-
})
|
|
711
|
-
.catch((err) => {
|
|
712
|
-
if (err.name === 'CssSyntaxError') {
|
|
713
|
-
console.error(err.toString())
|
|
714
|
-
} else {
|
|
715
|
-
console.error(err)
|
|
716
|
-
}
|
|
717
|
-
})
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
let css = await (() => {
|
|
721
|
-
// Piping in data, let's drain the stdin
|
|
722
|
-
if (input === '-') {
|
|
723
|
-
return drainStdin()
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// Input file has been provided
|
|
727
|
-
if (input) {
|
|
728
|
-
return fs.readFileSync(path.resolve(input), 'utf8')
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// No input file provided, fallback to default atrules
|
|
732
|
-
return '@tailwind base; @tailwind components; @tailwind utilities'
|
|
733
|
-
})()
|
|
734
|
-
|
|
735
|
-
let result = await processCSS(css)
|
|
736
|
-
env.DEBUG && console.timeEnd('Finished in')
|
|
737
|
-
return result
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
let config = refreshConfig(configPath)
|
|
741
|
-
|
|
742
|
-
if (input) {
|
|
743
|
-
contextDependencies.add(path.resolve(input))
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
watcher = chokidar.watch([...contextDependencies, ...extractFileGlobs(config)], {
|
|
747
|
-
ignoreInitial: true,
|
|
748
|
-
awaitWriteFinish:
|
|
749
|
-
process.platform === 'win32'
|
|
750
|
-
? {
|
|
751
|
-
stabilityThreshold: 50,
|
|
752
|
-
pollInterval: 10,
|
|
753
|
-
}
|
|
754
|
-
: false,
|
|
755
|
-
})
|
|
756
|
-
|
|
757
|
-
let chain = Promise.resolve()
|
|
758
|
-
|
|
759
|
-
watcher.on('change', async (file) => {
|
|
760
|
-
if (contextDependencies.has(file)) {
|
|
761
|
-
env.DEBUG && console.time('Resolve config')
|
|
762
|
-
context = null
|
|
763
|
-
config = refreshConfig(configPath)
|
|
764
|
-
env.DEBUG && console.timeEnd('Resolve config')
|
|
765
|
-
|
|
766
|
-
env.DEBUG && console.time('Watch new files')
|
|
767
|
-
let globs = extractFileGlobs(config)
|
|
768
|
-
watcher.add(configDependencies)
|
|
769
|
-
watcher.add(globs)
|
|
770
|
-
env.DEBUG && console.timeEnd('Watch new files')
|
|
771
|
-
|
|
772
|
-
chain = chain.then(async () => {
|
|
773
|
-
changedContent.push(...getChangedContent(config))
|
|
774
|
-
await rebuild(config)
|
|
775
|
-
})
|
|
776
|
-
} else {
|
|
777
|
-
chain = chain.then(async () => {
|
|
778
|
-
changedContent.push({
|
|
779
|
-
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
780
|
-
extension: path.extname(file).slice(1),
|
|
781
|
-
})
|
|
782
|
-
|
|
783
|
-
await rebuild(config)
|
|
784
|
-
})
|
|
785
|
-
}
|
|
786
|
-
})
|
|
787
|
-
|
|
788
|
-
watcher.on('add', async (file) => {
|
|
789
|
-
chain = chain.then(async () => {
|
|
790
|
-
changedContent.push({
|
|
791
|
-
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
792
|
-
extension: path.extname(file).slice(1),
|
|
793
|
-
})
|
|
794
|
-
|
|
795
|
-
await rebuild(config)
|
|
796
|
-
})
|
|
797
|
-
})
|
|
798
|
-
|
|
799
|
-
chain = chain.then(() => {
|
|
800
|
-
changedContent.push(...getChangedContent(config))
|
|
801
|
-
return rebuild(config)
|
|
802
|
-
})
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
if (shouldWatch) {
|
|
806
|
-
/* Abort the watcher if stdin is closed to avoid zombie processes */
|
|
807
|
-
process.stdin.on('end', () => process.exit(0))
|
|
808
|
-
process.stdin.resume()
|
|
809
|
-
startWatcher()
|
|
810
|
-
} else {
|
|
811
|
-
buildOnce()
|
|
812
|
-
}
|
|
3
|
+
if (process.env.OXIDE) {
|
|
4
|
+
module.exports = require('./oxide/cli')
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require('./cli/index')
|
|
813
7
|
}
|