@modern-js/plugin-tailwindcss 2.13.3 → 2.13.5-beta.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/cli.js +4 -0
  3. package/dist/esm/cli.js +4 -0
  4. package/dist/esm-node/cli.js +4 -0
  5. package/dist/js/modern/cli.js +174 -0
  6. package/dist/js/modern/design-token/cli/index.js +110 -0
  7. package/dist/js/modern/design-token/index.js +5 -0
  8. package/dist/js/modern/design-token/postcss-plugin/index.js +18 -0
  9. package/dist/js/modern/design-token/runtime/index.js +6 -0
  10. package/dist/js/modern/design-token/runtime/plugin.js +66 -0
  11. package/dist/js/modern/index.js +4 -0
  12. package/dist/js/modern/tailwind.js +45 -0
  13. package/dist/js/modern/types.js +0 -0
  14. package/dist/js/modern/utils.js +86 -0
  15. package/dist/js/node/cli.js +190 -0
  16. package/dist/js/node/design-token/cli/index.js +125 -0
  17. package/dist/js/node/design-token/index.js +33 -0
  18. package/dist/js/node/design-token/postcss-plugin/index.js +39 -0
  19. package/dist/js/node/design-token/runtime/index.js +34 -0
  20. package/dist/js/node/design-token/runtime/plugin.js +94 -0
  21. package/dist/js/node/index.js +31 -0
  22. package/dist/js/node/tailwind.js +68 -0
  23. package/dist/js/node/types.js +15 -0
  24. package/dist/js/node/utils.js +119 -0
  25. package/dist/js/treeshaking/cli.js +268 -0
  26. package/dist/js/treeshaking/design-token/cli/index.js +118 -0
  27. package/dist/js/treeshaking/design-token/index.js +3 -0
  28. package/dist/js/treeshaking/design-token/postcss-plugin/index.js +17 -0
  29. package/dist/js/treeshaking/design-token/runtime/index.js +4 -0
  30. package/dist/js/treeshaking/design-token/runtime/plugin.js +78 -0
  31. package/dist/js/treeshaking/index.js +2 -0
  32. package/dist/js/treeshaking/tailwind.js +91 -0
  33. package/dist/js/treeshaking/types.js +1 -0
  34. package/dist/js/treeshaking/utils.js +194 -0
  35. package/package.json +10 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @modern-js/plugin-tailwindcss
2
2
 
3
+ ## 2.13.4
4
+
5
+ ### Patch Changes
6
+
7
+ - @modern-js/runtime@2.13.4
8
+ - @modern-js/utils@2.13.4
9
+
3
10
  ## 2.13.3
4
11
 
5
12
  ### Patch Changes
package/dist/cjs/cli.js CHANGED
@@ -168,6 +168,10 @@ var cli_default = ({ pluginName } = {
168
168
  config.style.postcss.plugins = [tailwindPlugin];
169
169
  }
170
170
  return config;
171
+ },
172
+ modifyLibuild(config, next) {
173
+ config.transformCache = false;
174
+ return next(config);
171
175
  }
172
176
  };
173
177
  }
package/dist/esm/cli.js CHANGED
@@ -257,6 +257,10 @@ var cli_default = function() {
257
257
  ];
258
258
  }
259
259
  return config;
260
+ },
261
+ modifyLibuild: function modifyLibuild(config, next) {
262
+ config.transformCache = false;
263
+ return next(config);
260
264
  }
261
265
  }
262
266
  ];
@@ -148,6 +148,10 @@ var cli_default = ({ pluginName } = {
148
148
  config.style.postcss.plugins = [tailwindPlugin];
149
149
  }
150
150
  return config;
151
+ },
152
+ modifyLibuild(config, next) {
153
+ config.transformCache = false;
154
+ return next(config);
151
155
  }
152
156
  };
153
157
  }
@@ -0,0 +1,174 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import path from "path";
22
+ import {
23
+ PLUGIN_SCHEMAS,
24
+ fs,
25
+ CONFIG_CACHE_DIR,
26
+ globby,
27
+ nanoid,
28
+ slash
29
+ } from "@modern-js/utils";
30
+ import designTokenPlugin from "./design-token/cli";
31
+ import { getTailwindConfig } from "./tailwind";
32
+ import {
33
+ template,
34
+ checkTwinMacroExist,
35
+ getTailwindPath,
36
+ getTailwindVersion,
37
+ getTwinMacroMajorVersion
38
+ } from "./utils";
39
+ const supportCssInJsLibrary = "styled-components";
40
+ const getRandomTwConfigFileName = (internalDirectory) => {
41
+ return slash(
42
+ path.join(
43
+ internalDirectory,
44
+ `tailwind.config.${Date.now()}.${nanoid()}.js`
45
+ )
46
+ );
47
+ };
48
+ var cli_default = ({ pluginName } = {
49
+ pluginName: "@modern-js/plugin-tailwindcss"
50
+ }) => ({
51
+ name: "@modern-js/plugin-tailwindcss",
52
+ usePlugins: [
53
+ designTokenPlugin({
54
+ pluginName
55
+ })
56
+ ],
57
+ setup: (api) => __async(void 0, null, function* () {
58
+ const { appDirectory, internalDirectory } = api.useAppContext();
59
+ let internalTwConfigPath = "";
60
+ const haveTwinMacro = yield checkTwinMacroExist(appDirectory);
61
+ const tailwindPath = getTailwindPath(appDirectory);
62
+ const tailwindVersion = getTailwindVersion(appDirectory);
63
+ const defaultContent = [
64
+ "./config/html/**/*.html",
65
+ "./config/html/**/*.ejs",
66
+ "./config/html/**/*.hbs",
67
+ "./src/**/*.js",
68
+ "./src/**/*.jsx",
69
+ "./src/**/*.ts",
70
+ "./src/**/*.tsx",
71
+ "./storybook/**/*"
72
+ ];
73
+ return {
74
+ prepare() {
75
+ if (haveTwinMacro) {
76
+ const twinMajorVersion = getTwinMacroMajorVersion(appDirectory);
77
+ const useConfigPath = twinMajorVersion && twinMajorVersion < 3;
78
+ if (useConfigPath) {
79
+ internalTwConfigPath = getRandomTwConfigFileName(internalDirectory);
80
+ const globPattern = slash(
81
+ path.join(appDirectory, CONFIG_CACHE_DIR, "*.cjs")
82
+ );
83
+ const files = globby.sync(globPattern, {
84
+ absolute: true
85
+ });
86
+ if (files.length > 0) {
87
+ fs.writeFileSync(
88
+ internalTwConfigPath,
89
+ template(files[files.length - 1]),
90
+ "utf-8"
91
+ );
92
+ }
93
+ }
94
+ }
95
+ },
96
+ validateSchema() {
97
+ return PLUGIN_SCHEMAS["@modern-js/plugin-tailwindcss"];
98
+ },
99
+ config() {
100
+ let tailwindConfig;
101
+ const initTailwindConfig = () => {
102
+ var _a, _b;
103
+ if (!tailwindConfig) {
104
+ const modernConfig = api.useResolvedConfigContext();
105
+ tailwindConfig = getTailwindConfig(
106
+ tailwindVersion,
107
+ (_a = modernConfig == null ? void 0 : modernConfig.tools) == null ? void 0 : _a.tailwindcss,
108
+ (_b = modernConfig == null ? void 0 : modernConfig.source) == null ? void 0 : _b.designSystem,
109
+ {
110
+ pureConfig: {
111
+ content: defaultContent
112
+ }
113
+ }
114
+ );
115
+ }
116
+ };
117
+ return {
118
+ tools: {
119
+ postcss: (config) => {
120
+ initTailwindConfig();
121
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
122
+ if (Array.isArray(config.postcssOptions.plugins)) {
123
+ config.postcssOptions.plugins.push(tailwindPlugin);
124
+ } else {
125
+ config.postcssOptions.plugins = [tailwindPlugin];
126
+ }
127
+ },
128
+ babel(_, { addPlugins }) {
129
+ if (haveTwinMacro) {
130
+ initTailwindConfig();
131
+ addPlugins([
132
+ [
133
+ require.resolve("babel-plugin-macros"),
134
+ {
135
+ twin: {
136
+ preset: supportCssInJsLibrary,
137
+ config: internalTwConfigPath || tailwindConfig
138
+ }
139
+ }
140
+ ]
141
+ ]);
142
+ }
143
+ }
144
+ }
145
+ };
146
+ },
147
+ beforeBuildTask(config) {
148
+ const modernConfig = api.useResolvedConfigContext();
149
+ const { designSystem } = modernConfig;
150
+ const tailwindConfig = getTailwindConfig(
151
+ tailwindVersion,
152
+ config.style.tailwindCss,
153
+ designSystem,
154
+ {
155
+ pureConfig: {
156
+ content: defaultContent
157
+ }
158
+ }
159
+ );
160
+ const tailwindPlugin = require(tailwindPath)(tailwindConfig);
161
+ if (Array.isArray(config.style.postcss.plugins)) {
162
+ config.style.postcss.plugins.push(tailwindPlugin);
163
+ } else {
164
+ config.style.postcss.plugins = [tailwindPlugin];
165
+ }
166
+ return config;
167
+ }
168
+ };
169
+ })
170
+ });
171
+ export {
172
+ cli_default as default,
173
+ getRandomTwConfigFileName
174
+ };
@@ -0,0 +1,110 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import {
18
+ lazyImport,
19
+ PLUGIN_SCHEMAS,
20
+ createRuntimeExportsUtils
21
+ } from "@modern-js/utils";
22
+ var cli_default = ({ pluginName } = { pluginName: "@modern-js/plugin-tailwindcss" }) => ({
23
+ name: "@modern-js/plugin-design-token",
24
+ setup(api) {
25
+ let pluginsExportsUtils;
26
+ const resolveConfig = lazyImport("tailwindcss/resolveConfig", require);
27
+ const PLUGIN_IDENTIFIER = "designToken";
28
+ const getDesignTokens = (designSystem) => {
29
+ const tailwindcssConfig = {};
30
+ tailwindcssConfig.theme = designSystem ? __spreadValues({}, designSystem) : {};
31
+ if (!designSystem) {
32
+ tailwindcssConfig.presets = [];
33
+ }
34
+ if (designSystem) {
35
+ delete tailwindcssConfig.theme.supportStyledComponents;
36
+ }
37
+ return resolveConfig(tailwindcssConfig).theme || {};
38
+ };
39
+ return {
40
+ config() {
41
+ const appContext = api.useAppContext();
42
+ pluginsExportsUtils = createRuntimeExportsUtils(
43
+ appContext.internalDirectory,
44
+ "plugins"
45
+ );
46
+ return {
47
+ source: {
48
+ alias: {
49
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath()
50
+ }
51
+ },
52
+ tools: {}
53
+ };
54
+ },
55
+ modifyEntryImports({ entrypoint, imports }) {
56
+ var _a, _b;
57
+ const userConfig = api.useResolvedConfigContext();
58
+ const designSystem = (_b = (_a = userConfig.source) == null ? void 0 : _a.designSystem) != null ? _b : {};
59
+ if (typeof designSystem === "object" && designSystem.supportStyledComponents) {
60
+ const designTokens = getDesignTokens(userConfig.source.designSystem);
61
+ imports.push({
62
+ value: "@modern-js/runtime/plugins",
63
+ specifiers: [
64
+ {
65
+ imported: PLUGIN_IDENTIFIER
66
+ }
67
+ ],
68
+ initialize: `
69
+ const designTokens = ${JSON.stringify(designTokens)};
70
+ `
71
+ });
72
+ }
73
+ return {
74
+ entrypoint,
75
+ imports
76
+ };
77
+ },
78
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
79
+ var _a, _b;
80
+ const userConfig = api.useResolvedConfigContext();
81
+ const designSystem = (_b = (_a = userConfig.source) == null ? void 0 : _a.designSystem) != null ? _b : {};
82
+ let useSCThemeProvider = true;
83
+ if (designSystem) {
84
+ useSCThemeProvider = (designSystem == null ? void 0 : designSystem.supportStyledComponents) || false;
85
+ }
86
+ if (typeof designSystem === "object" && designSystem.supportStyledComponents) {
87
+ plugins.push({
88
+ name: PLUGIN_IDENTIFIER,
89
+ options: `{token: designTokens, useStyledComponentsThemeProvider: ${useSCThemeProvider ? "true" : "false"}, useDesignTokenContext: false}`
90
+ });
91
+ }
92
+ return {
93
+ entrypoint,
94
+ plugins
95
+ };
96
+ },
97
+ validateSchema() {
98
+ return PLUGIN_SCHEMAS["@modern-js/plugin-design-token"];
99
+ },
100
+ addRuntimeExports() {
101
+ pluginsExportsUtils.addExport(
102
+ `export { default as designToken } from '${pluginName}/runtime-design-token'`
103
+ );
104
+ }
105
+ };
106
+ }
107
+ });
108
+ export {
109
+ cli_default as default
110
+ };
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "./runtime";
2
+ export * from "./runtime";
3
+ export {
4
+ default2 as default
5
+ };
@@ -0,0 +1,18 @@
1
+ var postcss_plugin_default = ({
2
+ cssVarsHash = {}
3
+ } = {}) => ({
4
+ postcssPlugin: "postcss-replace-css-vars",
5
+ Declaration(decl) {
6
+ if (decl.value && typeof decl.value === "string") {
7
+ decl.value = decl.value.replace(/--\S*/g, (match) => {
8
+ if (cssVarsHash[match]) {
9
+ return cssVarsHash[match];
10
+ }
11
+ return match;
12
+ });
13
+ }
14
+ }
15
+ });
16
+ export {
17
+ postcss_plugin_default as default
18
+ };
@@ -0,0 +1,6 @@
1
+ import designTokenPlugin from "./plugin";
2
+ export * from "./plugin";
3
+ var runtime_default = designTokenPlugin;
4
+ export {
5
+ runtime_default as default
6
+ };
@@ -0,0 +1,66 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { jsx } from "react/jsx-runtime";
18
+ import hoistNonReactStatics from "hoist-non-react-statics";
19
+ import React, { useContext } from "react";
20
+ const DesignTokenContext = React.createContext({});
21
+ const useDesignTokens = () => useContext(DesignTokenContext);
22
+ var plugin_default = (options = {}) => ({
23
+ name: "@modern-js/plugin-design-token",
24
+ setup: () => ({
25
+ hoc({ App }, next) {
26
+ const DesignTokenAppWrapper = (props) => {
27
+ const {
28
+ token = {},
29
+ useStyledComponentsThemeProvider = false,
30
+ useDesignTokenContext = false
31
+ } = options;
32
+ if (useStyledComponentsThemeProvider && useDesignTokenContext) {
33
+ const { ThemeProvider } = require("@modern-js/runtime/styled");
34
+ return /* @__PURE__ */ jsx(ThemeProvider, {
35
+ theme: token,
36
+ children: /* @__PURE__ */ jsx(DesignTokenContext.Provider, {
37
+ value: token,
38
+ children: /* @__PURE__ */ jsx(App, __spreadValues({}, props))
39
+ })
40
+ });
41
+ } else if (useStyledComponentsThemeProvider) {
42
+ const { ThemeProvider } = require("@modern-js/runtime/styled");
43
+ return /* @__PURE__ */ jsx(ThemeProvider, {
44
+ theme: token,
45
+ children: /* @__PURE__ */ jsx(App, __spreadValues({}, props))
46
+ });
47
+ } else if (useDesignTokenContext) {
48
+ return /* @__PURE__ */ jsx(DesignTokenContext.Provider, {
49
+ value: token,
50
+ children: /* @__PURE__ */ jsx(App, __spreadValues({}, props))
51
+ });
52
+ } else {
53
+ return /* @__PURE__ */ jsx(App, __spreadValues({}, props));
54
+ }
55
+ };
56
+ return next({
57
+ App: hoistNonReactStatics(DesignTokenAppWrapper, App)
58
+ });
59
+ }
60
+ })
61
+ });
62
+ export {
63
+ DesignTokenContext,
64
+ plugin_default as default,
65
+ useDesignTokens
66
+ };
@@ -0,0 +1,4 @@
1
+ import { default as default2 } from "./cli";
2
+ export {
3
+ default2 as default
4
+ };
@@ -0,0 +1,45 @@
1
+ import { applyOptionsChain, logger } from "@modern-js/utils";
2
+ import { merge, cloneDeep } from "@modern-js/utils/lodash";
3
+ const checkIfExistNotAllowKeys = (tailwindConfig) => {
4
+ const notAllowExistKeys = ["theme"];
5
+ let notAllowKey = "";
6
+ const ret = Object.keys(tailwindConfig).some(
7
+ (key) => notAllowExistKeys.includes(key) && (notAllowKey = key)
8
+ );
9
+ return [ret, notAllowKey];
10
+ };
11
+ const getPureDesignSystemConfig = (designSystemConfig) => {
12
+ const pureDesignSystemConfig = cloneDeep(designSystemConfig);
13
+ delete pureDesignSystemConfig.supportStyledComponents;
14
+ return pureDesignSystemConfig;
15
+ };
16
+ const getTailwindConfig = (tailwindVersion, tailwindcss, designSystem, option = {}) => {
17
+ const purgeConfig = merge(
18
+ {
19
+ enabled: process.env.NODE_ENV === "production",
20
+ layers: ["utilities"],
21
+ content: []
22
+ },
23
+ option.pureConfig || {}
24
+ );
25
+ const defaultTailwindConfig = tailwindVersion === "3" ? { content: purgeConfig.content } : {
26
+ purge: purgeConfig
27
+ };
28
+ const tailwindConfig = applyOptionsChain(
29
+ defaultTailwindConfig,
30
+ tailwindcss || {}
31
+ );
32
+ const designSystemConfig = getPureDesignSystemConfig(designSystem != null ? designSystem : {});
33
+ const [exist, key] = checkIfExistNotAllowKeys(tailwindConfig);
34
+ if (exist) {
35
+ logger.error(
36
+ `should not exist '${key}' on tools.tailwindcss, please remove it`
37
+ );
38
+ process.exit(0);
39
+ }
40
+ tailwindConfig.theme = designSystemConfig || {};
41
+ return tailwindConfig;
42
+ };
43
+ export {
44
+ getTailwindConfig
45
+ };
File without changes
@@ -0,0 +1,86 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import path from "path";
22
+ import { fs } from "@modern-js/utils";
23
+ const template = (configPath) => `
24
+ function _interopRequireDefault(obj) {
25
+ return obj && obj.__esModule ? obj : { default: obj };
26
+ }
27
+ const modernConfig = _interopRequireDefault(require('${configPath}')).default;
28
+
29
+ const theme =
30
+ modernConfig && modernConfig.source && modernConfig.source.designSystem
31
+ ? modernConfig.source.designSystem
32
+ : {};
33
+ const tailwindcss =
34
+ modernConfig && modernConfig.tools && modernConfig.tools.tailwindcss
35
+ ? modernConfig.tools.tailwindcss
36
+ : {};
37
+
38
+ module.exports = {
39
+ theme,
40
+ ...tailwindcss,
41
+ };
42
+ `;
43
+ const TWIN_MACRO_NAME = "twin.macro";
44
+ const checkTwinMacroExist = (appDirectory) => __async(void 0, null, function* () {
45
+ const packageJson = (yield fs.readJSON(path.join(appDirectory, "package.json"), {
46
+ throws: false
47
+ })) || {};
48
+ return Boolean(
49
+ typeof packageJson.dependencies === "object" && packageJson.dependencies[TWIN_MACRO_NAME] || typeof packageJson.devDependencies === "object" && packageJson.devDependencies[TWIN_MACRO_NAME]
50
+ );
51
+ });
52
+ const getTwinMacroMajorVersion = (appDirectory) => {
53
+ try {
54
+ const pkgJsonPath = require.resolve(`${TWIN_MACRO_NAME}/package.json`, {
55
+ paths: [appDirectory]
56
+ });
57
+ const { version } = require(pkgJsonPath);
58
+ return Number(version.split(".")[0]);
59
+ } catch (err) {
60
+ return null;
61
+ }
62
+ };
63
+ function getTailwindPath(appDirectory) {
64
+ try {
65
+ return require.resolve("tailwindcss", { paths: [appDirectory, __dirname] });
66
+ } catch (err) {
67
+ return "tailwindcss";
68
+ }
69
+ }
70
+ function getTailwindVersion(appDirectory) {
71
+ try {
72
+ const packageJsonPath = require.resolve("tailwindcss/package.json", {
73
+ paths: [appDirectory, __dirname]
74
+ });
75
+ return require(packageJsonPath).version.split(".")[0];
76
+ } catch (err) {
77
+ return "3";
78
+ }
79
+ }
80
+ export {
81
+ checkTwinMacroExist,
82
+ getTailwindPath,
83
+ getTailwindVersion,
84
+ getTwinMacroMajorVersion,
85
+ template
86
+ };