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