@modern-js/plugin-tailwindcss 2.15.0 → 2.16.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/dist/esm/utils.js CHANGED
@@ -1,194 +1,200 @@
1
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
14
  }
15
- function _asyncToGenerator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(void 0);
27
+ });
28
+ };
29
29
  }
30
- var __generator = this && this.__generator || function(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
30
+ var __generator = function(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1)
35
+ throw t[1];
36
+ return t[1];
37
+ },
38
+ trys: [],
39
+ ops: []
40
+ };
41
+ return g = {
42
+ next: verb(0),
43
+ "throw": verb(1),
44
+ "return": verb(2)
45
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
46
+ return this;
47
+ }), g;
48
+ function verb(n) {
49
+ return function(v) {
50
+ return step([
51
+ n,
52
+ v
53
+ ]);
39
54
  };
40
- return(g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g);
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
55
+ }
56
+ function step(op) {
57
+ if (f)
58
+ throw new TypeError("Generator is already executing.");
59
+ while (_)
60
+ try {
61
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
62
+ return t;
63
+ if (y = 0, t)
64
+ op = [
65
+ op[0] & 2,
66
+ t.value
67
+ ];
68
+ switch (op[0]) {
69
+ case 0:
70
+ case 1:
71
+ t = op;
72
+ break;
73
+ case 4:
74
+ _.label++;
75
+ return {
76
+ value: op[1],
77
+ done: false
78
+ };
79
+ case 5:
80
+ _.label++;
81
+ y = op[1];
110
82
  op = [
111
- 6,
112
- e
83
+ 0
113
84
  ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
85
+ continue;
86
+ case 7:
87
+ op = _.ops.pop();
88
+ _.trys.pop();
89
+ continue;
90
+ default:
91
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
92
+ _ = 0;
93
+ continue;
94
+ }
95
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
96
+ _.label = op[1];
97
+ break;
98
+ }
99
+ if (op[0] === 6 && _.label < t[1]) {
100
+ _.label = t[1];
101
+ t = op;
102
+ break;
103
+ }
104
+ if (t && _.label < t[2]) {
105
+ _.label = t[2];
106
+ _.ops.push(op);
107
+ break;
108
+ }
109
+ if (t[2])
110
+ _.ops.pop();
111
+ _.trys.pop();
112
+ continue;
117
113
  }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
114
+ op = body.call(thisArg, _);
115
+ } catch (e) {
116
+ op = [
117
+ 6,
118
+ e
119
+ ];
120
+ y = 0;
121
+ } finally {
122
+ f = t = 0;
123
+ }
124
+ if (op[0] & 5)
125
+ throw op[1];
126
+ return {
127
+ value: op[0] ? op[1] : void 0,
128
+ done: true
129
+ };
130
+ }
124
131
  };
125
132
  import path from "path";
126
133
  import { fs } from "@modern-js/utils";
127
- var template = function(configPath) {
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");
134
+ export var template = function(configPath) {
135
+ 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
136
  };
130
137
  var TWIN_MACRO_NAME = "twin.macro";
131
- var checkTwinMacroExist = function() {
132
- var _ref = _asyncToGenerator(function(appDirectory) {
133
- var packageJson;
134
- return __generator(this, function(_state) {
135
- switch(_state.label){
136
- case 0:
137
- return [
138
- 4,
139
- fs.readJSON(path.join(appDirectory, "package.json"), {
140
- throws: false
141
- })
142
- ];
143
- case 1:
144
- packageJson = _state.sent() || {};
145
- return [
146
- 2,
147
- Boolean(typeof packageJson.dependencies === "object" && packageJson.dependencies[TWIN_MACRO_NAME] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[TWIN_MACRO_NAME])
148
- ];
149
- }
150
- });
138
+ export var checkTwinMacroExist = function() {
139
+ var _ref = _async_to_generator(function(appDirectory) {
140
+ var packageJson;
141
+ return __generator(this, function(_state) {
142
+ switch (_state.label) {
143
+ case 0:
144
+ return [
145
+ 4,
146
+ fs.readJSON(path.join(appDirectory, "package.json"), {
147
+ throws: false
148
+ })
149
+ ];
150
+ case 1:
151
+ packageJson = _state.sent() || {};
152
+ return [
153
+ 2,
154
+ Boolean(typeof packageJson.dependencies === "object" && packageJson.dependencies[TWIN_MACRO_NAME] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[TWIN_MACRO_NAME])
155
+ ];
156
+ }
151
157
  });
152
- return function checkTwinMacroExist(appDirectory) {
153
- return _ref.apply(this, arguments);
154
- };
158
+ });
159
+ return function checkTwinMacroExist2(appDirectory) {
160
+ return _ref.apply(this, arguments);
161
+ };
155
162
  }();
156
- var getTwinMacroMajorVersion = function(appDirectory) {
157
- try {
158
- var pkgJsonPath = require.resolve("".concat(TWIN_MACRO_NAME, "/package.json"), {
159
- paths: [
160
- appDirectory
161
- ]
162
- });
163
- var version = require(pkgJsonPath).version;
164
- return Number(version.split(".")[0]);
165
- } catch (err) {
166
- return null;
167
- }
163
+ export var getTwinMacroMajorVersion = function(appDirectory) {
164
+ try {
165
+ var pkgJsonPath = require.resolve("".concat(TWIN_MACRO_NAME, "/package.json"), {
166
+ paths: [
167
+ appDirectory
168
+ ]
169
+ });
170
+ var version = require(pkgJsonPath).version;
171
+ return Number(version.split(".")[0]);
172
+ } catch (err) {
173
+ return null;
174
+ }
168
175
  };
169
- function getTailwindPath(appDirectory) {
170
- try {
171
- return require.resolve("tailwindcss", {
172
- paths: [
173
- appDirectory,
174
- __dirname
175
- ]
176
- });
177
- } catch (err) {
178
- return "tailwindcss";
179
- }
176
+ export function getTailwindPath(appDirectory) {
177
+ try {
178
+ return require.resolve("tailwindcss", {
179
+ paths: [
180
+ appDirectory,
181
+ __dirname
182
+ ]
183
+ });
184
+ } catch (err) {
185
+ return "tailwindcss";
186
+ }
180
187
  }
181
- function getTailwindVersion(appDirectory) {
182
- try {
183
- var packageJsonPath = require.resolve("tailwindcss/package.json", {
184
- paths: [
185
- appDirectory,
186
- __dirname
187
- ]
188
- });
189
- return require(packageJsonPath).version.split(".")[0];
190
- } catch (err) {
191
- return "3";
192
- }
188
+ export function getTailwindVersion(appDirectory) {
189
+ try {
190
+ var packageJsonPath = require.resolve("tailwindcss/package.json", {
191
+ paths: [
192
+ appDirectory,
193
+ __dirname
194
+ ]
195
+ });
196
+ return require(packageJsonPath).version.split(".")[0];
197
+ } catch (err) {
198
+ return "3";
199
+ }
193
200
  }
194
- export { checkTwinMacroExist, getTailwindPath, getTailwindVersion, getTwinMacroMajorVersion, template };
@@ -1,158 +1,130 @@
1
1
  import path from "path";
2
- import {
3
- PLUGIN_SCHEMAS,
4
- fs,
5
- CONFIG_CACHE_DIR,
6
- globby,
7
- nanoid,
8
- slash
9
- } from "@modern-js/utils";
2
+ import { PLUGIN_SCHEMAS, fs, CONFIG_CACHE_DIR, globby, nanoid, slash } from "@modern-js/utils";
10
3
  import designTokenPlugin from "./design-token/cli";
11
4
  import { getTailwindConfig } from "./tailwind";
12
- import {
13
- template,
14
- checkTwinMacroExist,
15
- getTailwindPath,
16
- getTailwindVersion,
17
- getTwinMacroMajorVersion
18
- } from "./utils";
5
+ import { template, checkTwinMacroExist, getTailwindPath, getTailwindVersion, getTwinMacroMajorVersion } from "./utils";
19
6
  const supportCssInJsLibrary = "styled-components";
20
- const getRandomTwConfigFileName = (internalDirectory) => {
21
- return slash(
22
- path.join(
23
- internalDirectory,
24
- `tailwind.config.${Date.now()}.${nanoid()}.js`
25
- )
26
- );
7
+ export const getRandomTwConfigFileName = (internalDirectory) => {
8
+ return slash(path.join(internalDirectory, `tailwind.config.${Date.now()}.${nanoid()}.js`));
27
9
  };
28
- var cli_default = ({ pluginName } = {
10
+ export default ({ pluginName } = {
29
11
  pluginName: "@modern-js/plugin-tailwindcss"
30
- }) => ({
31
- name: "@modern-js/plugin-tailwindcss",
32
- // support designSystem.supportStyledComponents
33
- usePlugins: [
34
- designTokenPlugin({
35
- pluginName
36
- })
37
- ],
38
- setup: async (api) => {
39
- const { appDirectory, internalDirectory } = api.useAppContext();
40
- let internalTwConfigPath = "";
41
- const haveTwinMacro = await checkTwinMacroExist(appDirectory);
42
- const tailwindPath = getTailwindPath(appDirectory);
43
- const tailwindVersion = getTailwindVersion(appDirectory);
44
- const defaultContent = [
45
- "./config/html/**/*.html",
46
- "./config/html/**/*.ejs",
47
- "./config/html/**/*.hbs",
48
- "./src/**/*.js",
49
- "./src/**/*.jsx",
50
- "./src/**/*.ts",
51
- "./src/**/*.tsx",
52
- // about storybook
53
- "./storybook/**/*"
54
- ];
55
- return {
56
- prepare() {
57
- if (haveTwinMacro) {
58
- const twinMajorVersion = getTwinMacroMajorVersion(appDirectory);
59
- const useConfigPath = twinMajorVersion && twinMajorVersion < 3;
60
- if (useConfigPath) {
61
- internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
62
- const globPattern = slash(
63
- path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs")
64
- );
65
- const files = globby.sync(globPattern, {
66
- absolute: true
67
- });
68
- if (files.length > 0) {
69
- fs.writeFileSync(
70
- internalTwConfigPath,
71
- template(files[files.length - 1]),
72
- "utf-8"
73
- );
12
+ }) => {
13
+ return {
14
+ name: "@modern-js/plugin-tailwindcss",
15
+ // support designSystem.supportStyledComponents
16
+ usePlugins: [
17
+ designTokenPlugin({
18
+ pluginName
19
+ })
20
+ ],
21
+ setup: async (api) => {
22
+ const { appDirectory, internalDirectory } = api.useAppContext();
23
+ let internalTwConfigPath = "";
24
+ const haveTwinMacro = await checkTwinMacroExist(appDirectory);
25
+ const tailwindPath = getTailwindPath(appDirectory);
26
+ const tailwindVersion = getTailwindVersion(appDirectory);
27
+ const defaultContent = [
28
+ "./config/html/**/*.html",
29
+ "./config/html/**/*.ejs",
30
+ "./config/html/**/*.hbs",
31
+ "./src/**/*.js",
32
+ "./src/**/*.jsx",
33
+ "./src/**/*.ts",
34
+ "./src/**/*.tsx",
35
+ // about storybook
36
+ "./storybook/**/*"
37
+ ];
38
+ return {
39
+ prepare() {
40
+ if (haveTwinMacro) {
41
+ const twinMajorVersion = getTwinMacroMajorVersion(appDirectory);
42
+ const useConfigPath = twinMajorVersion && twinMajorVersion < 3;
43
+ if (useConfigPath) {
44
+ internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
45
+ const globPattern = slash(path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs"));
46
+ const files = globby.sync(globPattern, {
47
+ absolute: true
48
+ });
49
+ if (files.length > 0) {
50
+ fs.writeFileSync(internalTwConfigPath, template(files[files.length - 1]), "utf-8");
51
+ }
74
52
  }
75
53
  }
76
- }
77
- },
78
- validateSchema() {
79
- return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
80
- },
81
- config() {
82
- let tailwindConfig;
83
- const initTailwindConfig = () => {
84
- var _a, _b;
85
- if (!tailwindConfig) {
86
- const modernConfig = api.useResolvedConfigContext();
87
- tailwindConfig = getTailwindConfig(
88
- tailwindVersion,
89
- (_a = modernConfig == null ? void 0 : modernConfig.tools) == null ? void 0 : _a.tailwindcss,
90
- (_b = modernConfig == null ? void 0 : modernConfig.source) == null ? void 0 : _b.designSystem,
91
- {
54
+ },
55
+ validateSchema() {
56
+ return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
57
+ },
58
+ config() {
59
+ let tailwindConfig;
60
+ const initTailwindConfig = () => {
61
+ if (!tailwindConfig) {
62
+ var _modernConfig_tools, _modernConfig_source;
63
+ const modernConfig = api.useResolvedConfigContext();
64
+ tailwindConfig = getTailwindConfig(tailwindVersion, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_tools = modernConfig.tools) === null || _modernConfig_tools === void 0 ? void 0 : _modernConfig_tools.tailwindcss, modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_source = modernConfig.source) === null || _modernConfig_source === void 0 ? void 0 : _modernConfig_source.designSystem, {
92
65
  pureConfig: {
93
66
  content: defaultContent
94
67
  }
95
- }
96
- );
97
- }
98
- };
99
- return {
100
- tools: {
101
- // TODO: Add interface about postcss config
102
- // TODO: In module project, also is called, but should not be called.
103
- postcss: (config) => {
104
- initTailwindConfig();
105
- const tailwindPlugin = require(tailwindPath)(tailwindConfig);
106
- if (Array.isArray(config.postcssOptions.plugins)) {
107
- config.postcssOptions.plugins.push(tailwindPlugin);
108
- } else {
109
- config.postcssOptions.plugins = [tailwindPlugin];
110
- }
111
- },
112
- babel(_, { addPlugins }) {
113
- if (haveTwinMacro) {
68
+ });
69
+ }
70
+ };
71
+ return {
72
+ tools: {
73
+ // TODO: Add interface about postcss config
74
+ // TODO: In module project, also is called, but should not be called.
75
+ postcss: (config) => {
114
76
  initTailwindConfig();
115
- addPlugins([
116
- [
117
- require.resolve("babel-plugin-macros"),
118
- {
119
- twin: {
120
- preset: supportCssInJsLibrary,
121
- config: internalTwConfigPath || tailwindConfig
77
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
78
+ if (Array.isArray(config.postcssOptions.plugins)) {
79
+ config.postcssOptions.plugins.push(tailwindPlugin);
80
+ } else {
81
+ config.postcssOptions.plugins = [
82
+ tailwindPlugin
83
+ ];
84
+ }
85
+ },
86
+ babel(_, { addPlugins }) {
87
+ if (haveTwinMacro) {
88
+ initTailwindConfig();
89
+ addPlugins([
90
+ [
91
+ require.resolve("babel-plugin-macros"),
92
+ {
93
+ twin: {
94
+ preset: supportCssInJsLibrary,
95
+ config: internalTwConfigPath || tailwindConfig
96
+ }
122
97
  }
123
- }
124
- ]
125
- ]);
98
+ ]
99
+ ]);
100
+ }
126
101
  }
127
102
  }
128
- }
129
- };
130
- },
131
- beforeBuildTask(config) {
132
- const modernConfig = api.useResolvedConfigContext();
133
- const { designSystem } = modernConfig;
134
- const tailwindConfig = getTailwindConfig(
135
- tailwindVersion,
136
- config.style.tailwindCss,
137
- designSystem,
138
- {
103
+ };
104
+ },
105
+ beforeBuildTask(config) {
106
+ const modernConfig = api.useResolvedConfigContext();
107
+ const { designSystem } = modernConfig;
108
+ const tailwindConfig = getTailwindConfig(tailwindVersion, config.style.tailwindCss, designSystem, {
139
109
  pureConfig: {
140
110
  content: defaultContent
141
111
  }
112
+ });
113
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
114
+ if (Array.isArray(config.style.postcss.plugins)) {
115
+ config.style.postcss.plugins.push(tailwindPlugin);
116
+ } else {
117
+ config.style.postcss.plugins = [
118
+ tailwindPlugin
119
+ ];
142
120
  }
143
- );
144
- const tailwindPlugin = require(tailwindPath)(tailwindConfig);
145
- if (Array.isArray(config.style.postcss.plugins)) {
146
- config.style.postcss.plugins.push(tailwindPlugin);
147
- } else {
148
- config.style.postcss.plugins = [tailwindPlugin];
121
+ return config;
122
+ },
123
+ modifyLibuild(config, next) {
124
+ config.transformCache = false;
125
+ return next(config);
149
126
  }
150
- return config;
151
- }
152
- };
153
- }
154
- });
155
- export {
156
- cli_default as default,
157
- getRandomTwConfigFileName
127
+ };
128
+ }
129
+ };
158
130
  };