tailwindcss-patch 8.2.3 → 8.3.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/README.md +20 -0
- package/dist/{chunk-CFH3UEW6.js → chunk-7ZWFVW77.js} +476 -166
- package/dist/{chunk-KH3TRSVT.mjs → chunk-SN7IO2IS.mjs} +443 -133
- package/dist/cli.js +3 -233
- package/dist/cli.mjs +3 -233
- package/dist/index.d.mts +98 -1
- package/dist/index.d.ts +98 -1
- package/dist/index.js +8 -2
- package/dist/index.mjs +9 -3
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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(); } } 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; } var _class;// ../../node_modules/.pnpm/tsup@8.5.
|
|
2
|
-
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.src
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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(); } } 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; } var _class;// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
|
|
2
|
+
var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
|
|
3
3
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
4
4
|
|
|
5
5
|
// src/logger.ts
|
|
@@ -289,105 +289,6 @@ function groupTokensByFile(report, options) {
|
|
|
289
289
|
}, {});
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
// src/options/legacy.ts
|
|
293
|
-
function normalizeLegacyFeatures(patch) {
|
|
294
|
-
const apply = _optionalChain([patch, 'optionalAccess', _6 => _6.applyPatches]);
|
|
295
|
-
const extend = _optionalChain([apply, 'optionalAccess', _7 => _7.extendLengthUnits]);
|
|
296
|
-
let extendOption = false;
|
|
297
|
-
if (extend && typeof extend === "object") {
|
|
298
|
-
extendOption = {
|
|
299
|
-
...extend,
|
|
300
|
-
enabled: true
|
|
301
|
-
};
|
|
302
|
-
} else if (extend === true) {
|
|
303
|
-
extendOption = {
|
|
304
|
-
enabled: true,
|
|
305
|
-
units: ["rpx"],
|
|
306
|
-
overwrite: _optionalChain([patch, 'optionalAccess', _8 => _8.overwrite])
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _9 => _9.exportContext]), () => ( true)),
|
|
311
|
-
extendLengthUnits: extendOption
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
function fromLegacyOptions(options) {
|
|
315
|
-
if (!options) {
|
|
316
|
-
return {};
|
|
317
|
-
}
|
|
318
|
-
const patch = options.patch;
|
|
319
|
-
const features = normalizeLegacyFeatures(patch);
|
|
320
|
-
const output = _optionalChain([patch, 'optionalAccess', _10 => _10.output]);
|
|
321
|
-
const tailwindConfig = _optionalChain([patch, 'optionalAccess', _11 => _11.tailwindcss]);
|
|
322
|
-
const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _12 => _12.version]);
|
|
323
|
-
const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _13 => _13.v2]);
|
|
324
|
-
const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _14 => _14.v3]);
|
|
325
|
-
const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _15 => _15.v4]);
|
|
326
|
-
const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _16 => _16.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _17 => _17.config])));
|
|
327
|
-
const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _18 => _18.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _19 => _19.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _20 => _20.cwd])));
|
|
328
|
-
return {
|
|
329
|
-
cwd: _optionalChain([patch, 'optionalAccess', _21 => _21.cwd]),
|
|
330
|
-
overwrite: _optionalChain([patch, 'optionalAccess', _22 => _22.overwrite]),
|
|
331
|
-
filter: _optionalChain([patch, 'optionalAccess', _23 => _23.filter]),
|
|
332
|
-
cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
|
|
333
|
-
...options.cache,
|
|
334
|
-
enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
|
|
335
|
-
} : void 0,
|
|
336
|
-
output: output ? {
|
|
337
|
-
file: output.filename,
|
|
338
|
-
pretty: output.loose ? 2 : false,
|
|
339
|
-
removeUniversalSelector: output.removeUniversalSelector
|
|
340
|
-
} : void 0,
|
|
341
|
-
tailwind: {
|
|
342
|
-
packageName: _optionalChain([patch, 'optionalAccess', _24 => _24.packageName]),
|
|
343
|
-
version: tailwindVersion,
|
|
344
|
-
resolve: _optionalChain([patch, 'optionalAccess', _25 => _25.resolve]),
|
|
345
|
-
config: tailwindConfigPath,
|
|
346
|
-
cwd: tailwindCwd,
|
|
347
|
-
v2: tailwindV2,
|
|
348
|
-
v3: tailwindV3,
|
|
349
|
-
v4: tailwindV4
|
|
350
|
-
},
|
|
351
|
-
features: {
|
|
352
|
-
exposeContext: features.exposeContext,
|
|
353
|
-
extendLengthUnits: features.extendLengthUnits
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
function fromUnifiedConfig(registry) {
|
|
358
|
-
if (!registry) {
|
|
359
|
-
return {};
|
|
360
|
-
}
|
|
361
|
-
const tailwind = registry.tailwind;
|
|
362
|
-
const output = registry.output;
|
|
363
|
-
const pretty = (() => {
|
|
364
|
-
if (_optionalChain([output, 'optionalAccess', _26 => _26.pretty]) === void 0) {
|
|
365
|
-
return void 0;
|
|
366
|
-
}
|
|
367
|
-
if (typeof output.pretty === "boolean") {
|
|
368
|
-
return output.pretty ? 2 : false;
|
|
369
|
-
}
|
|
370
|
-
return output.pretty;
|
|
371
|
-
})();
|
|
372
|
-
return {
|
|
373
|
-
output: output ? {
|
|
374
|
-
file: output.file,
|
|
375
|
-
pretty,
|
|
376
|
-
removeUniversalSelector: output.stripUniversalSelector
|
|
377
|
-
} : void 0,
|
|
378
|
-
tailwind: tailwind ? {
|
|
379
|
-
version: tailwind.version,
|
|
380
|
-
packageName: tailwind.package,
|
|
381
|
-
resolve: tailwind.resolve,
|
|
382
|
-
config: tailwind.config,
|
|
383
|
-
cwd: tailwind.cwd,
|
|
384
|
-
v2: tailwind.legacy,
|
|
385
|
-
v3: tailwind.classic,
|
|
386
|
-
v4: tailwind.next
|
|
387
|
-
} : void 0
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
|
|
391
292
|
// src/options/normalize.ts
|
|
392
293
|
|
|
393
294
|
|
|
@@ -431,11 +332,11 @@ function normalizeCacheOptions(cache, projectRoot) {
|
|
|
431
332
|
};
|
|
432
333
|
}
|
|
433
334
|
function normalizeOutputOptions(output) {
|
|
434
|
-
const enabled = _nullishCoalesce(_optionalChain([output, 'optionalAccess',
|
|
435
|
-
const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess',
|
|
436
|
-
const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess',
|
|
437
|
-
const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess',
|
|
438
|
-
const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess',
|
|
335
|
+
const enabled = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _6 => _6.enabled]), () => ( true));
|
|
336
|
+
const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _7 => _7.file]), () => ( ".tw-patch/tw-class-list.json"));
|
|
337
|
+
const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _8 => _8.format]), () => ( "json"));
|
|
338
|
+
const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess', _9 => _9.pretty]), () => ( true)));
|
|
339
|
+
const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _10 => _10.removeUniversalSelector]), () => ( true));
|
|
439
340
|
return {
|
|
440
341
|
enabled,
|
|
441
342
|
file,
|
|
@@ -445,13 +346,13 @@ function normalizeOutputOptions(output) {
|
|
|
445
346
|
};
|
|
446
347
|
}
|
|
447
348
|
function normalizeExposeContextOptions(features) {
|
|
448
|
-
if (_optionalChain([features, 'optionalAccess',
|
|
349
|
+
if (_optionalChain([features, 'optionalAccess', _11 => _11.exposeContext]) === false) {
|
|
449
350
|
return {
|
|
450
351
|
enabled: false,
|
|
451
352
|
refProperty: "contextRef"
|
|
452
353
|
};
|
|
453
354
|
}
|
|
454
|
-
if (typeof _optionalChain([features, 'optionalAccess',
|
|
355
|
+
if (typeof _optionalChain([features, 'optionalAccess', _12 => _12.exposeContext]) === "object" && features.exposeContext) {
|
|
455
356
|
return {
|
|
456
357
|
enabled: true,
|
|
457
358
|
refProperty: _nullishCoalesce(features.exposeContext.refProperty, () => ( "contextRef"))
|
|
@@ -463,7 +364,7 @@ function normalizeExposeContextOptions(features) {
|
|
|
463
364
|
};
|
|
464
365
|
}
|
|
465
366
|
function normalizeExtendLengthUnitsOptions(features) {
|
|
466
|
-
const extend = _optionalChain([features, 'optionalAccess',
|
|
367
|
+
const extend = _optionalChain([features, 'optionalAccess', _13 => _13.extendLengthUnits]);
|
|
467
368
|
if (extend === false || extend === void 0) {
|
|
468
369
|
return null;
|
|
469
370
|
}
|
|
@@ -483,9 +384,12 @@ function normalizeExtendLengthUnitsOptions(features) {
|
|
|
483
384
|
};
|
|
484
385
|
}
|
|
485
386
|
function normalizeTailwindV4Options(v4, fallbackBase) {
|
|
486
|
-
const
|
|
487
|
-
const
|
|
488
|
-
const
|
|
387
|
+
const configuredBase = _optionalChain([v4, 'optionalAccess', _14 => _14.base]) ? _pathe2.default.resolve(v4.base) : void 0;
|
|
388
|
+
const base = _nullishCoalesce(configuredBase, () => ( fallbackBase));
|
|
389
|
+
const cssEntries = Array.isArray(_optionalChain([v4, 'optionalAccess', _15 => _15.cssEntries])) ? v4.cssEntries.filter((entry) => Boolean(entry)).map((entry) => _pathe2.default.resolve(entry)) : [];
|
|
390
|
+
const userSources = _optionalChain([v4, 'optionalAccess', _16 => _16.sources]);
|
|
391
|
+
const hasUserDefinedSources = Boolean(_optionalChain([userSources, 'optionalAccess', _17 => _17.length]));
|
|
392
|
+
const sources = hasUserDefinedSources ? userSources : [
|
|
489
393
|
{
|
|
490
394
|
base,
|
|
491
395
|
pattern: "**/*",
|
|
@@ -494,19 +398,21 @@ function normalizeTailwindV4Options(v4, fallbackBase) {
|
|
|
494
398
|
];
|
|
495
399
|
return {
|
|
496
400
|
base,
|
|
497
|
-
|
|
401
|
+
configuredBase,
|
|
402
|
+
css: _optionalChain([v4, 'optionalAccess', _18 => _18.css]),
|
|
498
403
|
cssEntries,
|
|
499
|
-
sources
|
|
404
|
+
sources,
|
|
405
|
+
hasUserDefinedSources
|
|
500
406
|
};
|
|
501
407
|
}
|
|
502
408
|
function normalizeTailwindOptions(tailwind, projectRoot) {
|
|
503
|
-
const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess',
|
|
504
|
-
const versionHint = _optionalChain([tailwind, 'optionalAccess',
|
|
505
|
-
const resolve = _optionalChain([tailwind, 'optionalAccess',
|
|
506
|
-
const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess',
|
|
507
|
-
const config = _optionalChain([tailwind, 'optionalAccess',
|
|
508
|
-
const postcssPlugin = _optionalChain([tailwind, 'optionalAccess',
|
|
509
|
-
const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess',
|
|
409
|
+
const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _19 => _19.packageName]), () => ( "tailwindcss"));
|
|
410
|
+
const versionHint = _optionalChain([tailwind, 'optionalAccess', _20 => _20.version]);
|
|
411
|
+
const resolve = _optionalChain([tailwind, 'optionalAccess', _21 => _21.resolve]);
|
|
412
|
+
const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _22 => _22.cwd]), () => ( projectRoot));
|
|
413
|
+
const config = _optionalChain([tailwind, 'optionalAccess', _23 => _23.config]);
|
|
414
|
+
const postcssPlugin = _optionalChain([tailwind, 'optionalAccess', _24 => _24.postcssPlugin]);
|
|
415
|
+
const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess', _25 => _25.v4]), cwd);
|
|
510
416
|
return {
|
|
511
417
|
packageName,
|
|
512
418
|
versionHint,
|
|
@@ -514,8 +420,8 @@ function normalizeTailwindOptions(tailwind, projectRoot) {
|
|
|
514
420
|
cwd,
|
|
515
421
|
config,
|
|
516
422
|
postcssPlugin,
|
|
517
|
-
v2: _optionalChain([tailwind, 'optionalAccess',
|
|
518
|
-
v3: _optionalChain([tailwind, 'optionalAccess',
|
|
423
|
+
v2: _optionalChain([tailwind, 'optionalAccess', _26 => _26.v2]),
|
|
424
|
+
v3: _optionalChain([tailwind, 'optionalAccess', _27 => _27.v3]),
|
|
519
425
|
v4
|
|
520
426
|
};
|
|
521
427
|
}
|
|
@@ -602,13 +508,31 @@ async function collectClassesFromTailwindV4(options) {
|
|
|
602
508
|
if (!v4Options) {
|
|
603
509
|
return set;
|
|
604
510
|
}
|
|
605
|
-
const
|
|
606
|
-
|
|
607
|
-
|
|
511
|
+
const toAbsolute = (value) => {
|
|
512
|
+
if (!value) {
|
|
513
|
+
return void 0;
|
|
514
|
+
}
|
|
515
|
+
return _pathe2.default.isAbsolute(value) ? value : _pathe2.default.resolve(options.projectRoot, value);
|
|
516
|
+
};
|
|
517
|
+
const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
|
|
518
|
+
const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
|
|
519
|
+
const resolveSources = (base) => {
|
|
520
|
+
if (!_optionalChain([v4Options, 'access', _28 => _28.sources, 'optionalAccess', _29 => _29.length])) {
|
|
521
|
+
return void 0;
|
|
522
|
+
}
|
|
523
|
+
if (!v4Options.hasUserDefinedSources && !resolvedConfiguredBase) {
|
|
524
|
+
return v4Options.sources.map((source) => ({
|
|
525
|
+
base,
|
|
526
|
+
pattern: source.pattern,
|
|
527
|
+
negated: source.negated
|
|
528
|
+
}));
|
|
529
|
+
}
|
|
530
|
+
return v4Options.sources.map((source) => ({
|
|
531
|
+
base: _nullishCoalesce(source.base, () => ( base)),
|
|
608
532
|
pattern: source.pattern,
|
|
609
533
|
negated: source.negated
|
|
610
|
-
};
|
|
611
|
-
}
|
|
534
|
+
}));
|
|
535
|
+
};
|
|
612
536
|
if (v4Options.cssEntries.length > 0) {
|
|
613
537
|
for (const entry of v4Options.cssEntries) {
|
|
614
538
|
const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
|
|
@@ -616,9 +540,12 @@ async function collectClassesFromTailwindV4(options) {
|
|
|
616
540
|
continue;
|
|
617
541
|
}
|
|
618
542
|
const css = await _fsextra2.default.readFile(filePath, "utf8");
|
|
543
|
+
const entryDir = _pathe2.default.dirname(filePath);
|
|
544
|
+
const baseForEntry = _nullishCoalesce(resolvedConfiguredBase, () => ( entryDir));
|
|
545
|
+
const sources = resolveSources(baseForEntry);
|
|
619
546
|
const candidates = await extractValidCandidates({
|
|
620
547
|
cwd: options.projectRoot,
|
|
621
|
-
base:
|
|
548
|
+
base: baseForEntry,
|
|
622
549
|
css,
|
|
623
550
|
sources
|
|
624
551
|
});
|
|
@@ -629,9 +556,11 @@ async function collectClassesFromTailwindV4(options) {
|
|
|
629
556
|
}
|
|
630
557
|
}
|
|
631
558
|
} else {
|
|
559
|
+
const baseForCss = _nullishCoalesce(resolvedConfiguredBase, () => ( resolvedDefaultBase));
|
|
560
|
+
const sources = resolveSources(baseForCss);
|
|
632
561
|
const candidates = await extractValidCandidates({
|
|
633
562
|
cwd: options.projectRoot,
|
|
634
|
-
base:
|
|
563
|
+
base: baseForCss,
|
|
635
564
|
css: v4Options.css,
|
|
636
565
|
sources
|
|
637
566
|
});
|
|
@@ -737,6 +666,105 @@ var _localpkg = require('local-pkg');
|
|
|
737
666
|
|
|
738
667
|
var _semver = require('semver');
|
|
739
668
|
|
|
669
|
+
// src/options/legacy.ts
|
|
670
|
+
function normalizeLegacyFeatures(patch) {
|
|
671
|
+
const apply = _optionalChain([patch, 'optionalAccess', _30 => _30.applyPatches]);
|
|
672
|
+
const extend = _optionalChain([apply, 'optionalAccess', _31 => _31.extendLengthUnits]);
|
|
673
|
+
let extendOption = false;
|
|
674
|
+
if (extend && typeof extend === "object") {
|
|
675
|
+
extendOption = {
|
|
676
|
+
...extend,
|
|
677
|
+
enabled: true
|
|
678
|
+
};
|
|
679
|
+
} else if (extend === true) {
|
|
680
|
+
extendOption = {
|
|
681
|
+
enabled: true,
|
|
682
|
+
units: ["rpx"],
|
|
683
|
+
overwrite: _optionalChain([patch, 'optionalAccess', _32 => _32.overwrite])
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
return {
|
|
687
|
+
exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _33 => _33.exportContext]), () => ( true)),
|
|
688
|
+
extendLengthUnits: extendOption
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
function fromLegacyOptions(options) {
|
|
692
|
+
if (!options) {
|
|
693
|
+
return {};
|
|
694
|
+
}
|
|
695
|
+
const patch = options.patch;
|
|
696
|
+
const features = normalizeLegacyFeatures(patch);
|
|
697
|
+
const output = _optionalChain([patch, 'optionalAccess', _34 => _34.output]);
|
|
698
|
+
const tailwindConfig = _optionalChain([patch, 'optionalAccess', _35 => _35.tailwindcss]);
|
|
699
|
+
const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _36 => _36.version]);
|
|
700
|
+
const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _37 => _37.v2]);
|
|
701
|
+
const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _38 => _38.v3]);
|
|
702
|
+
const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _39 => _39.v4]);
|
|
703
|
+
const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _40 => _40.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _41 => _41.config])));
|
|
704
|
+
const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _42 => _42.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _43 => _43.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _44 => _44.cwd])));
|
|
705
|
+
return {
|
|
706
|
+
cwd: _optionalChain([patch, 'optionalAccess', _45 => _45.cwd]),
|
|
707
|
+
overwrite: _optionalChain([patch, 'optionalAccess', _46 => _46.overwrite]),
|
|
708
|
+
filter: _optionalChain([patch, 'optionalAccess', _47 => _47.filter]),
|
|
709
|
+
cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
|
|
710
|
+
...options.cache,
|
|
711
|
+
enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
|
|
712
|
+
} : void 0,
|
|
713
|
+
output: output ? {
|
|
714
|
+
file: output.filename,
|
|
715
|
+
pretty: output.loose ? 2 : false,
|
|
716
|
+
removeUniversalSelector: output.removeUniversalSelector
|
|
717
|
+
} : void 0,
|
|
718
|
+
tailwind: {
|
|
719
|
+
packageName: _optionalChain([patch, 'optionalAccess', _48 => _48.packageName]),
|
|
720
|
+
version: tailwindVersion,
|
|
721
|
+
resolve: _optionalChain([patch, 'optionalAccess', _49 => _49.resolve]),
|
|
722
|
+
config: tailwindConfigPath,
|
|
723
|
+
cwd: tailwindCwd,
|
|
724
|
+
v2: tailwindV2,
|
|
725
|
+
v3: tailwindV3,
|
|
726
|
+
v4: tailwindV4
|
|
727
|
+
},
|
|
728
|
+
features: {
|
|
729
|
+
exposeContext: features.exposeContext,
|
|
730
|
+
extendLengthUnits: features.extendLengthUnits
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
function fromUnifiedConfig(registry) {
|
|
735
|
+
if (!registry) {
|
|
736
|
+
return {};
|
|
737
|
+
}
|
|
738
|
+
const tailwind = registry.tailwind;
|
|
739
|
+
const output = registry.output;
|
|
740
|
+
const pretty = (() => {
|
|
741
|
+
if (_optionalChain([output, 'optionalAccess', _50 => _50.pretty]) === void 0) {
|
|
742
|
+
return void 0;
|
|
743
|
+
}
|
|
744
|
+
if (typeof output.pretty === "boolean") {
|
|
745
|
+
return output.pretty ? 2 : false;
|
|
746
|
+
}
|
|
747
|
+
return output.pretty;
|
|
748
|
+
})();
|
|
749
|
+
return {
|
|
750
|
+
output: output ? {
|
|
751
|
+
file: output.file,
|
|
752
|
+
pretty,
|
|
753
|
+
removeUniversalSelector: output.stripUniversalSelector
|
|
754
|
+
} : void 0,
|
|
755
|
+
tailwind: tailwind ? {
|
|
756
|
+
version: tailwind.version,
|
|
757
|
+
packageName: tailwind.package,
|
|
758
|
+
resolve: tailwind.resolve,
|
|
759
|
+
config: tailwind.config,
|
|
760
|
+
cwd: tailwind.cwd,
|
|
761
|
+
v2: tailwind.legacy,
|
|
762
|
+
v3: tailwind.classic,
|
|
763
|
+
v4: tailwind.next
|
|
764
|
+
} : void 0
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
|
|
740
768
|
// src/patching/operations/export-context/index.ts
|
|
741
769
|
|
|
742
770
|
|
|
@@ -778,9 +806,9 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
|
|
|
778
806
|
});
|
|
779
807
|
let hasPatched = false;
|
|
780
808
|
traverse(ast, {
|
|
781
|
-
FunctionDeclaration(
|
|
782
|
-
const node =
|
|
783
|
-
if (_optionalChain([node, 'access',
|
|
809
|
+
FunctionDeclaration(path10) {
|
|
810
|
+
const node = path10.node;
|
|
811
|
+
if (_optionalChain([node, 'access', _51 => _51.id, 'optionalAccess', _52 => _52.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
|
|
784
812
|
return;
|
|
785
813
|
}
|
|
786
814
|
const returnStatement3 = node.body.body[0];
|
|
@@ -810,10 +838,10 @@ function transformPostcssPluginV2(content, options) {
|
|
|
810
838
|
const ast = _parser.parse.call(void 0, content);
|
|
811
839
|
let hasPatched = false;
|
|
812
840
|
traverse(ast, {
|
|
813
|
-
Program(
|
|
814
|
-
const program =
|
|
841
|
+
Program(path10) {
|
|
842
|
+
const program = path10.node;
|
|
815
843
|
const index = program.body.findIndex((statement) => {
|
|
816
|
-
return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access',
|
|
844
|
+
return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _53 => _53.id, 'optionalAccess', _54 => _54.name]) === "_default";
|
|
817
845
|
});
|
|
818
846
|
if (index === -1) {
|
|
819
847
|
return;
|
|
@@ -845,12 +873,12 @@ function transformPostcssPluginV2(content, options) {
|
|
|
845
873
|
);
|
|
846
874
|
}
|
|
847
875
|
},
|
|
848
|
-
FunctionDeclaration(
|
|
876
|
+
FunctionDeclaration(path10) {
|
|
849
877
|
if (hasPatched) {
|
|
850
878
|
return;
|
|
851
879
|
}
|
|
852
|
-
const fn =
|
|
853
|
-
if (_optionalChain([fn, 'access',
|
|
880
|
+
const fn = path10.node;
|
|
881
|
+
if (_optionalChain([fn, 'access', _55 => _55.id, 'optionalAccess', _56 => _56.name]) !== "_default") {
|
|
854
882
|
return;
|
|
855
883
|
}
|
|
856
884
|
if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
|
|
@@ -938,9 +966,9 @@ function transformProcessTailwindFeaturesReturnContext(content) {
|
|
|
938
966
|
const ast = _parser.parse.call(void 0, content);
|
|
939
967
|
let hasPatched = false;
|
|
940
968
|
traverse(ast, {
|
|
941
|
-
FunctionDeclaration(
|
|
942
|
-
const node =
|
|
943
|
-
if (_optionalChain([node, 'access',
|
|
969
|
+
FunctionDeclaration(path10) {
|
|
970
|
+
const node = path10.node;
|
|
971
|
+
if (_optionalChain([node, 'access', _57 => _57.id, 'optionalAccess', _58 => _58.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
|
|
944
972
|
return;
|
|
945
973
|
}
|
|
946
974
|
const [returnStatement3] = node.body.body;
|
|
@@ -971,10 +999,10 @@ function transformPostcssPlugin(content, { refProperty }) {
|
|
|
971
999
|
const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
|
|
972
1000
|
let hasPatched = false;
|
|
973
1001
|
traverse(ast, {
|
|
974
|
-
Program(
|
|
975
|
-
const program =
|
|
1002
|
+
Program(path10) {
|
|
1003
|
+
const program = path10.node;
|
|
976
1004
|
const index = program.body.findIndex((statement) => {
|
|
977
|
-
return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access',
|
|
1005
|
+
return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _59 => _59.expression, 'access', _60 => _60.right, 'access', _61 => _61.id, 'optionalAccess', _62 => _62.name]) === "tailwindcss";
|
|
978
1006
|
});
|
|
979
1007
|
if (index === -1) {
|
|
980
1008
|
return;
|
|
@@ -1010,12 +1038,12 @@ function transformPostcssPlugin(content, { refProperty }) {
|
|
|
1010
1038
|
);
|
|
1011
1039
|
}
|
|
1012
1040
|
},
|
|
1013
|
-
FunctionExpression(
|
|
1041
|
+
FunctionExpression(path10) {
|
|
1014
1042
|
if (hasPatched) {
|
|
1015
1043
|
return;
|
|
1016
1044
|
}
|
|
1017
|
-
const fn =
|
|
1018
|
-
if (_optionalChain([fn, 'access',
|
|
1045
|
+
const fn = path10.node;
|
|
1046
|
+
if (_optionalChain([fn, 'access', _63 => _63.id, 'optionalAccess', _64 => _64.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
|
|
1019
1047
|
return;
|
|
1020
1048
|
}
|
|
1021
1049
|
const [returnStatement3] = fn.body.body;
|
|
@@ -1180,21 +1208,21 @@ function updateLengthUnitsArray(content, options) {
|
|
|
1180
1208
|
let arrayRef;
|
|
1181
1209
|
let changed = false;
|
|
1182
1210
|
traverse(ast, {
|
|
1183
|
-
Identifier(
|
|
1184
|
-
if (
|
|
1185
|
-
arrayRef =
|
|
1211
|
+
Identifier(path10) {
|
|
1212
|
+
if (path10.node.name === variableName && t3.isVariableDeclarator(path10.parent) && t3.isArrayExpression(path10.parent.init)) {
|
|
1213
|
+
arrayRef = path10.parent.init;
|
|
1186
1214
|
const existing = new Set(
|
|
1187
|
-
|
|
1215
|
+
path10.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
|
|
1188
1216
|
);
|
|
1189
1217
|
for (const unit of units) {
|
|
1190
1218
|
if (!existing.has(unit)) {
|
|
1191
|
-
|
|
1219
|
+
path10.parent.init.elements = path10.parent.init.elements.map((element) => {
|
|
1192
1220
|
if (t3.isStringLiteral(element)) {
|
|
1193
1221
|
return t3.stringLiteral(element.value);
|
|
1194
1222
|
}
|
|
1195
1223
|
return element;
|
|
1196
1224
|
});
|
|
1197
|
-
|
|
1225
|
+
path10.parent.init.elements.push(t3.stringLiteral(unit));
|
|
1198
1226
|
changed = true;
|
|
1199
1227
|
}
|
|
1200
1228
|
}
|
|
@@ -1275,13 +1303,13 @@ function applyExtendLengthUnitsPatchV4(rootDir, options) {
|
|
|
1275
1303
|
const { code, file, match } = item;
|
|
1276
1304
|
const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
|
|
1277
1305
|
traverse(ast, {
|
|
1278
|
-
ArrayExpression(
|
|
1306
|
+
ArrayExpression(path10) {
|
|
1279
1307
|
for (const unit of opts.units) {
|
|
1280
|
-
if (
|
|
1308
|
+
if (path10.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
|
|
1281
1309
|
item.hasPatched = true;
|
|
1282
1310
|
return;
|
|
1283
1311
|
}
|
|
1284
|
-
|
|
1312
|
+
path10.node.elements.push(t3.stringLiteral(unit));
|
|
1285
1313
|
}
|
|
1286
1314
|
}
|
|
1287
1315
|
});
|
|
@@ -1323,7 +1351,7 @@ function applyTailwindPatches(context) {
|
|
|
1323
1351
|
majorVersion
|
|
1324
1352
|
});
|
|
1325
1353
|
}
|
|
1326
|
-
if (_optionalChain([options, 'access',
|
|
1354
|
+
if (_optionalChain([options, 'access', _65 => _65.features, 'access', _66 => _66.extendLengthUnits, 'optionalAccess', _67 => _67.enabled])) {
|
|
1327
1355
|
if (majorVersion === 3) {
|
|
1328
1356
|
results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
|
|
1329
1357
|
packageInfo.rootPath,
|
|
@@ -1489,7 +1517,7 @@ var TailwindcssPatcher = (_class = class {
|
|
|
1489
1517
|
return this.mergeWithCacheSync(set);
|
|
1490
1518
|
}
|
|
1491
1519
|
async extract(options) {
|
|
1492
|
-
const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1520
|
+
const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.write]), () => ( this.options.output.enabled));
|
|
1493
1521
|
const classSet = await this.getClassSet();
|
|
1494
1522
|
const classList = Array.from(classSet);
|
|
1495
1523
|
const result = {
|
|
@@ -1518,22 +1546,304 @@ var TailwindcssPatcher = (_class = class {
|
|
|
1518
1546
|
__init() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
|
|
1519
1547
|
async collectContentTokens(options) {
|
|
1520
1548
|
return extractProjectCandidatesWithPositions({
|
|
1521
|
-
cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1522
|
-
sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
1549
|
+
cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _69 => _69.cwd]), () => ( this.options.projectRoot)),
|
|
1550
|
+
sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _70 => _70.sources]), () => ( _optionalChain([this, 'access', _71 => _71.options, 'access', _72 => _72.tailwind, 'access', _73 => _73.v4, 'optionalAccess', _74 => _74.sources]))), () => ( []))
|
|
1523
1551
|
});
|
|
1524
1552
|
}
|
|
1525
1553
|
async collectContentTokensByFile(options) {
|
|
1526
1554
|
const report = await this.collectContentTokens({
|
|
1527
|
-
cwd: _optionalChain([options, 'optionalAccess',
|
|
1528
|
-
sources: _optionalChain([options, 'optionalAccess',
|
|
1555
|
+
cwd: _optionalChain([options, 'optionalAccess', _75 => _75.cwd]),
|
|
1556
|
+
sources: _optionalChain([options, 'optionalAccess', _76 => _76.sources])
|
|
1529
1557
|
});
|
|
1530
1558
|
return groupTokensByFile(report, {
|
|
1531
|
-
key: _optionalChain([options, 'optionalAccess',
|
|
1532
|
-
stripAbsolutePaths: _optionalChain([options, 'optionalAccess',
|
|
1559
|
+
key: _optionalChain([options, 'optionalAccess', _77 => _77.key]),
|
|
1560
|
+
stripAbsolutePaths: _optionalChain([options, 'optionalAccess', _78 => _78.stripAbsolutePaths])
|
|
1533
1561
|
});
|
|
1534
1562
|
}
|
|
1535
1563
|
}, _class);
|
|
1536
1564
|
|
|
1565
|
+
// src/cli/commands.ts
|
|
1566
|
+
|
|
1567
|
+
var _config = require('@tailwindcss-mangle/config');
|
|
1568
|
+
|
|
1569
|
+
// ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
|
|
1570
|
+
function isPlainObject(value) {
|
|
1571
|
+
if (value === null || typeof value !== "object") {
|
|
1572
|
+
return false;
|
|
1573
|
+
}
|
|
1574
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1575
|
+
if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
|
|
1576
|
+
return false;
|
|
1577
|
+
}
|
|
1578
|
+
if (Symbol.iterator in value) {
|
|
1579
|
+
return false;
|
|
1580
|
+
}
|
|
1581
|
+
if (Symbol.toStringTag in value) {
|
|
1582
|
+
return Object.prototype.toString.call(value) === "[object Module]";
|
|
1583
|
+
}
|
|
1584
|
+
return true;
|
|
1585
|
+
}
|
|
1586
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
1587
|
+
if (!isPlainObject(defaults)) {
|
|
1588
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
1589
|
+
}
|
|
1590
|
+
const object = Object.assign({}, defaults);
|
|
1591
|
+
for (const key in baseObject) {
|
|
1592
|
+
if (key === "__proto__" || key === "constructor") {
|
|
1593
|
+
continue;
|
|
1594
|
+
}
|
|
1595
|
+
const value = baseObject[key];
|
|
1596
|
+
if (value === null || value === void 0) {
|
|
1597
|
+
continue;
|
|
1598
|
+
}
|
|
1599
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
1600
|
+
continue;
|
|
1601
|
+
}
|
|
1602
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
1603
|
+
object[key] = [...value, ...object[key]];
|
|
1604
|
+
} else if (isPlainObject(value) && isPlainObject(object[key])) {
|
|
1605
|
+
object[key] = _defu(
|
|
1606
|
+
value,
|
|
1607
|
+
object[key],
|
|
1608
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
1609
|
+
merger
|
|
1610
|
+
);
|
|
1611
|
+
} else {
|
|
1612
|
+
object[key] = value;
|
|
1613
|
+
}
|
|
1614
|
+
}
|
|
1615
|
+
return object;
|
|
1616
|
+
}
|
|
1617
|
+
function createDefu(merger) {
|
|
1618
|
+
return (...arguments_) => (
|
|
1619
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
1620
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
1621
|
+
);
|
|
1622
|
+
}
|
|
1623
|
+
var defu = createDefu();
|
|
1624
|
+
var defuFn = createDefu((object, key, currentValue) => {
|
|
1625
|
+
if (object[key] !== void 0 && typeof currentValue === "function") {
|
|
1626
|
+
object[key] = currentValue(object[key]);
|
|
1627
|
+
return true;
|
|
1628
|
+
}
|
|
1629
|
+
});
|
|
1630
|
+
var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
1631
|
+
if (Array.isArray(object[key]) && typeof currentValue === "function") {
|
|
1632
|
+
object[key] = currentValue(object[key]);
|
|
1633
|
+
return true;
|
|
1634
|
+
}
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
// ../shared/src/utils.ts
|
|
1638
|
+
var defuOverrideArray = createDefu((obj, key, value) => {
|
|
1639
|
+
if (Array.isArray(obj[key]) && Array.isArray(value)) {
|
|
1640
|
+
obj[key] = value;
|
|
1641
|
+
return true;
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
var preserveClassNames = [
|
|
1645
|
+
// https://tailwindcss.com/docs/transition-timing-function start
|
|
1646
|
+
// https://github.com/sonofmagic/tailwindcss-mangle/issues/21
|
|
1647
|
+
"ease-out",
|
|
1648
|
+
"ease-linear",
|
|
1649
|
+
"ease-in",
|
|
1650
|
+
"ease-in-out"
|
|
1651
|
+
// https://tailwindcss.com/docs/transition-timing-function end
|
|
1652
|
+
];
|
|
1653
|
+
var preserveClassNamesMap = preserveClassNames.reduce((acc, cur) => {
|
|
1654
|
+
acc[cur] = true;
|
|
1655
|
+
return acc;
|
|
1656
|
+
}, {});
|
|
1657
|
+
var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
|
|
1658
|
+
|
|
1659
|
+
// src/cli/commands.ts
|
|
1660
|
+
var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
|
|
1661
|
+
|
|
1662
|
+
|
|
1663
|
+
var tailwindcssPatchCommands = [
|
|
1664
|
+
"install",
|
|
1665
|
+
"extract",
|
|
1666
|
+
"tokens",
|
|
1667
|
+
"init"
|
|
1668
|
+
];
|
|
1669
|
+
function createTailwindcssPatchCli(options = {}) {
|
|
1670
|
+
const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
|
|
1671
|
+
mountTailwindcssPatchCommands(cli, options.mountOptions);
|
|
1672
|
+
return cli;
|
|
1673
|
+
}
|
|
1674
|
+
function mountTailwindcssPatchCommands(cli, options = {}) {
|
|
1675
|
+
const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
|
|
1676
|
+
const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
|
|
1677
|
+
const TOKEN_FORMATS = ["json", "lines", "grouped-json"];
|
|
1678
|
+
const registrars = {
|
|
1679
|
+
install() {
|
|
1680
|
+
const { name, aliases } = resolveCommandNames("install", options, prefix);
|
|
1681
|
+
const command = cli.command(name, "Apply Tailwind CSS runtime patches").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).action(async (args) => {
|
|
1682
|
+
const patchOptions = await loadPatchOptions(args.cwd);
|
|
1683
|
+
const patcher = new TailwindcssPatcher(patchOptions);
|
|
1684
|
+
await patcher.patch();
|
|
1685
|
+
logger_default.success("Tailwind CSS runtime patched successfully.");
|
|
1686
|
+
});
|
|
1687
|
+
aliases.forEach((alias) => command.alias(alias));
|
|
1688
|
+
},
|
|
1689
|
+
extract() {
|
|
1690
|
+
const { name, aliases } = resolveCommandNames("extract", options, prefix);
|
|
1691
|
+
const command = cli.command(name, "Collect generated class names into a cache file").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).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(async (args) => {
|
|
1692
|
+
const overrides = {};
|
|
1693
|
+
if (args.output || args.format) {
|
|
1694
|
+
overrides.output = {
|
|
1695
|
+
file: args.output,
|
|
1696
|
+
format: args.format
|
|
1697
|
+
};
|
|
1698
|
+
}
|
|
1699
|
+
if (args.css) {
|
|
1700
|
+
overrides.tailwind = {
|
|
1701
|
+
v4: {
|
|
1702
|
+
cssEntries: [args.css]
|
|
1703
|
+
}
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
const patchOptions = await loadPatchOptions(args.cwd, overrides);
|
|
1707
|
+
const patcher = new TailwindcssPatcher(patchOptions);
|
|
1708
|
+
const result = await patcher.extract({ write: args.write });
|
|
1709
|
+
if (result.filename) {
|
|
1710
|
+
logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
|
|
1711
|
+
} else {
|
|
1712
|
+
logger_default.success(`Collected ${result.classList.length} classes.`);
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
aliases.forEach((alias) => command.alias(alias));
|
|
1716
|
+
},
|
|
1717
|
+
tokens() {
|
|
1718
|
+
const { name, aliases } = resolveCommandNames("tokens", options, prefix);
|
|
1719
|
+
const command = cli.command(name, "Extract Tailwind tokens with file/position metadata").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).option("--output <file>", "Override output file path", { default: ".tw-patch/tw-token-report.json" }).option("--format <format>", "Output format (json|lines|grouped-json)", { default: "json" }).option("--group-key <key>", "Grouping key for grouped-json output (relative|absolute)", { default: "relative" }).option("--no-write", "Skip writing to disk").action(async (args) => {
|
|
1720
|
+
const patchOptions = await loadPatchOptions(args.cwd);
|
|
1721
|
+
const patcher = new TailwindcssPatcher(patchOptions);
|
|
1722
|
+
const report = await patcher.collectContentTokens();
|
|
1723
|
+
const shouldWrite = _nullishCoalesce(args.write, () => ( true));
|
|
1724
|
+
let format = _nullishCoalesce(args.format, () => ( "json"));
|
|
1725
|
+
if (!TOKEN_FORMATS.includes(format)) {
|
|
1726
|
+
format = "json";
|
|
1727
|
+
}
|
|
1728
|
+
const targetFile = _nullishCoalesce(args.output, () => ( ".tw-patch/tw-token-report.json"));
|
|
1729
|
+
const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
|
|
1730
|
+
const buildGrouped = () => groupTokensByFile(report, {
|
|
1731
|
+
key: groupKey,
|
|
1732
|
+
stripAbsolutePaths: groupKey !== "absolute"
|
|
1733
|
+
});
|
|
1734
|
+
const grouped = format === "grouped-json" ? buildGrouped() : null;
|
|
1735
|
+
const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
|
|
1736
|
+
if (shouldWrite) {
|
|
1737
|
+
const target = _pathe2.default.resolve(targetFile);
|
|
1738
|
+
await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
|
|
1739
|
+
if (format === "json") {
|
|
1740
|
+
await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
|
|
1741
|
+
} else if (format === "grouped-json") {
|
|
1742
|
+
await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
|
|
1743
|
+
} else {
|
|
1744
|
+
const lines = report.entries.map(formatTokenLine);
|
|
1745
|
+
await _fsextra2.default.writeFile(target, `${lines.join("\n")}
|
|
1746
|
+
`, "utf8");
|
|
1747
|
+
}
|
|
1748
|
+
logger_default.success(
|
|
1749
|
+
`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`
|
|
1750
|
+
);
|
|
1751
|
+
} else {
|
|
1752
|
+
logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
|
|
1753
|
+
if (format === "lines") {
|
|
1754
|
+
const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
|
|
1755
|
+
if (preview) {
|
|
1756
|
+
logger_default.log("");
|
|
1757
|
+
logger_default.info(preview);
|
|
1758
|
+
if (report.entries.length > 5) {
|
|
1759
|
+
logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1762
|
+
} else if (format === "grouped-json") {
|
|
1763
|
+
const map = resolveGrouped();
|
|
1764
|
+
const { preview, moreFiles } = formatGroupedPreview(map);
|
|
1765
|
+
if (preview) {
|
|
1766
|
+
logger_default.log("");
|
|
1767
|
+
logger_default.info(preview);
|
|
1768
|
+
if (moreFiles > 0) {
|
|
1769
|
+
logger_default.info(`\u2026and ${moreFiles} more files.`);
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
} else {
|
|
1773
|
+
const previewEntries = report.entries.slice(0, 3);
|
|
1774
|
+
if (previewEntries.length) {
|
|
1775
|
+
logger_default.log("");
|
|
1776
|
+
logger_default.info(JSON.stringify(previewEntries, null, 2));
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
}
|
|
1780
|
+
if (report.skippedFiles.length) {
|
|
1781
|
+
logger_default.warn("Skipped files:");
|
|
1782
|
+
for (const skipped of report.skippedFiles) {
|
|
1783
|
+
logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
|
|
1784
|
+
}
|
|
1785
|
+
}
|
|
1786
|
+
});
|
|
1787
|
+
aliases.forEach((alias) => command.alias(alias));
|
|
1788
|
+
},
|
|
1789
|
+
init() {
|
|
1790
|
+
const { name, aliases } = resolveCommandNames("init", options, prefix);
|
|
1791
|
+
const command = cli.command(name, "Generate a tailwindcss-patch config file").option("--cwd <dir>", "Working directory", { default: _process2.default.cwd() }).action(async (args) => {
|
|
1792
|
+
await _config.initConfig.call(void 0, args.cwd);
|
|
1793
|
+
logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
|
|
1794
|
+
});
|
|
1795
|
+
aliases.forEach((alias) => command.alias(alias));
|
|
1796
|
+
}
|
|
1797
|
+
};
|
|
1798
|
+
for (const name of selectedCommands) {
|
|
1799
|
+
const register = registrars[name];
|
|
1800
|
+
if (register) {
|
|
1801
|
+
register();
|
|
1802
|
+
}
|
|
1803
|
+
}
|
|
1804
|
+
return cli;
|
|
1805
|
+
}
|
|
1806
|
+
async function loadPatchOptions(cwd, overrides) {
|
|
1807
|
+
const { config } = await _config.getConfig.call(void 0, cwd);
|
|
1808
|
+
const legacyConfig = config;
|
|
1809
|
+
const base = _optionalChain([config, 'optionalAccess', _79 => _79.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _80 => _80.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
|
|
1810
|
+
const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
|
|
1811
|
+
return merged;
|
|
1812
|
+
}
|
|
1813
|
+
function resolveCommandNames(command, mountOptions, prefix) {
|
|
1814
|
+
const override = _optionalChain([mountOptions, 'access', _81 => _81.commandOptions, 'optionalAccess', _82 => _82[command]]);
|
|
1815
|
+
const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _83 => _83.name]), () => ( command));
|
|
1816
|
+
const name = addPrefixIfMissing(baseName, prefix);
|
|
1817
|
+
const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _84 => _84.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
|
|
1818
|
+
return { name, aliases };
|
|
1819
|
+
}
|
|
1820
|
+
function addPrefixIfMissing(value, prefix) {
|
|
1821
|
+
if (!prefix || value.startsWith(prefix)) {
|
|
1822
|
+
return value;
|
|
1823
|
+
}
|
|
1824
|
+
return `${prefix}${value}`;
|
|
1825
|
+
}
|
|
1826
|
+
function formatTokenLine(entry) {
|
|
1827
|
+
return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
|
|
1828
|
+
}
|
|
1829
|
+
function formatGroupedPreview(map, limit = 3) {
|
|
1830
|
+
const files = Object.keys(map);
|
|
1831
|
+
if (!files.length) {
|
|
1832
|
+
return { preview: "", moreFiles: 0 };
|
|
1833
|
+
}
|
|
1834
|
+
const lines = files.slice(0, limit).map((file) => {
|
|
1835
|
+
const tokens = map[file];
|
|
1836
|
+
const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
|
|
1837
|
+
const suffix = tokens.length > 3 ? ", \u2026" : "";
|
|
1838
|
+
return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
|
|
1839
|
+
});
|
|
1840
|
+
return {
|
|
1841
|
+
preview: lines.join("\n"),
|
|
1842
|
+
moreFiles: Math.max(0, files.length - limit)
|
|
1843
|
+
};
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
|
|
1537
1847
|
|
|
1538
1848
|
|
|
1539
1849
|
|
|
@@ -1550,4 +1860,4 @@ var TailwindcssPatcher = (_class = class {
|
|
|
1550
1860
|
|
|
1551
1861
|
|
|
1552
1862
|
|
|
1553
|
-
exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.
|
|
1863
|
+
exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.normalizeOptions = normalizeOptions; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli; exports.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands;
|