tailwindcss 0.0.0-oxide.6bf5e56 → 0.0.0-oxide.c7d416b
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/lib/cli/index.js +231 -10
- package/lib/cli.js +4 -236
- package/lib/index.js +4 -46
- package/lib/plugin.js +48 -0
- package/oxide/README.md +1 -0
- package/oxide/package.json +18 -0
- package/oxide/packages/tailwindcss/dist/cli.js +2 -0
- package/oxide/packages/tailwindcss/dist/postcss-plugin.js +2 -0
- package/oxide/packages/tailwindcss/package.json +34 -0
- package/package.json +5 -3
- package/src/cli/index.js +234 -3
- package/src/cli.js +4 -231
- package/src/index.js +4 -46
- package/src/plugin.js +47 -0
package/lib/cli/index.js
CHANGED
|
@@ -1,18 +1,239 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
1
2
|
"use strict";
|
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
|
3
4
|
value: true
|
|
4
5
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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("./build");
|
|
10
|
+
const _help = require("./help");
|
|
11
|
+
const _init = require("./init");
|
|
12
|
+
function _interopRequireDefault(obj) {
|
|
13
|
+
return obj && obj.__esModule ? obj : {
|
|
14
|
+
default: obj
|
|
15
|
+
};
|
|
16
|
+
}
|
|
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;
|
|
24
|
+
}
|
|
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
|
+
// ---
|
|
34
|
+
function oneOf(...options) {
|
|
35
|
+
return Object.assign((value = true)=>{
|
|
36
|
+
for (let option of options){
|
|
37
|
+
let parsed = option(value);
|
|
38
|
+
if (parsed === value) {
|
|
39
|
+
return parsed;
|
|
14
40
|
}
|
|
41
|
+
}
|
|
42
|
+
throw new Error("...");
|
|
43
|
+
}, {
|
|
44
|
+
manualParsing: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
let commands = {
|
|
48
|
+
init: {
|
|
49
|
+
run: _init.init,
|
|
50
|
+
args: {
|
|
51
|
+
"--full": {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
description: `Initialize a full \`${configs.tailwind}\` file`
|
|
54
|
+
},
|
|
55
|
+
"--postcss": {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
description: `Initialize a \`${configs.postcss}\` file`
|
|
58
|
+
},
|
|
59
|
+
"-f": "--full",
|
|
60
|
+
"-p": "--postcss"
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
build: {
|
|
64
|
+
run: _build.build,
|
|
65
|
+
args: {
|
|
66
|
+
"--input": {
|
|
67
|
+
type: String,
|
|
68
|
+
description: "Input file"
|
|
69
|
+
},
|
|
70
|
+
"--output": {
|
|
71
|
+
type: String,
|
|
72
|
+
description: "Output file"
|
|
73
|
+
},
|
|
74
|
+
"--watch": {
|
|
75
|
+
type: oneOf(String, Boolean),
|
|
76
|
+
description: "Watch for changes and rebuild as needed"
|
|
77
|
+
},
|
|
78
|
+
"--poll": {
|
|
79
|
+
type: Boolean,
|
|
80
|
+
description: "Use polling instead of filesystem events when watching"
|
|
81
|
+
},
|
|
82
|
+
"--content": {
|
|
83
|
+
type: String,
|
|
84
|
+
description: "Content paths to use for removing unused classes"
|
|
85
|
+
},
|
|
86
|
+
"--purge": {
|
|
87
|
+
type: String,
|
|
88
|
+
deprecated: true
|
|
89
|
+
},
|
|
90
|
+
"--postcss": {
|
|
91
|
+
type: oneOf(String, Boolean),
|
|
92
|
+
description: "Load custom PostCSS configuration"
|
|
93
|
+
},
|
|
94
|
+
"--minify": {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
description: "Minify the output"
|
|
97
|
+
},
|
|
98
|
+
"--config": {
|
|
99
|
+
type: String,
|
|
100
|
+
description: "Path to a custom config file"
|
|
101
|
+
},
|
|
102
|
+
"--no-autoprefixer": {
|
|
103
|
+
type: Boolean,
|
|
104
|
+
description: "Disable autoprefixer"
|
|
105
|
+
},
|
|
106
|
+
"-c": "--config",
|
|
107
|
+
"-i": "--input",
|
|
108
|
+
"-o": "--output",
|
|
109
|
+
"-m": "--minify",
|
|
110
|
+
"-w": "--watch",
|
|
111
|
+
"-p": "--poll"
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
let sharedFlags = {
|
|
116
|
+
"--help": {
|
|
117
|
+
type: Boolean,
|
|
118
|
+
description: "Display usage information"
|
|
119
|
+
},
|
|
120
|
+
"-h": "--help"
|
|
121
|
+
};
|
|
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)({
|
|
124
|
+
usage: [
|
|
125
|
+
"tailwindcss [--input input.css] [--output output.css] [--watch] [options...]",
|
|
126
|
+
"tailwindcss init [--full] [--postcss] [options...]"
|
|
127
|
+
],
|
|
128
|
+
commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
|
|
129
|
+
options: {
|
|
130
|
+
...commands.build.args,
|
|
131
|
+
...sharedFlags
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
process.exit(0);
|
|
135
|
+
}
|
|
136
|
+
let command = ((arg = "")=>arg.startsWith("-") ? undefined : arg)(process.argv[2]) || "build";
|
|
137
|
+
if (commands[command] === undefined) {
|
|
138
|
+
if (_fs.default.existsSync(_path.default.resolve(command))) {
|
|
139
|
+
// TODO: Deprecate this in future versions
|
|
140
|
+
// Check if non-existing command, might be a file.
|
|
141
|
+
command = "build";
|
|
142
|
+
} else {
|
|
143
|
+
(0, _help.help)({
|
|
144
|
+
message: `Invalid command: ${command}`,
|
|
145
|
+
usage: [
|
|
146
|
+
"tailwindcss <command> [options]"
|
|
147
|
+
],
|
|
148
|
+
commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
|
|
149
|
+
options: sharedFlags
|
|
150
|
+
});
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Execute command
|
|
155
|
+
let { args: flags , run } = commands[command];
|
|
156
|
+
let args = (()=>{
|
|
157
|
+
try {
|
|
158
|
+
let result = (0, _arg.default)(Object.fromEntries(Object.entries({
|
|
159
|
+
...flags,
|
|
160
|
+
...sharedFlags
|
|
161
|
+
}).filter(([_key, value])=>{
|
|
162
|
+
var ref;
|
|
163
|
+
return !(value === null || value === void 0 ? void 0 : (ref = value.type) === null || ref === void 0 ? void 0 : ref.manualParsing);
|
|
164
|
+
}).map(([key, value])=>[
|
|
165
|
+
key,
|
|
166
|
+
typeof value === "object" ? value.type : value
|
|
167
|
+
])), {
|
|
168
|
+
permissive: true
|
|
15
169
|
});
|
|
170
|
+
// Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
|
|
171
|
+
for(let i = result["_"].length - 1; i >= 0; --i){
|
|
172
|
+
let flag = result["_"][i];
|
|
173
|
+
if (!flag.startsWith("-")) continue;
|
|
174
|
+
let [flagName, flagValue] = flag.split("=");
|
|
175
|
+
let handler = flags[flagName];
|
|
176
|
+
// Resolve flagName & handler
|
|
177
|
+
while(typeof handler === "string"){
|
|
178
|
+
flagName = handler;
|
|
179
|
+
handler = flags[handler];
|
|
180
|
+
}
|
|
181
|
+
if (!handler) continue;
|
|
182
|
+
let args = [];
|
|
183
|
+
let offset = i + 1;
|
|
184
|
+
// --flag value syntax was used so we need to pull `value` from `args`
|
|
185
|
+
if (flagValue === undefined) {
|
|
186
|
+
// Parse args for current flag
|
|
187
|
+
while(result["_"][offset] && !result["_"][offset].startsWith("-")){
|
|
188
|
+
args.push(result["_"][offset++]);
|
|
189
|
+
}
|
|
190
|
+
// Cleanup manually parsed flags + args
|
|
191
|
+
result["_"].splice(i, 1 + args.length);
|
|
192
|
+
// No args were provided, use default value defined in handler
|
|
193
|
+
// One arg was provided, use that directly
|
|
194
|
+
// Multiple args were provided so pass them all in an array
|
|
195
|
+
flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args;
|
|
196
|
+
} else {
|
|
197
|
+
// Remove the whole flag from the args array
|
|
198
|
+
result["_"].splice(i, 1);
|
|
199
|
+
}
|
|
200
|
+
// Set the resolved value in the `result` object
|
|
201
|
+
result[flagName] = handler.type(flagValue, flagName);
|
|
202
|
+
}
|
|
203
|
+
// Ensure that the `command` is always the first argument in the `args`.
|
|
204
|
+
// This is important so that we don't have to check if a default command
|
|
205
|
+
// (build) was used or not from within each plugin.
|
|
206
|
+
//
|
|
207
|
+
// E.g.: tailwindcss input.css -> _: ['build', 'input.css']
|
|
208
|
+
// E.g.: tailwindcss build input.css -> _: ['build', 'input.css']
|
|
209
|
+
if (result["_"][0] !== command) {
|
|
210
|
+
result["_"].unshift(command);
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (err.code === "ARG_UNKNOWN_OPTION") {
|
|
215
|
+
(0, _help.help)({
|
|
216
|
+
message: err.message,
|
|
217
|
+
usage: [
|
|
218
|
+
"tailwindcss <command> [options]"
|
|
219
|
+
],
|
|
220
|
+
options: sharedFlags
|
|
221
|
+
});
|
|
222
|
+
process.exit(1);
|
|
223
|
+
}
|
|
224
|
+
throw err;
|
|
225
|
+
}
|
|
226
|
+
})();
|
|
227
|
+
if (args["--help"]) {
|
|
228
|
+
(0, _help.help)({
|
|
229
|
+
options: {
|
|
230
|
+
...flags,
|
|
231
|
+
...sharedFlags
|
|
232
|
+
},
|
|
233
|
+
usage: [
|
|
234
|
+
`tailwindcss ${command} [options]`
|
|
235
|
+
]
|
|
16
236
|
});
|
|
17
|
-
|
|
237
|
+
process.exit(0);
|
|
18
238
|
}
|
|
239
|
+
run(args, configs);
|
package/lib/cli.js
CHANGED
|
@@ -1,239 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
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");
|
|
12
|
-
function _interopRequireDefault(obj) {
|
|
13
|
-
return obj && obj.__esModule ? obj : {
|
|
14
|
-
default: obj
|
|
15
|
-
};
|
|
3
|
+
if (process.env.OXIDE) {
|
|
4
|
+
module.exports = require("../oxide/packages/tailwindcss/dist/cli.js");
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require("./cli/index.js");
|
|
16
7
|
}
|
|
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;
|
|
24
|
-
}
|
|
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
|
-
// ---
|
|
34
|
-
function oneOf(...options) {
|
|
35
|
-
return Object.assign((value = true)=>{
|
|
36
|
-
for (let option of options){
|
|
37
|
-
let parsed = option(value);
|
|
38
|
-
if (parsed === value) {
|
|
39
|
-
return parsed;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
throw new Error("...");
|
|
43
|
-
}, {
|
|
44
|
-
manualParsing: true
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
let commands = {
|
|
48
|
-
init: {
|
|
49
|
-
run: _init.init,
|
|
50
|
-
args: {
|
|
51
|
-
"--full": {
|
|
52
|
-
type: Boolean,
|
|
53
|
-
description: `Initialize a full \`${configs.tailwind}\` file`
|
|
54
|
-
},
|
|
55
|
-
"--postcss": {
|
|
56
|
-
type: Boolean,
|
|
57
|
-
description: `Initialize a \`${configs.postcss}\` file`
|
|
58
|
-
},
|
|
59
|
-
"-f": "--full",
|
|
60
|
-
"-p": "--postcss"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
build: {
|
|
64
|
-
run: _build.build,
|
|
65
|
-
args: {
|
|
66
|
-
"--input": {
|
|
67
|
-
type: String,
|
|
68
|
-
description: "Input file"
|
|
69
|
-
},
|
|
70
|
-
"--output": {
|
|
71
|
-
type: String,
|
|
72
|
-
description: "Output file"
|
|
73
|
-
},
|
|
74
|
-
"--watch": {
|
|
75
|
-
type: oneOf(String, Boolean),
|
|
76
|
-
description: "Watch for changes and rebuild as needed"
|
|
77
|
-
},
|
|
78
|
-
"--poll": {
|
|
79
|
-
type: Boolean,
|
|
80
|
-
description: "Use polling instead of filesystem events when watching"
|
|
81
|
-
},
|
|
82
|
-
"--content": {
|
|
83
|
-
type: String,
|
|
84
|
-
description: "Content paths to use for removing unused classes"
|
|
85
|
-
},
|
|
86
|
-
"--purge": {
|
|
87
|
-
type: String,
|
|
88
|
-
deprecated: true
|
|
89
|
-
},
|
|
90
|
-
"--postcss": {
|
|
91
|
-
type: oneOf(String, Boolean),
|
|
92
|
-
description: "Load custom PostCSS configuration"
|
|
93
|
-
},
|
|
94
|
-
"--minify": {
|
|
95
|
-
type: Boolean,
|
|
96
|
-
description: "Minify the output"
|
|
97
|
-
},
|
|
98
|
-
"--config": {
|
|
99
|
-
type: String,
|
|
100
|
-
description: "Path to a custom config file"
|
|
101
|
-
},
|
|
102
|
-
"--no-autoprefixer": {
|
|
103
|
-
type: Boolean,
|
|
104
|
-
description: "Disable autoprefixer"
|
|
105
|
-
},
|
|
106
|
-
"-c": "--config",
|
|
107
|
-
"-i": "--input",
|
|
108
|
-
"-o": "--output",
|
|
109
|
-
"-m": "--minify",
|
|
110
|
-
"-w": "--watch",
|
|
111
|
-
"-p": "--poll"
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
let sharedFlags = {
|
|
116
|
-
"--help": {
|
|
117
|
-
type: Boolean,
|
|
118
|
-
description: "Display usage information"
|
|
119
|
-
},
|
|
120
|
-
"-h": "--help"
|
|
121
|
-
};
|
|
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)({
|
|
124
|
-
usage: [
|
|
125
|
-
"tailwindcss [--input input.css] [--output output.css] [--watch] [options...]",
|
|
126
|
-
"tailwindcss init [--full] [--postcss] [options...]"
|
|
127
|
-
],
|
|
128
|
-
commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
|
|
129
|
-
options: {
|
|
130
|
-
...commands.build.args,
|
|
131
|
-
...sharedFlags
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
process.exit(0);
|
|
135
|
-
}
|
|
136
|
-
let command = ((arg = "")=>arg.startsWith("-") ? undefined : arg)(process.argv[2]) || "build";
|
|
137
|
-
if (commands[command] === undefined) {
|
|
138
|
-
if (_fs.default.existsSync(_path.default.resolve(command))) {
|
|
139
|
-
// TODO: Deprecate this in future versions
|
|
140
|
-
// Check if non-existing command, might be a file.
|
|
141
|
-
command = "build";
|
|
142
|
-
} else {
|
|
143
|
-
(0, _help.help)({
|
|
144
|
-
message: `Invalid command: ${command}`,
|
|
145
|
-
usage: [
|
|
146
|
-
"tailwindcss <command> [options]"
|
|
147
|
-
],
|
|
148
|
-
commands: Object.keys(commands).filter((command)=>command !== "build").map((command)=>`${command} [options]`),
|
|
149
|
-
options: sharedFlags
|
|
150
|
-
});
|
|
151
|
-
process.exit(1);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Execute command
|
|
155
|
-
let { args: flags , run } = commands[command];
|
|
156
|
-
let args = (()=>{
|
|
157
|
-
try {
|
|
158
|
-
let result = (0, _arg.default)(Object.fromEntries(Object.entries({
|
|
159
|
-
...flags,
|
|
160
|
-
...sharedFlags
|
|
161
|
-
}).filter(([_key, value])=>{
|
|
162
|
-
var ref;
|
|
163
|
-
return !(value === null || value === void 0 ? void 0 : (ref = value.type) === null || ref === void 0 ? void 0 : ref.manualParsing);
|
|
164
|
-
}).map(([key, value])=>[
|
|
165
|
-
key,
|
|
166
|
-
typeof value === "object" ? value.type : value
|
|
167
|
-
])), {
|
|
168
|
-
permissive: true
|
|
169
|
-
});
|
|
170
|
-
// Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
|
|
171
|
-
for(let i = result["_"].length - 1; i >= 0; --i){
|
|
172
|
-
let flag = result["_"][i];
|
|
173
|
-
if (!flag.startsWith("-")) continue;
|
|
174
|
-
let [flagName, flagValue] = flag.split("=");
|
|
175
|
-
let handler = flags[flagName];
|
|
176
|
-
// Resolve flagName & handler
|
|
177
|
-
while(typeof handler === "string"){
|
|
178
|
-
flagName = handler;
|
|
179
|
-
handler = flags[handler];
|
|
180
|
-
}
|
|
181
|
-
if (!handler) continue;
|
|
182
|
-
let args = [];
|
|
183
|
-
let offset = i + 1;
|
|
184
|
-
// --flag value syntax was used so we need to pull `value` from `args`
|
|
185
|
-
if (flagValue === undefined) {
|
|
186
|
-
// Parse args for current flag
|
|
187
|
-
while(result["_"][offset] && !result["_"][offset].startsWith("-")){
|
|
188
|
-
args.push(result["_"][offset++]);
|
|
189
|
-
}
|
|
190
|
-
// Cleanup manually parsed flags + args
|
|
191
|
-
result["_"].splice(i, 1 + args.length);
|
|
192
|
-
// No args were provided, use default value defined in handler
|
|
193
|
-
// One arg was provided, use that directly
|
|
194
|
-
// Multiple args were provided so pass them all in an array
|
|
195
|
-
flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args;
|
|
196
|
-
} else {
|
|
197
|
-
// Remove the whole flag from the args array
|
|
198
|
-
result["_"].splice(i, 1);
|
|
199
|
-
}
|
|
200
|
-
// Set the resolved value in the `result` object
|
|
201
|
-
result[flagName] = handler.type(flagValue, flagName);
|
|
202
|
-
}
|
|
203
|
-
// Ensure that the `command` is always the first argument in the `args`.
|
|
204
|
-
// This is important so that we don't have to check if a default command
|
|
205
|
-
// (build) was used or not from within each plugin.
|
|
206
|
-
//
|
|
207
|
-
// E.g.: tailwindcss input.css -> _: ['build', 'input.css']
|
|
208
|
-
// E.g.: tailwindcss build input.css -> _: ['build', 'input.css']
|
|
209
|
-
if (result["_"][0] !== command) {
|
|
210
|
-
result["_"].unshift(command);
|
|
211
|
-
}
|
|
212
|
-
return result;
|
|
213
|
-
} catch (err) {
|
|
214
|
-
if (err.code === "ARG_UNKNOWN_OPTION") {
|
|
215
|
-
(0, _help.help)({
|
|
216
|
-
message: err.message,
|
|
217
|
-
usage: [
|
|
218
|
-
"tailwindcss <command> [options]"
|
|
219
|
-
],
|
|
220
|
-
options: sharedFlags
|
|
221
|
-
});
|
|
222
|
-
process.exit(1);
|
|
223
|
-
}
|
|
224
|
-
throw err;
|
|
225
|
-
}
|
|
226
|
-
})();
|
|
227
|
-
if (args["--help"]) {
|
|
228
|
-
(0, _help.help)({
|
|
229
|
-
options: {
|
|
230
|
-
...flags,
|
|
231
|
-
...sharedFlags
|
|
232
|
-
},
|
|
233
|
-
usage: [
|
|
234
|
-
`tailwindcss ${command} [options]`
|
|
235
|
-
]
|
|
236
|
-
});
|
|
237
|
-
process.exit(0);
|
|
238
|
-
}
|
|
239
|
-
run(args, configs);
|
package/lib/index.js
CHANGED
|
@@ -1,48 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
const _processTailwindFeatures = /*#__PURE__*/ _interopRequireDefault(require("./processTailwindFeatures"));
|
|
7
|
-
const _sharedState = require("./lib/sharedState");
|
|
8
|
-
const _findAtConfigPath = require("./lib/findAtConfigPath");
|
|
9
|
-
function _interopRequireDefault(obj) {
|
|
10
|
-
return obj && obj.__esModule ? obj : {
|
|
11
|
-
default: obj
|
|
12
|
-
};
|
|
2
|
+
if (process.env.OXIDE) {
|
|
3
|
+
module.exports = require("../oxide/packages/tailwindcss/dist/postcss-plugin.js");
|
|
4
|
+
} else {
|
|
5
|
+
module.exports = require("./plugin.js");
|
|
13
6
|
}
|
|
14
|
-
module.exports = function tailwindcss(configOrPath) {
|
|
15
|
-
return {
|
|
16
|
-
postcssPlugin: "tailwindcss",
|
|
17
|
-
plugins: [
|
|
18
|
-
_sharedState.env.DEBUG && function(root) {
|
|
19
|
-
console.log("\n");
|
|
20
|
-
console.time("JIT TOTAL");
|
|
21
|
-
return root;
|
|
22
|
-
},
|
|
23
|
-
function(root, result) {
|
|
24
|
-
var ref;
|
|
25
|
-
// Use the path for the `@config` directive if it exists, otherwise use the
|
|
26
|
-
// path for the file being processed
|
|
27
|
-
configOrPath = (ref = (0, _findAtConfigPath.findAtConfigPath)(root, result)) !== null && ref !== void 0 ? ref : configOrPath;
|
|
28
|
-
let context = (0, _setupTrackingContext.default)(configOrPath);
|
|
29
|
-
if (root.type === "document") {
|
|
30
|
-
let roots = root.nodes.filter((node)=>node.type === "root");
|
|
31
|
-
for (const root1 of roots){
|
|
32
|
-
if (root1.type === "root") {
|
|
33
|
-
(0, _processTailwindFeatures.default)(context)(root1, result);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
(0, _processTailwindFeatures.default)(context)(root, result);
|
|
39
|
-
},
|
|
40
|
-
_sharedState.env.DEBUG && function(root) {
|
|
41
|
-
console.timeEnd("JIT TOTAL");
|
|
42
|
-
console.log("\n");
|
|
43
|
-
return root;
|
|
44
|
-
}
|
|
45
|
-
].filter(Boolean)
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
module.exports.postcss = true;
|
package/lib/plugin.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
const _setupTrackingContext = /*#__PURE__*/ _interopRequireDefault(require("./lib/setupTrackingContext"));
|
|
6
|
+
const _processTailwindFeatures = /*#__PURE__*/ _interopRequireDefault(require("./processTailwindFeatures"));
|
|
7
|
+
const _sharedState = require("./lib/sharedState");
|
|
8
|
+
const _findAtConfigPath = require("./lib/findAtConfigPath");
|
|
9
|
+
function _interopRequireDefault(obj) {
|
|
10
|
+
return obj && obj.__esModule ? obj : {
|
|
11
|
+
default: obj
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
module.exports = function tailwindcss(configOrPath) {
|
|
15
|
+
return {
|
|
16
|
+
postcssPlugin: "tailwindcss",
|
|
17
|
+
plugins: [
|
|
18
|
+
_sharedState.env.DEBUG && function(root) {
|
|
19
|
+
console.log("\n");
|
|
20
|
+
console.time("JIT TOTAL");
|
|
21
|
+
return root;
|
|
22
|
+
},
|
|
23
|
+
function(root, result) {
|
|
24
|
+
var ref;
|
|
25
|
+
// Use the path for the `@config` directive if it exists, otherwise use the
|
|
26
|
+
// path for the file being processed
|
|
27
|
+
configOrPath = (ref = (0, _findAtConfigPath.findAtConfigPath)(root, result)) !== null && ref !== void 0 ? ref : configOrPath;
|
|
28
|
+
let context = (0, _setupTrackingContext.default)(configOrPath);
|
|
29
|
+
if (root.type === "document") {
|
|
30
|
+
let roots = root.nodes.filter((node)=>node.type === "root");
|
|
31
|
+
for (const root1 of roots){
|
|
32
|
+
if (root1.type === "root") {
|
|
33
|
+
(0, _processTailwindFeatures.default)(context)(root1, result);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
(0, _processTailwindFeatures.default)(context)(root, result);
|
|
39
|
+
},
|
|
40
|
+
_sharedState.env.DEBUG && function(root) {
|
|
41
|
+
console.timeEnd("JIT TOTAL");
|
|
42
|
+
console.log("\n");
|
|
43
|
+
return root;
|
|
44
|
+
}
|
|
45
|
+
].filter(Boolean)
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
module.exports.postcss = true;
|
package/oxide/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
## Tailwind CSS Oxide
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tailwindcss-oxide",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "cargo test",
|
|
7
|
+
"install": "npm run install:npm && cargo install cargo-watch cargo-fuzz",
|
|
8
|
+
"install:npm": "npm install --prefix ./crates/node",
|
|
9
|
+
"build": "cargo build --release",
|
|
10
|
+
"build:node": "npm --prefix ./crates/node run build",
|
|
11
|
+
"dev": "cargo watch --clear --quiet -x 'run --quiet'",
|
|
12
|
+
"dev:node": "cargo watch --clear --quiet --shell 'npm --prefix ./crates/node run build:debug'",
|
|
13
|
+
"fuzz": "cd ./crates/core; cargo fuzz run parsing; cd -",
|
|
14
|
+
"bench": "cargo bench",
|
|
15
|
+
"postbench": "open ./target/criterion/report/index.html"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT"
|
|
18
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tailwindcss",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "A utility-first CSS framework for rapidly building custom user interfaces.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "dist/postcss-plugin.js",
|
|
7
|
+
"types": "types/postscs-plugin.d.ts",
|
|
8
|
+
"repository": "https://github.com/tailwindlabs/tailwindcss.git",
|
|
9
|
+
"bugs": "https://github.com/tailwindlabs/tailwindcss/issues",
|
|
10
|
+
"homepage": "https://tailwindcss.com",
|
|
11
|
+
"bin": {
|
|
12
|
+
"tailwind": "dist/cli.js",
|
|
13
|
+
"tailwindcss": "dist/cli.js"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "swc src --out-dir dist --copy-files"
|
|
17
|
+
},
|
|
18
|
+
"files": [],
|
|
19
|
+
"browserslist": [
|
|
20
|
+
"> 1%",
|
|
21
|
+
"not edge <= 18",
|
|
22
|
+
"not ie 11",
|
|
23
|
+
"not op_mini all"
|
|
24
|
+
],
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=12.13.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@swc/cli": "^0.1.57",
|
|
30
|
+
"@swc/core": "^1.3.21",
|
|
31
|
+
"@swc/jest": "^0.2.23",
|
|
32
|
+
"typescript": "^4.9.3"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailwindcss",
|
|
3
|
-
"version": "0.0.0-oxide.
|
|
3
|
+
"version": "0.0.0-oxide.c7d416b",
|
|
4
4
|
"description": "A utility-first CSS framework for rapidly building custom user interfaces.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"tailwindcss": "lib/cli.js"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
|
-
"
|
|
16
|
+
"package:build": "npm run --prefix ./oxide/packages/tailwindcss build",
|
|
17
|
+
"preswcify": "npm run generate && rimraf lib && npm run package:build",
|
|
17
18
|
"swcify": "swc src --out-dir lib --copy-files",
|
|
18
19
|
"postswcify": "esbuild lib/cli-peer-dependencies.js --bundle --platform=node --outfile=peers/index.js",
|
|
19
20
|
"rebuild-fixtures": "npm run swcify && node -r @swc/register scripts/rebuildFixtures.js",
|
|
@@ -36,6 +37,7 @@
|
|
|
36
37
|
"cli/*",
|
|
37
38
|
"lib/*",
|
|
38
39
|
"peers/*",
|
|
40
|
+
"oxide/packages/tailwindcss/dist/*.js",
|
|
39
41
|
"scripts/*.js",
|
|
40
42
|
"stubs/*.stub.js",
|
|
41
43
|
"nesting/*",
|
|
@@ -66,7 +68,7 @@
|
|
|
66
68
|
"postcss": "^8.0.9"
|
|
67
69
|
},
|
|
68
70
|
"dependencies": {
|
|
69
|
-
"@tailwindcss/oxide": "0.0.0-insiders.
|
|
71
|
+
"@tailwindcss/oxide": "0.0.0-insiders.c7d416b",
|
|
70
72
|
"arg": "^5.0.2",
|
|
71
73
|
"chokidar": "^3.5.3",
|
|
72
74
|
"color-name": "^1.1.4",
|
package/src/cli/index.js
CHANGED
|
@@ -1,3 +1,234 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import arg from 'arg'
|
|
5
|
+
import fs from 'fs'
|
|
6
|
+
|
|
7
|
+
import { build } from './build'
|
|
8
|
+
import { help } from './help'
|
|
9
|
+
import { init } from './init'
|
|
10
|
+
|
|
11
|
+
function isESM() {
|
|
12
|
+
const pkgPath = path.resolve('./package.json')
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
16
|
+
return pkg.type && pkg.type === 'module'
|
|
17
|
+
} catch (err) {
|
|
18
|
+
return false
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let configs = isESM()
|
|
23
|
+
? {
|
|
24
|
+
tailwind: 'tailwind.config.cjs',
|
|
25
|
+
postcss: 'postcss.config.cjs',
|
|
26
|
+
}
|
|
27
|
+
: {
|
|
28
|
+
tailwind: 'tailwind.config.js',
|
|
29
|
+
postcss: 'postcss.config.js',
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// ---
|
|
33
|
+
|
|
34
|
+
function oneOf(...options) {
|
|
35
|
+
return Object.assign(
|
|
36
|
+
(value = true) => {
|
|
37
|
+
for (let option of options) {
|
|
38
|
+
let parsed = option(value)
|
|
39
|
+
if (parsed === value) {
|
|
40
|
+
return parsed
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
throw new Error('...')
|
|
45
|
+
},
|
|
46
|
+
{ manualParsing: true }
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let commands = {
|
|
51
|
+
init: {
|
|
52
|
+
run: init,
|
|
53
|
+
args: {
|
|
54
|
+
'--full': { type: Boolean, description: `Initialize a full \`${configs.tailwind}\` file` },
|
|
55
|
+
'--postcss': { type: Boolean, description: `Initialize a \`${configs.postcss}\` file` },
|
|
56
|
+
'-f': '--full',
|
|
57
|
+
'-p': '--postcss',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
build: {
|
|
61
|
+
run: build,
|
|
62
|
+
args: {
|
|
63
|
+
'--input': { type: String, description: 'Input file' },
|
|
64
|
+
'--output': { type: String, description: 'Output file' },
|
|
65
|
+
'--watch': {
|
|
66
|
+
type: oneOf(String, Boolean),
|
|
67
|
+
description: 'Watch for changes and rebuild as needed',
|
|
68
|
+
},
|
|
69
|
+
'--poll': {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
description: 'Use polling instead of filesystem events when watching',
|
|
72
|
+
},
|
|
73
|
+
'--content': {
|
|
74
|
+
type: String,
|
|
75
|
+
description: 'Content paths to use for removing unused classes',
|
|
76
|
+
},
|
|
77
|
+
'--purge': {
|
|
78
|
+
type: String,
|
|
79
|
+
deprecated: true,
|
|
80
|
+
},
|
|
81
|
+
'--postcss': {
|
|
82
|
+
type: oneOf(String, Boolean),
|
|
83
|
+
description: 'Load custom PostCSS configuration',
|
|
84
|
+
},
|
|
85
|
+
'--minify': { type: Boolean, description: 'Minify the output' },
|
|
86
|
+
'--config': {
|
|
87
|
+
type: String,
|
|
88
|
+
description: 'Path to a custom config file',
|
|
89
|
+
},
|
|
90
|
+
'--no-autoprefixer': {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
description: 'Disable autoprefixer',
|
|
93
|
+
},
|
|
94
|
+
'-c': '--config',
|
|
95
|
+
'-i': '--input',
|
|
96
|
+
'-o': '--output',
|
|
97
|
+
'-m': '--minify',
|
|
98
|
+
'-w': '--watch',
|
|
99
|
+
'-p': '--poll',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let sharedFlags = {
|
|
105
|
+
'--help': { type: Boolean, description: 'Display usage information' },
|
|
106
|
+
'-h': '--help',
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
process.stdout.isTTY /* Detect redirecting output to a file */ &&
|
|
111
|
+
(process.argv[2] === undefined ||
|
|
112
|
+
process.argv.slice(2).every((flag) => sharedFlags[flag] !== undefined))
|
|
113
|
+
) {
|
|
114
|
+
help({
|
|
115
|
+
usage: [
|
|
116
|
+
'tailwindcss [--input input.css] [--output output.css] [--watch] [options...]',
|
|
117
|
+
'tailwindcss init [--full] [--postcss] [options...]',
|
|
118
|
+
],
|
|
119
|
+
commands: Object.keys(commands)
|
|
120
|
+
.filter((command) => command !== 'build')
|
|
121
|
+
.map((command) => `${command} [options]`),
|
|
122
|
+
options: { ...commands.build.args, ...sharedFlags },
|
|
123
|
+
})
|
|
124
|
+
process.exit(0)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let command = ((arg = '') => (arg.startsWith('-') ? undefined : arg))(process.argv[2]) || 'build'
|
|
128
|
+
|
|
129
|
+
if (commands[command] === undefined) {
|
|
130
|
+
if (fs.existsSync(path.resolve(command))) {
|
|
131
|
+
// TODO: Deprecate this in future versions
|
|
132
|
+
// Check if non-existing command, might be a file.
|
|
133
|
+
command = 'build'
|
|
134
|
+
} else {
|
|
135
|
+
help({
|
|
136
|
+
message: `Invalid command: ${command}`,
|
|
137
|
+
usage: ['tailwindcss <command> [options]'],
|
|
138
|
+
commands: Object.keys(commands)
|
|
139
|
+
.filter((command) => command !== 'build')
|
|
140
|
+
.map((command) => `${command} [options]`),
|
|
141
|
+
options: sharedFlags,
|
|
142
|
+
})
|
|
143
|
+
process.exit(1)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Execute command
|
|
148
|
+
let { args: flags, run } = commands[command]
|
|
149
|
+
let args = (() => {
|
|
150
|
+
try {
|
|
151
|
+
let result = arg(
|
|
152
|
+
Object.fromEntries(
|
|
153
|
+
Object.entries({ ...flags, ...sharedFlags })
|
|
154
|
+
.filter(([_key, value]) => !value?.type?.manualParsing)
|
|
155
|
+
.map(([key, value]) => [key, typeof value === 'object' ? value.type : value])
|
|
156
|
+
),
|
|
157
|
+
{ permissive: true }
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
// Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
|
|
161
|
+
for (let i = result['_'].length - 1; i >= 0; --i) {
|
|
162
|
+
let flag = result['_'][i]
|
|
163
|
+
if (!flag.startsWith('-')) continue
|
|
164
|
+
|
|
165
|
+
let [flagName, flagValue] = flag.split('=')
|
|
166
|
+
let handler = flags[flagName]
|
|
167
|
+
|
|
168
|
+
// Resolve flagName & handler
|
|
169
|
+
while (typeof handler === 'string') {
|
|
170
|
+
flagName = handler
|
|
171
|
+
handler = flags[handler]
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (!handler) continue
|
|
175
|
+
|
|
176
|
+
let args = []
|
|
177
|
+
let offset = i + 1
|
|
178
|
+
|
|
179
|
+
// --flag value syntax was used so we need to pull `value` from `args`
|
|
180
|
+
if (flagValue === undefined) {
|
|
181
|
+
// Parse args for current flag
|
|
182
|
+
while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
|
|
183
|
+
args.push(result['_'][offset++])
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Cleanup manually parsed flags + args
|
|
187
|
+
result['_'].splice(i, 1 + args.length)
|
|
188
|
+
|
|
189
|
+
// No args were provided, use default value defined in handler
|
|
190
|
+
// One arg was provided, use that directly
|
|
191
|
+
// Multiple args were provided so pass them all in an array
|
|
192
|
+
flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args
|
|
193
|
+
} else {
|
|
194
|
+
// Remove the whole flag from the args array
|
|
195
|
+
result['_'].splice(i, 1)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Set the resolved value in the `result` object
|
|
199
|
+
result[flagName] = handler.type(flagValue, flagName)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Ensure that the `command` is always the first argument in the `args`.
|
|
203
|
+
// This is important so that we don't have to check if a default command
|
|
204
|
+
// (build) was used or not from within each plugin.
|
|
205
|
+
//
|
|
206
|
+
// E.g.: tailwindcss input.css -> _: ['build', 'input.css']
|
|
207
|
+
// E.g.: tailwindcss build input.css -> _: ['build', 'input.css']
|
|
208
|
+
if (result['_'][0] !== command) {
|
|
209
|
+
result['_'].unshift(command)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return result
|
|
213
|
+
} catch (err) {
|
|
214
|
+
if (err.code === 'ARG_UNKNOWN_OPTION') {
|
|
215
|
+
help({
|
|
216
|
+
message: err.message,
|
|
217
|
+
usage: ['tailwindcss <command> [options]'],
|
|
218
|
+
options: sharedFlags,
|
|
219
|
+
})
|
|
220
|
+
process.exit(1)
|
|
221
|
+
}
|
|
222
|
+
throw err
|
|
223
|
+
}
|
|
224
|
+
})()
|
|
225
|
+
|
|
226
|
+
if (args['--help']) {
|
|
227
|
+
help({
|
|
228
|
+
options: { ...flags, ...sharedFlags },
|
|
229
|
+
usage: [`tailwindcss ${command} [options]`],
|
|
230
|
+
})
|
|
231
|
+
process.exit(0)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
run(args, configs)
|
package/src/cli.js
CHANGED
|
@@ -1,234 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import { build } from './cli/build'
|
|
8
|
-
import { help } from './cli/help'
|
|
9
|
-
import { init } from './cli/init'
|
|
10
|
-
|
|
11
|
-
function isESM() {
|
|
12
|
-
const pkgPath = path.resolve('./package.json')
|
|
13
|
-
|
|
14
|
-
try {
|
|
15
|
-
let pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'))
|
|
16
|
-
return pkg.type && pkg.type === 'module'
|
|
17
|
-
} catch (err) {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let configs = isESM()
|
|
23
|
-
? {
|
|
24
|
-
tailwind: 'tailwind.config.cjs',
|
|
25
|
-
postcss: 'postcss.config.cjs',
|
|
26
|
-
}
|
|
27
|
-
: {
|
|
28
|
-
tailwind: 'tailwind.config.js',
|
|
29
|
-
postcss: 'postcss.config.js',
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// ---
|
|
33
|
-
|
|
34
|
-
function oneOf(...options) {
|
|
35
|
-
return Object.assign(
|
|
36
|
-
(value = true) => {
|
|
37
|
-
for (let option of options) {
|
|
38
|
-
let parsed = option(value)
|
|
39
|
-
if (parsed === value) {
|
|
40
|
-
return parsed
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
throw new Error('...')
|
|
45
|
-
},
|
|
46
|
-
{ manualParsing: true }
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let commands = {
|
|
51
|
-
init: {
|
|
52
|
-
run: init,
|
|
53
|
-
args: {
|
|
54
|
-
'--full': { type: Boolean, description: `Initialize a full \`${configs.tailwind}\` file` },
|
|
55
|
-
'--postcss': { type: Boolean, description: `Initialize a \`${configs.postcss}\` file` },
|
|
56
|
-
'-f': '--full',
|
|
57
|
-
'-p': '--postcss',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
build: {
|
|
61
|
-
run: build,
|
|
62
|
-
args: {
|
|
63
|
-
'--input': { type: String, description: 'Input file' },
|
|
64
|
-
'--output': { type: String, description: 'Output file' },
|
|
65
|
-
'--watch': {
|
|
66
|
-
type: oneOf(String, Boolean),
|
|
67
|
-
description: 'Watch for changes and rebuild as needed',
|
|
68
|
-
},
|
|
69
|
-
'--poll': {
|
|
70
|
-
type: Boolean,
|
|
71
|
-
description: 'Use polling instead of filesystem events when watching',
|
|
72
|
-
},
|
|
73
|
-
'--content': {
|
|
74
|
-
type: String,
|
|
75
|
-
description: 'Content paths to use for removing unused classes',
|
|
76
|
-
},
|
|
77
|
-
'--purge': {
|
|
78
|
-
type: String,
|
|
79
|
-
deprecated: true,
|
|
80
|
-
},
|
|
81
|
-
'--postcss': {
|
|
82
|
-
type: oneOf(String, Boolean),
|
|
83
|
-
description: 'Load custom PostCSS configuration',
|
|
84
|
-
},
|
|
85
|
-
'--minify': { type: Boolean, description: 'Minify the output' },
|
|
86
|
-
'--config': {
|
|
87
|
-
type: String,
|
|
88
|
-
description: 'Path to a custom config file',
|
|
89
|
-
},
|
|
90
|
-
'--no-autoprefixer': {
|
|
91
|
-
type: Boolean,
|
|
92
|
-
description: 'Disable autoprefixer',
|
|
93
|
-
},
|
|
94
|
-
'-c': '--config',
|
|
95
|
-
'-i': '--input',
|
|
96
|
-
'-o': '--output',
|
|
97
|
-
'-m': '--minify',
|
|
98
|
-
'-w': '--watch',
|
|
99
|
-
'-p': '--poll',
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
let sharedFlags = {
|
|
105
|
-
'--help': { type: Boolean, description: 'Display usage information' },
|
|
106
|
-
'-h': '--help',
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
process.stdout.isTTY /* Detect redirecting output to a file */ &&
|
|
111
|
-
(process.argv[2] === undefined ||
|
|
112
|
-
process.argv.slice(2).every((flag) => sharedFlags[flag] !== undefined))
|
|
113
|
-
) {
|
|
114
|
-
help({
|
|
115
|
-
usage: [
|
|
116
|
-
'tailwindcss [--input input.css] [--output output.css] [--watch] [options...]',
|
|
117
|
-
'tailwindcss init [--full] [--postcss] [options...]',
|
|
118
|
-
],
|
|
119
|
-
commands: Object.keys(commands)
|
|
120
|
-
.filter((command) => command !== 'build')
|
|
121
|
-
.map((command) => `${command} [options]`),
|
|
122
|
-
options: { ...commands.build.args, ...sharedFlags },
|
|
123
|
-
})
|
|
124
|
-
process.exit(0)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let command = ((arg = '') => (arg.startsWith('-') ? undefined : arg))(process.argv[2]) || 'build'
|
|
128
|
-
|
|
129
|
-
if (commands[command] === undefined) {
|
|
130
|
-
if (fs.existsSync(path.resolve(command))) {
|
|
131
|
-
// TODO: Deprecate this in future versions
|
|
132
|
-
// Check if non-existing command, might be a file.
|
|
133
|
-
command = 'build'
|
|
134
|
-
} else {
|
|
135
|
-
help({
|
|
136
|
-
message: `Invalid command: ${command}`,
|
|
137
|
-
usage: ['tailwindcss <command> [options]'],
|
|
138
|
-
commands: Object.keys(commands)
|
|
139
|
-
.filter((command) => command !== 'build')
|
|
140
|
-
.map((command) => `${command} [options]`),
|
|
141
|
-
options: sharedFlags,
|
|
142
|
-
})
|
|
143
|
-
process.exit(1)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Execute command
|
|
148
|
-
let { args: flags, run } = commands[command]
|
|
149
|
-
let args = (() => {
|
|
150
|
-
try {
|
|
151
|
-
let result = arg(
|
|
152
|
-
Object.fromEntries(
|
|
153
|
-
Object.entries({ ...flags, ...sharedFlags })
|
|
154
|
-
.filter(([_key, value]) => !value?.type?.manualParsing)
|
|
155
|
-
.map(([key, value]) => [key, typeof value === 'object' ? value.type : value])
|
|
156
|
-
),
|
|
157
|
-
{ permissive: true }
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
// Manual parsing of flags to allow for special flags like oneOf(Boolean, String)
|
|
161
|
-
for (let i = result['_'].length - 1; i >= 0; --i) {
|
|
162
|
-
let flag = result['_'][i]
|
|
163
|
-
if (!flag.startsWith('-')) continue
|
|
164
|
-
|
|
165
|
-
let [flagName, flagValue] = flag.split('=')
|
|
166
|
-
let handler = flags[flagName]
|
|
167
|
-
|
|
168
|
-
// Resolve flagName & handler
|
|
169
|
-
while (typeof handler === 'string') {
|
|
170
|
-
flagName = handler
|
|
171
|
-
handler = flags[handler]
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (!handler) continue
|
|
175
|
-
|
|
176
|
-
let args = []
|
|
177
|
-
let offset = i + 1
|
|
178
|
-
|
|
179
|
-
// --flag value syntax was used so we need to pull `value` from `args`
|
|
180
|
-
if (flagValue === undefined) {
|
|
181
|
-
// Parse args for current flag
|
|
182
|
-
while (result['_'][offset] && !result['_'][offset].startsWith('-')) {
|
|
183
|
-
args.push(result['_'][offset++])
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Cleanup manually parsed flags + args
|
|
187
|
-
result['_'].splice(i, 1 + args.length)
|
|
188
|
-
|
|
189
|
-
// No args were provided, use default value defined in handler
|
|
190
|
-
// One arg was provided, use that directly
|
|
191
|
-
// Multiple args were provided so pass them all in an array
|
|
192
|
-
flagValue = args.length === 0 ? undefined : args.length === 1 ? args[0] : args
|
|
193
|
-
} else {
|
|
194
|
-
// Remove the whole flag from the args array
|
|
195
|
-
result['_'].splice(i, 1)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// Set the resolved value in the `result` object
|
|
199
|
-
result[flagName] = handler.type(flagValue, flagName)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// Ensure that the `command` is always the first argument in the `args`.
|
|
203
|
-
// This is important so that we don't have to check if a default command
|
|
204
|
-
// (build) was used or not from within each plugin.
|
|
205
|
-
//
|
|
206
|
-
// E.g.: tailwindcss input.css -> _: ['build', 'input.css']
|
|
207
|
-
// E.g.: tailwindcss build input.css -> _: ['build', 'input.css']
|
|
208
|
-
if (result['_'][0] !== command) {
|
|
209
|
-
result['_'].unshift(command)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return result
|
|
213
|
-
} catch (err) {
|
|
214
|
-
if (err.code === 'ARG_UNKNOWN_OPTION') {
|
|
215
|
-
help({
|
|
216
|
-
message: err.message,
|
|
217
|
-
usage: ['tailwindcss <command> [options]'],
|
|
218
|
-
options: sharedFlags,
|
|
219
|
-
})
|
|
220
|
-
process.exit(1)
|
|
221
|
-
}
|
|
222
|
-
throw err
|
|
223
|
-
}
|
|
224
|
-
})()
|
|
225
|
-
|
|
226
|
-
if (args['--help']) {
|
|
227
|
-
help({
|
|
228
|
-
options: { ...flags, ...sharedFlags },
|
|
229
|
-
usage: [`tailwindcss ${command} [options]`],
|
|
230
|
-
})
|
|
231
|
-
process.exit(0)
|
|
3
|
+
if (process.env.OXIDE) {
|
|
4
|
+
module.exports = require('../oxide/packages/tailwindcss/dist/cli.js')
|
|
5
|
+
} else {
|
|
6
|
+
module.exports = require('./cli/index.js')
|
|
232
7
|
}
|
|
233
|
-
|
|
234
|
-
run(args, configs)
|
package/src/index.js
CHANGED
|
@@ -1,47 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = function tailwindcss(configOrPath) {
|
|
7
|
-
return {
|
|
8
|
-
postcssPlugin: 'tailwindcss',
|
|
9
|
-
plugins: [
|
|
10
|
-
env.DEBUG &&
|
|
11
|
-
function (root) {
|
|
12
|
-
console.log('\n')
|
|
13
|
-
console.time('JIT TOTAL')
|
|
14
|
-
return root
|
|
15
|
-
},
|
|
16
|
-
function (root, result) {
|
|
17
|
-
// Use the path for the `@config` directive if it exists, otherwise use the
|
|
18
|
-
// path for the file being processed
|
|
19
|
-
configOrPath = findAtConfigPath(root, result) ?? configOrPath
|
|
20
|
-
|
|
21
|
-
let context = setupTrackingContext(configOrPath)
|
|
22
|
-
|
|
23
|
-
if (root.type === 'document') {
|
|
24
|
-
let roots = root.nodes.filter((node) => node.type === 'root')
|
|
25
|
-
|
|
26
|
-
for (const root of roots) {
|
|
27
|
-
if (root.type === 'root') {
|
|
28
|
-
processTailwindFeatures(context)(root, result)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
processTailwindFeatures(context)(root, result)
|
|
36
|
-
},
|
|
37
|
-
env.DEBUG &&
|
|
38
|
-
function (root) {
|
|
39
|
-
console.timeEnd('JIT TOTAL')
|
|
40
|
-
console.log('\n')
|
|
41
|
-
return root
|
|
42
|
-
},
|
|
43
|
-
].filter(Boolean),
|
|
44
|
-
}
|
|
1
|
+
if (process.env.OXIDE) {
|
|
2
|
+
module.exports = require('../oxide/packages/tailwindcss/dist/postcss-plugin.js')
|
|
3
|
+
} else {
|
|
4
|
+
module.exports = require('./plugin.js')
|
|
45
5
|
}
|
|
46
|
-
|
|
47
|
-
module.exports.postcss = true
|
package/src/plugin.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import setupTrackingContext from './lib/setupTrackingContext'
|
|
2
|
+
import processTailwindFeatures from './processTailwindFeatures'
|
|
3
|
+
import { env } from './lib/sharedState'
|
|
4
|
+
import { findAtConfigPath } from './lib/findAtConfigPath'
|
|
5
|
+
|
|
6
|
+
module.exports = function tailwindcss(configOrPath) {
|
|
7
|
+
return {
|
|
8
|
+
postcssPlugin: 'tailwindcss',
|
|
9
|
+
plugins: [
|
|
10
|
+
env.DEBUG &&
|
|
11
|
+
function (root) {
|
|
12
|
+
console.log('\n')
|
|
13
|
+
console.time('JIT TOTAL')
|
|
14
|
+
return root
|
|
15
|
+
},
|
|
16
|
+
function (root, result) {
|
|
17
|
+
// Use the path for the `@config` directive if it exists, otherwise use the
|
|
18
|
+
// path for the file being processed
|
|
19
|
+
configOrPath = findAtConfigPath(root, result) ?? configOrPath
|
|
20
|
+
|
|
21
|
+
let context = setupTrackingContext(configOrPath)
|
|
22
|
+
|
|
23
|
+
if (root.type === 'document') {
|
|
24
|
+
let roots = root.nodes.filter((node) => node.type === 'root')
|
|
25
|
+
|
|
26
|
+
for (const root of roots) {
|
|
27
|
+
if (root.type === 'root') {
|
|
28
|
+
processTailwindFeatures(context)(root, result)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
processTailwindFeatures(context)(root, result)
|
|
36
|
+
},
|
|
37
|
+
env.DEBUG &&
|
|
38
|
+
function (root) {
|
|
39
|
+
console.timeEnd('JIT TOTAL')
|
|
40
|
+
console.log('\n')
|
|
41
|
+
return root
|
|
42
|
+
},
|
|
43
|
+
].filter(Boolean),
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
module.exports.postcss = true
|