@weapp-tailwindcss/merge 2.0.1 → 2.1.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/{chunk-7WDGWM6R.js → chunk-2YJESRDS.js} +5 -4
- package/dist/chunk-H62OPMAL.cjs +39 -0
- package/dist/index.cjs +2 -5
- package/dist/index.d.cts +1 -4
- package/dist/index.d.ts +1 -4
- package/dist/index.js +2 -5
- package/dist/v4.cjs +2 -5
- package/dist/v4.d.cts +14 -17
- package/dist/v4.d.ts +14 -17
- package/dist/v4.js +2 -5
- package/package.json +17 -37
- package/dist/chunk-2KHGHDND.js +0 -71
- package/dist/chunk-2VBLBSOS.js +0 -53
- package/dist/chunk-EJHUA3F5.cjs +0 -38
- package/dist/chunk-PZ4IYNKU.cjs +0 -71
- package/dist/chunk-V4RUVSPV.cjs +0 -53
- package/dist/cva.cjs +0 -25
- package/dist/cva.d.cts +0 -37
- package/dist/cva.d.ts +0 -37
- package/dist/cva.js +0 -25
- package/dist/postinstall.cjs +0 -209
- package/dist/postinstall.d.cts +0 -2
- package/dist/postinstall.d.ts +0 -2
- package/dist/postinstall.js +0 -209
- package/dist/types-DSXe0vN9.d.cts +0 -15
- package/dist/types-DSXe0vN9.d.ts +0 -15
- package/dist/v3.cjs +0 -40
- package/dist/v3.d.cts +0 -23
- package/dist/v3.d.ts +0 -23
- package/dist/v3.js +0 -40
- package/dist/variants.cjs +0 -76
- package/dist/variants.d.cts +0 -19
- package/dist/variants.d.ts +0 -19
- package/dist/variants.js +0 -76
- package/scripts/postinstall.mjs +0 -83
package/dist/cva.d.cts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as CLSX from 'clsx';
|
|
2
|
-
import { C as CreateOptions } from './types-DSXe0vN9.cjs';
|
|
3
|
-
import '@weapp-core/escape';
|
|
4
|
-
|
|
5
|
-
type ClassValue = CLSX.ClassValue
|
|
6
|
-
type ClassProp = {
|
|
7
|
-
class: ClassValue
|
|
8
|
-
className?: never
|
|
9
|
-
} | {
|
|
10
|
-
class?: never
|
|
11
|
-
className: ClassValue
|
|
12
|
-
} | {
|
|
13
|
-
class?: never
|
|
14
|
-
className?: never
|
|
15
|
-
}
|
|
16
|
-
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
|
|
17
|
-
|
|
18
|
-
type ConfigSchema = Record<string, Record<string, ClassValue>>
|
|
19
|
-
type ConfigVariants<T extends ConfigSchema> = {
|
|
20
|
-
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
|
|
21
|
-
}
|
|
22
|
-
type ConfigVariantsMulti<T extends ConfigSchema> = {
|
|
23
|
-
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined;
|
|
24
|
-
}
|
|
25
|
-
type Config<T> = T extends ConfigSchema ? {
|
|
26
|
-
variants?: T
|
|
27
|
-
defaultVariants?: ConfigVariants<T>
|
|
28
|
-
compoundVariants?: (T extends ConfigSchema ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp : ClassProp)[]
|
|
29
|
-
} : never
|
|
30
|
-
type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp
|
|
31
|
-
|
|
32
|
-
declare function create(options?: CreateOptions): {
|
|
33
|
-
cva: <T>(base?: ClassValue, config?: Config<T>) => (props?: Props<T> | undefined) => string;
|
|
34
|
-
};
|
|
35
|
-
declare const cva: <T>(base?: ClassValue, config?: Config<T>) => (props?: Props<T> | undefined) => string;
|
|
36
|
-
|
|
37
|
-
export { create, cva };
|
package/dist/cva.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as CLSX from 'clsx';
|
|
2
|
-
import { C as CreateOptions } from './types-DSXe0vN9.js';
|
|
3
|
-
import '@weapp-core/escape';
|
|
4
|
-
|
|
5
|
-
type ClassValue = CLSX.ClassValue
|
|
6
|
-
type ClassProp = {
|
|
7
|
-
class: ClassValue
|
|
8
|
-
className?: never
|
|
9
|
-
} | {
|
|
10
|
-
class?: never
|
|
11
|
-
className: ClassValue
|
|
12
|
-
} | {
|
|
13
|
-
class?: never
|
|
14
|
-
className?: never
|
|
15
|
-
}
|
|
16
|
-
type StringToBoolean<T> = T extends 'true' | 'false' ? boolean : T
|
|
17
|
-
|
|
18
|
-
type ConfigSchema = Record<string, Record<string, ClassValue>>
|
|
19
|
-
type ConfigVariants<T extends ConfigSchema> = {
|
|
20
|
-
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | null | undefined;
|
|
21
|
-
}
|
|
22
|
-
type ConfigVariantsMulti<T extends ConfigSchema> = {
|
|
23
|
-
[Variant in keyof T]?: StringToBoolean<keyof T[Variant]> | StringToBoolean<keyof T[Variant]>[] | undefined;
|
|
24
|
-
}
|
|
25
|
-
type Config<T> = T extends ConfigSchema ? {
|
|
26
|
-
variants?: T
|
|
27
|
-
defaultVariants?: ConfigVariants<T>
|
|
28
|
-
compoundVariants?: (T extends ConfigSchema ? (ConfigVariants<T> | ConfigVariantsMulti<T>) & ClassProp : ClassProp)[]
|
|
29
|
-
} : never
|
|
30
|
-
type Props<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp
|
|
31
|
-
|
|
32
|
-
declare function create(options?: CreateOptions): {
|
|
33
|
-
cva: <T>(base?: ClassValue, config?: Config<T>) => (props?: Props<T> | undefined) => string;
|
|
34
|
-
};
|
|
35
|
-
declare const cva: <T>(base?: ClassValue, config?: Config<T>) => (props?: Props<T> | undefined) => string;
|
|
36
|
-
|
|
37
|
-
export { create, cva };
|
package/dist/cva.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
resolveTransformers
|
|
3
|
-
} from "./chunk-2KHGHDND.js";
|
|
4
|
-
|
|
5
|
-
// src/cva.ts
|
|
6
|
-
import { cva as _cva } from "class-variance-authority";
|
|
7
|
-
function create(options) {
|
|
8
|
-
const transformers = resolveTransformers(options);
|
|
9
|
-
function cva2(base, config) {
|
|
10
|
-
const fn = _cva(base, config);
|
|
11
|
-
return (...props) => {
|
|
12
|
-
const value = fn(...props);
|
|
13
|
-
const normalized = transformers.unescape(value);
|
|
14
|
-
return transformers.escape(normalized);
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return {
|
|
18
|
-
cva: cva2
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
var { cva } = create();
|
|
22
|
-
export {
|
|
23
|
-
create,
|
|
24
|
-
cva
|
|
25
|
-
};
|
package/dist/postinstall.cjs
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
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
|
-
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
3
|
-
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
4
|
-
var _process = require('process'); var _process2 = _interopRequireDefault(_process);
|
|
5
|
-
var _url = require('url');
|
|
6
|
-
var _localpkg = require('local-pkg');
|
|
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
|
-
}
|
|
149
|
-
function main() {
|
|
150
|
-
const resolveDistDir = () => {
|
|
151
|
-
if (typeof __dirname === "string") {
|
|
152
|
-
return _path2.default.resolve(__dirname, "../dist");
|
|
153
|
-
}
|
|
154
|
-
const getImportMetaUrl = new Function("return import.meta.url");
|
|
155
|
-
return _url.fileURLToPath.call(void 0, new URL("../dist/", getImportMetaUrl()));
|
|
156
|
-
};
|
|
157
|
-
const distDir = resolveDistDir();
|
|
158
|
-
if (!_fs2.default.existsSync(distDir)) {
|
|
159
|
-
warn("dist directory not found. Skipping runtime switch.");
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const envConfig = readEnvConfig();
|
|
163
|
-
const tailwindInfo = detectTailwindInfo();
|
|
164
|
-
const resolution = resolveVariant(envConfig, tailwindInfo);
|
|
165
|
-
let targetVariant;
|
|
166
|
-
if (!resolution.variant) {
|
|
167
|
-
warn(`${resolution.reason}.`);
|
|
168
|
-
if (envConfig.disableFallback) {
|
|
169
|
-
warn("Fallback is disabled. Default entry will keep the bundled runtime.");
|
|
170
|
-
warn('You can import "@weapp-tailwindcss/merge/v3" or "@weapp-tailwindcss/merge/v4" manually when needed.');
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
targetVariant = FALLBACK_VARIANT;
|
|
174
|
-
info(`Fallback to ${describeVariant(targetVariant)}.`);
|
|
175
|
-
} else {
|
|
176
|
-
targetVariant = resolution.variant;
|
|
177
|
-
info(`Using ${describeVariant(targetVariant)} (${resolution.reason}).`);
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const { changedFiles } = ensureVariant(distDir, targetVariant);
|
|
181
|
-
if (changedFiles.length > 0) {
|
|
182
|
-
info(`Updated entry files: ${changedFiles.join(", ")}`);
|
|
183
|
-
} else {
|
|
184
|
-
info("Entry files already match the requested runtime.");
|
|
185
|
-
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
188
|
-
error(`Failed to switch runtime to ${targetVariant}. ${message}`);
|
|
189
|
-
if (envConfig.disableFallback || targetVariant === FALLBACK_VARIANT) {
|
|
190
|
-
warn("Leaving existing files untouched. Import a specific runtime manually if required.");
|
|
191
|
-
} else {
|
|
192
|
-
try {
|
|
193
|
-
const { changedFiles } = ensureVariant(distDir, FALLBACK_VARIANT);
|
|
194
|
-
if (changedFiles.length > 0) {
|
|
195
|
-
info(`Reverted to fallback runtime (${describeVariant(FALLBACK_VARIANT)}).`);
|
|
196
|
-
} else {
|
|
197
|
-
info("Fallback runtime was already in use. No changes applied.");
|
|
198
|
-
}
|
|
199
|
-
} catch (fallbackErr) {
|
|
200
|
-
const fallbackMessage = fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
|
|
201
|
-
error(`Failed to apply fallback runtime. ${fallbackMessage}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (envConfig.strict) {
|
|
205
|
-
_process2.default.exitCode = _nullishCoalesce(_process2.default.exitCode, () => ( 1));
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
main();
|
package/dist/postinstall.d.cts
DELETED
package/dist/postinstall.d.ts
DELETED
package/dist/postinstall.js
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
// src/postinstall.ts
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import process from "process";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
import { getPackageInfoSync } from "local-pkg";
|
|
7
|
-
import satisfies from "semver/functions/satisfies.js";
|
|
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, process.stdout);
|
|
17
|
-
}
|
|
18
|
-
function warn(message) {
|
|
19
|
-
printLine(message, process.stderr);
|
|
20
|
-
}
|
|
21
|
-
function error(message) {
|
|
22
|
-
printLine(message, process.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 = process.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 = process.env.WEAPP_TW_MERGE_TARGET_VERSION ?? process.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
|
-
process.env.WEAPP_TW_MERGE_RESOLVE_ROOT,
|
|
66
|
-
process.env.INIT_CWD,
|
|
67
|
-
process.env.npm_config_local_prefix,
|
|
68
|
-
process.env.PWD,
|
|
69
|
-
process.cwd()
|
|
70
|
-
]);
|
|
71
|
-
for (const root of searchRoots) {
|
|
72
|
-
try {
|
|
73
|
-
const info2 = getPackageInfoSync("tailwindcss", { paths: [root] });
|
|
74
|
-
if (info2?.version) {
|
|
75
|
-
return {
|
|
76
|
-
version: info2.version,
|
|
77
|
-
rootPath: info2.rootPath
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
} catch {
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
const info2 = getPackageInfoSync("tailwindcss");
|
|
85
|
-
if (info2?.version) {
|
|
86
|
-
return {
|
|
87
|
-
version: info2.version,
|
|
88
|
-
rootPath: info2.rootPath
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
} catch {
|
|
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 = satisfies(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 fs.readFileSync(pathname);
|
|
118
|
-
}
|
|
119
|
-
function copyFileIfChanged(source, target) {
|
|
120
|
-
const sourceBuffer = readFile(source);
|
|
121
|
-
if (fs.existsSync(target)) {
|
|
122
|
-
try {
|
|
123
|
-
const targetBuffer = readFile(target);
|
|
124
|
-
if (targetBuffer.equals(sourceBuffer)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
} catch {
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
fs.writeFileSync(target, sourceBuffer);
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
function ensureVariant(distDir, variant) {
|
|
134
|
-
const changedFiles = [];
|
|
135
|
-
for (const ext of EXTENSIONS) {
|
|
136
|
-
const source = path.resolve(distDir, `${variant}.${ext}`);
|
|
137
|
-
if (!fs.existsSync(source)) {
|
|
138
|
-
throw new Error(`Missing source file ${path.relative(process.cwd(), source)}`);
|
|
139
|
-
}
|
|
140
|
-
const target = path.resolve(distDir, `index.${ext}`);
|
|
141
|
-
if (copyFileIfChanged(source, target)) {
|
|
142
|
-
changedFiles.push(path.basename(target));
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
changedFiles
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
function main() {
|
|
150
|
-
const resolveDistDir = () => {
|
|
151
|
-
if (typeof __dirname === "string") {
|
|
152
|
-
return path.resolve(__dirname, "../dist");
|
|
153
|
-
}
|
|
154
|
-
const getImportMetaUrl = new Function("return import.meta.url");
|
|
155
|
-
return fileURLToPath(new URL("../dist/", getImportMetaUrl()));
|
|
156
|
-
};
|
|
157
|
-
const distDir = resolveDistDir();
|
|
158
|
-
if (!fs.existsSync(distDir)) {
|
|
159
|
-
warn("dist directory not found. Skipping runtime switch.");
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const envConfig = readEnvConfig();
|
|
163
|
-
const tailwindInfo = detectTailwindInfo();
|
|
164
|
-
const resolution = resolveVariant(envConfig, tailwindInfo);
|
|
165
|
-
let targetVariant;
|
|
166
|
-
if (!resolution.variant) {
|
|
167
|
-
warn(`${resolution.reason}.`);
|
|
168
|
-
if (envConfig.disableFallback) {
|
|
169
|
-
warn("Fallback is disabled. Default entry will keep the bundled runtime.");
|
|
170
|
-
warn('You can import "@weapp-tailwindcss/merge/v3" or "@weapp-tailwindcss/merge/v4" manually when needed.');
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
targetVariant = FALLBACK_VARIANT;
|
|
174
|
-
info(`Fallback to ${describeVariant(targetVariant)}.`);
|
|
175
|
-
} else {
|
|
176
|
-
targetVariant = resolution.variant;
|
|
177
|
-
info(`Using ${describeVariant(targetVariant)} (${resolution.reason}).`);
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const { changedFiles } = ensureVariant(distDir, targetVariant);
|
|
181
|
-
if (changedFiles.length > 0) {
|
|
182
|
-
info(`Updated entry files: ${changedFiles.join(", ")}`);
|
|
183
|
-
} else {
|
|
184
|
-
info("Entry files already match the requested runtime.");
|
|
185
|
-
}
|
|
186
|
-
} catch (err) {
|
|
187
|
-
const message = err instanceof Error ? err.message : String(err);
|
|
188
|
-
error(`Failed to switch runtime to ${targetVariant}. ${message}`);
|
|
189
|
-
if (envConfig.disableFallback || targetVariant === FALLBACK_VARIANT) {
|
|
190
|
-
warn("Leaving existing files untouched. Import a specific runtime manually if required.");
|
|
191
|
-
} else {
|
|
192
|
-
try {
|
|
193
|
-
const { changedFiles } = ensureVariant(distDir, FALLBACK_VARIANT);
|
|
194
|
-
if (changedFiles.length > 0) {
|
|
195
|
-
info(`Reverted to fallback runtime (${describeVariant(FALLBACK_VARIANT)}).`);
|
|
196
|
-
} else {
|
|
197
|
-
info("Fallback runtime was already in use. No changes applied.");
|
|
198
|
-
}
|
|
199
|
-
} catch (fallbackErr) {
|
|
200
|
-
const fallbackMessage = fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
|
|
201
|
-
error(`Failed to apply fallback runtime. ${fallbackMessage}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (envConfig.strict) {
|
|
205
|
-
process.exitCode = process.exitCode ?? 1;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
main();
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EscapeOptions, UnescapeOptions } from '@weapp-core/escape';
|
|
2
|
-
import { ClassValue } from 'clsx';
|
|
3
|
-
|
|
4
|
-
type EscapeConfig = false | EscapeOptions;
|
|
5
|
-
type UnescapeConfig = false | UnescapeOptions;
|
|
6
|
-
interface CreateOptions {
|
|
7
|
-
escape?: EscapeConfig;
|
|
8
|
-
unescape?: UnescapeConfig;
|
|
9
|
-
}
|
|
10
|
-
type TailwindMergeLibraryFn = (...inputs: any[]) => string;
|
|
11
|
-
type TailwindMergeRuntime = (...inputs: ClassValue[]) => string;
|
|
12
|
-
type TailwindMergeFactory<TFactory extends (...args: any[]) => TailwindMergeLibraryFn> = (...args: Parameters<TFactory>) => TailwindMergeRuntime;
|
|
13
|
-
type TailwindMergeVersion = 2 | 3;
|
|
14
|
-
|
|
15
|
-
export type { CreateOptions as C, EscapeConfig as E, TailwindMergeVersion as T, UnescapeConfig as U, TailwindMergeRuntime as a, TailwindMergeFactory as b };
|
package/dist/types-DSXe0vN9.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { EscapeOptions, UnescapeOptions } from '@weapp-core/escape';
|
|
2
|
-
import { ClassValue } from 'clsx';
|
|
3
|
-
|
|
4
|
-
type EscapeConfig = false | EscapeOptions;
|
|
5
|
-
type UnescapeConfig = false | UnescapeOptions;
|
|
6
|
-
interface CreateOptions {
|
|
7
|
-
escape?: EscapeConfig;
|
|
8
|
-
unescape?: UnescapeConfig;
|
|
9
|
-
}
|
|
10
|
-
type TailwindMergeLibraryFn = (...inputs: any[]) => string;
|
|
11
|
-
type TailwindMergeRuntime = (...inputs: ClassValue[]) => string;
|
|
12
|
-
type TailwindMergeFactory<TFactory extends (...args: any[]) => TailwindMergeLibraryFn> = (...args: Parameters<TFactory>) => TailwindMergeRuntime;
|
|
13
|
-
type TailwindMergeVersion = 2 | 3;
|
|
14
|
-
|
|
15
|
-
export type { CreateOptions as C, EscapeConfig as E, TailwindMergeVersion as T, UnescapeConfig as U, TailwindMergeRuntime as a, TailwindMergeFactory as b };
|
package/dist/v3.cjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _chunkV4RUVSPVcjs = require('./chunk-V4RUVSPV.cjs');
|
|
5
|
-
require('./chunk-PZ4IYNKU.cjs');
|
|
6
|
-
|
|
7
|
-
// src/v3.ts
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _tailwindmergev2 = require('tailwind-merge-v2');
|
|
16
|
-
var create = _chunkV4RUVSPVcjs.createRuntimeFactory.call(void 0, {
|
|
17
|
-
createTailwindMerge: _tailwindmergev2.createTailwindMerge,
|
|
18
|
-
extendTailwindMerge: _tailwindmergev2.extendTailwindMerge,
|
|
19
|
-
twJoin: _tailwindmergev2.twJoin,
|
|
20
|
-
twMerge: _tailwindmergev2.twMerge,
|
|
21
|
-
version: 2
|
|
22
|
-
});
|
|
23
|
-
var {
|
|
24
|
-
version: tailwindMergeVersion,
|
|
25
|
-
twMerge,
|
|
26
|
-
twJoin,
|
|
27
|
-
extendTailwindMerge,
|
|
28
|
-
createTailwindMerge
|
|
29
|
-
} = create();
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
exports.create = create; exports.createTailwindMerge = createTailwindMerge; exports.extendTailwindMerge = extendTailwindMerge; exports.getDefaultConfig = _tailwindmergev2.getDefaultConfig; exports.mergeConfigs = _tailwindmergev2.mergeConfigs; exports.tailwindMergeVersion = tailwindMergeVersion; exports.twJoin = twJoin; exports.twMerge = twMerge; exports.weappTwIgnore = _chunkV4RUVSPVcjs.weappTwIgnore;
|
package/dist/v3.d.cts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as tailwind_merge_v2 from 'tailwind-merge-v2';
|
|
2
|
-
import { createTailwindMerge as createTailwindMerge$1 } from 'tailwind-merge-v2';
|
|
3
|
-
export { getDefaultConfig, mergeConfigs } from 'tailwind-merge-v2';
|
|
4
|
-
import { C as CreateOptions, T as TailwindMergeVersion, a as TailwindMergeRuntime, b as TailwindMergeFactory } from './types-DSXe0vN9.cjs';
|
|
5
|
-
export { E as EscapeConfig, U as UnescapeConfig } from './types-DSXe0vN9.cjs';
|
|
6
|
-
export { ClassValue } from 'clsx';
|
|
7
|
-
export { weappTwIgnore } from 'weapp-tailwindcss/escape';
|
|
8
|
-
import '@weapp-core/escape';
|
|
9
|
-
|
|
10
|
-
declare const create: (createOptions?: CreateOptions) => {
|
|
11
|
-
version: TailwindMergeVersion;
|
|
12
|
-
twMerge: TailwindMergeRuntime;
|
|
13
|
-
twJoin: TailwindMergeRuntime;
|
|
14
|
-
extendTailwindMerge: TailwindMergeFactory<(<AdditionalClassGroupIds extends string = never, AdditionalThemeGroupIds extends string = never>(configExtension: tailwind_merge_v2.ConfigExtension<tailwind_merge_v2.DefaultClassGroupIds | AdditionalClassGroupIds, tailwind_merge_v2.DefaultThemeGroupIds | AdditionalThemeGroupIds> | ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>), ...createConfig: ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>)[]) => (...classLists: tailwind_merge_v2.ClassNameValue[]) => string)>;
|
|
15
|
-
createTailwindMerge: TailwindMergeFactory<typeof createTailwindMerge$1>;
|
|
16
|
-
};
|
|
17
|
-
declare const tailwindMergeVersion: TailwindMergeVersion;
|
|
18
|
-
declare const twMerge: TailwindMergeRuntime;
|
|
19
|
-
declare const twJoin: TailwindMergeRuntime;
|
|
20
|
-
declare const extendTailwindMerge: TailwindMergeFactory<(<AdditionalClassGroupIds extends string = never, AdditionalThemeGroupIds extends string = never>(configExtension: tailwind_merge_v2.ConfigExtension<tailwind_merge_v2.DefaultClassGroupIds | AdditionalClassGroupIds, tailwind_merge_v2.DefaultThemeGroupIds | AdditionalThemeGroupIds> | ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>), ...createConfig: ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>)[]) => (...classLists: tailwind_merge_v2.ClassNameValue[]) => string)>;
|
|
21
|
-
declare const createTailwindMerge: TailwindMergeFactory<typeof createTailwindMerge$1>;
|
|
22
|
-
|
|
23
|
-
export { CreateOptions, create, createTailwindMerge, extendTailwindMerge, tailwindMergeVersion, twJoin, twMerge };
|
package/dist/v3.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as tailwind_merge_v2 from 'tailwind-merge-v2';
|
|
2
|
-
import { createTailwindMerge as createTailwindMerge$1 } from 'tailwind-merge-v2';
|
|
3
|
-
export { getDefaultConfig, mergeConfigs } from 'tailwind-merge-v2';
|
|
4
|
-
import { C as CreateOptions, T as TailwindMergeVersion, a as TailwindMergeRuntime, b as TailwindMergeFactory } from './types-DSXe0vN9.js';
|
|
5
|
-
export { E as EscapeConfig, U as UnescapeConfig } from './types-DSXe0vN9.js';
|
|
6
|
-
export { ClassValue } from 'clsx';
|
|
7
|
-
export { weappTwIgnore } from 'weapp-tailwindcss/escape';
|
|
8
|
-
import '@weapp-core/escape';
|
|
9
|
-
|
|
10
|
-
declare const create: (createOptions?: CreateOptions) => {
|
|
11
|
-
version: TailwindMergeVersion;
|
|
12
|
-
twMerge: TailwindMergeRuntime;
|
|
13
|
-
twJoin: TailwindMergeRuntime;
|
|
14
|
-
extendTailwindMerge: TailwindMergeFactory<(<AdditionalClassGroupIds extends string = never, AdditionalThemeGroupIds extends string = never>(configExtension: tailwind_merge_v2.ConfigExtension<tailwind_merge_v2.DefaultClassGroupIds | AdditionalClassGroupIds, tailwind_merge_v2.DefaultThemeGroupIds | AdditionalThemeGroupIds> | ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>), ...createConfig: ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>)[]) => (...classLists: tailwind_merge_v2.ClassNameValue[]) => string)>;
|
|
15
|
-
createTailwindMerge: TailwindMergeFactory<typeof createTailwindMerge$1>;
|
|
16
|
-
};
|
|
17
|
-
declare const tailwindMergeVersion: TailwindMergeVersion;
|
|
18
|
-
declare const twMerge: TailwindMergeRuntime;
|
|
19
|
-
declare const twJoin: TailwindMergeRuntime;
|
|
20
|
-
declare const extendTailwindMerge: TailwindMergeFactory<(<AdditionalClassGroupIds extends string = never, AdditionalThemeGroupIds extends string = never>(configExtension: tailwind_merge_v2.ConfigExtension<tailwind_merge_v2.DefaultClassGroupIds | AdditionalClassGroupIds, tailwind_merge_v2.DefaultThemeGroupIds | AdditionalThemeGroupIds> | ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>), ...createConfig: ((config: tailwind_merge_v2.Config<string, string>) => tailwind_merge_v2.Config<string, string>)[]) => (...classLists: tailwind_merge_v2.ClassNameValue[]) => string)>;
|
|
21
|
-
declare const createTailwindMerge: TailwindMergeFactory<typeof createTailwindMerge$1>;
|
|
22
|
-
|
|
23
|
-
export { CreateOptions, create, createTailwindMerge, extendTailwindMerge, tailwindMergeVersion, twJoin, twMerge };
|