@modern-js/plugin-tailwindcss 2.0.0-beta.2 → 2.0.0-beta.4
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 +181 -0
- package/dist/js/modern/cli.js +139 -84
- package/dist/js/modern/design-token/cli/index.js +58 -54
- package/dist/js/modern/design-token/global.d.js +0 -0
- package/dist/js/modern/design-token/index.js +5 -2
- package/dist/js/modern/design-token/postcss-plugin/index.js +11 -8
- package/dist/js/modern/design-token/runtime/index.js +4 -1
- package/dist/js/modern/design-token/runtime/plugin.js +41 -29
- package/dist/js/modern/index.js +4 -1
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/modern/tailwind.js +30 -24
- package/dist/js/modern/utils.js +32 -8
- package/dist/js/node/cli.js +159 -95
- package/dist/js/node/design-token/cli/index.js +71 -59
- package/dist/js/node/design-token/global.d.js +0 -0
- package/dist/js/node/design-token/index.js +29 -24
- package/dist/js/node/design-token/postcss-plugin/index.js +28 -13
- package/dist/js/node/design-token/runtime/index.js +31 -22
- package/dist/js/node/design-token/runtime/plugin.js +65 -40
- package/dist/js/node/index.js +27 -11
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/node/tailwind.js +49 -30
- package/dist/js/node/utils.js +56 -16
- package/dist/js/treeshaking/cli.js +266 -134
- package/dist/js/treeshaking/design-token/cli/index.js +116 -101
- package/dist/js/treeshaking/design-token/global.d.js +1 -0
- package/dist/js/treeshaking/design-token/index.js +3 -2
- package/dist/js/treeshaking/design-token/postcss-plugin/index.js +17 -26
- package/dist/js/treeshaking/design-token/runtime/index.js +2 -1
- package/dist/js/treeshaking/design-token/runtime/plugin.js +76 -55
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/modern-app.env.d.js +1 -0
- package/dist/js/treeshaking/tailwind.js +86 -43
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/js/treeshaking/utils.js +159 -44
- package/dist/types/cli.d.ts +5 -2
- package/dist/types/design-token/cli/index.d.ts +2 -0
- package/dist/types/design-token/postcss-plugin/index.d.ts +2 -0
- package/dist/types/design-token/runtime/plugin.d.ts +2 -0
- package/dist/types/tailwind.d.ts +3 -3
- package/dist/types/types.d.ts +4 -10
- package/package.json +11 -9
package/dist/js/node/utils.js
CHANGED
@@ -1,13 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Object.
|
4
|
-
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
21
|
+
mod
|
22
|
+
));
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
24
|
+
var stdin_exports = {};
|
25
|
+
__export(stdin_exports, {
|
26
|
+
checkTwinMacroNotExist: () => checkTwinMacroNotExist,
|
27
|
+
template: () => template
|
5
28
|
});
|
6
|
-
|
7
|
-
var
|
8
|
-
var
|
9
|
-
|
10
|
-
|
29
|
+
module.exports = __toCommonJS(stdin_exports);
|
30
|
+
var import_path = __toESM(require("path"));
|
31
|
+
var import_utils = require("@modern-js/utils");
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
33
|
+
return new Promise((resolve, reject) => {
|
34
|
+
var fulfilled = (value) => {
|
35
|
+
try {
|
36
|
+
step(generator.next(value));
|
37
|
+
} catch (e) {
|
38
|
+
reject(e);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
var rejected = (value) => {
|
42
|
+
try {
|
43
|
+
step(generator.throw(value));
|
44
|
+
} catch (e) {
|
45
|
+
reject(e);
|
46
|
+
}
|
47
|
+
};
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
50
|
+
});
|
51
|
+
};
|
52
|
+
const template = (configPath) => `
|
11
53
|
function _interopRequireDefault(obj) {
|
12
54
|
return obj && obj.__esModule ? obj : { default: obj };
|
13
55
|
}
|
@@ -27,15 +69,13 @@ module.exports = {
|
|
27
69
|
...tailwindcss,
|
28
70
|
};
|
29
71
|
`;
|
30
|
-
|
31
|
-
const
|
32
|
-
const
|
33
|
-
const packageJson = (await _utils.fs.readJSON(_path.default.join(appDirectory, 'package.json'), {
|
72
|
+
const checkTwinMacroNotExist = (appDirectory) => __async(void 0, null, function* () {
|
73
|
+
const depName = "twin.macro";
|
74
|
+
const packageJson = (yield import_utils.fs.readJSON(import_path.default.join(appDirectory, "package.json"), {
|
34
75
|
throws: false
|
35
76
|
})) || {};
|
36
|
-
if (typeof packageJson.dependencies ===
|
77
|
+
if (typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName]) {
|
37
78
|
return false;
|
38
79
|
}
|
39
80
|
return true;
|
40
|
-
};
|
41
|
-
exports.checkTwinMacroNotExist = checkTwinMacroNotExist;
|
81
|
+
});
|
@@ -1,140 +1,272 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
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
|
+
}
|
15
|
+
function _asyncToGenerator(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(undefined);
|
27
|
+
});
|
28
|
+
};
|
29
|
+
}
|
30
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
31
|
+
var f, y, t, g, _ = {
|
32
|
+
label: 0,
|
33
|
+
sent: function() {
|
34
|
+
if (t[0] & 1) throw t[1];
|
35
|
+
return t[1];
|
36
|
+
},
|
37
|
+
trys: [],
|
38
|
+
ops: []
|
39
|
+
};
|
40
|
+
return(g = {
|
41
|
+
next: verb(0),
|
42
|
+
"throw": verb(1),
|
43
|
+
"return": verb(2)
|
44
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
45
|
+
return this;
|
46
|
+
}), g);
|
47
|
+
function verb(n) {
|
48
|
+
return function(v) {
|
49
|
+
return step([
|
50
|
+
n,
|
51
|
+
v
|
52
|
+
]);
|
53
|
+
};
|
54
|
+
}
|
55
|
+
function step(op) {
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
57
|
+
while(_)try {
|
58
|
+
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) return t;
|
59
|
+
if (y = 0, t) op = [
|
60
|
+
op[0] & 2,
|
61
|
+
t.value
|
62
|
+
];
|
63
|
+
switch(op[0]){
|
64
|
+
case 0:
|
65
|
+
case 1:
|
66
|
+
t = op;
|
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) {
|
110
|
+
op = [
|
111
|
+
6,
|
112
|
+
e
|
113
|
+
];
|
114
|
+
y = 0;
|
115
|
+
} finally{
|
116
|
+
f = t = 0;
|
117
|
+
}
|
118
|
+
if (op[0] & 5) throw op[1];
|
119
|
+
return {
|
120
|
+
value: op[0] ? op[1] : void 0,
|
121
|
+
done: true
|
122
|
+
};
|
123
|
+
}
|
124
|
+
};
|
125
|
+
import path from "path";
|
126
|
+
import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from "@modern-js/utils";
|
6
127
|
import DesignTokenPlugin from "./design-token/cli";
|
7
128
|
import { getTailwindConfig } from "./tailwind";
|
8
129
|
import { template, checkTwinMacroNotExist } from "./utils";
|
9
|
-
var supportCssInJsLibrary =
|
10
|
-
|
11
|
-
|
130
|
+
var supportCssInJsLibrary = "styled-components";
|
131
|
+
var getRandomTwConfigFileName = function(internalDirectory) {
|
132
|
+
return slash(path.join(internalDirectory, "tailwind.config.".concat(Date.now(), ".").concat(nanoid(), ".js")));
|
12
133
|
};
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
134
|
+
var cli_default = function() {
|
135
|
+
var pluginName = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {
|
136
|
+
pluginName: "@modern-js/plugin-tailwindcss"
|
137
|
+
}).pluginName;
|
138
|
+
return {
|
139
|
+
name: "@modern-js/plugin-tailwindcss",
|
140
|
+
usePlugins: [
|
141
|
+
DesignTokenPlugin({
|
142
|
+
pluginName: pluginName
|
143
|
+
})
|
144
|
+
],
|
145
|
+
setup: function() {
|
146
|
+
var _ref = _asyncToGenerator(function(api) {
|
147
|
+
var ref, appDirectory, internalDirectory, internalTwConfigPath, notHaveTwinMacro;
|
148
|
+
return __generator(this, function(_state) {
|
149
|
+
switch(_state.label){
|
150
|
+
case 0:
|
151
|
+
ref = api.useAppContext(), appDirectory = ref.appDirectory, internalDirectory = ref.internalDirectory;
|
152
|
+
internalTwConfigPath = "";
|
153
|
+
return [
|
154
|
+
4,
|
155
|
+
checkTwinMacroNotExist(appDirectory)
|
156
|
+
];
|
157
|
+
case 1:
|
158
|
+
notHaveTwinMacro = _state.sent();
|
159
|
+
return [
|
160
|
+
2,
|
161
|
+
{
|
162
|
+
prepare: function prepare() {
|
163
|
+
if (notHaveTwinMacro) {
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
|
167
|
+
var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs"));
|
168
|
+
var files = globby.sync(globPattern, {
|
169
|
+
absolute: true
|
170
|
+
});
|
171
|
+
if (files.length > 0) {
|
172
|
+
fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), "utf-8");
|
173
|
+
}
|
174
|
+
},
|
175
|
+
validateSchema: function validateSchema() {
|
176
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
|
177
|
+
},
|
178
|
+
config: function config() {
|
179
|
+
return {
|
180
|
+
tools: {
|
181
|
+
postcss: function(config) {
|
182
|
+
var ref, ref1;
|
183
|
+
var modernConfig = api.useResolvedConfigContext();
|
184
|
+
var tailwindConfig = getTailwindConfig(modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.tools) === null || ref === void 0 ? void 0 : ref.tailwindcss, modernConfig === null || modernConfig === void 0 ? void 0 : (ref1 = modernConfig.source) === null || ref1 === void 0 ? void 0 : ref1.designSystem, {
|
185
|
+
pureConfig: {
|
186
|
+
content: [
|
187
|
+
"./config/html/**/*.html",
|
188
|
+
"./config/html/**/*.ejs",
|
189
|
+
"./config/html/**/*.hbs",
|
190
|
+
"./src/**/*.js",
|
191
|
+
"./src/**/*.jsx",
|
192
|
+
"./src/**/*.ts",
|
193
|
+
"./src/**/*.tsx",
|
194
|
+
"./storybook/**/*",
|
195
|
+
"./styles/**/*.less",
|
196
|
+
"./styles/**/*.css",
|
197
|
+
"./styles/**/*.sass",
|
198
|
+
"./styles/**/*.scss"
|
199
|
+
]
|
200
|
+
}
|
201
|
+
});
|
202
|
+
if (Array.isArray(config.postcssOptions.plugins)) {
|
203
|
+
config.postcssOptions.plugins.push(require("tailwindcss")(tailwindConfig));
|
204
|
+
} else {
|
205
|
+
config.postcssOptions.plugins = [
|
206
|
+
require("tailwindcss")(tailwindConfig)
|
207
|
+
];
|
208
|
+
}
|
209
|
+
},
|
210
|
+
babel: function babel(_, param) {
|
211
|
+
var addPlugins = param.addPlugins;
|
212
|
+
if (notHaveTwinMacro) {
|
213
|
+
return;
|
214
|
+
}
|
215
|
+
addPlugins([
|
216
|
+
[
|
217
|
+
require.resolve("babel-plugin-macros"),
|
218
|
+
{
|
219
|
+
twin: {
|
220
|
+
preset: supportCssInJsLibrary,
|
221
|
+
config: internalTwConfigPath
|
222
|
+
}
|
223
|
+
}
|
224
|
+
]
|
225
|
+
]);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
};
|
229
|
+
},
|
230
|
+
beforeBuildTask: function beforeBuildTask(param) {
|
231
|
+
var config = param.config;
|
232
|
+
var modernConfig = api.useResolvedConfigContext();
|
233
|
+
var designSystem = modernConfig.designSystem;
|
234
|
+
var tailwindConfig = getTailwindConfig(config.style.tailwindCss, designSystem, {
|
235
|
+
pureConfig: {
|
236
|
+
content: [
|
237
|
+
"./config/html/**/*.html",
|
238
|
+
"./config/html/**/*.ejs",
|
239
|
+
"./config/html/**/*.hbs",
|
240
|
+
"./src/**/*.js",
|
241
|
+
"./src/**/*.jsx",
|
242
|
+
"./src/**/*.ts",
|
243
|
+
"./src/**/*.tsx",
|
244
|
+
"./storybook/**/*",
|
245
|
+
"./styles/**/*.less",
|
246
|
+
"./styles/**/*.css",
|
247
|
+
"./styles/**/*.sass",
|
248
|
+
"./styles/**/*.scss"
|
249
|
+
]
|
250
|
+
}
|
251
|
+
});
|
252
|
+
if (Array.isArray(config.style.postcss.plugins)) {
|
253
|
+
config.style.postcss.plugins.push(require("tailwindcss")(tailwindConfig));
|
254
|
+
} else {
|
255
|
+
config.style.postcss.plugins = [
|
256
|
+
require("tailwindcss")(tailwindConfig)
|
257
|
+
];
|
258
|
+
}
|
259
|
+
return config;
|
260
|
+
}
|
116
261
|
}
|
117
|
-
|
118
|
-
|
119
|
-
}
|
120
|
-
return false;
|
121
|
-
});
|
122
|
-
}
|
123
|
-
}
|
124
|
-
};
|
125
|
-
}
|
262
|
+
];
|
263
|
+
}
|
126
264
|
});
|
127
|
-
|
128
|
-
|
129
|
-
return
|
130
|
-
}
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
return _setup.apply(this, arguments);
|
136
|
-
}
|
137
|
-
return setup;
|
138
|
-
}()
|
139
|
-
};
|
140
|
-
});
|
265
|
+
});
|
266
|
+
return function(api) {
|
267
|
+
return _ref.apply(this, arguments);
|
268
|
+
};
|
269
|
+
}()
|
270
|
+
};
|
271
|
+
};
|
272
|
+
export { cli_default as default, getRandomTwConfigFileName };
|