tailwindcss 3.1.8 → 3.2.1
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 +64 -3
- package/README.md +6 -5
- package/lib/cli/build/deps.js +54 -0
- package/lib/cli/build/index.js +44 -0
- package/lib/cli/build/plugin.js +351 -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.js +11 -590
- package/lib/corePlugins.js +332 -108
- package/lib/css/preflight.css +5 -0
- package/lib/featureFlags.js +7 -4
- package/lib/index.js +6 -1
- package/lib/lib/content.js +167 -0
- package/lib/lib/defaultExtractor.js +15 -10
- package/lib/lib/detectNesting.js +2 -2
- package/lib/lib/evaluateTailwindFunctions.js +17 -1
- package/lib/lib/expandApplyAtRules.js +66 -37
- package/lib/lib/expandTailwindAtRules.js +10 -42
- package/lib/lib/findAtConfigPath.js +44 -0
- package/lib/lib/generateRules.js +180 -93
- package/lib/lib/normalizeTailwindDirectives.js +1 -1
- package/lib/lib/offsets.js +217 -0
- package/lib/lib/regex.js +1 -1
- package/lib/lib/setupContextUtils.js +339 -100
- package/lib/lib/setupTrackingContext.js +5 -39
- package/lib/lib/sharedState.js +2 -0
- package/lib/public/colors.js +1 -1
- package/lib/util/buildMediaQuery.js +6 -3
- package/lib/util/configurePlugins.js +1 -1
- package/lib/util/dataTypes.js +15 -19
- package/lib/util/formatVariantSelector.js +92 -8
- package/lib/util/getAllConfigs.js +14 -3
- package/lib/util/isValidArbitraryValue.js +1 -1
- package/lib/util/nameClass.js +3 -0
- package/lib/util/negateValue.js +15 -2
- package/lib/util/normalizeConfig.js +17 -3
- package/lib/util/normalizeScreens.js +100 -3
- package/lib/util/parseAnimationValue.js +1 -1
- package/lib/util/parseBoxShadowValue.js +1 -1
- package/lib/util/parseDependency.js +33 -54
- package/lib/util/parseGlob.js +34 -0
- package/lib/util/parseObjectStyles.js +1 -1
- package/lib/util/pluginUtils.js +87 -17
- package/lib/util/resolveConfig.js +2 -2
- package/lib/util/splitAtTopLevelOnly.js +31 -81
- package/lib/util/transformThemeValue.js +9 -2
- package/lib/util/validateConfig.js +1 -1
- package/lib/util/validateFormalSyntax.js +24 -0
- package/package.json +14 -13
- package/peers/index.js +3263 -1887
- package/plugin.d.ts +3 -3
- package/scripts/release-channel.js +18 -0
- package/scripts/release-notes.js +21 -0
- package/src/cli/build/deps.js +56 -0
- package/src/cli/build/index.js +45 -0
- package/src/cli/build/plugin.js +417 -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.js +4 -696
- package/src/corePlugins.js +262 -39
- package/src/css/preflight.css +5 -0
- package/src/featureFlags.js +12 -2
- package/src/index.js +5 -0
- package/src/lib/content.js +205 -0
- package/src/lib/defaultExtractor.js +3 -0
- package/src/lib/evaluateTailwindFunctions.js +22 -1
- package/src/lib/expandApplyAtRules.js +70 -29
- package/src/lib/expandTailwindAtRules.js +8 -46
- package/src/lib/findAtConfigPath.js +48 -0
- package/src/lib/generateRules.js +223 -101
- package/src/lib/offsets.js +270 -0
- package/src/lib/setupContextUtils.js +376 -89
- package/src/lib/setupTrackingContext.js +4 -45
- package/src/lib/sharedState.js +2 -0
- package/src/util/buildMediaQuery.js +5 -3
- package/src/util/dataTypes.js +15 -17
- package/src/util/formatVariantSelector.js +113 -9
- package/src/util/getAllConfigs.js +14 -2
- package/src/util/nameClass.js +4 -0
- package/src/util/negateValue.js +10 -2
- package/src/util/normalizeConfig.js +22 -2
- package/src/util/normalizeScreens.js +99 -4
- package/src/util/parseBoxShadowValue.js +1 -1
- package/src/util/parseDependency.js +37 -42
- package/src/util/parseGlob.js +24 -0
- package/src/util/pluginUtils.js +96 -14
- package/src/util/resolveConfig.js +1 -1
- package/src/util/splitAtTopLevelOnly.js +23 -49
- package/src/util/transformThemeValue.js +9 -1
- package/src/util/validateFormalSyntax.js +34 -0
- package/stubs/defaultConfig.stub.js +20 -3
- package/types/config.d.ts +48 -13
- package/types/generated/default-theme.d.ts +11 -0
package/src/cli.js
CHANGED
|
@@ -1,27 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { lazyPostcss, lazyPostcssImport, lazyCssnano, lazyAutoprefixer } from '../peers/index.js'
|
|
4
|
-
|
|
5
|
-
import chokidar from 'chokidar'
|
|
6
3
|
import path from 'path'
|
|
7
4
|
import arg from 'arg'
|
|
8
5
|
import fs from 'fs'
|
|
9
|
-
import postcssrc from 'postcss-load-config'
|
|
10
|
-
import { lilconfig } from 'lilconfig'
|
|
11
|
-
import loadPlugins from 'postcss-load-config/src/plugins' // Little bit scary, looking at private/internal API
|
|
12
|
-
import loadOptions from 'postcss-load-config/src/options' // Little bit scary, looking at private/internal API
|
|
13
|
-
import tailwind from './processTailwindFeatures'
|
|
14
|
-
import resolveConfigInternal from '../resolveConfig'
|
|
15
|
-
import fastGlob from 'fast-glob'
|
|
16
|
-
import getModuleDependencies from './lib/getModuleDependencies'
|
|
17
|
-
import log from './util/log'
|
|
18
|
-
import packageJson from '../package.json'
|
|
19
|
-
import normalizePath from 'normalize-path'
|
|
20
|
-
import { validateConfig } from './util/validateConfig.js'
|
|
21
6
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
7
|
+
import { build } from './cli/build'
|
|
8
|
+
import { help } from './cli/help'
|
|
9
|
+
import { init } from './cli/init'
|
|
25
10
|
|
|
26
11
|
function isESM() {
|
|
27
12
|
const pkgPath = path.resolve('./package.json')
|
|
@@ -46,112 +31,6 @@ let configs = isESM()
|
|
|
46
31
|
|
|
47
32
|
// ---
|
|
48
33
|
|
|
49
|
-
function indentRecursive(node, indent = 0) {
|
|
50
|
-
node.each &&
|
|
51
|
-
node.each((child, i) => {
|
|
52
|
-
if (!child.raws.before || !child.raws.before.trim() || child.raws.before.includes('\n')) {
|
|
53
|
-
child.raws.before = `\n${node.type !== 'rule' && i > 0 ? '\n' : ''}${' '.repeat(indent)}`
|
|
54
|
-
}
|
|
55
|
-
child.raws.after = `\n${' '.repeat(indent)}`
|
|
56
|
-
indentRecursive(child, indent + 1)
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function formatNodes(root) {
|
|
61
|
-
indentRecursive(root)
|
|
62
|
-
if (root.first) {
|
|
63
|
-
root.first.raws.before = ''
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function outputFile(file, contents) {
|
|
68
|
-
if (fs.existsSync(file) && (await fs.promises.readFile(file, 'utf8')) === contents) {
|
|
69
|
-
return // Skip writing the file
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Write the file
|
|
73
|
-
await fs.promises.writeFile(file, contents, 'utf8')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function drainStdin() {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
let result = ''
|
|
79
|
-
process.stdin.on('data', (chunk) => {
|
|
80
|
-
result += chunk
|
|
81
|
-
})
|
|
82
|
-
process.stdin.on('end', () => resolve(result))
|
|
83
|
-
process.stdin.on('error', (err) => reject(err))
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function help({ message, usage, commands, options }) {
|
|
88
|
-
let indent = 2
|
|
89
|
-
|
|
90
|
-
// Render header
|
|
91
|
-
console.log()
|
|
92
|
-
console.log(`${packageJson.name} v${packageJson.version}`)
|
|
93
|
-
|
|
94
|
-
// Render message
|
|
95
|
-
if (message) {
|
|
96
|
-
console.log()
|
|
97
|
-
for (let msg of message.split('\n')) {
|
|
98
|
-
console.log(msg)
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Render usage
|
|
103
|
-
if (usage && usage.length > 0) {
|
|
104
|
-
console.log()
|
|
105
|
-
console.log('Usage:')
|
|
106
|
-
for (let example of usage) {
|
|
107
|
-
console.log(' '.repeat(indent), example)
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Render commands
|
|
112
|
-
if (commands && commands.length > 0) {
|
|
113
|
-
console.log()
|
|
114
|
-
console.log('Commands:')
|
|
115
|
-
for (let command of commands) {
|
|
116
|
-
console.log(' '.repeat(indent), command)
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Render options
|
|
121
|
-
if (options) {
|
|
122
|
-
let groupedOptions = {}
|
|
123
|
-
for (let [key, value] of Object.entries(options)) {
|
|
124
|
-
if (typeof value === 'object') {
|
|
125
|
-
groupedOptions[key] = { ...value, flags: [key] }
|
|
126
|
-
} else {
|
|
127
|
-
groupedOptions[value].flags.push(key)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
console.log()
|
|
132
|
-
console.log('Options:')
|
|
133
|
-
for (let { flags, description, deprecated } of Object.values(groupedOptions)) {
|
|
134
|
-
if (deprecated) continue
|
|
135
|
-
|
|
136
|
-
if (flags.length === 1) {
|
|
137
|
-
console.log(
|
|
138
|
-
' '.repeat(indent + 4 /* 4 = "-i, ".length */),
|
|
139
|
-
flags.slice().reverse().join(', ').padEnd(20, ' '),
|
|
140
|
-
description
|
|
141
|
-
)
|
|
142
|
-
} else {
|
|
143
|
-
console.log(
|
|
144
|
-
' '.repeat(indent),
|
|
145
|
-
flags.slice().reverse().join(', ').padEnd(24, ' '),
|
|
146
|
-
description
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
console.log()
|
|
153
|
-
}
|
|
154
|
-
|
|
155
34
|
function oneOf(...options) {
|
|
156
35
|
return Object.assign(
|
|
157
36
|
(value = true) => {
|
|
@@ -168,15 +47,6 @@ function oneOf(...options) {
|
|
|
168
47
|
)
|
|
169
48
|
}
|
|
170
49
|
|
|
171
|
-
function loadPostcss() {
|
|
172
|
-
// Try to load a local `postcss` version first
|
|
173
|
-
try {
|
|
174
|
-
return require('postcss')
|
|
175
|
-
} catch {}
|
|
176
|
-
|
|
177
|
-
return lazyPostcss()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
50
|
let commands = {
|
|
181
51
|
init: {
|
|
182
52
|
run: init,
|
|
@@ -350,566 +220,4 @@ if (args['--help']) {
|
|
|
350
220
|
process.exit(0)
|
|
351
221
|
}
|
|
352
222
|
|
|
353
|
-
run()
|
|
354
|
-
|
|
355
|
-
// ---
|
|
356
|
-
|
|
357
|
-
function init() {
|
|
358
|
-
let messages = []
|
|
359
|
-
|
|
360
|
-
let tailwindConfigLocation = path.resolve(args['_'][1] ?? `./${configs.tailwind}`)
|
|
361
|
-
if (fs.existsSync(tailwindConfigLocation)) {
|
|
362
|
-
messages.push(`${path.basename(tailwindConfigLocation)} already exists.`)
|
|
363
|
-
} else {
|
|
364
|
-
let stubFile = fs.readFileSync(
|
|
365
|
-
args['--full']
|
|
366
|
-
? path.resolve(__dirname, '../stubs/defaultConfig.stub.js')
|
|
367
|
-
: path.resolve(__dirname, '../stubs/simpleConfig.stub.js'),
|
|
368
|
-
'utf8'
|
|
369
|
-
)
|
|
370
|
-
|
|
371
|
-
// Change colors import
|
|
372
|
-
stubFile = stubFile.replace('../colors', 'tailwindcss/colors')
|
|
373
|
-
|
|
374
|
-
fs.writeFileSync(tailwindConfigLocation, stubFile, 'utf8')
|
|
375
|
-
|
|
376
|
-
messages.push(`Created Tailwind CSS config file: ${path.basename(tailwindConfigLocation)}`)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (args['--postcss']) {
|
|
380
|
-
let postcssConfigLocation = path.resolve(`./${configs.postcss}`)
|
|
381
|
-
if (fs.existsSync(postcssConfigLocation)) {
|
|
382
|
-
messages.push(`${path.basename(postcssConfigLocation)} already exists.`)
|
|
383
|
-
} else {
|
|
384
|
-
let stubFile = fs.readFileSync(
|
|
385
|
-
path.resolve(__dirname, '../stubs/defaultPostCssConfig.stub.js'),
|
|
386
|
-
'utf8'
|
|
387
|
-
)
|
|
388
|
-
|
|
389
|
-
fs.writeFileSync(postcssConfigLocation, stubFile, 'utf8')
|
|
390
|
-
|
|
391
|
-
messages.push(`Created PostCSS config file: ${path.basename(postcssConfigLocation)}`)
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (messages.length > 0) {
|
|
396
|
-
console.log()
|
|
397
|
-
for (let message of messages) {
|
|
398
|
-
console.log(message)
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
async function build() {
|
|
404
|
-
let input = args['--input']
|
|
405
|
-
let output = args['--output']
|
|
406
|
-
let shouldWatch = args['--watch']
|
|
407
|
-
let shouldPoll = args['--poll']
|
|
408
|
-
let shouldCoalesceWriteEvents = shouldPoll || process.platform === 'win32'
|
|
409
|
-
let includePostCss = args['--postcss']
|
|
410
|
-
|
|
411
|
-
// Polling interval in milliseconds
|
|
412
|
-
// Used only when polling or coalescing add/change events on Windows
|
|
413
|
-
let pollInterval = 10
|
|
414
|
-
|
|
415
|
-
// TODO: Deprecate this in future versions
|
|
416
|
-
if (!input && args['_'][1]) {
|
|
417
|
-
console.error('[deprecation] Running tailwindcss without -i, please provide an input file.')
|
|
418
|
-
input = args['--input'] = args['_'][1]
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (input && input !== '-' && !fs.existsSync((input = path.resolve(input)))) {
|
|
422
|
-
console.error(`Specified input file ${args['--input']} does not exist.`)
|
|
423
|
-
process.exit(9)
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
if (args['--config'] && !fs.existsSync((args['--config'] = path.resolve(args['--config'])))) {
|
|
427
|
-
console.error(`Specified config file ${args['--config']} does not exist.`)
|
|
428
|
-
process.exit(9)
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
let configPath = args['--config']
|
|
432
|
-
? args['--config']
|
|
433
|
-
: ((defaultPath) => (fs.existsSync(defaultPath) ? defaultPath : null))(
|
|
434
|
-
path.resolve(`./${configs.tailwind}`)
|
|
435
|
-
)
|
|
436
|
-
|
|
437
|
-
async function loadPostCssPlugins() {
|
|
438
|
-
let customPostCssPath = typeof args['--postcss'] === 'string' ? args['--postcss'] : undefined
|
|
439
|
-
let config = customPostCssPath
|
|
440
|
-
? await (async () => {
|
|
441
|
-
let file = path.resolve(customPostCssPath)
|
|
442
|
-
|
|
443
|
-
// Implementation, see: https://unpkg.com/browse/postcss-load-config@3.1.0/src/index.js
|
|
444
|
-
let { config = {} } = await lilconfig('postcss').load(file)
|
|
445
|
-
if (typeof config === 'function') {
|
|
446
|
-
config = config()
|
|
447
|
-
} else {
|
|
448
|
-
config = Object.assign({}, config)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
if (!config.plugins) {
|
|
452
|
-
config.plugins = []
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return {
|
|
456
|
-
file,
|
|
457
|
-
plugins: loadPlugins(config, file),
|
|
458
|
-
options: loadOptions(config, file),
|
|
459
|
-
}
|
|
460
|
-
})()
|
|
461
|
-
: await postcssrc()
|
|
462
|
-
|
|
463
|
-
let configPlugins = config.plugins
|
|
464
|
-
|
|
465
|
-
let configPluginTailwindIdx = configPlugins.findIndex((plugin) => {
|
|
466
|
-
if (typeof plugin === 'function' && plugin.name === 'tailwindcss') {
|
|
467
|
-
return true
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
if (typeof plugin === 'object' && plugin !== null && plugin.postcssPlugin === 'tailwindcss') {
|
|
471
|
-
return true
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
return false
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
let beforePlugins =
|
|
478
|
-
configPluginTailwindIdx === -1 ? [] : configPlugins.slice(0, configPluginTailwindIdx)
|
|
479
|
-
let afterPlugins =
|
|
480
|
-
configPluginTailwindIdx === -1
|
|
481
|
-
? configPlugins
|
|
482
|
-
: configPlugins.slice(configPluginTailwindIdx + 1)
|
|
483
|
-
|
|
484
|
-
return [beforePlugins, afterPlugins, config.options]
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
function loadBuiltinPostcssPlugins() {
|
|
488
|
-
let postcss = loadPostcss()
|
|
489
|
-
let IMPORT_COMMENT = '__TAILWIND_RESTORE_IMPORT__: '
|
|
490
|
-
return [
|
|
491
|
-
[
|
|
492
|
-
(root) => {
|
|
493
|
-
root.walkAtRules('import', (rule) => {
|
|
494
|
-
if (rule.params.slice(1).startsWith('tailwindcss/')) {
|
|
495
|
-
rule.after(postcss.comment({ text: IMPORT_COMMENT + rule.params }))
|
|
496
|
-
rule.remove()
|
|
497
|
-
}
|
|
498
|
-
})
|
|
499
|
-
},
|
|
500
|
-
(() => {
|
|
501
|
-
try {
|
|
502
|
-
return require('postcss-import')
|
|
503
|
-
} catch {}
|
|
504
|
-
|
|
505
|
-
return lazyPostcssImport()
|
|
506
|
-
})(),
|
|
507
|
-
(root) => {
|
|
508
|
-
root.walkComments((rule) => {
|
|
509
|
-
if (rule.text.startsWith(IMPORT_COMMENT)) {
|
|
510
|
-
rule.after(
|
|
511
|
-
postcss.atRule({
|
|
512
|
-
name: 'import',
|
|
513
|
-
params: rule.text.replace(IMPORT_COMMENT, ''),
|
|
514
|
-
})
|
|
515
|
-
)
|
|
516
|
-
rule.remove()
|
|
517
|
-
}
|
|
518
|
-
})
|
|
519
|
-
},
|
|
520
|
-
],
|
|
521
|
-
[],
|
|
522
|
-
{},
|
|
523
|
-
]
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
function resolveConfig() {
|
|
527
|
-
let config = configPath ? require(configPath) : {}
|
|
528
|
-
|
|
529
|
-
if (args['--purge']) {
|
|
530
|
-
log.warn('purge-flag-deprecated', [
|
|
531
|
-
'The `--purge` flag has been deprecated.',
|
|
532
|
-
'Please use `--content` instead.',
|
|
533
|
-
])
|
|
534
|
-
if (!args['--content']) {
|
|
535
|
-
args['--content'] = args['--purge']
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
if (args['--content']) {
|
|
540
|
-
let files = args['--content'].split(/(?<!{[^}]+),/)
|
|
541
|
-
let resolvedConfig = resolveConfigInternal(config, { content: { files } })
|
|
542
|
-
resolvedConfig.content.files = files
|
|
543
|
-
resolvedConfig = validateConfig(resolvedConfig)
|
|
544
|
-
return resolvedConfig
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
let resolvedConfig = resolveConfigInternal(config)
|
|
548
|
-
resolvedConfig = validateConfig(resolvedConfig)
|
|
549
|
-
return resolvedConfig
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
function extractFileGlobs(config) {
|
|
553
|
-
return config.content.files
|
|
554
|
-
.filter((file) => {
|
|
555
|
-
// Strings in this case are files / globs. If it is something else,
|
|
556
|
-
// like an object it's probably a raw content object. But this object
|
|
557
|
-
// is not watchable, so let's remove it.
|
|
558
|
-
return typeof file === 'string'
|
|
559
|
-
})
|
|
560
|
-
.map((glob) => normalizePath(glob))
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
function extractRawContent(config) {
|
|
564
|
-
return config.content.files.filter((file) => {
|
|
565
|
-
return typeof file === 'object' && file !== null
|
|
566
|
-
})
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
function getChangedContent(config) {
|
|
570
|
-
let changedContent = []
|
|
571
|
-
|
|
572
|
-
// Resolve globs from the content config
|
|
573
|
-
let globs = extractFileGlobs(config)
|
|
574
|
-
let files = fastGlob.sync(globs)
|
|
575
|
-
|
|
576
|
-
for (let file of files) {
|
|
577
|
-
changedContent.push({
|
|
578
|
-
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
579
|
-
extension: path.extname(file).slice(1),
|
|
580
|
-
})
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// Resolve raw content in the tailwind config
|
|
584
|
-
for (let { raw: content, extension = 'html' } of extractRawContent(config)) {
|
|
585
|
-
changedContent.push({ content, extension })
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
return changedContent
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
async function buildOnce() {
|
|
592
|
-
let config = resolveConfig()
|
|
593
|
-
let changedContent = getChangedContent(config)
|
|
594
|
-
|
|
595
|
-
let tailwindPlugin = () => {
|
|
596
|
-
return {
|
|
597
|
-
postcssPlugin: 'tailwindcss',
|
|
598
|
-
Once(root, { result }) {
|
|
599
|
-
tailwind(({ createContext }) => {
|
|
600
|
-
return () => {
|
|
601
|
-
return createContext(config, changedContent)
|
|
602
|
-
}
|
|
603
|
-
})(root, result)
|
|
604
|
-
},
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
tailwindPlugin.postcss = true
|
|
609
|
-
|
|
610
|
-
let [beforePlugins, afterPlugins, postcssOptions] = includePostCss
|
|
611
|
-
? await loadPostCssPlugins()
|
|
612
|
-
: loadBuiltinPostcssPlugins()
|
|
613
|
-
|
|
614
|
-
let plugins = [
|
|
615
|
-
...beforePlugins,
|
|
616
|
-
tailwindPlugin,
|
|
617
|
-
!args['--minify'] && formatNodes,
|
|
618
|
-
...afterPlugins,
|
|
619
|
-
!args['--no-autoprefixer'] &&
|
|
620
|
-
(() => {
|
|
621
|
-
// Try to load a local `autoprefixer` version first
|
|
622
|
-
try {
|
|
623
|
-
return require('autoprefixer')
|
|
624
|
-
} catch {}
|
|
625
|
-
|
|
626
|
-
return lazyAutoprefixer()
|
|
627
|
-
})(),
|
|
628
|
-
args['--minify'] &&
|
|
629
|
-
(() => {
|
|
630
|
-
let options = { preset: ['default', { cssDeclarationSorter: false }] }
|
|
631
|
-
|
|
632
|
-
// Try to load a local `cssnano` version first
|
|
633
|
-
try {
|
|
634
|
-
return require('cssnano')
|
|
635
|
-
} catch {}
|
|
636
|
-
|
|
637
|
-
return lazyCssnano()(options)
|
|
638
|
-
})(),
|
|
639
|
-
].filter(Boolean)
|
|
640
|
-
|
|
641
|
-
let postcss = loadPostcss()
|
|
642
|
-
let processor = postcss(plugins)
|
|
643
|
-
|
|
644
|
-
function processCSS(css) {
|
|
645
|
-
let start = process.hrtime.bigint()
|
|
646
|
-
return Promise.resolve()
|
|
647
|
-
.then(() => (output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null))
|
|
648
|
-
.then(() => processor.process(css, { ...postcssOptions, from: input, to: output }))
|
|
649
|
-
.then((result) => {
|
|
650
|
-
if (!output) {
|
|
651
|
-
return process.stdout.write(result.css)
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return Promise.all(
|
|
655
|
-
[
|
|
656
|
-
outputFile(output, result.css),
|
|
657
|
-
result.map && outputFile(output + '.map', result.map.toString()),
|
|
658
|
-
].filter(Boolean)
|
|
659
|
-
)
|
|
660
|
-
})
|
|
661
|
-
.then(() => {
|
|
662
|
-
let end = process.hrtime.bigint()
|
|
663
|
-
console.error()
|
|
664
|
-
console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
|
|
665
|
-
})
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
let css = await (() => {
|
|
669
|
-
// Piping in data, let's drain the stdin
|
|
670
|
-
if (input === '-') {
|
|
671
|
-
return drainStdin()
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// Input file has been provided
|
|
675
|
-
if (input) {
|
|
676
|
-
return fs.readFileSync(path.resolve(input), 'utf8')
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// No input file provided, fallback to default atrules
|
|
680
|
-
return '@tailwind base; @tailwind components; @tailwind utilities'
|
|
681
|
-
})()
|
|
682
|
-
|
|
683
|
-
return processCSS(css)
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
let context = null
|
|
687
|
-
|
|
688
|
-
async function startWatcher() {
|
|
689
|
-
let changedContent = []
|
|
690
|
-
let configDependencies = []
|
|
691
|
-
let contextDependencies = new Set()
|
|
692
|
-
let watcher = null
|
|
693
|
-
|
|
694
|
-
function refreshConfig() {
|
|
695
|
-
env.DEBUG && console.time('Module dependencies')
|
|
696
|
-
for (let file of configDependencies) {
|
|
697
|
-
delete require.cache[require.resolve(file)]
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
if (configPath) {
|
|
701
|
-
configDependencies = getModuleDependencies(configPath).map(({ file }) => file)
|
|
702
|
-
|
|
703
|
-
for (let dependency of configDependencies) {
|
|
704
|
-
contextDependencies.add(dependency)
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
env.DEBUG && console.timeEnd('Module dependencies')
|
|
708
|
-
|
|
709
|
-
return resolveConfig()
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
let [beforePlugins, afterPlugins] = includePostCss
|
|
713
|
-
? await loadPostCssPlugins()
|
|
714
|
-
: loadBuiltinPostcssPlugins()
|
|
715
|
-
|
|
716
|
-
let plugins = [
|
|
717
|
-
...beforePlugins,
|
|
718
|
-
'__TAILWIND_PLUGIN_POSITION__',
|
|
719
|
-
!args['--minify'] && formatNodes,
|
|
720
|
-
...afterPlugins,
|
|
721
|
-
!args['--no-autoprefixer'] &&
|
|
722
|
-
(() => {
|
|
723
|
-
// Try to load a local `autoprefixer` version first
|
|
724
|
-
try {
|
|
725
|
-
return require('autoprefixer')
|
|
726
|
-
} catch {}
|
|
727
|
-
|
|
728
|
-
return lazyAutoprefixer()
|
|
729
|
-
})(),
|
|
730
|
-
args['--minify'] &&
|
|
731
|
-
(() => {
|
|
732
|
-
let options = { preset: ['default', { cssDeclarationSorter: false }] }
|
|
733
|
-
|
|
734
|
-
// Try to load a local `cssnano` version first
|
|
735
|
-
try {
|
|
736
|
-
return require('cssnano')
|
|
737
|
-
} catch {}
|
|
738
|
-
|
|
739
|
-
return lazyCssnano()(options)
|
|
740
|
-
})(),
|
|
741
|
-
].filter(Boolean)
|
|
742
|
-
|
|
743
|
-
async function rebuild(config) {
|
|
744
|
-
env.DEBUG && console.time('Finished in')
|
|
745
|
-
|
|
746
|
-
let tailwindPlugin = () => {
|
|
747
|
-
return {
|
|
748
|
-
postcssPlugin: 'tailwindcss',
|
|
749
|
-
Once(root, { result }) {
|
|
750
|
-
env.DEBUG && console.time('Compiling CSS')
|
|
751
|
-
tailwind(({ createContext }) => {
|
|
752
|
-
console.error()
|
|
753
|
-
console.error('Rebuilding...')
|
|
754
|
-
|
|
755
|
-
return () => {
|
|
756
|
-
if (context !== null) {
|
|
757
|
-
context.changedContent = changedContent.splice(0)
|
|
758
|
-
return context
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
env.DEBUG && console.time('Creating context')
|
|
762
|
-
context = createContext(config, changedContent.splice(0))
|
|
763
|
-
env.DEBUG && console.timeEnd('Creating context')
|
|
764
|
-
return context
|
|
765
|
-
}
|
|
766
|
-
})(root, result)
|
|
767
|
-
env.DEBUG && console.timeEnd('Compiling CSS')
|
|
768
|
-
},
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
tailwindPlugin.postcss = true
|
|
773
|
-
|
|
774
|
-
let tailwindPluginIdx = plugins.indexOf('__TAILWIND_PLUGIN_POSITION__')
|
|
775
|
-
let copy = plugins.slice()
|
|
776
|
-
copy.splice(tailwindPluginIdx, 1, tailwindPlugin)
|
|
777
|
-
let postcss = loadPostcss()
|
|
778
|
-
let processor = postcss(copy)
|
|
779
|
-
|
|
780
|
-
function processCSS(css) {
|
|
781
|
-
let start = process.hrtime.bigint()
|
|
782
|
-
return Promise.resolve()
|
|
783
|
-
.then(() =>
|
|
784
|
-
output ? fs.promises.mkdir(path.dirname(output), { recursive: true }) : null
|
|
785
|
-
)
|
|
786
|
-
.then(() => processor.process(css, { from: input, to: output }))
|
|
787
|
-
.then(async (result) => {
|
|
788
|
-
for (let message of result.messages) {
|
|
789
|
-
if (message.type === 'dependency') {
|
|
790
|
-
contextDependencies.add(message.file)
|
|
791
|
-
}
|
|
792
|
-
}
|
|
793
|
-
watcher.add([...contextDependencies])
|
|
794
|
-
|
|
795
|
-
if (!output) {
|
|
796
|
-
return process.stdout.write(result.css)
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
return Promise.all(
|
|
800
|
-
[
|
|
801
|
-
outputFile(output, result.css),
|
|
802
|
-
result.map && outputFile(output + '.map', result.map.toString()),
|
|
803
|
-
].filter(Boolean)
|
|
804
|
-
)
|
|
805
|
-
})
|
|
806
|
-
.then(() => {
|
|
807
|
-
let end = process.hrtime.bigint()
|
|
808
|
-
console.error('Done in', (end - start) / BigInt(1e6) + 'ms.')
|
|
809
|
-
})
|
|
810
|
-
.catch((err) => {
|
|
811
|
-
if (err.name === 'CssSyntaxError') {
|
|
812
|
-
console.error(err.toString())
|
|
813
|
-
} else {
|
|
814
|
-
console.error(err)
|
|
815
|
-
}
|
|
816
|
-
})
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
let css = await (() => {
|
|
820
|
-
// Piping in data, let's drain the stdin
|
|
821
|
-
if (input === '-') {
|
|
822
|
-
return drainStdin()
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
// Input file has been provided
|
|
826
|
-
if (input) {
|
|
827
|
-
return fs.readFileSync(path.resolve(input), 'utf8')
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
// No input file provided, fallback to default atrules
|
|
831
|
-
return '@tailwind base; @tailwind components; @tailwind utilities'
|
|
832
|
-
})()
|
|
833
|
-
|
|
834
|
-
let result = await processCSS(css)
|
|
835
|
-
env.DEBUG && console.timeEnd('Finished in')
|
|
836
|
-
return result
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
let config = refreshConfig(configPath)
|
|
840
|
-
|
|
841
|
-
if (input) {
|
|
842
|
-
contextDependencies.add(path.resolve(input))
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
watcher = chokidar.watch([...contextDependencies, ...extractFileGlobs(config)], {
|
|
846
|
-
usePolling: shouldPoll,
|
|
847
|
-
interval: shouldPoll ? pollInterval : undefined,
|
|
848
|
-
ignoreInitial: true,
|
|
849
|
-
awaitWriteFinish: shouldCoalesceWriteEvents
|
|
850
|
-
? {
|
|
851
|
-
stabilityThreshold: 50,
|
|
852
|
-
pollInterval: pollInterval,
|
|
853
|
-
}
|
|
854
|
-
: false,
|
|
855
|
-
})
|
|
856
|
-
|
|
857
|
-
let chain = Promise.resolve()
|
|
858
|
-
|
|
859
|
-
watcher.on('change', async (file) => {
|
|
860
|
-
if (contextDependencies.has(file)) {
|
|
861
|
-
env.DEBUG && console.time('Resolve config')
|
|
862
|
-
context = null
|
|
863
|
-
config = refreshConfig(configPath)
|
|
864
|
-
env.DEBUG && console.timeEnd('Resolve config')
|
|
865
|
-
|
|
866
|
-
env.DEBUG && console.time('Watch new files')
|
|
867
|
-
let globs = extractFileGlobs(config)
|
|
868
|
-
watcher.add(configDependencies)
|
|
869
|
-
watcher.add(globs)
|
|
870
|
-
env.DEBUG && console.timeEnd('Watch new files')
|
|
871
|
-
|
|
872
|
-
chain = chain.then(async () => {
|
|
873
|
-
changedContent.push(...getChangedContent(config))
|
|
874
|
-
await rebuild(config)
|
|
875
|
-
})
|
|
876
|
-
} else {
|
|
877
|
-
chain = chain.then(async () => {
|
|
878
|
-
changedContent.push({
|
|
879
|
-
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
880
|
-
extension: path.extname(file).slice(1),
|
|
881
|
-
})
|
|
882
|
-
|
|
883
|
-
await rebuild(config)
|
|
884
|
-
})
|
|
885
|
-
}
|
|
886
|
-
})
|
|
887
|
-
|
|
888
|
-
watcher.on('add', async (file) => {
|
|
889
|
-
chain = chain.then(async () => {
|
|
890
|
-
changedContent.push({
|
|
891
|
-
content: fs.readFileSync(path.resolve(file), 'utf8'),
|
|
892
|
-
extension: path.extname(file).slice(1),
|
|
893
|
-
})
|
|
894
|
-
|
|
895
|
-
await rebuild(config)
|
|
896
|
-
})
|
|
897
|
-
})
|
|
898
|
-
|
|
899
|
-
chain = chain.then(() => {
|
|
900
|
-
changedContent.push(...getChangedContent(config))
|
|
901
|
-
return rebuild(config)
|
|
902
|
-
})
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
if (shouldWatch) {
|
|
906
|
-
/* Abort the watcher if stdin is closed to avoid zombie processes */
|
|
907
|
-
if (process.stdin.isTTY) {
|
|
908
|
-
process.stdin.on('end', () => process.exit(0))
|
|
909
|
-
process.stdin.resume()
|
|
910
|
-
}
|
|
911
|
-
startWatcher()
|
|
912
|
-
} else {
|
|
913
|
-
buildOnce()
|
|
914
|
-
}
|
|
915
|
-
}
|
|
223
|
+
run(args, configs)
|