@modern-js/plugin-tailwindcss 2.0.0-beta.6 → 2.0.0-beta.7

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # @modern-js/plugin-tailwindcss
2
2
 
3
+ ## 2.0.0-beta.7
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [c9e800d39a]
12
+ - Updated dependencies [edd1cfb1af]
13
+ - Updated dependencies [6bda14ed71]
14
+ - Updated dependencies [dda38c9c3e]
15
+ - Updated dependencies [8b8e1bb571]
16
+ - Updated dependencies [bbe4c4ab64]
17
+ - @modern-js/runtime@2.0.0-beta.7
18
+ - @modern-js/utils@2.0.0-beta.7
19
+
3
20
  ## 2.0.0-beta.6
4
21
 
5
22
  ### Major Changes
@@ -29,7 +29,12 @@ import {
29
29
  } from "@modern-js/utils";
30
30
  import DesignTokenPlugin from "./design-token/cli";
31
31
  import { getTailwindConfig } from "./tailwind";
32
- import { template, checkTwinMacroNotExist } from "./utils";
32
+ import {
33
+ template,
34
+ checkTwinMacroExist,
35
+ getTailwindPath,
36
+ getTailwindVersion
37
+ } from "./utils";
33
38
  const supportCssInJsLibrary = "styled-components";
34
39
  const getRandomTwConfigFileName = (internalDirectory) => {
35
40
  return slash(
@@ -51,10 +56,22 @@ var cli_default = ({ pluginName } = {
51
56
  setup: (api) => __async(void 0, null, function* () {
52
57
  const { appDirectory, internalDirectory } = api.useAppContext();
53
58
  let internalTwConfigPath = "";
54
- const notHaveTwinMacro = yield checkTwinMacroNotExist(appDirectory);
59
+ const haveTwinMacro = yield checkTwinMacroExist(appDirectory);
60
+ const tailwindPath = getTailwindPath(appDirectory);
61
+ const tailwindVersion = getTailwindVersion(appDirectory);
62
+ const defaultContent = [
63
+ "./config/html/**/*.html",
64
+ "./config/html/**/*.ejs",
65
+ "./config/html/**/*.hbs",
66
+ "./src/**/*.js",
67
+ "./src/**/*.jsx",
68
+ "./src/**/*.ts",
69
+ "./src/**/*.tsx",
70
+ "./storybook/**/*"
71
+ ];
55
72
  return {
56
73
  prepare() {
57
- if (notHaveTwinMacro) {
74
+ if (!haveTwinMacro) {
58
75
  return;
59
76
  }
60
77
  internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
@@ -82,89 +99,58 @@ var cli_default = ({ pluginName } = {
82
99
  var _a, _b;
83
100
  const modernConfig = api.useResolvedConfigContext();
84
101
  const tailwindConfig = getTailwindConfig(
102
+ tailwindVersion,
85
103
  (_a = modernConfig == null ? void 0 : modernConfig.tools) == null ? void 0 : _a.tailwindcss,
86
104
  (_b = modernConfig == null ? void 0 : modernConfig.source) == null ? void 0 : _b.designSystem,
87
105
  {
88
106
  pureConfig: {
89
- content: [
90
- "./config/html/**/*.html",
91
- "./config/html/**/*.ejs",
92
- "./config/html/**/*.hbs",
93
- "./src/**/*.js",
94
- "./src/**/*.jsx",
95
- "./src/**/*.ts",
96
- "./src/**/*.tsx",
97
- "./storybook/**/*",
98
- "./styles/**/*.less",
99
- "./styles/**/*.css",
100
- "./styles/**/*.sass",
101
- "./styles/**/*.scss"
102
- ]
107
+ content: defaultContent
103
108
  }
104
109
  }
105
110
  );
111
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
106
112
  if (Array.isArray(config.postcssOptions.plugins)) {
107
- config.postcssOptions.plugins.push(
108
- require("tailwindcss")(tailwindConfig)
109
- );
113
+ config.postcssOptions.plugins.push(tailwindPlugin);
110
114
  } else {
111
- config.postcssOptions.plugins = [
112
- require("tailwindcss")(tailwindConfig)
113
- ];
115
+ config.postcssOptions.plugins = [tailwindPlugin];
114
116
  }
115
117
  },
116
118
  babel(_, { addPlugins }) {
117
- if (notHaveTwinMacro) {
118
- return;
119
- }
120
- addPlugins([
121
- [
122
- require.resolve("babel-plugin-macros"),
123
- {
124
- twin: {
125
- preset: supportCssInJsLibrary,
126
- config: internalTwConfigPath
119
+ if (haveTwinMacro) {
120
+ addPlugins([
121
+ [
122
+ require.resolve("babel-plugin-macros"),
123
+ {
124
+ twin: {
125
+ preset: supportCssInJsLibrary,
126
+ config: internalTwConfigPath
127
+ }
127
128
  }
128
- }
129
- ]
130
- ]);
129
+ ]
130
+ ]);
131
+ }
131
132
  }
132
133
  }
133
134
  };
134
135
  },
135
- beforeBuildTask({ config }) {
136
+ beforeBuildTask(config) {
136
137
  const modernConfig = api.useResolvedConfigContext();
137
138
  const { designSystem } = modernConfig;
138
139
  const tailwindConfig = getTailwindConfig(
140
+ tailwindVersion,
139
141
  config.style.tailwindCss,
140
142
  designSystem,
141
143
  {
142
144
  pureConfig: {
143
- content: [
144
- "./config/html/**/*.html",
145
- "./config/html/**/*.ejs",
146
- "./config/html/**/*.hbs",
147
- "./src/**/*.js",
148
- "./src/**/*.jsx",
149
- "./src/**/*.ts",
150
- "./src/**/*.tsx",
151
- "./storybook/**/*",
152
- "./styles/**/*.less",
153
- "./styles/**/*.css",
154
- "./styles/**/*.sass",
155
- "./styles/**/*.scss"
156
- ]
145
+ content: defaultContent
157
146
  }
158
147
  }
159
148
  );
149
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
160
150
  if (Array.isArray(config.style.postcss.plugins)) {
161
- config.style.postcss.plugins.push(
162
- require("tailwindcss")(tailwindConfig)
163
- );
151
+ config.style.postcss.plugins.push(tailwindPlugin);
164
152
  } else {
165
- config.style.postcss.plugins = [
166
- require("tailwindcss")(tailwindConfig)
167
- ];
153
+ config.style.postcss.plugins = [tailwindPlugin];
168
154
  }
169
155
  return config;
170
156
  }
@@ -13,7 +13,7 @@ const getPureDesignSystemConfig = (designSystemConfig) => {
13
13
  delete pureDesignSystemConfig.supportStyledComponents;
14
14
  return pureDesignSystemConfig;
15
15
  };
16
- const getTailwindConfig = (tailwindcss, designSystem, option = {}) => {
16
+ const getTailwindConfig = (tailwindVersion, tailwindcss, designSystem, option = {}) => {
17
17
  const purgeConfig = merge(
18
18
  {
19
19
  enabled: process.env.NODE_ENV === "production",
@@ -22,7 +22,7 @@ const getTailwindConfig = (tailwindcss, designSystem, option = {}) => {
22
22
  },
23
23
  option.pureConfig || {}
24
24
  );
25
- const defaultTailwindConfig = {
25
+ const defaultTailwindConfig = tailwindVersion === "3" ? { content: purgeConfig.content } : {
26
26
  purge: purgeConfig
27
27
  };
28
28
  const tailwindConfig = applyOptionsChain(
@@ -40,17 +40,35 @@ module.exports = {
40
40
  ...tailwindcss,
41
41
  };
42
42
  `;
43
- const checkTwinMacroNotExist = (appDirectory) => __async(void 0, null, function* () {
43
+ const checkTwinMacroExist = (appDirectory) => __async(void 0, null, function* () {
44
44
  const depName = "twin.macro";
45
45
  const packageJson = (yield fs.readJSON(path.join(appDirectory, "package.json"), {
46
46
  throws: false
47
47
  })) || {};
48
- if (typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName]) {
49
- return false;
50
- }
51
- return true;
48
+ return Boolean(
49
+ typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName]
50
+ );
52
51
  });
52
+ function getTailwindPath(appDirectory) {
53
+ try {
54
+ return require.resolve("tailwindcss", { paths: [appDirectory, __dirname] });
55
+ } catch (err) {
56
+ return "tailwindcss";
57
+ }
58
+ }
59
+ function getTailwindVersion(appDirectory) {
60
+ try {
61
+ const packageJsonPath = require.resolve("tailwindcss/package.json", {
62
+ paths: [appDirectory, __dirname]
63
+ });
64
+ return require(packageJsonPath).version.split(".")[0];
65
+ } catch (err) {
66
+ return "3";
67
+ }
68
+ }
53
69
  export {
54
- checkTwinMacroNotExist,
70
+ checkTwinMacroExist,
71
+ getTailwindPath,
72
+ getTailwindVersion,
55
73
  template
56
74
  };
@@ -73,10 +73,22 @@ var cli_default = ({ pluginName } = {
73
73
  setup: (api) => __async(void 0, null, function* () {
74
74
  const { appDirectory, internalDirectory } = api.useAppContext();
75
75
  let internalTwConfigPath = "";
76
- const notHaveTwinMacro = yield (0, import_utils2.checkTwinMacroNotExist)(appDirectory);
76
+ const haveTwinMacro = yield (0, import_utils2.checkTwinMacroExist)(appDirectory);
77
+ const tailwindPath = (0, import_utils2.getTailwindPath)(appDirectory);
78
+ const tailwindVersion = (0, import_utils2.getTailwindVersion)(appDirectory);
79
+ const defaultContent = [
80
+ "./config/html/**/*.html",
81
+ "./config/html/**/*.ejs",
82
+ "./config/html/**/*.hbs",
83
+ "./src/**/*.js",
84
+ "./src/**/*.jsx",
85
+ "./src/**/*.ts",
86
+ "./src/**/*.tsx",
87
+ "./storybook/**/*"
88
+ ];
77
89
  return {
78
90
  prepare() {
79
- if (notHaveTwinMacro) {
91
+ if (!haveTwinMacro) {
80
92
  return;
81
93
  }
82
94
  internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
@@ -104,89 +116,58 @@ var cli_default = ({ pluginName } = {
104
116
  var _a, _b;
105
117
  const modernConfig = api.useResolvedConfigContext();
106
118
  const tailwindConfig = (0, import_tailwind.getTailwindConfig)(
119
+ tailwindVersion,
107
120
  (_a = modernConfig == null ? void 0 : modernConfig.tools) == null ? void 0 : _a.tailwindcss,
108
121
  (_b = modernConfig == null ? void 0 : modernConfig.source) == null ? void 0 : _b.designSystem,
109
122
  {
110
123
  pureConfig: {
111
- content: [
112
- "./config/html/**/*.html",
113
- "./config/html/**/*.ejs",
114
- "./config/html/**/*.hbs",
115
- "./src/**/*.js",
116
- "./src/**/*.jsx",
117
- "./src/**/*.ts",
118
- "./src/**/*.tsx",
119
- "./storybook/**/*",
120
- "./styles/**/*.less",
121
- "./styles/**/*.css",
122
- "./styles/**/*.sass",
123
- "./styles/**/*.scss"
124
- ]
124
+ content: defaultContent
125
125
  }
126
126
  }
127
127
  );
128
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
128
129
  if (Array.isArray(config.postcssOptions.plugins)) {
129
- config.postcssOptions.plugins.push(
130
- require("tailwindcss")(tailwindConfig)
131
- );
130
+ config.postcssOptions.plugins.push(tailwindPlugin);
132
131
  } else {
133
- config.postcssOptions.plugins = [
134
- require("tailwindcss")(tailwindConfig)
135
- ];
132
+ config.postcssOptions.plugins = [tailwindPlugin];
136
133
  }
137
134
  },
138
135
  babel(_, { addPlugins }) {
139
- if (notHaveTwinMacro) {
140
- return;
141
- }
142
- addPlugins([
143
- [
144
- require.resolve("babel-plugin-macros"),
145
- {
146
- twin: {
147
- preset: supportCssInJsLibrary,
148
- config: internalTwConfigPath
136
+ if (haveTwinMacro) {
137
+ addPlugins([
138
+ [
139
+ require.resolve("babel-plugin-macros"),
140
+ {
141
+ twin: {
142
+ preset: supportCssInJsLibrary,
143
+ config: internalTwConfigPath
144
+ }
149
145
  }
150
- }
151
- ]
152
- ]);
146
+ ]
147
+ ]);
148
+ }
153
149
  }
154
150
  }
155
151
  };
156
152
  },
157
- beforeBuildTask({ config }) {
153
+ beforeBuildTask(config) {
158
154
  const modernConfig = api.useResolvedConfigContext();
159
155
  const { designSystem } = modernConfig;
160
156
  const tailwindConfig = (0, import_tailwind.getTailwindConfig)(
157
+ tailwindVersion,
161
158
  config.style.tailwindCss,
162
159
  designSystem,
163
160
  {
164
161
  pureConfig: {
165
- content: [
166
- "./config/html/**/*.html",
167
- "./config/html/**/*.ejs",
168
- "./config/html/**/*.hbs",
169
- "./src/**/*.js",
170
- "./src/**/*.jsx",
171
- "./src/**/*.ts",
172
- "./src/**/*.tsx",
173
- "./storybook/**/*",
174
- "./styles/**/*.less",
175
- "./styles/**/*.css",
176
- "./styles/**/*.sass",
177
- "./styles/**/*.scss"
178
- ]
162
+ content: defaultContent
179
163
  }
180
164
  }
181
165
  );
166
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
182
167
  if (Array.isArray(config.style.postcss.plugins)) {
183
- config.style.postcss.plugins.push(
184
- require("tailwindcss")(tailwindConfig)
185
- );
168
+ config.style.postcss.plugins.push(tailwindPlugin);
186
169
  } else {
187
- config.style.postcss.plugins = [
188
- require("tailwindcss")(tailwindConfig)
189
- ];
170
+ config.style.postcss.plugins = [tailwindPlugin];
190
171
  }
191
172
  return config;
192
173
  }
@@ -35,7 +35,7 @@ const getPureDesignSystemConfig = (designSystemConfig) => {
35
35
  delete pureDesignSystemConfig.supportStyledComponents;
36
36
  return pureDesignSystemConfig;
37
37
  };
38
- const getTailwindConfig = (tailwindcss, designSystem, option = {}) => {
38
+ const getTailwindConfig = (tailwindVersion, tailwindcss, designSystem, option = {}) => {
39
39
  const purgeConfig = (0, import_lodash.merge)(
40
40
  {
41
41
  enabled: process.env.NODE_ENV === "production",
@@ -44,7 +44,7 @@ const getTailwindConfig = (tailwindcss, designSystem, option = {}) => {
44
44
  },
45
45
  option.pureConfig || {}
46
46
  );
47
- const defaultTailwindConfig = {
47
+ const defaultTailwindConfig = tailwindVersion === "3" ? { content: purgeConfig.content } : {
48
48
  purge: purgeConfig
49
49
  };
50
50
  const tailwindConfig = (0, import_utils.applyOptionsChain)(
@@ -43,7 +43,9 @@ var __async = (__this, __arguments, generator) => {
43
43
  };
44
44
  var utils_exports = {};
45
45
  __export(utils_exports, {
46
- checkTwinMacroNotExist: () => checkTwinMacroNotExist,
46
+ checkTwinMacroExist: () => checkTwinMacroExist,
47
+ getTailwindPath: () => getTailwindPath,
48
+ getTailwindVersion: () => getTailwindVersion,
47
49
  template: () => template
48
50
  });
49
51
  module.exports = __toCommonJS(utils_exports);
@@ -69,18 +71,36 @@ module.exports = {
69
71
  ...tailwindcss,
70
72
  };
71
73
  `;
72
- const checkTwinMacroNotExist = (appDirectory) => __async(void 0, null, function* () {
74
+ const checkTwinMacroExist = (appDirectory) => __async(void 0, null, function* () {
73
75
  const depName = "twin.macro";
74
76
  const packageJson = (yield import_utils.fs.readJSON(import_path.default.join(appDirectory, "package.json"), {
75
77
  throws: false
76
78
  })) || {};
77
- if (typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName]) {
78
- return false;
79
- }
80
- return true;
79
+ return Boolean(
80
+ typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName]
81
+ );
81
82
  });
83
+ function getTailwindPath(appDirectory) {
84
+ try {
85
+ return require.resolve("tailwindcss", { paths: [appDirectory, __dirname] });
86
+ } catch (err) {
87
+ return "tailwindcss";
88
+ }
89
+ }
90
+ function getTailwindVersion(appDirectory) {
91
+ try {
92
+ const packageJsonPath = require.resolve("tailwindcss/package.json", {
93
+ paths: [appDirectory, __dirname]
94
+ });
95
+ return require(packageJsonPath).version.split(".")[0];
96
+ } catch (err) {
97
+ return "3";
98
+ }
99
+ }
82
100
  // Annotate the CommonJS export names for ESM import in node:
83
101
  0 && (module.exports = {
84
- checkTwinMacroNotExist,
102
+ checkTwinMacroExist,
103
+ getTailwindPath,
104
+ getTailwindVersion,
85
105
  template
86
106
  });
@@ -126,7 +126,7 @@ import path from "path";
126
126
  import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from "@modern-js/utils";
127
127
  import DesignTokenPlugin from "./design-token/cli";
128
128
  import { getTailwindConfig } from "./tailwind";
129
- import { template, checkTwinMacroNotExist } from "./utils";
129
+ import { template, checkTwinMacroExist, getTailwindPath, getTailwindVersion } from "./utils";
130
130
  var supportCssInJsLibrary = "styled-components";
131
131
  var getRandomTwConfigFileName = function(internalDirectory) {
132
132
  return slash(path.join(internalDirectory, "tailwind.config.".concat(Date.now(), ".").concat(nanoid(), ".js")));
@@ -144,7 +144,7 @@ var cli_default = function() {
144
144
  ],
145
145
  setup: function() {
146
146
  var _ref = _asyncToGenerator(function(api) {
147
- var ref, appDirectory, internalDirectory, internalTwConfigPath, notHaveTwinMacro;
147
+ var ref, appDirectory, internalDirectory, internalTwConfigPath, haveTwinMacro, tailwindPath, tailwindVersion, defaultContent;
148
148
  return __generator(this, function(_state) {
149
149
  switch(_state.label){
150
150
  case 0:
@@ -152,15 +152,27 @@ var cli_default = function() {
152
152
  internalTwConfigPath = "";
153
153
  return [
154
154
  4,
155
- checkTwinMacroNotExist(appDirectory)
155
+ checkTwinMacroExist(appDirectory)
156
156
  ];
157
157
  case 1:
158
- notHaveTwinMacro = _state.sent();
158
+ haveTwinMacro = _state.sent();
159
+ tailwindPath = getTailwindPath(appDirectory);
160
+ tailwindVersion = getTailwindVersion(appDirectory);
161
+ defaultContent = [
162
+ "./config/html/**/*.html",
163
+ "./config/html/**/*.ejs",
164
+ "./config/html/**/*.hbs",
165
+ "./src/**/*.js",
166
+ "./src/**/*.jsx",
167
+ "./src/**/*.ts",
168
+ "./src/**/*.tsx",
169
+ "./storybook/**/*"
170
+ ];
159
171
  return [
160
172
  2,
161
173
  {
162
174
  prepare: function prepare() {
163
- if (notHaveTwinMacro) {
175
+ if (!haveTwinMacro) {
164
176
  return;
165
177
  }
166
178
  internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
@@ -181,79 +193,53 @@ var cli_default = function() {
181
193
  postcss: function(config) {
182
194
  var ref, ref1;
183
195
  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, {
196
+ var tailwindConfig = getTailwindConfig(tailwindVersion, 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
197
  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
- ]
198
+ content: defaultContent
200
199
  }
201
200
  });
201
+ var tailwindPlugin = require(tailwindPath)(tailwindConfig);
202
202
  if (Array.isArray(config.postcssOptions.plugins)) {
203
- config.postcssOptions.plugins.push(require("tailwindcss")(tailwindConfig));
203
+ config.postcssOptions.plugins.push(tailwindPlugin);
204
204
  } else {
205
205
  config.postcssOptions.plugins = [
206
- require("tailwindcss")(tailwindConfig)
206
+ tailwindPlugin
207
207
  ];
208
208
  }
209
209
  },
210
210
  babel: function babel(_, param) {
211
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
212
+ if (haveTwinMacro) {
213
+ addPlugins([
214
+ [
215
+ require.resolve("babel-plugin-macros"),
216
+ {
217
+ twin: {
218
+ preset: supportCssInJsLibrary,
219
+ config: internalTwConfigPath
220
+ }
222
221
  }
223
- }
224
- ]
225
- ]);
222
+ ]
223
+ ]);
224
+ }
226
225
  }
227
226
  }
228
227
  };
229
228
  },
230
- beforeBuildTask: function beforeBuildTask(param) {
231
- var config = param.config;
229
+ beforeBuildTask: function beforeBuildTask(config) {
232
230
  var modernConfig = api.useResolvedConfigContext();
233
231
  var designSystem = modernConfig.designSystem;
234
- var tailwindConfig = getTailwindConfig(config.style.tailwindCss, designSystem, {
232
+ var tailwindConfig = getTailwindConfig(tailwindVersion, config.style.tailwindCss, designSystem, {
235
233
  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
- ]
234
+ content: defaultContent
250
235
  }
251
236
  });
237
+ var tailwindPlugin = require(tailwindPath)(tailwindConfig);
252
238
  if (Array.isArray(config.style.postcss.plugins)) {
253
- config.style.postcss.plugins.push(require("tailwindcss")(tailwindConfig));
239
+ config.style.postcss.plugins.push(tailwindPlugin);
254
240
  } else {
255
241
  config.style.postcss.plugins = [
256
- require("tailwindcss")(tailwindConfig)
242
+ tailwindPlugin
257
243
  ];
258
244
  }
259
245
  return config;
@@ -64,8 +64,8 @@ var getPureDesignSystemConfig = function(designSystemConfig) {
64
64
  delete pureDesignSystemConfig.supportStyledComponents;
65
65
  return pureDesignSystemConfig;
66
66
  };
67
- var getTailwindConfig = function(tailwindcss, designSystem) {
68
- var option = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
67
+ var getTailwindConfig = function(tailwindVersion, tailwindcss, designSystem) {
68
+ var option = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
69
69
  var purgeConfig = merge({
70
70
  enabled: process.env.NODE_ENV === "production",
71
71
  layers: [
@@ -73,7 +73,9 @@ var getTailwindConfig = function(tailwindcss, designSystem) {
73
73
  ],
74
74
  content: []
75
75
  }, option.pureConfig || {});
76
- var defaultTailwindConfig = {
76
+ var defaultTailwindConfig = tailwindVersion === "3" ? {
77
+ content: purgeConfig.content
78
+ } : {
77
79
  purge: purgeConfig
78
80
  };
79
81
  var tailwindConfig = applyOptionsChain(defaultTailwindConfig, tailwindcss || {});
@@ -127,7 +127,7 @@ import { fs } from "@modern-js/utils";
127
127
  var template = function(configPath) {
128
128
  return "\nfunction _interopRequireDefault(obj) {\n return obj && obj.__esModule ? obj : { default: obj };\n}\nconst modernConfig = _interopRequireDefault(require('".concat(configPath, "')).default;\n\nconst theme =\n modernConfig && modernConfig.source && modernConfig.source.designSystem\n ? modernConfig.source.designSystem\n : {};\nconst tailwindcss =\n modernConfig && modernConfig.tools && modernConfig.tools.tailwindcss\n ? modernConfig.tools.tailwindcss\n : {};\n\nmodule.exports = {\n theme,\n ...tailwindcss,\n};\n");
129
129
  };
130
- var checkTwinMacroNotExist = function() {
130
+ var checkTwinMacroExist = function() {
131
131
  var _ref = _asyncToGenerator(function(appDirectory) {
132
132
  var depName, packageJson;
133
133
  return __generator(this, function(_state) {
@@ -142,21 +142,40 @@ var checkTwinMacroNotExist = function() {
142
142
  ];
143
143
  case 1:
144
144
  packageJson = _state.sent() || {};
145
- if (typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName]) {
146
- return [
147
- 2,
148
- false
149
- ];
150
- }
151
145
  return [
152
146
  2,
153
- true
147
+ Boolean(typeof packageJson.dependencies === "object" && packageJson.dependencies[depName] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[depName])
154
148
  ];
155
149
  }
156
150
  });
157
151
  });
158
- return function checkTwinMacroNotExist(appDirectory) {
152
+ return function checkTwinMacroExist(appDirectory) {
159
153
  return _ref.apply(this, arguments);
160
154
  };
161
155
  }();
162
- export { checkTwinMacroNotExist, template };
156
+ function getTailwindPath(appDirectory) {
157
+ try {
158
+ return require.resolve("tailwindcss", {
159
+ paths: [
160
+ appDirectory,
161
+ __dirname
162
+ ]
163
+ });
164
+ } catch (err) {
165
+ return "tailwindcss";
166
+ }
167
+ }
168
+ function getTailwindVersion(appDirectory) {
169
+ try {
170
+ var packageJsonPath = require.resolve("tailwindcss/package.json", {
171
+ paths: [
172
+ appDirectory,
173
+ __dirname
174
+ ]
175
+ });
176
+ return require(packageJsonPath).version.split(".")[0];
177
+ } catch (err) {
178
+ return "3";
179
+ }
180
+ }
181
+ export { checkTwinMacroExist, getTailwindPath, getTailwindVersion, template };
@@ -1,5 +1,5 @@
1
1
  import { DesignSystem, Tailwind } from './types';
2
- declare const getTailwindConfig: (tailwindcss?: Tailwind, designSystem?: DesignSystem, option?: {
2
+ declare const getTailwindConfig: (tailwindVersion: '2' | '3', tailwindcss?: Tailwind, designSystem?: DesignSystem, option?: {
3
3
  pureConfig?: Record<string, any>;
4
4
  }) => Record<string, any>;
5
5
  export { getTailwindConfig };
@@ -1,2 +1,4 @@
1
1
  export declare const template: (configPath: string) => string;
2
- export declare const checkTwinMacroNotExist: (appDirectory: string) => Promise<boolean>;
2
+ export declare const checkTwinMacroExist: (appDirectory: string) => Promise<boolean>;
3
+ export declare function getTailwindPath(appDirectory: string): string;
4
+ export declare function getTailwindVersion(appDirectory: string): '2' | '3';
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.0.0-beta.6",
14
+ "version": "2.0.0-beta.7",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -46,28 +46,27 @@
46
46
  "@babel/runtime": "^7.18.0",
47
47
  "babel-plugin-macros": "3.1.0",
48
48
  "hoist-non-react-statics": "^3.3.2",
49
- "@modern-js/utils": "2.0.0-beta.6"
49
+ "@modern-js/utils": "2.0.0-beta.7"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/jest": "^27",
53
53
  "@types/node": "^14",
54
- "@types/tailwindcss": "^2.2.1",
55
54
  "typescript": "^4",
56
- "tailwindcss": "^2.0.4",
55
+ "tailwindcss": "^3.2.4",
57
56
  "jest": "^27",
58
57
  "react": "^18",
59
58
  "postcss": "^8.4.14",
60
- "@modern-js/core": "2.0.0-beta.6",
61
- "@modern-js/module-tools": "2.0.0-beta.6",
62
- "@modern-js/runtime": "2.0.0-beta.6",
63
- "@modern-js/types": "2.0.0-beta.6",
64
- "@scripts/build": "2.0.0-beta.6",
65
- "@modern-js/app-tools": "2.0.0-beta.6",
66
- "@scripts/jest-config": "2.0.0-beta.6"
59
+ "@modern-js/core": "2.0.0-beta.7",
60
+ "@modern-js/module-tools": "2.0.0-beta.7",
61
+ "@modern-js/runtime": "2.0.0-beta.7",
62
+ "@modern-js/types": "2.0.0-beta.7",
63
+ "@scripts/build": "2.0.0-beta.7",
64
+ "@modern-js/app-tools": "2.0.0-beta.7",
65
+ "@scripts/jest-config": "2.0.0-beta.7"
67
66
  },
68
67
  "peerDependencies": {
69
- "tailwindcss": "^2.0.4",
70
- "@modern-js/runtime": "^2.0.0-beta.6"
68
+ "tailwindcss": ">= 2.0.0 || >= 3.0.0",
69
+ "@modern-js/runtime": "^2.0.0-beta.7"
71
70
  },
72
71
  "peerDependenciesMeta": {
73
72
  "@modern-js/runtime": {