@modern-js/plugin-tailwindcss 1.2.10 → 1.3.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @modern-js/plugin-tailwindcss
2
2
 
3
+ ## 1.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8d0eb81f5: support twin.macro
8
+
9
+ ## 1.2.11
10
+
11
+ ### Patch Changes
12
+
13
+ - a1198d509: feat: bump babel 7.18.0
14
+ - Updated dependencies [a1198d509]
15
+ - @modern-js/plugin-design-token@1.0.10
16
+
3
17
  ## 1.2.10
4
18
 
5
19
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.getRandomTwConfigFileName = exports.default = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
@@ -11,52 +11,127 @@ var _cli = _interopRequireDefault(require("@modern-js/plugin-design-token/cli"))
11
11
 
12
12
  var _tailwind = require("./tailwind");
13
13
 
14
+ var _utils2 = require("./utils");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
18
+ 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; }
19
+
20
+ 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; }
21
+
22
+ 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; }
23
+
24
+ const supportCssInJsLibrary = 'styled-components';
25
+
26
+ const getRandomTwConfigFileName = internalDirectory => {
27
+ return `${internalDirectory}/tailwind.config.${Date.now()}.${(0, _utils.nanoid)()}.js`;
28
+ };
29
+
30
+ exports.getRandomTwConfigFileName = getRandomTwConfigFileName;
31
+
16
32
  var _default = () => ({
17
33
  name: '@modern-js/plugin-tailwindcss',
18
34
  // support designSystem.supportStyledComponents
19
35
  usePlugins: [(0, _cli.default)()],
20
- setup: api => ({
21
- validateSchema() {
22
- return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
23
- },
24
-
25
- config() {
26
- return {
27
- tools: {
28
- // TODO: Add interface about postcss config
29
- // TODO: In module project, also is called, but should not be called.
30
- postcss: config => {
31
- const modernConfig = api.useResolvedConfigContext();
32
- const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
33
- pureConfig: {
34
- content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
35
- './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
36
+ setup: async api => {
37
+ const {
38
+ appDirectory,
39
+ internalDirectory
40
+ } = api.useAppContext();
41
+ let internalTwConfigPath = ''; // When reinstalling dependencies, most of the time the project will be restarted
42
+
43
+ const notHaveTwinMacro = await (0, _utils2.checkTwinMacroNotExist)(appDirectory);
44
+ return {
45
+ prepare() {
46
+ if (notHaveTwinMacro) {
47
+ return;
48
+ }
49
+
50
+ internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
51
+
52
+ const files = _utils.globby.sync(`${appDirectory}/${_utils.CONFIG_CACHE_DIR}/*.cjs`, {
53
+ absolute: true
54
+ });
55
+
56
+ if (files.length > 0) {
57
+ _utils.fs.writeFileSync(internalTwConfigPath, (0, _utils2.template)(files[files.length - 1]), 'utf-8');
58
+ }
59
+ },
60
+
61
+ validateSchema() {
62
+ return _utils.PLUGIN_SCHEMAS['@modern-js/plugin-tailwindcss'];
63
+ },
64
+
65
+ config() {
66
+ return {
67
+ tools: {
68
+ // TODO: Add interface about postcss config
69
+ // TODO: In module project, also is called, but should not be called.
70
+ postcss: config => {
71
+ const modernConfig = api.useResolvedConfigContext();
72
+ const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
73
+ pureConfig: {
74
+ content: ['./config/html/**/*.html', './config/html/**/*.ejs', './config/html/**/*.hbs', './src/**/*.js', './src/**/*.jsx', './src/**/*.ts', './src/**/*.tsx', // about storybook
75
+ './storybook/**/*', './styles/**/*.less', './styles/**/*.css', './styles/**/*.sass', './styles/**/*.scss']
76
+ }
77
+ });
78
+
79
+ if (Array.isArray(config.postcssOptions.plugins)) {
80
+ config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
81
+ } else {
82
+ config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
36
83
  }
37
- });
84
+ },
85
+
86
+ babel(config) {
87
+ var _config$plugins;
88
+
89
+ if (notHaveTwinMacro) {
90
+ return;
91
+ }
92
+
93
+ const twinConfig = {
94
+ twin: {
95
+ preset: supportCssInJsLibrary,
96
+ config: internalTwConfigPath
97
+ }
98
+ };
99
+ (_config$plugins = config.plugins) === null || _config$plugins === void 0 ? void 0 : _config$plugins.some(plugin => {
100
+ if (Array.isArray(plugin) && plugin[0]) {
101
+ const pluginTarget = plugin[0];
102
+ let pluginOptions = plugin[1];
103
+
104
+ if (typeof pluginTarget === 'string' && pluginTarget.includes('compiled/babel-plugin-macros')) {
105
+ if (pluginOptions) {
106
+ pluginOptions = _objectSpread(_objectSpread({}, pluginOptions), twinConfig);
107
+ } else {
108
+ plugin.push(twinConfig);
109
+ }
38
110
 
39
- if (Array.isArray(config.postcssOptions.plugins)) {
40
- config.postcssOptions.plugins.push(require('tailwindcss')(tailwindConfig));
41
- } else {
42
- config.postcssOptions.plugins = [require('tailwindcss')(tailwindConfig)];
111
+ return true;
112
+ }
113
+ }
114
+
115
+ return false;
116
+ });
43
117
  }
118
+
44
119
  }
45
- }
46
- };
47
- },
48
-
49
- moduleTailwindConfig() {
50
- const modernConfig = api.useResolvedConfigContext();
51
- const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
52
- pureConfig: {
53
- 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']
54
- }
55
- });
56
- return require('tailwindcss')(tailwindConfig);
57
- }
120
+ };
121
+ },
122
+
123
+ moduleTailwindConfig() {
124
+ const modernConfig = api.useResolvedConfigContext();
125
+ const tailwindConfig = (0, _tailwind.getTailwindConfig)(modernConfig, {
126
+ pureConfig: {
127
+ 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']
128
+ }
129
+ });
130
+ return require('tailwindcss')(tailwindConfig);
131
+ }
58
132
 
59
- })
133
+ };
134
+ }
60
135
  });
61
136
 
62
137
  exports.default = _default;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.template = exports.checkTwinMacroNotExist = void 0;
7
+
8
+ var _path = _interopRequireDefault(require("path"));
9
+
10
+ var _utils = require("@modern-js/utils");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ const template = configPath => `
15
+ function _interopRequireDefault(obj) {
16
+ return obj && obj.__esModule ? obj : { default: obj };
17
+ }
18
+ const modernConfig = _interopRequireDefault(require('${configPath}')).default;
19
+
20
+ const theme =
21
+ modernConfig && modernConfig.source && modernConfig.source.designSystem
22
+ ? modernConfig.source.designSystem
23
+ : {};
24
+ const tailwindcss =
25
+ modernConfig && modernConfig.tools && modernConfig.tools.tailwindcss
26
+ ? modernConfig.tools.tailwindcss
27
+ : {};
28
+
29
+ module.exports = {
30
+ theme,
31
+ ...tailwindcss,
32
+ };
33
+ `;
34
+
35
+ exports.template = template;
36
+
37
+ const checkTwinMacroNotExist = async appDirectory => {
38
+ const depName = 'twin.macro';
39
+ const packageJson = (await _utils.fs.readJSON(_path.default.join(appDirectory, 'package.json'), {
40
+ throws: false
41
+ })) || {};
42
+
43
+ if (typeof packageJson.dependencies === 'object' && packageJson.dependencies[depName] || typeof packageJson.devDependencies === 'object' && packageJson.devDependencies[depName]) {
44
+ return false;
45
+ }
46
+
47
+ return true;
48
+ };
49
+
50
+ exports.checkTwinMacroNotExist = checkTwinMacroNotExist;
@@ -1,4 +1,5 @@
1
1
  import type { CliPlugin } from '@modern-js/core';
2
+ export declare const getRandomTwConfigFileName: (internalDirectory: string) => string;
2
3
 
3
4
  declare const _default: () => CliPlugin;
4
5
 
@@ -0,0 +1,2 @@
1
+ export declare const template: (configPath: string) => string;
2
+ export declare const checkTwinMacroNotExist: (appDirectory: string) => Promise<boolean>;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.10",
14
+ "version": "1.3.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -32,12 +32,12 @@
32
32
  }
33
33
  },
34
34
  "dependencies": {
35
- "@babel/runtime": "^7",
36
- "@modern-js/utils": "^1.7.3",
37
- "@modern-js/plugin-design-token": "^1.0.7"
35
+ "@babel/runtime": "^7.18.0",
36
+ "@modern-js/utils": "^1.7.8",
37
+ "@modern-js/plugin-design-token": "^1.0.11"
38
38
  },
39
39
  "devDependencies": {
40
- "@modern-js/core": "1.10.2",
40
+ "@modern-js/core": "1.12.1",
41
41
  "@scripts/build": "0.0.0",
42
42
  "@types/jest": "^27",
43
43
  "@types/node": "^14",
@@ -45,6 +45,7 @@
45
45
  "typescript": "^4",
46
46
  "tailwindcss": "^2.0.4",
47
47
  "jest": "^27",
48
+ "postcss": "^8.4.14",
48
49
  "@scripts/jest-config": "0.0.0"
49
50
  },
50
51
  "peerDependencies": {
@@ -72,7 +73,8 @@
72
73
  "files": [
73
74
  "src/**/*",
74
75
  "tsconfig.json",
75
- "package.json"
76
+ "package.json",
77
+ "tests/**/*"
76
78
  ],
77
79
  "output": []
78
80
  }