weapp-tailwindcss 4.7.2 → 4.7.3

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 (44) hide show
  1. package/dist/{chunk-QZRXYCOQ.js → chunk-2AAEKHNR.js} +5 -5
  2. package/dist/{chunk-5BW6X6AJ.mjs → chunk-CIBW3DQO.mjs} +2 -2
  3. package/dist/{chunk-JYCQWWYU.mjs → chunk-DXFNC4BP.mjs} +21 -4
  4. package/dist/{chunk-FPDJ3BCM.js → chunk-JTGVWJ3Z.js} +23 -6
  5. package/dist/{chunk-GNWJEIZZ.js → chunk-L2CHPESJ.js} +6 -5
  6. package/dist/{chunk-Z2H7M33Z.mjs → chunk-O3TOCTXE.mjs} +3 -2
  7. package/dist/chunk-R7GWRQDJ.js +15 -0
  8. package/dist/chunk-SCOGAO45.mjs +18 -0
  9. package/dist/{chunk-OPTIAB5G.js → chunk-SIZNRUIV.js} +4 -4
  10. package/dist/{chunk-2SI3KT2H.js → chunk-UAU6XVAY.js} +2 -2
  11. package/dist/{chunk-Q6PLZCM6.mjs → chunk-XFYWHJEU.mjs} +1 -1
  12. package/dist/cli.js +383 -15
  13. package/dist/cli.mjs +382 -15
  14. package/dist/core.js +4 -4
  15. package/dist/core.mjs +2 -2
  16. package/dist/css-macro/postcss.js +1 -1
  17. package/dist/css-macro/postcss.mjs +1 -1
  18. package/dist/css-macro.js +1 -1
  19. package/dist/css-macro.mjs +1 -1
  20. package/dist/defaults.js +1 -1
  21. package/dist/defaults.mjs +1 -1
  22. package/dist/escape.js +1 -1
  23. package/dist/escape.mjs +1 -1
  24. package/dist/gulp.js +5 -5
  25. package/dist/gulp.mjs +3 -3
  26. package/dist/index.js +7 -7
  27. package/dist/index.mjs +5 -5
  28. package/dist/postcss-html-transform.js +1 -1
  29. package/dist/postcss-html-transform.mjs +1 -1
  30. package/dist/presets.js +3 -3
  31. package/dist/presets.mjs +1 -1
  32. package/dist/types.d.mts +6 -0
  33. package/dist/types.d.ts +6 -0
  34. package/dist/types.js +1 -1
  35. package/dist/types.mjs +1 -1
  36. package/dist/vite.js +5 -5
  37. package/dist/vite.mjs +3 -3
  38. package/dist/webpack.js +5 -5
  39. package/dist/webpack.mjs +3 -3
  40. package/dist/webpack4.js +7 -7
  41. package/dist/webpack4.mjs +2 -2
  42. package/package.json +6 -4
  43. package/dist/chunk-4EUTRMUC.mjs +0 -10
  44. package/dist/chunk-QXSBMK2W.js +0 -7
package/dist/cli.js CHANGED
@@ -1,31 +1,399 @@
1
- "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1
+ "use strict"; function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } async function _asyncNullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return await 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; }
2
2
 
3
3
  var _chunkOXASK55Qjs = require('./chunk-OXASK55Q.js');
4
4
 
5
5
 
6
6
 
7
- var _chunkFPDJ3BCMjs = require('./chunk-FPDJ3BCM.js');
7
+ var _chunkJTGVWJ3Zjs = require('./chunk-JTGVWJ3Z.js');
8
8
  require('./chunk-DWAEHRHN.js');
9
- require('./chunk-OPTIAB5G.js');
9
+ require('./chunk-SIZNRUIV.js');
10
10
  require('./chunk-WXBFAARR.js');
11
- require('./chunk-UW3WHSZ5.js');
12
- require('./chunk-QXSBMK2W.js');
11
+
12
+
13
+ var _chunkUW3WHSZ5js = require('./chunk-UW3WHSZ5.js');
14
+
15
+
16
+
17
+ var _chunkR7GWRQDJjs = require('./chunk-R7GWRQDJ.js');
13
18
 
14
19
  // src/cli.ts
20
+ var _promises = require('fs/promises');
21
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
15
22
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
23
+ var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
16
24
  var _semver = require('semver'); var _semver2 = _interopRequireDefault(_semver);
25
+ var _tailwindcsspatch = require('tailwindcss-patch');
26
+
27
+ // src/cli/config.ts
28
+ var _module = require('module');
29
+ var MODULE_ID = "@tailwindcss-mangle/config";
30
+ var cachedRequire;
31
+ function getNodeRequire() {
32
+ if (cachedRequire) {
33
+ return cachedRequire;
34
+ }
35
+ if (typeof _chunkR7GWRQDJjs.__require === "function") {
36
+ cachedRequire = _chunkR7GWRQDJjs.__require;
37
+ return cachedRequire;
38
+ }
39
+ try {
40
+ cachedRequire = _module.createRequire.call(void 0, _chunkR7GWRQDJjs.importMetaUrl);
41
+ } catch (e) {
42
+ cachedRequire = void 0;
43
+ }
44
+ return cachedRequire;
45
+ }
46
+ async function tryDynamicImport(moduleId) {
47
+ try {
48
+ return await Promise.resolve().then(() => _interopRequireWildcard(require(moduleId)));
49
+ } catch (e2) {
50
+ return void 0;
51
+ }
52
+ }
53
+ function tryRequire(moduleId) {
54
+ const nodeRequire = getNodeRequire();
55
+ if (!nodeRequire) {
56
+ return void 0;
57
+ }
58
+ try {
59
+ return nodeRequire(moduleId);
60
+ } catch (e3) {
61
+ return void 0;
62
+ }
63
+ }
64
+ function isValidModule(mod) {
65
+ return Boolean(mod) && typeof mod.initConfig === "function" && typeof mod.CONFIG_NAME === "string";
66
+ }
67
+ async function loadTailwindcssMangleConfig() {
68
+ const mod = await _asyncNullishCoalesce(await tryDynamicImport(MODULE_ID), async () => ( tryRequire(MODULE_ID)));
69
+ return isValidModule(mod) ? mod : void 0;
70
+ }
71
+
72
+ // src/cli/context.ts
73
+
74
+
75
+ function mergeTailwindcssPatcherOptions(overrides, current) {
76
+ if (!current) {
77
+ return overrides;
78
+ }
79
+ return _chunkUW3WHSZ5js.defuOverrideArray.call(void 0, overrides, current);
80
+ }
81
+ function resolveEntry(entry, cwd) {
82
+ if (_path2.default.isAbsolute(entry)) {
83
+ return _path2.default.normalize(entry);
84
+ }
85
+ const base = _nullishCoalesce(cwd, () => ( _process2.default.cwd()));
86
+ return _path2.default.normalize(_path2.default.resolve(base, entry));
87
+ }
88
+ function buildTailwindcssPatcherOptions(overrides) {
89
+ if (!overrides) {
90
+ return void 0;
91
+ }
92
+ const filtered = {};
93
+ if (overrides.cwd) {
94
+ filtered.cwd = overrides.cwd;
95
+ }
96
+ if (overrides.output) {
97
+ const output = {};
98
+ if (overrides.output.file) {
99
+ output.file = overrides.output.file;
100
+ }
101
+ if (overrides.output.format) {
102
+ output.format = overrides.output.format;
103
+ }
104
+ if (Object.keys(output).length > 0) {
105
+ filtered.output = output;
106
+ }
107
+ }
108
+ return Object.keys(filtered).length > 0 ? filtered : void 0;
109
+ }
110
+ function createCliContext(overrides, resolvedCwd) {
111
+ const userOptions = {
112
+ ..._nullishCoalesce(overrides, () => ( {}))
113
+ };
114
+ if (resolvedCwd) {
115
+ if (!userOptions.tailwindcssBasedir) {
116
+ userOptions.tailwindcssBasedir = resolvedCwd;
117
+ }
118
+ const cwdOptions = { cwd: resolvedCwd };
119
+ const current = userOptions.tailwindcssPatcherOptions;
120
+ userOptions.tailwindcssPatcherOptions = mergeTailwindcssPatcherOptions(
121
+ cwdOptions,
122
+ current
123
+ );
124
+ }
125
+ return _chunkJTGVWJ3Zjs.getCompilerContext.call(void 0, userOptions);
126
+ }
127
+ function formatOutputPath(target, baseDir) {
128
+ const root = _nullishCoalesce(baseDir, () => ( _process2.default.cwd()));
129
+ const relative = _path2.default.relative(root, target);
130
+ if (!relative) {
131
+ return ".";
132
+ }
133
+ if (relative.startsWith("..")) {
134
+ return _path2.default.normalize(target);
135
+ }
136
+ return relative.startsWith(".") ? relative : `.${_path2.default.sep}${relative}`;
137
+ }
138
+
139
+ // src/cli/helpers.ts
140
+
141
+
142
+
143
+ function readStringOption(flag, value) {
144
+ if (value == null) {
145
+ return void 0;
146
+ }
147
+ if (typeof value !== "string") {
148
+ throw new TypeError(`Option "--${flag}" expects a string value.`);
149
+ }
150
+ const trimmed = value.trim();
151
+ if (trimmed.length === 0) {
152
+ throw new TypeError(`Option "--${flag}" expects a non-empty value.`);
153
+ }
154
+ return trimmed;
155
+ }
156
+ function normalizeTokenFormat(format) {
157
+ switch (format) {
158
+ case "json":
159
+ case "lines":
160
+ case "grouped-json":
161
+ return format;
162
+ default:
163
+ return "json";
164
+ }
165
+ }
166
+ function normalizeExtractFormat(format) {
167
+ if (!format) {
168
+ return void 0;
169
+ }
170
+ if (format === "json" || format === "lines") {
171
+ return format;
172
+ }
173
+ return void 0;
174
+ }
175
+ function toBoolean(value, fallback) {
176
+ if (typeof value === "boolean") {
177
+ return value;
178
+ }
179
+ if (typeof value === "string") {
180
+ if (value === "true") {
181
+ return true;
182
+ }
183
+ if (value === "false") {
184
+ return false;
185
+ }
186
+ }
187
+ if (value == null) {
188
+ return fallback;
189
+ }
190
+ return Boolean(value);
191
+ }
192
+ function resolveCliCwd(value) {
193
+ const raw = readStringOption("cwd", value);
194
+ if (!raw) {
195
+ return void 0;
196
+ }
197
+ return _path2.default.isAbsolute(raw) ? _path2.default.normalize(raw) : _path2.default.resolve(_process2.default.cwd(), raw);
198
+ }
199
+ async function ensureDir(dir) {
200
+ await _promises.mkdir.call(void 0, dir, { recursive: true });
201
+ }
202
+ function handleCliError(error) {
203
+ if (error instanceof Error) {
204
+ _chunkOXASK55Qjs.logger.error(error.message);
205
+ if (error.stack && _process2.default.env.WEAPP_TW_DEBUG === "1") {
206
+ _chunkOXASK55Qjs.logger.error(error.stack);
207
+ }
208
+ } else {
209
+ _chunkOXASK55Qjs.logger.error(String(error));
210
+ }
211
+ }
212
+ function commandAction(handler) {
213
+ return async (...args) => {
214
+ try {
215
+ await handler(...args);
216
+ } catch (error) {
217
+ handleCliError(error);
218
+ _process2.default.exitCode = 1;
219
+ }
220
+ };
221
+ }
222
+
223
+ // src/cli/tokens.ts
224
+
225
+ async function collectTailwindTokens(patcher) {
226
+ const candidate = patcher;
227
+ if (candidate && typeof candidate.collectContentTokens === "function") {
228
+ return candidate.collectContentTokens();
229
+ }
230
+ throw new Error("The current Tailwind CSS patcher does not support token collection.");
231
+ }
232
+ function formatTokenLine(entry) {
233
+ return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
234
+ }
235
+ function formatGroupedPreview(map, limit = 3) {
236
+ const files = Object.keys(map);
237
+ if (files.length === 0) {
238
+ return { preview: "", moreFiles: 0 };
239
+ }
240
+ const lines = files.slice(0, limit).map((file) => {
241
+ const tokens = map[file];
242
+ const samples = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
243
+ const suffix = tokens.length > 3 ? ", ..." : "";
244
+ return `${file}: ${tokens.length} tokens (${samples}${suffix})`;
245
+ });
246
+ const moreFiles = files.length > limit ? files.length - limit : 0;
247
+ return {
248
+ preview: lines.join("\n"),
249
+ moreFiles
250
+ };
251
+ }
252
+ function logTokenPreview(report, format, groupKey) {
253
+ if (format === "lines") {
254
+ const preview = report.entries.slice(0, 5).map(formatTokenLine);
255
+ if (preview.length > 0) {
256
+ _chunkOXASK55Qjs.logger.log("");
257
+ for (const line of preview) {
258
+ _chunkOXASK55Qjs.logger.info(line);
259
+ }
260
+ if (report.entries.length > 5) {
261
+ _chunkOXASK55Qjs.logger.info(`...and ${report.entries.length - 5} more.`);
262
+ }
263
+ }
264
+ return;
265
+ }
266
+ if (format === "grouped-json") {
267
+ const grouped = _tailwindcsspatch.groupTokensByFile.call(void 0, report, {
268
+ key: groupKey,
269
+ stripAbsolutePaths: groupKey !== "absolute"
270
+ });
271
+ const { preview, moreFiles } = formatGroupedPreview(grouped);
272
+ if (preview) {
273
+ _chunkOXASK55Qjs.logger.log("");
274
+ _chunkOXASK55Qjs.logger.info(preview);
275
+ if (moreFiles > 0) {
276
+ _chunkOXASK55Qjs.logger.info(`...and ${moreFiles} more files.`);
277
+ }
278
+ }
279
+ return;
280
+ }
281
+ const previewEntries = report.entries.slice(0, 3);
282
+ if (previewEntries.length > 0) {
283
+ _chunkOXASK55Qjs.logger.log("");
284
+ _chunkOXASK55Qjs.logger.info(JSON.stringify(previewEntries, null, 2));
285
+ }
286
+ }
287
+
288
+ // src/cli.ts
17
289
  _process2.default.title = "node (weapp-tailwindcss)";
18
- var args = _process2.default.argv.slice(2);
19
- if (_semver2.default.lt(_process2.default.versions.node, _chunkFPDJ3BCMjs.WEAPP_TW_REQUIRED_NODE_VERSION)) {
290
+ if (_semver2.default.lt(_process2.default.versions.node, _chunkJTGVWJ3Zjs.WEAPP_TW_REQUIRED_NODE_VERSION)) {
20
291
  _chunkOXASK55Qjs.logger.warn(
21
- `You are using Node.js ${_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${_chunkFPDJ3BCMjs.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
292
+ `You are using Node.js ${_process2.default.versions.node}. For weapp-tailwindcss, Node.js version >= v${_chunkJTGVWJ3Zjs.WEAPP_TW_REQUIRED_NODE_VERSION} is required.`
22
293
  );
23
294
  }
24
- var command = args[0];
25
- async function run() {
26
- if (command === "patch") {
27
- const ctx = _chunkFPDJ3BCMjs.getCompilerContext.call(void 0, );
295
+ var cli = _cac2.default.call(void 0, "weapp-tailwindcss");
296
+ cli.command("patch", "Apply Tailwind CSS runtime patches").alias("install").option("--cwd <dir>", "Working directory").action(
297
+ commandAction(async (options) => {
298
+ const resolvedCwd = resolveCliCwd(options.cwd);
299
+ const ctx = createCliContext(void 0, resolvedCwd);
28
300
  await ctx.twPatcher.patch();
29
- }
30
- }
31
- void run();
301
+ _chunkOXASK55Qjs.logger.success("Tailwind CSS runtime patched successfully.");
302
+ })
303
+ );
304
+ cli.command("extract", "Collect generated class names into a cache file").option("--cwd <dir>", "Working directory").option("--output <file>", "Override output file path").option("--format <format>", "Output format (json|lines)").option("--css <file>", "Tailwind CSS entry CSS when using v4").option("--no-write", "Skip writing to disk").action(
305
+ commandAction(async (options) => {
306
+ const resolvedCwd = resolveCliCwd(options.cwd);
307
+ const outputPath = readStringOption("output", options.output);
308
+ const formatOption = readStringOption("format", options.format);
309
+ const cssOption = readStringOption("css", options.css);
310
+ const overrides = {};
311
+ if (cssOption) {
312
+ overrides.cssEntries = [resolveEntry(cssOption, resolvedCwd)];
313
+ }
314
+ const normalizedFormat = normalizeExtractFormat(formatOption);
315
+ const outputOverrides = buildTailwindcssPatcherOptions(
316
+ normalizedFormat || outputPath ? {
317
+ output: {
318
+ file: outputPath,
319
+ format: normalizedFormat
320
+ }
321
+ } : void 0
322
+ );
323
+ if (outputOverrides) {
324
+ overrides.tailwindcssPatcherOptions = outputOverrides;
325
+ }
326
+ const ctx = createCliContext(overrides, resolvedCwd);
327
+ const write = toBoolean(options.write, true);
328
+ const result = await ctx.twPatcher.extract({ write });
329
+ const classCount = _nullishCoalesce(_nullishCoalesce(_optionalChain([result, 'optionalAccess', _ => _.classList, 'optionalAccess', _2 => _2.length]), () => ( _optionalChain([result, 'optionalAccess', _3 => _3.classSet, 'optionalAccess', _4 => _4.size]))), () => ( 0));
330
+ if (_optionalChain([result, 'optionalAccess', _5 => _5.filename])) {
331
+ _chunkOXASK55Qjs.logger.success(`Collected ${classCount} classes -> ${formatOutputPath(result.filename, resolvedCwd)}`);
332
+ } else {
333
+ _chunkOXASK55Qjs.logger.success(`Collected ${classCount} classes.`);
334
+ }
335
+ })
336
+ );
337
+ cli.command("tokens", "Extract Tailwind tokens with location metadata").option("--cwd <dir>", "Working directory").option("--output <file>", "Override output file path").option("--format <format>", "Output format (json|lines|grouped-json)").option("--group-key <key>", "Grouping key for grouped-json output (relative|absolute)").option("--no-write", "Skip writing to disk").action(
338
+ commandAction(async (options) => {
339
+ const resolvedCwd = resolveCliCwd(options.cwd);
340
+ const outputPath = readStringOption("output", options.output);
341
+ const formatInput = readStringOption("format", options.format);
342
+ const groupKeyInput = readStringOption("group-key", options.groupKey);
343
+ const format = normalizeTokenFormat(_nullishCoalesce(formatInput, () => ( "json")));
344
+ const groupKey = groupKeyInput === "absolute" ? "absolute" : "relative";
345
+ const write = toBoolean(options.write, true);
346
+ const ctx = createCliContext(void 0, resolvedCwd);
347
+ const report = await collectTailwindTokens(ctx.twPatcher);
348
+ const baseDir = _nullishCoalesce(resolvedCwd, () => ( _process2.default.cwd()));
349
+ if (write) {
350
+ const targetRelative = _nullishCoalesce(outputPath, () => ( ".tw-patch/tw-token-report.json"));
351
+ const target = _path2.default.resolve(baseDir, targetRelative);
352
+ await ensureDir(_path2.default.dirname(target));
353
+ if (format === "json") {
354
+ await _promises.writeFile.call(void 0, target, `${JSON.stringify(report, null, 2)}
355
+ `, "utf8");
356
+ } else if (format === "grouped-json") {
357
+ const grouped = _tailwindcsspatch.groupTokensByFile.call(void 0, report, {
358
+ key: groupKey,
359
+ stripAbsolutePaths: groupKey !== "absolute"
360
+ });
361
+ await _promises.writeFile.call(void 0, target, `${JSON.stringify(grouped, null, 2)}
362
+ `, "utf8");
363
+ } else {
364
+ const lines = report.entries.map(formatTokenLine);
365
+ await _promises.writeFile.call(void 0, target, `${lines.join("\n")}
366
+ `, "utf8");
367
+ }
368
+ _chunkOXASK55Qjs.logger.success(
369
+ `Collected ${report.entries.length} tokens (${format}) -> ${formatOutputPath(target, resolvedCwd)}`
370
+ );
371
+ } else {
372
+ _chunkOXASK55Qjs.logger.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
373
+ logTokenPreview(report, format, groupKey);
374
+ }
375
+ if (report.skippedFiles.length > 0) {
376
+ _chunkOXASK55Qjs.logger.warn("Skipped files:");
377
+ for (const skipped of report.skippedFiles) {
378
+ _chunkOXASK55Qjs.logger.warn(` - ${skipped.file} (${skipped.reason})`);
379
+ }
380
+ }
381
+ })
382
+ );
383
+ cli.command("init", "Generate a tailwindcss-patch config file").option("--cwd <dir>", "Working directory").action(
384
+ commandAction(async (options) => {
385
+ const resolvedCwd = resolveCliCwd(options.cwd);
386
+ const moduleResult = await loadTailwindcssMangleConfig();
387
+ if (!moduleResult) {
388
+ _chunkOXASK55Qjs.logger.error("Unable to load @tailwindcss-mangle/config. Please install tailwindcss-patch >= 8.2.0.");
389
+ _process2.default.exitCode = 1;
390
+ return;
391
+ }
392
+ const cwd = _nullishCoalesce(resolvedCwd, () => ( _process2.default.cwd()));
393
+ await moduleResult.initConfig(cwd);
394
+ _chunkOXASK55Qjs.logger.success(`${moduleResult.CONFIG_NAME}.config.ts initialized.`);
395
+ })
396
+ );
397
+ cli.help();
398
+ cli.version(_nullishCoalesce(_process2.default.env.npm_package_version, () => ( "0.0.0")));
399
+ cli.parse();