@modern-js/plugin-tailwindcss 2.0.0-beta.0 → 2.0.0-beta.1

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 (31) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/dist/js/modern/cli.js +33 -37
  3. package/dist/js/modern/design-token/cli/index.js +13 -38
  4. package/dist/js/modern/design-token/postcss-plugin/index.js +0 -3
  5. package/dist/js/modern/design-token/runtime/plugin.js +0 -8
  6. package/dist/js/modern/tailwind.js +6 -10
  7. package/dist/js/modern/types.js +0 -0
  8. package/dist/js/modern/utils.js +0 -2
  9. package/dist/js/node/cli.js +33 -49
  10. package/dist/js/node/design-token/cli/index.js +13 -41
  11. package/dist/js/node/design-token/index.js +0 -4
  12. package/dist/js/node/design-token/postcss-plugin/index.js +0 -5
  13. package/dist/js/node/design-token/runtime/index.js +0 -5
  14. package/dist/js/node/design-token/runtime/plugin.js +0 -20
  15. package/dist/js/node/index.js +0 -2
  16. package/dist/js/node/tailwind.js +6 -13
  17. package/dist/js/node/types.js +0 -0
  18. package/dist/js/node/utils.js +0 -9
  19. package/dist/js/treeshaking/cli.js +34 -36
  20. package/dist/js/treeshaking/design-token/cli/index.js +22 -30
  21. package/dist/js/treeshaking/design-token/postcss-plugin/index.js +2 -6
  22. package/dist/js/treeshaking/design-token/runtime/plugin.js +7 -12
  23. package/dist/js/treeshaking/tailwind.js +9 -14
  24. package/dist/js/treeshaking/types.js +0 -0
  25. package/dist/js/treeshaking/utils.js +0 -9
  26. package/dist/types/cli.d.ts +0 -2
  27. package/dist/types/design-token/cli/index.d.ts +0 -2
  28. package/dist/types/design-token/postcss-plugin/index.d.ts +0 -2
  29. package/dist/types/design-token/runtime/plugin.d.ts +0 -2
  30. package/dist/types/types.d.ts +10 -0
  31. package/package.json +9 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,75 @@
1
1
  # @modern-js/plugin-tailwindcss
2
2
 
3
+ ## 2.0.0-beta.1
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9: chore: v2
8
+
9
+ ### Minor Changes
10
+
11
+ - 92f0ead: feat:
12
+
13
+ 1. add style config and add new hook
14
+ 2. add dts alias logic
15
+ 3. add copy logic
16
+ 4. add log logic
17
+ 5. add skipDeps config
18
+
19
+ feat:
20
+
21
+ 1. 添加样式配置以及新的 hook
22
+ 2. 添加 dts 别名处理
23
+ 3. 添加 copy 逻辑
24
+ 4. 添加日志逻辑
25
+ 5. 添加 skipDeps 配置
26
+
27
+ - 92f0ead: feat:
28
+
29
+ 1. core: 增加 test 函数
30
+ 2. module plugins: 增加 `babel`, `mainField`, `target` 插件
31
+ 3. storybook: 修改部分逻辑并且增加 tspath webpack 插件
32
+ 4. 增加 designSystem 配置
33
+
34
+ feat:
35
+
36
+ 1. core: add test method
37
+ 2. module plugins: add `babel`, `mainField`, `target` plugin
38
+ 3. storybook: change some logic and add tspath webpack plugin
39
+ 4. add `designSystem` config
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [2344eb2]
44
+ - Updated dependencies [a11fcf8]
45
+ - Updated dependencies [b18fa8f]
46
+ - Updated dependencies [c9e800d39a]
47
+ - Updated dependencies [3e57f2b]
48
+ - Updated dependencies [fbf5eed]
49
+ - Updated dependencies [a2509bfbdb]
50
+ - Updated dependencies [4369648ae2]
51
+ - Updated dependencies [92f0ead]
52
+ - Updated dependencies [92c0994]
53
+ - Updated dependencies [edd1cfb1af]
54
+ - Updated dependencies [cc971eabfc]
55
+ - Updated dependencies [5b9049f]
56
+ - Updated dependencies [6bda14ed71]
57
+ - Updated dependencies [92004d1]
58
+ - Updated dependencies [b8bbe036c7]
59
+ - Updated dependencies [40ed587]
60
+ - Updated dependencies [60d5378632]
61
+ - Updated dependencies [d5a31df781]
62
+ - Updated dependencies [dda38c9]
63
+ - Updated dependencies [8b8e1bb571]
64
+ - Updated dependencies [3bbea92b2a]
65
+ - Updated dependencies [18aaf42]
66
+ - Updated dependencies [fcace5b5b9]
67
+ - Updated dependencies [abf3421]
68
+ - Updated dependencies [543be9558e]
69
+ - Updated dependencies [14b712d]
70
+ - @modern-js/runtime@2.0.0-beta.1
71
+ - @modern-js/utils@2.0.0-beta.1
72
+
3
73
  ## 2.0.0-beta.0
4
74
 
5
75
  ### Major Changes
@@ -1,9 +1,6 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
4
  import path from 'path';
8
5
  import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from '@modern-js/utils';
9
6
  import DesignTokenPlugin from "./design-token/cli";
@@ -28,30 +25,26 @@ export default (({
28
25
  appDirectory,
29
26
  internalDirectory
30
27
  } = api.useAppContext();
31
- let internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
32
-
28
+ let internalTwConfigPath = '';
29
+ // When reinstalling dependencies, most of the time the project will be restarted
33
30
  const notHaveTwinMacro = await checkTwinMacroNotExist(appDirectory);
34
31
  return {
35
32
  prepare() {
36
33
  if (notHaveTwinMacro) {
37
34
  return;
38
35
  }
39
-
40
36
  internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
41
37
  const globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, '*.cjs'));
42
38
  const files = globby.sync(globPattern, {
43
39
  absolute: true
44
40
  });
45
-
46
41
  if (files.length > 0) {
47
42
  fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), 'utf-8');
48
43
  }
49
44
  },
50
-
51
45
  validateSchema() {
52
46
  return PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
53
47
  },
54
-
55
48
  config() {
56
49
  return {
57
50
  tools: {
@@ -59,27 +52,44 @@ export default (({
59
52
  // TODO: In module project, also is called, but should not be called.
60
53
  postcss: config => {
61
54
  const modernConfig = api.useResolvedConfigContext();
62
- const tailwindConfig = getTailwindConfig(modernConfig, {
63
- pureConfig: {
64
- content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
65
- './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
55
+ if (!config.postcssOptions
56
+ // config.$$tools === 'module-tools'
57
+ ) {
58
+ if (Array.isArray(config.plugins)) {
59
+ const tailwindConfig = getTailwindConfig(modernConfig, {
60
+ pureConfig: {
61
+ 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']
62
+ }
63
+ });
64
+ config.plugins.push(require('tailwindcss')(tailwindConfig));
65
+ } else {
66
+ const tailwindConfig = getTailwindConfig(modernConfig, {
67
+ pureConfig: {
68
+ 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']
69
+ }
70
+ });
71
+ config.plugins = [require('tailwindcss')(tailwindConfig)];
66
72
  }
67
- });
68
-
69
- if (Array.isArray(config.postcssOptions.plugins)) {
70
- config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
71
73
  } else {
72
- config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
74
+ const tailwindConfig = getTailwindConfig(modernConfig, {
75
+ pureConfig: {
76
+ content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx',
77
+ // about storybook
78
+ './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
79
+ }
80
+ });
81
+ if (Array.isArray(config.postcssOptions.plugins)) {
82
+ config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
83
+ } else {
84
+ config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
85
+ }
73
86
  }
74
87
  },
75
-
76
88
  babel(config) {
77
89
  var _config$plugins;
78
-
79
90
  if (notHaveTwinMacro) {
80
91
  return;
81
92
  }
82
-
83
93
  const twinConfig = {
84
94
  twin: {
85
95
  preset: supportCssInJsLibrary,
@@ -90,37 +100,23 @@ export default (({
90
100
  if (Array.isArray(plugin) && plugin[0]) {
91
101
  const pluginTarget = plugin[0];
92
102
  let pluginOptions = plugin[1];
93
-
94
- if (typeof pluginTarget === 'string' && // TODO: use babel chain
103
+ if (typeof pluginTarget === 'string' &&
104
+ // TODO: use babel chain
95
105
  slash(pluginTarget).includes('compiled/babel-plugin-macros')) {
96
106
  if (pluginOptions) {
97
107
  pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
98
108
  } else {
99
109
  plugin.push(twinConfig);
100
110
  }
101
-
102
111
  return true;
103
112
  }
104
113
  }
105
-
106
114
  return false;
107
115
  });
108
116
  }
109
-
110
117
  }
111
118
  };
112
- },
113
-
114
- moduleTailwindConfig() {
115
- const modernConfig = api.useResolvedConfigContext();
116
- const tailwindConfig = getTailwindConfig(modernConfig, {
117
- pureConfig: {
118
- 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']
119
- }
120
- });
121
- return require('tailwindcss')(tailwindConfig);
122
119
  }
123
-
124
120
  };
125
121
  }
126
122
  }));
@@ -1,9 +1,6 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
4
  import { lazyImport, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
8
5
  export default (({
9
6
  pluginName
@@ -11,34 +8,27 @@ export default (({
11
8
  pluginName: '@modern-js/plugin-tailwindcss'
12
9
  }) => ({
13
10
  name: '@modern-js/plugin-design-token',
14
-
15
11
  setup(api) {
16
12
  let pluginsExportsUtils;
17
13
  const resolveConfig = lazyImport('tailwindcss/resolveConfig', require);
18
14
  const PLUGIN_IDENTIFIER = 'designToken';
19
-
20
15
  const getDesignTokens = userConfig => {
21
- const {
22
- source: {
23
- designSystem
24
- }
25
- } = userConfig; // TODO: Type to be filled
26
-
16
+ var _userConfig$source;
17
+ const designSystem = (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.designSystem;
27
18
  const tailwindcssConfig = {};
28
- tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
19
+ tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
29
20
 
21
+ // not use default design token when designToken.defaultTheme is false or theme is false
30
22
  if (!designSystem) {
31
23
  tailwindcssConfig.presets = [];
32
- } // when only designSystem exist, need remove supportStyledComponents
33
-
24
+ }
34
25
 
26
+ // when only designSystem exist, need remove supportStyledComponents
35
27
  if (designSystem) {
36
28
  delete tailwindcssConfig.theme.supportStyledComponents;
37
29
  }
38
-
39
30
  return resolveConfig(tailwindcssConfig).theme || {};
40
31
  };
41
-
42
32
  return {
43
33
  config() {
44
34
  const appContext = api.useAppContext();
@@ -49,25 +39,21 @@ export default (({
49
39
  '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
50
40
  }
51
41
  },
52
- tools: {// TODO: support less、scss、css vars
42
+ tools: {
43
+ // TODO: support less、scss、css vars
53
44
  // less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
54
45
  // sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
55
46
  // postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
56
47
  }
57
48
  };
58
49
  },
59
-
60
50
  modifyEntryImports({
61
51
  entrypoint,
62
52
  imports
63
53
  }) {
54
+ var _userConfig$source$de, _userConfig$source2;
64
55
  const userConfig = api.useResolvedConfigContext();
65
- const {
66
- source: {
67
- designSystem
68
- }
69
- } = userConfig;
70
-
56
+ const designSystem = (_userConfig$source$de = (_userConfig$source2 = userConfig.source) === null || _userConfig$source2 === void 0 ? void 0 : _userConfig$source2.designSystem) !== null && _userConfig$source$de !== void 0 ? _userConfig$source$de : {};
71
57
  if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
72
58
  const designTokens = getDesignTokens(userConfig);
73
59
  imports.push({
@@ -80,52 +66,41 @@ export default (({
80
66
  `
81
67
  });
82
68
  }
83
-
84
69
  return {
85
70
  entrypoint,
86
71
  imports
87
72
  };
88
73
  },
89
-
90
74
  modifyEntryRuntimePlugins({
91
75
  entrypoint,
92
76
  plugins
93
77
  }) {
94
- const {
95
- source: {
96
- designSystem
97
- }
98
- } = api.useResolvedConfigContext();
78
+ var _userConfig$source$de2, _userConfig$source3;
79
+ const userConfig = api.useResolvedConfigContext();
80
+ const designSystem = (_userConfig$source$de2 = (_userConfig$source3 = userConfig.source) === null || _userConfig$source3 === void 0 ? void 0 : _userConfig$source3.designSystem) !== null && _userConfig$source$de2 !== void 0 ? _userConfig$source$de2 : {};
99
81
  let useSCThemeProvider = true;
100
-
101
82
  if (designSystem) {
102
83
  // when designSystem exist, designToken.styledComponents`s default value is false.
103
84
  useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
104
85
  }
105
-
106
86
  if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
107
87
  plugins.push({
108
88
  name: PLUGIN_IDENTIFIER,
109
89
  options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
110
90
  });
111
91
  }
112
-
113
92
  return {
114
93
  entrypoint,
115
94
  plugins
116
95
  };
117
96
  },
118
-
119
97
  validateSchema() {
120
98
  // add source.designSystem.supportStyledComponents config
121
99
  return PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
122
100
  },
123
-
124
101
  addRuntimeExports() {
125
102
  pluginsExportsUtils.addExport(`export { default as designToken } from '${pluginName}/runtime-design-token'`);
126
103
  }
127
-
128
104
  };
129
105
  }
130
-
131
106
  }));
@@ -2,17 +2,14 @@ export default (({
2
2
  cssVarsHash: _cssVarsHash = {}
3
3
  } = {}) => ({
4
4
  postcssPlugin: 'postcss-replace-css-vars',
5
-
6
5
  Declaration(decl) {
7
6
  if (decl.value && typeof decl.value === 'string') {
8
7
  decl.value = decl.value.replace(/--\S*/g, match => {
9
8
  if (_cssVarsHash[match]) {
10
9
  return _cssVarsHash[match];
11
10
  }
12
-
13
11
  return match;
14
12
  });
15
13
  }
16
14
  }
17
-
18
15
  }));
@@ -1,9 +1,6 @@
1
1
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
-
3
2
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
-
5
3
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
4
  import hoistNonReactStatics from 'hoist-non-react-statics';
8
5
  import React, { useContext } from 'react';
9
6
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -21,12 +18,10 @@ export default ((options = {}) => ({
21
18
  useStyledComponentsThemeProvider = false,
22
19
  useDesignTokenContext = false
23
20
  } = options;
24
-
25
21
  if (useStyledComponentsThemeProvider && useDesignTokenContext) {
26
22
  const {
27
23
  ThemeProvider
28
24
  } = require('@modern-js/runtime/styled');
29
-
30
25
  return /*#__PURE__*/_jsx(ThemeProvider, {
31
26
  theme: token,
32
27
  children: /*#__PURE__*/_jsx(DesignTokenContext.Provider, {
@@ -38,7 +33,6 @@ export default ((options = {}) => ({
38
33
  const {
39
34
  ThemeProvider
40
35
  } = require('@modern-js/runtime/styled');
41
-
42
36
  return /*#__PURE__*/_jsx(ThemeProvider, {
43
37
  theme: token,
44
38
  children: /*#__PURE__*/_jsx(App, _objectSpread({}, props))
@@ -52,11 +46,9 @@ export default ((options = {}) => ({
52
46
  return /*#__PURE__*/_jsx(App, _objectSpread({}, props));
53
47
  }
54
48
  };
55
-
56
49
  return next({
57
50
  App: hoistNonReactStatics(DesignTokenAppWrapper, App)
58
51
  });
59
52
  }
60
-
61
53
  })
62
54
  }));
@@ -1,20 +1,18 @@
1
1
  import { applyOptionsChain, logger } from '@modern-js/utils';
2
2
  import { merge, cloneDeep } from '@modern-js/utils/lodash';
3
-
4
3
  const checkIfExistNotAllowKeys = tailwindConfig => {
5
4
  const notAllowExistKeys = ['theme'];
6
5
  let notAllowKey = '';
7
6
  const ret = Object.keys(tailwindConfig).some(key => notAllowExistKeys.includes(key) && (notAllowKey = key));
8
7
  return [ret, notAllowKey];
9
8
  };
10
-
11
9
  const getPureDesignSystemConfig = designSystemConfig => {
12
10
  const pureDesignSystemConfig = cloneDeep(designSystemConfig);
13
11
  delete pureDesignSystemConfig.supportStyledComponents;
14
12
  return pureDesignSystemConfig;
15
13
  };
16
-
17
14
  const getTailwindConfig = (config, option = {}) => {
15
+ var _ref, _designSystem;
18
16
  const purgeConfig = merge({
19
17
  // TODO: how the operating environment is determined
20
18
  enabled: process.env.NODE_ENV === 'production',
@@ -26,18 +24,16 @@ const getTailwindConfig = (config, option = {}) => {
26
24
  purge: purgeConfig
27
25
  };
28
26
  const tailwindConfig = applyOptionsChain(defaultTailwindConfig, config.tools.tailwindcss || {});
29
- const designSystem = getPureDesignSystemConfig(config.source.designSystem || {});
27
+ const designSystem = getPureDesignSystemConfig((_ref = (_designSystem = config.designSystem) !== null && _designSystem !== void 0 ? _designSystem : config.source.designSystem) !== null && _ref !== void 0 ? _ref : {});
30
28
  const [exist, key] = checkIfExistNotAllowKeys(tailwindConfig);
31
-
32
29
  if (exist) {
33
- logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`); // eslint-disable-next-line no-process-exit
34
-
30
+ logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`);
31
+ // eslint-disable-next-line no-process-exit
35
32
  process.exit(0);
36
- } // Because there is no default theme configuration
37
-
33
+ }
38
34
 
35
+ // Because there is no default theme configuration
39
36
  tailwindConfig.theme = designSystem || {};
40
37
  return tailwindConfig;
41
38
  };
42
-
43
39
  export { getTailwindConfig };
File without changes
@@ -25,10 +25,8 @@ export const checkTwinMacroNotExist = async appDirectory => {
25
25
  const packageJson = (await fs.readJSON(path.join(appDirectory, 'package.json'), {
26
26
  throws: false
27
27
  })) || {};
28
-
29
28
  if (typeof packageJson.dependencies === 'object' && packageJson.dependencies[depName] || typeof packageJson.devDependencies === 'object' && packageJson.devDependencies[depName]) {
30
29
  return false;
31
30
  }
32
-
33
31
  return true;
34
32
  };
@@ -4,33 +4,20 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getRandomTwConfigFileName = exports.default = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _cli = _interopRequireDefault(require("./design-token/cli"));
13
-
14
10
  var _tailwind = require("./tailwind");
15
-
16
11
  var _utils2 = require("./utils");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
-
22
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
-
24
15
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
26
16
  const supportCssInJsLibrary = 'styled-components';
27
-
28
17
  const getRandomTwConfigFileName = internalDirectory => {
29
18
  return (0, _utils.slash)(_path.default.join(internalDirectory, `tailwind.config.${Date.now()}.${(0, _utils.nanoid)()}.js`));
30
19
  };
31
-
32
20
  exports.getRandomTwConfigFileName = getRandomTwConfigFileName;
33
-
34
21
  var _default = ({
35
22
  pluginName
36
23
  } = {
@@ -46,31 +33,26 @@ var _default = ({
46
33
  appDirectory,
47
34
  internalDirectory
48
35
  } = api.useAppContext();
49
- let internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
50
-
36
+ let internalTwConfigPath = '';
37
+ // When reinstalling dependencies, most of the time the project will be restarted
51
38
  const notHaveTwinMacro = await (0, _utils2.checkTwinMacroNotExist)(appDirectory);
52
39
  return {
53
40
  prepare() {
54
41
  if (notHaveTwinMacro) {
55
42
  return;
56
43
  }
57
-
58
44
  internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
59
45
  const globPattern = (0, _utils.slash)(_path.default.join(appDirectory, _utils.CONFIG_CACHE_DIR, '*.cjs'));
60
-
61
46
  const files = _utils.globby.sync(globPattern, {
62
47
  absolute: true
63
48
  });
64
-
65
49
  if (files.length > 0) {
66
50
  _utils.fs.writeFileSync(internalTwConfigPath, (0, _utils2.template)(files[files.length - 1]), 'utf-8');
67
51
  }
68
52
  },
69
-
70
53
  validateSchema() {
71
54
  return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
72
55
  },
73
-
74
56
  config() {
75
57
  return {
76
58
  tools: {
@@ -78,27 +60,44 @@ var _default = ({
78
60
  // TODO: In module project, also is called, but should not be called.
79
61
  postcss: config => {
80
62
  const modernConfig = api.useResolvedConfigContext();
81
- const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
82
- pureConfig: {
83
- content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
84
- './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
63
+ if (!config.postcssOptions
64
+ // config.$$tools === 'module-tools'
65
+ ) {
66
+ if (Array.isArray(config.plugins)) {
67
+ const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
68
+ pureConfig: {
69
+ 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']
70
+ }
71
+ });
72
+ config.plugins.push(require('tailwindcss')(tailwindConfig));
73
+ } else {
74
+ const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
75
+ pureConfig: {
76
+ 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']
77
+ }
78
+ });
79
+ config.plugins = [require('tailwindcss')(tailwindConfig)];
85
80
  }
86
- });
87
-
88
- if (Array.isArray(config.postcssOptions.plugins)) {
89
- config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
90
81
  } else {
91
- config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
82
+ const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
83
+ pureConfig: {
84
+ content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx',
85
+ // about storybook
86
+ './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
87
+ }
88
+ });
89
+ if (Array.isArray(config.postcssOptions.plugins)) {
90
+ config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
91
+ } else {
92
+ config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
93
+ }
92
94
  }
93
95
  },
94
-
95
96
  babel(config) {
96
97
  var _config$plugins;
97
-
98
98
  if (notHaveTwinMacro) {
99
99
  return;
100
100
  }
101
-
102
101
  const twinConfig = {
103
102
  twin: {
104
103
  preset: supportCssInJsLibrary,
@@ -109,39 +108,24 @@ var _default = ({
109
108
  if (Array.isArray(plugin) && plugin[0]) {
110
109
  const pluginTarget = plugin[0];
111
110
  let pluginOptions = plugin[1];
112
-
113
- if (typeof pluginTarget === 'string' && // TODO: use babel chain
111
+ if (typeof pluginTarget === 'string' &&
112
+ // TODO: use babel chain
114
113
  (0, _utils.slash)(pluginTarget).includes('compiled/babel-plugin-macros')) {
115
114
  if (pluginOptions) {
116
115
  pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
117
116
  } else {
118
117
  plugin.push(twinConfig);
119
118
  }
120
-
121
119
  return true;
122
120
  }
123
121
  }
124
-
125
122
  return false;
126
123
  });
127
124
  }
128
-
129
125
  }
130
126
  };
131
- },
132
-
133
- moduleTailwindConfig() {
134
- const modernConfig = api.useResolvedConfigContext();
135
- const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
136
- pureConfig: {
137
- 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']
138
- }
139
- });
140
- return require('tailwindcss')(tailwindConfig);
141
127
  }
142
-
143
128
  };
144
129
  }
145
130
  });
146
-
147
131
  exports.default = _default;