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