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