@weapp-tailwindcss/merge 1.3.0-alpha.0 → 2.0.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.
@@ -0,0 +1,71 @@
1
+ // src/core/transformers.ts
2
+ import {
3
+ escape as escapeSelectors,
4
+ MappingChars2String,
5
+ unescape as unescapeSelectors
6
+ } from "@weapp-core/escape";
7
+ var identity = (value) => value;
8
+ function isConfig(value) {
9
+ return typeof value === "object" && value !== null;
10
+ }
11
+ function mergeWithDefaultMap(map) {
12
+ if (!map) {
13
+ return void 0;
14
+ }
15
+ if (map === MappingChars2String) {
16
+ return MappingChars2String;
17
+ }
18
+ return {
19
+ ...MappingChars2String,
20
+ ...map
21
+ };
22
+ }
23
+ function resolveSharedMap(options) {
24
+ const { escape, unescape } = options ?? {};
25
+ if (isConfig(escape) && escape.map) {
26
+ return mergeWithDefaultMap(escape.map);
27
+ }
28
+ if (isConfig(unescape) && unescape.map) {
29
+ return mergeWithDefaultMap(unescape.map);
30
+ }
31
+ return MappingChars2String;
32
+ }
33
+ function resolveTransformers(options) {
34
+ const sharedMap = resolveSharedMap(options);
35
+ const escapeConfig = options?.escape;
36
+ const unescapeConfig = options?.unescape;
37
+ const escapeEnabled = escapeConfig !== false;
38
+ const unescapeEnabled = unescapeConfig !== false;
39
+ let escapeOptions;
40
+ if (escapeEnabled) {
41
+ if (isConfig(escapeConfig)) {
42
+ escapeOptions = {
43
+ ...escapeConfig,
44
+ map: mergeWithDefaultMap(escapeConfig.map) ?? sharedMap
45
+ };
46
+ } else {
47
+ escapeOptions = { map: sharedMap };
48
+ }
49
+ }
50
+ let unescapeOptions;
51
+ if (unescapeEnabled) {
52
+ if (isConfig(unescapeConfig)) {
53
+ unescapeOptions = {
54
+ ...unescapeConfig,
55
+ map: mergeWithDefaultMap(unescapeConfig.map) ?? sharedMap
56
+ };
57
+ } else {
58
+ unescapeOptions = { map: sharedMap };
59
+ }
60
+ }
61
+ const escapeFn = escapeEnabled ? (value) => escapeSelectors(value, escapeOptions) : identity;
62
+ const unescapeFn = unescapeEnabled ? (value) => unescapeSelectors(value, unescapeOptions) : identity;
63
+ return {
64
+ escape: escapeFn,
65
+ unescape: unescapeFn
66
+ };
67
+ }
68
+
69
+ export {
70
+ resolveTransformers
71
+ };
@@ -0,0 +1,53 @@
1
+ import {
2
+ resolveTransformers
3
+ } from "./chunk-2KHGHDND.js";
4
+
5
+ // ../weapp-tailwindcss/dist/chunk-VSRDBMDB.mjs
6
+ import { escape, MappingChars2String } from "@weapp-core/escape";
7
+
8
+ // ../weapp-tailwindcss/dist/escape.mjs
9
+ import { isAllowedClassName } from "@weapp-core/escape";
10
+ var weappTwIgnore = String.raw;
11
+
12
+ // src/core/create-runtime.ts
13
+ import { clsx } from "clsx";
14
+ function wrapClassAggregator(fn, transformers) {
15
+ return (...inputs) => {
16
+ const normalized = transformers.unescape(clsx(...inputs));
17
+ return transformers.escape(fn(normalized));
18
+ };
19
+ }
20
+ function wrapFactory(factory, transformers) {
21
+ return (...args) => {
22
+ const runtime = factory(...args);
23
+ return wrapClassAggregator(runtime, transformers);
24
+ };
25
+ }
26
+ function createRuntimeFactory(options) {
27
+ const {
28
+ version,
29
+ twMerge: _twMerge,
30
+ twJoin: _twJoin,
31
+ extendTailwindMerge: _extendTailwindMerge,
32
+ createTailwindMerge: _createTailwindMerge
33
+ } = options;
34
+ return function createRuntime(createOptions) {
35
+ const transformers = resolveTransformers(createOptions);
36
+ const twMerge = wrapClassAggregator(_twMerge, transformers);
37
+ const twJoin = wrapClassAggregator(_twJoin, transformers);
38
+ const extendTailwindMerge = wrapFactory(_extendTailwindMerge, transformers);
39
+ const createTailwindMerge = wrapFactory(_createTailwindMerge, transformers);
40
+ return {
41
+ version,
42
+ twMerge,
43
+ twJoin,
44
+ extendTailwindMerge,
45
+ createTailwindMerge
46
+ };
47
+ };
48
+ }
49
+
50
+ export {
51
+ weappTwIgnore,
52
+ createRuntimeFactory
53
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createRuntimeFactory
3
- } from "./chunk-NNOJ7CWV.js";
3
+ } from "./chunk-2VBLBSOS.js";
4
4
 
5
5
  // src/v4.ts
6
6
  import {
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkJONLHXMVcjs = require('./chunk-JONLHXMV.cjs');
3
+ var _chunkV4RUVSPVcjs = require('./chunk-V4RUVSPV.cjs');
4
4
 
5
5
  // src/v4.ts
6
6
 
@@ -11,7 +11,7 @@ var _chunkJONLHXMVcjs = require('./chunk-JONLHXMV.cjs');
11
11
 
12
12
 
13
13
  var _tailwindmerge = require('tailwind-merge');
14
- var create = _chunkJONLHXMVcjs.createRuntimeFactory.call(void 0, {
14
+ var create = _chunkV4RUVSPVcjs.createRuntimeFactory.call(void 0, {
15
15
  createTailwindMerge: _tailwindmerge.createTailwindMerge,
16
16
  extendTailwindMerge: _tailwindmerge.extendTailwindMerge,
17
17
  twJoin: _tailwindmerge.twJoin,
@@ -0,0 +1,71 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/core/transformers.ts
2
+
3
+
4
+
5
+
6
+ var _escape = require('@weapp-core/escape');
7
+ var identity = (value) => value;
8
+ function isConfig(value) {
9
+ return typeof value === "object" && value !== null;
10
+ }
11
+ function mergeWithDefaultMap(map) {
12
+ if (!map) {
13
+ return void 0;
14
+ }
15
+ if (map === _escape.MappingChars2String) {
16
+ return _escape.MappingChars2String;
17
+ }
18
+ return {
19
+ ..._escape.MappingChars2String,
20
+ ...map
21
+ };
22
+ }
23
+ function resolveSharedMap(options) {
24
+ const { escape, unescape } = _nullishCoalesce(options, () => ( {}));
25
+ if (isConfig(escape) && escape.map) {
26
+ return mergeWithDefaultMap(escape.map);
27
+ }
28
+ if (isConfig(unescape) && unescape.map) {
29
+ return mergeWithDefaultMap(unescape.map);
30
+ }
31
+ return _escape.MappingChars2String;
32
+ }
33
+ function resolveTransformers(options) {
34
+ const sharedMap = resolveSharedMap(options);
35
+ const escapeConfig = _optionalChain([options, 'optionalAccess', _ => _.escape]);
36
+ const unescapeConfig = _optionalChain([options, 'optionalAccess', _2 => _2.unescape]);
37
+ const escapeEnabled = escapeConfig !== false;
38
+ const unescapeEnabled = unescapeConfig !== false;
39
+ let escapeOptions;
40
+ if (escapeEnabled) {
41
+ if (isConfig(escapeConfig)) {
42
+ escapeOptions = {
43
+ ...escapeConfig,
44
+ map: _nullishCoalesce(mergeWithDefaultMap(escapeConfig.map), () => ( sharedMap))
45
+ };
46
+ } else {
47
+ escapeOptions = { map: sharedMap };
48
+ }
49
+ }
50
+ let unescapeOptions;
51
+ if (unescapeEnabled) {
52
+ if (isConfig(unescapeConfig)) {
53
+ unescapeOptions = {
54
+ ...unescapeConfig,
55
+ map: _nullishCoalesce(mergeWithDefaultMap(unescapeConfig.map), () => ( sharedMap))
56
+ };
57
+ } else {
58
+ unescapeOptions = { map: sharedMap };
59
+ }
60
+ }
61
+ const escapeFn = escapeEnabled ? (value) => _escape.escape.call(void 0, value, escapeOptions) : identity;
62
+ const unescapeFn = unescapeEnabled ? (value) => _escape.unescape.call(void 0, value, unescapeOptions) : identity;
63
+ return {
64
+ escape: escapeFn,
65
+ unescape: unescapeFn
66
+ };
67
+ }
68
+
69
+
70
+
71
+ exports.resolveTransformers = resolveTransformers;
@@ -0,0 +1,53 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkPZ4IYNKUcjs = require('./chunk-PZ4IYNKU.cjs');
4
+
5
+ // ../weapp-tailwindcss/dist/chunk-VSRDBMDB.mjs
6
+ var _escape = require('@weapp-core/escape');
7
+
8
+ // ../weapp-tailwindcss/dist/escape.mjs
9
+
10
+ var weappTwIgnore = String.raw;
11
+
12
+ // src/core/create-runtime.ts
13
+ var _clsx = require('clsx');
14
+ function wrapClassAggregator(fn, transformers) {
15
+ return (...inputs) => {
16
+ const normalized = transformers.unescape(_clsx.clsx.call(void 0, ...inputs));
17
+ return transformers.escape(fn(normalized));
18
+ };
19
+ }
20
+ function wrapFactory(factory, transformers) {
21
+ return (...args) => {
22
+ const runtime = factory(...args);
23
+ return wrapClassAggregator(runtime, transformers);
24
+ };
25
+ }
26
+ function createRuntimeFactory(options) {
27
+ const {
28
+ version,
29
+ twMerge: _twMerge,
30
+ twJoin: _twJoin,
31
+ extendTailwindMerge: _extendTailwindMerge,
32
+ createTailwindMerge: _createTailwindMerge
33
+ } = options;
34
+ return function createRuntime(createOptions) {
35
+ const transformers = _chunkPZ4IYNKUcjs.resolveTransformers.call(void 0, createOptions);
36
+ const twMerge = wrapClassAggregator(_twMerge, transformers);
37
+ const twJoin = wrapClassAggregator(_twJoin, transformers);
38
+ const extendTailwindMerge = wrapFactory(_extendTailwindMerge, transformers);
39
+ const createTailwindMerge = wrapFactory(_createTailwindMerge, transformers);
40
+ return {
41
+ version,
42
+ twMerge,
43
+ twJoin,
44
+ extendTailwindMerge,
45
+ createTailwindMerge
46
+ };
47
+ };
48
+ }
49
+
50
+
51
+
52
+
53
+ exports.weappTwIgnore = weappTwIgnore; exports.createRuntimeFactory = createRuntimeFactory;
package/dist/cva.cjs CHANGED
@@ -1,15 +1,17 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkBWF73VRWcjs = require('./chunk-BWF73VRW.cjs');
3
+ var _chunkPZ4IYNKUcjs = require('./chunk-PZ4IYNKU.cjs');
4
4
 
5
5
  // src/cva.ts
6
6
  var _classvarianceauthority = require('class-variance-authority');
7
7
  function create(options) {
8
- const escapeFn = _chunkBWF73VRWcjs.resolveEscape.call(void 0, options);
8
+ const transformers = _chunkPZ4IYNKUcjs.resolveTransformers.call(void 0, options);
9
9
  function cva2(base, config) {
10
10
  const fn = _classvarianceauthority.cva.call(void 0, base, config);
11
11
  return (...props) => {
12
- return escapeFn(fn(...props));
12
+ const value = fn(...props);
13
+ const normalized = transformers.unescape(value);
14
+ return transformers.escape(normalized);
13
15
  };
14
16
  }
15
17
  return {
package/dist/cva.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as CLSX from 'clsx';
2
- import { C as CreateOptions } from './types-NMbxxvgq.cjs';
2
+ import { C as CreateOptions } from './types-DSXe0vN9.cjs';
3
+ import '@weapp-core/escape';
3
4
 
4
5
  type ClassValue = CLSX.ClassValue
5
6
  type ClassProp = {
package/dist/cva.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as CLSX from 'clsx';
2
- import { C as CreateOptions } from './types-NMbxxvgq.js';
2
+ import { C as CreateOptions } from './types-DSXe0vN9.js';
3
+ import '@weapp-core/escape';
3
4
 
4
5
  type ClassValue = CLSX.ClassValue
5
6
  type ClassProp = {
package/dist/cva.js CHANGED
@@ -1,15 +1,17 @@
1
1
  import {
2
- resolveEscape
3
- } from "./chunk-4KECYPIX.js";
2
+ resolveTransformers
3
+ } from "./chunk-2KHGHDND.js";
4
4
 
5
5
  // src/cva.ts
6
6
  import { cva as _cva } from "class-variance-authority";
7
7
  function create(options) {
8
- const escapeFn = resolveEscape(options);
8
+ const transformers = resolveTransformers(options);
9
9
  function cva2(base, config) {
10
10
  const fn = _cva(base, config);
11
11
  return (...props) => {
12
- return escapeFn(fn(...props));
12
+ const value = fn(...props);
13
+ const normalized = transformers.unescape(value);
14
+ return transformers.escape(normalized);
13
15
  };
14
16
  }
15
17
  return {
package/dist/index.cjs CHANGED
@@ -7,11 +7,11 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkQKJSGQ4Hcjs = require('./chunk-QKJSGQ4H.cjs');
11
- require('./chunk-JONLHXMV.cjs');
10
+ var _chunkEJHUA3F5cjs = require('./chunk-EJHUA3F5.cjs');
12
11
 
13
12
 
14
- var _chunkBWF73VRWcjs = require('./chunk-BWF73VRW.cjs');
13
+ var _chunkV4RUVSPVcjs = require('./chunk-V4RUVSPV.cjs');
14
+ require('./chunk-PZ4IYNKU.cjs');
15
15
 
16
16
 
17
17
 
@@ -22,4 +22,4 @@ var _chunkBWF73VRWcjs = require('./chunk-BWF73VRW.cjs');
22
22
 
23
23
 
24
24
 
25
- exports.create = _chunkQKJSGQ4Hcjs.create; exports.createTailwindMerge = _chunkQKJSGQ4Hcjs.createTailwindMerge; exports.extendTailwindMerge = _chunkQKJSGQ4Hcjs.extendTailwindMerge; exports.getDefaultConfig = _chunkQKJSGQ4Hcjs.getDefaultConfig; exports.mergeConfigs = _chunkQKJSGQ4Hcjs.mergeConfigs; exports.tailwindMergeVersion = _chunkQKJSGQ4Hcjs.tailwindMergeVersion; exports.twJoin = _chunkQKJSGQ4Hcjs.twJoin; exports.twMerge = _chunkQKJSGQ4Hcjs.twMerge; exports.weappTwIgnore = _chunkBWF73VRWcjs.weappTwIgnore;
25
+ exports.create = _chunkEJHUA3F5cjs.create; exports.createTailwindMerge = _chunkEJHUA3F5cjs.createTailwindMerge; exports.extendTailwindMerge = _chunkEJHUA3F5cjs.extendTailwindMerge; exports.getDefaultConfig = _chunkEJHUA3F5cjs.getDefaultConfig; exports.mergeConfigs = _chunkEJHUA3F5cjs.mergeConfigs; exports.tailwindMergeVersion = _chunkEJHUA3F5cjs.tailwindMergeVersion; exports.twJoin = _chunkEJHUA3F5cjs.twJoin; exports.twMerge = _chunkEJHUA3F5cjs.twMerge; exports.weappTwIgnore = _chunkV4RUVSPVcjs.weappTwIgnore;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { create, createTailwindMerge, extendTailwindMerge, tailwindMergeVersion, twJoin, twMerge } from './v4.cjs';
2
+ export { C as CreateOptions, E as EscapeConfig, U as UnescapeConfig } from './types-DSXe0vN9.cjs';
2
3
  export { getDefaultConfig, mergeConfigs } from 'tailwind-merge';
3
4
  export { weappTwIgnore } from 'weapp-tailwindcss/escape';
4
5
  export { ClassValue } from 'clsx';
5
- import './types-NMbxxvgq.cjs';
6
+ import '@weapp-core/escape';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { create, createTailwindMerge, extendTailwindMerge, tailwindMergeVersion, twJoin, twMerge } from './v4.js';
2
+ export { C as CreateOptions, E as EscapeConfig, U as UnescapeConfig } from './types-DSXe0vN9.js';
2
3
  export { getDefaultConfig, mergeConfigs } from 'tailwind-merge';
3
4
  export { weappTwIgnore } from 'weapp-tailwindcss/escape';
4
5
  export { ClassValue } from 'clsx';
5
- import './types-NMbxxvgq.js';
6
+ import '@weapp-core/escape';
package/dist/index.js CHANGED
@@ -7,11 +7,11 @@ import {
7
7
  tailwindMergeVersion,
8
8
  twJoin,
9
9
  twMerge
10
- } from "./chunk-HLKKHLS5.js";
11
- import "./chunk-NNOJ7CWV.js";
10
+ } from "./chunk-7WDGWM6R.js";
12
11
  import {
13
12
  weappTwIgnore
14
- } from "./chunk-4KECYPIX.js";
13
+ } from "./chunk-2VBLBSOS.js";
14
+ import "./chunk-2KHGHDND.js";
15
15
  export {
16
16
  create,
17
17
  createTailwindMerge,
@@ -1,32 +1,202 @@
1
- "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/postinstall.ts
1
+ "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/postinstall.ts
2
2
  var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
3
3
  var _path = require('path'); var _path2 = _interopRequireDefault(_path);
4
+ var _process = require('process'); var _process2 = _interopRequireDefault(_process);
5
+ var _url = require('url');
4
6
  var _localpkg = require('local-pkg');
5
7
  var _satisfiesjs = require('semver/functions/satisfies.js'); var _satisfiesjs2 = _interopRequireDefault(_satisfiesjs);
8
+ var LOG_PREFIX = "[weapp-tailwindcss/merge]";
9
+ var FALLBACK_VARIANT = "v4";
10
+ var EXTENSIONS = ["cjs", "d.cts", "d.ts", "js"];
11
+ function printLine(message, stream) {
12
+ stream.write(`${LOG_PREFIX} ${message}
13
+ `);
14
+ }
15
+ function info(message) {
16
+ printLine(message, _process2.default.stdout);
17
+ }
18
+ function warn(message) {
19
+ printLine(message, _process2.default.stderr);
20
+ }
21
+ function error(message) {
22
+ printLine(message, _process2.default.stderr);
23
+ }
24
+ function describeVariant(variant) {
25
+ if (variant === "v3") {
26
+ return "tailwind-merge@2 runtime (Tailwind CSS v3)";
27
+ }
28
+ return "tailwind-merge@3 runtime (Tailwind CSS v4)";
29
+ }
30
+ function parseBooleanEnv(name) {
31
+ const value = _process2.default.env[name];
32
+ if (!value) {
33
+ return false;
34
+ }
35
+ return ["1", "true", "yes", "on"].includes(value.trim().toLowerCase());
36
+ }
37
+ function parseVariantEnv(value) {
38
+ if (!value) {
39
+ return void 0;
40
+ }
41
+ const normalized = value.trim().toLowerCase().replace(/^v/, "");
42
+ if (normalized === "3") {
43
+ return "v3";
44
+ }
45
+ if (normalized === "4") {
46
+ return "v4";
47
+ }
48
+ warn(`Unknown runtime variant "${value}". Supported values are "v3" and "v4".`);
49
+ return void 0;
50
+ }
51
+ function readEnvConfig() {
52
+ const forcedVariantEnv = _nullishCoalesce(_process2.default.env.WEAPP_TW_MERGE_TARGET_VERSION, () => ( _process2.default.env.WEAPP_TW_MERGE_FORCE_VERSION));
53
+ const forcedVariant = parseVariantEnv(forcedVariantEnv);
54
+ return {
55
+ forcedVariant,
56
+ disableFallback: parseBooleanEnv("WEAPP_TW_MERGE_DISABLE_FALLBACK") || parseBooleanEnv("WEAPP_TW_MERGE_NO_FALLBACK"),
57
+ strict: parseBooleanEnv("WEAPP_TW_MERGE_STRICT")
58
+ };
59
+ }
60
+ function unique(values) {
61
+ return Array.from(new Set(values.filter((value) => value != null)));
62
+ }
63
+ function detectTailwindInfo() {
64
+ const searchRoots = unique([
65
+ _process2.default.env.WEAPP_TW_MERGE_RESOLVE_ROOT,
66
+ _process2.default.env.INIT_CWD,
67
+ _process2.default.env.npm_config_local_prefix,
68
+ _process2.default.env.PWD,
69
+ _process2.default.cwd()
70
+ ]);
71
+ for (const root of searchRoots) {
72
+ try {
73
+ const info2 = _localpkg.getPackageInfoSync.call(void 0, "tailwindcss", { paths: [root] });
74
+ if (_optionalChain([info2, 'optionalAccess', _ => _.version])) {
75
+ return {
76
+ version: info2.version,
77
+ rootPath: info2.rootPath
78
+ };
79
+ }
80
+ } catch (e) {
81
+ }
82
+ }
83
+ try {
84
+ const info2 = _localpkg.getPackageInfoSync.call(void 0, "tailwindcss");
85
+ if (_optionalChain([info2, 'optionalAccess', _2 => _2.version])) {
86
+ return {
87
+ version: info2.version,
88
+ rootPath: info2.rootPath
89
+ };
90
+ }
91
+ } catch (e2) {
92
+ }
93
+ return void 0;
94
+ }
95
+ function resolveVariant(env, tailwindInfo) {
96
+ if (env.forcedVariant) {
97
+ return {
98
+ variant: env.forcedVariant,
99
+ reason: "forced by environment",
100
+ detected: true
101
+ };
102
+ }
103
+ if (tailwindInfo) {
104
+ const target = _satisfiesjs2.default.call(void 0, tailwindInfo.version, "^4.0.0-0") ? "v4" : "v3";
105
+ return {
106
+ variant: target,
107
+ reason: `tailwindcss@${tailwindInfo.version}`,
108
+ detected: true
109
+ };
110
+ }
111
+ return {
112
+ reason: "tailwindcss not found",
113
+ detected: false
114
+ };
115
+ }
116
+ function readFile(pathname) {
117
+ return _fs2.default.readFileSync(pathname);
118
+ }
119
+ function copyFileIfChanged(source, target) {
120
+ const sourceBuffer = readFile(source);
121
+ if (_fs2.default.existsSync(target)) {
122
+ try {
123
+ const targetBuffer = readFile(target);
124
+ if (targetBuffer.equals(sourceBuffer)) {
125
+ return false;
126
+ }
127
+ } catch (e3) {
128
+ }
129
+ }
130
+ _fs2.default.writeFileSync(target, sourceBuffer);
131
+ return true;
132
+ }
133
+ function ensureVariant(distDir, variant) {
134
+ const changedFiles = [];
135
+ for (const ext of EXTENSIONS) {
136
+ const source = _path2.default.resolve(distDir, `${variant}.${ext}`);
137
+ if (!_fs2.default.existsSync(source)) {
138
+ throw new Error(`Missing source file ${_path2.default.relative(_process2.default.cwd(), source)}`);
139
+ }
140
+ const target = _path2.default.resolve(distDir, `index.${ext}`);
141
+ if (copyFileIfChanged(source, target)) {
142
+ changedFiles.push(_path2.default.basename(target));
143
+ }
144
+ }
145
+ return {
146
+ changedFiles
147
+ };
148
+ }
6
149
  function main() {
7
- const distDir = _path2.default.resolve(__dirname, "../dist");
150
+ const distDir = _url.fileURLToPath.call(void 0, new URL("../dist/", import.meta.url));
8
151
  if (!_fs2.default.existsSync(distDir)) {
152
+ warn("dist directory not found. Skipping runtime switch.");
9
153
  return;
10
154
  }
11
- const packageInfo = _localpkg.getPackageInfoSync.call(void 0, "tailwindcss");
12
- if (!packageInfo) {
13
- console.warn("tailwindcss not found in the project. Skipping swicth version of tailwind-merge.");
14
- return;
155
+ const envConfig = readEnvConfig();
156
+ const tailwindInfo = detectTailwindInfo();
157
+ const resolution = resolveVariant(envConfig, tailwindInfo);
158
+ let targetVariant;
159
+ if (!resolution.variant) {
160
+ warn(`${resolution.reason}.`);
161
+ if (envConfig.disableFallback) {
162
+ warn("Fallback is disabled. Default entry will keep the bundled runtime.");
163
+ warn('You can import "@weapp-tailwindcss/merge/v3" or "@weapp-tailwindcss/merge/v4" manually when needed.');
164
+ return;
165
+ }
166
+ targetVariant = FALLBACK_VARIANT;
167
+ info(`Fallback to ${describeVariant(targetVariant)}.`);
168
+ } else {
169
+ targetVariant = resolution.variant;
170
+ info(`Using ${describeVariant(targetVariant)} (${resolution.reason}).`);
171
+ }
172
+ try {
173
+ const { changedFiles } = ensureVariant(distDir, targetVariant);
174
+ if (changedFiles.length > 0) {
175
+ info(`Updated entry files: ${changedFiles.join(", ")}`);
176
+ } else {
177
+ info("Entry files already match the requested runtime.");
178
+ }
179
+ } catch (err) {
180
+ const message = err instanceof Error ? err.message : String(err);
181
+ error(`Failed to switch runtime to ${targetVariant}. ${message}`);
182
+ if (envConfig.disableFallback || targetVariant === FALLBACK_VARIANT) {
183
+ warn("Leaving existing files untouched. Import a specific runtime manually if required.");
184
+ } else {
185
+ try {
186
+ const { changedFiles } = ensureVariant(distDir, FALLBACK_VARIANT);
187
+ if (changedFiles.length > 0) {
188
+ info(`Reverted to fallback runtime (${describeVariant(FALLBACK_VARIANT)}).`);
189
+ } else {
190
+ info("Fallback runtime was already in use. No changes applied.");
191
+ }
192
+ } catch (fallbackErr) {
193
+ const fallbackMessage = fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
194
+ error(`Failed to apply fallback runtime. ${fallbackMessage}`);
195
+ }
196
+ }
197
+ if (envConfig.strict) {
198
+ _process2.default.exitCode = _nullishCoalesce(_process2.default.exitCode, () => ( 1));
199
+ }
15
200
  }
16
- const tailwindVersion = packageInfo.version;
17
- let targetVersion = 3;
18
- if (_satisfiesjs2.default.call(void 0, tailwindVersion, "^4.0.0")) {
19
- targetVersion = 4;
20
- }
21
- console.log(`tailwindcss version: ${tailwindVersion}`);
22
- console.log(`Switch version of tailwind-merge to v${targetVersion - 1}.`);
23
- for (const ext of ["cjs", "d.cts", "d.ts", "js"]) {
24
- const file = `v${targetVersion}.${ext}`;
25
- _fs2.default.copyFileSync(
26
- _path2.default.resolve(distDir, file),
27
- _path2.default.resolve(distDir, `index.${ext}`)
28
- );
29
- }
30
- console.log("Switch version of tailwind-merge success.");
31
201
  }
32
202
  main();
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }