@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.
Files changed (42) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/dist/js/modern/cli.js +139 -84
  3. package/dist/js/modern/design-token/cli/index.js +58 -54
  4. package/dist/js/modern/design-token/global.d.js +0 -0
  5. package/dist/js/modern/design-token/index.js +5 -2
  6. package/dist/js/modern/design-token/postcss-plugin/index.js +11 -8
  7. package/dist/js/modern/design-token/runtime/index.js +4 -1
  8. package/dist/js/modern/design-token/runtime/plugin.js +41 -29
  9. package/dist/js/modern/index.js +4 -1
  10. package/dist/js/modern/modern-app.env.d.js +0 -0
  11. package/dist/js/modern/tailwind.js +30 -24
  12. package/dist/js/modern/utils.js +32 -8
  13. package/dist/js/node/cli.js +159 -95
  14. package/dist/js/node/design-token/cli/index.js +71 -59
  15. package/dist/js/node/design-token/global.d.js +0 -0
  16. package/dist/js/node/design-token/index.js +29 -24
  17. package/dist/js/node/design-token/postcss-plugin/index.js +28 -13
  18. package/dist/js/node/design-token/runtime/index.js +31 -22
  19. package/dist/js/node/design-token/runtime/plugin.js +65 -40
  20. package/dist/js/node/index.js +27 -11
  21. package/dist/js/node/modern-app.env.d.js +0 -0
  22. package/dist/js/node/tailwind.js +49 -30
  23. package/dist/js/node/utils.js +56 -16
  24. package/dist/js/treeshaking/cli.js +266 -134
  25. package/dist/js/treeshaking/design-token/cli/index.js +116 -101
  26. package/dist/js/treeshaking/design-token/global.d.js +1 -0
  27. package/dist/js/treeshaking/design-token/index.js +3 -2
  28. package/dist/js/treeshaking/design-token/postcss-plugin/index.js +17 -26
  29. package/dist/js/treeshaking/design-token/runtime/index.js +2 -1
  30. package/dist/js/treeshaking/design-token/runtime/plugin.js +76 -55
  31. package/dist/js/treeshaking/index.js +2 -1
  32. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  33. package/dist/js/treeshaking/tailwind.js +86 -43
  34. package/dist/js/treeshaking/types.js +1 -0
  35. package/dist/js/treeshaking/utils.js +159 -44
  36. package/dist/types/cli.d.ts +5 -2
  37. package/dist/types/design-token/cli/index.d.ts +2 -0
  38. package/dist/types/design-token/postcss-plugin/index.d.ts +2 -0
  39. package/dist/types/design-token/runtime/plugin.d.ts +2 -0
  40. package/dist/types/tailwind.d.ts +3 -3
  41. package/dist/types/types.d.ts +4 -10
  42. package/package.json +11 -9
@@ -1,13 +1,55 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- exports.template = exports.checkTwinMacroNotExist = void 0;
7
- var _path = _interopRequireDefault(require("path"));
8
- var _utils = require("@modern-js/utils");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const template = configPath => `
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
- exports.template = template;
31
- const checkTwinMacroNotExist = async appDirectory => {
32
- const depName = 'twin.macro';
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 === 'object' && packageJson.dependencies[depName] || typeof packageJson.devDependencies === 'object' && packageJson.devDependencies[depName]) {
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
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
- import path from 'path';
5
- import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from '@modern-js/utils';
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 = 'styled-components';
10
- export var getRandomTwConfigFileName = function getRandomTwConfigFileName(internalDirectory) {
11
- return slash(path.join(internalDirectory, "tailwind.config.".concat(Date.now(), ".").concat(nanoid(), ".js")));
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
- export default (function () {
14
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
15
- pluginName: '@modern-js/plugin-tailwindcss'
16
- },
17
- pluginName = _ref.pluginName;
18
- return {
19
- name: '@modern-js/plugin-tailwindcss',
20
- // support designSystem.supportStyledComponents
21
- usePlugins: [DesignTokenPlugin({
22
- pluginName: pluginName
23
- })],
24
- setup: function () {
25
- var _setup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
26
- var _api$useAppContext, appDirectory, internalDirectory, internalTwConfigPath, notHaveTwinMacro;
27
- return _regeneratorRuntime().wrap(function _callee$(_context) {
28
- while (1) {
29
- switch (_context.prev = _context.next) {
30
- case 0:
31
- _api$useAppContext = api.useAppContext(), appDirectory = _api$useAppContext.appDirectory, internalDirectory = _api$useAppContext.internalDirectory;
32
- internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
33
- _context.next = 4;
34
- return checkTwinMacroNotExist(appDirectory);
35
- case 4:
36
- notHaveTwinMacro = _context.sent;
37
- return _context.abrupt("return", {
38
- prepare: function prepare() {
39
- if (notHaveTwinMacro) {
40
- return;
41
- }
42
- internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
43
- var globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, '*.cjs'));
44
- var files = globby.sync(globPattern, {
45
- absolute: true
46
- });
47
- if (files.length > 0) {
48
- fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), 'utf-8');
49
- }
50
- },
51
- validateSchema: function validateSchema() {
52
- return PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
53
- },
54
- config: function config() {
55
- return {
56
- tools: {
57
- // TODO: Add interface about postcss config
58
- // TODO: In module project, also is called, but should not be called.
59
- postcss: function postcss(config) {
60
- var modernConfig = api.useResolvedConfigContext();
61
- if (!config.postcssOptions
62
- // config.$$tools === 'module-tools'
63
- ) {
64
- if (Array.isArray(config.plugins)) {
65
- var tailwindConfig = getTailwindConfig(modernConfig, {
66
- pureConfig: {
67
- content: ['./src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', './src/**/*.less', './src/**/*.css', './src/**/*.sass', './src/**/*.scss', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
68
- }
69
- });
70
- config.plugins.push(require('tailwindcss')(tailwindConfig));
71
- } else {
72
- var _tailwindConfig = getTailwindConfig(modernConfig, {
73
- pureConfig: {
74
- content: ['./src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', './src/**/*.less', './src/**/*.css', './src/**/*.sass', './src/**/*.scss', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
75
- }
76
- });
77
- config.plugins = [require('tailwindcss')(_tailwindConfig)];
78
- }
79
- } else {
80
- var _tailwindConfig2 = getTailwindConfig(modernConfig, {
81
- pureConfig: {
82
- content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx',
83
- // about storybook
84
- './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
85
- }
86
- });
87
- if (Array.isArray(config.postcssOptions.plugins)) {
88
- config.postcssOptions.plugins.push(require('tailwindcss')(_tailwindConfig2));
89
- } else {
90
- config.postcssOptions.plugins = [require('tailwindcss')(_tailwindConfig2)];
91
- }
92
- }
93
- },
94
- babel: function babel(config) {
95
- var _config$plugins;
96
- if (notHaveTwinMacro) {
97
- return;
98
- }
99
- var twinConfig = {
100
- twin: {
101
- preset: supportCssInJsLibrary,
102
- config: internalTwConfigPath
103
- }
104
- };
105
- (_config$plugins = config.plugins) === null || _config$plugins === void 0 ? void 0 : _config$plugins.some(function (plugin) {
106
- if (Array.isArray(plugin) && plugin[0]) {
107
- var pluginTarget = plugin[0];
108
- var pluginOptions = plugin[1];
109
- if (typeof pluginTarget === 'string' &&
110
- // TODO: use babel chain
111
- slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
112
- if (pluginOptions) {
113
- pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
114
- } else {
115
- plugin.push(twinConfig);
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
- return true;
118
- }
119
- }
120
- return false;
121
- });
122
- }
123
- }
124
- };
125
- }
262
+ ];
263
+ }
126
264
  });
127
- case 6:
128
- case "end":
129
- return _context.stop();
130
- }
131
- }
132
- }, _callee);
133
- }));
134
- function setup(_x) {
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 };