tailwindcss-patch 8.7.3 → 8.7.4-alpha.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
- // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.6_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js
1
+ // ../../node_modules/.pnpm/tsup@8.5.1_jiti@2.6.1_postcss@8.5.8_tsx@4.21.0_typescript@5.9.3_yaml@2.8.2/node_modules/tsup/assets/esm_shims.js
2
2
  import path from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  var getFilename = () => fileURLToPath(import.meta.url);
@@ -1,6 +1,6 @@
1
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; var _class2;
2
2
 
3
- var _chunk7JAOSSROjs = require('./chunk-7JAOSSRO.js');
3
+ var _chunk5CWNAWKPjs = require('./chunk-5CWNAWKP.js');
4
4
 
5
5
  // src/logger.ts
6
6
  var _consola = require('consola');
@@ -20,7 +20,7 @@ var _pathe = require('pathe'); var _pathe2 = _interopRequireDefault(_pathe);
20
20
  // package.json
21
21
  var package_default = {
22
22
  name: "tailwindcss-patch",
23
- version: "8.7.3",
23
+ version: "8.7.4-alpha.0",
24
24
  description: "patch tailwindcss for exposing context and extract classes",
25
25
  author: "ice breaker <1324318532@qq.com>",
26
26
  license: "MIT",
@@ -66,6 +66,7 @@ var package_default = {
66
66
  build: "tsup",
67
67
  test: "vitest run",
68
68
  "test:dev": "vitest",
69
+ "bench:cold-start": "node --import tsx bench/cold-start.ts",
69
70
  patch: "tsx dev/bin.ts install",
70
71
  r0: "tsx dev/bin.ts extract",
71
72
  r1: "tsx dev/bin.ts extract --css index.css"
@@ -106,12 +107,12 @@ var package_default = {
106
107
  "@babel/types": "^7.29.0",
107
108
  "@tailwindcss-mangle/config": "workspace:*",
108
109
  "@tailwindcss/node": "^4.2.1",
109
- cac: "^6.7.14",
110
+ cac: "^7.0.0",
110
111
  consola: "^3.4.2",
111
- "fs-extra": "^11.3.3",
112
+ "fs-extra": "^11.3.4",
112
113
  "local-pkg": "^1.1.2",
113
114
  pathe: "^2.0.3",
114
- postcss: "^8.5.6",
115
+ postcss: "^8.5.8",
115
116
  semver: "^7.7.4",
116
117
  "tailwindcss-config": "^1.1.4"
117
118
  },
@@ -1906,7 +1907,7 @@ async function loadWorkspaceConfigModule() {
1906
1907
  }
1907
1908
  async function loadWorkspaceDefu() {
1908
1909
  if (!defuPromise) {
1909
- defuPromise = Promise.resolve().then(() => _interopRequireWildcard(require("./dist-NW65QXLC.js"))).then((mod) => mod.defu).catch(async (error) => {
1910
+ defuPromise = Promise.resolve().then(() => _interopRequireWildcard(require("./dist-7O2232CU.js"))).then((mod) => mod.defu).catch(async (error) => {
1910
1911
  if (!isMissingSharedModuleError(error)) {
1911
1912
  throw error;
1912
1913
  }
@@ -1931,33 +1932,66 @@ async function loadPatchOptionsForWorkspace(cwd, overrides) {
1931
1932
  var _fs = require('fs');
1932
1933
 
1933
1934
 
1935
+ var nodeImportPromise;
1936
+ var oxideImportPromise;
1937
+ var designSystemPromiseCache = /* @__PURE__ */ new Map();
1938
+ var designSystemCandidateCache = /* @__PURE__ */ new Map();
1934
1939
  async function importNode() {
1935
1940
  return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/node")));
1936
1941
  }
1937
1942
  async function importOxide() {
1938
1943
  return Promise.resolve().then(() => _interopRequireWildcard(require("@tailwindcss/oxide")));
1939
1944
  }
1945
+ function getNodeModule() {
1946
+ nodeImportPromise ??= importNode();
1947
+ return nodeImportPromise;
1948
+ }
1949
+ function getOxideModule() {
1950
+ oxideImportPromise ??= importOxide();
1951
+ return oxideImportPromise;
1952
+ }
1953
+ function createDesignSystemCacheKey(css, bases) {
1954
+ return JSON.stringify({
1955
+ css,
1956
+ bases: Array.from(new Set(bases.filter(Boolean)))
1957
+ });
1958
+ }
1940
1959
  async function loadDesignSystem(css, bases) {
1941
1960
  const uniqueBases = Array.from(new Set(bases.filter(Boolean)));
1942
1961
  if (uniqueBases.length === 0) {
1943
1962
  throw new Error("No base directories provided for Tailwind CSS design system.");
1944
1963
  }
1945
- const { __unstable__loadDesignSystem } = await importNode();
1946
- let lastError;
1947
- for (const base of uniqueBases) {
1948
- try {
1949
- return await __unstable__loadDesignSystem(css, { base });
1950
- } catch (error) {
1951
- lastError = error;
1952
- }
1953
- }
1954
- if (lastError instanceof Error) {
1955
- throw lastError;
1964
+ const cacheKey = createDesignSystemCacheKey(css, uniqueBases);
1965
+ const cached = designSystemPromiseCache.get(cacheKey);
1966
+ if (cached) {
1967
+ return cached;
1956
1968
  }
1957
- throw new Error("Failed to load Tailwind CSS design system.");
1969
+ const promise = (async () => {
1970
+ const { __unstable__loadDesignSystem } = await getNodeModule();
1971
+ let lastError;
1972
+ for (const base of uniqueBases) {
1973
+ try {
1974
+ return await __unstable__loadDesignSystem(css, { base });
1975
+ } catch (error) {
1976
+ lastError = error;
1977
+ }
1978
+ }
1979
+ if (lastError instanceof Error) {
1980
+ throw lastError;
1981
+ }
1982
+ throw new Error("Failed to load Tailwind CSS design system.");
1983
+ })();
1984
+ designSystemPromiseCache.set(cacheKey, promise);
1985
+ promise.catch(() => {
1986
+ if (designSystemPromiseCache.get(cacheKey) === promise) {
1987
+ designSystemPromiseCache.delete(cacheKey);
1988
+ designSystemCandidateCache.delete(cacheKey);
1989
+ }
1990
+ });
1991
+ return promise;
1958
1992
  }
1959
1993
  async function extractRawCandidatesWithPositions(content, extension = "html") {
1960
- const { Scanner } = await importOxide();
1994
+ const { Scanner } = await getOxideModule();
1961
1995
  const scanner = new Scanner({});
1962
1996
  const result = scanner.getCandidatesWithPositions({ content, extension });
1963
1997
  return result.map(({ candidate, position }) => ({
@@ -1967,7 +2001,7 @@ async function extractRawCandidatesWithPositions(content, extension = "html") {
1967
2001
  }));
1968
2002
  }
1969
2003
  async function extractRawCandidates(sources) {
1970
- const { Scanner } = await importOxide();
2004
+ const { Scanner } = await getOxideModule();
1971
2005
  const scanner = new Scanner(sources === void 0 ? {} : { sources });
1972
2006
  return scanner.scan();
1973
2007
  }
@@ -1988,25 +2022,44 @@ async function extractValidCandidates(options) {
1988
2022
  pattern: source.pattern,
1989
2023
  negated: source.negated
1990
2024
  }));
2025
+ const designSystemKey = createDesignSystemCacheKey(css, [base, ...baseFallbacks]);
1991
2026
  const designSystem = await loadDesignSystem(css, [base, ...baseFallbacks]);
2027
+ const candidateCache = _nullishCoalesce(designSystemCandidateCache.get(designSystemKey), () => ( /* @__PURE__ */ new Map()));
2028
+ designSystemCandidateCache.set(designSystemKey, candidateCache);
1992
2029
  const candidates = await extractRawCandidates(sources);
1993
- const parsedCandidates = candidates.filter(
1994
- (rawCandidate) => designSystem.parseCandidate(rawCandidate).length > 0
1995
- );
1996
- if (parsedCandidates.length === 0) {
1997
- return parsedCandidates;
1998
- }
1999
- const cssByCandidate = designSystem.candidatesToCss(parsedCandidates);
2000
2030
  const validCandidates = [];
2001
- for (let index = 0; index < parsedCandidates.length; index++) {
2002
- const candidate = parsedCandidates[index];
2031
+ const uncachedCandidates = [];
2032
+ for (const rawCandidate of candidates) {
2033
+ const cached = candidateCache.get(rawCandidate);
2034
+ if (cached === true) {
2035
+ validCandidates.push(rawCandidate);
2036
+ continue;
2037
+ }
2038
+ if (cached === false) {
2039
+ continue;
2040
+ }
2041
+ if (designSystem.parseCandidate(rawCandidate).length > 0) {
2042
+ uncachedCandidates.push(rawCandidate);
2043
+ continue;
2044
+ }
2045
+ candidateCache.set(rawCandidate, false);
2046
+ }
2047
+ if (uncachedCandidates.length === 0) {
2048
+ return validCandidates;
2049
+ }
2050
+ const cssByCandidate = designSystem.candidatesToCss(uncachedCandidates);
2051
+ for (let index = 0; index < uncachedCandidates.length; index++) {
2052
+ const candidate = uncachedCandidates[index];
2003
2053
  if (candidate === void 0) {
2004
2054
  continue;
2005
2055
  }
2006
- const css2 = cssByCandidate[index];
2007
- if (typeof css2 === "string" && css2.trim().length > 0) {
2008
- validCandidates.push(candidate);
2056
+ const candidateCss = cssByCandidate[index];
2057
+ const isValid = typeof candidateCss === "string" && candidateCss.trim().length > 0;
2058
+ candidateCache.set(candidate, isValid);
2059
+ if (!isValid) {
2060
+ continue;
2009
2061
  }
2062
+ validCandidates.push(candidate);
2010
2063
  }
2011
2064
  return validCandidates;
2012
2065
  }
@@ -2078,7 +2131,7 @@ function toRelativeFile(cwd, filename) {
2078
2131
  async function extractProjectCandidatesWithPositions(options) {
2079
2132
  const cwd = _optionalChain([options, 'optionalAccess', _103 => _103.cwd]) ? _pathe2.default.resolve(options.cwd) : _process2.default.cwd();
2080
2133
  const normalizedSources = normalizeSources(_optionalChain([options, 'optionalAccess', _104 => _104.sources]), cwd);
2081
- const { Scanner } = await importOxide();
2134
+ const { Scanner } = await getOxideModule();
2082
2135
  const scanner = new Scanner({
2083
2136
  sources: normalizedSources
2084
2137
  });
@@ -2266,7 +2319,7 @@ async function collectClassesFromTailwindV4(options) {
2266
2319
  var _module = require('module');
2267
2320
 
2268
2321
 
2269
- var require2 = _module.createRequire.call(void 0, _chunk7JAOSSROjs.importMetaUrl);
2322
+ var require2 = _module.createRequire.call(void 0, _chunk5CWNAWKPjs.importMetaUrl);
2270
2323
  function resolveRuntimeEntry(packageInfo, majorVersion) {
2271
2324
  const root = packageInfo.rootPath;
2272
2325
  if (majorVersion === 2) {
@@ -2314,9 +2367,52 @@ function loadRuntimeContexts(packageInfo, majorVersion, refProperty) {
2314
2367
  // src/runtime/process-tailwindcss.ts
2315
2368
 
2316
2369
 
2370
+
2317
2371
  var _postcss = require('postcss'); var _postcss2 = _interopRequireDefault(_postcss);
2318
2372
  var _tailwindcssconfig = require('tailwindcss-config');
2319
- var require3 = _module.createRequire.call(void 0, _chunk7JAOSSROjs.importMetaUrl);
2373
+ var require3 = _module.createRequire.call(void 0, _chunk5CWNAWKPjs.importMetaUrl);
2374
+ function resolveModuleEntry(id) {
2375
+ return _pathe2.default.isAbsolute(id) ? id : require3.resolve(id);
2376
+ }
2377
+ function resolvePackageRootFromEntry(entry) {
2378
+ let current = _pathe2.default.dirname(entry);
2379
+ while (current && current !== _pathe2.default.dirname(current)) {
2380
+ const packageJsonPath = _pathe2.default.join(current, "package.json");
2381
+ if (_fsextra2.default.pathExistsSync(packageJsonPath)) {
2382
+ return current;
2383
+ }
2384
+ current = _pathe2.default.dirname(current);
2385
+ }
2386
+ return void 0;
2387
+ }
2388
+ function clearTailwindV3RuntimeState(pluginName) {
2389
+ try {
2390
+ const entry = resolveModuleEntry(pluginName);
2391
+ const root = resolvePackageRootFromEntry(entry);
2392
+ if (!root) {
2393
+ return;
2394
+ }
2395
+ const sharedStatePath = _pathe2.default.join(root, "lib/lib/sharedState.js");
2396
+ if (!_fsextra2.default.pathExistsSync(sharedStatePath)) {
2397
+ return;
2398
+ }
2399
+ const sharedState = _optionalChain([require3, 'access', _109 => _109.cache, 'access', _110 => _110[sharedStatePath], 'optionalAccess', _111 => _111.exports]);
2400
+ _optionalChain([sharedState, 'optionalAccess', _112 => _112.contextMap, 'optionalAccess', _113 => _113.clear, 'call', _114 => _114()]);
2401
+ _optionalChain([sharedState, 'optionalAccess', _115 => _115.configContextMap, 'optionalAccess', _116 => _116.clear, 'call', _117 => _117()]);
2402
+ _optionalChain([sharedState, 'optionalAccess', _118 => _118.contextSourcesMap, 'optionalAccess', _119 => _119.clear, 'call', _120 => _120()]);
2403
+ _optionalChain([sharedState, 'optionalAccess', _121 => _121.sourceHashMap, 'optionalAccess', _122 => _122.clear, 'call', _123 => _123()]);
2404
+ for (const candidate of ["lib/plugin.js", "lib/index.js"]) {
2405
+ const runtimeEntry = _pathe2.default.join(root, candidate);
2406
+ if (!_fsextra2.default.pathExistsSync(runtimeEntry)) {
2407
+ continue;
2408
+ }
2409
+ const runtimeModule = _optionalChain([require3, 'access', _124 => _124.cache, 'access', _125 => _125[runtimeEntry], 'optionalAccess', _126 => _126.exports]);
2410
+ _optionalChain([runtimeModule, 'optionalAccess', _127 => _127.contextRef, 'optionalAccess', _128 => _128.value, 'optionalAccess', _129 => _129.splice, 'call', _130 => _130(0, runtimeModule.contextRef.value.length)]);
2411
+ break;
2412
+ }
2413
+ } catch (e10) {
2414
+ }
2415
+ }
2320
2416
  async function resolveConfigPath(options) {
2321
2417
  if (options.config && _pathe2.default.isAbsolute(options.config)) {
2322
2418
  return options.config;
@@ -2330,6 +2426,9 @@ async function resolveConfigPath(options) {
2330
2426
  async function runTailwindBuild(options) {
2331
2427
  const configPath = await resolveConfigPath(options);
2332
2428
  const pluginName = _nullishCoalesce(options.postcssPlugin, () => ( (options.majorVersion === 4 ? "@tailwindcss/postcss" : "tailwindcss")));
2429
+ if (options.majorVersion === 3) {
2430
+ clearTailwindV3RuntimeState(pluginName);
2431
+ }
2333
2432
  if (options.majorVersion === 4) {
2334
2433
  return _postcss2.default.call(void 0, [
2335
2434
  require3(pluginName)({
@@ -2390,7 +2489,7 @@ function transformProcessTailwindFeaturesReturnContextV2(content) {
2390
2489
  traverse(ast, {
2391
2490
  FunctionDeclaration(path18) {
2392
2491
  const node = path18.node;
2393
- if (_optionalChain([node, 'access', _109 => _109.id, 'optionalAccess', _110 => _110.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
2492
+ if (_optionalChain([node, 'access', _131 => _131.id, 'optionalAccess', _132 => _132.name]) !== "processTailwindFeatures" || node.body.body.length !== 1 || !t.isReturnStatement(node.body.body[0])) {
2394
2493
  return;
2395
2494
  }
2396
2495
  const returnStatement3 = node.body.body[0];
@@ -2423,7 +2522,7 @@ function transformPostcssPluginV2(content, options) {
2423
2522
  Program(path18) {
2424
2523
  const program = path18.node;
2425
2524
  const index = program.body.findIndex((statement) => {
2426
- return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _111 => _111.id, 'optionalAccess', _112 => _112.name]) === "_default";
2525
+ return t.isFunctionDeclaration(statement) && _optionalChain([statement, 'access', _133 => _133.id, 'optionalAccess', _134 => _134.name]) === "_default";
2427
2526
  });
2428
2527
  if (index === -1) {
2429
2528
  return;
@@ -2460,7 +2559,7 @@ function transformPostcssPluginV2(content, options) {
2460
2559
  return;
2461
2560
  }
2462
2561
  const fn = path18.node;
2463
- if (_optionalChain([fn, 'access', _113 => _113.id, 'optionalAccess', _114 => _114.name]) !== "_default") {
2562
+ if (_optionalChain([fn, 'access', _135 => _135.id, 'optionalAccess', _136 => _136.name]) !== "_default") {
2464
2563
  return;
2465
2564
  }
2466
2565
  if (fn.body.body.length !== 1 || !t.isReturnStatement(fn.body.body[0])) {
@@ -2550,7 +2649,7 @@ function transformProcessTailwindFeaturesReturnContext(content) {
2550
2649
  traverse(ast, {
2551
2650
  FunctionDeclaration(path18) {
2552
2651
  const node = path18.node;
2553
- if (_optionalChain([node, 'access', _115 => _115.id, 'optionalAccess', _116 => _116.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
2652
+ if (_optionalChain([node, 'access', _137 => _137.id, 'optionalAccess', _138 => _138.name]) !== "processTailwindFeatures" || node.body.body.length !== 1) {
2554
2653
  return;
2555
2654
  }
2556
2655
  const [returnStatement3] = node.body.body;
@@ -2584,7 +2683,7 @@ function transformPostcssPlugin(content, { refProperty }) {
2584
2683
  Program(path18) {
2585
2684
  const program = path18.node;
2586
2685
  const index = program.body.findIndex((statement) => {
2587
- return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _117 => _117.expression, 'access', _118 => _118.right, 'access', _119 => _119.id, 'optionalAccess', _120 => _120.name]) === "tailwindcss";
2686
+ return t2.isExpressionStatement(statement) && t2.isAssignmentExpression(statement.expression) && t2.isMemberExpression(statement.expression.left) && t2.isFunctionExpression(statement.expression.right) && _optionalChain([statement, 'access', _139 => _139.expression, 'access', _140 => _140.right, 'access', _141 => _141.id, 'optionalAccess', _142 => _142.name]) === "tailwindcss";
2588
2687
  });
2589
2688
  if (index === -1) {
2590
2689
  return;
@@ -2625,7 +2724,7 @@ function transformPostcssPlugin(content, { refProperty }) {
2625
2724
  return;
2626
2725
  }
2627
2726
  const fn = path18.node;
2628
- if (_optionalChain([fn, 'access', _121 => _121.id, 'optionalAccess', _122 => _122.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
2727
+ if (_optionalChain([fn, 'access', _143 => _143.id, 'optionalAccess', _144 => _144.name]) !== "tailwindcss" || fn.body.body.length !== 1) {
2629
2728
  return;
2630
2729
  }
2631
2730
  const [returnStatement3] = fn.body.body;
@@ -3022,7 +3121,7 @@ function checkExtendLengthUnitsPatch(context) {
3022
3121
  function getPatchStatusReport(context) {
3023
3122
  return {
3024
3123
  package: {
3025
- name: _nullishCoalesce(context.packageInfo.name, () => ( _optionalChain([context, 'access', _123 => _123.packageInfo, 'access', _124 => _124.packageJson, 'optionalAccess', _125 => _125.name]))),
3124
+ name: _nullishCoalesce(context.packageInfo.name, () => ( _optionalChain([context, 'access', _145 => _145.packageInfo, 'access', _146 => _146.packageJson, 'optionalAccess', _147 => _147.name]))),
3026
3125
  version: context.packageInfo.version,
3027
3126
  root: context.packageInfo.rootPath
3028
3127
  },
@@ -3142,7 +3241,7 @@ function applyTailwindPatches(context) {
3142
3241
  majorVersion
3143
3242
  });
3144
3243
  }
3145
- if (_optionalChain([options, 'access', _126 => _126.features, 'access', _127 => _127.extendLengthUnits, 'optionalAccess', _128 => _128.enabled])) {
3244
+ if (_optionalChain([options, 'access', _148 => _148.features, 'access', _149 => _149.extendLengthUnits, 'optionalAccess', _150 => _150.enabled])) {
3146
3245
  if (majorVersion === 3) {
3147
3246
  results.extendLengthUnits = applyExtendLengthUnitsPatchV3(
3148
3247
  packageInfo.rootPath,
@@ -3205,6 +3304,8 @@ var TailwindcssPatcher = (_class2 = class {
3205
3304
 
3206
3305
 
3207
3306
 
3307
+
3308
+
3208
3309
  constructor(options = {}) {;_class2.prototype.__init4.call(this);
3209
3310
  const resolvedOptions = options && typeof options === "object" && "patch" in options ? fromLegacyOptions(options) : options;
3210
3311
  this.options = normalizeOptions(resolvedOptions);
@@ -3228,11 +3329,20 @@ var TailwindcssPatcher = (_class2 = class {
3228
3329
  this.cacheStore = new CacheStore(this.options.cache, this.cacheContext);
3229
3330
  }
3230
3331
  async patch() {
3231
- return applyTailwindPatches({
3332
+ const snapshot = this.createPatchSnapshot();
3333
+ if (this.patchMemo && this.patchMemo.snapshot === snapshot) {
3334
+ return this.patchMemo.result;
3335
+ }
3336
+ const result = applyTailwindPatches({
3232
3337
  packageInfo: this.packageInfo,
3233
3338
  options: this.options,
3234
3339
  majorVersion: this.majorVersion
3235
3340
  });
3341
+ this.patchMemo = {
3342
+ result,
3343
+ snapshot: this.createPatchSnapshot()
3344
+ };
3345
+ return result;
3236
3346
  }
3237
3347
  async getPatchStatus() {
3238
3348
  return getPatchStatusReport({
@@ -3250,6 +3360,9 @@ var TailwindcssPatcher = (_class2 = class {
3250
3360
  }
3251
3361
  async runTailwindBuildIfNeeded() {
3252
3362
  if (this.majorVersion === 2 || this.majorVersion === 3) {
3363
+ if (this.inFlightBuild) {
3364
+ return this.inFlightBuild;
3365
+ }
3253
3366
  const executionOptions = resolveTailwindExecutionOptions(this.options, this.majorVersion);
3254
3367
  const buildOptions = {
3255
3368
  cwd: executionOptions.cwd,
@@ -3257,8 +3370,53 @@ var TailwindcssPatcher = (_class2 = class {
3257
3370
  ...executionOptions.config === void 0 ? {} : { config: executionOptions.config },
3258
3371
  ...executionOptions.postcssPlugin === void 0 ? {} : { postcssPlugin: executionOptions.postcssPlugin }
3259
3372
  };
3260
- await runTailwindBuild(buildOptions);
3373
+ this.inFlightBuild = runTailwindBuild(buildOptions).then(() => void 0);
3374
+ try {
3375
+ await this.inFlightBuild;
3376
+ } finally {
3377
+ this.inFlightBuild = void 0;
3378
+ }
3379
+ }
3380
+ }
3381
+ createPatchSnapshot() {
3382
+ const entries = [];
3383
+ const pushSnapshot = (filePath) => {
3384
+ if (!_fsextra2.default.pathExistsSync(filePath)) {
3385
+ entries.push(`${filePath}:missing`);
3386
+ return;
3387
+ }
3388
+ const stat = _fsextra2.default.statSync(filePath);
3389
+ entries.push(`${filePath}:${stat.size}:${Math.trunc(stat.mtimeMs)}`);
3390
+ };
3391
+ if (this.options.features.exposeContext.enabled && (this.majorVersion === 2 || this.majorVersion === 3)) {
3392
+ if (this.majorVersion === 2) {
3393
+ pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, "lib/jit/processTailwindFeatures.js"));
3394
+ pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, "lib/jit/index.js"));
3395
+ } else {
3396
+ pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, "lib/processTailwindFeatures.js"));
3397
+ const pluginPath = ["lib/plugin.js", "lib/index.js"].map((file) => _pathe2.default.resolve(this.packageInfo.rootPath, file)).find((file) => _fsextra2.default.pathExistsSync(file));
3398
+ if (pluginPath) {
3399
+ pushSnapshot(pluginPath);
3400
+ }
3401
+ }
3402
+ }
3403
+ if (_optionalChain([this, 'access', _151 => _151.options, 'access', _152 => _152.features, 'access', _153 => _153.extendLengthUnits, 'optionalAccess', _154 => _154.enabled])) {
3404
+ if (this.majorVersion === 3) {
3405
+ const target = _nullishCoalesce(this.options.features.extendLengthUnits.lengthUnitsFilePath, () => ( "lib/util/dataTypes.js"));
3406
+ pushSnapshot(_pathe2.default.resolve(this.packageInfo.rootPath, target));
3407
+ } else if (this.majorVersion === 4) {
3408
+ const distDir = _pathe2.default.resolve(this.packageInfo.rootPath, "dist");
3409
+ if (_fsextra2.default.pathExistsSync(distDir)) {
3410
+ const chunkNames = _fsextra2.default.readdirSync(distDir).filter((entry) => entry.endsWith(".js") || entry.endsWith(".mjs")).sort();
3411
+ for (const chunkName of chunkNames) {
3412
+ pushSnapshot(_pathe2.default.join(distDir, chunkName));
3413
+ }
3414
+ } else {
3415
+ entries.push(`${distDir}:missing`);
3416
+ }
3417
+ }
3261
3418
  }
3419
+ return entries.join("|");
3262
3420
  }
3263
3421
  async collectClassSet() {
3264
3422
  if (this.majorVersion === 4) {
@@ -3270,12 +3428,12 @@ var TailwindcssPatcher = (_class2 = class {
3270
3428
  debugCacheRead(meta) {
3271
3429
  if (meta.hit) {
3272
3430
  logger_default.debug(
3273
- `[cache] hit fingerprint=${_nullishCoalesce(_optionalChain([meta, 'access', _129 => _129.fingerprint, 'optionalAccess', _130 => _130.slice, 'call', _131 => _131(0, 12)]), () => ( "n/a"))} schema=${_nullishCoalesce(meta.schemaVersion, () => ( "legacy"))} ${meta.details.join("; ")}`
3431
+ `[cache] hit fingerprint=${_nullishCoalesce(_optionalChain([meta, 'access', _155 => _155.fingerprint, 'optionalAccess', _156 => _156.slice, 'call', _157 => _157(0, 12)]), () => ( "n/a"))} schema=${_nullishCoalesce(meta.schemaVersion, () => ( "legacy"))} ${meta.details.join("; ")}`
3274
3432
  );
3275
3433
  return;
3276
3434
  }
3277
3435
  logger_default.debug(
3278
- `[cache] miss reason=${meta.reason} fingerprint=${_nullishCoalesce(_optionalChain([meta, 'access', _132 => _132.fingerprint, 'optionalAccess', _133 => _133.slice, 'call', _134 => _134(0, 12)]), () => ( "n/a"))} schema=${_nullishCoalesce(meta.schemaVersion, () => ( "legacy"))} ${meta.details.join("; ")}`
3436
+ `[cache] miss reason=${meta.reason} fingerprint=${_nullishCoalesce(_optionalChain([meta, 'access', _158 => _158.fingerprint, 'optionalAccess', _159 => _159.slice, 'call', _160 => _160(0, 12)]), () => ( "n/a"))} schema=${_nullishCoalesce(meta.schemaVersion, () => ( "legacy"))} ${meta.details.join("; ")}`
3279
3437
  );
3280
3438
  }
3281
3439
  async mergeWithCache(set) {
@@ -3288,13 +3446,13 @@ var TailwindcssPatcher = (_class2 = class {
3288
3446
  for (const value of existing) {
3289
3447
  set.add(value);
3290
3448
  }
3291
- const writeTarget = await this.cacheStore.write(set);
3449
+ const writeTarget = this.areSetsEqual(existing, set) ? void 0 : await this.cacheStore.write(set);
3292
3450
  if (writeTarget) {
3293
3451
  logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
3294
3452
  }
3295
3453
  } else {
3296
3454
  if (set.size > 0) {
3297
- const writeTarget = await this.cacheStore.write(set);
3455
+ const writeTarget = this.areSetsEqual(existing, set) ? void 0 : await this.cacheStore.write(set);
3298
3456
  if (writeTarget) {
3299
3457
  logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
3300
3458
  }
@@ -3314,13 +3472,13 @@ var TailwindcssPatcher = (_class2 = class {
3314
3472
  for (const value of existing) {
3315
3473
  set.add(value);
3316
3474
  }
3317
- const writeTarget = this.cacheStore.writeSync(set);
3475
+ const writeTarget = this.areSetsEqual(existing, set) ? void 0 : this.cacheStore.writeSync(set);
3318
3476
  if (writeTarget) {
3319
3477
  logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
3320
3478
  }
3321
3479
  } else {
3322
3480
  if (set.size > 0) {
3323
- const writeTarget = this.cacheStore.writeSync(set);
3481
+ const writeTarget = this.areSetsEqual(existing, set) ? void 0 : this.cacheStore.writeSync(set);
3324
3482
  if (writeTarget) {
3325
3483
  logger_default.debug(`[cache] stored ${set.size} classes -> ${writeTarget}`);
3326
3484
  }
@@ -3330,6 +3488,17 @@ var TailwindcssPatcher = (_class2 = class {
3330
3488
  }
3331
3489
  return set;
3332
3490
  }
3491
+ areSetsEqual(a, b) {
3492
+ if (a.size !== b.size) {
3493
+ return false;
3494
+ }
3495
+ for (const value of a) {
3496
+ if (!b.has(value)) {
3497
+ return false;
3498
+ }
3499
+ }
3500
+ return true;
3501
+ }
3333
3502
  async getClassSet() {
3334
3503
  await this.runTailwindBuildIfNeeded();
3335
3504
  const set = await this.collectClassSet();
@@ -3348,7 +3517,7 @@ var TailwindcssPatcher = (_class2 = class {
3348
3517
  return merged;
3349
3518
  }
3350
3519
  async extract(options) {
3351
- const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _135 => _135.write]), () => ( this.options.output.enabled));
3520
+ const shouldWrite = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _161 => _161.write]), () => ( this.options.output.enabled));
3352
3521
  const classSet = await this.getClassSet();
3353
3522
  const classList = Array.from(classSet);
3354
3523
  const result = {
@@ -3384,19 +3553,19 @@ var TailwindcssPatcher = (_class2 = class {
3384
3553
  __init4() {this.extractValidCandidates = exports.extractValidCandidates = extractValidCandidates}
3385
3554
  async collectContentTokens(options) {
3386
3555
  return extractProjectCandidatesWithPositions({
3387
- cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _136 => _136.cwd]), () => ( this.options.projectRoot)),
3388
- sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _137 => _137.sources]), () => ( _optionalChain([this, 'access', _138 => _138.options, 'access', _139 => _139.tailwind, 'access', _140 => _140.v4, 'optionalAccess', _141 => _141.sources]))), () => ( []))
3556
+ cwd: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _162 => _162.cwd]), () => ( this.options.projectRoot)),
3557
+ sources: _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _163 => _163.sources]), () => ( _optionalChain([this, 'access', _164 => _164.options, 'access', _165 => _165.tailwind, 'access', _166 => _166.v4, 'optionalAccess', _167 => _167.sources]))), () => ( []))
3389
3558
  });
3390
3559
  }
3391
3560
  async collectContentTokensByFile(options) {
3392
3561
  const collectContentOptions = {
3393
- ..._optionalChain([options, 'optionalAccess', _142 => _142.cwd]) === void 0 ? {} : { cwd: options.cwd },
3394
- ..._optionalChain([options, 'optionalAccess', _143 => _143.sources]) === void 0 ? {} : { sources: options.sources }
3562
+ ..._optionalChain([options, 'optionalAccess', _168 => _168.cwd]) === void 0 ? {} : { cwd: options.cwd },
3563
+ ..._optionalChain([options, 'optionalAccess', _169 => _169.sources]) === void 0 ? {} : { sources: options.sources }
3395
3564
  };
3396
3565
  const report = await this.collectContentTokens(collectContentOptions);
3397
3566
  const groupOptions = {
3398
- ..._optionalChain([options, 'optionalAccess', _144 => _144.key]) === void 0 ? {} : { key: options.key },
3399
- ..._optionalChain([options, 'optionalAccess', _145 => _145.stripAbsolutePaths]) === void 0 ? {} : { stripAbsolutePaths: options.stripAbsolutePaths }
3567
+ ..._optionalChain([options, 'optionalAccess', _170 => _170.key]) === void 0 ? {} : { key: options.key },
3568
+ ..._optionalChain([options, 'optionalAccess', _171 => _171.stripAbsolutePaths]) === void 0 ? {} : { stripAbsolutePaths: options.stripAbsolutePaths }
3400
3569
  };
3401
3570
  return groupTokensByFile(report, groupOptions);
3402
3571
  }
@@ -3797,7 +3966,7 @@ async function collectWorkspaceConfigFiles(cwd, maxDepth) {
3797
3966
  let entries;
3798
3967
  try {
3799
3968
  entries = await _fsextra2.default.readdir(dir, { withFileTypes: true });
3800
- } catch (e10) {
3969
+ } catch (e11) {
3801
3970
  continue;
3802
3971
  }
3803
3972
  for (const entry of entries) {
@@ -3897,7 +4066,7 @@ async function rollbackWrittenEntries(wroteEntries) {
3897
4066
  written.entry.written = false;
3898
4067
  written.entry.rolledBack = true;
3899
4068
  rollbackCount += 1;
3900
- } catch (e11) {
4069
+ } catch (e12) {
3901
4070
  }
3902
4071
  }
3903
4072
  return rollbackCount;
@@ -4289,10 +4458,10 @@ function addPrefixIfMissing(value, prefix) {
4289
4458
  return `${prefix}${value}`;
4290
4459
  }
4291
4460
  function resolveCommandNames(command, mountOptions, prefix) {
4292
- const override = _optionalChain([mountOptions, 'access', _146 => _146.commandOptions, 'optionalAccess', _147 => _147[command]]);
4293
- const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _148 => _148.name]), () => ( command));
4461
+ const override = _optionalChain([mountOptions, 'access', _172 => _172.commandOptions, 'optionalAccess', _173 => _173[command]]);
4462
+ const baseName = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _174 => _174.name]), () => ( command));
4294
4463
  const name = addPrefixIfMissing(baseName, prefix);
4295
- const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _149 => _149.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
4464
+ const aliases = (_nullishCoalesce(_optionalChain([override, 'optionalAccess', _175 => _175.aliases]), () => ( []))).map((alias) => addPrefixIfMissing(alias, prefix));
4296
4465
  return { name, aliases };
4297
4466
  }
4298
4467
  function resolveOptionDefinitions(defaults, override) {
@@ -4312,8 +4481,8 @@ function resolveOptionDefinitions(defaults, override) {
4312
4481
  function resolveCommandMetadata(command, mountOptions, prefix, defaults) {
4313
4482
  const names = resolveCommandNames(command, mountOptions, prefix);
4314
4483
  const definition = defaults[command];
4315
- const override = _optionalChain([mountOptions, 'access', _150 => _150.commandOptions, 'optionalAccess', _151 => _151[command]]);
4316
- const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _152 => _152.description]), () => ( definition.description));
4484
+ const override = _optionalChain([mountOptions, 'access', _176 => _176.commandOptions, 'optionalAccess', _177 => _177[command]]);
4485
+ const description = _nullishCoalesce(_optionalChain([override, 'optionalAccess', _178 => _178.description]), () => ( definition.description));
4317
4486
  const optionDefs = resolveOptionDefinitions(definition.optionDefs, override);
4318
4487
  return { ...names, description, optionDefs };
4319
4488
  }
@@ -4832,7 +5001,7 @@ function registerTailwindcssPatchCommand(cli, commandName, options, prefix, defa
4832
5001
  command,
4833
5002
  commandName,
4834
5003
  args,
4835
- _optionalChain([options, 'access', _153 => _153.commandHandlers, 'optionalAccess', _154 => _154[commandName]]),
5004
+ _optionalChain([options, 'access', _179 => _179.commandHandlers, 'optionalAccess', _180 => _180[commandName]]),
4836
5005
  defaultCommandHandlers[commandName]
4837
5006
  );
4838
5007
  });
package/dist/cli.js CHANGED
@@ -2,23 +2,23 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkEFYAZO6Cjs = require('./chunk-EFYAZO6C.js');
6
- require('./chunk-7JAOSSRO.js');
5
+ var _chunkZXW4S356js = require('./chunk-ZXW4S356.js');
6
+ require('./chunk-5CWNAWKP.js');
7
7
 
8
8
  // src/cli.ts
9
9
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
10
10
  async function main() {
11
- const cli = _chunkEFYAZO6Cjs.createTailwindcssPatchCli.call(void 0, );
11
+ const cli = _chunkZXW4S356js.createTailwindcssPatchCli.call(void 0, );
12
12
  cli.help();
13
13
  cli.parse(_process2.default.argv, { run: false });
14
14
  await cli.runMatchedCommand();
15
15
  }
16
16
  main().catch((error) => {
17
- if (error instanceof _chunkEFYAZO6Cjs.ValidateCommandError) {
17
+ if (error instanceof _chunkZXW4S356js.ValidateCommandError) {
18
18
  _process2.default.exitCode = error.exitCode;
19
19
  return;
20
20
  }
21
21
  const message = error instanceof Error ? error.message : String(error);
22
- _chunkEFYAZO6Cjs.logger_default.error(message);
22
+ _chunkZXW4S356js.logger_default.error(message);
23
23
  _process2.default.exitCode = 1;
24
24
  });
package/dist/cli.mjs CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  ValidateCommandError,
3
3
  createTailwindcssPatchCli,
4
4
  logger_default
5
- } from "./chunk-3T6WSV7F.mjs";
6
- import "./chunk-JHEI2MLC.mjs";
5
+ } from "./chunk-6ZDYMYHE.mjs";
6
+ import "./chunk-A67ABH3M.mjs";
7
7
 
8
8
  // src/cli.ts
9
9
  import process from "process";
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('./chunk-7JAOSSRO.js');
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }require('./chunk-5CWNAWKP.js');
2
2
 
3
3
  // ../shared/dist/index.js
4
4
  var _process = require('process'); var _process2 = _interopRequireDefault(_process);
@@ -1,4 +1,4 @@
1
- import "./chunk-JHEI2MLC.mjs";
1
+ import "./chunk-A67ABH3M.mjs";
2
2
 
3
3
  // ../shared/dist/index.js
4
4
  import process from "process";