weapp-tailwindcss 5.4.0 → 5.4.2

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.
Files changed (47) hide show
  1. package/dist/{compiler-C93NfxSe.cjs → compiler-B-m9VGqj.cjs} +74 -12
  2. package/dist/{compiler-qDa3phIv.js → compiler-BgMj2E5l.js} +64 -14
  3. package/dist/core/compiler/index.d.ts +1 -1
  4. package/dist/core/compiler/root-store.d.ts +6 -3
  5. package/dist/core/compiler/types.d.ts +9 -3
  6. package/dist/core.cjs +26 -1
  7. package/dist/core.d.ts +3 -1
  8. package/dist/core.js +3 -2
  9. package/dist/framework.cjs +22 -2
  10. package/dist/framework.js +22 -2
  11. package/dist/{generator-C0m2S4WI.js → generator-BjK5PRR-.js} +25 -8
  12. package/dist/{generator-CKJ6sj1f.cjs → generator-WlhrtNa3.cjs} +23 -6
  13. package/dist/generator.cjs +1 -1
  14. package/dist/generator.js +1 -1
  15. package/dist/{gulp-CW6JGqVn.cjs → gulp-ChecVI6A.cjs} +5 -5
  16. package/dist/{gulp-e2iWsmEK.js → gulp-D6LcfRz_.js} +4 -4
  17. package/dist/gulp.cjs +1 -1
  18. package/dist/gulp.js +1 -1
  19. package/dist/{hmr-timing-DgMgwSce.js → hmr-timing-CqDfjvqE.js} +5 -5
  20. package/dist/{hmr-timing-n7QQKFp7.cjs → hmr-timing-afnWvy7u.cjs} +3 -3
  21. package/dist/index.cjs +4 -4
  22. package/dist/index.js +4 -4
  23. package/dist/{pipeline-helpers-DoLQy44Q.cjs → pipeline-helpers-DxPFMGxz.cjs} +3 -3
  24. package/dist/postcss.cjs +1 -1
  25. package/dist/postcss.js +1 -1
  26. package/dist/presets.cjs +1 -1
  27. package/dist/presets.js +1 -1
  28. package/dist/rspack.cjs +2 -2
  29. package/dist/rspack.js +2 -2
  30. package/dist/{source-candidate-scan-signature-B0lOMiwB.js → source-candidate-scan-signature-BVScymyM.js} +3 -3
  31. package/dist/{source-candidate-scan-signature-Chb-Zrwt.cjs → source-candidate-scan-signature-FywFU3Rg.cjs} +3 -3
  32. package/dist/{tailwindcss-BSKl0FTD.js → tailwindcss-9xmoCkaR.js} +1 -1
  33. package/dist/{tailwindcss-BGlJ1m1l.cjs → tailwindcss-D3jltF7M.cjs} +1 -1
  34. package/dist/typedoc.export.d.ts +1 -1
  35. package/dist/types/index.d.ts +1 -0
  36. package/dist/{v4-generation-core-B2sUkkgq.cjs → v4-generation-core-CPKNwzjz.cjs} +3 -3
  37. package/dist/{vite-B0IPgrvM.cjs → vite-D-gmOkPN.cjs} +43 -15
  38. package/dist/{vite-CcEb2SOl.js → vite-D3aCtpmv.js} +42 -14
  39. package/dist/vite.cjs +1 -1
  40. package/dist/vite.js +1 -1
  41. package/dist/weapp-tw-css-generation-loader.cjs +1 -1
  42. package/dist/weapp-tw-css-import-rewrite-loader.cjs +5 -5
  43. package/dist/{webpack-BPA5I79o.js → webpack-B-6a8Z8F.js} +8 -8
  44. package/dist/{webpack-B5vc13U_.cjs → webpack-yAne9ZYu.cjs} +7 -7
  45. package/dist/webpack.cjs +1 -1
  46. package/dist/webpack.js +1 -1
  47. package/package.json +2 -2
@@ -1,8 +1,8 @@
1
1
  const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
2
2
  const require_framework = require("./framework.cjs");
3
- const require_generator = require("./generator-CKJ6sj1f.cjs");
3
+ const require_generator = require("./generator-WlhrtNa3.cjs");
4
4
  const require_object = require("./object-DbHtAXRk.cjs");
5
- const require_tailwindcss = require("./tailwindcss-BGlJ1m1l.cjs");
5
+ const require_tailwindcss = require("./tailwindcss-D3jltF7M.cjs");
6
6
  require("./utils-CuKLf1Zv.cjs");
7
7
  const require_wxml = require("./wxml-o-CUulAM.cjs");
8
8
  const require_defaults = require("./defaults.cjs");
@@ -286,8 +286,9 @@ function disposeGenerator(generator) {
286
286
  generator?.dispose?.();
287
287
  }
288
288
  var CompilerRootStore = class {
289
- constructor(maxRoots) {
289
+ constructor(maxRoots, onRootEvicted) {
290
290
  this.maxRoots = maxRoots;
291
+ this.onRootEvicted = onRootEvicted;
291
292
  require_object._defineProperty(this, "dependencyRoots", /* @__PURE__ */ new Map());
292
293
  require_object._defineProperty(this, "releasing", /* @__PURE__ */ new Map());
293
294
  require_object._defineProperty(this, "roots", /* @__PURE__ */ new Map());
@@ -304,7 +305,7 @@ var CompilerRootStore = class {
304
305
  }
305
306
  if (this.roots.size >= this.maxRoots) {
306
307
  const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
307
- if (oldest) this.remove(oldest.id);
308
+ if (oldest) this.remove(oldest.id, true);
308
309
  }
309
310
  const entry = {
310
311
  accepting: true,
@@ -316,7 +317,8 @@ var CompilerRootStore = class {
316
317
  id,
317
318
  invalidation: 0,
318
319
  pending: Promise.resolve(),
319
- pendingCount: 0
320
+ pendingCount: 0,
321
+ sources: []
320
322
  };
321
323
  this.roots.set(id, entry);
322
324
  return entry;
@@ -334,12 +336,17 @@ var CompilerRootStore = class {
334
336
  owners.add(entry.id);
335
337
  }
336
338
  }
339
+ attachSources(entry, sources) {
340
+ entry.sources = [...sources];
341
+ }
337
342
  invalidate(ids) {
338
343
  const affected = /* @__PURE__ */ new Set();
339
344
  for (const id of ids) {
340
345
  const root = this.roots.get(id);
341
346
  if (root?.accepting) affected.add(root.id);
342
347
  for (const rootId of this.dependencyRoots.get(id) ?? []) affected.add(rootId);
348
+ const sourcePath = stripSourceQuery(id);
349
+ for (const sourceRoot of this.roots.values()) if (sourceRoot.accepting && sourceRoot.sources.length > 0 && require_generator.isFileMatchedByTailwindSourceEntries(sourcePath, sourceRoot.sources)) affected.add(sourceRoot.id);
343
350
  }
344
351
  for (const rootId of affected) {
345
352
  const entry = this.roots.get(rootId);
@@ -351,10 +358,10 @@ var CompilerRootStore = class {
351
358
  while (this.roots.size > this.maxRoots) {
352
359
  const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
353
360
  if (!oldest) return;
354
- this.remove(oldest.id);
361
+ this.remove(oldest.id, true);
355
362
  }
356
363
  }
357
- remove(id) {
364
+ remove(id, notifyEvicted = false) {
358
365
  const pendingRelease = this.releasing.get(id);
359
366
  if (pendingRelease) return pendingRelease;
360
367
  const entry = this.roots.get(id);
@@ -373,6 +380,8 @@ var CompilerRootStore = class {
373
380
  entry.source = void 0;
374
381
  entry.sourceInput = void 0;
375
382
  entry.sourceFingerprint = void 0;
383
+ entry.sources = [];
384
+ if (notifyEvicted) this.onRootEvicted?.(id);
376
385
  }).finally(() => {
377
386
  this.releasing.delete(id);
378
387
  });
@@ -392,6 +401,9 @@ var CompilerRootStore = class {
392
401
  entry.dependencies.clear();
393
402
  }
394
403
  };
404
+ function stripSourceQuery(id) {
405
+ return id.replace(/[?#].*$/, "");
406
+ }
395
407
  //#endregion
396
408
  //#region src/core/compiler/snapshot.ts
397
409
  const readonlySetValues = /* @__PURE__ */ new WeakMap();
@@ -1892,8 +1904,10 @@ function createInternalCompilerContext(opts) {
1892
1904
  applyFrameworkPlatformDefaults(ctx);
1893
1905
  applyLoggerLevel(ctx.logLevel);
1894
1906
  const tailwindRuntime = require_tailwindcss.createTailwindcssRuntimeFromContext(ctx);
1895
- logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
1896
- logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
1907
+ if (opts?.__internalViteDeferRuntimeLogs !== true) {
1908
+ logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
1909
+ logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
1910
+ }
1897
1911
  if (opts?.__internalDeferMissingCssEntriesWarning !== true) require_tailwindcss.warnMissingCssEntries(ctx, tailwindRuntime);
1898
1912
  ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
1899
1913
  const cssCalcOptions = require_tailwindcss.applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
@@ -1948,6 +1962,18 @@ function resolveStyleOptions(options) {
1948
1962
  isMainChunk: true
1949
1963
  } : options;
1950
1964
  }
1965
+ function resolveCssTransformOptions(options) {
1966
+ const { finalize: _finalize, ...styleOptions } = options ?? {};
1967
+ return {
1968
+ finalize: _finalize,
1969
+ styleOptions: resolveStyleOptions(styleOptions)
1970
+ };
1971
+ }
1972
+ function finalizeResultRoot(result, snapshot, shouldFinalize) {
1973
+ if (!shouldFinalize || result.root.type !== "root") return;
1974
+ (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCssRoot)(result.root, { isTailwindcssV4: snapshot.target === "weapp" });
1975
+ result.css = result.root.toString();
1976
+ }
1951
1977
  function createCompilerTransforms({ ensureActive, track, userOptions }) {
1952
1978
  const context = getCompilerContext({
1953
1979
  ...userOptions,
@@ -1981,12 +2007,23 @@ function createCompilerTransforms({ ensureActive, track, userOptions }) {
1981
2007
  function transformCss(css, snapshot, options) {
1982
2008
  ensureActive();
1983
2009
  getInternalCompilerSnapshot(snapshot);
1984
- return track(styleHandler(css, resolveStyleOptions(options)).then(clonePostcssResult));
2010
+ const resolved = resolveCssTransformOptions(options);
2011
+ const shouldFinalize = resolved.finalize ?? snapshot.target === "weapp";
2012
+ return track(styleHandler(css, resolved.styleOptions).then((result) => {
2013
+ const cloned = clonePostcssResult(result);
2014
+ finalizeResultRoot(cloned, snapshot, shouldFinalize);
2015
+ return cloned;
2016
+ }));
1985
2017
  }
1986
2018
  function transformCssRoot(root, snapshot, options) {
1987
2019
  ensureActive();
1988
2020
  getInternalCompilerSnapshot(snapshot);
1989
- return track(styleHandler.transformRoot(root, resolveStyleOptions(options)));
2021
+ const resolved = resolveCssTransformOptions(options);
2022
+ const shouldFinalize = resolved.finalize ?? snapshot.target === "weapp";
2023
+ return track(styleHandler.transformRoot(root, resolved.styleOptions).then((result) => {
2024
+ finalizeResultRoot(result, snapshot, shouldFinalize);
2025
+ return result;
2026
+ }));
1990
2027
  }
1991
2028
  function transformJavaScript(source, snapshot, options) {
1992
2029
  ensureActive();
@@ -2015,7 +2052,7 @@ function createCompilerTransforms({ ensureActive, track, userOptions }) {
2015
2052
  const DEFAULT_MAX_ROOTS = 128;
2016
2053
  function createCompiler(options = {}) {
2017
2054
  const { compiler: compilerOptions, ...userOptions } = options;
2018
- const rootStore = new CompilerRootStore(Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS)));
2055
+ const rootStore = new CompilerRootStore(Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS)), compilerOptions?.onRootEvicted);
2019
2056
  const activeTasks = /* @__PURE__ */ new Set();
2020
2057
  let lifecycle = "active";
2021
2058
  let disposePromise;
@@ -2090,6 +2127,7 @@ function createCompiler(options = {}) {
2090
2127
  entry.appliedInvalidation = invalidation;
2091
2128
  entry.latestSnapshot = snapshot;
2092
2129
  rootStore.attachDependencies(entry, dependencies);
2130
+ rootStore.attachSources(entry, sources);
2093
2131
  if (!engineReused && previousGenerator !== generator) previousGenerator?.dispose?.();
2094
2132
  const css = target === "tailwind" ? generated.rawCss : generated.css;
2095
2133
  const incrementalCss = target === "tailwind" ? generated.incrementalRawCss : generated.incrementalCss;
@@ -2133,6 +2171,16 @@ function createCompiler(options = {}) {
2133
2171
  ensureActive();
2134
2172
  return createRegisteredCompilerSnapshot(request);
2135
2173
  }
2174
+ function finalizeCss(css, options) {
2175
+ ensureActive();
2176
+ return (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCss)(css, options);
2177
+ }
2178
+ function finalizeCssRoot(root, options) {
2179
+ ensureActive();
2180
+ const cloned = root.clone();
2181
+ (0, _weapp_tailwindcss_postcss.finalizeMiniProgramCssRoot)(cloned, options);
2182
+ return cloned;
2183
+ }
2136
2184
  function mergeSnapshots(snapshots) {
2137
2185
  ensureActive();
2138
2186
  return mergeRegisteredCompilerSnapshots(snapshots);
@@ -2160,6 +2208,8 @@ function createCompiler(options = {}) {
2160
2208
  return {
2161
2209
  createSnapshot,
2162
2210
  dispose,
2211
+ finalizeCss,
2212
+ finalizeCssRoot,
2163
2213
  generate,
2164
2214
  invalidate,
2165
2215
  mergeSnapshots,
@@ -2204,6 +2254,18 @@ Object.defineProperty(exports, "getCompilerContext", {
2204
2254
  return getCompilerContext;
2205
2255
  }
2206
2256
  });
2257
+ Object.defineProperty(exports, "logRuntimeTailwindcssVersion", {
2258
+ enumerable: true,
2259
+ get: function() {
2260
+ return logRuntimeTailwindcssVersion;
2261
+ }
2262
+ });
2263
+ Object.defineProperty(exports, "logTailwindcssTarget", {
2264
+ enumerable: true,
2265
+ get: function() {
2266
+ return logTailwindcssTarget;
2267
+ }
2268
+ });
2207
2269
  Object.defineProperty(exports, "normalizeFrameworkStylePlatform", {
2208
2270
  enumerable: true,
2209
2271
  get: function() {
@@ -1,7 +1,7 @@
1
1
  import { resolveMpxPlatform } from "./framework.js";
2
- import { It as shouldUseUniAppWebRpxCompatibility, Lt as loadTailwindV4DesignSystem, Nt as resolveCssMacroTailwindV4Source, Rt as resolveValidTailwindV4Candidates$1, a as resolveGeneratorRuntimeBranch, d as resolveTailwindV4SourceFromRuntime, i as normalizeWeappTailwindcssGeneratorOptions, k as resolveBooleanObjectOption, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source$1, yt as createTailwindV4Engine$1 } from "./generator-C0m2S4WI.js";
2
+ import { It as shouldUseUniAppWebRpxCompatibility, Lt as loadTailwindV4DesignSystem, Nt as resolveCssMacroTailwindV4Source, Rt as resolveValidTailwindV4Candidates$1, a as resolveGeneratorRuntimeBranch, d as resolveTailwindV4SourceFromRuntime, i as normalizeWeappTailwindcssGeneratorOptions, k as resolveBooleanObjectOption, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source$1, wt as isFileMatchedByTailwindSourceEntries, yt as createTailwindV4Engine$1 } from "./generator-BjK5PRR-.js";
3
3
  import { n as _defineProperty } from "./object-B-8IHefx.js";
4
- import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-BSKl0FTD.js";
4
+ import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-9xmoCkaR.js";
5
5
  import { i as isMap, n as defuOverrideArray } from "./utils-MVwpU07P.js";
6
6
  import { _ as md5Hash, a as jsHandler, c as getReplacementCacheStore, d as decodeUnicode2, f as resolveClassNameTransformWithResult, l as jsStringEscape, m as createDebug, s as getReplacement, t as createTemplateHandler } from "./wxml-CvKyV69S.js";
7
7
  import { getDefaultOptions, resolveDefaultCssPreflight } from "./defaults.js";
@@ -9,7 +9,7 @@ import { createRequire } from "node:module";
9
9
  import path from "node:path";
10
10
  import process from "node:process";
11
11
  import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
12
- import { createStyleHandler } from "@weapp-tailwindcss/postcss";
12
+ import { createStyleHandler, finalizeMiniProgramCss, finalizeMiniProgramCssRoot } from "@weapp-tailwindcss/postcss";
13
13
  import { LRUCache } from "lru-cache";
14
14
  import { rm } from "node:fs/promises";
15
15
  import MagicString from "magic-string";
@@ -283,8 +283,9 @@ function disposeGenerator(generator) {
283
283
  generator?.dispose?.();
284
284
  }
285
285
  var CompilerRootStore = class {
286
- constructor(maxRoots) {
286
+ constructor(maxRoots, onRootEvicted) {
287
287
  this.maxRoots = maxRoots;
288
+ this.onRootEvicted = onRootEvicted;
288
289
  _defineProperty(this, "dependencyRoots", /* @__PURE__ */ new Map());
289
290
  _defineProperty(this, "releasing", /* @__PURE__ */ new Map());
290
291
  _defineProperty(this, "roots", /* @__PURE__ */ new Map());
@@ -301,7 +302,7 @@ var CompilerRootStore = class {
301
302
  }
302
303
  if (this.roots.size >= this.maxRoots) {
303
304
  const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
304
- if (oldest) this.remove(oldest.id);
305
+ if (oldest) this.remove(oldest.id, true);
305
306
  }
306
307
  const entry = {
307
308
  accepting: true,
@@ -313,7 +314,8 @@ var CompilerRootStore = class {
313
314
  id,
314
315
  invalidation: 0,
315
316
  pending: Promise.resolve(),
316
- pendingCount: 0
317
+ pendingCount: 0,
318
+ sources: []
317
319
  };
318
320
  this.roots.set(id, entry);
319
321
  return entry;
@@ -331,12 +333,17 @@ var CompilerRootStore = class {
331
333
  owners.add(entry.id);
332
334
  }
333
335
  }
336
+ attachSources(entry, sources) {
337
+ entry.sources = [...sources];
338
+ }
334
339
  invalidate(ids) {
335
340
  const affected = /* @__PURE__ */ new Set();
336
341
  for (const id of ids) {
337
342
  const root = this.roots.get(id);
338
343
  if (root?.accepting) affected.add(root.id);
339
344
  for (const rootId of this.dependencyRoots.get(id) ?? []) affected.add(rootId);
345
+ const sourcePath = stripSourceQuery(id);
346
+ for (const sourceRoot of this.roots.values()) if (sourceRoot.accepting && sourceRoot.sources.length > 0 && isFileMatchedByTailwindSourceEntries(sourcePath, sourceRoot.sources)) affected.add(sourceRoot.id);
340
347
  }
341
348
  for (const rootId of affected) {
342
349
  const entry = this.roots.get(rootId);
@@ -348,10 +355,10 @@ var CompilerRootStore = class {
348
355
  while (this.roots.size > this.maxRoots) {
349
356
  const oldest = [...this.roots.values()].find((entry) => entry.pendingCount === 0);
350
357
  if (!oldest) return;
351
- this.remove(oldest.id);
358
+ this.remove(oldest.id, true);
352
359
  }
353
360
  }
354
- remove(id) {
361
+ remove(id, notifyEvicted = false) {
355
362
  const pendingRelease = this.releasing.get(id);
356
363
  if (pendingRelease) return pendingRelease;
357
364
  const entry = this.roots.get(id);
@@ -370,6 +377,8 @@ var CompilerRootStore = class {
370
377
  entry.source = void 0;
371
378
  entry.sourceInput = void 0;
372
379
  entry.sourceFingerprint = void 0;
380
+ entry.sources = [];
381
+ if (notifyEvicted) this.onRootEvicted?.(id);
373
382
  }).finally(() => {
374
383
  this.releasing.delete(id);
375
384
  });
@@ -389,6 +398,9 @@ var CompilerRootStore = class {
389
398
  entry.dependencies.clear();
390
399
  }
391
400
  };
401
+ function stripSourceQuery(id) {
402
+ return id.replace(/[?#].*$/, "");
403
+ }
392
404
  //#endregion
393
405
  //#region src/core/compiler/snapshot.ts
394
406
  const readonlySetValues = /* @__PURE__ */ new WeakMap();
@@ -1722,8 +1734,10 @@ function createInternalCompilerContext(opts) {
1722
1734
  applyFrameworkPlatformDefaults(ctx);
1723
1735
  applyLoggerLevel(ctx.logLevel);
1724
1736
  const tailwindRuntime = createTailwindcssRuntimeFromContext(ctx);
1725
- logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
1726
- logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
1737
+ if (opts?.__internalViteDeferRuntimeLogs !== true) {
1738
+ logTailwindcssTarget(tailwindRuntime, ctx.tailwindcssBasedir);
1739
+ logRuntimeTailwindcssVersion(ctx.tailwindcssBasedir, tailwindRuntime.packageInfo?.rootPath, tailwindRuntime.packageInfo?.version);
1740
+ }
1727
1741
  if (opts?.__internalDeferMissingCssEntriesWarning !== true) warnMissingCssEntries(ctx, tailwindRuntime);
1728
1742
  ctx.cssPreflight = resolveContextCssPreflight(opts, ctx, tailwindRuntime.majorVersion);
1729
1743
  const cssCalcOptions = applyV4CssCalcDefaults(ctx.cssCalc, tailwindRuntime);
@@ -1778,6 +1792,18 @@ function resolveStyleOptions(options) {
1778
1792
  isMainChunk: true
1779
1793
  } : options;
1780
1794
  }
1795
+ function resolveCssTransformOptions(options) {
1796
+ const { finalize: _finalize, ...styleOptions } = options ?? {};
1797
+ return {
1798
+ finalize: _finalize,
1799
+ styleOptions: resolveStyleOptions(styleOptions)
1800
+ };
1801
+ }
1802
+ function finalizeResultRoot(result, snapshot, shouldFinalize) {
1803
+ if (!shouldFinalize || result.root.type !== "root") return;
1804
+ finalizeMiniProgramCssRoot(result.root, { isTailwindcssV4: snapshot.target === "weapp" });
1805
+ result.css = result.root.toString();
1806
+ }
1781
1807
  function createCompilerTransforms({ ensureActive, track, userOptions }) {
1782
1808
  const context = getCompilerContext({
1783
1809
  ...userOptions,
@@ -1811,12 +1837,23 @@ function createCompilerTransforms({ ensureActive, track, userOptions }) {
1811
1837
  function transformCss(css, snapshot, options) {
1812
1838
  ensureActive();
1813
1839
  getInternalCompilerSnapshot(snapshot);
1814
- return track(styleHandler(css, resolveStyleOptions(options)).then(clonePostcssResult));
1840
+ const resolved = resolveCssTransformOptions(options);
1841
+ const shouldFinalize = resolved.finalize ?? snapshot.target === "weapp";
1842
+ return track(styleHandler(css, resolved.styleOptions).then((result) => {
1843
+ const cloned = clonePostcssResult(result);
1844
+ finalizeResultRoot(cloned, snapshot, shouldFinalize);
1845
+ return cloned;
1846
+ }));
1815
1847
  }
1816
1848
  function transformCssRoot(root, snapshot, options) {
1817
1849
  ensureActive();
1818
1850
  getInternalCompilerSnapshot(snapshot);
1819
- return track(styleHandler.transformRoot(root, resolveStyleOptions(options)));
1851
+ const resolved = resolveCssTransformOptions(options);
1852
+ const shouldFinalize = resolved.finalize ?? snapshot.target === "weapp";
1853
+ return track(styleHandler.transformRoot(root, resolved.styleOptions).then((result) => {
1854
+ finalizeResultRoot(result, snapshot, shouldFinalize);
1855
+ return result;
1856
+ }));
1820
1857
  }
1821
1858
  function transformJavaScript(source, snapshot, options) {
1822
1859
  ensureActive();
@@ -1845,7 +1882,7 @@ function createCompilerTransforms({ ensureActive, track, userOptions }) {
1845
1882
  const DEFAULT_MAX_ROOTS = 128;
1846
1883
  function createCompiler(options = {}) {
1847
1884
  const { compiler: compilerOptions, ...userOptions } = options;
1848
- const rootStore = new CompilerRootStore(Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS)));
1885
+ const rootStore = new CompilerRootStore(Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS)), compilerOptions?.onRootEvicted);
1849
1886
  const activeTasks = /* @__PURE__ */ new Set();
1850
1887
  let lifecycle = "active";
1851
1888
  let disposePromise;
@@ -1920,6 +1957,7 @@ function createCompiler(options = {}) {
1920
1957
  entry.appliedInvalidation = invalidation;
1921
1958
  entry.latestSnapshot = snapshot;
1922
1959
  rootStore.attachDependencies(entry, dependencies);
1960
+ rootStore.attachSources(entry, sources);
1923
1961
  if (!engineReused && previousGenerator !== generator) previousGenerator?.dispose?.();
1924
1962
  const css = target === "tailwind" ? generated.rawCss : generated.css;
1925
1963
  const incrementalCss = target === "tailwind" ? generated.incrementalRawCss : generated.incrementalCss;
@@ -1963,6 +2001,16 @@ function createCompiler(options = {}) {
1963
2001
  ensureActive();
1964
2002
  return createRegisteredCompilerSnapshot(request);
1965
2003
  }
2004
+ function finalizeCss(css, options) {
2005
+ ensureActive();
2006
+ return finalizeMiniProgramCss(css, options);
2007
+ }
2008
+ function finalizeCssRoot(root, options) {
2009
+ ensureActive();
2010
+ const cloned = root.clone();
2011
+ finalizeMiniProgramCssRoot(cloned, options);
2012
+ return cloned;
2013
+ }
1966
2014
  function mergeSnapshots(snapshots) {
1967
2015
  ensureActive();
1968
2016
  return mergeRegisteredCompilerSnapshots(snapshots);
@@ -1990,6 +2038,8 @@ function createCompiler(options = {}) {
1990
2038
  return {
1991
2039
  createSnapshot,
1992
2040
  dispose,
2041
+ finalizeCss,
2042
+ finalizeCssRoot,
1993
2043
  generate,
1994
2044
  invalidate,
1995
2045
  mergeSnapshots,
@@ -1998,4 +2048,4 @@ function createCompiler(options = {}) {
1998
2048
  };
1999
2049
  }
2000
2050
  //#endregion
2001
- export { pluginName as a, toCustomAttributesEntities as c, ensureRuntimeClassSet as d, refreshTailwindRuntimeState as f, resolveStyleOptionsFromContext as i, collectRuntimeClassSet as l, DefaultCompilationSession as m, getCompilerContext as n, vitePluginName as o, normalizeFrameworkStylePlatform as p, normalizeStyleHandlerMajorVersion as r, shouldSkipJsTransform as s, createCompiler as t, createTailwindRuntimeReadyPromise as u };
2051
+ export { pluginName as a, toCustomAttributesEntities as c, collectRuntimeClassSet as d, createTailwindRuntimeReadyPromise as f, DefaultCompilationSession as g, normalizeFrameworkStylePlatform as h, resolveStyleOptionsFromContext as i, logTailwindcssTarget as l, refreshTailwindRuntimeState as m, getCompilerContext as n, vitePluginName as o, ensureRuntimeClassSet as p, normalizeStyleHandlerMajorVersion as r, shouldSkipJsTransform as s, createCompiler as t, logRuntimeTailwindcssVersion as u };
@@ -1,2 +1,2 @@
1
1
  export { createCompiler } from './compiler.js';
2
- export type { Compiler, CompilerCacheReuseState, CompilerGenerateRequest, CompilerGenerateResult, CompilerSnapshot, CompilerSnapshotRoot, CompilerSourcePattern, CompilerTarget, CompilerTemplateTransformOptions, CreateCompilerOptions, CreateCompilerSnapshotRequest, } from './types.js';
2
+ export type { Compiler, CompilerCacheReuseState, CompilerCssTransformOptions, CompilerGenerateRequest, CompilerGenerateResult, CompilerSnapshot, CompilerSnapshotRoot, CompilerSourcePattern, CompilerTarget, CompilerTemplateTransformOptions, CreateCompilerOptions, CreateCompilerSnapshotRequest, } from './types.js';
@@ -1,6 +1,6 @@
1
1
  import type { CompilerGenerationCacheEntry } from './generation-cache.js';
2
2
  import type { CompilerCompilationCacheEntry } from './generation-state.js';
3
- import type { CompilerSnapshot } from './types.js';
3
+ import type { CompilerSnapshot, CompilerSourcePattern } from './types.js';
4
4
  import type { TailwindV4ResolvedSource, WeappTailwindcssGenerator } from '../../generator/index.js';
5
5
  import { DefaultCompilationSession } from '../../compiler/session.js';
6
6
  export interface CompilerRootSession {
@@ -21,18 +21,21 @@ export interface CompilerRootSession {
21
21
  source?: TailwindV4ResolvedSource | undefined;
22
22
  sourceFingerprint?: string | undefined;
23
23
  sourceInput?: object | undefined;
24
+ sources: CompilerSourcePattern[];
24
25
  }
25
26
  export declare class CompilerRootStore {
26
27
  private readonly maxRoots;
28
+ private readonly onRootEvicted?;
27
29
  private readonly dependencyRoots;
28
30
  private readonly releasing;
29
31
  private readonly roots;
30
- constructor(maxRoots: number);
32
+ constructor(maxRoots: number, onRootEvicted?: ((id: string) => void) | undefined);
31
33
  get(id: string): CompilerRootSession;
32
34
  attachDependencies(entry: CompilerRootSession, dependencies: Iterable<string>): void;
35
+ attachSources(entry: CompilerRootSession, sources: Iterable<CompilerSourcePattern>): void;
33
36
  invalidate(ids: Iterable<string>): readonly string[];
34
37
  trim(): void;
35
- remove(id: string): Promise<void>;
38
+ remove(id: string, notifyEvicted?: boolean): Promise<void>;
36
39
  dispose(): Promise<void>;
37
40
  private detachDependencies;
38
41
  }
@@ -1,4 +1,4 @@
1
- import type { Document, IStyleHandlerOptions, Result as PostcssResult, Root } from '@weapp-tailwindcss/postcss';
1
+ import type { Document, FinalizeMiniProgramCssOptions, IStyleHandlerOptions, Result as PostcssResult, Root } from '@weapp-tailwindcss/postcss';
2
2
  import type { TailwindV4ResolvedSource, TailwindV4SourceOptions, WeappTailwindcssGenerateOptions, WeappTailwindcssGenerateResult } from '../../generator/index.js';
3
3
  import type { CreateJsHandlerOptions, ITemplateHandlerOptions, JsHandlerResult, UserDefinedOptions } from '../../types/index.js';
4
4
  export type CompilerTarget = 'tailwind' | 'weapp' | 'web';
@@ -49,20 +49,26 @@ export interface CreateCompilerSnapshotRequest {
49
49
  target?: CompilerTarget | undefined;
50
50
  }
51
51
  export type CompilerTemplateTransformOptions = Omit<ITemplateHandlerOptions, 'classSetMode' | 'runtimeSet'>;
52
+ export type CompilerCssTransformOptions = Partial<IStyleHandlerOptions> & {
53
+ finalize?: boolean | undefined;
54
+ };
52
55
  export type CreateCompilerOptions = UserDefinedOptions & {
53
56
  compiler?: {
54
57
  maxRoots?: number | undefined;
58
+ onRootEvicted?: ((id: string) => void) | undefined;
55
59
  } | undefined;
56
60
  };
57
61
  export interface Compiler {
58
62
  createSnapshot: (request: CreateCompilerSnapshotRequest) => CompilerSnapshot;
59
63
  dispose: () => Promise<void>;
64
+ finalizeCss: (css: string, options?: FinalizeMiniProgramCssOptions) => string;
65
+ finalizeCssRoot: (root: Root, options?: FinalizeMiniProgramCssOptions) => Root;
60
66
  generate: (request: CompilerGenerateRequest) => Promise<CompilerGenerateResult>;
61
67
  invalidate: (ids: Iterable<string>) => readonly string[];
62
68
  mergeSnapshots: (snapshots: Iterable<CompilerSnapshot>) => CompilerSnapshot;
63
69
  remove: (id: string) => Promise<void>;
64
- transformCss: (css: string, snapshot: CompilerSnapshot, options?: Partial<IStyleHandlerOptions>) => Promise<PostcssResult<Root | Document>>;
65
- transformCssRoot: (root: Root, snapshot: CompilerSnapshot, options?: Partial<IStyleHandlerOptions>) => Promise<PostcssResult<Root>>;
70
+ transformCss: (css: string, snapshot: CompilerSnapshot, options?: CompilerCssTransformOptions) => Promise<PostcssResult<Root | Document>>;
71
+ transformCssRoot: (root: Root, snapshot: CompilerSnapshot, options?: CompilerCssTransformOptions) => Promise<PostcssResult<Root>>;
66
72
  transformJavaScript: (source: string, snapshot: CompilerSnapshot, options?: CreateJsHandlerOptions) => Promise<JsHandlerResult>;
67
73
  transformTemplate: (source: string, snapshot: CompilerSnapshot, options?: CompilerTemplateTransformOptions) => Promise<string>;
68
74
  }
package/dist/core.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_compiler = require("./compiler-C93NfxSe.cjs");
2
+ const require_compiler = require("./compiler-B-m9VGqj.cjs");
3
+ let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
3
4
  let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
4
5
  //#region src/core.ts
5
6
  const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
@@ -140,3 +141,27 @@ function createContext(options = {}) {
140
141
  //#endregion
141
142
  exports.createCompiler = require_compiler.createCompiler;
142
143
  exports.createContext = createContext;
144
+ Object.defineProperty(exports, "finalizeMiniProgramCss", {
145
+ enumerable: true,
146
+ get: function() {
147
+ return _weapp_tailwindcss_postcss.finalizeMiniProgramCss;
148
+ }
149
+ });
150
+ Object.defineProperty(exports, "finalizeMiniProgramCssRoot", {
151
+ enumerable: true,
152
+ get: function() {
153
+ return _weapp_tailwindcss_postcss.finalizeMiniProgramCssRoot;
154
+ }
155
+ });
156
+ Object.defineProperty(exports, "postcss", {
157
+ enumerable: true,
158
+ get: function() {
159
+ return _weapp_tailwindcss_postcss.postcss;
160
+ }
161
+ });
162
+ Object.defineProperty(exports, "removeTailwindSourceDirectivesRoot", {
163
+ enumerable: true,
164
+ get: function() {
165
+ return _weapp_tailwindcss_postcss.removeTailwindSourceDirectivesRoot;
166
+ }
167
+ });
package/dist/core.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import type { CreateJsHandlerOptions, IStyleHandlerOptions, ITemplateHandlerOptions, UserDefinedOptions } from './types/index.js';
2
+ export type { Compiler, CompilerCacheReuseState, CompilerCssTransformOptions, CompilerGenerateRequest, CompilerGenerateResult, CompilerSnapshot, CompilerSnapshotRoot, CompilerSourcePattern, CompilerTarget, CompilerTemplateTransformOptions, CreateCompilerOptions, CreateCompilerSnapshotRequest, } from './core/compiler/index.js';
2
3
  export { createCompiler } from './core/compiler/index.js';
3
- export type { Compiler, CompilerCacheReuseState, CompilerGenerateRequest, CompilerGenerateResult, CompilerSnapshot, CompilerSnapshotRoot, CompilerSourcePattern, CompilerTarget, CompilerTemplateTransformOptions, CreateCompilerOptions, CreateCompilerSnapshotRequest, } from './core/compiler/index.js';
4
+ export { finalizeMiniProgramCss, finalizeMiniProgramCssRoot, postcss, removeTailwindSourceDirectivesRoot, } from '@weapp-tailwindcss/postcss';
5
+ export type { FinalizeMiniProgramCssOptions } from '@weapp-tailwindcss/postcss';
4
6
  type RuntimeJsTransformOptions = {
5
7
  runtimeSet?: Set<string>;
6
8
  } & CreateJsHandlerOptions;
package/dist/core.js CHANGED
@@ -1,4 +1,5 @@
1
- import { d as ensureRuntimeClassSet, n as getCompilerContext, s as shouldSkipJsTransform, t as createCompiler, u as createTailwindRuntimeReadyPromise } from "./compiler-qDa3phIv.js";
1
+ import { f as createTailwindRuntimeReadyPromise, n as getCompilerContext, p as ensureRuntimeClassSet, s as shouldSkipJsTransform, t as createCompiler } from "./compiler-BgMj2E5l.js";
2
+ import { finalizeMiniProgramCss, finalizeMiniProgramCssRoot, postcss, removeTailwindSourceDirectivesRoot } from "@weapp-tailwindcss/postcss";
2
3
  import { defuOverrideArray } from "@weapp-tailwindcss/shared";
3
4
  //#region src/core.ts
4
5
  const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
@@ -137,4 +138,4 @@ function createContext(options = {}) {
137
138
  };
138
139
  }
139
140
  //#endregion
140
- export { createCompiler, createContext };
141
+ export { createCompiler, createContext, finalizeMiniProgramCss, finalizeMiniProgramCssRoot, postcss, removeTailwindSourceDirectivesRoot };
@@ -207,10 +207,30 @@ function detectAppType(options = {}) {
207
207
  });
208
208
  }
209
209
  function resolveImplicitAppTypeFromViteRoot(root, options = {}) {
210
- return detectAppType({
211
- root,
210
+ const resolvedRoot = node_path.default.resolve(root);
211
+ if (options.searchUp !== false) return detectAppType({
212
+ root: resolvedRoot,
212
213
  searchUp: options.searchUp
213
214
  });
215
+ if (!(0, node_fs.existsSync)(resolvedRoot)) return;
216
+ const localProfile = detectAppType({
217
+ root: resolvedRoot,
218
+ searchUp: false
219
+ });
220
+ if (localProfile) return localProfile;
221
+ let current = resolvedRoot;
222
+ while (true) {
223
+ if ((0, node_fs.existsSync)(node_path.default.join(current, PACKAGE_JSON_FILE))) {
224
+ if (current === resolvedRoot) return;
225
+ return detectAppType({
226
+ root: current,
227
+ searchUp: false
228
+ });
229
+ }
230
+ const parent = node_path.default.dirname(current);
231
+ if (parent === current) return;
232
+ current = parent;
233
+ }
214
234
  }
215
235
  //#endregion
216
236
  exports.detectAppType = detectAppType;
package/dist/framework.js CHANGED
@@ -203,10 +203,30 @@ function detectAppType(options = {}) {
203
203
  });
204
204
  }
205
205
  function resolveImplicitAppTypeFromViteRoot(root, options = {}) {
206
- return detectAppType({
207
- root,
206
+ const resolvedRoot = path.resolve(root);
207
+ if (options.searchUp !== false) return detectAppType({
208
+ root: resolvedRoot,
208
209
  searchUp: options.searchUp
209
210
  });
211
+ if (!existsSync(resolvedRoot)) return;
212
+ const localProfile = detectAppType({
213
+ root: resolvedRoot,
214
+ searchUp: false
215
+ });
216
+ if (localProfile) return localProfile;
217
+ let current = resolvedRoot;
218
+ while (true) {
219
+ if (existsSync(path.join(current, PACKAGE_JSON_FILE))) {
220
+ if (current === resolvedRoot) return;
221
+ return detectAppType({
222
+ root: current,
223
+ searchUp: false
224
+ });
225
+ }
226
+ const parent = path.dirname(current);
227
+ if (parent === current) return;
228
+ current = parent;
229
+ }
210
230
  }
211
231
  //#endregion
212
232
  export { detectAppType, detectAppTypeFromEnv, detectAppTypeFromPackageJson, isMpxPackage, isRunningInHBuilderX, isTaroPackage, isUniAppPackage, isUniAppVitePackage, isUniAppXManifest, isUniAppXPackage, isWeappVitePackage, resolveImplicitAppTypeFromViteRoot, resolveMpxPlatform, resolvePlatform, resolveTaroPlatform, resolveUniAppXPlatform, resolveUniPlatform, resolveUniPlatformsFromEnv, resolveUniUtsPlatform };