weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.7

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 (171) hide show
  1. package/README.md +4 -5
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  4. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  5. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  6. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  7. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  8. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  9. package/dist/bundlers/shared/generator-css/directives.d.ts +11 -0
  10. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  11. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  12. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  13. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  14. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  15. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  16. package/dist/bundlers/shared/generator-css.d.ts +12 -22
  17. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  18. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  19. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  20. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  21. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  22. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  23. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  24. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  25. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  26. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  27. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  28. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  29. package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
  30. package/dist/bundlers/vite/index.d.ts +1 -1
  31. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  32. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  33. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  34. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  35. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  37. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
  38. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +0 -1
  39. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +1 -1
  40. package/dist/cache-DPN5yKSX.js +497 -0
  41. package/dist/cache-nq0_XJoS.mjs +429 -0
  42. package/dist/cli/context.d.ts +0 -3
  43. package/dist/cli/helpers.d.ts +1 -2
  44. package/dist/cli/mount-options.d.ts +2 -0
  45. package/dist/cli/types.d.ts +0 -2
  46. package/dist/cli.js +108 -598
  47. package/dist/cli.mjs +119 -608
  48. package/dist/constants.d.ts +1 -2
  49. package/dist/context/tailwindcss.d.ts +1 -1
  50. package/dist/core.js +13 -20
  51. package/dist/core.mjs +8 -14
  52. package/dist/css-macro/postcss.js +1 -1
  53. package/dist/css-macro/postcss.mjs +1 -1
  54. package/dist/css-macro.d.ts +1 -0
  55. package/dist/css-macro.js +2 -2
  56. package/dist/css-macro.mjs +2 -2
  57. package/dist/defaults.d.ts +15 -1
  58. package/dist/defaults.js +33 -14
  59. package/dist/defaults.mjs +30 -15
  60. package/dist/generator/index.d.ts +1 -1
  61. package/dist/generator/options.d.ts +3 -4
  62. package/dist/{generator-Y-Ikv4Fu.mjs → generator-CzfdCZyd.mjs} +277 -23
  63. package/dist/{generator-mmhXzZnv.js → generator-TOp4uz7c.js} +281 -27
  64. package/dist/{generator-css-Bwy_Uz89.mjs → generator-css-B938WI9a.mjs} +694 -506
  65. package/dist/{generator-css-CRLrHW4F.js → generator-css-Dnpl-IY2.js} +699 -505
  66. package/dist/generator.js +1 -1
  67. package/dist/generator.mjs +1 -1
  68. package/dist/gulp.js +29 -28
  69. package/dist/gulp.mjs +25 -24
  70. package/dist/index.d.ts +1 -1
  71. package/dist/index.js +6 -6
  72. package/dist/index.mjs +5 -5
  73. package/dist/js/index.d.ts +1 -0
  74. package/dist/js/literal-transform.d.ts +2 -0
  75. package/dist/logger-BRy6XPQ2.js +1 -0
  76. package/dist/logger-Bub1jggA.mjs +2 -0
  77. package/dist/postcss/config-directive.d.ts +1 -0
  78. package/dist/postcss/context.d.ts +9 -0
  79. package/dist/postcss/source-files.d.ts +8 -0
  80. package/dist/postcss/tailwind-version.d.ts +3 -0
  81. package/dist/postcss-BtAP6sQO.mjs +288 -0
  82. package/dist/postcss-WsXlC7A-.js +298 -0
  83. package/dist/postcss.d.ts +2 -2
  84. package/dist/postcss.js +3 -276
  85. package/dist/postcss.mjs +1 -269
  86. package/dist/{recorder-GdTJ3QqX.js → precheck-Dka94ArV.js} +141 -283
  87. package/dist/{recorder-XdFvVASS.mjs → precheck-DlrmwCc-.mjs} +106 -247
  88. package/dist/presets.js +6 -4
  89. package/dist/presets.mjs +4 -2
  90. package/dist/reset.d.ts +1 -0
  91. package/dist/{css-imports-BbrbluP9.js → run-tasks-B50A3pxt.js} +6 -55
  92. package/dist/{css-imports-CSdPq_Sc.mjs → run-tasks-DdNi-hkk.mjs} +5 -42
  93. package/dist/runtime-patch-pGdCqAEu.mjs +71 -0
  94. package/dist/runtime-patch-qwuisukL.js +85 -0
  95. package/dist/tailwindcss/miniprogram.d.ts +5 -1
  96. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  97. package/dist/tailwindcss/patcher.d.ts +1 -2
  98. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  99. package/dist/tailwindcss/runtime.d.ts +2 -3
  100. package/dist/tailwindcss/targets.d.ts +1 -5
  101. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  102. package/dist/tailwindcss/v4/patcher.d.ts +2 -1
  103. package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
  104. package/dist/tailwindcss/version.d.ts +4 -0
  105. package/dist/{logger-BoVx1Dbt.mjs → tailwindcss-BIJ185GB.mjs} +25 -434
  106. package/dist/{logger-BZ45DZJT.js → tailwindcss-T1U5T-iF.js} +30 -468
  107. package/dist/typedoc.export.d.ts +0 -2
  108. package/dist/types/index.d.ts +2 -9
  109. package/dist/types/shared.d.ts +3 -0
  110. package/dist/types/user-defined-options/general.d.ts +0 -2
  111. package/dist/types/user-defined-options/important.d.ts +3 -3
  112. package/dist/uni-app-x/vite.d.ts +1 -1
  113. package/dist/utils/disabled.d.ts +2 -3
  114. package/dist/{vite-BDywuCjn.mjs → vite-BXChkciE.mjs} +669 -481
  115. package/dist/{vite-DgRh_GXn.js → vite-D0CoRblu.js} +707 -519
  116. package/dist/vite.d.ts +1 -2
  117. package/dist/vite.js +3 -4
  118. package/dist/vite.mjs +2 -2
  119. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  120. package/dist/{webpack-CiHqVZTg.mjs → webpack-BNdGm9KL.mjs} +224 -38
  121. package/dist/{webpack-CAJR4hhP.js → webpack-D-sUCY0u.js} +250 -69
  122. package/dist/webpack.js +1 -1
  123. package/dist/webpack.mjs +1 -1
  124. package/package.json +23 -35
  125. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  126. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  127. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  128. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  129. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  130. package/dist/cli/config.d.ts +0 -5
  131. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  132. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  133. package/dist/cli/patch-options.d.ts +0 -6
  134. package/dist/cli/tokens.d.ts +0 -4
  135. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  136. package/dist/cli/workspace/patch-package.d.ts +0 -3
  137. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  138. package/dist/cli/workspace/types.d.ts +0 -11
  139. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  140. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  141. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  142. package/dist/cli/workspace.d.ts +0 -2
  143. package/dist/experimental/index.d.ts +0 -2
  144. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  145. package/dist/experimental/oxc/index.d.ts +0 -2
  146. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  147. package/dist/experimental/shared/cache.d.ts +0 -3
  148. package/dist/experimental/shared/transform.d.ts +0 -3
  149. package/dist/experimental/shared.d.ts +0 -8
  150. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  151. package/dist/experimental/swc/index.d.ts +0 -2
  152. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  153. package/dist/js/syntax.d.ts +0 -10
  154. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  155. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  156. package/dist/patcher-options-6gJN2EXy.js +0 -115
  157. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  158. package/dist/tailwindcss/recorder.d.ts +0 -13
  159. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  160. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  161. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  162. package/dist/tailwindcss/targets/types.d.ts +0 -35
  163. package/dist/types/disabled-options.d.ts +0 -4
  164. package/dist/webpack4.d.ts +0 -4
  165. package/dist/webpack4.js +0 -387
  166. package/dist/webpack4.mjs +0 -379
  167. package/scripts/postinstall.mjs +0 -59
  168. /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
  169. /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
  170. /package/dist/{utils-7DUGTFED.mjs → utils-BJjKRQgf.mjs} +0 -0
  171. /package/dist/{utils-DmC9_In3.js → utils-VZvGusYs.js} +0 -0
@@ -1,22 +1,24 @@
1
1
  const require_chunk = require("./chunk-8l464Juk.js");
2
- const require_generator = require("./generator-mmhXzZnv.js");
3
- const require_patcher_options = require("./patcher-options-6gJN2EXy.js");
4
- const require_recorder = require("./recorder-GdTJ3QqX.js");
5
- const require_utils = require("./utils-DmC9_In3.js");
6
- const require_logger = require("./logger-BZ45DZJT.js");
7
- const require_generator_css = require("./generator-css-CRLrHW4F.js");
8
- const require_css_imports = require("./css-imports-BbrbluP9.js");
2
+ const require_cache = require("./cache-DPN5yKSX.js");
3
+ const require_runtime_patch = require("./runtime-patch-qwuisukL.js");
4
+ const require_generator = require("./generator-TOp4uz7c.js");
5
+ const require_precheck = require("./precheck-Dka94ArV.js");
6
+ const require_utils = require("./utils-VZvGusYs.js");
7
+ const require_tailwindcss = require("./tailwindcss-T1U5T-iF.js");
8
+ const require_generator_css = require("./generator-css-Dnpl-IY2.js");
9
+ const require_run_tasks = require("./run-tasks-B50A3pxt.js");
10
+ require("./logger-BRy6XPQ2.js");
9
11
  let node_path = require("node:path");
10
12
  node_path = require_chunk.__toESM(node_path);
11
13
  let node_process = require("node:process");
12
14
  node_process = require_chunk.__toESM(node_process);
15
+ let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
16
+ let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
13
17
  let tailwindcss_patch = require("tailwindcss-patch");
14
- let node_buffer = require("node:buffer");
15
18
  let node_fs = require("node:fs");
16
19
  node_fs = require_chunk.__toESM(node_fs);
20
+ let node_buffer = require("node:buffer");
17
21
  let node_fs_promises = require("node:fs/promises");
18
- let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
19
- let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
20
22
  let magic_string = require("magic-string");
21
23
  magic_string = require_chunk.__toESM(magic_string);
22
24
  let _weapp_tailwindcss_shared_extractors = require("@weapp-tailwindcss/shared/extractors");
@@ -25,11 +27,11 @@ let fast_glob = require("fast-glob");
25
27
  fast_glob = require_chunk.__toESM(fast_glob);
26
28
  let _weapp_tailwindcss_postcss_html_transform = require("@weapp-tailwindcss/postcss/html-transform");
27
29
  _weapp_tailwindcss_postcss_html_transform = require_chunk.__toESM(_weapp_tailwindcss_postcss_html_transform);
28
- let postcss_load_config = require("postcss-load-config");
29
- postcss_load_config = require_chunk.__toESM(postcss_load_config);
30
30
  let _vue_compiler_dom = require("@vue/compiler-dom");
31
31
  let _vue_compiler_sfc = require("@vue/compiler-sfc");
32
32
  let comment_json = require("comment-json");
33
+ let postcss_load_config = require("postcss-load-config");
34
+ postcss_load_config = require_chunk.__toESM(postcss_load_config);
33
35
  //#region src/uni-app-x/component-local-style.ts
34
36
  const EXPRESSION_WRAPPER_PREFIX = "(\n";
35
37
  const EXPRESSION_WRAPPER_SUFFIX = "\n)";
@@ -60,7 +62,7 @@ function createAlias(fileId, utility, index) {
60
62
  }
61
63
  function isRuntimeCandidate(candidate, runtimeSet) {
62
64
  if (!runtimeSet || runtimeSet.size === 0) return false;
63
- return runtimeSet.has(candidate) || runtimeSet.has(require_recorder.replaceWxml(candidate));
65
+ return runtimeSet.has(candidate) || runtimeSet.has(require_precheck.replaceWxml(candidate));
64
66
  }
65
67
  function shouldEnableComponentLocalStyle(id) {
66
68
  return COMPONENT_RE.test(id);
@@ -69,8 +71,8 @@ var UniAppXComponentLocalStyleCollector = class {
69
71
  constructor(fileId, runtimeSet) {
70
72
  this.fileId = fileId;
71
73
  this.runtimeSet = runtimeSet;
72
- this.aliasByUtility = /* @__PURE__ */ new Map();
73
- this.aliasByLookup = /* @__PURE__ */ new Map();
74
+ require_precheck._defineProperty(this, "aliasByUtility", /* @__PURE__ */ new Map());
75
+ require_precheck._defineProperty(this, "aliasByLookup", /* @__PURE__ */ new Map());
74
76
  }
75
77
  ensureAlias(utility) {
76
78
  const cached = this.aliasByUtility.get(utility);
@@ -78,7 +80,7 @@ var UniAppXComponentLocalStyleCollector = class {
78
80
  const alias = createAlias(this.fileId, utility, this.aliasByUtility.size);
79
81
  this.aliasByUtility.set(utility, alias);
80
82
  this.aliasByLookup.set(utility, alias);
81
- this.aliasByLookup.set(require_recorder.replaceWxml(utility), alias);
83
+ this.aliasByLookup.set(require_precheck.replaceWxml(utility), alias);
82
84
  return alias;
83
85
  }
84
86
  rewriteLiteral(literal, shouldInclude) {
@@ -97,14 +99,14 @@ var UniAppXComponentLocalStyleCollector = class {
97
99
  collectRuntimeClasses(rawSource, options = {}) {
98
100
  const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
99
101
  try {
100
- const analysis = require_recorder.analyzeSource(require_recorder.babelParse(wrapped, {
102
+ const analysis = require_precheck.analyzeSource(require_precheck.babelParse(wrapped, {
101
103
  plugins: ["typescript"],
102
104
  sourceType: options.wrapExpression ? "module" : "unambiguous"
103
105
  }), {}, void 0, false);
104
106
  for (const path of analysis.targetPaths) {
105
107
  const { literal, allowDoubleQuotes } = extractLiteralValue(path);
106
108
  const candidates = (0, _weapp_tailwindcss_shared_extractors.splitCode)(literal, allowDoubleQuotes);
107
- const classContext = options.wrapExpression || require_recorder.isClassContextLiteralPath(path);
109
+ const classContext = options.wrapExpression || require_precheck.isClassContextLiteralPath(path);
108
110
  for (const candidate of candidates) {
109
111
  if (!candidate || !classContext && !isRuntimeCandidate(candidate, this.runtimeSet)) continue;
110
112
  if (isRuntimeCandidate(candidate, this.runtimeSet)) this.ensureAlias(candidate);
@@ -116,12 +118,12 @@ var UniAppXComponentLocalStyleCollector = class {
116
118
  if (this.aliasByLookup.size === 0) return rawSource;
117
119
  const wrapped = options.wrapExpression ? `${EXPRESSION_WRAPPER_PREFIX}${rawSource}${EXPRESSION_WRAPPER_SUFFIX}` : rawSource;
118
120
  try {
119
- const analysis = require_recorder.analyzeSource(require_recorder.babelParse(wrapped, {
121
+ const analysis = require_precheck.analyzeSource(require_precheck.babelParse(wrapped, {
120
122
  plugins: ["typescript"],
121
123
  sourceType: options.wrapExpression ? "module" : "unambiguous"
122
124
  }), {}, void 0, false);
123
125
  if (analysis.targetPaths.length === 0) return rawSource;
124
- const updater = new require_recorder.JsTokenUpdater();
126
+ const updater = new require_precheck.JsTokenUpdater();
125
127
  for (const path of analysis.targetPaths) {
126
128
  const { literal, allowDoubleQuotes, offset } = extractLiteralValue(path);
127
129
  const candidates = (0, _weapp_tailwindcss_shared_extractors.splitCode)(literal, allowDoubleQuotes);
@@ -184,7 +186,7 @@ function updateStaticAttribute(ms, prop, content = prop.value?.content) {
184
186
  if (!prop.value) return;
185
187
  const start = prop.value.loc.start.offset + 1;
186
188
  const end = prop.value.loc.end.offset - 1;
187
- if (start < end) ms.update(start, end, require_recorder.replaceWxml(content ?? ""));
189
+ if (start < end) ms.update(start, end, require_precheck.replaceWxml(content ?? ""));
188
190
  }
189
191
  function updateStaticAttributeWithLocalStyle(ms, prop, collector, content = prop.value?.content) {
190
192
  if (!prop.value) return;
@@ -198,7 +200,7 @@ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
198
200
  const start = prop.exp.loc.start.offset;
199
201
  const end = prop.exp.loc.end.offset;
200
202
  if (start >= end) return;
201
- const generated = require_recorder.generateCode(expression, {
203
+ const generated = require_precheck.generateCode(expression, {
202
204
  jsHandler,
203
205
  runtimeSet,
204
206
  wrapExpression: true
@@ -212,7 +214,7 @@ function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector,
212
214
  const end = prop.exp.loc.end.offset;
213
215
  if (start >= end) return;
214
216
  collector.collectRuntimeClasses(expression, { wrapExpression: true });
215
- const generated = require_recorder.generateCode(expression, {
217
+ const generated = require_precheck.generateCode(expression, {
216
218
  jsHandler,
217
219
  runtimeSet,
218
220
  wrapExpression: true
@@ -234,7 +236,7 @@ const UVUE_NVUE_RE$1 = /\.(?:uvue|nvue)(?:\?.*)?$/;
234
236
  function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
235
237
  if (!UVUE_NVUE_RE$1.test(id)) return;
236
238
  const { customAttributesEntities, disabledDefaultTemplateHandler = false } = options;
237
- const matchCustomAttribute = require_recorder.createAttributeMatcher(customAttributesEntities);
239
+ const matchCustomAttribute = require_precheck.createAttributeMatcher(customAttributesEntities);
238
240
  const ms = new magic_string.default(code);
239
241
  const { descriptor, errors } = (0, _vue_compiler_sfc.parse)(code);
240
242
  const localStyleCollector = options.enableComponentLocalStyle && shouldEnableComponentLocalStyle(id) ? new UniAppXComponentLocalStyleCollector(id, runtimeSet) : void 0;
@@ -371,11 +373,11 @@ function resolveUniAppXCssTarget(id) {
371
373
  return UVUE_NVUE_RE.test((0, _weapp_tailwindcss_shared.cleanUrl)(id)) ? "uvue" : void 0;
372
374
  }
373
375
  function resolveUniAppXJsTransformEnabled$1(uniAppX) {
374
- return uniAppX === void 0 ? true : require_logger.isUniAppXEnabled(uniAppX);
376
+ return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
375
377
  }
376
378
  function createUniAppXPlugins(options) {
377
379
  const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, jsHandler, ensureRuntimeClassSet, getResolvedConfig, uniAppX } = options;
378
- const resolvedUniAppXOptions = require_logger.resolveUniAppXOptions(uniAppX);
380
+ const resolvedUniAppXOptions = require_tailwindcss.resolveUniAppXOptions(uniAppX);
379
381
  const isIosPlatform = providedIosPlatform ?? require_utils.resolveUniUtsPlatform().isAppIos;
380
382
  const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
381
383
  let componentLocalStyleEnabled;
@@ -427,14 +429,14 @@ function createUniAppXPlugins(options) {
427
429
  const cssPlugins = [{
428
430
  name: "weapp-tailwindcss:uni-app-x:css",
429
431
  async transform(code, id) {
430
- await runtimeState.patchPromise;
432
+ await runtimeState.readyPromise;
431
433
  return transformStyle(code, id);
432
434
  }
433
435
  }, {
434
436
  name: "weapp-tailwindcss:uni-app-x:css:pre",
435
437
  enforce: "pre",
436
438
  async transform(code, id) {
437
- await runtimeState.patchPromise;
439
+ await runtimeState.readyPromise;
438
440
  const { query } = parseVueRequest(id);
439
441
  const lang = query.lang;
440
442
  if (isIosPlatform && isPreprocessorRequest(id, lang)) return;
@@ -480,7 +482,7 @@ function createUniAppXPlugins(options) {
480
482
  function createUniAppXAssetTask(file, originalSource, outDir, options) {
481
483
  return async () => {
482
484
  const { cache, hashKey, createHandlerOptions, debug, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
483
- const absoluteFile = require_css_imports.toAbsoluteOutputPath(file, outDir);
485
+ const absoluteFile = require_run_tasks.toAbsoluteOutputPath(file, outDir);
484
486
  const rawSource = originalSource.source.toString();
485
487
  await require_generator_css.processCachedTask({
486
488
  cache,
@@ -512,6 +514,22 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
512
514
  }
513
515
  //#endregion
514
516
  //#region src/bundlers/vite/css-finalizer.ts
517
+ function isAddWatchFileInvalidRollupPhaseError$1(error) {
518
+ const candidate = error;
519
+ return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
520
+ }
521
+ function registerGeneratorDependencies$1(ctx, dependencies) {
522
+ if (typeof ctx.addWatchFile !== "function") return;
523
+ for (const dependency of dependencies ?? []) try {
524
+ ctx.addWatchFile(dependency);
525
+ } catch (error) {
526
+ if (isAddWatchFileInvalidRollupPhaseError$1(error)) {
527
+ _weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
528
+ continue;
529
+ }
530
+ throw error;
531
+ }
532
+ }
515
533
  function createCssHandlerOptions(opts, majorVersion, file) {
516
534
  return {
517
535
  isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
@@ -524,7 +542,7 @@ function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
524
542
  return processed && shouldFinalizeProcessedCssAsset(opts, file);
525
543
  }
526
544
  function shouldFinalizeProcessedCssAsset(opts, file) {
527
- return require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator).mode !== "off" && opts.mainCssChunkMatcher(file, opts.appType);
545
+ return opts.mainCssChunkMatcher(file, opts.appType);
528
546
  }
529
547
  function createViteCssFinalizerOutputPlugin(context) {
530
548
  return {
@@ -536,7 +554,7 @@ function createViteCssFinalizerOutputPlugin(context) {
536
554
  if (getResolvedConfig()?.command !== "build") return;
537
555
  const entries = Object.entries(bundle).filter(([, output]) => output.type === "asset" && opts.cssMatcher(output.fileName) && (!isCssAssetProcessed(output, output.fileName) || shouldFinalizeProcessedCssAsset(opts, output.fileName)));
538
556
  if (entries.length === 0) return;
539
- await runtimeState.patchPromise;
557
+ await runtimeState.readyPromise;
540
558
  await waitForSourceCandidateSyncs?.();
541
559
  const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
542
560
  const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
@@ -563,6 +581,7 @@ function createViteCssFinalizerOutputPlugin(context) {
563
581
  }) : void 0;
564
582
  const nextCss = generated?.css ?? (await opts.styleHandler(rawSource, cssHandlerOptions)).css;
565
583
  if (generated) {
584
+ registerGeneratorDependencies$1(this, generated.dependencies);
566
585
  debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
567
586
  recordCssAssetResult?.(file, nextCss);
568
587
  if (cssHandlerOptions.isMainChunk) rememberMainCssSource?.(file, rawSource);
@@ -593,11 +612,11 @@ function isJavaScriptEntry(entry) {
593
612
  }
594
613
  function createBundleModuleGraphOptions(outputDir, entries) {
595
614
  const normalizedEntries = /* @__PURE__ */ new Map();
596
- for (const [id, entry] of entries) normalizedEntries.set(require_css_imports.normalizeOutputPathKey(id), entry);
597
- const getEntry = (id) => entries.get(id) ?? normalizedEntries.get(require_css_imports.normalizeOutputPathKey(id));
615
+ for (const [id, entry] of entries) normalizedEntries.set(require_run_tasks.normalizeOutputPathKey(id), entry);
616
+ const getEntry = (id) => entries.get(id) ?? normalizedEntries.get(require_run_tasks.normalizeOutputPathKey(id));
598
617
  return {
599
618
  resolve(specifier, importer) {
600
- return require_css_imports.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => Boolean(getEntry(candidate)));
619
+ return require_run_tasks.resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => Boolean(getEntry(candidate)));
601
620
  },
602
621
  load(id) {
603
622
  const entry = getEntry(id);
@@ -612,9 +631,9 @@ function createBundleModuleGraphOptions(outputDir, entries) {
612
631
  function applyLinkedResults(linked, entries, onLinkedUpdate, onApplied) {
613
632
  if (!linked) return;
614
633
  const normalizedEntries = /* @__PURE__ */ new Map();
615
- for (const [entryId, entry] of entries) normalizedEntries.set(require_css_imports.normalizeOutputPathKey(entryId), entry);
634
+ for (const [entryId, entry] of entries) normalizedEntries.set(require_run_tasks.normalizeOutputPathKey(entryId), entry);
616
635
  for (const [id, { code }] of Object.entries(linked)) {
617
- const entry = entries.get(id) ?? normalizedEntries.get(require_css_imports.normalizeOutputPathKey(id));
636
+ const entry = entries.get(id) ?? normalizedEntries.get(require_run_tasks.normalizeOutputPathKey(id));
618
637
  if (!entry) continue;
619
638
  const previous = readOutputEntry(entry);
620
639
  if (previous == null || previous === code) continue;
@@ -654,14 +673,14 @@ function createHtmlRuntimeAffectingSignature(source) {
654
673
  }
655
674
  function createJsRuntimeAffectingSignature(source) {
656
675
  try {
657
- const ast = require_recorder.babelParse(source, {
676
+ const ast = require_precheck.babelParse(source, {
658
677
  cache: true,
659
678
  cacheKey: "vite-runtime-affecting:unambiguous",
660
679
  plugins: ["jsx", "typescript"],
661
680
  sourceType: "unambiguous"
662
681
  });
663
682
  const parts = [];
664
- require_recorder.traverse(ast, {
683
+ require_precheck.traverse(ast, {
665
684
  noScope: true,
666
685
  StringLiteral(path) {
667
686
  parts.push(`s:${path.node.value}`);
@@ -735,7 +754,7 @@ function collectJsEntries(fileName, output, outDir, store) {
735
754
  output
736
755
  };
737
756
  if (!isJavaScriptEntry(entry)) return;
738
- const absolute = require_css_imports.toAbsoluteOutputPath(fileName, outDir);
757
+ const absolute = require_run_tasks.toAbsoluteOutputPath(fileName, outDir);
739
758
  store.set(absolute, entry);
740
759
  }
741
760
  function markProcessFile(type, file, processFiles) {
@@ -826,7 +845,160 @@ function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
826
845
  state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
827
846
  }
828
847
  //#endregion
829
- //#region src/bundlers/vite/generate-bundle.ts
848
+ //#region src/bundlers/vite/generate-bundle/candidates.ts
849
+ const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
850
+ const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
851
+ function isArbitraryValueCandidate(candidate) {
852
+ return candidate.includes("[") && candidate.includes("]");
853
+ }
854
+ function collectUnescapedDynamicCandidates(source) {
855
+ const matches = /* @__PURE__ */ new Set();
856
+ for (const expression of source.match(MUSTACHE_EXPRESSION_RE) ?? []) {
857
+ QUOTED_LITERAL_RE.lastIndex = 0;
858
+ let quoted = QUOTED_LITERAL_RE.exec(expression);
859
+ while (quoted !== null) {
860
+ const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
861
+ for (const candidate of (0, _weapp_tailwindcss_shared_extractors.splitCode)(literal, true)) {
862
+ const normalized = candidate.trim();
863
+ if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
864
+ matches.add(normalized);
865
+ }
866
+ quoted = QUOTED_LITERAL_RE.exec(expression);
867
+ }
868
+ }
869
+ return [...matches];
870
+ }
871
+ function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
872
+ if (candidates.has("container")) return candidates;
873
+ if (!sourceCandidates.has("container")) return candidates;
874
+ return new Set([...candidates, "container"]);
875
+ }
876
+ //#endregion
877
+ //#region src/bundlers/vite/generate-bundle/css-handler-options.ts
878
+ function createCssHandlerOptionsCache(options) {
879
+ const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
880
+ const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
881
+ const getCssHandlerOptions = (file) => {
882
+ const majorVersion = options.getMajorVersion();
883
+ const isMainChunk = options.mainCssChunkMatcher(file, options.appType);
884
+ const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
885
+ const cached = cssHandlerOptionsCache.get(cacheKey);
886
+ if (cached) return cached;
887
+ const created = {
888
+ isMainChunk,
889
+ postcssOptions: { options: { from: file } },
890
+ majorVersion
891
+ };
892
+ cssHandlerOptionsCache.set(cacheKey, created);
893
+ return created;
894
+ };
895
+ const getCssUserHandlerOptions = (file) => {
896
+ const cacheKey = `${options.getMajorVersion() ?? "unknown"}:${file}`;
897
+ const cached = cssUserHandlerOptionsCache.get(cacheKey);
898
+ if (cached) return cached;
899
+ const created = {
900
+ ...getCssHandlerOptions(file),
901
+ isMainChunk: false
902
+ };
903
+ cssUserHandlerOptionsCache.set(cacheKey, created);
904
+ return created;
905
+ };
906
+ return {
907
+ getCssHandlerOptions,
908
+ getCssUserHandlerOptions
909
+ };
910
+ }
911
+ //#endregion
912
+ //#region src/bundlers/vite/generate-bundle/css-share-scope.ts
913
+ const CSS_URL_FUNCTION_RE = /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/gi;
914
+ const CSS_PATH_INDEPENDENT_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/|#)/i;
915
+ const CSS_IMPORT_RE = /@import\b/i;
916
+ function isPathIndependentCssUrl(value) {
917
+ const normalized = value.trim();
918
+ return normalized.length > 0 && CSS_PATH_INDEPENDENT_URL_RE.test(normalized);
919
+ }
920
+ function hasPathDependentCssUrl(rawSource) {
921
+ CSS_URL_FUNCTION_RE.lastIndex = 0;
922
+ let match = CSS_URL_FUNCTION_RE.exec(rawSource);
923
+ while (match !== null) {
924
+ if (!isPathIndependentCssUrl(match[1] ?? match[2] ?? match[3] ?? "")) return true;
925
+ match = CSS_URL_FUNCTION_RE.exec(rawSource);
926
+ }
927
+ return false;
928
+ }
929
+ function createCssTransformShareScope(file, rawSource) {
930
+ if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${require_run_tasks.normalizeOutputPathKey(node_path.default.dirname(file))}`;
931
+ return "global";
932
+ }
933
+ function createCssTransformShareScopeKey(opts, file, rawSource) {
934
+ if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${require_run_tasks.normalizeOutputPathKey(file)}`;
935
+ return createCssTransformShareScope(file, rawSource);
936
+ }
937
+ function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
938
+ return `${runtimeSignature}:${generatorCandidateSignature}`;
939
+ }
940
+ //#endregion
941
+ //#region src/bundlers/vite/generate-bundle/dirty-state.ts
942
+ function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
943
+ const currentFileSet = new Set(currentBundleFiles);
944
+ for (const file of previousBundleFiles) if (!currentFileSet.has(file)) return true;
945
+ return false;
946
+ }
947
+ //#endregion
948
+ //#region src/bundlers/vite/generate-bundle/js-entries.ts
949
+ function createJsEntryResolver(jsEntries) {
950
+ const normalizedJsEntries = /* @__PURE__ */ new Map();
951
+ for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_run_tasks.normalizeOutputPathKey(id), entry);
952
+ return (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_run_tasks.normalizeOutputPathKey(id));
953
+ }
954
+ //#endregion
955
+ //#region src/bundlers/vite/generate-bundle/js-handler-options.ts
956
+ function resolveUniAppXJsTransformEnabled(uniAppX) {
957
+ return uniAppX === void 0 ? true : require_tailwindcss.isUniAppXEnabled(uniAppX);
958
+ }
959
+ function createJsHandlerOptionsFactory(options) {
960
+ return (absoluteFilename, extra) => ({
961
+ ...extra,
962
+ filename: absoluteFilename,
963
+ tailwindcssMajorVersion: options.getMajorVersion(),
964
+ moduleGraph: options.moduleGraph,
965
+ babelParserOptions: {
966
+ ...extra?.babelParserOptions ?? {},
967
+ sourceFilename: absoluteFilename
968
+ }
969
+ });
970
+ }
971
+ //#endregion
972
+ //#region src/bundlers/vite/generate-bundle/js-linking.ts
973
+ function createLinkedUpdateHelpers(options) {
974
+ const pendingLinkedUpdates = [];
975
+ const handleLinkedUpdate = (fileName, previous, next) => {
976
+ options.onUpdate(fileName, previous, next);
977
+ options.debug("js linked handle: %s", fileName);
978
+ };
979
+ const scheduleLinkedApply = (entry, code) => {
980
+ pendingLinkedUpdates.push(() => {
981
+ if (entry.output.type === "chunk") entry.output.code = code;
982
+ else entry.output.source = code;
983
+ });
984
+ };
985
+ const applyLinkedUpdates = (linked) => {
986
+ applyLinkedResults(linked, options.jsEntries, handleLinkedUpdate, scheduleLinkedApply);
987
+ };
988
+ return {
989
+ applyLinkedUpdates,
990
+ pendingLinkedUpdates
991
+ };
992
+ }
993
+ function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
994
+ if (!linked || !linkedSet) return;
995
+ for (const id of Object.keys(linked)) {
996
+ const linkedEntry = getJsEntry(id);
997
+ if (linkedEntry) linkedSet.add(linkedEntry.fileName);
998
+ }
999
+ }
1000
+ //#endregion
1001
+ //#region src/bundlers/vite/generate-bundle/metrics.ts
830
1002
  function formatDebugFileList(files, limit = 8) {
831
1003
  if (files.size === 0) return "-";
832
1004
  const sorted = [...files].sort();
@@ -852,9 +1024,6 @@ function createEmptyMetrics() {
852
1024
  function measureElapsed(start) {
853
1025
  return performance.now() - start;
854
1026
  }
855
- function resolveUniAppXJsTransformEnabled(uniAppX) {
856
- return uniAppX === void 0 ? true : require_logger.isUniAppXEnabled(uniAppX);
857
- }
858
1027
  function formatCacheHitRate(metric) {
859
1028
  if (metric.total === 0) return "0.00%";
860
1029
  return `${(metric.cacheHits / metric.total * 100).toFixed(2)}%`;
@@ -862,6 +1031,50 @@ function formatCacheHitRate(metric) {
862
1031
  function formatMs(value) {
863
1032
  return value.toFixed(2);
864
1033
  }
1034
+ //#endregion
1035
+ //#region src/bundlers/vite/generate-bundle/process-plan.ts
1036
+ function logBundleProcessPlan(options) {
1037
+ const { debug, snapshot, useIncrementalMode, iteration } = options;
1038
+ const { processFiles } = snapshot;
1039
+ if (useIncrementalMode) {
1040
+ debug("dirty iteration=%d html=%d[%s] js=%d[%s] css=%d[%s] other=%d[%s]", iteration, snapshot.changedByType.html.size, formatDebugFileList(snapshot.changedByType.html), snapshot.changedByType.js.size, formatDebugFileList(snapshot.changedByType.js), snapshot.changedByType.css.size, formatDebugFileList(snapshot.changedByType.css), snapshot.changedByType.other.size, formatDebugFileList(snapshot.changedByType.other));
1041
+ debug("process iteration=%d html=%d[%s] js=%d[%s] css=%d[%s]", iteration, processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
1042
+ return;
1043
+ }
1044
+ debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
1045
+ }
1046
+ //#endregion
1047
+ //#region src/bundlers/vite/generate-bundle/rollup-assets.ts
1048
+ function createReplayCssAsset(fileName, source) {
1049
+ return {
1050
+ type: "asset",
1051
+ fileName,
1052
+ name: void 0,
1053
+ source,
1054
+ needsCodeReference: false,
1055
+ names: [],
1056
+ originalFileName: null,
1057
+ originalFileNames: []
1058
+ };
1059
+ }
1060
+ function isAddWatchFileInvalidRollupPhaseError(error) {
1061
+ const candidate = error;
1062
+ return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
1063
+ }
1064
+ function registerGeneratorDependencies(ctx, dependencies) {
1065
+ if (typeof ctx.addWatchFile !== "function") return;
1066
+ for (const dependency of dependencies ?? []) try {
1067
+ ctx.addWatchFile(dependency);
1068
+ } catch (error) {
1069
+ if (isAddWatchFileInvalidRollupPhaseError(error)) {
1070
+ _weapp_tailwindcss_logger.logger.debug("跳过生成模式依赖监听注册,当前 Rollup 阶段不允许 addWatchFile: %s", dependency);
1071
+ continue;
1072
+ }
1073
+ throw error;
1074
+ }
1075
+ }
1076
+ //#endregion
1077
+ //#region src/bundlers/vite/generate-bundle/signatures.ts
865
1078
  function summarizeStringDiff(previous, next) {
866
1079
  if (previous === next) return "same";
867
1080
  const previousLength = previous.length;
@@ -908,111 +1121,22 @@ function getSnapshotHash(snapshotMap, file, fallback) {
908
1121
  function hasRuntimeAffectingSourceChanges(changedByType) {
909
1122
  return changedByType.html.size > 0 || changedByType.js.size > 0;
910
1123
  }
911
- const CSS_URL_FUNCTION_RE = /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/gi;
912
- const CSS_PATH_INDEPENDENT_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/|#)/i;
913
- const CSS_IMPORT_RE = /@import\b/i;
914
- function isPathIndependentCssUrl(value) {
915
- const normalized = value.trim();
916
- return normalized.length > 0 && CSS_PATH_INDEPENDENT_URL_RE.test(normalized);
917
- }
918
- function hasPathDependentCssUrl(rawSource) {
919
- CSS_URL_FUNCTION_RE.lastIndex = 0;
920
- let match = CSS_URL_FUNCTION_RE.exec(rawSource);
921
- while (match !== null) {
922
- if (!isPathIndependentCssUrl(match[1] ?? match[2] ?? match[3] ?? "")) return true;
923
- match = CSS_URL_FUNCTION_RE.exec(rawSource);
924
- }
925
- return false;
926
- }
927
- function createCssTransformShareScope(file, rawSource) {
928
- if (CSS_IMPORT_RE.test(rawSource) || hasPathDependentCssUrl(rawSource)) return `dir:${require_css_imports.normalizeOutputPathKey(node_path.default.dirname(file))}`;
929
- return "global";
930
- }
931
- function createCssTransformShareScopeKey(opts, file, rawSource) {
932
- if (require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator).mode === "force" && opts.mainCssChunkMatcher(file, opts.appType)) return `main:${require_css_imports.normalizeOutputPathKey(file)}`;
933
- return createCssTransformShareScope(file, rawSource);
934
- }
935
- function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
936
- return `${runtimeSignature}:${generatorCandidateSignature}`;
937
- }
938
- function createReplayCssAsset(fileName, source) {
939
- return {
940
- type: "asset",
941
- fileName,
942
- name: void 0,
943
- source,
944
- needsCodeReference: false,
945
- names: [],
946
- originalFileName: null,
947
- originalFileNames: []
948
- };
949
- }
950
- function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
951
- const currentFileSet = new Set(currentBundleFiles);
952
- for (const file of previousBundleFiles) if (!currentFileSet.has(file)) return true;
953
- return false;
954
- }
955
- const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
956
- const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
957
- function isArbitraryValueCandidate(candidate) {
958
- return candidate.includes("[") && candidate.includes("]");
959
- }
960
- function collectUnescapedDynamicCandidates(source) {
961
- const matches = /* @__PURE__ */ new Set();
962
- for (const expression of source.match(MUSTACHE_EXPRESSION_RE) ?? []) {
963
- QUOTED_LITERAL_RE.lastIndex = 0;
964
- let quoted = QUOTED_LITERAL_RE.exec(expression);
965
- while (quoted !== null) {
966
- const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
967
- for (const candidate of (0, _weapp_tailwindcss_shared_extractors.splitCode)(literal, true)) {
968
- const normalized = candidate.trim();
969
- if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
970
- matches.add(normalized);
971
- }
972
- quoted = QUOTED_LITERAL_RE.exec(expression);
973
- }
974
- }
975
- return [...matches];
976
- }
977
- function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
978
- if (candidates.has("container")) return candidates;
979
- if (!sourceCandidates.has("container")) return candidates;
980
- return new Set([...candidates, "container"]);
981
- }
1124
+ //#endregion
1125
+ //#region src/bundlers/vite/generate-bundle.ts
982
1126
  function createGenerateBundleHook(context) {
983
1127
  const state = createBundleBuildState();
984
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
985
- const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
1128
+ const cssHandlerOptions = createCssHandlerOptionsCache({
1129
+ appType: context.opts.appType,
1130
+ mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
1131
+ getMajorVersion: () => context.runtimeState.twPatcher.majorVersion
1132
+ });
986
1133
  return async function generateBundle(_opt, bundle) {
1134
+ const addWatchFile = (id) => this.addWatchFile?.(id);
987
1135
  const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, recordCssAssetResult, getSourceCandidates, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSources, getRememberedMainCssSignature, setRememberedMainCssSignature, recordGeneratorCandidates } = context;
988
- const { appType, cache, mainCssChunkMatcher, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
1136
+ const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
989
1137
  const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
990
- const getCssHandlerOptions = (file) => {
991
- const majorVersion = runtimeState.twPatcher.majorVersion;
992
- const isMainChunk = mainCssChunkMatcher(file, appType);
993
- const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
994
- const cached = cssHandlerOptionsCache.get(cacheKey);
995
- if (cached) return cached;
996
- const created = {
997
- isMainChunk,
998
- postcssOptions: { options: { from: file } },
999
- majorVersion
1000
- };
1001
- cssHandlerOptionsCache.set(cacheKey, created);
1002
- return created;
1003
- };
1004
- const getCssUserHandlerOptions = (file) => {
1005
- const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
1006
- const cached = cssUserHandlerOptionsCache.get(cacheKey);
1007
- if (cached) return cached;
1008
- const created = {
1009
- ...getCssHandlerOptions(file),
1010
- isMainChunk: false
1011
- };
1012
- cssUserHandlerOptionsCache.set(cacheKey, created);
1013
- return created;
1014
- };
1015
- await runtimeState.patchPromise;
1138
+ const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
1139
+ await runtimeState.readyPromise;
1016
1140
  debug("start");
1017
1141
  onStart();
1018
1142
  const metrics = createEmptyMetrics();
@@ -1029,52 +1153,56 @@ function createGenerateBundleHook(context) {
1029
1153
  const useBundleRuntimeClassSet = useIncrementalMode || runtimeState.twPatcher.majorVersion === 4;
1030
1154
  const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
1031
1155
  const processFiles = snapshot.processFiles;
1032
- if (useIncrementalMode) {
1033
- debug("dirty iteration=%d html=%d[%s] js=%d[%s] css=%d[%s] other=%d[%s]", state.iteration + 1, snapshot.changedByType.html.size, formatDebugFileList(snapshot.changedByType.html), snapshot.changedByType.js.size, formatDebugFileList(snapshot.changedByType.js), snapshot.changedByType.css.size, formatDebugFileList(snapshot.changedByType.css), snapshot.changedByType.other.size, formatDebugFileList(snapshot.changedByType.other));
1034
- debug("process iteration=%d html=%d[%s] js=%d[%s] css=%d[%s]", state.iteration + 1, processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
1035
- } else debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
1156
+ logBundleProcessPlan({
1157
+ debug,
1158
+ snapshot,
1159
+ useIncrementalMode,
1160
+ iteration: state.iteration + 1
1161
+ });
1036
1162
  const jsEntries = snapshot.jsEntries;
1037
- const normalizedJsEntries = /* @__PURE__ */ new Map();
1038
- for (const [id, entry] of jsEntries) normalizedJsEntries.set(require_css_imports.normalizeOutputPathKey(id), entry);
1039
- const getJsEntry = (id) => jsEntries.get(id) ?? normalizedJsEntries.get(require_css_imports.normalizeOutputPathKey(id));
1163
+ const getJsEntry = createJsEntryResolver(jsEntries);
1040
1164
  const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
1041
1165
  const runtimeStart = performance.now();
1042
1166
  const runtime = useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
1043
1167
  const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
1044
1168
  await waitForSourceCandidateSyncs?.();
1045
1169
  const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
1046
- const collectedGeneratorCandidates = generatorOptions.mode === "force" ? new Set(sourceCandidates) : new Set([...runtime, ...sourceCandidates]);
1170
+ const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
1047
1171
  const generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, shouldFilterTailwindV4MiniProgramCandidates ? require_generator.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates);
1048
1172
  const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
1049
1173
  recordGeneratorCandidates?.(generatorRuntime);
1050
- const defaultTemplateHandlerOptions = { runtimeSet: runtime };
1174
+ let transformRuntime = runtime;
1175
+ if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size > 0) {
1176
+ const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
1177
+ const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
1178
+ if (mainCssEntry) {
1179
+ const validatedRuntime = await require_generator_css.validateCandidatesByGenerator({
1180
+ opts,
1181
+ runtimeState,
1182
+ candidates: generatorRuntime,
1183
+ rawSource: mainCssEntry.source,
1184
+ file: mainCssEntry.file,
1185
+ cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
1186
+ cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
1187
+ styleHandler,
1188
+ debug
1189
+ });
1190
+ if (validatedRuntime.size > 0) transformRuntime = new Set([...runtime, ...validatedRuntime]);
1191
+ }
1192
+ }
1193
+ const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
1051
1194
  metrics.runtimeSet = measureElapsed(runtimeStart);
1052
1195
  if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
1053
- debug("get runtimeSet, class count: %d", runtime.size);
1054
- const runtimeSignature = require_logger.getRuntimeClassSetSignature(runtimeState.twPatcher) ?? "runtime:missing";
1055
- const handleLinkedUpdate = (fileName, previous, next) => {
1056
- onUpdate(fileName, previous, next);
1057
- debug("js linked handle: %s", fileName);
1058
- };
1059
- const pendingLinkedUpdates = [];
1060
- const scheduleLinkedApply = (entry, code) => {
1061
- pendingLinkedUpdates.push(() => {
1062
- if (entry.output.type === "chunk") entry.output.code = code;
1063
- else entry.output.source = code;
1064
- });
1065
- };
1066
- const applyLinkedUpdates = (linked) => {
1067
- applyLinkedResults(linked, jsEntries, handleLinkedUpdate, scheduleLinkedApply);
1068
- };
1069
- const createHandlerOptions = (absoluteFilename, extra) => ({
1070
- ...extra,
1071
- filename: absoluteFilename,
1072
- tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
1073
- moduleGraph: moduleGraphOptions,
1074
- babelParserOptions: {
1075
- ...extra?.babelParserOptions ?? {},
1076
- sourceFilename: absoluteFilename
1077
- }
1196
+ debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
1197
+ const runtimeSignature = require_cache.getRuntimeClassSetSignature(runtimeState.twPatcher) ?? "runtime:missing";
1198
+ const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
1199
+ jsEntries,
1200
+ onUpdate,
1201
+ debug
1202
+ });
1203
+ const createHandlerOptions = createJsHandlerOptionsFactory({
1204
+ getMajorVersion: () => runtimeState.twPatcher.majorVersion,
1205
+ moduleGraph: moduleGraphOptions
1078
1206
  });
1079
1207
  const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
1080
1208
  const sharedCssResultCache = /* @__PURE__ */ new Map();
@@ -1152,7 +1280,7 @@ function createGenerateBundleHook(context) {
1152
1280
  }
1153
1281
  const runTransform = async () => {
1154
1282
  const start = performance.now();
1155
- await runtimeState.patchPromise;
1283
+ await runtimeState.readyPromise;
1156
1284
  const generated = await require_generator_css.generateCssByGenerator({
1157
1285
  opts,
1158
1286
  runtimeState,
@@ -1165,6 +1293,7 @@ function createGenerateBundleHook(context) {
1165
1293
  debug
1166
1294
  });
1167
1295
  if (generated) {
1296
+ registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
1168
1297
  if (debugCssDiff) debug("css diff %s: %s", file, summarizeStringDiff(rawSource, generated.css));
1169
1298
  debug("css generated result: %s bytes=%d", file, generated.css.length);
1170
1299
  recordCssAssetResult?.(file, generated.css);
@@ -1217,20 +1346,17 @@ function createGenerateBundleHook(context) {
1217
1346
  const rawSource = originalSource.code;
1218
1347
  if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
1219
1348
  const handlerOptions = createHandlerOptions(absoluteFile);
1220
- if (!disableJsPrecheck && require_recorder.shouldSkipJsTransform(rawSource, handlerOptions)) {
1349
+ if (!disableJsPrecheck && require_precheck.shouldSkipJsTransform(rawSource, handlerOptions)) {
1221
1350
  metrics.js.elapsed += measureElapsed(start);
1222
1351
  metrics.js.transformed++;
1223
1352
  return { result: rawSource };
1224
1353
  }
1225
- const { code, linked } = await jsHandler(rawSource, runtime, handlerOptions);
1354
+ const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
1226
1355
  metrics.js.elapsed += measureElapsed(start);
1227
1356
  metrics.js.transformed++;
1228
1357
  onUpdate(file, rawSource, code);
1229
1358
  debug("js handle: %s", file);
1230
- if (linked) for (const id of Object.keys(linked)) {
1231
- const linkedEntry = getJsEntry(id);
1232
- if (linkedEntry && linkedSet) linkedSet.add(linkedEntry.fileName);
1233
- }
1359
+ collectLinkedFileNames(linked, getJsEntry, linkedSet);
1234
1360
  applyLinkedUpdates(linked);
1235
1361
  return { result: code };
1236
1362
  }
@@ -1241,10 +1367,7 @@ function createGenerateBundleHook(context) {
1241
1367
  if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
1242
1368
  const baseApplyLinkedUpdates = applyLinkedUpdates;
1243
1369
  const wrappedApplyLinkedUpdates = (linked) => {
1244
- if (linked) for (const id of Object.keys(linked)) {
1245
- const linkedEntry = getJsEntry(id);
1246
- if (linkedEntry && linkedSet) linkedSet.add(linkedEntry.fileName);
1247
- }
1370
+ collectLinkedFileNames(linked, getJsEntry, linkedSet);
1248
1371
  baseApplyLinkedUpdates(linked);
1249
1372
  };
1250
1373
  const factory = createUniAppXAssetTask(file, originalSource, outDir, {
@@ -1255,7 +1378,7 @@ function createGenerateBundleHook(context) {
1255
1378
  debug,
1256
1379
  jsHandler,
1257
1380
  onUpdate,
1258
- runtimeSet: runtime,
1381
+ runtimeSet: transformRuntime,
1259
1382
  applyLinkedResults: wrappedApplyLinkedUpdates,
1260
1383
  uniAppX
1261
1384
  });
@@ -1276,7 +1399,7 @@ function createGenerateBundleHook(context) {
1276
1399
  sourceType: "unambiguous"
1277
1400
  }
1278
1401
  });
1279
- if (!disableJsPrecheck && require_recorder.shouldSkipJsTransform(currentSource, precheckOptions)) {
1402
+ if (!disableJsPrecheck && require_precheck.shouldSkipJsTransform(currentSource, precheckOptions)) {
1280
1403
  metrics.js.elapsed += measureElapsed(start);
1281
1404
  metrics.js.transformed++;
1282
1405
  return;
@@ -1288,7 +1411,7 @@ function createGenerateBundleHook(context) {
1288
1411
  }
1289
1412
  }
1290
1413
  const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature);
1291
- if (useIncrementalMode && generatorOptions.mode !== "off") for (const [file, rawSource] of getRememberedMainCssSources?.() ?? []) {
1414
+ if (useIncrementalMode) for (const [file, rawSource] of getRememberedMainCssSources?.() ?? []) {
1292
1415
  if (bundleFiles.includes(file) || getRememberedMainCssSignature?.(file) === cssRuntimeSignature) continue;
1293
1416
  tasks.push((async () => {
1294
1417
  const start = performance.now();
@@ -1307,6 +1430,7 @@ function createGenerateBundleHook(context) {
1307
1430
  const css = generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css;
1308
1431
  setRememberedMainCssSignature?.(file, cssRuntimeSignature);
1309
1432
  if (generated) {
1433
+ registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
1310
1434
  recordCssAssetResult?.(file, generated.css);
1311
1435
  debug("css replay generated result: %s bytes=%d", file, css.length);
1312
1436
  }
@@ -1324,7 +1448,7 @@ function createGenerateBundleHook(context) {
1324
1448
  debug("css replay handle: %s", file);
1325
1449
  })());
1326
1450
  }
1327
- require_css_imports.pushConcurrentTaskFactories(tasks, jsTaskFactories);
1451
+ require_run_tasks.pushConcurrentTaskFactories(tasks, jsTaskFactories);
1328
1452
  await Promise.all(tasks);
1329
1453
  for (const apply of pendingLinkedUpdates) apply();
1330
1454
  updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
@@ -1334,24 +1458,251 @@ function createGenerateBundleHook(context) {
1334
1458
  };
1335
1459
  }
1336
1460
  //#endregion
1337
- //#region src/bundlers/vite/incremental-runtime-class-set.ts
1338
- const debug$1 = require_recorder.createDebug("[vite:runtime-set] ");
1339
- const EXTENSION_DOT_PREFIX_RE = /^\./;
1340
- function createExtractOptions(context, source) {
1341
- return {
1342
- cwd: context.projectRoot,
1343
- base: context.base,
1344
- baseFallbacks: context.baseFallbacks,
1345
- css: context.css,
1346
- content: source,
1347
- extension: "html"
1348
- };
1461
+ //#region src/bundlers/vite/official-tailwind-plugins.ts
1462
+ const tailwindPostcssPluginNames = new Set(["tailwindcss", "@tailwindcss/postcss"]);
1463
+ function getPostcssPluginName(plugin) {
1464
+ if (!plugin) return;
1465
+ if (typeof plugin === "function" && "postcss" in plugin) try {
1466
+ return getPostcssPluginName(plugin());
1467
+ } catch {
1468
+ return;
1469
+ }
1470
+ if (typeof plugin !== "object" || !("postcssPlugin" in plugin)) return;
1471
+ const { postcssPlugin } = plugin;
1472
+ return typeof postcssPlugin === "string" ? postcssPlugin : void 0;
1349
1473
  }
1350
- function createRuntimeEntries(snapshot) {
1351
- return snapshot.entries.filter((entry) => entry.type === "html" || entry.type === "js");
1474
+ function isTailwindPostcssPlugin(plugin) {
1475
+ const name = getPostcssPluginName(plugin);
1476
+ return typeof name === "string" && tailwindPostcssPluginNames.has(name);
1352
1477
  }
1353
- function collectChangedRuntimeFiles(snapshot) {
1354
- return new Set([...snapshot.runtimeAffectingChangedByType.html, ...snapshot.runtimeAffectingChangedByType.js]);
1478
+ function removeTailwindPostcssPlugins(plugins) {
1479
+ let removed = 0;
1480
+ for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindPostcssPlugin(plugins[i])) {
1481
+ plugins.splice(i, 1);
1482
+ removed++;
1483
+ }
1484
+ return removed;
1485
+ }
1486
+ function isTailwindVitePlugin(plugin) {
1487
+ if (!plugin || typeof plugin !== "object" || !("name" in plugin)) return false;
1488
+ const { name } = plugin;
1489
+ return typeof name === "string" && name.startsWith("@tailwindcss/vite");
1490
+ }
1491
+ function removeTailwindVitePlugins(plugins) {
1492
+ let removed = 0;
1493
+ for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindVitePlugin(plugins[i])) {
1494
+ plugins.splice(i, 1);
1495
+ removed++;
1496
+ }
1497
+ return removed;
1498
+ }
1499
+ function disableTailwindVitePlugin(plugin) {
1500
+ if (!isTailwindVitePlugin(plugin)) return false;
1501
+ const mutablePlugin = plugin;
1502
+ for (const hook of [
1503
+ "configResolved",
1504
+ "configureServer",
1505
+ "transform",
1506
+ "hotUpdate",
1507
+ "handleHotUpdate"
1508
+ ]) delete mutablePlugin[hook];
1509
+ return true;
1510
+ }
1511
+ function disableAndRemoveTailwindVitePlugins(plugins) {
1512
+ let removed = 0;
1513
+ for (let i = plugins.length - 1; i >= 0; i--) {
1514
+ const plugin = plugins[i];
1515
+ if (Array.isArray(plugin)) {
1516
+ removed += disableAndRemoveTailwindVitePlugins(plugin);
1517
+ if (plugin.length === 0) plugins.splice(i, 1);
1518
+ continue;
1519
+ }
1520
+ if (disableTailwindVitePlugin(plugin)) {
1521
+ plugins.splice(i, 1);
1522
+ removed++;
1523
+ }
1524
+ }
1525
+ return removed;
1526
+ }
1527
+ //#endregion
1528
+ //#region src/bundlers/vite/postcss-config.ts
1529
+ async function resolveFilteredPostcssConfig(root) {
1530
+ try {
1531
+ const loaded = await (0, postcss_load_config.default)({}, root);
1532
+ const plugins = Array.isArray(loaded.plugins) ? [...loaded.plugins] : [];
1533
+ const removed = removeTailwindPostcssPlugins(plugins);
1534
+ if (removed === 0) return;
1535
+ return {
1536
+ options: loaded.options,
1537
+ plugins,
1538
+ removed
1539
+ };
1540
+ } catch (error) {
1541
+ if ((error instanceof Error ? error.message : String(error)).includes("No PostCSS Config found")) return;
1542
+ throw error;
1543
+ }
1544
+ }
1545
+ //#endregion
1546
+ //#region src/bundlers/vite/resolve-app-type.ts
1547
+ const PACKAGE_JSON_FILE$1 = "package.json";
1548
+ const MPX_SCRIPT_RE = /\bmpx(?:-cli-service)?\b/u;
1549
+ const TARO_SCRIPT_RE = /\btaro\b/u;
1550
+ const TAILWINDCSS_VITE_MARKERS = [["src/app.mpx", "mpx"], ["app.mpx", "mpx"]];
1551
+ function resolveDependencyNames(pkg) {
1552
+ return new Set([
1553
+ ...Object.keys(pkg.dependencies ?? {}),
1554
+ ...Object.keys(pkg.devDependencies ?? {}),
1555
+ ...Object.keys(pkg.peerDependencies ?? {}),
1556
+ ...Object.keys(pkg.optionalDependencies ?? {})
1557
+ ]);
1558
+ }
1559
+ function hasScriptMatch(pkg, pattern) {
1560
+ return Object.values(pkg.scripts ?? {}).some((script) => pattern.test(script));
1561
+ }
1562
+ function resolveAppTypeFromPackageJson(pkg) {
1563
+ const dependencyNames = resolveDependencyNames(pkg);
1564
+ if (dependencyNames.has("weapp-vite") || [...dependencyNames].some((name) => name.startsWith("@weapp-vite/"))) return "weapp-vite";
1565
+ if ([...dependencyNames].some((name) => name.startsWith("@mpxjs/")) || hasScriptMatch(pkg, MPX_SCRIPT_RE)) return "mpx";
1566
+ if ([...dependencyNames].some((name) => name.startsWith("@tarojs/")) || hasScriptMatch(pkg, TARO_SCRIPT_RE)) return "taro";
1567
+ if (dependencyNames.has("@dcloudio/vite-plugin-uni")) return "uni-app-vite";
1568
+ if (dependencyNames.has("@dcloudio/vue-cli-plugin-uni") || dependencyNames.has("@dcloudio/uni-app") || Object.hasOwn(pkg, "uni-app")) return "uni-app";
1569
+ }
1570
+ function tryReadUniAppManifest(root) {
1571
+ const manifestPath = node_path.default.join(root, "manifest.json");
1572
+ if (!(0, node_fs.existsSync)(manifestPath)) return;
1573
+ try {
1574
+ return JSON.parse((0, node_fs.readFileSync)(manifestPath, "utf8"));
1575
+ } catch {}
1576
+ }
1577
+ function tryReadPackageJson(root) {
1578
+ const packageJsonPath = node_path.default.join(root, PACKAGE_JSON_FILE$1);
1579
+ if (!(0, node_fs.existsSync)(packageJsonPath)) return;
1580
+ try {
1581
+ return JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
1582
+ } catch {}
1583
+ }
1584
+ function resolveAppTypeFromMarkers(root) {
1585
+ for (const [relativePath, appType] of TAILWINDCSS_VITE_MARKERS) if ((0, node_fs.existsSync)(node_path.default.join(root, relativePath))) return appType;
1586
+ }
1587
+ function resolveImplicitAppTypeFromViteRoot(root) {
1588
+ const resolvedRoot = node_path.default.resolve(root);
1589
+ if (!(0, node_fs.existsSync)(resolvedRoot)) return;
1590
+ const markerDetected = resolveAppTypeFromMarkers(resolvedRoot);
1591
+ if (markerDetected) return markerDetected;
1592
+ let current = resolvedRoot;
1593
+ while (true) {
1594
+ const manifest = tryReadUniAppManifest(current);
1595
+ if (manifest && Object.hasOwn(manifest, "uni-app-x")) return "uni-app-x";
1596
+ const pkg = tryReadPackageJson(current);
1597
+ if (pkg) {
1598
+ const detected = resolveAppTypeFromPackageJson(pkg);
1599
+ if (detected) return detected;
1600
+ }
1601
+ const parent = node_path.default.dirname(current);
1602
+ if (parent === current) break;
1603
+ current = parent;
1604
+ }
1605
+ }
1606
+ //#endregion
1607
+ //#region src/bundlers/shared/css-imports.ts
1608
+ const tailwindcssImportRE = /^tailwindcss(?:\/.*)?$/;
1609
+ const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])(tailwindcss(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
1610
+ function normalizeTailwindcssSpecifier(specifier) {
1611
+ if (specifier === "tailwindcss$") return "tailwindcss";
1612
+ return specifier;
1613
+ }
1614
+ function getTailwindcssSubpath(specifier) {
1615
+ if (specifier === "tailwindcss") return "index.css";
1616
+ return specifier.slice(12);
1617
+ }
1618
+ function resolveTailwindcssImport(specifier, pkgDir, options) {
1619
+ const normalized = normalizeTailwindcssSpecifier(specifier);
1620
+ if (!tailwindcssImportRE.test(normalized)) return null;
1621
+ if (normalized === "tailwindcss") return options?.rootImport ?? "weapp-tailwindcss/index.css";
1622
+ return (options?.join ?? node_path.default.join)(pkgDir, getTailwindcssSubpath(normalized));
1623
+ }
1624
+ function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
1625
+ let hasReplacements = false;
1626
+ const rewritten = code.replace(tailwindcssCssImportStatementRE, (full, prefix, quote, specifier, suffix) => {
1627
+ const replacement = resolveTailwindcssImport(specifier, pkgDir, options);
1628
+ if (!replacement) return full;
1629
+ hasReplacements = true;
1630
+ return `${prefix}${quote}${replacement}${suffix}`;
1631
+ });
1632
+ return hasReplacements ? rewritten : void 0;
1633
+ }
1634
+ //#endregion
1635
+ //#region src/bundlers/vite/rewrite-css-imports.ts
1636
+ function joinPosixPath(base, subpath) {
1637
+ if (base.endsWith("/")) return `${base}${subpath}`;
1638
+ return `${base}/${subpath}`;
1639
+ }
1640
+ function isCssLikeImporter(importer) {
1641
+ if (!importer) return false;
1642
+ const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
1643
+ return isCSSRequest(normalized) || normalized.endsWith("/*");
1644
+ }
1645
+ function stripTailwindConfigDirectives(code) {
1646
+ return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
1647
+ }
1648
+ function createRewriteCssImportsPlugins(options) {
1649
+ if (!options.shouldRewrite) return [];
1650
+ const { appType, getAppType, rootImport, shouldOwnTailwindGeneration, weappTailwindcssDirPosix } = options;
1651
+ const resolveAppType = () => getAppType?.() ?? appType;
1652
+ return [{
1653
+ name: `${require_precheck.vitePluginName}:rewrite-css-imports`,
1654
+ enforce: "pre",
1655
+ resolveId: {
1656
+ order: "pre",
1657
+ handler(id, importer) {
1658
+ const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
1659
+ join: joinPosixPath,
1660
+ appType: resolveAppType(),
1661
+ rootImport
1662
+ });
1663
+ if (!replacement) return null;
1664
+ if (importer && !isCssLikeImporter(importer)) return null;
1665
+ return replacement;
1666
+ }
1667
+ },
1668
+ transform: {
1669
+ order: "pre",
1670
+ handler(code, id) {
1671
+ if (!isCSSRequest(id)) return null;
1672
+ const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, {
1673
+ join: joinPosixPath,
1674
+ appType: resolveAppType(),
1675
+ rootImport
1676
+ });
1677
+ const nextCode = shouldOwnTailwindGeneration ? stripTailwindConfigDirectives(rewritten ?? code) : rewritten;
1678
+ if (!nextCode || nextCode === code) return null;
1679
+ return {
1680
+ code: nextCode,
1681
+ map: null
1682
+ };
1683
+ }
1684
+ }
1685
+ }];
1686
+ }
1687
+ //#endregion
1688
+ //#region src/bundlers/vite/incremental-runtime-class-set.ts
1689
+ const debug$1 = require_runtime_patch.createDebug("[vite:runtime-set] ");
1690
+ const EXTENSION_DOT_PREFIX_RE = /^\./;
1691
+ function createExtractOptions(context, source) {
1692
+ return {
1693
+ cwd: context.projectRoot,
1694
+ base: context.base,
1695
+ baseFallbacks: context.baseFallbacks,
1696
+ css: context.css,
1697
+ content: source,
1698
+ extension: "html"
1699
+ };
1700
+ }
1701
+ function createRuntimeEntries(snapshot) {
1702
+ return snapshot.entries.filter((entry) => entry.type === "html" || entry.type === "js");
1703
+ }
1704
+ function collectChangedRuntimeFiles(snapshot) {
1705
+ return new Set([...snapshot.runtimeAffectingChangedByType.html, ...snapshot.runtimeAffectingChangedByType.js]);
1355
1706
  }
1356
1707
  function resolveEntryExtension(entry) {
1357
1708
  const ext = entry.file.split(/[?#]/, 1)[0]?.split(".").pop()?.replace(EXTENSION_DOT_PREFIX_RE, "") ?? "";
@@ -1444,7 +1795,7 @@ function createBundleRuntimeClassSetManager(options = {}) {
1444
1795
  return candidates;
1445
1796
  }
1446
1797
  async function sync(patcher, snapshot) {
1447
- const nextSignature = require_logger.getRuntimeClassSetSignature(patcher) ?? "runtime:missing";
1798
+ const nextSignature = require_cache.getRuntimeClassSetSignature(patcher) ?? "runtime:missing";
1448
1799
  const runtimeEntries = createRuntimeEntries(snapshot);
1449
1800
  const runtimeEntriesByFile = new Map(runtimeEntries.map((entry) => [entry.file, entry]));
1450
1801
  const currentRuntimeFiles = new Set(runtimeEntriesByFile.keys());
@@ -1498,114 +1849,111 @@ function createBundleRuntimeClassSetManager(options = {}) {
1498
1849
  };
1499
1850
  }
1500
1851
  //#endregion
1501
- //#region src/bundlers/vite/resolve-app-type.ts
1502
- const PACKAGE_JSON_FILE$1 = "package.json";
1503
- const MPX_SCRIPT_RE = /\bmpx(?:-cli-service)?\b/u;
1504
- const TARO_SCRIPT_RE = /\btaro\b/u;
1505
- const TAILWINDCSS_VITE_MARKERS = [["src/app.mpx", "mpx"], ["app.mpx", "mpx"]];
1506
- function resolveDependencyNames(pkg) {
1507
- return new Set([
1508
- ...Object.keys(pkg.dependencies ?? {}),
1509
- ...Object.keys(pkg.devDependencies ?? {}),
1510
- ...Object.keys(pkg.peerDependencies ?? {}),
1511
- ...Object.keys(pkg.optionalDependencies ?? {})
1512
- ]);
1513
- }
1514
- function hasScriptMatch(pkg, pattern) {
1515
- return Object.values(pkg.scripts ?? {}).some((script) => pattern.test(script));
1516
- }
1517
- function resolveAppTypeFromPackageJson(pkg) {
1518
- const dependencyNames = resolveDependencyNames(pkg);
1519
- if (dependencyNames.has("weapp-vite") || [...dependencyNames].some((name) => name.startsWith("@weapp-vite/"))) return "weapp-vite";
1520
- if ([...dependencyNames].some((name) => name.startsWith("@mpxjs/")) || hasScriptMatch(pkg, MPX_SCRIPT_RE)) return "mpx";
1521
- if ([...dependencyNames].some((name) => name.startsWith("@tarojs/")) || hasScriptMatch(pkg, TARO_SCRIPT_RE)) return "taro";
1522
- if (dependencyNames.has("@dcloudio/vite-plugin-uni")) return "uni-app-vite";
1523
- if (dependencyNames.has("@dcloudio/vue-cli-plugin-uni") || dependencyNames.has("@dcloudio/uni-app") || Object.hasOwn(pkg, "uni-app")) return "uni-app";
1524
- }
1525
- function tryReadUniAppManifest(root) {
1526
- const manifestPath = node_path.default.join(root, "manifest.json");
1527
- if (!(0, node_fs.existsSync)(manifestPath)) return;
1528
- try {
1529
- return JSON.parse((0, node_fs.readFileSync)(manifestPath, "utf8"));
1530
- } catch {}
1531
- }
1532
- function tryReadPackageJson(root) {
1533
- const packageJsonPath = node_path.default.join(root, PACKAGE_JSON_FILE$1);
1534
- if (!(0, node_fs.existsSync)(packageJsonPath)) return;
1535
- try {
1536
- return JSON.parse((0, node_fs.readFileSync)(packageJsonPath, "utf8"));
1537
- } catch {}
1538
- }
1539
- function resolveAppTypeFromMarkers(root) {
1540
- for (const [relativePath, appType] of TAILWINDCSS_VITE_MARKERS) if ((0, node_fs.existsSync)(node_path.default.join(root, relativePath))) return appType;
1541
- }
1542
- function resolveImplicitAppTypeFromViteRoot(root) {
1543
- const resolvedRoot = node_path.default.resolve(root);
1544
- if (!(0, node_fs.existsSync)(resolvedRoot)) return;
1545
- const markerDetected = resolveAppTypeFromMarkers(resolvedRoot);
1546
- if (markerDetected) return markerDetected;
1547
- let current = resolvedRoot;
1548
- while (true) {
1549
- const manifest = tryReadUniAppManifest(current);
1550
- if (manifest && Object.hasOwn(manifest, "uni-app-x")) return "uni-app-x";
1551
- const pkg = tryReadPackageJson(current);
1552
- if (pkg) {
1553
- const detected = resolveAppTypeFromPackageJson(pkg);
1554
- if (detected) return detected;
1852
+ //#region src/bundlers/vite/runtime-class-set.ts
1853
+ function createViteRuntimeClassSet(options) {
1854
+ const { opts, initialTwPatcher, refreshTailwindcssPatcher, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
1855
+ const runtimeState = {
1856
+ twPatcher: initialTwPatcher,
1857
+ readyPromise: require_precheck.createTailwindRuntimeReadyPromise(initialTwPatcher),
1858
+ refreshTailwindcssPatcher
1859
+ };
1860
+ const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager();
1861
+ let runtimeSet;
1862
+ let runtimeSetPromise;
1863
+ let runtimeRefreshSignature;
1864
+ let runtimeRefreshOptionsKey;
1865
+ function resolveRuntimeRefreshOptions() {
1866
+ const configPath = require_cache.resolveTailwindcssOptions(runtimeState.twPatcher.options)?.config;
1867
+ const signature = require_cache.getRuntimeClassSetSignature(runtimeState.twPatcher);
1868
+ const optionsKey = JSON.stringify({
1869
+ appType: opts.appType,
1870
+ uniAppX: uniAppXEnabled,
1871
+ customAttributesEntities,
1872
+ disabledDefaultTemplateHandler,
1873
+ configPath
1874
+ });
1875
+ const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
1876
+ runtimeRefreshSignature = signature;
1877
+ runtimeRefreshOptionsKey = optionsKey;
1878
+ return {
1879
+ changed,
1880
+ signature,
1881
+ optionsKey
1882
+ };
1883
+ }
1884
+ async function refreshRuntimeState(force) {
1885
+ const invalidation = resolveRuntimeRefreshOptions();
1886
+ const refreshed = await require_precheck.refreshTailwindRuntimeState(runtimeState, {
1887
+ force: force || invalidation.changed,
1888
+ clearCache: force || invalidation.changed
1889
+ });
1890
+ if (invalidation.changed) debug("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
1891
+ if (refreshed) {
1892
+ runtimeSet = void 0;
1893
+ runtimeSetPromise = void 0;
1894
+ }
1895
+ }
1896
+ async function ensureRuntimeClassSet(force = false) {
1897
+ const forceRuntimeRefresh = force || node_process.default.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
1898
+ await refreshRuntimeState(force);
1899
+ await runtimeState.readyPromise;
1900
+ if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
1901
+ if (forceRuntimeRefresh || !runtimeSetPromise) {
1902
+ const invalidation = resolveRuntimeRefreshOptions();
1903
+ runtimeSetPromise = require_precheck.collectRuntimeClassSet(runtimeState.twPatcher, {
1904
+ force: forceRuntimeRefresh || invalidation.changed,
1905
+ skipRefresh: forceRuntimeRefresh,
1906
+ clearCache: forceRuntimeRefresh || invalidation.changed
1907
+ });
1908
+ }
1909
+ const task = runtimeSetPromise;
1910
+ try {
1911
+ runtimeSet = await task;
1912
+ return runtimeSet;
1913
+ } finally {
1914
+ if (runtimeSetPromise === task) runtimeSetPromise = void 0;
1915
+ }
1916
+ }
1917
+ async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false) {
1918
+ const forceRuntimeRefresh = forceRefresh || node_process.default.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
1919
+ const invalidation = resolveRuntimeRefreshOptions();
1920
+ const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
1921
+ const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
1922
+ await refreshRuntimeState(shouldRefreshPatcher);
1923
+ await runtimeState.readyPromise;
1924
+ if (shouldRefreshPatcher) {
1925
+ runtimeSet = void 0;
1926
+ runtimeSetPromise = void 0;
1927
+ await bundleRuntimeClassSetManager.reset();
1555
1928
  }
1556
- const parent = node_path.default.dirname(current);
1557
- if (parent === current) break;
1558
- current = parent;
1559
- }
1560
- }
1561
- //#endregion
1562
- //#region src/bundlers/vite/rewrite-css-imports.ts
1563
- function joinPosixPath(base, subpath) {
1564
- if (base.endsWith("/")) return `${base}${subpath}`;
1565
- return `${base}/${subpath}`;
1566
- }
1567
- function isCssLikeImporter(importer) {
1568
- if (!importer) return false;
1569
- const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
1570
- return isCSSRequest(normalized) || normalized.endsWith("/*");
1571
- }
1572
- function createRewriteCssImportsPlugins(options) {
1573
- if (!options.shouldRewrite) return [];
1574
- const { appType, getAppType, rootImport, weappTailwindcssDirPosix } = options;
1575
- const resolveAppType = () => getAppType?.() ?? appType;
1576
- return [{
1577
- name: `${require_recorder.vitePluginName}:rewrite-css-imports`,
1578
- enforce: "pre",
1579
- resolveId: {
1580
- order: "pre",
1581
- handler(id, importer) {
1582
- const replacement = require_css_imports.resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
1583
- join: joinPosixPath,
1584
- appType: resolveAppType(),
1585
- rootImport
1586
- });
1587
- if (!replacement) return null;
1588
- if (importer && !isCssLikeImporter(importer)) return null;
1589
- return replacement;
1590
- }
1591
- },
1592
- transform: {
1593
- order: "pre",
1594
- handler(code, id) {
1595
- if (!isCSSRequest(id)) return null;
1596
- const rewritten = require_css_imports.rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, {
1597
- join: joinPosixPath,
1598
- appType: resolveAppType(),
1599
- rootImport
1600
- });
1601
- if (!rewritten) return null;
1602
- return {
1603
- code: rewritten,
1604
- map: null
1605
- };
1606
- }
1929
+ if (runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) try {
1930
+ const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
1931
+ runtimeSet = nextRuntimeSet;
1932
+ return nextRuntimeSet;
1933
+ } catch (error) {
1934
+ debug("incremental runtime set sync failed, fallback to full collect: %O", error);
1935
+ await bundleRuntimeClassSetManager.reset();
1607
1936
  }
1608
- }];
1937
+ if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
1938
+ const task = require_precheck.collectRuntimeClassSet(runtimeState.twPatcher, {
1939
+ force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
1940
+ skipRefresh: forceRuntimeRefresh,
1941
+ clearCache: forceRuntimeRefresh || invalidation.changed
1942
+ });
1943
+ runtimeSetPromise = task;
1944
+ try {
1945
+ runtimeSet = await task;
1946
+ return runtimeSet;
1947
+ } finally {
1948
+ if (runtimeSetPromise === task) runtimeSetPromise = void 0;
1949
+ }
1950
+ }
1951
+ return {
1952
+ runtimeState,
1953
+ refreshRuntimeState,
1954
+ ensureRuntimeClassSet,
1955
+ ensureBundleRuntimeClassSet
1956
+ };
1609
1957
  }
1610
1958
  //#endregion
1611
1959
  //#region src/bundlers/vite/source-candidates.ts
@@ -1760,92 +2108,8 @@ function createSourceCandidateCollector() {
1760
2108
  };
1761
2109
  }
1762
2110
  //#endregion
1763
- //#region src/bundlers/vite/index.ts
1764
- const debug = require_recorder.createDebug();
1765
- const weappTailwindcssPackageDir = require_css_imports.resolvePackageDir("weapp-tailwindcss");
1766
- const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
2111
+ //#region src/bundlers/vite/tailwind-basedir.ts
1767
2112
  const PACKAGE_JSON_FILE = "package.json";
1768
- const tailwindPostcssPluginNames = new Set(["tailwindcss", "@tailwindcss/postcss"]);
1769
- function getPostcssPluginName(plugin) {
1770
- if (!plugin) return;
1771
- if (typeof plugin === "function" && "postcss" in plugin) try {
1772
- return getPostcssPluginName(plugin());
1773
- } catch {
1774
- return;
1775
- }
1776
- if (typeof plugin !== "object" || !("postcssPlugin" in plugin)) return;
1777
- const { postcssPlugin } = plugin;
1778
- return typeof postcssPlugin === "string" ? postcssPlugin : void 0;
1779
- }
1780
- function isTailwindPostcssPlugin(plugin) {
1781
- const name = getPostcssPluginName(plugin);
1782
- return typeof name === "string" && tailwindPostcssPluginNames.has(name);
1783
- }
1784
- function removeTailwindPostcssPlugins(plugins) {
1785
- let removed = 0;
1786
- for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindPostcssPlugin(plugins[i])) {
1787
- plugins.splice(i, 1);
1788
- removed++;
1789
- }
1790
- return removed;
1791
- }
1792
- async function resolveFilteredPostcssConfig(root) {
1793
- try {
1794
- const loaded = await (0, postcss_load_config.default)({}, root);
1795
- const plugins = Array.isArray(loaded.plugins) ? [...loaded.plugins] : [];
1796
- const removed = removeTailwindPostcssPlugins(plugins);
1797
- if (removed === 0) return;
1798
- return {
1799
- options: loaded.options,
1800
- plugins,
1801
- removed
1802
- };
1803
- } catch (error) {
1804
- if ((error instanceof Error ? error.message : String(error)).includes("No PostCSS Config found")) return;
1805
- throw error;
1806
- }
1807
- }
1808
- function isTailwindVitePlugin(plugin) {
1809
- if (!plugin || typeof plugin !== "object" || !("name" in plugin)) return false;
1810
- const { name } = plugin;
1811
- return typeof name === "string" && name.startsWith("@tailwindcss/vite");
1812
- }
1813
- function removeTailwindVitePlugins(plugins) {
1814
- let removed = 0;
1815
- for (let i = plugins.length - 1; i >= 0; i--) if (isTailwindVitePlugin(plugins[i])) {
1816
- plugins.splice(i, 1);
1817
- removed++;
1818
- }
1819
- return removed;
1820
- }
1821
- function disableTailwindVitePlugin(plugin) {
1822
- if (!isTailwindVitePlugin(plugin)) return false;
1823
- const mutablePlugin = plugin;
1824
- for (const hook of [
1825
- "configResolved",
1826
- "configureServer",
1827
- "transform",
1828
- "hotUpdate",
1829
- "handleHotUpdate"
1830
- ]) delete mutablePlugin[hook];
1831
- return true;
1832
- }
1833
- function disableAndRemoveTailwindVitePlugins(plugins) {
1834
- let removed = 0;
1835
- for (let i = plugins.length - 1; i >= 0; i--) {
1836
- const plugin = plugins[i];
1837
- if (Array.isArray(plugin)) {
1838
- removed += disableAndRemoveTailwindVitePlugins(plugin);
1839
- if (plugin.length === 0) plugins.splice(i, 1);
1840
- continue;
1841
- }
1842
- if (disableTailwindVitePlugin(plugin)) {
1843
- plugins.splice(i, 1);
1844
- removed++;
1845
- }
1846
- }
1847
- return removed;
1848
- }
1849
2113
  function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
1850
2114
  const resolvedRoot = node_path.default.resolve(root);
1851
2115
  if (!(0, node_fs.existsSync)(resolvedRoot)) return resolvedRoot;
@@ -1857,154 +2121,66 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
1857
2121
  if (parent === current) break;
1858
2122
  current = parent;
1859
2123
  }
1860
- const tailwindConfigPath = require_logger.findTailwindConfig(searchRoots);
2124
+ const tailwindConfigPath = require_cache.findTailwindConfig(searchRoots);
1861
2125
  if (tailwindConfigPath) return node_path.default.dirname(tailwindConfigPath);
1862
- const packageRoot = require_logger.findNearestPackageRoot(resolvedRoot);
2126
+ const packageRoot = require_cache.findNearestPackageRoot(resolvedRoot);
1863
2127
  if (packageRoot && (0, node_fs.existsSync)(node_path.default.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
1864
2128
  return resolvedRoot;
1865
2129
  }
2130
+ //#endregion
2131
+ //#region src/bundlers/vite/index.ts
2132
+ const debug = require_runtime_patch.createDebug();
2133
+ const weappTailwindcssPackageDir = require_run_tasks.resolvePackageDir("weapp-tailwindcss");
2134
+ const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
1866
2135
  /**
1867
- * @name UnifiedViteWeappTailwindcssPlugin
2136
+ * @name WeappTailwindcss
1868
2137
  * @description uni-app vite / uni-app-x 版本插件
1869
2138
  * @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
1870
2139
  */
1871
- function UnifiedViteWeappTailwindcssPlugin(options = {}) {
2140
+ function WeappTailwindcss(options = {}) {
1872
2141
  const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
1873
- const rewriteCssImportsSpecified = Object.hasOwn(options, "rewriteCssImports");
1874
2142
  const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
1875
- const opts = require_recorder.getCompilerContext(options);
2143
+ const opts = require_precheck.getCompilerContext(options);
1876
2144
  const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, twPatcher: initialTwPatcher, refreshTailwindcssPatcher, uniAppX, disabledDefaultTemplateHandler } = opts;
1877
- const uniAppXEnabled = require_logger.isUniAppXEnabled(uniAppX);
1878
- const disabledOptions = require_css_imports.resolveDisabledOptions(disabled);
2145
+ const uniAppXEnabled = require_tailwindcss.isUniAppXEnabled(uniAppX);
2146
+ const disabledOptions = require_run_tasks.resolvePluginDisabledState(disabled);
1879
2147
  const tailwindcssMajorVersion = initialTwPatcher.majorVersion ?? 0;
1880
- const shouldOwnTailwindGeneration = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator).mode !== "off" && !disabledOptions.plugin;
1881
- const shouldRewriteCssImports = opts.rewriteCssImports !== false && !disabledOptions.rewriteCssImports && (rewriteCssImportsSpecified || tailwindcssMajorVersion >= 4);
2148
+ const shouldOwnTailwindGeneration = !disabledOptions.plugin;
2149
+ const shouldRewriteCssImports = tailwindcssMajorVersion >= 4;
1882
2150
  const rewritePlugins = createRewriteCssImportsPlugins({
1883
2151
  getAppType: () => opts.appType,
1884
2152
  rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
2153
+ shouldOwnTailwindGeneration,
1885
2154
  shouldRewrite: shouldRewriteCssImports,
1886
2155
  weappTailwindcssDirPosix
1887
2156
  });
1888
2157
  if (disabledOptions.plugin) return rewritePlugins.length ? rewritePlugins : void 0;
1889
- const customAttributesEntities = require_recorder.toCustomAttributesEntities(customAttributes);
1890
- const patchRecorderState = require_recorder.setupPatchRecorder(initialTwPatcher, opts.tailwindcssBasedir, {
1891
- source: "runtime",
1892
- cwd: opts.tailwindcssBasedir ?? node_process.default.cwd()
1893
- });
1894
- const runtimeState = {
1895
- twPatcher: initialTwPatcher,
1896
- patchPromise: patchRecorderState.patchPromise,
1897
- refreshTailwindcssPatcher,
1898
- onPatchCompleted: patchRecorderState.onPatchCompleted
1899
- };
1900
- let runtimeSet;
1901
- let runtimeSetPromise;
2158
+ const customAttributesEntities = require_precheck.toCustomAttributesEntities(customAttributes);
1902
2159
  let resolvedConfig;
1903
- let runtimeRefreshSignature;
1904
- let runtimeRefreshOptionsKey;
1905
2160
  let recordedGeneratorCandidates;
1906
- const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager();
1907
2161
  const sourceCandidateCollector = createSourceCandidateCollector();
1908
2162
  const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
1909
2163
  const processedCssAssets = /* @__PURE__ */ new WeakSet();
1910
2164
  const processedCssAssetFiles = /* @__PURE__ */ new Set();
1911
2165
  const rememberedMainCssSources = /* @__PURE__ */ new Map();
1912
2166
  const rememberedMainCssSignatureByFile = /* @__PURE__ */ new Map();
1913
- function resolveRuntimeRefreshOptions() {
1914
- const configPath = require_patcher_options.resolveTailwindcssOptions(runtimeState.twPatcher.options)?.config;
1915
- const signature = require_logger.getRuntimeClassSetSignature(runtimeState.twPatcher);
1916
- const optionsKey = JSON.stringify({
1917
- appType: opts.appType,
1918
- uniAppX: uniAppXEnabled,
1919
- customAttributesEntities,
1920
- disabledDefaultTemplateHandler,
1921
- configPath,
1922
- rewriteCssImports: shouldRewriteCssImports
1923
- });
1924
- const changed = signature !== runtimeRefreshSignature || optionsKey !== runtimeRefreshOptionsKey;
1925
- runtimeRefreshSignature = signature;
1926
- runtimeRefreshOptionsKey = optionsKey;
1927
- return {
1928
- changed,
1929
- signature,
1930
- optionsKey
1931
- };
1932
- }
1933
- async function refreshRuntimeState(force) {
1934
- const invalidation = resolveRuntimeRefreshOptions();
1935
- const refreshed = await require_recorder.refreshTailwindRuntimeState(runtimeState, {
1936
- force: force || invalidation.changed,
1937
- clearCache: force || invalidation.changed
1938
- });
1939
- if (invalidation.changed) debug("runtime signature changed, refresh triggered. signature: %s", invalidation.signature);
1940
- if (refreshed) {
1941
- runtimeSet = void 0;
1942
- runtimeSetPromise = void 0;
1943
- }
1944
- }
1945
- async function ensureRuntimeClassSet(force = false) {
1946
- const forceRuntimeRefresh = force || node_process.default.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
1947
- await refreshRuntimeState(force);
1948
- await runtimeState.patchPromise;
1949
- if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
1950
- if (forceRuntimeRefresh || !runtimeSetPromise) {
1951
- const invalidation = resolveRuntimeRefreshOptions();
1952
- runtimeSetPromise = require_recorder.collectRuntimeClassSet(runtimeState.twPatcher, {
1953
- force: forceRuntimeRefresh || invalidation.changed,
1954
- skipRefresh: forceRuntimeRefresh,
1955
- clearCache: forceRuntimeRefresh || invalidation.changed
1956
- });
1957
- }
1958
- const task = runtimeSetPromise;
1959
- try {
1960
- runtimeSet = await task;
1961
- return runtimeSet;
1962
- } finally {
1963
- if (runtimeSetPromise === task) runtimeSetPromise = void 0;
1964
- }
1965
- }
1966
- async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false) {
1967
- const forceRuntimeRefresh = forceRefresh || node_process.default.env.WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH === "1";
1968
- const invalidation = resolveRuntimeRefreshOptions();
1969
- const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
1970
- const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
1971
- await refreshRuntimeState(shouldRefreshPatcher);
1972
- await runtimeState.patchPromise;
1973
- if (shouldRefreshPatcher) {
1974
- runtimeSet = void 0;
1975
- runtimeSetPromise = void 0;
1976
- await bundleRuntimeClassSetManager.reset();
1977
- }
1978
- if (runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) try {
1979
- const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
1980
- runtimeSet = nextRuntimeSet;
1981
- return nextRuntimeSet;
1982
- } catch (error) {
1983
- debug("incremental runtime set sync failed, fallback to full collect: %O", error);
1984
- await bundleRuntimeClassSetManager.reset();
1985
- }
1986
- if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
1987
- const task = require_recorder.collectRuntimeClassSet(runtimeState.twPatcher, {
1988
- force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
1989
- skipRefresh: forceRuntimeRefresh,
1990
- clearCache: forceRuntimeRefresh || invalidation.changed
1991
- });
1992
- runtimeSetPromise = task;
1993
- try {
1994
- runtimeSet = await task;
1995
- return runtimeSet;
1996
- } finally {
1997
- if (runtimeSetPromise === task) runtimeSetPromise = void 0;
1998
- }
1999
- }
2167
+ const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
2168
+ opts,
2169
+ initialTwPatcher,
2170
+ refreshTailwindcssPatcher,
2171
+ uniAppXEnabled,
2172
+ customAttributesEntities,
2173
+ disabledDefaultTemplateHandler,
2174
+ debug
2175
+ });
2000
2176
  onLoad();
2001
2177
  const getResolvedConfig = () => resolvedConfig;
2002
2178
  const markCssAssetProcessed = (asset, file) => {
2003
2179
  processedCssAssets.add(asset);
2004
- if (file) processedCssAssetFiles.add(require_css_imports.normalizeOutputPathKey(file));
2180
+ if (file) processedCssAssetFiles.add(require_run_tasks.normalizeOutputPathKey(file));
2005
2181
  };
2006
2182
  const isCssAssetProcessed = (asset, file) => {
2007
- return processedCssAssets.has(asset) || (file ? processedCssAssetFiles.has(require_css_imports.normalizeOutputPathKey(file)) : false);
2183
+ return processedCssAssets.has(asset) || (file ? processedCssAssetFiles.has(require_run_tasks.normalizeOutputPathKey(file)) : false);
2008
2184
  };
2009
2185
  const recordGeneratorCandidates = (candidates) => {
2010
2186
  recordedGeneratorCandidates = new Set(candidates);
@@ -2064,7 +2240,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
2064
2240
  const plugins = [
2065
2241
  ...rewritePlugins,
2066
2242
  {
2067
- name: `${require_recorder.vitePluginName}:source-candidates`,
2243
+ name: `${require_precheck.vitePluginName}:source-candidates`,
2068
2244
  enforce: "pre",
2069
2245
  async transform(code, id) {
2070
2246
  if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return;
@@ -2089,10 +2265,22 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
2089
2265
  root,
2090
2266
  outDir
2091
2267
  });
2268
+ const basedir = opts.tailwindcssBasedir ? node_path.default.resolve(opts.tailwindcssBasedir) : void 0;
2269
+ if (basedir && basedir !== node_path.default.resolve(root)) await sourceCandidateCollector.scanRoot({
2270
+ root: basedir,
2271
+ outDir
2272
+ });
2273
+ for (const cssEntry of opts.tailwindcss?.cssEntries ?? []) {
2274
+ const cssEntryRoot = node_path.default.dirname(node_path.default.resolve(cssEntry));
2275
+ if (cssEntryRoot !== node_path.default.resolve(root) && cssEntryRoot !== basedir) await sourceCandidateCollector.scanRoot({
2276
+ root: cssEntryRoot,
2277
+ outDir
2278
+ });
2279
+ }
2092
2280
  }
2093
2281
  },
2094
2282
  {
2095
- name: `${require_recorder.vitePluginName}:post`,
2283
+ name: `${require_precheck.vitePluginName}:post`,
2096
2284
  enforce: "post",
2097
2285
  config(config) {
2098
2286
  if (!shouldOwnTailwindGeneration) return;
@@ -2191,9 +2379,9 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
2191
2379
  return plugins;
2192
2380
  }
2193
2381
  //#endregion
2194
- Object.defineProperty(exports, "UnifiedViteWeappTailwindcssPlugin", {
2382
+ Object.defineProperty(exports, "WeappTailwindcss", {
2195
2383
  enumerable: true,
2196
2384
  get: function() {
2197
- return UnifiedViteWeappTailwindcssPlugin;
2385
+ return WeappTailwindcss;
2198
2386
  }
2199
2387
  });