tailwindcss-patch 8.4.2 → 8.5.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.
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.20.6_typescript@5.9.3_yaml@2.8.1/node_modules/tsup/assets/cjs_shims.js
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;// ../../node_modules/.pnpm/tsup@8.5.1_jiti@1.21.7_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/cjs_shims.js
2
2
  var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${__filename}`).href : document.currentScript && document.currentScript.tagName.toUpperCase() === "SCRIPT" ? document.currentScript.src : new URL("main.js", document.baseURI).href;
3
3
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
4
4
 
@@ -524,328 +524,186 @@ function normalizeOptions(options = {}) {
524
524
  };
525
525
  }
526
526
 
527
- // src/runtime/class-collector.ts
528
-
527
+ // src/patching/status.ts
528
+ var _types = require('@babel/types'); var t4 = _interopRequireWildcard(_types); var t = _interopRequireWildcard(_types); var t2 = _interopRequireWildcard(_types); var t3 = _interopRequireWildcard(_types);
529
529
 
530
530
 
531
531
 
532
- // src/utils.ts
533
- function isObject(val) {
534
- return val !== null && typeof val === "object" && Array.isArray(val) === false;
532
+ // src/babel/index.ts
533
+ var _generator = require('@babel/generator'); var _generator2 = _interopRequireDefault(_generator);
534
+ var _traverse = require('@babel/traverse'); var _traverse2 = _interopRequireDefault(_traverse);
535
+ var _parser = require('@babel/parser');
536
+ function _interopDefaultCompat(e) {
537
+ return e && typeof e === "object" && "default" in e ? e.default : e;
535
538
  }
536
- function spliceChangesIntoString(str, changes) {
537
- if (!changes[0]) {
538
- return str;
539
+ var generate = _interopDefaultCompat(_generator2.default);
540
+ var traverse = _interopDefaultCompat(_traverse2.default);
541
+
542
+ // src/patching/operations/export-context/postcss-v2.ts
543
+
544
+ var IDENTIFIER_RE = /^[A-Z_$][\w$]*$/i;
545
+ function toIdentifierName(property) {
546
+ if (!property) {
547
+ return "contextRef";
539
548
  }
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;
549
+ const sanitized = property.replace(/[^\w$]/gu, "_");
550
+ if (/^\d/.test(sanitized)) {
551
+ return `_${sanitized}`;
552
552
  }
553
- result += str.slice(previous.end);
554
- return result;
553
+ return sanitized || "contextRef";
555
554
  }
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
- }
555
+ function createExportsMember(property) {
556
+ if (IDENTIFIER_RE.test(property)) {
557
+ return t.memberExpression(t.identifier("exports"), t.identifier(property));
570
558
  }
571
- return set;
559
+ return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
572
560
  }
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;
561
+ function transformProcessTailwindFeaturesReturnContextV2(content) {
562
+ const ast = _parser.parse.call(void 0, content, {
563
+ sourceType: "unambiguous"
564
+ });
565
+ let hasPatched = false;
566
+ traverse(ast, {
567
+ FunctionDeclaration(path11) {
568
+ const node = path11.node;
569
+ if (_optionalChain([node, 'access', _28 => _28.id, 'optionalAccess', _29 => _29.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
570
+ return;
571
+ }
572
+ const returnStatement3 = node.body.body[0];
573
+ if (!t.isFunctionExpression(returnStatement3.argument)) {
574
+ return;
575
+ }
576
+ const body = returnStatement3.argument.body.body;
577
+ const lastStatement = body[body.length - 1];
578
+ const alreadyReturnsContext = Boolean(
579
+ t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
580
+ );
581
+ hasPatched = alreadyReturnsContext;
582
+ if (!alreadyReturnsContext) {
583
+ body.push(t.returnStatement(t.identifier("context")));
584
+ }
590
585
  }
591
- return v4Options.sources.map((source) => ({
592
- base: _nullishCoalesce(source.base, () => ( base)),
593
- pattern: source.pattern,
594
- negated: source.negated
595
- }));
586
+ });
587
+ return {
588
+ code: hasPatched ? content : generate(ast).code,
589
+ hasPatched
596
590
  };
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
591
+ }
592
+ function transformPostcssPluginV2(content, options) {
593
+ const refIdentifier = t.identifier(toIdentifierName(options.refProperty));
594
+ const exportMember = createExportsMember(options.refProperty);
595
+ const valueMember = t.memberExpression(refIdentifier, t.identifier("value"));
596
+ const ast = _parser.parse.call(void 0, content);
597
+ let hasPatched = false;
598
+ traverse(ast, {
599
+ Program(path11) {
600
+ const program = path11.node;
601
+ const index = program.body.findIndex((statement) => {
602
+ return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _30 => _30.id, 'optionalAccess', _31 => _31.name]) === "_default";
612
603
  });
613
- for (const candidate of candidates) {
614
- if (options.filter(candidate)) {
615
- set.add(candidate);
616
- }
604
+ if (index === -1) {
605
+ return;
617
606
  }
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);
607
+ const previous = program.body[index - 1];
608
+ const beforePrevious = program.body[index - 2];
609
+ const alreadyHasVariable = Boolean(
610
+ previous && t.isVariableDeclaration(previous) && previous.declarations.length === 1 && t.isIdentifier(previous.declarations[0].id) && previous.declarations[0].id.name === refIdentifier.name
611
+ );
612
+ const alreadyAssignsExports = Boolean(
613
+ 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
614
+ );
615
+ hasPatched = alreadyHasVariable && alreadyAssignsExports;
616
+ if (!alreadyHasVariable) {
617
+ program.body.splice(
618
+ index,
619
+ 0,
620
+ t.variableDeclaration("var", [
621
+ t.variableDeclarator(
622
+ refIdentifier,
623
+ t.objectExpression([
624
+ t.objectProperty(t.identifier("value"), t.arrayExpression())
625
+ ])
626
+ )
627
+ ]),
628
+ t.expressionStatement(
629
+ t.assignmentExpression("=", exportMember, refIdentifier)
630
+ )
631
+ );
632
+ }
633
+ },
634
+ FunctionDeclaration(path11) {
635
+ if (hasPatched) {
636
+ return;
637
+ }
638
+ const fn = path11.node;
639
+ if (_optionalChain([fn, 'access', _32 => _32.id, 'optionalAccess', _33 => _33.name]) !== "_default") {
640
+ return;
641
+ }
642
+ if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
643
+ return;
644
+ }
645
+ const returnStatement3 = fn.body.body[0];
646
+ if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
647
+ return;
648
+ }
649
+ const fnExpression = returnStatement3.argument.callee.object.elements[1];
650
+ if (!fnExpression || !t.isFunctionExpression(fnExpression)) {
651
+ return;
652
+ }
653
+ const block = fnExpression.body;
654
+ const statements = block.body;
655
+ if (t.isExpressionStatement(statements[0]) && t.isAssignmentExpression(statements[0].expression) && t.isNumericLiteral(statements[0].expression.right)) {
656
+ hasPatched = true;
657
+ return;
658
+ }
659
+ const lastStatement = statements[statements.length - 1];
660
+ if (lastStatement && t.isExpressionStatement(lastStatement)) {
661
+ statements[statements.length - 1] = t.expressionStatement(
662
+ t.callExpression(
663
+ t.memberExpression(valueMember, t.identifier("push")),
664
+ [lastStatement.expression]
665
+ )
666
+ );
667
+ }
668
+ const index = statements.findIndex((statement) => t.isIfStatement(statement));
669
+ if (index > -1) {
670
+ const ifStatement = statements[index];
671
+ if (t.isBlockStatement(ifStatement.consequent) && ifStatement.consequent.body[1] && t.isForOfStatement(ifStatement.consequent.body[1])) {
672
+ const forOf = ifStatement.consequent.body[1];
673
+ if (t.isBlockStatement(forOf.body) && forOf.body.body.length === 1) {
674
+ const nestedIf = forOf.body.body[0];
675
+ if (nestedIf && t.isIfStatement(nestedIf) && t.isBlockStatement(nestedIf.consequent) && nestedIf.consequent.body.length === 1 && t.isExpressionStatement(nestedIf.consequent.body[0])) {
676
+ nestedIf.consequent.body[0] = t.expressionStatement(
677
+ t.callExpression(
678
+ t.memberExpression(valueMember, t.identifier("push")),
679
+ [nestedIf.consequent.body[0].expression]
680
+ )
681
+ );
682
+ }
683
+ }
684
+ }
631
685
  }
686
+ statements.unshift(
687
+ t.expressionStatement(
688
+ t.assignmentExpression(
689
+ "=",
690
+ t.memberExpression(valueMember, t.identifier("length")),
691
+ t.numericLiteral(0)
692
+ )
693
+ )
694
+ );
632
695
  }
633
- }
634
- return set;
696
+ });
697
+ return {
698
+ code: hasPatched ? content : generate(ast).code,
699
+ hasPatched
700
+ };
635
701
  }
636
702
 
637
- // src/runtime/context-registry.ts
638
- var _module = require('module');
639
-
703
+ // src/patching/operations/export-context/postcss-v3.ts
640
704
 
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) {
705
+ var IDENTIFIER_RE2 = /^[A-Z_$][\w$]*$/i;
706
+ function toIdentifierName2(property) {
849
707
  if (!property) {
850
708
  return "contextRef";
851
709
  }
@@ -855,35 +713,35 @@ function toIdentifierName(property) {
855
713
  }
856
714
  return sanitized || "contextRef";
857
715
  }
858
- function createExportsMember(property) {
859
- if (IDENTIFIER_RE.test(property)) {
860
- return t.memberExpression(t.identifier("exports"), t.identifier(property));
716
+ function createModuleExportsMember(property) {
717
+ const object = t2.memberExpression(t2.identifier("module"), t2.identifier("exports"));
718
+ if (IDENTIFIER_RE2.test(property)) {
719
+ return t2.memberExpression(object, t2.identifier(property));
861
720
  }
862
- return t.memberExpression(t.identifier("exports"), t.stringLiteral(property), true);
721
+ return t2.memberExpression(object, t2.stringLiteral(property), true);
863
722
  }
864
- function transformProcessTailwindFeaturesReturnContextV2(content) {
865
- const ast = _parser.parse.call(void 0, content, {
866
- sourceType: "unambiguous"
867
- });
723
+ function transformProcessTailwindFeaturesReturnContext(content) {
724
+ const ast = _parser.parse.call(void 0, content);
868
725
  let hasPatched = false;
869
726
  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])) {
727
+ FunctionDeclaration(path11) {
728
+ const node = path11.node;
729
+ if (_optionalChain([node, 'access', _34 => _34.id, 'optionalAccess', _35 => _35.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
873
730
  return;
874
731
  }
875
- const returnStatement3 = node.body.body[0];
876
- if (!t.isFunctionExpression(returnStatement3.argument)) {
732
+ const [returnStatement3] = node.body.body;
733
+ if (!t2.isReturnStatement(returnStatement3) || !t2.isFunctionExpression(returnStatement3.argument)) {
877
734
  return;
878
735
  }
879
- const body = returnStatement3.argument.body.body;
736
+ const expression = returnStatement3.argument;
737
+ const body = expression.body.body;
880
738
  const lastStatement = body[body.length - 1];
881
739
  const alreadyReturnsContext = Boolean(
882
- t.isReturnStatement(lastStatement) && t.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
740
+ t2.isReturnStatement(lastStatement) && t2.isIdentifier(lastStatement.argument) && lastStatement.argument.name === "context"
883
741
  );
884
742
  hasPatched = alreadyReturnsContext;
885
743
  if (!alreadyReturnsContext) {
886
- body.push(t.returnStatement(t.identifier("context")));
744
+ body.push(t2.returnStatement(t2.identifier("context")));
887
745
  }
888
746
  }
889
747
  });
@@ -892,233 +750,72 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
892
750
  hasPatched
893
751
  };
894
752
  }
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"));
753
+ function transformPostcssPlugin(content, { refProperty }) {
899
754
  const ast = _parser.parse.call(void 0, content);
755
+ const refIdentifier = t2.identifier(toIdentifierName2(refProperty));
756
+ const moduleExportsMember = createModuleExportsMember(refProperty);
757
+ const valueMember = t2.memberExpression(refIdentifier, t2.identifier("value"));
900
758
  let hasPatched = false;
901
759
  traverse(ast, {
902
- Program(path10) {
903
- const program = path10.node;
760
+ Program(path11) {
761
+ const program = path11.node;
904
762
  const index = program.body.findIndex((statement) => {
905
- return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _53 => _53.id, 'optionalAccess', _54 => _54.name]) === "_default";
763
+ 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
764
  });
907
765
  if (index === -1) {
908
766
  return;
909
767
  }
910
- const previous = program.body[index - 1];
911
- const beforePrevious = program.body[index - 2];
768
+ const previousStatement = program.body[index - 1];
769
+ const lastStatement = program.body[program.body.length - 1];
912
770
  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
771
+ previousStatement && t2.isVariableDeclaration(previousStatement) && previousStatement.declarations.length === 1 && t2.isIdentifier(previousStatement.declarations[0].id) && previousStatement.declarations[0].id.name === refIdentifier.name
914
772
  );
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
773
+ const alreadyAssignsModuleExports = Boolean(
774
+ 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
775
  );
918
- hasPatched = alreadyHasVariable && alreadyAssignsExports;
776
+ hasPatched = alreadyHasVariable && alreadyAssignsModuleExports;
919
777
  if (!alreadyHasVariable) {
920
778
  program.body.splice(
921
779
  index,
922
780
  0,
923
- t.variableDeclaration("var", [
924
- t.variableDeclarator(
781
+ t2.variableDeclaration("const", [
782
+ t2.variableDeclarator(
925
783
  refIdentifier,
926
- t.objectExpression([
927
- t.objectProperty(t.identifier("value"), t.arrayExpression())
784
+ t2.objectExpression([
785
+ t2.objectProperty(t2.identifier("value"), t2.arrayExpression())
928
786
  ])
929
787
  )
930
- ]),
931
- t.expressionStatement(
932
- t.assignmentExpression("=", exportMember, refIdentifier)
788
+ ])
789
+ );
790
+ }
791
+ if (!alreadyAssignsModuleExports) {
792
+ program.body.push(
793
+ t2.expressionStatement(
794
+ t2.assignmentExpression("=", moduleExportsMember, refIdentifier)
933
795
  )
934
796
  );
935
797
  }
936
798
  },
937
- FunctionDeclaration(path10) {
799
+ FunctionExpression(path11) {
938
800
  if (hasPatched) {
939
801
  return;
940
802
  }
941
- const fn = path10.node;
942
- if (_optionalChain([fn, 'access', _55 => _55.id, 'optionalAccess', _56 => _56.name]) !== "_default") {
803
+ const fn = path11.node;
804
+ if (_optionalChain([fn, 'access', _40 => _40.id, 'optionalAccess', _41 => _41.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
943
805
  return;
944
806
  }
945
- if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
807
+ const [returnStatement3] = fn.body.body;
808
+ if (!returnStatement3 || !t2.isReturnStatement(returnStatement3) || !t2.isObjectExpression(returnStatement3.argument)) {
946
809
  return;
947
810
  }
948
- const returnStatement3 = fn.body.body[0];
949
- if (!t.isCallExpression(returnStatement3.argument) || !t.isMemberExpression(returnStatement3.argument.callee) || !t.isArrayExpression(returnStatement3.argument.callee.object)) {
811
+ const properties = returnStatement3.argument.properties;
812
+ if (properties.length !== 2) {
950
813
  return;
951
814
  }
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) {
1108
- return;
1109
- }
1110
- const [returnStatement3] = fn.body.body;
1111
- if (!returnStatement3 || !t2.isReturnStatement(returnStatement3) || !t2.isObjectExpression(returnStatement3.argument)) {
1112
- return;
1113
- }
1114
- const properties = returnStatement3.argument.properties;
1115
- if (properties.length !== 2) {
1116
- return;
1117
- }
1118
- const pluginsProperty = properties.find(
1119
- (prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === "plugins"
1120
- );
1121
- if (!pluginsProperty || !t2.isObjectProperty(pluginsProperty) || !t2.isCallExpression(pluginsProperty.value) || !t2.isMemberExpression(pluginsProperty.value.callee) || !t2.isArrayExpression(pluginsProperty.value.callee.object)) {
815
+ const pluginsProperty = properties.find(
816
+ (prop) => t2.isObjectProperty(prop) && t2.isIdentifier(prop.key) && prop.key.name === "plugins"
817
+ );
818
+ if (!pluginsProperty || !t2.isObjectProperty(pluginsProperty) || !t2.isCallExpression(pluginsProperty.value) || !t2.isMemberExpression(pluginsProperty.value.callee) || !t2.isArrayExpression(pluginsProperty.value.callee.object)) {
1122
819
  return;
1123
820
  }
1124
821
  const pluginsArray = pluginsProperty.value.callee.object.elements;
@@ -1165,14 +862,659 @@ function transformPostcssPlugin(content, { refProperty }) {
1165
862
  )
1166
863
  );
1167
864
  }
1168
- });
865
+ });
866
+ return {
867
+ code: hasPatched ? content : generate(ast).code,
868
+ hasPatched
869
+ };
870
+ }
871
+
872
+ // src/patching/operations/extend-length-units.ts
873
+
874
+
875
+
876
+
877
+ // src/utils.ts
878
+ function isObject(val) {
879
+ return val !== null && typeof val === "object" && Array.isArray(val) === false;
880
+ }
881
+ function spliceChangesIntoString(str, changes) {
882
+ if (!changes[0]) {
883
+ return str;
884
+ }
885
+ changes.sort((a, b) => {
886
+ return a.end - b.end || a.start - b.start;
887
+ });
888
+ let result = "";
889
+ let previous = changes[0];
890
+ result += str.slice(0, previous.start);
891
+ result += previous.replacement;
892
+ for (let i = 1; i < changes.length; ++i) {
893
+ const change = changes[i];
894
+ result += str.slice(previous.end, change.start);
895
+ result += change.replacement;
896
+ previous = change;
897
+ }
898
+ result += str.slice(previous.end);
899
+ return result;
900
+ }
901
+
902
+ // src/patching/operations/extend-length-units.ts
903
+ function updateLengthUnitsArray(content, options) {
904
+ const { variableName = "lengthUnits", units } = options;
905
+ const ast = _parser.parse.call(void 0, content);
906
+ let arrayRef;
907
+ let changed = false;
908
+ traverse(ast, {
909
+ Identifier(path11) {
910
+ if (path11.node.name === variableName && t3.isVariableDeclarator(path11.parent) && t3.isArrayExpression(path11.parent.init)) {
911
+ arrayRef = path11.parent.init;
912
+ const existing = new Set(
913
+ path11.parent.init.elements.map((element) => t3.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
914
+ );
915
+ for (const unit of units) {
916
+ if (!existing.has(unit)) {
917
+ path11.parent.init.elements = path11.parent.init.elements.map((element) => {
918
+ if (t3.isStringLiteral(element)) {
919
+ return t3.stringLiteral(element.value);
920
+ }
921
+ return element;
922
+ });
923
+ path11.parent.init.elements.push(t3.stringLiteral(unit));
924
+ changed = true;
925
+ }
926
+ }
927
+ }
928
+ }
929
+ });
930
+ return {
931
+ arrayRef,
932
+ changed
933
+ };
934
+ }
935
+ function applyExtendLengthUnitsPatchV3(rootDir, options) {
936
+ if (!options.enabled) {
937
+ return { changed: false, code: void 0 };
938
+ }
939
+ const opts = {
940
+ ...options,
941
+ lengthUnitsFilePath: _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js")),
942
+ variableName: _nullishCoalesce(options.variableName, () => ( "lengthUnits"))
943
+ };
944
+ const dataTypesFilePath = _pathe2.default.resolve(rootDir, opts.lengthUnitsFilePath);
945
+ const exists = _fsextra2.default.existsSync(dataTypesFilePath);
946
+ if (!exists) {
947
+ return { changed: false, code: void 0 };
948
+ }
949
+ const content = _fsextra2.default.readFileSync(dataTypesFilePath, "utf8");
950
+ const { arrayRef, changed } = updateLengthUnitsArray(content, opts);
951
+ if (!arrayRef || !changed) {
952
+ return { changed: false, code: void 0 };
953
+ }
954
+ const { code } = generate(arrayRef, {
955
+ jsescOption: { quotes: "single" }
956
+ });
957
+ if (arrayRef.start != null && arrayRef.end != null) {
958
+ const nextCode = `${content.slice(0, arrayRef.start)}${code}${content.slice(arrayRef.end)}`;
959
+ if (opts.overwrite) {
960
+ const target = opts.destPath ? _pathe2.default.resolve(opts.destPath) : dataTypesFilePath;
961
+ _fsextra2.default.writeFileSync(target, nextCode, "utf8");
962
+ logger_default.success("Patched Tailwind CSS length unit list (v3).");
963
+ }
964
+ return {
965
+ changed: true,
966
+ code: nextCode
967
+ };
968
+ }
969
+ return {
970
+ changed: false,
971
+ code: void 0
972
+ };
973
+ }
974
+ function applyExtendLengthUnitsPatchV4(rootDir, options) {
975
+ if (!options.enabled) {
976
+ return { files: [], changed: false };
977
+ }
978
+ const opts = { ...options };
979
+ const distDir = _pathe2.default.resolve(rootDir, "dist");
980
+ if (!_fsextra2.default.existsSync(distDir)) {
981
+ return { files: [], changed: false };
982
+ }
983
+ const entries = _fsextra2.default.readdirSync(distDir);
984
+ const chunkNames = entries.filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs"));
985
+ const pattern = /\[\s*["']cm["'],\s*["']mm["'],[\w,"']+\]/;
986
+ const candidates = chunkNames.map((chunkName) => {
987
+ const file = _pathe2.default.join(distDir, chunkName);
988
+ const code = _fsextra2.default.readFileSync(file, "utf8");
989
+ const match = pattern.exec(code);
990
+ if (!match) {
991
+ return null;
992
+ }
993
+ return {
994
+ file,
995
+ code,
996
+ match,
997
+ hasPatched: false
998
+ };
999
+ }).filter((candidate) => candidate !== null);
1000
+ for (const item of candidates) {
1001
+ const { code, file, match } = item;
1002
+ const ast = _parser.parse.call(void 0, match[0], { sourceType: "unambiguous" });
1003
+ traverse(ast, {
1004
+ ArrayExpression(path11) {
1005
+ for (const unit of opts.units) {
1006
+ if (path11.node.elements.some((element) => t3.isStringLiteral(element) && element.value === unit)) {
1007
+ item.hasPatched = true;
1008
+ return;
1009
+ }
1010
+ path11.node.elements.push(t3.stringLiteral(unit));
1011
+ }
1012
+ }
1013
+ });
1014
+ if (item.hasPatched) {
1015
+ continue;
1016
+ }
1017
+ const { code: replacement } = generate(ast, { minified: true });
1018
+ const start = _nullishCoalesce(match.index, () => ( 0));
1019
+ const end = start + match[0].length;
1020
+ item.code = spliceChangesIntoString(code, [
1021
+ {
1022
+ start,
1023
+ end,
1024
+ replacement: replacement.endsWith(";") ? replacement.slice(0, -1) : replacement
1025
+ }
1026
+ ]);
1027
+ if (opts.overwrite) {
1028
+ _fsextra2.default.writeFileSync(file, item.code, "utf8");
1029
+ }
1030
+ }
1031
+ if (candidates.some((file) => !file.hasPatched)) {
1032
+ logger_default.success("Patched Tailwind CSS length unit list (v4).");
1033
+ }
1034
+ return {
1035
+ changed: candidates.some((file) => !file.hasPatched),
1036
+ files: candidates
1037
+ };
1038
+ }
1039
+
1040
+ // src/patching/status.ts
1041
+ function inspectLengthUnitsArray(content, variableName, units) {
1042
+ const ast = _parser.parse.call(void 0, content);
1043
+ let found = false;
1044
+ let missingUnits = [];
1045
+ traverse(ast, {
1046
+ Identifier(path11) {
1047
+ if (path11.node.name === variableName && t4.isVariableDeclarator(path11.parent) && t4.isArrayExpression(path11.parent.init)) {
1048
+ found = true;
1049
+ const existing = new Set(
1050
+ path11.parent.init.elements.map((element) => t4.isStringLiteral(element) ? element.value : void 0).filter(Boolean)
1051
+ );
1052
+ missingUnits = units.filter((unit) => !existing.has(unit));
1053
+ path11.stop();
1054
+ }
1055
+ }
1056
+ });
1057
+ return {
1058
+ found,
1059
+ missingUnits
1060
+ };
1061
+ }
1062
+ function checkExposeContextPatch(context) {
1063
+ const { packageInfo, options, majorVersion } = context;
1064
+ const refProperty = options.features.exposeContext.refProperty;
1065
+ if (!options.features.exposeContext.enabled) {
1066
+ return {
1067
+ name: "exposeContext",
1068
+ status: "skipped",
1069
+ reason: "exposeContext feature disabled",
1070
+ files: []
1071
+ };
1072
+ }
1073
+ if (majorVersion === 4) {
1074
+ return {
1075
+ name: "exposeContext",
1076
+ status: "unsupported",
1077
+ reason: "Context export patch is only required for Tailwind v2/v3",
1078
+ files: []
1079
+ };
1080
+ }
1081
+ const checks = [];
1082
+ function inspectFile(relative, transform) {
1083
+ const filePath = _pathe2.default.resolve(packageInfo.rootPath, relative);
1084
+ if (!_fsextra2.default.existsSync(filePath)) {
1085
+ checks.push({ relative, exists: false, patched: false });
1086
+ return;
1087
+ }
1088
+ const content = _fsextra2.default.readFileSync(filePath, "utf8");
1089
+ const { hasPatched } = transform(content);
1090
+ checks.push({
1091
+ relative,
1092
+ exists: true,
1093
+ patched: hasPatched
1094
+ });
1095
+ }
1096
+ if (majorVersion === 3) {
1097
+ inspectFile("lib/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContext);
1098
+ const pluginCandidates = ["lib/plugin.js", "lib/index.js"];
1099
+ const pluginRelative = pluginCandidates.find((candidate) => _fsextra2.default.existsSync(_pathe2.default.resolve(packageInfo.rootPath, candidate)));
1100
+ if (pluginRelative) {
1101
+ inspectFile(pluginRelative, (content) => transformPostcssPlugin(content, { refProperty }));
1102
+ } else {
1103
+ checks.push({ relative: "lib/plugin.js", exists: false, patched: false });
1104
+ }
1105
+ } else {
1106
+ inspectFile("lib/jit/processTailwindFeatures.js", transformProcessTailwindFeaturesReturnContextV2);
1107
+ inspectFile("lib/jit/index.js", (content) => transformPostcssPluginV2(content, { refProperty }));
1108
+ }
1109
+ const files = checks.filter((check) => check.exists).map((check) => check.relative);
1110
+ const missingFiles = checks.filter((check) => !check.exists);
1111
+ const unpatchedFiles = checks.filter((check) => check.exists && !check.patched);
1112
+ const reasons = [];
1113
+ if (missingFiles.length) {
1114
+ reasons.push(`missing files: ${missingFiles.map((item) => item.relative).join(", ")}`);
1115
+ }
1116
+ if (unpatchedFiles.length) {
1117
+ reasons.push(`unpatched files: ${unpatchedFiles.map((item) => item.relative).join(", ")}`);
1118
+ }
1119
+ return {
1120
+ name: "exposeContext",
1121
+ status: reasons.length ? "not-applied" : "applied",
1122
+ reason: reasons.length ? reasons.join("; ") : void 0,
1123
+ files
1124
+ };
1125
+ }
1126
+ function checkExtendLengthUnitsV3(rootDir, options) {
1127
+ const lengthUnitsFilePath = _nullishCoalesce(options.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js"));
1128
+ const variableName = _nullishCoalesce(options.variableName, () => ( "lengthUnits"));
1129
+ const target = _pathe2.default.resolve(rootDir, lengthUnitsFilePath);
1130
+ const files = _fsextra2.default.existsSync(target) ? [_pathe2.default.relative(rootDir, target)] : [];
1131
+ if (!_fsextra2.default.existsSync(target)) {
1132
+ return {
1133
+ name: "extendLengthUnits",
1134
+ status: "not-applied",
1135
+ reason: `missing ${lengthUnitsFilePath}`,
1136
+ files
1137
+ };
1138
+ }
1139
+ const content = _fsextra2.default.readFileSync(target, "utf8");
1140
+ const { found, missingUnits } = inspectLengthUnitsArray(content, variableName, options.units);
1141
+ if (!found) {
1142
+ return {
1143
+ name: "extendLengthUnits",
1144
+ status: "not-applied",
1145
+ reason: `could not locate ${variableName} array in ${lengthUnitsFilePath}`,
1146
+ files
1147
+ };
1148
+ }
1149
+ if (missingUnits.length) {
1150
+ return {
1151
+ name: "extendLengthUnits",
1152
+ status: "not-applied",
1153
+ reason: `missing units: ${missingUnits.join(", ")}`,
1154
+ files
1155
+ };
1156
+ }
1157
+ return {
1158
+ name: "extendLengthUnits",
1159
+ status: "applied",
1160
+ files
1161
+ };
1162
+ }
1163
+ function checkExtendLengthUnitsV4(rootDir, options) {
1164
+ const distDir = _pathe2.default.resolve(rootDir, "dist");
1165
+ if (!_fsextra2.default.existsSync(distDir)) {
1166
+ return {
1167
+ name: "extendLengthUnits",
1168
+ status: "not-applied",
1169
+ reason: "dist directory not found for Tailwind v4 package",
1170
+ files: []
1171
+ };
1172
+ }
1173
+ const result = applyExtendLengthUnitsPatchV4(rootDir, {
1174
+ ...options,
1175
+ enabled: true,
1176
+ overwrite: false
1177
+ });
1178
+ if (result.files.length === 0) {
1179
+ return {
1180
+ name: "extendLengthUnits",
1181
+ status: "not-applied",
1182
+ reason: "no bundle chunks matched the length unit pattern",
1183
+ files: []
1184
+ };
1185
+ }
1186
+ const files = result.files.map((file) => _pathe2.default.relative(rootDir, file.file));
1187
+ const pending = result.files.filter((file) => !file.hasPatched);
1188
+ if (pending.length) {
1189
+ return {
1190
+ name: "extendLengthUnits",
1191
+ status: "not-applied",
1192
+ reason: `missing units in ${pending.length} bundle${pending.length > 1 ? "s" : ""}`,
1193
+ files: pending.map((file) => _pathe2.default.relative(rootDir, file.file))
1194
+ };
1195
+ }
1196
+ return {
1197
+ name: "extendLengthUnits",
1198
+ status: "applied",
1199
+ files
1200
+ };
1201
+ }
1202
+ function checkExtendLengthUnitsPatch(context) {
1203
+ const { packageInfo, options, majorVersion } = context;
1204
+ if (!options.features.extendLengthUnits) {
1205
+ return {
1206
+ name: "extendLengthUnits",
1207
+ status: "skipped",
1208
+ reason: "extendLengthUnits feature disabled",
1209
+ files: []
1210
+ };
1211
+ }
1212
+ if (majorVersion === 2) {
1213
+ return {
1214
+ name: "extendLengthUnits",
1215
+ status: "unsupported",
1216
+ reason: "length unit extension is only applied for Tailwind v3/v4",
1217
+ files: []
1218
+ };
1219
+ }
1220
+ if (majorVersion === 3) {
1221
+ return checkExtendLengthUnitsV3(packageInfo.rootPath, options.features.extendLengthUnits);
1222
+ }
1223
+ return checkExtendLengthUnitsV4(packageInfo.rootPath, options.features.extendLengthUnits);
1224
+ }
1225
+ function getPatchStatusReport(context) {
1226
+ return {
1227
+ package: {
1228
+ name: _nullishCoalesce(context.packageInfo.name, () => ( _optionalChain([context, 'access', _42 => _42.packageInfo, 'access', _43 => _43.packageJson, 'optionalAccess', _44 => _44.name]))),
1229
+ version: context.packageInfo.version,
1230
+ root: context.packageInfo.rootPath
1231
+ },
1232
+ majorVersion: context.majorVersion,
1233
+ entries: [
1234
+ checkExposeContextPatch(context),
1235
+ checkExtendLengthUnitsPatch(context)
1236
+ ]
1237
+ };
1238
+ }
1239
+
1240
+ // src/runtime/class-collector.ts
1241
+
1242
+
1243
+
1244
+ function collectClassesFromContexts(contexts, filter) {
1245
+ const set = /* @__PURE__ */ new Set();
1246
+ for (const context of contexts) {
1247
+ if (!isObject(context) || !context.classCache) {
1248
+ continue;
1249
+ }
1250
+ for (const key of context.classCache.keys()) {
1251
+ const className = key.toString();
1252
+ if (filter(className)) {
1253
+ set.add(className);
1254
+ }
1255
+ }
1256
+ }
1257
+ return set;
1258
+ }
1259
+ async function collectClassesFromTailwindV4(options) {
1260
+ const set = /* @__PURE__ */ new Set();
1261
+ const v4Options = options.tailwind.v4;
1262
+ if (!v4Options) {
1263
+ return set;
1264
+ }
1265
+ const toAbsolute = (value) => {
1266
+ if (!value) {
1267
+ return void 0;
1268
+ }
1269
+ return _pathe2.default.isAbsolute(value) ? value : _pathe2.default.resolve(options.projectRoot, value);
1270
+ };
1271
+ const resolvedConfiguredBase = toAbsolute(v4Options.configuredBase);
1272
+ const resolvedDefaultBase = _nullishCoalesce(toAbsolute(v4Options.base), () => ( _process2.default.cwd()));
1273
+ const resolveSources = (base) => {
1274
+ if (!_optionalChain([v4Options, 'access', _45 => _45.sources, 'optionalAccess', _46 => _46.length])) {
1275
+ return void 0;
1276
+ }
1277
+ return v4Options.sources.map((source) => ({
1278
+ base: _nullishCoalesce(source.base, () => ( base)),
1279
+ pattern: source.pattern,
1280
+ negated: source.negated
1281
+ }));
1282
+ };
1283
+ if (v4Options.cssEntries.length > 0) {
1284
+ for (const entry of v4Options.cssEntries) {
1285
+ const filePath = _pathe2.default.isAbsolute(entry) ? entry : _pathe2.default.resolve(options.projectRoot, entry);
1286
+ if (!await _fsextra2.default.pathExists(filePath)) {
1287
+ continue;
1288
+ }
1289
+ const css = await _fsextra2.default.readFile(filePath, "utf8");
1290
+ const entryDir = _pathe2.default.dirname(filePath);
1291
+ const baseForEntry = _nullishCoalesce(resolvedConfiguredBase, () => ( entryDir));
1292
+ const sources = resolveSources(baseForEntry);
1293
+ const candidates = await extractValidCandidates({
1294
+ cwd: options.projectRoot,
1295
+ base: baseForEntry,
1296
+ css,
1297
+ sources
1298
+ });
1299
+ for (const candidate of candidates) {
1300
+ if (options.filter(candidate)) {
1301
+ set.add(candidate);
1302
+ }
1303
+ }
1304
+ }
1305
+ } else {
1306
+ const baseForCss = _nullishCoalesce(resolvedConfiguredBase, () => ( resolvedDefaultBase));
1307
+ const sources = resolveSources(baseForCss);
1308
+ const candidates = await extractValidCandidates({
1309
+ cwd: options.projectRoot,
1310
+ base: baseForCss,
1311
+ css: v4Options.css,
1312
+ sources
1313
+ });
1314
+ for (const candidate of candidates) {
1315
+ if (options.filter(candidate)) {
1316
+ set.add(candidate);
1317
+ }
1318
+ }
1319
+ }
1320
+ return set;
1321
+ }
1322
+
1323
+ // src/runtime/context-registry.ts
1324
+ var _module = require('module');
1325
+
1326
+
1327
+ var require2 = _module.createRequire.call(void 0, importMetaUrl);
1328
+ function resolveRuntimeEntry(packageInfo, majorVersion) {
1329
+ const root = packageInfo.rootPath;
1330
+ if (majorVersion === 2) {
1331
+ const jitIndex = _pathe2.default.join(root, "lib/jit/index.js");
1332
+ if (_fsextra2.default.existsSync(jitIndex)) {
1333
+ return jitIndex;
1334
+ }
1335
+ } else if (majorVersion === 3) {
1336
+ const plugin = _pathe2.default.join(root, "lib/plugin.js");
1337
+ const index = _pathe2.default.join(root, "lib/index.js");
1338
+ if (_fsextra2.default.existsSync(plugin)) {
1339
+ return plugin;
1340
+ }
1341
+ if (_fsextra2.default.existsSync(index)) {
1342
+ return index;
1343
+ }
1344
+ }
1345
+ return void 0;
1346
+ }
1347
+ function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
1348
+ if (majorVersion === 4) {
1349
+ return [];
1350
+ }
1351
+ const entry = resolveRuntimeEntry(packageInfo, majorVersion);
1352
+ if (!entry) {
1353
+ return [];
1354
+ }
1355
+ const moduleExports = require2(entry);
1356
+ if (!moduleExports) {
1357
+ return [];
1358
+ }
1359
+ const ref = moduleExports[refProperty];
1360
+ if (!ref) {
1361
+ return [];
1362
+ }
1363
+ if (Array.isArray(ref)) {
1364
+ return ref;
1365
+ }
1366
+ if (typeof ref === "object" && Array.isArray(ref.value)) {
1367
+ return ref.value;
1368
+ }
1369
+ return [];
1370
+ }
1371
+
1372
+ // src/runtime/process-tailwindcss.ts
1373
+
1374
+
1375
+ var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
1376
+ var _tailwindcssconfig = require('tailwindcss-config');
1377
+ var require3 = _module.createRequire.call(void 0, importMetaUrl);
1378
+ async function resolveConfigPath(options) {
1379
+ if (options.config && _pathe2.default.isAbsolute(options.config)) {
1380
+ return options.config;
1381
+ }
1382
+ const result = await _tailwindcssconfig.loadConfig.call(void 0, { cwd: options.cwd });
1383
+ if (!result) {
1384
+ throw new Error(`Unable to locate Tailwind CSS config from ${options.cwd}`);
1385
+ }
1386
+ return result.filepath;
1387
+ }
1388
+ async function runTailwindBuild(options) {
1389
+ const configPath = await resolveConfigPath(options);
1390
+ const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
1391
+ if (options.majorVersion === 4) {
1392
+ return _postcss2.default.call(void 0, [
1393
+ require3(pluginName)({
1394
+ config: configPath
1395
+ })
1396
+ ]).process("@import 'tailwindcss';", {
1397
+ from: void 0
1398
+ });
1399
+ }
1400
+ return _postcss2.default.call(void 0, [
1401
+ require3(pluginName)({
1402
+ config: configPath
1403
+ })
1404
+ ]).process("@tailwind base;@tailwind components;@tailwind utilities;", {
1405
+ from: void 0
1406
+ });
1407
+ }
1408
+
1409
+ // src/api/tailwindcss-patcher.ts
1410
+
1411
+
1412
+ var _localpkg = require('local-pkg');
1413
+
1414
+ var _semver = require('semver');
1415
+
1416
+ // src/options/legacy.ts
1417
+ function normalizeLegacyFeatures(patch) {
1418
+ const apply = _optionalChain([patch, 'optionalAccess', _47 => _47.applyPatches]);
1419
+ const extend = _optionalChain([apply, 'optionalAccess', _48 => _48.extendLengthUnits]);
1420
+ let extendOption = false;
1421
+ if (extend && typeof extend === "object") {
1422
+ extendOption = {
1423
+ ...extend,
1424
+ enabled: true
1425
+ };
1426
+ } else if (extend === true) {
1427
+ extendOption = {
1428
+ enabled: true,
1429
+ units: ["rpx"],
1430
+ overwrite: _optionalChain([patch, 'optionalAccess', _49 => _49.overwrite])
1431
+ };
1432
+ }
1433
+ return {
1434
+ exposeContext: _nullishCoalesce(_optionalChain([apply, 'optionalAccess', _50 => _50.exportContext]), () => ( true)),
1435
+ extendLengthUnits: extendOption
1436
+ };
1437
+ }
1438
+ function fromLegacyOptions(options) {
1439
+ if (!options) {
1440
+ return {};
1441
+ }
1442
+ const patch = options.patch;
1443
+ const features = normalizeLegacyFeatures(patch);
1444
+ const output = _optionalChain([patch, 'optionalAccess', _51 => _51.output]);
1445
+ const tailwindConfig = _optionalChain([patch, 'optionalAccess', _52 => _52.tailwindcss]);
1446
+ const tailwindVersion = _optionalChain([tailwindConfig, 'optionalAccess', _53 => _53.version]);
1447
+ const tailwindV2 = _optionalChain([tailwindConfig, 'optionalAccess', _54 => _54.v2]);
1448
+ const tailwindV3 = _optionalChain([tailwindConfig, 'optionalAccess', _55 => _55.v3]);
1449
+ const tailwindV4 = _optionalChain([tailwindConfig, 'optionalAccess', _56 => _56.v4]);
1450
+ const tailwindConfigPath = _nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _57 => _57.config]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _58 => _58.config])));
1451
+ const tailwindCwd = _nullishCoalesce(_nullishCoalesce(_optionalChain([tailwindV3, 'optionalAccess', _59 => _59.cwd]), () => ( _optionalChain([tailwindV2, 'optionalAccess', _60 => _60.cwd]))), () => ( _optionalChain([patch, 'optionalAccess', _61 => _61.cwd])));
1452
+ return {
1453
+ cwd: _optionalChain([patch, 'optionalAccess', _62 => _62.cwd]),
1454
+ overwrite: _optionalChain([patch, 'optionalAccess', _63 => _63.overwrite]),
1455
+ filter: _optionalChain([patch, 'optionalAccess', _64 => _64.filter]),
1456
+ cache: typeof options.cache === "boolean" ? options.cache : options.cache ? {
1457
+ ...options.cache,
1458
+ enabled: _nullishCoalesce(options.cache.enabled, () => ( true))
1459
+ } : void 0,
1460
+ output: output ? {
1461
+ file: output.filename,
1462
+ pretty: output.loose ? 2 : false,
1463
+ removeUniversalSelector: output.removeUniversalSelector
1464
+ } : void 0,
1465
+ tailwind: {
1466
+ packageName: _optionalChain([patch, 'optionalAccess', _65 => _65.packageName]),
1467
+ version: tailwindVersion,
1468
+ resolve: _optionalChain([patch, 'optionalAccess', _66 => _66.resolve]),
1469
+ config: tailwindConfigPath,
1470
+ cwd: tailwindCwd,
1471
+ v2: tailwindV2,
1472
+ v3: tailwindV3,
1473
+ v4: tailwindV4
1474
+ },
1475
+ features: {
1476
+ exposeContext: features.exposeContext,
1477
+ extendLengthUnits: features.extendLengthUnits
1478
+ }
1479
+ };
1480
+ }
1481
+ function fromUnifiedConfig(registry) {
1482
+ if (!registry) {
1483
+ return {};
1484
+ }
1485
+ const tailwind = registry.tailwind;
1486
+ const output = registry.output;
1487
+ const pretty = (() => {
1488
+ if (_optionalChain([output, 'optionalAccess', _67 => _67.pretty]) === void 0) {
1489
+ return void 0;
1490
+ }
1491
+ if (typeof output.pretty === "boolean") {
1492
+ return output.pretty ? 2 : false;
1493
+ }
1494
+ return output.pretty;
1495
+ })();
1169
1496
  return {
1170
- code: hasPatched ? content : generate(ast).code,
1171
- hasPatched
1497
+ output: output ? {
1498
+ file: output.file,
1499
+ pretty,
1500
+ removeUniversalSelector: output.stripUniversalSelector
1501
+ } : void 0,
1502
+ tailwind: tailwind ? {
1503
+ version: tailwind.version,
1504
+ packageName: tailwind.package,
1505
+ resolve: tailwind.resolve,
1506
+ config: tailwind.config,
1507
+ cwd: tailwind.cwd,
1508
+ v2: tailwind.legacy,
1509
+ v3: tailwind.classic,
1510
+ v4: tailwind.next
1511
+ } : void 0
1172
1512
  };
1173
1513
  }
1174
1514
 
1175
1515
  // src/patching/operations/export-context/index.ts
1516
+
1517
+
1176
1518
  function writeFileIfRequired(filePath, code, overwrite, successMessage) {
1177
1519
  if (!overwrite) {
1178
1520
  return;
@@ -1259,147 +1601,6 @@ function applyExposeContextPatch(params) {
1259
1601
  return result;
1260
1602
  }
1261
1603
 
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
1604
  // src/patching/patch-runner.ts
1404
1605
  function applyTailwindPatches(context) {
1405
1606
  const { packageInfo, options, majorVersion } = context;
@@ -1412,7 +1613,7 @@ function applyTailwindPatches(context) {
1412
1613
  majorVersion
1413
1614
  });
1414
1615
  }
1415
- if (_optionalChain([options, 'access', _65 => _65.features, 'access', _66 => _66.extendLengthUnits, 'optionalAccess', _67 => _67.enabled])) {
1616
+ if (_optionalChain([options, 'access', _68 => _68.features, 'access', _69 => _69.extendLengthUnits, 'optionalAccess', _70 => _70.enabled])) {
1416
1617
  if (majorVersion === 3) {
1417
1618
  results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
1418
1619
  packageInfo.rootPath,
@@ -1498,6 +1699,13 @@ var TailwindcssPatcher = (_class = class {
1498
1699
  majorVersion: this.majorVersion
1499
1700
  });
1500
1701
  }
1702
+ async getPatchStatus() {
1703
+ return getPatchStatusReport({
1704
+ packageInfo: this.packageInfo,
1705
+ options: this.options,
1706
+ majorVersion: this.majorVersion
1707
+ });
1708
+ }
1501
1709
  getContexts() {
1502
1710
  return loadRuntimeContexts(
1503
1711
  this.packageInfo,
@@ -1523,13 +1731,6 @@ var TailwindcssPatcher = (_class = class {
1523
1731
  const contexts = this.getContexts();
1524
1732
  return collectClassesFromContexts(contexts, this.options.filter);
1525
1733
  }
1526
- collectClassSetSync() {
1527
- if (this.majorVersion === 4) {
1528
- throw new Error("getClassSetSync is not supported for Tailwind CSS v4 projects. Use getClassSet instead.");
1529
- }
1530
- const contexts = this.getContexts();
1531
- return collectClassesFromContexts(contexts, this.options.filter);
1532
- }
1533
1734
  async mergeWithCache(set) {
1534
1735
  if (!this.options.cache.enabled) {
1535
1736
  return set;
@@ -1574,11 +1775,19 @@ var TailwindcssPatcher = (_class = class {
1574
1775
  return this.mergeWithCache(set);
1575
1776
  }
1576
1777
  getClassSetSync() {
1577
- const set = this.collectClassSetSync();
1578
- return this.mergeWithCacheSync(set);
1778
+ if (this.majorVersion === 4) {
1779
+ throw new Error("getClassSetSync is not supported for Tailwind CSS v4 projects. Use getClassSet instead.");
1780
+ }
1781
+ const contexts = this.getContexts();
1782
+ const set = collectClassesFromContexts(contexts, this.options.filter);
1783
+ const merged = this.mergeWithCacheSync(set);
1784
+ if (contexts.length === 0 && merged.size === 0) {
1785
+ return void 0;
1786
+ }
1787
+ return merged;
1579
1788
  }
1580
1789
  async extract(options) {
1581
- const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _68 => _68.write]), () => ( this.options.output.enabled));
1790
+ const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _71 => _71.write]), () => ( this.options.output.enabled));
1582
1791
  const classSet = await this.getClassSet();
1583
1792
  const classList = Array.from(classSet);
1584
1793
  const result = {
@@ -1607,18 +1816,18 @@ var TailwindcssPatcher = (_class = class {
1607
1816
  __init() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
1608
1817
  async collectContentTokens(options) {
1609
1818
  return extractProjectCandidatesWithPositions({
1610
- cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _69 => _69.cwd]), () => ( this.options.projectRoot)),
1611
- 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]))), () => ( []))
1819
+ cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _72 => _72.cwd]), () => ( this.options.projectRoot)),
1820
+ 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]))), () => ( []))
1612
1821
  });
1613
1822
  }
1614
1823
  async collectContentTokensByFile(options) {
1615
1824
  const report = await this.collectContentTokens({
1616
- cwd: _optionalChain([options, 'optionalAccess', _75 => _75.cwd]),
1617
- sources: _optionalChain([options, 'optionalAccess', _76 => _76.sources])
1825
+ cwd: _optionalChain([options, 'optionalAccess', _78 => _78.cwd]),
1826
+ sources: _optionalChain([options, 'optionalAccess', _79 => _79.sources])
1618
1827
  });
1619
1828
  return groupTokensByFile(report, {
1620
- key: _optionalChain([options, 'optionalAccess', _77 => _77.key]),
1621
- stripAbsolutePaths: _optionalChain([options, 'optionalAccess', _78 => _78.stripAbsolutePaths])
1829
+ key: _optionalChain([options, 'optionalAccess', _80 => _80.key]),
1830
+ stripAbsolutePaths: _optionalChain([options, 'optionalAccess', _81 => _81.stripAbsolutePaths])
1622
1831
  });
1623
1832
  }
1624
1833
  }, _class);
@@ -1721,7 +1930,7 @@ var acceptChars = [..."abcdefghijklmnopqrstuvwxyz"];
1721
1930
  var _cac = require('cac'); var _cac2 = _interopRequireDefault(_cac);
1722
1931
 
1723
1932
 
1724
- var tailwindcssPatchCommands = ["install", "extract", "tokens", "init"];
1933
+ var tailwindcssPatchCommands = ["install", "extract", "tokens", "init", "status"];
1725
1934
  var TOKEN_FORMATS = ["json", "lines", "grouped-json"];
1726
1935
  var DEFAULT_TOKEN_REPORT = ".tw-patch/tw-token-report.json";
1727
1936
  function formatTokenLine(entry) {
@@ -1761,7 +1970,7 @@ function createDefaultRunner(factory) {
1761
1970
  async function loadPatchOptionsForCwd(cwd, overrides) {
1762
1971
  const { config } = await _config.getConfig.call(void 0, cwd);
1763
1972
  const legacyConfig = config;
1764
- const base = _optionalChain([config, 'optionalAccess', _79 => _79.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _80 => _80.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
1973
+ const base = _optionalChain([config, 'optionalAccess', _82 => _82.registry]) ? fromUnifiedConfig(config.registry) : _optionalChain([legacyConfig, 'optionalAccess', _83 => _83.patch]) ? fromLegacyOptions({ patch: legacyConfig.patch }) : {};
1765
1974
  const merged = defu(_nullishCoalesce(overrides, () => ( {})), base);
1766
1975
  return merged;
1767
1976
  }
@@ -1849,6 +2058,13 @@ function buildDefaultCommandDefinitions() {
1849
2058
  init: {
1850
2059
  description: "Generate a tailwindcss-patch config file",
1851
2060
  optionDefs: [createCwdOptionDefinition()]
2061
+ },
2062
+ status: {
2063
+ description: "Check which Tailwind patches are applied",
2064
+ optionDefs: [
2065
+ createCwdOptionDefinition(),
2066
+ { flags: "--json", description: "Print a JSON report of patch status" }
2067
+ ]
1852
2068
  }
1853
2069
  };
1854
2070
  }
@@ -1859,10 +2075,10 @@ function addPrefixIfMissing(value, prefix) {
1859
2075
  return `${prefix}${value}`;
1860
2076
  }
1861
2077
  function resolveCommandNames(command, mountOptions, prefix) {
1862
- const override = _optionalChain([mountOptions, 'access', _81 => _81.commandOptions, 'optionalAccess', _82 => _82[command]]);
1863
- const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _83 => _83.name]), () => ( command));
2078
+ const override = _optionalChain([mountOptions, 'access', _84 => _84.commandOptions, 'optionalAccess', _85 => _85[command]]);
2079
+ const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _86 => _86.name]), () => ( command));
1864
2080
  const name = addPrefixIfMissing(baseName, prefix);
1865
- const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _84 => _84.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
2081
+ const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
1866
2082
  return { name, aliases };
1867
2083
  }
1868
2084
  function resolveOptionDefinitions(defaults, override) {
@@ -1896,8 +2112,8 @@ function runWithCommandHandler(cli, command, commandName, args, handler, default
1896
2112
  function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
1897
2113
  const names = resolveCommandNames(command, mountOptions, prefix);
1898
2114
  const definition = defaults[command];
1899
- const override = _optionalChain([mountOptions, 'access', _85 => _85.commandOptions, 'optionalAccess', _86 => _86[command]]);
1900
- const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _87 => _87.description]), () => ( definition.description));
2115
+ const override = _optionalChain([mountOptions, 'access', _88 => _88.commandOptions, 'optionalAccess', _89 => _89[command]]);
2116
+ const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _90 => _90.description]), () => ( definition.description));
1901
2117
  const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
1902
2118
  return { ...names, description, optionDefs };
1903
2119
  }
@@ -2005,6 +2221,46 @@ async function initCommandDefaultHandler(ctx) {
2005
2221
  await _config.initConfig.call(void 0, ctx.cwd);
2006
2222
  logger_default.success(`\u2728 ${_config.CONFIG_NAME}.config.ts initialized!`);
2007
2223
  }
2224
+ function formatFilesHint(entry) {
2225
+ if (!entry.files.length) {
2226
+ return "";
2227
+ }
2228
+ return ` (${entry.files.join(", ")})`;
2229
+ }
2230
+ async function statusCommandDefaultHandler(ctx) {
2231
+ const patcher = await ctx.createPatcher();
2232
+ const report = await patcher.getPatchStatus();
2233
+ if (ctx.args.json) {
2234
+ logger_default.log(JSON.stringify(report, null, 2));
2235
+ return report;
2236
+ }
2237
+ const applied = report.entries.filter((entry) => entry.status === "applied");
2238
+ const pending = report.entries.filter((entry) => entry.status === "not-applied");
2239
+ const skipped = report.entries.filter((entry) => entry.status === "skipped" || entry.status === "unsupported");
2240
+ const packageLabel = `${_nullishCoalesce(report.package.name, () => ( "tailwindcss"))}@${_nullishCoalesce(report.package.version, () => ( "unknown"))}`;
2241
+ logger_default.info(`Patch status for ${packageLabel} (v${report.majorVersion})`);
2242
+ if (applied.length) {
2243
+ logger_default.success("Applied:");
2244
+ applied.forEach((entry) => logger_default.success(` \u2022 ${entry.name}${formatFilesHint(entry)}`));
2245
+ }
2246
+ if (pending.length) {
2247
+ logger_default.warn("Needs attention:");
2248
+ pending.forEach((entry) => {
2249
+ const details = entry.reason ? ` \u2013 ${entry.reason}` : "";
2250
+ logger_default.warn(` \u2022 ${entry.name}${formatFilesHint(entry)}${details}`);
2251
+ });
2252
+ } else {
2253
+ logger_default.success("All applicable patches are applied.");
2254
+ }
2255
+ if (skipped.length) {
2256
+ logger_default.info("Skipped:");
2257
+ skipped.forEach((entry) => {
2258
+ const details = entry.reason ? ` \u2013 ${entry.reason}` : "";
2259
+ logger_default.info(` \u2022 ${entry.name}${details}`);
2260
+ });
2261
+ }
2262
+ return report;
2263
+ }
2008
2264
  function mountTailwindcssPatchCommands(cli, options = {}) {
2009
2265
  const prefix = _nullishCoalesce(options.commandPrefix, () => ( ""));
2010
2266
  const selectedCommands = _nullishCoalesce(options.commands, () => ( tailwindcssPatchCommands));
@@ -2020,7 +2276,7 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2020
2276
  command,
2021
2277
  "install",
2022
2278
  args,
2023
- _optionalChain([options, 'access', _88 => _88.commandHandlers, 'optionalAccess', _89 => _89.install]),
2279
+ _optionalChain([options, 'access', _91 => _91.commandHandlers, 'optionalAccess', _92 => _92.install]),
2024
2280
  installCommandDefaultHandler
2025
2281
  );
2026
2282
  });
@@ -2036,7 +2292,7 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2036
2292
  command,
2037
2293
  "extract",
2038
2294
  args,
2039
- _optionalChain([options, 'access', _90 => _90.commandHandlers, 'optionalAccess', _91 => _91.extract]),
2295
+ _optionalChain([options, 'access', _93 => _93.commandHandlers, 'optionalAccess', _94 => _94.extract]),
2040
2296
  extractCommandDefaultHandler
2041
2297
  );
2042
2298
  });
@@ -2052,7 +2308,7 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2052
2308
  command,
2053
2309
  "tokens",
2054
2310
  args,
2055
- _optionalChain([options, 'access', _92 => _92.commandHandlers, 'optionalAccess', _93 => _93.tokens]),
2311
+ _optionalChain([options, 'access', _95 => _95.commandHandlers, 'optionalAccess', _96 => _96.tokens]),
2056
2312
  tokensCommandDefaultHandler
2057
2313
  );
2058
2314
  });
@@ -2068,11 +2324,27 @@ function mountTailwindcssPatchCommands(cli, options = {}) {
2068
2324
  command,
2069
2325
  "init",
2070
2326
  args,
2071
- _optionalChain([options, 'access', _94 => _94.commandHandlers, 'optionalAccess', _95 => _95.init]),
2327
+ _optionalChain([options, 'access', _97 => _97.commandHandlers, 'optionalAccess', _98 => _98.init]),
2072
2328
  initCommandDefaultHandler
2073
2329
  );
2074
2330
  });
2075
2331
  metadata.aliases.forEach((alias) => command.alias(alias));
2332
+ },
2333
+ status: () => {
2334
+ const metadata = resolveCommandMetadata("status", options, prefix, defaultDefinitions);
2335
+ const command = cli.command(metadata.name, metadata.description);
2336
+ applyCommandOptions(command, metadata.optionDefs);
2337
+ command.action(async (args) => {
2338
+ return runWithCommandHandler(
2339
+ cli,
2340
+ command,
2341
+ "status",
2342
+ args,
2343
+ _optionalChain([options, 'access', _99 => _99.commandHandlers, 'optionalAccess', _100 => _100.status]),
2344
+ statusCommandDefaultHandler
2345
+ );
2346
+ });
2347
+ metadata.aliases.forEach((alias) => command.alias(alias));
2076
2348
  }
2077
2349
  };
2078
2350
  for (const name of selectedCommands) {
@@ -2106,4 +2378,5 @@ function createTailwindcssPatchCli(options = {}) {
2106
2378
 
2107
2379
 
2108
2380
 
2109
- 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;
2381
+
2382
+ 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;