@modern-js/plugin-tailwindcss 1.2.11 → 1.4.0-alpha.0

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