tailwindcss-patch 8.2.4 → 8.4.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.
@@ -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', _27 => _27.enabled]), () => ( true));
435
- const file = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _28 => _28.file]), () => ( ".tw-patch/tw-class-list.json"));
436
- const format = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _29 => _29.format]), () => ( "json"));
437
- const pretty = toPrettyValue(_nullishCoalesce(_optionalChain([output, 'optionalAccess', _30 => _30.pretty]), () => ( true)));
438
- const removeUniversalSelector = _nullishCoalesce(_optionalChain([output, 'optionalAccess', _31 => _31.removeUniversalSelector]), () => ( true));
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', _32 => _32.exposeContext]) === false) {
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', _33 => _33.exposeContext]) === "object" && features.exposeContext) {
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', _34 => _34.extendLengthUnits]);
367
+ const extend = _optionalChain([features, 'optionalAccess', _13 => _13.extendLengthUnits]);
467
368
  if (extend === false || extend === void 0) {
468
369
  return null;
469
370
  }
@@ -483,11 +384,11 @@ function normalizeExtendLengthUnitsOptions(features) {
483
384
  };
484
385
  }
485
386
  function normalizeTailwindV4Options(v4, fallbackBase) {
486
- const configuredBase = _optionalChain([v4, 'optionalAccess', _35 => _35.base]) ? _pathe2.default.resolve(v4.base) : void 0;
387
+ const configuredBase = _optionalChain([v4, 'optionalAccess', _14 => _14.base]) ? _pathe2.default.resolve(v4.base) : void 0;
487
388
  const base = _nullishCoalesce(configuredBase, () => ( fallbackBase));
488
- const cssEntries = Array.isArray(_optionalChain([v4, 'optionalAccess', _36 => _36.cssEntries])) ? v4.cssEntries.filter((entry) => Boolean(entry)).map((entry) => _pathe2.default.resolve(entry)) : [];
489
- const userSources = _optionalChain([v4, 'optionalAccess', _37 => _37.sources]);
490
- const hasUserDefinedSources = Boolean(_optionalChain([userSources, 'optionalAccess', _38 => _38.length]));
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]));
491
392
  const sources = hasUserDefinedSources ? userSources : [
492
393
  {
493
394
  base,
@@ -498,20 +399,20 @@ function normalizeTailwindV4Options(v4, fallbackBase) {
498
399
  return {
499
400
  base,
500
401
  configuredBase,
501
- css: _optionalChain([v4, 'optionalAccess', _39 => _39.css]),
402
+ css: _optionalChain([v4, 'optionalAccess', _18 => _18.css]),
502
403
  cssEntries,
503
404
  sources,
504
405
  hasUserDefinedSources
505
406
  };
506
407
  }
507
408
  function normalizeTailwindOptions(tailwind, projectRoot) {
508
- const packageName = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _40 => _40.packageName]), () => ( "tailwindcss"));
509
- const versionHint = _optionalChain([tailwind, 'optionalAccess', _41 => _41.version]);
510
- const resolve = _optionalChain([tailwind, 'optionalAccess', _42 => _42.resolve]);
511
- const cwd = _nullishCoalesce(_optionalChain([tailwind, 'optionalAccess', _43 => _43.cwd]), () => ( projectRoot));
512
- const config = _optionalChain([tailwind, 'optionalAccess', _44 => _44.config]);
513
- const postcssPlugin = _optionalChain([tailwind, 'optionalAccess', _45 => _45.postcssPlugin]);
514
- const v4 = normalizeTailwindV4Options(_optionalChain([tailwind, 'optionalAccess', _46 => _46.v4]), cwd);
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);
515
416
  return {
516
417
  packageName,
517
418
  versionHint,
@@ -519,8 +420,8 @@ function normalizeTailwindOptions(tailwind, projectRoot) {
519
420
  cwd,
520
421
  config,
521
422
  postcssPlugin,
522
- v2: _optionalChain([tailwind, 'optionalAccess', _47 => _47.v2]),
523
- v3: _optionalChain([tailwind, 'optionalAccess', _48 => _48.v3]),
423
+ v2: _optionalChain([tailwind, 'optionalAccess', _26 => _26.v2]),
424
+ v3: _optionalChain([tailwind, 'optionalAccess', _27 => _27.v3]),
524
425
  v4
525
426
  };
526
427
  }
@@ -616,7 +517,7 @@ async function collectClassesFromTailwindV4(options) {
616
517
  const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
617
518
  const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
618
519
  const resolveSources = (base) => {
619
- if (!_optionalChain([v4Options, 'access', _49 => _49.sources, 'optionalAccess', _50 => _50.length])) {
520
+ if (!_optionalChain([v4Options, 'access', _28 => _28.sources, 'optionalAccess', _29 => _29.length])) {
620
521
  return void 0;
621
522
  }
622
523
  if (!v4Options.hasUserDefinedSources && !resolvedConfiguredBase) {
@@ -765,6 +666,105 @@ var _localpkg = require('local-pkg');
765
666
 
766
667
  var _semver = require('semver');
767
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
+
768
768
  // src/patching/operations/export-context/index.ts
769
769
 
770
770
 
@@ -806,8 +806,8 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
806
806
  });
807
807
  let hasPatched = false;
808
808
  traverse(ast, {
809
- FunctionDeclaration(path9) {
810
- const node = path9.node;
809
+ FunctionDeclaration(path10) {
810
+ const node = path10.node;
811
811
  if (_optionalChain([node, 'access', _51 => _51.id, 'optionalAccess', _52 => _52.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
812
812
  return;
813
813
  }
@@ -838,8 +838,8 @@ function transformPostcssPluginV2(content, options) {
838
838
  const ast = _parser.parse.call(void 0, content);
839
839
  let hasPatched = false;
840
840
  traverse(ast, {
841
- Program(path9) {
842
- const program = path9.node;
841
+ Program(path10) {
842
+ const program = path10.node;
843
843
  const index = program.body.findIndex((statement) => {
844
844
  return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _53 => _53.id, 'optionalAccess', _54 => _54.name]) === "_default";
845
845
  });
@@ -873,11 +873,11 @@ function transformPostcssPluginV2(content, options) {
873
873
  );
874
874
  }
875
875
  },
876
- FunctionDeclaration(path9) {
876
+ FunctionDeclaration(path10) {
877
877
  if (hasPatched) {
878
878
  return;
879
879
  }
880
- const fn = path9.node;
880
+ const fn = path10.node;
881
881
  if (_optionalChain([fn, 'access', _55 => _55.id, 'optionalAccess', _56 => _56.name]) !== "_default") {
882
882
  return;
883
883
  }
@@ -966,8 +966,8 @@ function transformProcessTailwindFeaturesReturnContext(content) {
966
966
  const ast = _parser.parse.call(void 0, content);
967
967
  let hasPatched = false;
968
968
  traverse(ast, {
969
- FunctionDeclaration(path9) {
970
- const node = path9.node;
969
+ FunctionDeclaration(path10) {
970
+ const node = path10.node;
971
971
  if (_optionalChain([node, 'access', _57 => _57.id, 'optionalAccess', _58 => _58.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
972
972
  return;
973
973
  }
@@ -999,8 +999,8 @@ function transformPostcssPlugin(content, { refProperty }) {
999
999
  const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
1000
1000
  let hasPatched = false;
1001
1001
  traverse(ast, {
1002
- Program(path9) {
1003
- const program = path9.node;
1002
+ Program(path10) {
1003
+ const program = path10.node;
1004
1004
  const index = program.body.findIndex((statement) => {
1005
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";
1006
1006
  });
@@ -1038,11 +1038,11 @@ function transformPostcssPlugin(content, { refProperty }) {
1038
1038
  );
1039
1039
  }
1040
1040
  },
1041
- FunctionExpression(path9) {
1041
+ FunctionExpression(path10) {
1042
1042
  if (hasPatched) {
1043
1043
  return;
1044
1044
  }
1045
- const fn = path9.node;
1045
+ const fn = path10.node;
1046
1046
  if (_optionalChain([fn, 'access', _63 => _63.id, 'optionalAccess', _64 => _64.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
1047
1047
  return;
1048
1048
  }
@@ -1208,21 +1208,21 @@ function updateLengthUnitsArray(content, options) {
1208
1208
  let arrayRef;
1209
1209
  let changed = false;
1210
1210
  traverse(ast, {
1211
- Identifier(path9) {
1212
- if (path9.node.name === variableName && t3.isVariableDeclarator(path9.parent) && t3.isArrayExpression(path9.parent.init)) {
1213
- arrayRef = path9.parent.init;
1211
+ Identifier(path10) {
1212
+ if (path10.node.name === variableName && t3.isVariableDeclarator(path10.parent) && t3.isArrayExpression(path10.parent.init)) {
1213
+ arrayRef = path10.parent.init;
1214
1214
  const existing = new Set(
1215
- path9.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
1215
+ path10.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
1216
1216
  );
1217
1217
  for (const unit of units) {
1218
1218
  if (!existing.has(unit)) {
1219
- path9.parent.init.elements = path9.parent.init.elements.map((element) => {
1219
+ path10.parent.init.elements = path10.parent.init.elements.map((element) => {
1220
1220
  if (t3.isStringLiteral(element)) {
1221
1221
  return t3.stringLiteral(element.value);
1222
1222
  }
1223
1223
  return element;
1224
1224
  });
1225
- path9.parent.init.elements.push(t3.stringLiteral(unit));
1225
+ path10.parent.init.elements.push(t3.stringLiteral(unit));
1226
1226
  changed = true;
1227
1227
  }
1228
1228
  }
@@ -1303,13 +1303,13 @@ function applyExtendLengthUnitsPatchV4(rootDir, options) {
1303
1303
  const { code, file, match } = item;
1304
1304
  const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
1305
1305
  traverse(ast, {
1306
- ArrayExpression(path9) {
1306
+ ArrayExpression(path10) {
1307
1307
  for (const unit of opts.units) {
1308
- if (path9.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
1308
+ if (path10.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
1309
1309
  item.hasPatched = true;
1310
1310
  return;
1311
1311
  }
1312
- path9.node.elements.push(t3.stringLiteral(unit));
1312
+ path10.node.elements.push(t3.stringLiteral(unit));
1313
1313
  }
1314
1314
  }
1315
1315
  });
@@ -1562,6 +1562,473 @@ var TailwindcssPatcher = (_class = class {
1562
1562
  }
1563
1563
  }, _class);
1564
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 = ["install", "extract", "tokens", "init"];
1664
+ var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
1665
+ var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
1666
+ function formatTokenLine(entry) {
1667
+ return `${entry.relativeFile}:${entry.line}:${entry.column} ${entry.rawCandidate} (${entry.start}-${entry.end})`;
1668
+ }
1669
+ function formatGroupedPreview(map, limit = 3) {
1670
+ const files = Object.keys(map);
1671
+ if (!files.length) {
1672
+ return { preview: "", moreFiles: 0 };
1673
+ }
1674
+ const lines = files.slice(0, limit).map((file) => {
1675
+ const tokens = map[file];
1676
+ const sample = tokens.slice(0, 3).map((token) => token.rawCandidate).join(", ");
1677
+ const suffix = tokens.length > 3 ? ", \u2026" : "";
1678
+ return `${file}: ${tokens.length} tokens (${sample}${suffix})`;
1679
+ });
1680
+ return {
1681
+ preview: lines.join("\n"),
1682
+ moreFiles: Math.max(0, files.length - limit)
1683
+ };
1684
+ }
1685
+ function resolveCwd(rawCwd) {
1686
+ if (!rawCwd) {
1687
+ return _process2.default.cwd();
1688
+ }
1689
+ return _pathe2.default.resolve(rawCwd);
1690
+ }
1691
+ function createDefaultRunner(factory) {
1692
+ let promise;
1693
+ return () => {
1694
+ if (!promise) {
1695
+ promise = factory();
1696
+ }
1697
+ return promise;
1698
+ };
1699
+ }
1700
+ async function loadPatchOptionsForCwd(cwd, overrides) {
1701
+ const { config } = await _config.getConfig.call(void 0, cwd);
1702
+ const legacyConfig = config;
1703
+ const base = _optionalChain([config, 'optionalAccess', _79 => _79.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _80 => _80.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
1704
+ const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
1705
+ return merged;
1706
+ }
1707
+ function createCommandContext(cli, command, commandName, args, cwd) {
1708
+ let cachedOptions;
1709
+ let cachedPatcher;
1710
+ let cachedConfig;
1711
+ const loadPatchOptionsForContext = (overrides) => {
1712
+ if (overrides) {
1713
+ return loadPatchOptionsForCwd(cwd, overrides);
1714
+ }
1715
+ if (!cachedOptions) {
1716
+ cachedOptions = loadPatchOptionsForCwd(cwd);
1717
+ }
1718
+ return cachedOptions;
1719
+ };
1720
+ const createPatcherForContext = async (overrides) => {
1721
+ if (overrides) {
1722
+ const patchOptions = await loadPatchOptionsForCwd(cwd, overrides);
1723
+ return new TailwindcssPatcher(patchOptions);
1724
+ }
1725
+ if (!cachedPatcher) {
1726
+ cachedPatcher = loadPatchOptionsForContext().then((options) => new TailwindcssPatcher(options));
1727
+ }
1728
+ return cachedPatcher;
1729
+ };
1730
+ return {
1731
+ cli,
1732
+ command,
1733
+ commandName,
1734
+ args,
1735
+ cwd,
1736
+ logger: logger_default,
1737
+ loadConfig: () => {
1738
+ if (!cachedConfig) {
1739
+ cachedConfig = _config.getConfig.call(void 0, cwd);
1740
+ }
1741
+ return cachedConfig;
1742
+ },
1743
+ loadPatchOptions: loadPatchOptionsForContext,
1744
+ createPatcher: createPatcherForContext
1745
+ };
1746
+ }
1747
+ function createCwdOptionDefinition(description = "Working directory") {
1748
+ return {
1749
+ flags: "--cwd <dir>",
1750
+ description,
1751
+ config: { default: _process2.default.cwd() }
1752
+ };
1753
+ }
1754
+ function buildDefaultCommandDefinitions() {
1755
+ return {
1756
+ install: {
1757
+ description: "Apply Tailwind CSS runtime patches",
1758
+ optionDefs: [createCwdOptionDefinition()]
1759
+ },
1760
+ extract: {
1761
+ description: "Collect generated class names into a cache file",
1762
+ optionDefs: [
1763
+ createCwdOptionDefinition(),
1764
+ { flags: "--output <file>", description: "Override output file path" },
1765
+ { flags: "--format <format>", description: "Output format (json|lines)" },
1766
+ { flags: "--css <file>", description: "Tailwind CSS entry CSS when using v4" },
1767
+ { flags: "--no-write", description: "Skip writing to disk" }
1768
+ ]
1769
+ },
1770
+ tokens: {
1771
+ description: "Extract Tailwind tokens with file/position metadata",
1772
+ optionDefs: [
1773
+ createCwdOptionDefinition(),
1774
+ { flags: "--output <file>", description: "Override output file path", config: { default: DEFAULT_TOKEN_REPORT } },
1775
+ {
1776
+ flags: "--format <format>",
1777
+ description: "Output format (json|lines|grouped-json)",
1778
+ config: { default: "json" }
1779
+ },
1780
+ {
1781
+ flags: "--group-key <key>",
1782
+ description: "Grouping key for grouped-json output (relative|absolute)",
1783
+ config: { default: "relative" }
1784
+ },
1785
+ { flags: "--no-write", description: "Skip writing to disk" }
1786
+ ]
1787
+ },
1788
+ init: {
1789
+ description: "Generate a tailwindcss-patch config file",
1790
+ optionDefs: [createCwdOptionDefinition()]
1791
+ }
1792
+ };
1793
+ }
1794
+ function addPrefixIfMissing(value, prefix) {
1795
+ if (!prefix || value.startsWith(prefix)) {
1796
+ return value;
1797
+ }
1798
+ return `${prefix}${value}`;
1799
+ }
1800
+ function resolveCommandNames(command, mountOptions, prefix) {
1801
+ const override = _optionalChain([mountOptions, 'access', _81 => _81.commandOptions, 'optionalAccess', _82 => _82[command]]);
1802
+ const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _83 => _83.name]), () => ( command));
1803
+ const name = addPrefixIfMissing(baseName, prefix);
1804
+ const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _84 => _84.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
1805
+ return { name, aliases };
1806
+ }
1807
+ function resolveOptionDefinitions(defaults, override) {
1808
+ if (!override) {
1809
+ return defaults;
1810
+ }
1811
+ const appendDefaults = _nullishCoalesce(override.appendDefaultOptions, () => ( true));
1812
+ const customDefs = _nullishCoalesce(override.optionDefs, () => ( []));
1813
+ if (!appendDefaults) {
1814
+ return customDefs;
1815
+ }
1816
+ if (customDefs.length === 0) {
1817
+ return defaults;
1818
+ }
1819
+ return [...defaults, ...customDefs];
1820
+ }
1821
+ function applyCommandOptions(command, optionDefs) {
1822
+ for (const option of optionDefs) {
1823
+ command.option(option.flags, _nullishCoalesce(option.description, () => ( "")), option.config);
1824
+ }
1825
+ }
1826
+ function runWithCommandHandler(cli, command, commandName, args, handler, defaultHandler) {
1827
+ const cwd = resolveCwd(args.cwd);
1828
+ const context = createCommandContext(cli, command, commandName, args, cwd);
1829
+ const runDefault = createDefaultRunner(() => defaultHandler(context));
1830
+ if (!handler) {
1831
+ return runDefault();
1832
+ }
1833
+ return handler(context, runDefault);
1834
+ }
1835
+ function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
1836
+ const names = resolveCommandNames(command, mountOptions, prefix);
1837
+ const definition = defaults[command];
1838
+ const override = _optionalChain([mountOptions, 'access', _85 => _85.commandOptions, 'optionalAccess', _86 => _86[command]]);
1839
+ const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.description]), () => ( definition.description));
1840
+ const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
1841
+ return { ...names, description, optionDefs };
1842
+ }
1843
+ async function installCommandDefaultHandler(ctx) {
1844
+ const patcher = await ctx.createPatcher();
1845
+ await patcher.patch();
1846
+ logger_default.success("Tailwind CSS runtime patched successfully.");
1847
+ }
1848
+ async function extractCommandDefaultHandler(ctx) {
1849
+ const { args } = ctx;
1850
+ const overrides = {};
1851
+ let hasOverrides = false;
1852
+ if (args.output || args.format) {
1853
+ overrides.output = {
1854
+ file: args.output,
1855
+ format: args.format
1856
+ };
1857
+ hasOverrides = true;
1858
+ }
1859
+ if (args.css) {
1860
+ overrides.tailwind = {
1861
+ v4: {
1862
+ cssEntries: [args.css]
1863
+ }
1864
+ };
1865
+ hasOverrides = true;
1866
+ }
1867
+ const patcher = await ctx.createPatcher(hasOverrides ? overrides : void 0);
1868
+ const result = await patcher.extract({ write: args.write });
1869
+ if (result.filename) {
1870
+ logger_default.success(`Collected ${result.classList.length} classes \u2192 ${result.filename}`);
1871
+ } else {
1872
+ logger_default.success(`Collected ${result.classList.length} classes.`);
1873
+ }
1874
+ return result;
1875
+ }
1876
+ async function tokensCommandDefaultHandler(ctx) {
1877
+ const { args } = ctx;
1878
+ const patcher = await ctx.createPatcher();
1879
+ const report = await patcher.collectContentTokens();
1880
+ const shouldWrite = _nullishCoalesce(args.write, () => ( true));
1881
+ let format = _nullishCoalesce(args.format, () => ( "json"));
1882
+ if (!TOKEN_FORMATS.includes(format)) {
1883
+ format = "json";
1884
+ }
1885
+ const targetFile = _nullishCoalesce(args.output, () => ( DEFAULT_TOKEN_REPORT));
1886
+ const groupKey = args.groupKey === "absolute" ? "absolute" : "relative";
1887
+ const buildGrouped = () => groupTokensByFile(report, {
1888
+ key: groupKey,
1889
+ stripAbsolutePaths: groupKey !== "absolute"
1890
+ });
1891
+ const grouped = format === "grouped-json" ? buildGrouped() : null;
1892
+ const resolveGrouped = () => _nullishCoalesce(grouped, () => ( buildGrouped()));
1893
+ if (shouldWrite) {
1894
+ const target = _pathe2.default.resolve(targetFile);
1895
+ await _fsextra2.default.ensureDir(_pathe2.default.dirname(target));
1896
+ if (format === "json") {
1897
+ await _fsextra2.default.writeJSON(target, report, { spaces: 2 });
1898
+ } else if (format === "grouped-json") {
1899
+ await _fsextra2.default.writeJSON(target, resolveGrouped(), { spaces: 2 });
1900
+ } else {
1901
+ const lines = report.entries.map(formatTokenLine);
1902
+ await _fsextra2.default.writeFile(target, `${lines.join("\n")}
1903
+ `, "utf8");
1904
+ }
1905
+ logger_default.success(`Collected ${report.entries.length} tokens (${format}) \u2192 ${target.replace(_process2.default.cwd(), ".")}`);
1906
+ } else {
1907
+ logger_default.success(`Collected ${report.entries.length} tokens from ${report.filesScanned} files.`);
1908
+ if (format === "lines") {
1909
+ const preview = report.entries.slice(0, 5).map(formatTokenLine).join("\n");
1910
+ if (preview) {
1911
+ logger_default.log("");
1912
+ logger_default.info(preview);
1913
+ if (report.entries.length > 5) {
1914
+ logger_default.info(`\u2026and ${report.entries.length - 5} more.`);
1915
+ }
1916
+ }
1917
+ } else if (format === "grouped-json") {
1918
+ const map = resolveGrouped();
1919
+ const { preview, moreFiles } = formatGroupedPreview(map);
1920
+ if (preview) {
1921
+ logger_default.log("");
1922
+ logger_default.info(preview);
1923
+ if (moreFiles > 0) {
1924
+ logger_default.info(`\u2026and ${moreFiles} more files.`);
1925
+ }
1926
+ }
1927
+ } else {
1928
+ const previewEntries = report.entries.slice(0, 3);
1929
+ if (previewEntries.length) {
1930
+ logger_default.log("");
1931
+ logger_default.info(JSON.stringify(previewEntries, null, 2));
1932
+ }
1933
+ }
1934
+ }
1935
+ if (report.skippedFiles.length) {
1936
+ logger_default.warn("Skipped files:");
1937
+ for (const skipped of report.skippedFiles) {
1938
+ logger_default.warn(` \u2022 ${skipped.file} (${skipped.reason})`);
1939
+ }
1940
+ }
1941
+ return report;
1942
+ }
1943
+ async function initCommandDefaultHandler(ctx) {
1944
+ await _config.initConfig.call(void 0, ctx.cwd);
1945
+ logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
1946
+ }
1947
+ function mountTailwindcssPatchCommands(cli, options = {}) {
1948
+ const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
1949
+ const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
1950
+ const defaultDefinitions = buildDefaultCommandDefinitions();
1951
+ const registrars = {
1952
+ install: () => {
1953
+ const metadata = resolveCommandMetadata("install", options, prefix, defaultDefinitions);
1954
+ const command = cli.command(metadata.name, metadata.description);
1955
+ applyCommandOptions(command, metadata.optionDefs);
1956
+ command.action(async (args) => {
1957
+ return runWithCommandHandler(
1958
+ cli,
1959
+ command,
1960
+ "install",
1961
+ args,
1962
+ _optionalChain([options, 'access', _88 => _88.commandHandlers, 'optionalAccess', _89 => _89.install]),
1963
+ installCommandDefaultHandler
1964
+ );
1965
+ });
1966
+ metadata.aliases.forEach((alias) => command.alias(alias));
1967
+ },
1968
+ extract: () => {
1969
+ const metadata = resolveCommandMetadata("extract", options, prefix, defaultDefinitions);
1970
+ const command = cli.command(metadata.name, metadata.description);
1971
+ applyCommandOptions(command, metadata.optionDefs);
1972
+ command.action(async (args) => {
1973
+ return runWithCommandHandler(
1974
+ cli,
1975
+ command,
1976
+ "extract",
1977
+ args,
1978
+ _optionalChain([options, 'access', _90 => _90.commandHandlers, 'optionalAccess', _91 => _91.extract]),
1979
+ extractCommandDefaultHandler
1980
+ );
1981
+ });
1982
+ metadata.aliases.forEach((alias) => command.alias(alias));
1983
+ },
1984
+ tokens: () => {
1985
+ const metadata = resolveCommandMetadata("tokens", options, prefix, defaultDefinitions);
1986
+ const command = cli.command(metadata.name, metadata.description);
1987
+ applyCommandOptions(command, metadata.optionDefs);
1988
+ command.action(async (args) => {
1989
+ return runWithCommandHandler(
1990
+ cli,
1991
+ command,
1992
+ "tokens",
1993
+ args,
1994
+ _optionalChain([options, 'access', _92 => _92.commandHandlers, 'optionalAccess', _93 => _93.tokens]),
1995
+ tokensCommandDefaultHandler
1996
+ );
1997
+ });
1998
+ metadata.aliases.forEach((alias) => command.alias(alias));
1999
+ },
2000
+ init: () => {
2001
+ const metadata = resolveCommandMetadata("init", options, prefix, defaultDefinitions);
2002
+ const command = cli.command(metadata.name, metadata.description);
2003
+ applyCommandOptions(command, metadata.optionDefs);
2004
+ command.action(async (args) => {
2005
+ return runWithCommandHandler(
2006
+ cli,
2007
+ command,
2008
+ "init",
2009
+ args,
2010
+ _optionalChain([options, 'access', _94 => _94.commandHandlers, 'optionalAccess', _95 => _95.init]),
2011
+ initCommandDefaultHandler
2012
+ );
2013
+ });
2014
+ metadata.aliases.forEach((alias) => command.alias(alias));
2015
+ }
2016
+ };
2017
+ for (const name of selectedCommands) {
2018
+ const register = registrars[name];
2019
+ if (register) {
2020
+ register();
2021
+ }
2022
+ }
2023
+ return cli;
2024
+ }
2025
+ function createTailwindcssPatchCli(options = {}) {
2026
+ const cli = _cac2.default.call(void 0, _nullishCoalesce(options.name, () => ( "tw-patch")));
2027
+ mountTailwindcssPatchCommands(cli, options.mountOptions);
2028
+ return cli;
2029
+ }
2030
+
2031
+
1565
2032
 
1566
2033
 
1567
2034
 
@@ -1578,4 +2045,4 @@ var TailwindcssPatcher = (_class = class {
1578
2045
 
1579
2046
 
1580
2047
 
1581
- exports.logger_default = logger_default; exports.CacheStore = CacheStore; exports.extractRawCandidatesWithPositions = extractRawCandidatesWithPositions; exports.extractRawCandidates = extractRawCandidates; exports.extractValidCandidates = extractValidCandidates; exports.extractProjectCandidatesWithPositions = extractProjectCandidatesWithPositions; exports.groupTokensByFile = groupTokensByFile; exports.fromLegacyOptions = fromLegacyOptions; exports.fromUnifiedConfig = fromUnifiedConfig; exports.normalizeOptions = normalizeOptions; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher;
2048
+ 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.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli;