tailwindcss-patch 8.4.3 → 8.5.1

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.
@@ -13,6 +13,9 @@ var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsex
13
13
  function isErrnoException(error) {
14
14
  return error instanceof Error && typeof error.code === "string";
15
15
  }
16
+ function isAccessDenied(error) {
17
+ return isErrnoException(error) && Boolean(error.code && ["EPERM", "EBUSY", "EACCES"].includes(error.code));
18
+ }
16
19
  var CacheStore = class {
17
20
  constructor(options) {
18
21
  this.options = options;
@@ -30,17 +33,22 @@ var CacheStore = class {
30
33
  async replaceCacheFile(tempPath) {
31
34
  try {
32
35
  await _fsextra2.default.rename(tempPath, this.options.path);
36
+ return true;
33
37
  } catch (error) {
34
38
  if (isErrnoException(error) && (error.code === "EEXIST" || error.code === "EPERM")) {
35
39
  try {
36
40
  await _fsextra2.default.remove(this.options.path);
37
41
  } catch (removeError) {
42
+ if (isAccessDenied(removeError)) {
43
+ logger_default.debug("Tailwind class cache locked or read-only, skipping update.", removeError);
44
+ return false;
45
+ }
38
46
  if (!isErrnoException(removeError) || removeError.code !== "ENOENT") {
39
47
  throw removeError;
40
48
  }
41
49
  }
42
50
  await _fsextra2.default.rename(tempPath, this.options.path);
43
- return;
51
+ return true;
44
52
  }
45
53
  throw error;
46
54
  }
@@ -48,17 +56,22 @@ var CacheStore = class {
48
56
  replaceCacheFileSync(tempPath) {
49
57
  try {
50
58
  _fsextra2.default.renameSync(tempPath, this.options.path);
59
+ return true;
51
60
  } catch (error) {
52
61
  if (isErrnoException(error) && (error.code === "EEXIST" || error.code === "EPERM")) {
53
62
  try {
54
63
  _fsextra2.default.removeSync(this.options.path);
55
64
  } catch (removeError) {
65
+ if (isAccessDenied(removeError)) {
66
+ logger_default.debug("Tailwind class cache locked or read-only, skipping update.", removeError);
67
+ return false;
68
+ }
56
69
  if (!isErrnoException(removeError) || removeError.code !== "ENOENT") {
57
70
  throw removeError;
58
71
  }
59
72
  }
60
73
  _fsextra2.default.renameSync(tempPath, this.options.path);
61
- return;
74
+ return true;
62
75
  }
63
76
  throw error;
64
77
  }
@@ -83,8 +96,12 @@ var CacheStore = class {
83
96
  try {
84
97
  await this.ensureDir();
85
98
  await _fsextra2.default.writeJSON(tempPath, Array.from(data));
86
- await this.replaceCacheFile(tempPath);
87
- return this.options.path;
99
+ const replaced = await this.replaceCacheFile(tempPath);
100
+ if (replaced) {
101
+ return this.options.path;
102
+ }
103
+ await this.cleanupTempFile(tempPath);
104
+ return void 0;
88
105
  } catch (error) {
89
106
  await this.cleanupTempFile(tempPath);
90
107
  logger_default.error("Unable to persist Tailwind class cache", error);
@@ -99,8 +116,12 @@ var CacheStore = class {
99
116
  try {
100
117
  this.ensureDirSync();
101
118
  _fsextra2.default.writeJSONSync(tempPath, Array.from(data));
102
- this.replaceCacheFileSync(tempPath);
103
- return this.options.path;
119
+ const replaced = this.replaceCacheFileSync(tempPath);
120
+ if (replaced) {
121
+ return this.options.path;
122
+ }
123
+ this.cleanupTempFileSync(tempPath);
124
+ return void 0;
104
125
  } catch (error) {
105
126
  this.cleanupTempFileSync(tempPath);
106
127
  logger_default.error("Unable to persist Tailwind class cache", error);
@@ -524,328 +545,186 @@ function normalizeOptions(options = {}) {
524
545
  };
525
546
  }
526
547
 
527
- // src/runtime/class-collector.ts
528
-
548
+ // src/patching/status.ts
549
+ var _types = require('@babel/types'); var t4 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
529
550
 
530
551
 
531
552
 
532
- // src/utils.ts
533
- function isObject(val) {
534
- return val !== null && typeof val === "object" && Array.isArray(val) === false;
553
+ // src/babel/index.ts
554
+ var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
555
+ var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
556
+ var _parser = require('@babel/parser');
557
+ function _interopDefaultCompat(e) {
558
+ return e && typeof e === "object" && "default" in e ? e.default : e;
535
559
  }
536
- function spliceChangesIntoString(str, changes) {
537
- if (!changes[0]) {
538
- return str;
560
+ var generate = _interopDefaultCompat(_generator2.default);
561
+ var traverse = _interopDefaultCompat(_traverse2.default);
562
+
563
+ // src/patching/operations/export-context/postcss-v2.ts
564
+
565
+ var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
566
+ function toIdentifierName(property) {
567
+ if (!property) {
568
+ return "contextRef";
539
569
  }
540
- changes.sort((a, b) => {
541
- return a.end - b.end || a.start - b.start;
542
- });
543
- let result = "";
544
- let previous = changes[0];
545
- result += str.slice(0, previous.start);
546
- result += previous.replacement;
547
- for (let i = 1; i < changes.length; ++i) {
548
- const change = changes[i];
549
- result += str.slice(previous.end, change.start);
550
- result += change.replacement;
551
- previous = change;
570
+ const sanitized = property.replace(/[^\w$]/gu, "_");
571
+ if (/^\d/.test(sanitized)) {
572
+ return `_${sanitized}`;
552
573
  }
553
- result += str.slice(previous.end);
554
- return result;
574
+ return sanitized || "contextRef";
555
575
  }
556
-
557
- // src/runtime/class-collector.ts
558
- function collectClassesFromContexts(contexts, filter) {
559
- const set = /* @__PURE__ */ new Set();
560
- for (const context of contexts) {
561
- if (!isObject(context) || !context.classCache) {
562
- continue;
563
- }
564
- for (const key of context.classCache.keys()) {
565
- const className = key.toString();
566
- if (filter(className)) {
567
- set.add(className);
568
- }
569
- }
576
+ function createExportsMember(property) {
577
+ if (IDENTIFIER_RE.test(property)) {
578
+ return t.memberExpression(t.identifier("exports"), t.identifier(property));
570
579
  }
571
- return set;
580
+ return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
572
581
  }
573
- async function collectClassesFromTailwindV4(options) {
574
- const set = /* @__PURE__ */ new Set();
575
- const v4Options = options.tailwind.v4;
576
- if (!v4Options) {
577
- return set;
578
- }
579
- const toAbsolute = (value) => {
580
- if (!value) {
581
- return void 0;
582
- }
583
- return _pathe2.default.isAbsolute(value) ? value : _pathe2.default.resolve(options.projectRoot, value);
584
- };
585
- const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
586
- const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
587
- const resolveSources = (base) => {
588
- if (!_optionalChain([v4Options, 'access', _28 => _28.sources, 'optionalAccess', _29 => _29.length])) {
589
- return void 0;
582
+ function transformProcessTailwindFeaturesReturnContextV2(content) {
583
+ const ast = _parser.parse.call(void 0, content, {
584
+ sourceType: "unambiguous"
585
+ });
586
+ let hasPatched = false;
587
+ traverse(ast, {
588
+ FunctionDeclaration(path11) {
589
+ const node = path11.node;
590
+ if (_optionalChain([node, 'access', _28 => _28.id, 'optionalAccess', _29 => _29.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
591
+ return;
592
+ }
593
+ const returnStatement3 = node.body.body[0];
594
+ if (!t.isFunctionExpression(returnStatement3.argument)) {
595
+ return;
596
+ }
597
+ const body = returnStatement3.argument.body.body;
598
+ const lastStatement = body[body.length - 1];
599
+ const alreadyReturnsContext = Boolean(
600
+ t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
601
+ );
602
+ hasPatched = alreadyReturnsContext;
603
+ if (!alreadyReturnsContext) {
604
+ body.push(t.returnStatement(t.identifier("context")));
605
+ }
590
606
  }
591
- return v4Options.sources.map((source) => ({
592
- base: _nullishCoalesce(source.base, () => ( base)),
593
- pattern: source.pattern,
594
- negated: source.negated
595
- }));
607
+ });
608
+ return {
609
+ code: hasPatched ? content : generate(ast).code,
610
+ hasPatched
596
611
  };
597
- if (v4Options.cssEntries.length > 0) {
598
- for (const entry of v4Options.cssEntries) {
599
- const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
600
- if (!await _fsextra2.default.pathExists(filePath)) {
601
- continue;
602
- }
603
- const css = await _fsextra2.default.readFile(filePath, "utf8");
604
- const entryDir = _pathe2.default.dirname(filePath);
605
- const baseForEntry = _nullishCoalesce(resolvedConfiguredBase, () => ( entryDir));
606
- const sources = resolveSources(baseForEntry);
607
- const candidates = await extractValidCandidates({
608
- cwd: options.projectRoot,
609
- base: baseForEntry,
610
- css,
611
- sources
612
+ }
613
+ function transformPostcssPluginV2(content, options) {
614
+ const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
615
+ const exportMember = createExportsMember(options.refProperty);
616
+ const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
617
+ const ast = _parser.parse.call(void 0, content);
618
+ let hasPatched = false;
619
+ traverse(ast, {
620
+ Program(path11) {
621
+ const program = path11.node;
622
+ const index = program.body.findIndex((statement) => {
623
+ return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _30 => _30.id, 'optionalAccess', _31 => _31.name]) === "_default";
612
624
  });
613
- for (const candidate of candidates) {
614
- if (options.filter(candidate)) {
615
- set.add(candidate);
616
- }
625
+ if (index === -1) {
626
+ return;
617
627
  }
618
- }
619
- } else {
620
- const baseForCss = _nullishCoalesce(resolvedConfiguredBase, () => ( resolvedDefaultBase));
621
- const sources = resolveSources(baseForCss);
622
- const candidates = await extractValidCandidates({
623
- cwd: options.projectRoot,
624
- base: baseForCss,
625
- css: v4Options.css,
626
- sources
627
- });
628
- for (const candidate of candidates) {
629
- if (options.filter(candidate)) {
630
- set.add(candidate);
628
+ const previous = program.body[index - 1];
629
+ const beforePrevious = program.body[index - 2];
630
+ const alreadyHasVariable = Boolean(
631
+ previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && t.isIdentifier(previous.declarations[0].id) && previous.declarations[0].id.name === refIdentifier.name
632
+ );
633
+ const alreadyAssignsExports = Boolean(
634
+ beforePrevious && t.isExpressionStatement(beforePrevious) && t.isAssignmentExpression(beforePrevious.expression) && t.isMemberExpression(beforePrevious.expression.left) && t.isIdentifier(beforePrevious.expression.right) && beforePrevious.expression.right.name === refIdentifier.name && generate(beforePrevious.expression.left).code === generate(exportMember).code
635
+ );
636
+ hasPatched = alreadyHasVariable && alreadyAssignsExports;
637
+ if (!alreadyHasVariable) {
638
+ program.body.splice(
639
+ index,
640
+ 0,
641
+ t.variableDeclaration("var", [
642
+ t.variableDeclarator(
643
+ refIdentifier,
644
+ t.objectExpression([
645
+ t.objectProperty(t.identifier("value"), t.arrayExpression())
646
+ ])
647
+ )
648
+ ]),
649
+ t.expressionStatement(
650
+ t.assignmentExpression("=", exportMember, refIdentifier)
651
+ )
652
+ );
653
+ }
654
+ },
655
+ FunctionDeclaration(path11) {
656
+ if (hasPatched) {
657
+ return;
658
+ }
659
+ const fn = path11.node;
660
+ if (_optionalChain([fn, 'access', _32 => _32.id, 'optionalAccess', _33 => _33.name]) !== "_default") {
661
+ return;
662
+ }
663
+ if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
664
+ return;
665
+ }
666
+ const returnStatement3 = fn.body.body[0];
667
+ if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
668
+ return;
669
+ }
670
+ const fnExpression = returnStatement3.argument.callee.object.elements[1];
671
+ if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
672
+ return;
673
+ }
674
+ const block = fnExpression.body;
675
+ const statements = block.body;
676
+ if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
677
+ hasPatched = true;
678
+ return;
679
+ }
680
+ const lastStatement = statements[statements.length - 1];
681
+ if (lastStatement && t.isExpressionStatement(lastStatement)) {
682
+ statements[statements.length - 1] = t.expressionStatement(
683
+ t.callExpression(
684
+ t.memberExpression(valueMember, t.identifier("push")),
685
+ [lastStatement.expression]
686
+ )
687
+ );
688
+ }
689
+ const index = statements.findIndex((statement) => t.isIfStatement(statement));
690
+ if (index > -1) {
691
+ const ifStatement = statements[index];
692
+ if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
693
+ const forOf = ifStatement.consequent.body[1];
694
+ if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
695
+ const nestedIf = forOf.body.body[0];
696
+ if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
697
+ nestedIf.consequent.body[0] = t.expressionStatement(
698
+ t.callExpression(
699
+ t.memberExpression(valueMember, t.identifier("push")),
700
+ [nestedIf.consequent.body[0].expression]
701
+ )
702
+ );
703
+ }
704
+ }
705
+ }
631
706
  }
707
+ statements.unshift(
708
+ t.expressionStatement(
709
+ t.assignmentExpression(
710
+ "=",
711
+ t.memberExpression(valueMember, t.identifier("length")),
712
+ t.numericLiteral(0)
713
+ )
714
+ )
715
+ );
632
716
  }
633
- }
634
- return set;
717
+ });
718
+ return {
719
+ code: hasPatched ? content : generate(ast).code,
720
+ hasPatched
721
+ };
635
722
  }
636
723
 
637
- // src/runtime/context-registry.ts
638
- var _module = require('module');
639
-
724
+ // src/patching/operations/export-context/postcss-v3.ts
640
725
 
641
- var require2 = _module.createRequire.call(void 0, importMetaUrl);
642
- function resolveRuntimeEntry(packageInfo, majorVersion) {
643
- const root = packageInfo.rootPath;
644
- if (majorVersion === 2) {
645
- const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
646
- if (_fsextra2.default.existsSync(jitIndex)) {
647
- return jitIndex;
648
- }
649
- } else if (majorVersion === 3) {
650
- const plugin = _pathe2.default.join(root, "lib/plugin.js");
651
- const index = _pathe2.default.join(root, "lib/index.js");
652
- if (_fsextra2.default.existsSync(plugin)) {
653
- return plugin;
654
- }
655
- if (_fsextra2.default.existsSync(index)) {
656
- return index;
657
- }
658
- }
659
- return void 0;
660
- }
661
- function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
662
- if (majorVersion === 4) {
663
- return [];
664
- }
665
- const entry = resolveRuntimeEntry(packageInfo, majorVersion);
666
- if (!entry) {
667
- return [];
668
- }
669
- const moduleExports = require2(entry);
670
- if (!moduleExports) {
671
- return [];
672
- }
673
- const ref = moduleExports[refProperty];
674
- if (!ref) {
675
- return [];
676
- }
677
- if (Array.isArray(ref)) {
678
- return ref;
679
- }
680
- if (typeof ref === "object" && Array.isArray(ref.value)) {
681
- return ref.value;
682
- }
683
- return [];
684
- }
685
-
686
- // src/runtime/process-tailwindcss.ts
687
-
688
-
689
- var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
690
- var _tailwindcssconfig = require('tailwindcss-config');
691
- var require3 = _module.createRequire.call(void 0, importMetaUrl);
692
- async function resolveConfigPath(options) {
693
- if (options.config && _pathe2.default.isAbsolute(options.config)) {
694
- return options.config;
695
- }
696
- const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
697
- if (!result) {
698
- throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
699
- }
700
- return result.filepath;
701
- }
702
- async function runTailwindBuild(options) {
703
- const configPath = await resolveConfigPath(options);
704
- const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
705
- if (options.majorVersion === 4) {
706
- return _postcss2.default.call(void 0, [
707
- require3(pluginName)({
708
- config: configPath
709
- })
710
- ]).process("@import 'tailwindcss';", {
711
- from: void 0
712
- });
713
- }
714
- return _postcss2.default.call(void 0, [
715
- require3(pluginName)({
716
- config: configPath
717
- })
718
- ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
719
- from: void 0
720
- });
721
- }
722
-
723
- // src/api/tailwindcss-patcher.ts
724
-
725
-
726
- var _localpkg = require('local-pkg');
727
-
728
- var _semver = require('semver');
729
-
730
- // src/options/legacy.ts
731
- function normalizeLegacyFeatures(patch) {
732
- const apply = _optionalChain([patch, 'optionalAccess', _30 => _30.applyPatches]);
733
- const extend = _optionalChain([apply, 'optionalAccess', _31 => _31.extendLengthUnits]);
734
- let extendOption = false;
735
- if (extend && typeof extend === "object") {
736
- extendOption = {
737
- ...extend,
738
- enabled: true
739
- };
740
- } else if (extend === true) {
741
- extendOption = {
742
- enabled: true,
743
- units: ["rpx"],
744
- overwrite: _optionalChain([patch, 'optionalAccess', _32 => _32.overwrite])
745
- };
746
- }
747
- return {
748
- exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _33 => _33.exportContext]), () => ( true)),
749
- extendLengthUnits: extendOption
750
- };
751
- }
752
- function fromLegacyOptions(options) {
753
- if (!options) {
754
- return {};
755
- }
756
- const patch = options.patch;
757
- const features = normalizeLegacyFeatures(patch);
758
- const output = _optionalChain([patch, 'optionalAccess', _34 => _34.output]);
759
- const tailwindConfig = _optionalChain([patch, 'optionalAccess', _35 => _35.tailwindcss]);
760
- const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _36 => _36.version]);
761
- const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _37 => _37.v2]);
762
- const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _38 => _38.v3]);
763
- const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _39 => _39.v4]);
764
- const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _40 => _40.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _41 => _41.config])));
765
- const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _42 => _42.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _43 => _43.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _44 => _44.cwd])));
766
- return {
767
- cwd: _optionalChain([patch, 'optionalAccess', _45 => _45.cwd]),
768
- overwrite: _optionalChain([patch, 'optionalAccess', _46 => _46.overwrite]),
769
- filter: _optionalChain([patch, 'optionalAccess', _47 => _47.filter]),
770
- cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
771
- ...options.cache,
772
- enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
773
- } : void 0,
774
- output: output ? {
775
- file: output.filename,
776
- pretty: output.loose ? 2 : false,
777
- removeUniversalSelector: output.removeUniversalSelector
778
- } : void 0,
779
- tailwind: {
780
- packageName: _optionalChain([patch, 'optionalAccess', _48 => _48.packageName]),
781
- version: tailwindVersion,
782
- resolve: _optionalChain([patch, 'optionalAccess', _49 => _49.resolve]),
783
- config: tailwindConfigPath,
784
- cwd: tailwindCwd,
785
- v2: tailwindV2,
786
- v3: tailwindV3,
787
- v4: tailwindV4
788
- },
789
- features: {
790
- exposeContext: features.exposeContext,
791
- extendLengthUnits: features.extendLengthUnits
792
- }
793
- };
794
- }
795
- function fromUnifiedConfig(registry) {
796
- if (!registry) {
797
- return {};
798
- }
799
- const tailwind = registry.tailwind;
800
- const output = registry.output;
801
- const pretty = (() => {
802
- if (_optionalChain([output, 'optionalAccess', _50 => _50.pretty]) === void 0) {
803
- return void 0;
804
- }
805
- if (typeof output.pretty === "boolean") {
806
- return output.pretty ? 2 : false;
807
- }
808
- return output.pretty;
809
- })();
810
- return {
811
- output: output ? {
812
- file: output.file,
813
- pretty,
814
- removeUniversalSelector: output.stripUniversalSelector
815
- } : void 0,
816
- tailwind: tailwind ? {
817
- version: tailwind.version,
818
- packageName: tailwind.package,
819
- resolve: tailwind.resolve,
820
- config: tailwind.config,
821
- cwd: tailwind.cwd,
822
- v2: tailwind.legacy,
823
- v3: tailwind.classic,
824
- v4: tailwind.next
825
- } : void 0
826
- };
827
- }
828
-
829
- // src/patching/operations/export-context/index.ts
830
-
831
-
832
-
833
- // src/patching/operations/export-context/postcss-v2.ts
834
- var _types = require('@babel/types'); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
835
-
836
- // src/babel/index.ts
837
- var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
838
- var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
839
- var _parser = require('@babel/parser');
840
- function _interopDefaultCompat(e) {
841
- return e && typeof e === "object" && "default" in e ? e.default : e;
842
- }
843
- var generate = _interopDefaultCompat(_generator2.default);
844
- var traverse = _interopDefaultCompat(_traverse2.default);
845
-
846
- // src/patching/operations/export-context/postcss-v2.ts
847
- var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
848
- function toIdentifierName(property) {
726
+ var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
727
+ function toIdentifierName2(property) {
849
728
  if (!property) {
850
729
  return "contextRef";
851
730
  }
@@ -855,35 +734,35 @@ function toIdentifierName(property) {
855
734
  }
856
735
  return sanitized || "contextRef";
857
736
  }
858
- function createExportsMember(property) {
859
- if (IDENTIFIER_RE.test(property)) {
860
- return t.memberExpression(t.identifier("exports"), t.identifier(property));
737
+ function createModuleExportsMember(property) {
738
+ const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
739
+ if (IDENTIFIER_RE2.test(property)) {
740
+ return t2.memberExpression(object, t2.identifier(property));
861
741
  }
862
- return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
742
+ return t2.memberExpression(object, t2.stringLiteral(property), true);
863
743
  }
864
- function transformProcessTailwindFeaturesReturnContextV2(content) {
865
- const ast = _parser.parse.call(void 0, content, {
866
- sourceType: "unambiguous"
867
- });
744
+ function transformProcessTailwindFeaturesReturnContext(content) {
745
+ const ast = _parser.parse.call(void 0, content);
868
746
  let hasPatched = false;
869
747
  traverse(ast, {
870
- FunctionDeclaration(path10) {
871
- const node = path10.node;
872
- if (_optionalChain([node, 'access', _51 => _51.id, 'optionalAccess', _52 => _52.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
748
+ FunctionDeclaration(path11) {
749
+ const node = path11.node;
750
+ if (_optionalChain([node, 'access', _34 => _34.id, 'optionalAccess', _35 => _35.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
873
751
  return;
874
752
  }
875
- const returnStatement3 = node.body.body[0];
876
- if (!t.isFunctionExpression(returnStatement3.argument)) {
753
+ const [returnStatement3] = node.body.body;
754
+ if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
877
755
  return;
878
756
  }
879
- const body = returnStatement3.argument.body.body;
757
+ const expression = returnStatement3.argument;
758
+ const body = expression.body.body;
880
759
  const lastStatement = body[body.length - 1];
881
760
  const alreadyReturnsContext = Boolean(
882
- t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
761
+ t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
883
762
  );
884
763
  hasPatched = alreadyReturnsContext;
885
764
  if (!alreadyReturnsContext) {
886
- body.push(t.returnStatement(t.identifier("context")));
765
+ body.push(t2.returnStatement(t2.identifier("context")));
887
766
  }
888
767
  }
889
768
  });
@@ -892,219 +771,58 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
892
771
  hasPatched
893
772
  };
894
773
  }
895
- function transformPostcssPluginV2(content, options) {
896
- const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
897
- const exportMember = createExportsMember(options.refProperty);
898
- const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
774
+ function transformPostcssPlugin(content, { refProperty }) {
899
775
  const ast = _parser.parse.call(void 0, content);
776
+ const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
777
+ const moduleExportsMember = createModuleExportsMember(refProperty);
778
+ const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
900
779
  let hasPatched = false;
901
780
  traverse(ast, {
902
- Program(path10) {
903
- const program = path10.node;
781
+ Program(path11) {
782
+ const program = path11.node;
904
783
  const index = program.body.findIndex((statement) => {
905
- return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _53 => _53.id, 'optionalAccess', _54 => _54.name]) === "_default";
784
+ return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _36 => _36.expression, 'access', _37 => _37.right, 'access', _38 => _38.id, 'optionalAccess', _39 => _39.name]) === "tailwindcss";
906
785
  });
907
786
  if (index === -1) {
908
787
  return;
909
788
  }
910
- const previous = program.body[index - 1];
911
- const beforePrevious = program.body[index - 2];
789
+ const previousStatement = program.body[index - 1];
790
+ const lastStatement = program.body[program.body.length - 1];
912
791
  const alreadyHasVariable = Boolean(
913
- previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && t.isIdentifier(previous.declarations[0].id) && previous.declarations[0].id.name === refIdentifier.name
792
+ previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && t2.isIdentifier(previousStatement.declarations[0].id) && previousStatement.declarations[0].id.name === refIdentifier.name
914
793
  );
915
- const alreadyAssignsExports = Boolean(
916
- beforePrevious && t.isExpressionStatement(beforePrevious) && t.isAssignmentExpression(beforePrevious.expression) && t.isMemberExpression(beforePrevious.expression.left) && t.isIdentifier(beforePrevious.expression.right) && beforePrevious.expression.right.name === refIdentifier.name && generate(beforePrevious.expression.left).code === generate(exportMember).code
794
+ const alreadyAssignsModuleExports = Boolean(
795
+ t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isMemberExpression(lastStatement.expression.left) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === refIdentifier.name && generate(lastStatement.expression.left).code === generate(moduleExportsMember).code
917
796
  );
918
- hasPatched = alreadyHasVariable && alreadyAssignsExports;
797
+ hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
919
798
  if (!alreadyHasVariable) {
920
799
  program.body.splice(
921
800
  index,
922
801
  0,
923
- t.variableDeclaration("var", [
924
- t.variableDeclarator(
802
+ t2.variableDeclaration("const", [
803
+ t2.variableDeclarator(
925
804
  refIdentifier,
926
- t.objectExpression([
927
- t.objectProperty(t.identifier("value"), t.arrayExpression())
805
+ t2.objectExpression([
806
+ t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
928
807
  ])
929
808
  )
930
- ]),
931
- t.expressionStatement(
932
- t.assignmentExpression("=", exportMember, refIdentifier)
809
+ ])
810
+ );
811
+ }
812
+ if (!alreadyAssignsModuleExports) {
813
+ program.body.push(
814
+ t2.expressionStatement(
815
+ t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
933
816
  )
934
817
  );
935
818
  }
936
819
  },
937
- FunctionDeclaration(path10) {
820
+ FunctionExpression(path11) {
938
821
  if (hasPatched) {
939
822
  return;
940
823
  }
941
- const fn = path10.node;
942
- if (_optionalChain([fn, 'access', _55 => _55.id, 'optionalAccess', _56 => _56.name]) !== "_default") {
943
- return;
944
- }
945
- if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
946
- return;
947
- }
948
- const returnStatement3 = fn.body.body[0];
949
- if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
950
- return;
951
- }
952
- const fnExpression = returnStatement3.argument.callee.object.elements[1];
953
- if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
954
- return;
955
- }
956
- const block = fnExpression.body;
957
- const statements = block.body;
958
- if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
959
- hasPatched = true;
960
- return;
961
- }
962
- const lastStatement = statements[statements.length - 1];
963
- if (lastStatement && t.isExpressionStatement(lastStatement)) {
964
- statements[statements.length - 1] = t.expressionStatement(
965
- t.callExpression(
966
- t.memberExpression(valueMember, t.identifier("push")),
967
- [lastStatement.expression]
968
- )
969
- );
970
- }
971
- const index = statements.findIndex((statement) => t.isIfStatement(statement));
972
- if (index > -1) {
973
- const ifStatement = statements[index];
974
- if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
975
- const forOf = ifStatement.consequent.body[1];
976
- if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
977
- const nestedIf = forOf.body.body[0];
978
- if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
979
- nestedIf.consequent.body[0] = t.expressionStatement(
980
- t.callExpression(
981
- t.memberExpression(valueMember, t.identifier("push")),
982
- [nestedIf.consequent.body[0].expression]
983
- )
984
- );
985
- }
986
- }
987
- }
988
- }
989
- statements.unshift(
990
- t.expressionStatement(
991
- t.assignmentExpression(
992
- "=",
993
- t.memberExpression(valueMember, t.identifier("length")),
994
- t.numericLiteral(0)
995
- )
996
- )
997
- );
998
- }
999
- });
1000
- return {
1001
- code: hasPatched ? content : generate(ast).code,
1002
- hasPatched
1003
- };
1004
- }
1005
-
1006
- // src/patching/operations/export-context/postcss-v3.ts
1007
-
1008
- var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
1009
- function toIdentifierName2(property) {
1010
- if (!property) {
1011
- return "contextRef";
1012
- }
1013
- const sanitized = property.replace(/[^\w$]/gu, "_");
1014
- if (/^\d/.test(sanitized)) {
1015
- return `_${sanitized}`;
1016
- }
1017
- return sanitized || "contextRef";
1018
- }
1019
- function createModuleExportsMember(property) {
1020
- const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
1021
- if (IDENTIFIER_RE2.test(property)) {
1022
- return t2.memberExpression(object, t2.identifier(property));
1023
- }
1024
- return t2.memberExpression(object, t2.stringLiteral(property), true);
1025
- }
1026
- function transformProcessTailwindFeaturesReturnContext(content) {
1027
- const ast = _parser.parse.call(void 0, content);
1028
- let hasPatched = false;
1029
- traverse(ast, {
1030
- FunctionDeclaration(path10) {
1031
- const node = path10.node;
1032
- if (_optionalChain([node, 'access', _57 => _57.id, 'optionalAccess', _58 => _58.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
1033
- return;
1034
- }
1035
- const [returnStatement3] = node.body.body;
1036
- if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
1037
- return;
1038
- }
1039
- const expression = returnStatement3.argument;
1040
- const body = expression.body.body;
1041
- const lastStatement = body[body.length - 1];
1042
- const alreadyReturnsContext = Boolean(
1043
- t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
1044
- );
1045
- hasPatched = alreadyReturnsContext;
1046
- if (!alreadyReturnsContext) {
1047
- body.push(t2.returnStatement(t2.identifier("context")));
1048
- }
1049
- }
1050
- });
1051
- return {
1052
- code: hasPatched ? content : generate(ast).code,
1053
- hasPatched
1054
- };
1055
- }
1056
- function transformPostcssPlugin(content, { refProperty }) {
1057
- const ast = _parser.parse.call(void 0, content);
1058
- const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
1059
- const moduleExportsMember = createModuleExportsMember(refProperty);
1060
- const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
1061
- let hasPatched = false;
1062
- traverse(ast, {
1063
- Program(path10) {
1064
- const program = path10.node;
1065
- const index = program.body.findIndex((statement) => {
1066
- 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";
1067
- });
1068
- if (index === -1) {
1069
- return;
1070
- }
1071
- const previousStatement = program.body[index - 1];
1072
- const lastStatement = program.body[program.body.length - 1];
1073
- const alreadyHasVariable = Boolean(
1074
- previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && t2.isIdentifier(previousStatement.declarations[0].id) && previousStatement.declarations[0].id.name === refIdentifier.name
1075
- );
1076
- const alreadyAssignsModuleExports = Boolean(
1077
- t2.isExpressionStatement(lastStatement) && t2.isAssignmentExpression(lastStatement.expression) && t2.isMemberExpression(lastStatement.expression.left) && t2.isIdentifier(lastStatement.expression.right) && lastStatement.expression.right.name === refIdentifier.name && generate(lastStatement.expression.left).code === generate(moduleExportsMember).code
1078
- );
1079
- hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
1080
- if (!alreadyHasVariable) {
1081
- program.body.splice(
1082
- index,
1083
- 0,
1084
- t2.variableDeclaration("const", [
1085
- t2.variableDeclarator(
1086
- refIdentifier,
1087
- t2.objectExpression([
1088
- t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
1089
- ])
1090
- )
1091
- ])
1092
- );
1093
- }
1094
- if (!alreadyAssignsModuleExports) {
1095
- program.body.push(
1096
- t2.expressionStatement(
1097
- t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
1098
- )
1099
- );
1100
- }
1101
- },
1102
- FunctionExpression(path10) {
1103
- if (hasPatched) {
1104
- return;
1105
- }
1106
- const fn = path10.node;
1107
- if (_optionalChain([fn, 'access', _63 => _63.id, 'optionalAccess', _64 => _64.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
824
+ const fn = path11.node;
825
+ if (_optionalChain([fn, 'access', _40 => _40.id, 'optionalAccess', _41 => _41.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
1108
826
  return;
1109
827
  }
1110
828
  const [returnStatement3] = fn.body.body;
@@ -1167,12 +885,657 @@ function transformPostcssPlugin(content, { refProperty }) {
1167
885
  }
1168
886
  });
1169
887
  return {
1170
- code: hasPatched ? content : generate(ast).code,
1171
- hasPatched
888
+ code: hasPatched ? content : generate(ast).code,
889
+ hasPatched
890
+ };
891
+ }
892
+
893
+ // src/patching/operations/extend-length-units.ts
894
+
895
+
896
+
897
+
898
+ // src/utils.ts
899
+ function isObject(val) {
900
+ return val !== null && typeof val === "object" && Array.isArray(val) === false;
901
+ }
902
+ function spliceChangesIntoString(str, changes) {
903
+ if (!changes[0]) {
904
+ return str;
905
+ }
906
+ changes.sort((a, b) => {
907
+ return a.end - b.end || a.start - b.start;
908
+ });
909
+ let result = "";
910
+ let previous = changes[0];
911
+ result += str.slice(0, previous.start);
912
+ result += previous.replacement;
913
+ for (let i = 1; i < changes.length; ++i) {
914
+ const change = changes[i];
915
+ result += str.slice(previous.end, change.start);
916
+ result += change.replacement;
917
+ previous = change;
918
+ }
919
+ result += str.slice(previous.end);
920
+ return result;
921
+ }
922
+
923
+ // src/patching/operations/extend-length-units.ts
924
+ function updateLengthUnitsArray(content, options) {
925
+ const { variableName = "lengthUnits", units } = options;
926
+ const ast = _parser.parse.call(void 0, content);
927
+ let arrayRef;
928
+ let changed = false;
929
+ traverse(ast, {
930
+ Identifier(path11) {
931
+ if (path11.node.name === variableName && t3.isVariableDeclarator(path11.parent) && t3.isArrayExpression(path11.parent.init)) {
932
+ arrayRef = path11.parent.init;
933
+ const existing = new Set(
934
+ path11.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
935
+ );
936
+ for (const unit of units) {
937
+ if (!existing.has(unit)) {
938
+ path11.parent.init.elements = path11.parent.init.elements.map((element) => {
939
+ if (t3.isStringLiteral(element)) {
940
+ return t3.stringLiteral(element.value);
941
+ }
942
+ return element;
943
+ });
944
+ path11.parent.init.elements.push(t3.stringLiteral(unit));
945
+ changed = true;
946
+ }
947
+ }
948
+ }
949
+ }
950
+ });
951
+ return {
952
+ arrayRef,
953
+ changed
954
+ };
955
+ }
956
+ function applyExtendLengthUnitsPatchV3(rootDir, options) {
957
+ if (!options.enabled) {
958
+ return { changed: false, code: void 0 };
959
+ }
960
+ const opts = {
961
+ ...options,
962
+ lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
963
+ variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
964
+ };
965
+ const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
966
+ const exists = _fsextra2.default.existsSync(dataTypesFilePath);
967
+ if (!exists) {
968
+ return { changed: false, code: void 0 };
969
+ }
970
+ const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
971
+ const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
972
+ if (!arrayRef || !changed) {
973
+ return { changed: false, code: void 0 };
974
+ }
975
+ const { code } = generate(arrayRef, {
976
+ jsescOption: { quotes: "single" }
977
+ });
978
+ if (arrayRef.start != null && arrayRef.end != null) {
979
+ const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
980
+ if (opts.overwrite) {
981
+ const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
982
+ _fsextra2.default.writeFileSync(target, nextCode, "utf8");
983
+ logger_default.success("Patched Tailwind CSS length unit list (v3).");
984
+ }
985
+ return {
986
+ changed: true,
987
+ code: nextCode
988
+ };
989
+ }
990
+ return {
991
+ changed: false,
992
+ code: void 0
993
+ };
994
+ }
995
+ function applyExtendLengthUnitsPatchV4(rootDir, options) {
996
+ if (!options.enabled) {
997
+ return { files: [], changed: false };
998
+ }
999
+ const opts = { ...options };
1000
+ const distDir = _pathe2.default.resolve(rootDir, "dist");
1001
+ if (!_fsextra2.default.existsSync(distDir)) {
1002
+ return { files: [], changed: false };
1003
+ }
1004
+ const entries = _fsextra2.default.readdirSync(distDir);
1005
+ const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
1006
+ const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
1007
+ const candidates = chunkNames.map((chunkName) => {
1008
+ const file = _pathe2.default.join(distDir, chunkName);
1009
+ const code = _fsextra2.default.readFileSync(file, "utf8");
1010
+ const match = pattern.exec(code);
1011
+ if (!match) {
1012
+ return null;
1013
+ }
1014
+ return {
1015
+ file,
1016
+ code,
1017
+ match,
1018
+ hasPatched: false
1019
+ };
1020
+ }).filter((candidate) => candidate !== null);
1021
+ for (const item of candidates) {
1022
+ const { code, file, match } = item;
1023
+ const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
1024
+ traverse(ast, {
1025
+ ArrayExpression(path11) {
1026
+ for (const unit of opts.units) {
1027
+ if (path11.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
1028
+ item.hasPatched = true;
1029
+ return;
1030
+ }
1031
+ path11.node.elements.push(t3.stringLiteral(unit));
1032
+ }
1033
+ }
1034
+ });
1035
+ if (item.hasPatched) {
1036
+ continue;
1037
+ }
1038
+ const { code: replacement } = generate(ast, { minified: true });
1039
+ const start = _nullishCoalesce(match.index, () => ( 0));
1040
+ const end = start + match[0].length;
1041
+ item.code = spliceChangesIntoString(code, [
1042
+ {
1043
+ start,
1044
+ end,
1045
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
1046
+ }
1047
+ ]);
1048
+ if (opts.overwrite) {
1049
+ _fsextra2.default.writeFileSync(file, item.code, "utf8");
1050
+ }
1051
+ }
1052
+ if (candidates.some((file) => !file.hasPatched)) {
1053
+ logger_default.success("Patched Tailwind CSS length unit list (v4).");
1054
+ }
1055
+ return {
1056
+ changed: candidates.some((file) => !file.hasPatched),
1057
+ files: candidates
1058
+ };
1059
+ }
1060
+
1061
+ // src/patching/status.ts
1062
+ function inspectLengthUnitsArray(content, variableName, units) {
1063
+ const ast = _parser.parse.call(void 0, content);
1064
+ let found = false;
1065
+ let missingUnits = [];
1066
+ traverse(ast, {
1067
+ Identifier(path11) {
1068
+ if (path11.node.name === variableName && t4.isVariableDeclarator(path11.parent) && t4.isArrayExpression(path11.parent.init)) {
1069
+ found = true;
1070
+ const existing = new Set(
1071
+ path11.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
1072
+ );
1073
+ missingUnits = units.filter((unit) => !existing.has(unit));
1074
+ path11.stop();
1075
+ }
1076
+ }
1077
+ });
1078
+ return {
1079
+ found,
1080
+ missingUnits
1081
+ };
1082
+ }
1083
+ function checkExposeContextPatch(context) {
1084
+ const { packageInfo, options, majorVersion } = context;
1085
+ const refProperty = options.features.exposeContext.refProperty;
1086
+ if (!options.features.exposeContext.enabled) {
1087
+ return {
1088
+ name: "exposeContext",
1089
+ status: "skipped",
1090
+ reason: "exposeContext feature disabled",
1091
+ files: []
1092
+ };
1093
+ }
1094
+ if (majorVersion === 4) {
1095
+ return {
1096
+ name: "exposeContext",
1097
+ status: "unsupported",
1098
+ reason: "Context export patch is only required for Tailwind v2/v3",
1099
+ files: []
1100
+ };
1101
+ }
1102
+ const checks = [];
1103
+ function inspectFile(relative, transform) {
1104
+ const filePath = _pathe2.default.resolve(packageInfo.rootPath, relative);
1105
+ if (!_fsextra2.default.existsSync(filePath)) {
1106
+ checks.push({ relative, exists: false, patched: false });
1107
+ return;
1108
+ }
1109
+ const content = _fsextra2.default.readFileSync(filePath, "utf8");
1110
+ const { hasPatched } = transform(content);
1111
+ checks.push({
1112
+ relative,
1113
+ exists: true,
1114
+ patched: hasPatched
1115
+ });
1116
+ }
1117
+ if (majorVersion === 3) {
1118
+ inspectFile("lib/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContext);
1119
+ const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
1120
+ const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(packageInfo.rootPath, candidate)));
1121
+ if (pluginRelative) {
1122
+ inspectFile(pluginRelative, (content) => transformPostcssPlugin(content, { refProperty }));
1123
+ } else {
1124
+ checks.push({ relative: "lib/plugin.js", exists: false, patched: false });
1125
+ }
1126
+ } else {
1127
+ inspectFile("lib/jit/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContextV2);
1128
+ inspectFile("lib/jit/index.js", (content) => transformPostcssPluginV2(content, { refProperty }));
1129
+ }
1130
+ const files = checks.filter((check) => check.exists).map((check) => check.relative);
1131
+ const missingFiles = checks.filter((check) => !check.exists);
1132
+ const unpatchedFiles = checks.filter((check) => check.exists && !check.patched);
1133
+ const reasons = [];
1134
+ if (missingFiles.length) {
1135
+ reasons.push(`missing files: ${missingFiles.map((item) => item.relative).join(", ")}`);
1136
+ }
1137
+ if (unpatchedFiles.length) {
1138
+ reasons.push(`unpatched files: ${unpatchedFiles.map((item) => item.relative).join(", ")}`);
1139
+ }
1140
+ return {
1141
+ name: "exposeContext",
1142
+ status: reasons.length ? "not-applied" : "applied",
1143
+ reason: reasons.length ? reasons.join("; ") : void 0,
1144
+ files
1145
+ };
1146
+ }
1147
+ function checkExtendLengthUnitsV3(rootDir, options) {
1148
+ const lengthUnitsFilePath = _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js"));
1149
+ const variableName = _nullishCoalesce(options.variableName, () => ( "lengthUnits"));
1150
+ const target = _pathe2.default.resolve(rootDir, lengthUnitsFilePath);
1151
+ const files = _fsextra2.default.existsSync(target) ? [_pathe2.default.relative(rootDir, target)] : [];
1152
+ if (!_fsextra2.default.existsSync(target)) {
1153
+ return {
1154
+ name: "extendLengthUnits",
1155
+ status: "not-applied",
1156
+ reason: `missing ${lengthUnitsFilePath}`,
1157
+ files
1158
+ };
1159
+ }
1160
+ const content = _fsextra2.default.readFileSync(target, "utf8");
1161
+ const { found, missingUnits } = inspectLengthUnitsArray(content, variableName, options.units);
1162
+ if (!found) {
1163
+ return {
1164
+ name: "extendLengthUnits",
1165
+ status: "not-applied",
1166
+ reason: `could not locate ${variableName} array in ${lengthUnitsFilePath}`,
1167
+ files
1168
+ };
1169
+ }
1170
+ if (missingUnits.length) {
1171
+ return {
1172
+ name: "extendLengthUnits",
1173
+ status: "not-applied",
1174
+ reason: `missing units: ${missingUnits.join(", ")}`,
1175
+ files
1176
+ };
1177
+ }
1178
+ return {
1179
+ name: "extendLengthUnits",
1180
+ status: "applied",
1181
+ files
1182
+ };
1183
+ }
1184
+ function checkExtendLengthUnitsV4(rootDir, options) {
1185
+ const distDir = _pathe2.default.resolve(rootDir, "dist");
1186
+ if (!_fsextra2.default.existsSync(distDir)) {
1187
+ return {
1188
+ name: "extendLengthUnits",
1189
+ status: "not-applied",
1190
+ reason: "dist directory not found for Tailwind v4 package",
1191
+ files: []
1192
+ };
1193
+ }
1194
+ const result = applyExtendLengthUnitsPatchV4(rootDir, {
1195
+ ...options,
1196
+ enabled: true,
1197
+ overwrite: false
1198
+ });
1199
+ if (result.files.length === 0) {
1200
+ return {
1201
+ name: "extendLengthUnits",
1202
+ status: "not-applied",
1203
+ reason: "no bundle chunks matched the length unit pattern",
1204
+ files: []
1205
+ };
1206
+ }
1207
+ const files = result.files.map((file) => _pathe2.default.relative(rootDir, file.file));
1208
+ const pending = result.files.filter((file) => !file.hasPatched);
1209
+ if (pending.length) {
1210
+ return {
1211
+ name: "extendLengthUnits",
1212
+ status: "not-applied",
1213
+ reason: `missing units in ${pending.length} bundle${pending.length > 1 ? "s" : ""}`,
1214
+ files: pending.map((file) => _pathe2.default.relative(rootDir, file.file))
1215
+ };
1216
+ }
1217
+ return {
1218
+ name: "extendLengthUnits",
1219
+ status: "applied",
1220
+ files
1221
+ };
1222
+ }
1223
+ function checkExtendLengthUnitsPatch(context) {
1224
+ const { packageInfo, options, majorVersion } = context;
1225
+ if (!options.features.extendLengthUnits) {
1226
+ return {
1227
+ name: "extendLengthUnits",
1228
+ status: "skipped",
1229
+ reason: "extendLengthUnits feature disabled",
1230
+ files: []
1231
+ };
1232
+ }
1233
+ if (majorVersion === 2) {
1234
+ return {
1235
+ name: "extendLengthUnits",
1236
+ status: "unsupported",
1237
+ reason: "length unit extension is only applied for Tailwind v3/v4",
1238
+ files: []
1239
+ };
1240
+ }
1241
+ if (majorVersion === 3) {
1242
+ return checkExtendLengthUnitsV3(packageInfo.rootPath, options.features.extendLengthUnits);
1243
+ }
1244
+ return checkExtendLengthUnitsV4(packageInfo.rootPath, options.features.extendLengthUnits);
1245
+ }
1246
+ function getPatchStatusReport(context) {
1247
+ return {
1248
+ package: {
1249
+ name: _nullishCoalesce(context.packageInfo.name, () => ( _optionalChain([context, 'access', _42 => _42.packageInfo, 'access', _43 => _43.packageJson, 'optionalAccess', _44 => _44.name]))),
1250
+ version: context.packageInfo.version,
1251
+ root: context.packageInfo.rootPath
1252
+ },
1253
+ majorVersion: context.majorVersion,
1254
+ entries: [
1255
+ checkExposeContextPatch(context),
1256
+ checkExtendLengthUnitsPatch(context)
1257
+ ]
1258
+ };
1259
+ }
1260
+
1261
+ // src/runtime/class-collector.ts
1262
+
1263
+
1264
+
1265
+ function collectClassesFromContexts(contexts, filter) {
1266
+ const set = /* @__PURE__ */ new Set();
1267
+ for (const context of contexts) {
1268
+ if (!isObject(context) || !context.classCache) {
1269
+ continue;
1270
+ }
1271
+ for (const key of context.classCache.keys()) {
1272
+ const className = key.toString();
1273
+ if (filter(className)) {
1274
+ set.add(className);
1275
+ }
1276
+ }
1277
+ }
1278
+ return set;
1279
+ }
1280
+ async function collectClassesFromTailwindV4(options) {
1281
+ const set = /* @__PURE__ */ new Set();
1282
+ const v4Options = options.tailwind.v4;
1283
+ if (!v4Options) {
1284
+ return set;
1285
+ }
1286
+ const toAbsolute = (value) => {
1287
+ if (!value) {
1288
+ return void 0;
1289
+ }
1290
+ return _pathe2.default.isAbsolute(value) ? value : _pathe2.default.resolve(options.projectRoot, value);
1291
+ };
1292
+ const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
1293
+ const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
1294
+ const resolveSources = (base) => {
1295
+ if (!_optionalChain([v4Options, 'access', _45 => _45.sources, 'optionalAccess', _46 => _46.length])) {
1296
+ return void 0;
1297
+ }
1298
+ return v4Options.sources.map((source) => ({
1299
+ base: _nullishCoalesce(source.base, () => ( base)),
1300
+ pattern: source.pattern,
1301
+ negated: source.negated
1302
+ }));
1303
+ };
1304
+ if (v4Options.cssEntries.length > 0) {
1305
+ for (const entry of v4Options.cssEntries) {
1306
+ const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
1307
+ if (!await _fsextra2.default.pathExists(filePath)) {
1308
+ continue;
1309
+ }
1310
+ const css = await _fsextra2.default.readFile(filePath, "utf8");
1311
+ const entryDir = _pathe2.default.dirname(filePath);
1312
+ const baseForEntry = _nullishCoalesce(resolvedConfiguredBase, () => ( entryDir));
1313
+ const sources = resolveSources(baseForEntry);
1314
+ const candidates = await extractValidCandidates({
1315
+ cwd: options.projectRoot,
1316
+ base: baseForEntry,
1317
+ css,
1318
+ sources
1319
+ });
1320
+ for (const candidate of candidates) {
1321
+ if (options.filter(candidate)) {
1322
+ set.add(candidate);
1323
+ }
1324
+ }
1325
+ }
1326
+ } else {
1327
+ const baseForCss = _nullishCoalesce(resolvedConfiguredBase, () => ( resolvedDefaultBase));
1328
+ const sources = resolveSources(baseForCss);
1329
+ const candidates = await extractValidCandidates({
1330
+ cwd: options.projectRoot,
1331
+ base: baseForCss,
1332
+ css: v4Options.css,
1333
+ sources
1334
+ });
1335
+ for (const candidate of candidates) {
1336
+ if (options.filter(candidate)) {
1337
+ set.add(candidate);
1338
+ }
1339
+ }
1340
+ }
1341
+ return set;
1342
+ }
1343
+
1344
+ // src/runtime/context-registry.ts
1345
+ var _module = require('module');
1346
+
1347
+
1348
+ var require2 = _module.createRequire.call(void 0, importMetaUrl);
1349
+ function resolveRuntimeEntry(packageInfo, majorVersion) {
1350
+ const root = packageInfo.rootPath;
1351
+ if (majorVersion === 2) {
1352
+ const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
1353
+ if (_fsextra2.default.existsSync(jitIndex)) {
1354
+ return jitIndex;
1355
+ }
1356
+ } else if (majorVersion === 3) {
1357
+ const plugin = _pathe2.default.join(root, "lib/plugin.js");
1358
+ const index = _pathe2.default.join(root, "lib/index.js");
1359
+ if (_fsextra2.default.existsSync(plugin)) {
1360
+ return plugin;
1361
+ }
1362
+ if (_fsextra2.default.existsSync(index)) {
1363
+ return index;
1364
+ }
1365
+ }
1366
+ return void 0;
1367
+ }
1368
+ function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
1369
+ if (majorVersion === 4) {
1370
+ return [];
1371
+ }
1372
+ const entry = resolveRuntimeEntry(packageInfo, majorVersion);
1373
+ if (!entry) {
1374
+ return [];
1375
+ }
1376
+ const moduleExports = require2(entry);
1377
+ if (!moduleExports) {
1378
+ return [];
1379
+ }
1380
+ const ref = moduleExports[refProperty];
1381
+ if (!ref) {
1382
+ return [];
1383
+ }
1384
+ if (Array.isArray(ref)) {
1385
+ return ref;
1386
+ }
1387
+ if (typeof ref === "object" && Array.isArray(ref.value)) {
1388
+ return ref.value;
1389
+ }
1390
+ return [];
1391
+ }
1392
+
1393
+ // src/runtime/process-tailwindcss.ts
1394
+
1395
+
1396
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
1397
+ var _tailwindcssconfig = require('tailwindcss-config');
1398
+ var require3 = _module.createRequire.call(void 0, importMetaUrl);
1399
+ async function resolveConfigPath(options) {
1400
+ if (options.config && _pathe2.default.isAbsolute(options.config)) {
1401
+ return options.config;
1402
+ }
1403
+ const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
1404
+ if (!result) {
1405
+ throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
1406
+ }
1407
+ return result.filepath;
1408
+ }
1409
+ async function runTailwindBuild(options) {
1410
+ const configPath = await resolveConfigPath(options);
1411
+ const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
1412
+ if (options.majorVersion === 4) {
1413
+ return _postcss2.default.call(void 0, [
1414
+ require3(pluginName)({
1415
+ config: configPath
1416
+ })
1417
+ ]).process("@import 'tailwindcss';", {
1418
+ from: void 0
1419
+ });
1420
+ }
1421
+ return _postcss2.default.call(void 0, [
1422
+ require3(pluginName)({
1423
+ config: configPath
1424
+ })
1425
+ ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
1426
+ from: void 0
1427
+ });
1428
+ }
1429
+
1430
+ // src/api/tailwindcss-patcher.ts
1431
+
1432
+
1433
+ var _localpkg = require('local-pkg');
1434
+
1435
+ var _semver = require('semver');
1436
+
1437
+ // src/options/legacy.ts
1438
+ function normalizeLegacyFeatures(patch) {
1439
+ const apply = _optionalChain([patch, 'optionalAccess', _47 => _47.applyPatches]);
1440
+ const extend = _optionalChain([apply, 'optionalAccess', _48 => _48.extendLengthUnits]);
1441
+ let extendOption = false;
1442
+ if (extend && typeof extend === "object") {
1443
+ extendOption = {
1444
+ ...extend,
1445
+ enabled: true
1446
+ };
1447
+ } else if (extend === true) {
1448
+ extendOption = {
1449
+ enabled: true,
1450
+ units: ["rpx"],
1451
+ overwrite: _optionalChain([patch, 'optionalAccess', _49 => _49.overwrite])
1452
+ };
1453
+ }
1454
+ return {
1455
+ exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _50 => _50.exportContext]), () => ( true)),
1456
+ extendLengthUnits: extendOption
1457
+ };
1458
+ }
1459
+ function fromLegacyOptions(options) {
1460
+ if (!options) {
1461
+ return {};
1462
+ }
1463
+ const patch = options.patch;
1464
+ const features = normalizeLegacyFeatures(patch);
1465
+ const output = _optionalChain([patch, 'optionalAccess', _51 => _51.output]);
1466
+ const tailwindConfig = _optionalChain([patch, 'optionalAccess', _52 => _52.tailwindcss]);
1467
+ const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _53 => _53.version]);
1468
+ const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _54 => _54.v2]);
1469
+ const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _55 => _55.v3]);
1470
+ const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _56 => _56.v4]);
1471
+ const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _57 => _57.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _58 => _58.config])));
1472
+ const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _59 => _59.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _60 => _60.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _61 => _61.cwd])));
1473
+ return {
1474
+ cwd: _optionalChain([patch, 'optionalAccess', _62 => _62.cwd]),
1475
+ overwrite: _optionalChain([patch, 'optionalAccess', _63 => _63.overwrite]),
1476
+ filter: _optionalChain([patch, 'optionalAccess', _64 => _64.filter]),
1477
+ cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
1478
+ ...options.cache,
1479
+ enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
1480
+ } : void 0,
1481
+ output: output ? {
1482
+ file: output.filename,
1483
+ pretty: output.loose ? 2 : false,
1484
+ removeUniversalSelector: output.removeUniversalSelector
1485
+ } : void 0,
1486
+ tailwind: {
1487
+ packageName: _optionalChain([patch, 'optionalAccess', _65 => _65.packageName]),
1488
+ version: tailwindVersion,
1489
+ resolve: _optionalChain([patch, 'optionalAccess', _66 => _66.resolve]),
1490
+ config: tailwindConfigPath,
1491
+ cwd: tailwindCwd,
1492
+ v2: tailwindV2,
1493
+ v3: tailwindV3,
1494
+ v4: tailwindV4
1495
+ },
1496
+ features: {
1497
+ exposeContext: features.exposeContext,
1498
+ extendLengthUnits: features.extendLengthUnits
1499
+ }
1500
+ };
1501
+ }
1502
+ function fromUnifiedConfig(registry) {
1503
+ if (!registry) {
1504
+ return {};
1505
+ }
1506
+ const tailwind = registry.tailwind;
1507
+ const output = registry.output;
1508
+ const pretty = (() => {
1509
+ if (_optionalChain([output, 'optionalAccess', _67 => _67.pretty]) === void 0) {
1510
+ return void 0;
1511
+ }
1512
+ if (typeof output.pretty === "boolean") {
1513
+ return output.pretty ? 2 : false;
1514
+ }
1515
+ return output.pretty;
1516
+ })();
1517
+ return {
1518
+ output: output ? {
1519
+ file: output.file,
1520
+ pretty,
1521
+ removeUniversalSelector: output.stripUniversalSelector
1522
+ } : void 0,
1523
+ tailwind: tailwind ? {
1524
+ version: tailwind.version,
1525
+ packageName: tailwind.package,
1526
+ resolve: tailwind.resolve,
1527
+ config: tailwind.config,
1528
+ cwd: tailwind.cwd,
1529
+ v2: tailwind.legacy,
1530
+ v3: tailwind.classic,
1531
+ v4: tailwind.next
1532
+ } : void 0
1172
1533
  };
1173
1534
  }
1174
1535
 
1175
1536
  // src/patching/operations/export-context/index.ts
1537
+
1538
+
1176
1539
  function writeFileIfRequired(filePath, code, overwrite, successMessage) {
1177
1540
  if (!overwrite) {
1178
1541
  return;
@@ -1259,147 +1622,6 @@ function applyExposeContextPatch(params) {
1259
1622
  return result;
1260
1623
  }
1261
1624
 
1262
- // src/patching/operations/extend-length-units.ts
1263
-
1264
-
1265
-
1266
- function updateLengthUnitsArray(content, options) {
1267
- const { variableName = "lengthUnits", units } = options;
1268
- const ast = _parser.parse.call(void 0, content);
1269
- let arrayRef;
1270
- let changed = false;
1271
- traverse(ast, {
1272
- Identifier(path10) {
1273
- if (path10.node.name === variableName && t3.isVariableDeclarator(path10.parent) && t3.isArrayExpression(path10.parent.init)) {
1274
- arrayRef = path10.parent.init;
1275
- const existing = new Set(
1276
- path10.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
1277
- );
1278
- for (const unit of units) {
1279
- if (!existing.has(unit)) {
1280
- path10.parent.init.elements = path10.parent.init.elements.map((element) => {
1281
- if (t3.isStringLiteral(element)) {
1282
- return t3.stringLiteral(element.value);
1283
- }
1284
- return element;
1285
- });
1286
- path10.parent.init.elements.push(t3.stringLiteral(unit));
1287
- changed = true;
1288
- }
1289
- }
1290
- }
1291
- }
1292
- });
1293
- return {
1294
- arrayRef,
1295
- changed
1296
- };
1297
- }
1298
- function applyExtendLengthUnitsPatchV3(rootDir, options) {
1299
- if (!options.enabled) {
1300
- return { changed: false, code: void 0 };
1301
- }
1302
- const opts = {
1303
- ...options,
1304
- lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
1305
- variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
1306
- };
1307
- const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
1308
- const exists = _fsextra2.default.existsSync(dataTypesFilePath);
1309
- if (!exists) {
1310
- return { changed: false, code: void 0 };
1311
- }
1312
- const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
1313
- const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
1314
- if (!arrayRef || !changed) {
1315
- return { changed: false, code: void 0 };
1316
- }
1317
- const { code } = generate(arrayRef, {
1318
- jsescOption: { quotes: "single" }
1319
- });
1320
- if (arrayRef.start != null && arrayRef.end != null) {
1321
- const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
1322
- if (opts.overwrite) {
1323
- const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
1324
- _fsextra2.default.writeFileSync(target, nextCode, "utf8");
1325
- logger_default.success("Patched Tailwind CSS length unit list (v3).");
1326
- }
1327
- return {
1328
- changed: true,
1329
- code: nextCode
1330
- };
1331
- }
1332
- return {
1333
- changed: false,
1334
- code: void 0
1335
- };
1336
- }
1337
- function applyExtendLengthUnitsPatchV4(rootDir, options) {
1338
- if (!options.enabled) {
1339
- return { files: [], changed: false };
1340
- }
1341
- const opts = { ...options };
1342
- const distDir = _pathe2.default.resolve(rootDir, "dist");
1343
- if (!_fsextra2.default.existsSync(distDir)) {
1344
- return { files: [], changed: false };
1345
- }
1346
- const entries = _fsextra2.default.readdirSync(distDir);
1347
- const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
1348
- const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
1349
- const candidates = chunkNames.map((chunkName) => {
1350
- const file = _pathe2.default.join(distDir, chunkName);
1351
- const code = _fsextra2.default.readFileSync(file, "utf8");
1352
- const match = pattern.exec(code);
1353
- if (!match) {
1354
- return null;
1355
- }
1356
- return {
1357
- file,
1358
- code,
1359
- match,
1360
- hasPatched: false
1361
- };
1362
- }).filter((candidate) => candidate !== null);
1363
- for (const item of candidates) {
1364
- const { code, file, match } = item;
1365
- const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
1366
- traverse(ast, {
1367
- ArrayExpression(path10) {
1368
- for (const unit of opts.units) {
1369
- if (path10.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
1370
- item.hasPatched = true;
1371
- return;
1372
- }
1373
- path10.node.elements.push(t3.stringLiteral(unit));
1374
- }
1375
- }
1376
- });
1377
- if (item.hasPatched) {
1378
- continue;
1379
- }
1380
- const { code: replacement } = generate(ast, { minified: true });
1381
- const start = _nullishCoalesce(match.index, () => ( 0));
1382
- const end = start + match[0].length;
1383
- item.code = spliceChangesIntoString(code, [
1384
- {
1385
- start,
1386
- end,
1387
- replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
1388
- }
1389
- ]);
1390
- if (opts.overwrite) {
1391
- _fsextra2.default.writeFileSync(file, item.code, "utf8");
1392
- }
1393
- }
1394
- if (candidates.some((file) => !file.hasPatched)) {
1395
- logger_default.success("Patched Tailwind CSS length unit list (v4).");
1396
- }
1397
- return {
1398
- changed: candidates.some((file) => !file.hasPatched),
1399
- files: candidates
1400
- };
1401
- }
1402
-
1403
1625
  // src/patching/patch-runner.ts
1404
1626
  function applyTailwindPatches(context) {
1405
1627
  const { packageInfo, options, majorVersion } = context;
@@ -1412,7 +1634,7 @@ function applyTailwindPatches(context) {
1412
1634
  majorVersion
1413
1635
  });
1414
1636
  }
1415
- if (_optionalChain([options, 'access', _65 => _65.features, 'access', _66 => _66.extendLengthUnits, 'optionalAccess', _67 => _67.enabled])) {
1637
+ if (_optionalChain([options, 'access', _68 => _68.features, 'access', _69 => _69.extendLengthUnits, 'optionalAccess', _70 => _70.enabled])) {
1416
1638
  if (majorVersion === 3) {
1417
1639
  results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
1418
1640
  packageInfo.rootPath,
@@ -1498,6 +1720,13 @@ var TailwindcssPatcher = (_class = class {
1498
1720
  majorVersion: this.majorVersion
1499
1721
  });
1500
1722
  }
1723
+ async getPatchStatus() {
1724
+ return getPatchStatusReport({
1725
+ packageInfo: this.packageInfo,
1726
+ options: this.options,
1727
+ majorVersion: this.majorVersion
1728
+ });
1729
+ }
1501
1730
  getContexts() {
1502
1731
  return loadRuntimeContexts(
1503
1732
  this.packageInfo,
@@ -1579,7 +1808,7 @@ var TailwindcssPatcher = (_class = class {
1579
1808
  return merged;
1580
1809
  }
1581
1810
  async extract(options) {
1582
- const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.write]), () => ( this.options.output.enabled));
1811
+ const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.write]), () => ( this.options.output.enabled));
1583
1812
  const classSet = await this.getClassSet();
1584
1813
  const classList = Array.from(classSet);
1585
1814
  const result = {
@@ -1608,18 +1837,18 @@ var TailwindcssPatcher = (_class = class {
1608
1837
  __init() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
1609
1838
  async collectContentTokens(options) {
1610
1839
  return extractProjectCandidatesWithPositions({
1611
- cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _69 => _69.cwd]), () => ( this.options.projectRoot)),
1612
- 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]))), () => ( []))
1840
+ cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.cwd]), () => ( this.options.projectRoot)),
1841
+ sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _73 => _73.sources]), () => ( _optionalChain([this, 'access', _74 => _74.options, 'access', _75 => _75.tailwind, 'access', _76 => _76.v4, 'optionalAccess', _77 => _77.sources]))), () => ( []))
1613
1842
  });
1614
1843
  }
1615
1844
  async collectContentTokensByFile(options) {
1616
1845
  const report = await this.collectContentTokens({
1617
- cwd: _optionalChain([options, 'optionalAccess', _75 => _75.cwd]),
1618
- sources: _optionalChain([options, 'optionalAccess', _76 => _76.sources])
1846
+ cwd: _optionalChain([options, 'optionalAccess', _78 => _78.cwd]),
1847
+ sources: _optionalChain([options, 'optionalAccess', _79 => _79.sources])
1619
1848
  });
1620
1849
  return groupTokensByFile(report, {
1621
- key: _optionalChain([options, 'optionalAccess', _77 => _77.key]),
1622
- stripAbsolutePaths: _optionalChain([options, 'optionalAccess', _78 => _78.stripAbsolutePaths])
1850
+ key: _optionalChain([options, 'optionalAccess', _80 => _80.key]),
1851
+ stripAbsolutePaths: _optionalChain([options, 'optionalAccess', _81 => _81.stripAbsolutePaths])
1623
1852
  });
1624
1853
  }
1625
1854
  }, _class);
@@ -1722,7 +1951,7 @@ var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
1722
1951
  var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
1723
1952
 
1724
1953
 
1725
- var tailwindcssPatchCommands = ["install", "extract", "tokens", "init"];
1954
+ var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "status"];
1726
1955
  var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
1727
1956
  var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
1728
1957
  function formatTokenLine(entry) {
@@ -1762,7 +1991,7 @@ function createDefaultRunner(factory) {
1762
1991
  async function loadPatchOptionsForCwd(cwd, overrides) {
1763
1992
  const { config } = await _config.getConfig.call(void 0, cwd);
1764
1993
  const legacyConfig = config;
1765
- const base = _optionalChain([config, 'optionalAccess', _79 => _79.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _80 => _80.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
1994
+ const base = _optionalChain([config, 'optionalAccess', _82 => _82.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _83 => _83.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
1766
1995
  const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
1767
1996
  return merged;
1768
1997
  }
@@ -1850,6 +2079,13 @@ function buildDefaultCommandDefinitions() {
1850
2079
  init: {
1851
2080
  description: "Generate a tailwindcss-patch config file",
1852
2081
  optionDefs: [createCwdOptionDefinition()]
2082
+ },
2083
+ status: {
2084
+ description: "Check which Tailwind patches are applied",
2085
+ optionDefs: [
2086
+ createCwdOptionDefinition(),
2087
+ { flags: "--json", description: "Print a JSON report of patch status" }
2088
+ ]
1853
2089
  }
1854
2090
  };
1855
2091
  }
@@ -1860,10 +2096,10 @@ function addPrefixIfMissing(value, prefix) {
1860
2096
  return `${prefix}${value}`;
1861
2097
  }
1862
2098
  function resolveCommandNames(command, mountOptions, prefix) {
1863
- const override = _optionalChain([mountOptions, 'access', _81 => _81.commandOptions, 'optionalAccess', _82 => _82[command]]);
1864
- const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _83 => _83.name]), () => ( command));
2099
+ const override = _optionalChain([mountOptions, 'access', _84 => _84.commandOptions, 'optionalAccess', _85 => _85[command]]);
2100
+ const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _86 => _86.name]), () => ( command));
1865
2101
  const name = addPrefixIfMissing(baseName, prefix);
1866
- const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _84 => _84.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
2102
+ const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
1867
2103
  return { name, aliases };
1868
2104
  }
1869
2105
  function resolveOptionDefinitions(defaults, override) {
@@ -1897,8 +2133,8 @@ function runWithCommandHandler(cli, command, commandName, args, handler, default
1897
2133
  function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
1898
2134
  const names = resolveCommandNames(command, mountOptions, prefix);
1899
2135
  const definition = defaults[command];
1900
- const override = _optionalChain([mountOptions, 'access', _85 => _85.commandOptions, 'optionalAccess', _86 => _86[command]]);
1901
- const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.description]), () => ( definition.description));
2136
+ const override = _optionalChain([mountOptions, 'access', _88 => _88.commandOptions, 'optionalAccess', _89 => _89[command]]);
2137
+ const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _90 => _90.description]), () => ( definition.description));
1902
2138
  const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
1903
2139
  return { ...names, description, optionDefs };
1904
2140
  }
@@ -2006,6 +2242,46 @@ async function initCommandDefaultHandler(ctx) {
2006
2242
  await _config.initConfig.call(void 0, ctx.cwd);
2007
2243
  logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
2008
2244
  }
2245
+ function formatFilesHint(entry) {
2246
+ if (!entry.files.length) {
2247
+ return "";
2248
+ }
2249
+ return ` (${entry.files.join(", ")})`;
2250
+ }
2251
+ async function statusCommandDefaultHandler(ctx) {
2252
+ const patcher = await ctx.createPatcher();
2253
+ const report = await patcher.getPatchStatus();
2254
+ if (ctx.args.json) {
2255
+ logger_default.log(JSON.stringify(report, null, 2));
2256
+ return report;
2257
+ }
2258
+ const applied = report.entries.filter((entry) => entry.status === "applied");
2259
+ const pending = report.entries.filter((entry) => entry.status === "not-applied");
2260
+ const skipped = report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported");
2261
+ const packageLabel = `${_nullishCoalesce(report.package.name, () => ( "tailwindcss"))}@${_nullishCoalesce(report.package.version, () => ( "unknown"))}`;
2262
+ logger_default.info(`Patch status for ${packageLabel} (v${report.majorVersion})`);
2263
+ if (applied.length) {
2264
+ logger_default.success("Applied:");
2265
+ applied.forEach((entry) => logger_default.success(` \u2022 ${entry.name}${formatFilesHint(entry)}`));
2266
+ }
2267
+ if (pending.length) {
2268
+ logger_default.warn("Needs attention:");
2269
+ pending.forEach((entry) => {
2270
+ const details = entry.reason ? ` \u2013 ${entry.reason}` : "";
2271
+ logger_default.warn(` \u2022 ${entry.name}${formatFilesHint(entry)}${details}`);
2272
+ });
2273
+ } else {
2274
+ logger_default.success("All applicable patches are applied.");
2275
+ }
2276
+ if (skipped.length) {
2277
+ logger_default.info("Skipped:");
2278
+ skipped.forEach((entry) => {
2279
+ const details = entry.reason ? ` \u2013 ${entry.reason}` : "";
2280
+ logger_default.info(` \u2022 ${entry.name}${details}`);
2281
+ });
2282
+ }
2283
+ return report;
2284
+ }
2009
2285
  function mountTailwindcssPatchCommands(cli, options = {}) {
2010
2286
  const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
2011
2287
  const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
@@ -2021,7 +2297,7 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2021
2297
  command,
2022
2298
  "install",
2023
2299
  args,
2024
- _optionalChain([options, 'access', _88 => _88.commandHandlers, 'optionalAccess', _89 => _89.install]),
2300
+ _optionalChain([options, 'access', _91 => _91.commandHandlers, 'optionalAccess', _92 => _92.install]),
2025
2301
  installCommandDefaultHandler
2026
2302
  );
2027
2303
  });
@@ -2037,7 +2313,7 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2037
2313
  command,
2038
2314
  "extract",
2039
2315
  args,
2040
- _optionalChain([options, 'access', _90 => _90.commandHandlers, 'optionalAccess', _91 => _91.extract]),
2316
+ _optionalChain([options, 'access', _93 => _93.commandHandlers, 'optionalAccess', _94 => _94.extract]),
2041
2317
  extractCommandDefaultHandler
2042
2318
  );
2043
2319
  });
@@ -2053,7 +2329,7 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2053
2329
  command,
2054
2330
  "tokens",
2055
2331
  args,
2056
- _optionalChain([options, 'access', _92 => _92.commandHandlers, 'optionalAccess', _93 => _93.tokens]),
2332
+ _optionalChain([options, 'access', _95 => _95.commandHandlers, 'optionalAccess', _96 => _96.tokens]),
2057
2333
  tokensCommandDefaultHandler
2058
2334
  );
2059
2335
  });
@@ -2069,11 +2345,27 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2069
2345
  command,
2070
2346
  "init",
2071
2347
  args,
2072
- _optionalChain([options, 'access', _94 => _94.commandHandlers, 'optionalAccess', _95 => _95.init]),
2348
+ _optionalChain([options, 'access', _97 => _97.commandHandlers, 'optionalAccess', _98 => _98.init]),
2073
2349
  initCommandDefaultHandler
2074
2350
  );
2075
2351
  });
2076
2352
  metadata.aliases.forEach((alias) => command.alias(alias));
2353
+ },
2354
+ status: () => {
2355
+ const metadata = resolveCommandMetadata("status", options, prefix, defaultDefinitions);
2356
+ const command = cli.command(metadata.name, metadata.description);
2357
+ applyCommandOptions(command, metadata.optionDefs);
2358
+ command.action(async (args) => {
2359
+ return runWithCommandHandler(
2360
+ cli,
2361
+ command,
2362
+ "status",
2363
+ args,
2364
+ _optionalChain([options, 'access', _99 => _99.commandHandlers, 'optionalAccess', _100 => _100.status]),
2365
+ statusCommandDefaultHandler
2366
+ );
2367
+ });
2368
+ metadata.aliases.forEach((alias) => command.alias(alias));
2077
2369
  }
2078
2370
  };
2079
2371
  for (const name of selectedCommands) {
@@ -2107,4 +2399,5 @@ function createTailwindcssPatchCli(options = {}) {
2107
2399
 
2108
2400
 
2109
2401
 
2110
- 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;
2402
+
2403
+ 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.getPatchStatusReport = getPatchStatusReport; exports.collectClassesFromContexts = collectClassesFromContexts; exports.collectClassesFromTailwindV4 = collectClassesFromTailwindV4; exports.loadRuntimeContexts = loadRuntimeContexts; exports.runTailwindBuild = runTailwindBuild; exports.TailwindcssPatcher = TailwindcssPatcher; exports.tailwindcssPatchCommands = tailwindcssPatchCommands; exports.mountTailwindcssPatchCommands = mountTailwindcssPatchCommands; exports.createTailwindcssPatchCli = createTailwindcssPatchCli;