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

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 (32) hide show
  1. package/CHANGELOG.md +141 -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 +7 -11
  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 +7 -14
  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 +10 -15
  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 +2 -4
  27. package/dist/types/design-token/cli/index.d.ts +2 -4
  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/tailwind.d.ts +2 -2
  31. package/dist/types/types.d.ts +10 -0
  32. package/package.json +13 -12
@@ -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;
@@ -4,49 +4,37 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  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; }
11
-
12
9
  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; }
13
-
14
10
  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; }
15
-
16
11
  var _default = ({
17
12
  pluginName
18
13
  } = {
19
14
  pluginName: '@modern-js/plugin-tailwindcss'
20
15
  }) => ({
21
16
  name: '@modern-js/plugin-design-token',
22
-
23
17
  setup(api) {
24
18
  let pluginsExportsUtils;
25
19
  const resolveConfig = (0, _utils.lazyImport)('tailwindcss/resolveConfig', require);
26
20
  const PLUGIN_IDENTIFIER = 'designToken';
27
-
28
21
  const getDesignTokens = userConfig => {
29
- const {
30
- source: {
31
- designSystem
32
- }
33
- } = userConfig; // TODO: Type to be filled
34
-
22
+ var _userConfig$source;
23
+ const designSystem = (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.designSystem;
35
24
  const tailwindcssConfig = {};
36
- tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {}; // not use default design token when designToken.defaultTheme is false or theme is false
25
+ tailwindcssConfig.theme = designSystem ? _objectSpread({}, designSystem) : {};
37
26
 
27
+ // not use default design token when designToken.defaultTheme is false or theme is false
38
28
  if (!designSystem) {
39
29
  tailwindcssConfig.presets = [];
40
- } // when only designSystem exist, need remove supportStyledComponents
41
-
30
+ }
42
31
 
32
+ // when only designSystem exist, need remove supportStyledComponents
43
33
  if (designSystem) {
44
34
  delete tailwindcssConfig.theme.supportStyledComponents;
45
35
  }
46
-
47
36
  return resolveConfig(tailwindcssConfig).theme || {};
48
37
  };
49
-
50
38
  return {
51
39
  config() {
52
40
  const appContext = api.useAppContext();
@@ -57,25 +45,21 @@ var _default = ({
57
45
  '@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
58
46
  }
59
47
  },
60
- tools: {// TODO: support less、scss、css vars
48
+ tools: {
49
+ // TODO: support less、scss、css vars
61
50
  // less: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR166
62
51
  // sass: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR229
63
52
  // postcss: https://github.com/modern-js-dev/modern.js/pull/398/files#diff-f77c749e403fbf1fb676d5687bef3d7138a230331c849298d8afaff9b6afbc3dR281
64
53
  }
65
54
  };
66
55
  },
67
-
68
56
  modifyEntryImports({
69
57
  entrypoint,
70
58
  imports
71
59
  }) {
60
+ var _userConfig$source$de, _userConfig$source2;
72
61
  const userConfig = api.useResolvedConfigContext();
73
- const {
74
- source: {
75
- designSystem
76
- }
77
- } = userConfig;
78
-
62
+ 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 : {};
79
63
  if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
80
64
  const designTokens = getDesignTokens(userConfig);
81
65
  imports.push({
@@ -88,54 +72,42 @@ var _default = ({
88
72
  `
89
73
  });
90
74
  }
91
-
92
75
  return {
93
76
  entrypoint,
94
77
  imports
95
78
  };
96
79
  },
97
-
98
80
  modifyEntryRuntimePlugins({
99
81
  entrypoint,
100
82
  plugins
101
83
  }) {
102
- const {
103
- source: {
104
- designSystem
105
- }
106
- } = api.useResolvedConfigContext();
84
+ var _userConfig$source$de2, _userConfig$source3;
85
+ const userConfig = api.useResolvedConfigContext();
86
+ 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 : {};
107
87
  let useSCThemeProvider = true;
108
-
109
88
  if (designSystem) {
110
89
  // when designSystem exist, designToken.styledComponents`s default value is false.
111
90
  useSCThemeProvider = (designSystem === null || designSystem === void 0 ? void 0 : designSystem.supportStyledComponents) || false;
112
91
  }
113
-
114
92
  if (typeof designSystem === 'object' && designSystem.supportStyledComponents) {
115
93
  plugins.push({
116
94
  name: PLUGIN_IDENTIFIER,
117
95
  options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? 'true' : 'false'}, useDesignTokenContext: false}`
118
96
  });
119
97
  }
120
-
121
98
  return {
122
99
  entrypoint,
123
100
  plugins
124
101
  };
125
102
  },
126
-
127
103
  validateSchema() {
128
104
  // add source.designSystem.supportStyledComponents config
129
105
  return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-design-token'];
130
106
  },
131
-
132
107
  addRuntimeExports() {
133
108
  pluginsExportsUtils.addExport(`export { default as designToken } from '${pluginName}/runtime-design-token'`);
134
109
  }
135
-
136
110
  };
137
111
  }
138
-
139
112
  });
140
-
141
113
  exports.default = _default;
@@ -10,9 +10,7 @@ Object.defineProperty(exports, "default", {
10
10
  return _runtime.default;
11
11
  }
12
12
  });
13
-
14
13
  var _runtime = _interopRequireWildcard(require("./runtime"));
15
-
16
14
  Object.keys(_runtime).forEach(function (key) {
17
15
  if (key === "default" || key === "__esModule") return;
18
16
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -24,7 +22,5 @@ Object.keys(_runtime).forEach(function (key) {
24
22
  }
25
23
  });
26
24
  });
27
-
28
25
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
-
30
26
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -4,24 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _default = ({
9
8
  cssVarsHash: _cssVarsHash = {}
10
9
  } = {}) => ({
11
10
  postcssPlugin: 'postcss-replace-css-vars',
12
-
13
11
  Declaration(decl) {
14
12
  if (decl.value && typeof decl.value === 'string') {
15
13
  decl.value = decl.value.replace(/--\S*/g, match => {
16
14
  if (_cssVarsHash[match]) {
17
15
  return _cssVarsHash[match];
18
16
  }
19
-
20
17
  return match;
21
18
  });
22
19
  }
23
20
  }
24
-
25
21
  });
26
-
27
22
  exports.default = _default;
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {};
7
7
  exports.default = void 0;
8
-
9
8
  var _plugin = _interopRequireWildcard(require("./plugin"));
10
-
11
9
  Object.keys(_plugin).forEach(function (key) {
12
10
  if (key === "default" || key === "__esModule") return;
13
11
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -19,10 +17,7 @@ Object.keys(_plugin).forEach(function (key) {
19
17
  }
20
18
  });
21
19
  });
22
-
23
20
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
-
25
21
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
26
-
27
22
  var _default = _plugin.default;
28
23
  exports.default = _default;
@@ -4,33 +4,19 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.useDesignTokens = exports.default = exports.DesignTokenContext = void 0;
7
-
8
7
  var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
9
-
10
8
  var _react = _interopRequireWildcard(require("react"));
11
-
12
9
  var _jsxRuntime = require("react/jsx-runtime");
13
-
14
10
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
-
16
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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 DesignTokenContext = /*#__PURE__*/_react.default.createContext({});
27
-
28
17
  exports.DesignTokenContext = DesignTokenContext;
29
-
30
18
  const useDesignTokens = () => (0, _react.useContext)(DesignTokenContext);
31
-
32
19
  exports.useDesignTokens = useDesignTokens;
33
-
34
20
  var _default = (options = {}) => ({
35
21
  name: '@modern-js/plugin-design-token',
36
22
  setup: () => ({
@@ -43,12 +29,10 @@ var _default = (options = {}) => ({
43
29
  useStyledComponentsThemeProvider = false,
44
30
  useDesignTokenContext = false
45
31
  } = options;
46
-
47
32
  if (useStyledComponentsThemeProvider && useDesignTokenContext) {
48
33
  const {
49
34
  ThemeProvider
50
35
  } = require('@modern-js/runtime/styled');
51
-
52
36
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeProvider, {
53
37
  theme: token,
54
38
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DesignTokenContext.Provider, {
@@ -60,7 +44,6 @@ var _default = (options = {}) => ({
60
44
  const {
61
45
  ThemeProvider
62
46
  } = require('@modern-js/runtime/styled');
63
-
64
47
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(ThemeProvider, {
65
48
  theme: token,
66
49
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props))
@@ -74,13 +57,10 @@ var _default = (options = {}) => ({
74
57
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(App, _objectSpread({}, props));
75
58
  }
76
59
  };
77
-
78
60
  return next({
79
61
  App: (0, _hoistNonReactStatics.default)(DesignTokenAppWrapper, App)
80
62
  });
81
63
  }
82
-
83
64
  })
84
65
  });
85
-
86
66
  exports.default = _default;
@@ -9,7 +9,5 @@ Object.defineProperty(exports, "default", {
9
9
  return _cli.default;
10
10
  }
11
11
  });
12
-
13
12
  var _cli = _interopRequireDefault(require("./cli"));
14
-
15
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -4,25 +4,21 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getTailwindConfig = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  var _lodash = require("@modern-js/utils/lodash");
11
-
12
9
  const checkIfExistNotAllowKeys = tailwindConfig => {
13
10
  const notAllowExistKeys = ['theme'];
14
11
  let notAllowKey = '';
15
12
  const ret = Object.keys(tailwindConfig).some(key => notAllowExistKeys.includes(key) && (notAllowKey = key));
16
13
  return [ret, notAllowKey];
17
14
  };
18
-
19
15
  const getPureDesignSystemConfig = designSystemConfig => {
20
16
  const pureDesignSystemConfig = (0, _lodash.cloneDeep)(designSystemConfig);
21
17
  delete pureDesignSystemConfig.supportStyledComponents;
22
18
  return pureDesignSystemConfig;
23
19
  };
24
-
25
20
  const getTailwindConfig = (config, option = {}) => {
21
+ var _config$tools, _ref, _designSystem;
26
22
  const purgeConfig = (0, _lodash.merge)({
27
23
  // TODO: how the operating environment is determined
28
24
  enabled: process.env.NODE_ENV === 'production',
@@ -33,20 +29,17 @@ const getTailwindConfig = (config, option = {}) => {
33
29
  const defaultTailwindConfig = {
34
30
  purge: purgeConfig
35
31
  };
36
- const tailwindConfig = (0, _utils.applyOptionsChain)(defaultTailwindConfig, config.tools.tailwindcss || {});
37
- const designSystem = getPureDesignSystemConfig(config.source.designSystem || {});
32
+ const tailwindConfig = (0, _utils.applyOptionsChain)(defaultTailwindConfig, ((_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.tailwindcss) || {});
33
+ const designSystem = getPureDesignSystemConfig((_ref = (_designSystem = config.designSystem) !== null && _designSystem !== void 0 ? _designSystem : config.source.designSystem) !== null && _ref !== void 0 ? _ref : {});
38
34
  const [exist, key] = checkIfExistNotAllowKeys(tailwindConfig);
39
-
40
35
  if (exist) {
41
- _utils.logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`); // eslint-disable-next-line no-process-exit
42
-
43
-
36
+ _utils.logger.error(`should not exist '${key}' on tools.tailwindcss, please remove it`);
37
+ // eslint-disable-next-line no-process-exit
44
38
  process.exit(0);
45
- } // Because there is no default theme configuration
46
-
39
+ }
47
40
 
41
+ // Because there is no default theme configuration
48
42
  tailwindConfig.theme = designSystem || {};
49
43
  return tailwindConfig;
50
44
  };
51
-
52
45
  exports.getTailwindConfig = getTailwindConfig;
File without changes
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.template = exports.checkTwinMacroNotExist = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
10
  const template = configPath => `
15
11
  function _interopRequireDefault(obj) {
16
12
  return obj && obj.__esModule ? obj : { default: obj };
@@ -31,20 +27,15 @@ module.exports = {
31
27
  ...tailwindcss,
32
28
  };
33
29
  `;
34
-
35
30
  exports.template = template;
36
-
37
31
  const checkTwinMacroNotExist = async appDirectory => {
38
32
  const depName = 'twin.macro';
39
33
  const packageJson = (await _utils.fs.readJSON(_path.default.join(appDirectory, 'package.json'), {
40
34
  throws: false
41
35
  })) || {};
42
-
43
36
  if (typeof packageJson.dependencies === 'object' && packageJson.dependencies[depName] || typeof packageJson.devDependencies === 'object' && packageJson.devDependencies[depName]) {
44
37
  return false;
45
38
  }
46
-
47
39
  return true;
48
40
  };
49
-
50
41
  exports.checkTwinMacroNotExist = checkTwinMacroNotExist;