@modern-js/plugin-tailwindcss 2.14.0 → 2.16.0
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 +25 -0
- package/dist/cjs/cli.js +130 -158
- package/dist/cjs/design-token/cli/index.js +93 -111
- package/dist/cjs/design-token/index.js +26 -36
- package/dist/cjs/design-token/postcss-plugin/index.js +8 -26
- package/dist/cjs/design-token/runtime/index.js +27 -37
- package/dist/cjs/design-token/runtime/plugin.js +90 -52
- package/dist/cjs/index.js +13 -34
- package/dist/cjs/tailwind.js +33 -52
- package/dist/cjs/types.js +4 -15
- package/dist/cjs/utils.js +36 -49
- package/dist/esm/cli.js +264 -253
- package/dist/esm/design-token/cli/index.js +112 -113
- package/dist/esm/design-token/index.js +1 -2
- package/dist/esm/design-token/postcss-plugin/index.js +17 -17
- package/dist/esm/design-token/runtime/index.js +1 -2
- package/dist/esm/design-token/runtime/plugin.js +71 -71
- package/dist/esm/index.js +1 -2
- package/dist/esm/tailwind.js +88 -76
- package/dist/esm/types.js +1 -1
- package/dist/esm/utils.js +183 -177
- package/dist/esm-node/cli.js +109 -137
- package/dist/esm-node/design-token/cli/index.js +85 -94
- package/dist/esm-node/design-token/index.js +1 -4
- package/dist/esm-node/design-token/postcss-plugin/index.js +1 -6
- package/dist/esm-node/design-token/runtime/index.js +1 -4
- package/dist/esm-node/design-token/runtime/plugin.js +29 -18
- package/dist/esm-node/index.js +1 -4
- package/dist/esm-node/tailwind.js +24 -27
- package/dist/esm-node/types.js +1 -0
- package/dist/esm-node/utils.js +19 -18
- package/package.json +15 -11
package/dist/esm/cli.js
CHANGED
@@ -1,126 +1,133 @@
|
|
1
1
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
2
|
+
try {
|
3
|
+
var info = gen[key](arg);
|
4
|
+
var value = info.value;
|
5
|
+
} catch (error) {
|
6
|
+
reject(error);
|
7
|
+
return;
|
8
|
+
}
|
9
|
+
if (info.done) {
|
10
|
+
resolve(value);
|
11
|
+
} else {
|
12
|
+
Promise.resolve(value).then(_next, _throw);
|
13
|
+
}
|
14
14
|
}
|
15
|
-
function
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
function _async_to_generator(fn) {
|
16
|
+
return function() {
|
17
|
+
var self = this, args = arguments;
|
18
|
+
return new Promise(function(resolve, reject) {
|
19
|
+
var gen = fn.apply(self, args);
|
20
|
+
function _next(value) {
|
21
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
22
|
+
}
|
23
|
+
function _throw(err) {
|
24
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
25
|
+
}
|
26
|
+
_next(void 0);
|
27
|
+
});
|
28
|
+
};
|
29
29
|
}
|
30
|
-
var __generator =
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
30
|
+
var __generator = function(thisArg, body) {
|
31
|
+
var f, y, t, g, _ = {
|
32
|
+
label: 0,
|
33
|
+
sent: function() {
|
34
|
+
if (t[0] & 1)
|
35
|
+
throw t[1];
|
36
|
+
return t[1];
|
37
|
+
},
|
38
|
+
trys: [],
|
39
|
+
ops: []
|
40
|
+
};
|
41
|
+
return g = {
|
42
|
+
next: verb(0),
|
43
|
+
"throw": verb(1),
|
44
|
+
"return": verb(2)
|
45
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
46
|
+
return this;
|
47
|
+
}), g;
|
48
|
+
function verb(n) {
|
49
|
+
return function(v) {
|
50
|
+
return step([
|
51
|
+
n,
|
52
|
+
v
|
53
|
+
]);
|
39
54
|
};
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
break;
|
68
|
-
case 4:
|
69
|
-
_.label++;
|
70
|
-
return {
|
71
|
-
value: op[1],
|
72
|
-
done: false
|
73
|
-
};
|
74
|
-
case 5:
|
75
|
-
_.label++;
|
76
|
-
y = op[1];
|
77
|
-
op = [
|
78
|
-
0
|
79
|
-
];
|
80
|
-
continue;
|
81
|
-
case 7:
|
82
|
-
op = _.ops.pop();
|
83
|
-
_.trys.pop();
|
84
|
-
continue;
|
85
|
-
default:
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
87
|
-
_ = 0;
|
88
|
-
continue;
|
89
|
-
}
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
91
|
-
_.label = op[1];
|
92
|
-
break;
|
93
|
-
}
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
95
|
-
_.label = t[1];
|
96
|
-
t = op;
|
97
|
-
break;
|
98
|
-
}
|
99
|
-
if (t && _.label < t[2]) {
|
100
|
-
_.label = t[2];
|
101
|
-
_.ops.push(op);
|
102
|
-
break;
|
103
|
-
}
|
104
|
-
if (t[2]) _.ops.pop();
|
105
|
-
_.trys.pop();
|
106
|
-
continue;
|
107
|
-
}
|
108
|
-
op = body.call(thisArg, _);
|
109
|
-
} catch (e) {
|
55
|
+
}
|
56
|
+
function step(op) {
|
57
|
+
if (f)
|
58
|
+
throw new TypeError("Generator is already executing.");
|
59
|
+
while (_)
|
60
|
+
try {
|
61
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
|
62
|
+
return t;
|
63
|
+
if (y = 0, t)
|
64
|
+
op = [
|
65
|
+
op[0] & 2,
|
66
|
+
t.value
|
67
|
+
];
|
68
|
+
switch (op[0]) {
|
69
|
+
case 0:
|
70
|
+
case 1:
|
71
|
+
t = op;
|
72
|
+
break;
|
73
|
+
case 4:
|
74
|
+
_.label++;
|
75
|
+
return {
|
76
|
+
value: op[1],
|
77
|
+
done: false
|
78
|
+
};
|
79
|
+
case 5:
|
80
|
+
_.label++;
|
81
|
+
y = op[1];
|
110
82
|
op = [
|
111
|
-
|
112
|
-
e
|
83
|
+
0
|
113
84
|
];
|
114
|
-
|
115
|
-
|
116
|
-
|
85
|
+
continue;
|
86
|
+
case 7:
|
87
|
+
op = _.ops.pop();
|
88
|
+
_.trys.pop();
|
89
|
+
continue;
|
90
|
+
default:
|
91
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
92
|
+
_ = 0;
|
93
|
+
continue;
|
94
|
+
}
|
95
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
96
|
+
_.label = op[1];
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
if (op[0] === 6 && _.label < t[1]) {
|
100
|
+
_.label = t[1];
|
101
|
+
t = op;
|
102
|
+
break;
|
103
|
+
}
|
104
|
+
if (t && _.label < t[2]) {
|
105
|
+
_.label = t[2];
|
106
|
+
_.ops.push(op);
|
107
|
+
break;
|
108
|
+
}
|
109
|
+
if (t[2])
|
110
|
+
_.ops.pop();
|
111
|
+
_.trys.pop();
|
112
|
+
continue;
|
117
113
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
114
|
+
op = body.call(thisArg, _);
|
115
|
+
} catch (e) {
|
116
|
+
op = [
|
117
|
+
6,
|
118
|
+
e
|
119
|
+
];
|
120
|
+
y = 0;
|
121
|
+
} finally {
|
122
|
+
f = t = 0;
|
123
|
+
}
|
124
|
+
if (op[0] & 5)
|
125
|
+
throw op[1];
|
126
|
+
return {
|
127
|
+
value: op[0] ? op[1] : void 0,
|
128
|
+
done: true
|
129
|
+
};
|
130
|
+
}
|
124
131
|
};
|
125
132
|
import path from "path";
|
126
133
|
import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from "@modern-js/utils";
|
@@ -128,145 +135,149 @@ import designTokenPlugin from "./design-token/cli";
|
|
128
135
|
import { getTailwindConfig } from "./tailwind";
|
129
136
|
import { template, checkTwinMacroExist, getTailwindPath, getTailwindVersion, getTwinMacroMajorVersion } from "./utils";
|
130
137
|
var supportCssInJsLibrary = "styled-components";
|
131
|
-
var getRandomTwConfigFileName = function(internalDirectory) {
|
132
|
-
|
138
|
+
export var getRandomTwConfigFileName = function(internalDirectory) {
|
139
|
+
return slash(path.join(internalDirectory, "tailwind.config.".concat(Date.now(), ".").concat(nanoid(), ".js")));
|
133
140
|
};
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
141
|
+
export default function() {
|
142
|
+
var pluginName = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
143
|
+
pluginName: "@modern-js/plugin-tailwindcss"
|
144
|
+
}).pluginName;
|
145
|
+
return {
|
146
|
+
name: "@modern-js/plugin-tailwindcss",
|
147
|
+
// support designSystem.supportStyledComponents
|
148
|
+
usePlugins: [
|
149
|
+
designTokenPlugin({
|
150
|
+
pluginName
|
151
|
+
})
|
152
|
+
],
|
153
|
+
setup: function() {
|
154
|
+
var _ref = _async_to_generator(function(api) {
|
155
|
+
var _api_useAppContext, appDirectory, internalDirectory, internalTwConfigPath, haveTwinMacro, tailwindPath, tailwindVersion, defaultContent;
|
156
|
+
return __generator(this, function(_state) {
|
157
|
+
switch (_state.label) {
|
158
|
+
case 0:
|
159
|
+
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, internalDirectory = _api_useAppContext.internalDirectory;
|
160
|
+
internalTwConfigPath = "";
|
161
|
+
return [
|
162
|
+
4,
|
163
|
+
checkTwinMacroExist(appDirectory)
|
164
|
+
];
|
165
|
+
case 1:
|
166
|
+
haveTwinMacro = _state.sent();
|
167
|
+
tailwindPath = getTailwindPath(appDirectory);
|
168
|
+
tailwindVersion = getTailwindVersion(appDirectory);
|
169
|
+
defaultContent = [
|
170
|
+
"./config/html/**/*.html",
|
171
|
+
"./config/html/**/*.ejs",
|
172
|
+
"./config/html/**/*.hbs",
|
173
|
+
"./src/**/*.js",
|
174
|
+
"./src/**/*.jsx",
|
175
|
+
"./src/**/*.ts",
|
176
|
+
"./src/**/*.tsx",
|
177
|
+
// about storybook
|
178
|
+
"./storybook/**/*"
|
179
|
+
];
|
180
|
+
return [
|
181
|
+
2,
|
182
|
+
{
|
183
|
+
prepare: function prepare() {
|
184
|
+
if (haveTwinMacro) {
|
185
|
+
var twinMajorVersion = getTwinMacroMajorVersion(appDirectory);
|
186
|
+
var useConfigPath = twinMajorVersion && twinMajorVersion < 3;
|
187
|
+
if (useConfigPath) {
|
188
|
+
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
189
|
+
var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs"));
|
190
|
+
var files = globby.sync(globPattern, {
|
191
|
+
absolute: true
|
192
|
+
});
|
193
|
+
if (files.length > 0) {
|
194
|
+
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), "utf-8");
|
195
|
+
}
|
196
|
+
}
|
197
|
+
}
|
198
|
+
},
|
199
|
+
validateSchema: function validateSchema() {
|
200
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
|
201
|
+
},
|
202
|
+
config: function config() {
|
203
|
+
var tailwindConfig;
|
204
|
+
var initTailwindConfig = function() {
|
205
|
+
if (!tailwindConfig) {
|
206
|
+
var _modernConfig_tools, _modernConfig_source;
|
207
|
+
var modernConfig = api.useResolvedConfigContext();
|
208
|
+
tailwindConfig = getTailwindConfig(tailwindVersion, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_tools = modernConfig.tools) === null || _modernConfig_tools === void 0 ? void 0 : _modernConfig_tools.tailwindcss, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_source = modernConfig.source) === null || _modernConfig_source === void 0 ? void 0 : _modernConfig_source.designSystem, {
|
209
|
+
pureConfig: {
|
210
|
+
content: defaultContent
|
211
|
+
}
|
212
|
+
});
|
213
|
+
}
|
214
|
+
};
|
215
|
+
return {
|
216
|
+
tools: {
|
217
|
+
// TODO: Add interface about postcss config
|
218
|
+
// TODO: In module project, also is called, but should not be called.
|
219
|
+
postcss: function(config2) {
|
220
|
+
initTailwindConfig();
|
221
|
+
var tailwindPlugin = require(tailwindPath)(tailwindConfig);
|
222
|
+
if (Array.isArray(config2.postcssOptions.plugins)) {
|
223
|
+
config2.postcssOptions.plugins.push(tailwindPlugin);
|
224
|
+
} else {
|
225
|
+
config2.postcssOptions.plugins = [
|
226
|
+
tailwindPlugin
|
172
227
|
];
|
173
|
-
|
174
|
-
|
228
|
+
}
|
229
|
+
},
|
230
|
+
babel: function babel(_, param) {
|
231
|
+
var addPlugins = param.addPlugins;
|
232
|
+
if (haveTwinMacro) {
|
233
|
+
initTailwindConfig();
|
234
|
+
addPlugins([
|
235
|
+
[
|
236
|
+
require.resolve("babel-plugin-macros"),
|
175
237
|
{
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
if (useConfigPath) {
|
181
|
-
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
182
|
-
var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs"));
|
183
|
-
var files = globby.sync(globPattern, {
|
184
|
-
absolute: true
|
185
|
-
});
|
186
|
-
if (files.length > 0) {
|
187
|
-
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), "utf-8");
|
188
|
-
}
|
189
|
-
}
|
190
|
-
}
|
191
|
-
},
|
192
|
-
validateSchema: function validateSchema() {
|
193
|
-
return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
|
194
|
-
},
|
195
|
-
config: function config() {
|
196
|
-
var tailwindConfig;
|
197
|
-
var initTailwindConfig = function() {
|
198
|
-
if (!tailwindConfig) {
|
199
|
-
var _modernConfig_tools, _modernConfig_source;
|
200
|
-
var modernConfig = api.useResolvedConfigContext();
|
201
|
-
tailwindConfig = getTailwindConfig(tailwindVersion, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_tools = modernConfig.tools) === null || _modernConfig_tools === void 0 ? void 0 : _modernConfig_tools.tailwindcss, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_source = modernConfig.source) === null || _modernConfig_source === void 0 ? void 0 : _modernConfig_source.designSystem, {
|
202
|
-
pureConfig: {
|
203
|
-
content: defaultContent
|
204
|
-
}
|
205
|
-
});
|
206
|
-
}
|
207
|
-
};
|
208
|
-
return {
|
209
|
-
tools: {
|
210
|
-
// TODO: Add interface about postcss config
|
211
|
-
// TODO: In module project, also is called, but should not be called.
|
212
|
-
postcss: function(config) {
|
213
|
-
initTailwindConfig();
|
214
|
-
var tailwindPlugin = require(tailwindPath)(tailwindConfig);
|
215
|
-
if (Array.isArray(config.postcssOptions.plugins)) {
|
216
|
-
config.postcssOptions.plugins.push(tailwindPlugin);
|
217
|
-
} else {
|
218
|
-
config.postcssOptions.plugins = [
|
219
|
-
tailwindPlugin
|
220
|
-
];
|
221
|
-
}
|
222
|
-
},
|
223
|
-
babel: function babel(_, param) {
|
224
|
-
var addPlugins = param.addPlugins;
|
225
|
-
if (haveTwinMacro) {
|
226
|
-
initTailwindConfig();
|
227
|
-
addPlugins([
|
228
|
-
[
|
229
|
-
require.resolve("babel-plugin-macros"),
|
230
|
-
{
|
231
|
-
twin: {
|
232
|
-
preset: supportCssInJsLibrary,
|
233
|
-
config: internalTwConfigPath || tailwindConfig
|
234
|
-
}
|
235
|
-
}
|
236
|
-
]
|
237
|
-
]);
|
238
|
-
}
|
239
|
-
}
|
240
|
-
}
|
241
|
-
};
|
242
|
-
},
|
243
|
-
beforeBuildTask: function beforeBuildTask(config) {
|
244
|
-
var modernConfig = api.useResolvedConfigContext();
|
245
|
-
var designSystem = modernConfig.designSystem;
|
246
|
-
var tailwindConfig = getTailwindConfig(tailwindVersion, config.style.tailwindCss, designSystem, {
|
247
|
-
pureConfig: {
|
248
|
-
content: defaultContent
|
249
|
-
}
|
250
|
-
});
|
251
|
-
var tailwindPlugin = require(tailwindPath)(tailwindConfig);
|
252
|
-
if (Array.isArray(config.style.postcss.plugins)) {
|
253
|
-
config.style.postcss.plugins.push(tailwindPlugin);
|
254
|
-
} else {
|
255
|
-
config.style.postcss.plugins = [
|
256
|
-
tailwindPlugin
|
257
|
-
];
|
258
|
-
}
|
259
|
-
return config;
|
260
|
-
}
|
238
|
+
twin: {
|
239
|
+
preset: supportCssInJsLibrary,
|
240
|
+
config: internalTwConfigPath || tailwindConfig
|
241
|
+
}
|
261
242
|
}
|
262
|
-
|
243
|
+
]
|
244
|
+
]);
|
245
|
+
}
|
246
|
+
}
|
247
|
+
}
|
248
|
+
};
|
249
|
+
},
|
250
|
+
beforeBuildTask: function beforeBuildTask(config) {
|
251
|
+
var modernConfig = api.useResolvedConfigContext();
|
252
|
+
var designSystem = modernConfig.designSystem;
|
253
|
+
var tailwindConfig = getTailwindConfig(tailwindVersion, config.style.tailwindCss, designSystem, {
|
254
|
+
pureConfig: {
|
255
|
+
content: defaultContent
|
256
|
+
}
|
257
|
+
});
|
258
|
+
var tailwindPlugin = require(tailwindPath)(tailwindConfig);
|
259
|
+
if (Array.isArray(config.style.postcss.plugins)) {
|
260
|
+
config.style.postcss.plugins.push(tailwindPlugin);
|
261
|
+
} else {
|
262
|
+
config.style.postcss.plugins = [
|
263
|
+
tailwindPlugin
|
264
|
+
];
|
263
265
|
}
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
266
|
+
return config;
|
267
|
+
},
|
268
|
+
modifyLibuild: function modifyLibuild(config, next) {
|
269
|
+
config.transformCache = false;
|
270
|
+
return next(config);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
];
|
274
|
+
}
|
275
|
+
});
|
276
|
+
});
|
277
|
+
return function(api) {
|
278
|
+
return _ref.apply(this, arguments);
|
279
|
+
};
|
280
|
+
}()
|
281
|
+
};
|
282
|
+
}
|
283
|
+
;
|