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

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 (244) hide show
  1. package/README.md +6 -7
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/auto-TH1jG2UW.js +115 -0
  4. package/dist/auto-XyKTOP7B.mjs +78 -0
  5. package/dist/bundle-state-Bi-cQua6.mjs +413 -0
  6. package/dist/bundle-state-Ct_8GcSR.js +529 -0
  7. package/dist/bundlers/shared/cache.d.ts +6 -6
  8. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -0
  9. package/dist/bundlers/shared/css-cleanup.d.ts +1 -4
  10. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  11. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  12. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  13. package/dist/bundlers/shared/generator-css/directives.d.ts +21 -0
  14. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  15. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  16. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  17. package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
  18. package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
  19. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
  20. package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
  21. package/dist/bundlers/shared/generator-css.d.ts +16 -22
  22. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  23. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  24. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  25. package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
  26. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  27. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
  28. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
  29. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  30. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  31. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  32. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  33. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  34. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  35. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  36. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  37. package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
  38. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
  39. package/dist/bundlers/vite/index.d.ts +5 -2
  40. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  41. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  42. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  43. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
  44. package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
  45. package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
  46. package/dist/bundlers/vite/source-candidates.d.ts +19 -1
  47. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  48. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  49. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  50. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
  51. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +6 -2
  52. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +9 -3
  53. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +2 -1
  54. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  55. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -6
  56. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  57. package/dist/cache/index.d.ts +6 -6
  58. package/dist/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
  59. package/dist/cli/context.d.ts +1 -14
  60. package/dist/cli/doctor/types.d.ts +11 -11
  61. package/dist/cli/helpers.d.ts +1 -2
  62. package/dist/cli/mount-options.d.ts +2 -0
  63. package/dist/cli/types.d.ts +0 -2
  64. package/dist/cli/vscode-entry.d.ts +3 -3
  65. package/dist/cli.js +758 -604
  66. package/dist/cli.mjs +766 -612
  67. package/dist/constants.d.ts +1 -2
  68. package/dist/context/runtime-package-replacements.d.ts +2 -0
  69. package/dist/context/style-options.d.ts +3 -0
  70. package/dist/core.js +12 -20
  71. package/dist/core.mjs +8 -14
  72. package/dist/css-macro/auto.d.ts +10 -0
  73. package/dist/css-macro/constants.d.ts +5 -2
  74. package/dist/css-macro/postcss.d.ts +1 -0
  75. package/dist/css-macro/postcss.js +7 -46
  76. package/dist/css-macro/postcss.mjs +2 -46
  77. package/dist/css-macro.d.ts +1 -0
  78. package/dist/css-macro.js +16 -7
  79. package/dist/css-macro.mjs +15 -6
  80. package/dist/defaults-8xrgzxFY.mjs +151 -0
  81. package/dist/defaults-zKUH2mDe.js +193 -0
  82. package/dist/defaults.d.ts +15 -1
  83. package/dist/defaults.js +6 -131
  84. package/dist/defaults.mjs +2 -129
  85. package/dist/escape.js +10 -2
  86. package/dist/escape.mjs +10 -2
  87. package/dist/generator/index.d.ts +1 -1
  88. package/dist/generator/options.d.ts +9 -8
  89. package/dist/generator/types.d.ts +3 -3
  90. package/dist/generator-CrU-Ghc1.js +90 -0
  91. package/dist/generator-Qw-tZ0Z2.mjs +65 -0
  92. package/dist/generator.js +12 -12
  93. package/dist/generator.mjs +2 -1
  94. package/dist/gulp.js +187 -48
  95. package/dist/gulp.mjs +180 -41
  96. package/dist/incremental-runtime-class-set-Boqi1QlB.mjs +2224 -0
  97. package/dist/incremental-runtime-class-set-FAOHZmzh.js +2293 -0
  98. package/dist/index.d.ts +3 -2
  99. package/dist/index.js +19 -7
  100. package/dist/index.mjs +6 -5
  101. package/dist/js/babel/cache-options.d.ts +3 -0
  102. package/dist/js/babel/parse.d.ts +7 -4
  103. package/dist/js/index.d.ts +1 -0
  104. package/dist/js/literal-transform.d.ts +2 -0
  105. package/dist/js/precheck.d.ts +2 -2
  106. package/dist/logger-BNzxZbZj.mjs +2 -0
  107. package/dist/logger-TlKT3xmR.js +1 -0
  108. package/dist/postcss/config-directive.d.ts +1 -0
  109. package/dist/postcss/context.d.ts +9 -0
  110. package/dist/postcss/source-files.d.ts +8 -0
  111. package/dist/postcss/tailwind-version.d.ts +3 -0
  112. package/dist/postcss-C6zOQqlL.mjs +228 -0
  113. package/dist/postcss-C7BMYpEF.mjs +169 -0
  114. package/dist/postcss-CiYLsqZn.js +192 -0
  115. package/dist/postcss-DAWf9D3C.js +237 -0
  116. package/dist/postcss-html-transform.js +1 -1
  117. package/dist/postcss.d.ts +2 -2
  118. package/dist/postcss.js +3 -276
  119. package/dist/postcss.mjs +1 -269
  120. package/dist/precheck-D7K12zeX.mjs +4716 -0
  121. package/dist/precheck-D7gJSmJz.js +4842 -0
  122. package/dist/presets/index.d.ts +1 -0
  123. package/dist/presets/uni-app-x.d.ts +1 -0
  124. package/dist/presets.js +29 -13
  125. package/dist/presets.mjs +25 -11
  126. package/dist/reset.d.ts +1 -0
  127. package/dist/reset.js +1 -1
  128. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  129. package/dist/shared/mpx.d.ts +1 -0
  130. package/dist/source-candidates-CX2ozpKM.mjs +322 -0
  131. package/dist/source-candidates-DNM8iwXW.js +335 -0
  132. package/dist/tailwindcss/miniprogram.d.ts +1 -1
  133. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  134. package/dist/tailwindcss/patcher.d.ts +1 -2
  135. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  136. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  137. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  138. package/dist/tailwindcss/runtime.d.ts +11 -12
  139. package/dist/tailwindcss/source-scan.d.ts +35 -0
  140. package/dist/tailwindcss/targets.d.ts +1 -5
  141. package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
  142. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  143. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  144. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  145. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  146. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  147. package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
  148. package/dist/tailwindcss/version.d.ts +4 -0
  149. package/dist/tailwindcss-B-e2RiXr.js +642 -0
  150. package/dist/tailwindcss-C7dJHZ0G.mjs +591 -0
  151. package/dist/typedoc.export.d.ts +0 -2
  152. package/dist/types/index.d.ts +52 -49
  153. package/dist/types/shared.d.ts +6 -0
  154. package/dist/types/user-defined-options/general.d.ts +25 -24
  155. package/dist/types/user-defined-options/important.d.ts +33 -28
  156. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  157. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  158. package/dist/uni-app-x/vite.d.ts +1 -1
  159. package/dist/unocss/index.d.ts +2 -0
  160. package/dist/utils/disabled.d.ts +2 -3
  161. package/dist/utils/object.d.ts +9 -0
  162. package/dist/utils/options.d.ts +2 -0
  163. package/dist/utils/regex.d.ts +1 -0
  164. package/dist/{utils-DmC9_In3.js → utils-D7Ygohep.js} +2 -2
  165. package/dist/{utils-7DUGTFED.mjs → utils-DsaS975I.mjs} +1 -1
  166. package/dist/v3-engine-CHItlVq5.js +3616 -0
  167. package/dist/v3-engine-DcvCCHfs.mjs +3321 -0
  168. package/dist/vite-BgTPSkQS.js +24446 -0
  169. package/dist/vite-fFRpSvyz.mjs +24432 -0
  170. package/dist/vite.d.ts +1 -2
  171. package/dist/vite.js +3 -4
  172. package/dist/vite.mjs +2 -2
  173. package/dist/weapp-tw-css-import-rewrite-loader.js +5227 -18
  174. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  175. package/dist/webpack-BXSWVdXh.js +851 -0
  176. package/dist/webpack-Dx2AZpGU.mjs +841 -0
  177. package/dist/webpack.d.ts +1 -3
  178. package/dist/webpack.js +3 -4
  179. package/dist/webpack.mjs +2 -2
  180. package/package.json +38 -48
  181. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  182. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  183. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  184. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  185. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  186. package/dist/cli/config.d.ts +0 -5
  187. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  188. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  189. package/dist/cli/patch-options.d.ts +0 -6
  190. package/dist/cli/tokens.d.ts +0 -4
  191. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  192. package/dist/cli/workspace/patch-package.d.ts +0 -3
  193. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  194. package/dist/cli/workspace/types.d.ts +0 -11
  195. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  196. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  197. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  198. package/dist/cli/workspace.d.ts +0 -2
  199. package/dist/constants-B-_T5UnW.mjs +0 -44
  200. package/dist/constants-p1dyh1x1.js +0 -73
  201. package/dist/css-imports-BbrbluP9.js +0 -177
  202. package/dist/css-imports-CSdPq_Sc.mjs +0 -128
  203. package/dist/experimental/index.d.ts +0 -2
  204. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  205. package/dist/experimental/oxc/index.d.ts +0 -2
  206. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  207. package/dist/experimental/shared/cache.d.ts +0 -3
  208. package/dist/experimental/shared/transform.d.ts +0 -3
  209. package/dist/experimental/shared.d.ts +0 -8
  210. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  211. package/dist/experimental/swc/index.d.ts +0 -2
  212. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  213. package/dist/generator-Y-Ikv4Fu.mjs +0 -1177
  214. package/dist/generator-css-Bwy_Uz89.mjs +0 -1097
  215. package/dist/generator-css-CRLrHW4F.js +0 -1124
  216. package/dist/generator-mmhXzZnv.js +0 -1276
  217. package/dist/js/syntax.d.ts +0 -10
  218. package/dist/lightningcss/index.d.ts +0 -8
  219. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  220. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  221. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  222. package/dist/lightningcss/style-handler.d.ts +0 -17
  223. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  224. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  225. package/dist/logger-BZ45DZJT.js +0 -1003
  226. package/dist/logger-BoVx1Dbt.mjs +0 -935
  227. package/dist/patcher-options-6gJN2EXy.js +0 -115
  228. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  229. package/dist/recorder-GdTJ3QqX.js +0 -2878
  230. package/dist/recorder-XdFvVASS.mjs +0 -2763
  231. package/dist/tailwindcss/recorder.d.ts +0 -13
  232. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  233. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  234. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  235. package/dist/tailwindcss/targets/types.d.ts +0 -35
  236. package/dist/types/disabled-options.d.ts +0 -4
  237. package/dist/vite-BDywuCjn.mjs +0 -2186
  238. package/dist/vite-DgRh_GXn.js +0 -2199
  239. package/dist/webpack-CAJR4hhP.js +0 -456
  240. package/dist/webpack-CiHqVZTg.mjs +0 -441
  241. package/dist/webpack4.d.ts +0 -4
  242. package/dist/webpack4.js +0 -387
  243. package/dist/webpack4.mjs +0 -379
  244. package/scripts/postinstall.mjs +0 -59
@@ -0,0 +1,841 @@
1
+ import { b as ensureRuntimeClassSet, d as _defineProperty, f as init_defineProperty, i as pluginName, n as getCompilerContext, t as shouldSkipJsTransform, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./precheck-D7K12zeX.mjs";
2
+ import { B as createDebug, W as resolveTailwindcssOptions, l as getRuntimeClassSetSignature } from "./v3-engine-DcvCCHfs.mjs";
3
+ import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-Qw-tZ0Z2.mjs";
4
+ import { i as generateCssByGenerator, r as emitHmrTiming, s as processCachedTask, t as createBundleRuntimeClassSetManager } from "./incremental-runtime-class-set-Boqi1QlB.mjs";
5
+ import { r as getGroupedEntries } from "./utils-DsaS975I.mjs";
6
+ import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-C7dJHZ0G.mjs";
7
+ import { _ as stripRequestQuery, b as toAbsoluteOutputPath, d as resolvePluginDisabledState, g as isSourceStyleRequest, l as stripBundlerGeneratedCssMarkers, n as createBundleBuildState, o as pushConcurrentTaskFactories, r as updateBundleBuildState, t as buildBundleSnapshot, u as resolvePackageDir, y as resolveOutputSpecifier } from "./bundle-state-Bi-cQua6.mjs";
8
+ import Module, { createRequire } from "node:module";
9
+ import fs from "node:fs";
10
+ import path from "node:path";
11
+ import process from "node:process";
12
+ import { fileURLToPath } from "node:url";
13
+ //#region src/shared/tailwindcss-css-redirect.ts
14
+ const moduleWithMutableResolve = Module;
15
+ const patched = /* @__PURE__ */ new WeakSet();
16
+ function installTailwindcssCssRedirect(pkgDir) {
17
+ const target = path.join(pkgDir, "index.css");
18
+ const original = moduleWithMutableResolve._resolveFilename;
19
+ if (patched.has(original)) return;
20
+ const replacements = new Set(["tailwindcss", "tailwindcss$"]);
21
+ const resolveTailwindcssCss = (request, parent, isMain, options) => {
22
+ if (replacements.has(request)) return target;
23
+ if (request.startsWith("tailwindcss/")) return path.join(pkgDir, request.slice(12));
24
+ return original(request, parent, isMain, options);
25
+ };
26
+ moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
27
+ patched.add(moduleWithMutableResolve._resolveFilename);
28
+ }
29
+ //#endregion
30
+ //#region src/shared/mpx.ts
31
+ const localRequire = createRequire(import.meta.url);
32
+ const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
33
+ const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
34
+ function isMpxStyleResourceQuery(query) {
35
+ if (typeof query !== "string") return false;
36
+ return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
37
+ }
38
+ function isMpx(appType) {
39
+ return appType === "mpx";
40
+ }
41
+ function getTailwindcssCssEntry(pkgDir) {
42
+ return path.join(pkgDir, "index.css");
43
+ }
44
+ function resolveMpxWebpackPluginDir(compiler) {
45
+ const candidates = [
46
+ compiler?.context,
47
+ compiler?.options?.context,
48
+ process.cwd()
49
+ ].filter((item) => typeof item === "string" && item.length > 0);
50
+ for (const candidate of candidates) try {
51
+ const projectRequire = createRequire(path.join(candidate, "package.json"));
52
+ return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
53
+ } catch {}
54
+ const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
55
+ if (cachedPackageJson) return path.dirname(cachedPackageJson);
56
+ try {
57
+ return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
58
+ } catch {
59
+ return;
60
+ }
61
+ }
62
+ function isMpxWebpackPluginRequest(request) {
63
+ return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
64
+ }
65
+ function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
66
+ if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
67
+ return path.join(mpxWebpackPluginDir, request.slice(22));
68
+ }
69
+ function addMpxWebpackPluginAlias(alias, pkgDir) {
70
+ const recordLoader = path.join(pkgDir, "lib/record-loader");
71
+ const styleCompiler = path.join(pkgDir, "lib/style-compiler/index");
72
+ const stripConditionalLoader = path.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
73
+ if (Array.isArray(alias)) alias.push({
74
+ name: "@mpxjs/webpack-plugin/lib/record-loader",
75
+ alias: recordLoader
76
+ }, {
77
+ name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
78
+ alias: styleCompiler
79
+ }, {
80
+ name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
81
+ alias: stripConditionalLoader
82
+ }, {
83
+ name: /^@mpxjs\/webpack-plugin\//,
84
+ alias: pkgDir
85
+ });
86
+ else {
87
+ alias["@mpxjs/webpack-plugin"] = pkgDir;
88
+ alias["@mpxjs/webpack-plugin$"] = pkgDir;
89
+ alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
90
+ alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
91
+ alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
92
+ }
93
+ }
94
+ function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
95
+ compiler.options.resolveLoader = compiler.options.resolveLoader || {};
96
+ const alias = compiler.options.resolveLoader.alias ?? {};
97
+ compiler.options.resolveLoader.alias = alias;
98
+ addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
99
+ }
100
+ function resolveMpxWebpackPluginRequire(compiler) {
101
+ const candidates = [
102
+ compiler?.context,
103
+ compiler?.options?.context,
104
+ process.cwd()
105
+ ].filter((item) => typeof item === "string" && item.length > 0);
106
+ for (const candidate of candidates) try {
107
+ const projectRequire = createRequire(path.join(candidate, "package.json"));
108
+ projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
109
+ return projectRequire;
110
+ } catch {}
111
+ const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
112
+ if (cachedPackageJson) return createRequire(cachedPackageJson);
113
+ return localRequire;
114
+ }
115
+ function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
116
+ if (!mpxWebpackPluginDir) return false;
117
+ const projectRequire = resolveMpxWebpackPluginRequire(compiler);
118
+ let normalize;
119
+ try {
120
+ normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
121
+ } catch {
122
+ return false;
123
+ }
124
+ if (typeof normalize.lib !== "function") return false;
125
+ if (normalize.lib.__weappTwPatched) return true;
126
+ const wrappedLib = (file) => path.join(mpxWebpackPluginDir, "lib", file);
127
+ wrappedLib.__weappTwPatched = true;
128
+ wrappedLib.__weappTwOriginal = normalize.lib;
129
+ normalize.lib = wrappedLib;
130
+ return true;
131
+ }
132
+ function ensureMpxTailwindcssAliases(compiler, pkgDir) {
133
+ const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
134
+ compiler.options = compiler.options || {};
135
+ compiler.options.resolve = compiler.options.resolve || {};
136
+ const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
137
+ patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
138
+ if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
139
+ const alias = compiler.options.resolve.alias ?? {};
140
+ compiler.options.resolve.alias = alias;
141
+ if (Array.isArray(alias)) alias.push({
142
+ name: "tailwindcss",
143
+ alias: tailwindcssCssEntry
144
+ }, {
145
+ name: "tailwindcss$",
146
+ alias: tailwindcssCssEntry
147
+ });
148
+ else {
149
+ alias.tailwindcss = tailwindcssCssEntry;
150
+ alias.tailwindcss$ = tailwindcssCssEntry;
151
+ }
152
+ if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
153
+ return tailwindcssCssEntry;
154
+ }
155
+ function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
156
+ if (!enabled || typeof loaderContext.resolve !== "function") return;
157
+ const originalResolve = loaderContext.resolve;
158
+ if (originalResolve.__weappTwPatched) return;
159
+ const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
160
+ const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
161
+ const wrappedResolve = function(context, request, callback) {
162
+ if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
163
+ if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
164
+ if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
165
+ return originalResolve.call(this, context, request, callback);
166
+ };
167
+ wrappedResolve.__weappTwPatched = true;
168
+ loaderContext.resolve = wrappedResolve;
169
+ }
170
+ function setupMpxTailwindcssRedirect(pkgDir, enabled) {
171
+ if (enabled) installTailwindcssCssRedirect(pkgDir);
172
+ }
173
+ const CSS_EXT_RE = /\.css$/i;
174
+ function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
175
+ var _compiler$options;
176
+ if (!loader) return;
177
+ const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
178
+ moduleOptions.rules = moduleOptions.rules || [];
179
+ const createRule = (match) => ({
180
+ ...match,
181
+ enforce: "pre",
182
+ use: [{
183
+ loader,
184
+ options: loaderOptions
185
+ }]
186
+ });
187
+ moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
188
+ test: CSS_EXT_RE,
189
+ resourceQuery: (query) => !isMpxStyleResourceQuery(query)
190
+ }));
191
+ }
192
+ //#endregion
193
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
194
+ const MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
195
+ function getCacheKey(filename) {
196
+ return filename;
197
+ }
198
+ function stripResourceQuery(resource) {
199
+ if (typeof resource !== "string") return resource;
200
+ return stripRequestQuery(resource);
201
+ }
202
+ function isCssLikeModuleResource(resource, cssMatcher, appType) {
203
+ if (typeof resource !== "string") return false;
204
+ const normalizedResource = stripResourceQuery(resource);
205
+ if (normalizedResource && cssMatcher(normalizedResource)) return true;
206
+ if (isSourceStyleRequest(resource)) return true;
207
+ if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
208
+ return false;
209
+ }
210
+ function hasLoaderEntry(entries, target) {
211
+ if (!target) return false;
212
+ return entries.some((entry) => entry.loader?.includes?.(target));
213
+ }
214
+ function normalizeWatchPath(file) {
215
+ return path.resolve(file);
216
+ }
217
+ function isFileInContext(file, context) {
218
+ const relative = path.relative(normalizeWatchPath(context), normalizeWatchPath(file));
219
+ return relative.length > 0 && !relative.startsWith("..") && !path.isAbsolute(relative);
220
+ }
221
+ function toChunkFiles(files) {
222
+ if (!files) return [];
223
+ if (Array.isArray(files)) return files;
224
+ return [...files];
225
+ }
226
+ function createAssetHashByChunkMap(chunks) {
227
+ const partsByFile = /* @__PURE__ */ new Map();
228
+ for (const chunk of chunks) {
229
+ const hash = typeof chunk.hash === "string" ? chunk.hash : void 0;
230
+ if (!hash) continue;
231
+ const chunkId = String(chunk.id ?? chunk.name ?? "");
232
+ for (const file of toChunkFiles(chunk.files)) {
233
+ if (!file) continue;
234
+ let parts = partsByFile.get(file);
235
+ if (!parts) {
236
+ parts = [];
237
+ partsByFile.set(file, parts);
238
+ }
239
+ parts.push(`${chunkId}:${hash}`);
240
+ }
241
+ }
242
+ const hashByFile = /* @__PURE__ */ new Map();
243
+ for (const [file, parts] of partsByFile.entries()) hashByFile.set(file, parts.sort().join("|"));
244
+ return hashByFile;
245
+ }
246
+ function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
247
+ return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
248
+ }
249
+ function isWatchFileInRuntimeDependencies(file, dependencies) {
250
+ const normalizedFile = normalizeWatchPath(file);
251
+ for (const dependency of dependencies.files ?? []) if (normalizeWatchPath(dependency) === normalizedFile) return true;
252
+ for (const context of dependencies.contexts ?? []) if (isFileInContext(normalizedFile, context)) return true;
253
+ return false;
254
+ }
255
+ //#endregion
256
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
257
+ function createWebpackSnapshotAssets(assets) {
258
+ return Object.fromEntries(Object.entries(assets).map(([file, asset]) => {
259
+ const source = asset.source();
260
+ return [file, {
261
+ fileName: file,
262
+ source: typeof source === "string" ? source : source?.toString() ?? "",
263
+ type: "asset"
264
+ }];
265
+ }));
266
+ }
267
+ function setupWebpackV5ProcessAssetsHook(options) {
268
+ const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, debug } = options;
269
+ const { Compilation, sources } = compiler.webpack;
270
+ const { ConcatSource } = sources;
271
+ const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
272
+ const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
273
+ const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
274
+ const bundleBuildState = createBundleBuildState();
275
+ const bundleRuntimeClassSetManager = runtimeClassSetManager ?? createBundleRuntimeClassSetManager();
276
+ let webpackWatchRuntimeScanInitialized = false;
277
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
278
+ compilation.hooks.processAssets.tapPromise({
279
+ name: pluginName,
280
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
281
+ }, async (assets) => {
282
+ compilerOptions.onStart();
283
+ debug("start");
284
+ await runtimeState.readyPromise;
285
+ const hmrTimingStartedAt = performance.now();
286
+ for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
287
+ const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
288
+ const entries = Object.entries(assets);
289
+ const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
290
+ const outputDir = compilerOutputPath ? path.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? process.cwd();
291
+ const jsAssets = /* @__PURE__ */ new Map();
292
+ for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
293
+ const absolute = toAbsoluteOutputPath(file, outputDir);
294
+ jsAssets.set(absolute, file);
295
+ }
296
+ const moduleGraphOptions = {
297
+ resolve(specifier, importer) {
298
+ return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
299
+ },
300
+ load: (id) => {
301
+ const assetName = jsAssets.get(id);
302
+ if (!assetName) return;
303
+ const asset = compilation.getAsset(assetName);
304
+ if (!asset) return;
305
+ const source = asset.source.source();
306
+ return typeof source === "string" ? source : source.toString();
307
+ },
308
+ filter(id) {
309
+ return jsAssets.has(id);
310
+ }
311
+ };
312
+ const applyLinkedResults = (linked) => {
313
+ if (!linked) return;
314
+ for (const [id, { code }] of Object.entries(linked)) {
315
+ const assetName = jsAssets.get(id);
316
+ if (!assetName) continue;
317
+ const asset = compilation.getAsset(assetName);
318
+ if (!asset) continue;
319
+ const previousSource = asset.source.source();
320
+ const previous = typeof previousSource === "string" ? previousSource : previousSource.toString();
321
+ if (previous === code) continue;
322
+ const source = new ConcatSource(code);
323
+ compilation.updateAsset(assetName, source);
324
+ compilerOptions.onUpdate(assetName, previous, code);
325
+ debug("js linked handle: %s", assetName);
326
+ }
327
+ };
328
+ const groupedEntries = getGroupedEntries(entries, compilerOptions);
329
+ const getCssHandlerOptions = (file) => {
330
+ const majorVersion = runtimeState.twPatcher.majorVersion;
331
+ const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
332
+ const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
333
+ const cached = cssHandlerOptionsCache.get(cacheKey);
334
+ if (cached) return cached;
335
+ const created = {
336
+ isMainChunk,
337
+ postcssOptions: { options: { from: file } },
338
+ ...majorVersion === void 0 ? {} : { majorVersion }
339
+ };
340
+ cssHandlerOptionsCache.set(cacheKey, created);
341
+ return created;
342
+ };
343
+ const getCssUserHandlerOptions = (file) => {
344
+ const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
345
+ const cached = cssUserHandlerOptionsCache.get(cacheKey);
346
+ if (cached) return cached;
347
+ const created = {
348
+ ...getCssHandlerOptions(file),
349
+ isMainChunk: false
350
+ };
351
+ cssUserHandlerOptionsCache.set(cacheKey, created);
352
+ return created;
353
+ };
354
+ const forceRuntimeRefresh = getRuntimeRefreshRequirement();
355
+ debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
356
+ let runtimeSet;
357
+ const watchMode = isWatchMode?.() === true;
358
+ if (watchMode && runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
359
+ const snapshot = buildBundleSnapshot(createWebpackSnapshotAssets(assets), compilerOptions, outputDir, bundleBuildState);
360
+ if (!webpackWatchRuntimeScanInitialized) {
361
+ for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
362
+ }
363
+ try {
364
+ runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
365
+ } catch (error) {
366
+ debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
367
+ await bundleRuntimeClassSetManager.reset();
368
+ runtimeSet = await ensureRuntimeClassSet(runtimeState, {
369
+ forceRefresh: false,
370
+ forceCollect: true,
371
+ clearCache: false,
372
+ allowEmpty: false
373
+ });
374
+ }
375
+ updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
376
+ webpackWatchRuntimeScanInitialized = true;
377
+ } else {
378
+ if (forceRuntimeRefresh) {
379
+ await bundleRuntimeClassSetManager.reset();
380
+ webpackWatchRuntimeScanInitialized = false;
381
+ }
382
+ runtimeSet = await ensureRuntimeClassSet(runtimeState, {
383
+ forceRefresh: forceRuntimeRefresh,
384
+ forceCollect: !watchMode || forceRuntimeRefresh,
385
+ clearCache: forceRuntimeRefresh,
386
+ allowEmpty: false
387
+ });
388
+ }
389
+ await refreshRuntimeMetadata(forceRuntimeRefresh);
390
+ consumeRuntimeRefreshRequirement();
391
+ const runtimeSetHash = compilerOptions.cache.computeHash([getRuntimeClassSetSignature(runtimeState.twPatcher), [...runtimeSet].sort().join("\n")].join("\n\n"));
392
+ const defaultTemplateHandlerOptions = { runtimeSet };
393
+ debug("get runtimeSet, class count: %d", runtimeSet.size);
394
+ const tasks = [];
395
+ if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
396
+ const [file, originalSource] = element;
397
+ const rawSource = originalSource.source().toString();
398
+ const cacheKey = file;
399
+ const chunkHash = assetHashByChunk.get(file);
400
+ tasks.push(processCachedTask({
401
+ cache: compilerOptions.cache,
402
+ cacheKey,
403
+ hashKey: `${file}:asset`,
404
+ rawSource,
405
+ hash: chunkHash,
406
+ applyResult(source) {
407
+ compilation.updateAsset(file, source);
408
+ },
409
+ onCacheHit() {
410
+ debug("html cache hit: %s", file);
411
+ },
412
+ transform: async () => {
413
+ const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
414
+ const source = new ConcatSource(wxml);
415
+ compilerOptions.onUpdate(file, rawSource, wxml);
416
+ debug("html handle: %s", file);
417
+ return { result: source };
418
+ }
419
+ }));
420
+ }
421
+ const jsTaskFactories = [];
422
+ if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
423
+ const cacheKey = getCacheKey(file);
424
+ const asset = compilation.getAsset(file);
425
+ if (!asset) continue;
426
+ const absoluteFile = toAbsoluteOutputPath(file, outputDir);
427
+ const initialSource = asset.source.source();
428
+ const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
429
+ const chunkHash = assetHashByChunk.get(file);
430
+ jsTaskFactories.push(async () => {
431
+ await processCachedTask({
432
+ cache: compilerOptions.cache,
433
+ cacheKey,
434
+ hashKey: `${file}:asset`,
435
+ rawSource: initialRawSource,
436
+ hash: chunkHash,
437
+ applyResult(source) {
438
+ compilation.updateAsset(file, source);
439
+ },
440
+ onCacheHit() {
441
+ debug("js cache hit: %s", file);
442
+ },
443
+ transform: async () => {
444
+ const currentSourceValue = compilation.getAsset(file)?.source.source();
445
+ const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
446
+ const handlerOptions = {
447
+ tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
448
+ filename: absoluteFile,
449
+ moduleGraph: moduleGraphOptions,
450
+ babelParserOptions: { sourceFilename: absoluteFile }
451
+ };
452
+ if (shouldSkipJsTransform(currentSource, {
453
+ ...handlerOptions,
454
+ classNameSet: runtimeSet
455
+ })) return { result: new ConcatSource(currentSource) };
456
+ const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
457
+ const source = new ConcatSource(code);
458
+ compilerOptions.onUpdate(file, currentSource, code);
459
+ debug("js handle: %s", file);
460
+ applyLinkedResults(linked);
461
+ return { result: source };
462
+ }
463
+ });
464
+ });
465
+ }
466
+ if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
467
+ const [file, originalSource] = element;
468
+ const rawSource = originalSource.source().toString();
469
+ if (isWebpackProcessedCssAsset?.(file, rawSource)) {
470
+ const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
471
+ tasks.push(processCachedTask({
472
+ cache: compilerOptions.cache,
473
+ cacheKey: file,
474
+ hashKey: `${file}:asset`,
475
+ rawSource,
476
+ hash: createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash),
477
+ applyResult(source) {
478
+ compilation.updateAsset(file, source);
479
+ },
480
+ onCacheHit() {
481
+ debug("css webpack-loader-pipeline cache hit: %s", file);
482
+ },
483
+ transform: async () => {
484
+ compilerOptions.onUpdate(file, rawSource, nextCss);
485
+ debug("css skip webpack-loader-pipeline asset: %s", file);
486
+ return { result: new ConcatSource(nextCss) };
487
+ }
488
+ }));
489
+ continue;
490
+ }
491
+ const cacheKey = file;
492
+ const runtimeAwareHash = createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), runtimeSetHash);
493
+ tasks.push(processCachedTask({
494
+ cache: compilerOptions.cache,
495
+ cacheKey,
496
+ hashKey: `${file}:asset`,
497
+ rawSource,
498
+ hash: runtimeAwareHash,
499
+ applyResult(source) {
500
+ compilation.updateAsset(file, source);
501
+ },
502
+ onCacheHit() {
503
+ debug("css cache hit: %s", file);
504
+ },
505
+ transform: async () => {
506
+ await runtimeState.readyPromise;
507
+ const cssHandlerOptions = getCssHandlerOptions(file);
508
+ const generated = await generateCssByGenerator({
509
+ opts: compilerOptions,
510
+ runtimeState,
511
+ runtime: runtimeSet,
512
+ rawSource,
513
+ file,
514
+ cssHandlerOptions,
515
+ cssUserHandlerOptions: getCssUserHandlerOptions(file),
516
+ styleHandler: compilerOptions.styleHandler,
517
+ debug
518
+ });
519
+ const css = generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css;
520
+ const source = new ConcatSource(css);
521
+ compilerOptions.onUpdate(file, rawSource, css);
522
+ if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
523
+ else debug("css handle: %s", file);
524
+ return { result: source };
525
+ }
526
+ }));
527
+ }
528
+ pushConcurrentTaskFactories(tasks, jsTaskFactories);
529
+ await Promise.all(tasks);
530
+ debug("end");
531
+ emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt);
532
+ compilerOptions.onEnd();
533
+ });
534
+ });
535
+ }
536
+ //#endregion
537
+ //#region ../../node_modules/.pnpm/tsdown@0.22.1_oxc-resolver@11.19.1_@emnapi+core@1.10.0_@emnapi+runtime@1.10.0__tsx@4.22_7adbbd5d1a5b528f26574a7006ddfb8a/node_modules/tsdown/esm-shims.js
538
+ const getFilename = () => fileURLToPath(import.meta.url);
539
+ const getDirname = () => path.dirname(getFilename());
540
+ const __dirname = /* @__PURE__ */ getDirname();
541
+ //#endregion
542
+ //#region src/bundlers/webpack/loaders/runtime-registry.ts
543
+ const runtimeRegistryHolder = globalThis;
544
+ const runtimeRegistry = runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ ?? (runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ = /* @__PURE__ */ new Map());
545
+ function setWebpackLoaderRuntime(key, entry) {
546
+ runtimeRegistry.set(key, entry);
547
+ }
548
+ //#endregion
549
+ //#region src/bundlers/webpack/shared/loader-anchors.ts
550
+ const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
551
+ const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
552
+ const MPX_REWRITE_PRECEDENCE_LOADERS = [MPX_STYLE_COMPILER_LOADER, MPX_STRIP_CONDITIONAL_LOADER];
553
+ function createFinder(targets) {
554
+ return (entries) => entries.findIndex((entry) => targets.some((target) => entry?.loader?.includes?.(target)));
555
+ }
556
+ function createPrioritizedFinder(targets) {
557
+ return (entries) => {
558
+ for (const target of targets) {
559
+ const idx = entries.findIndex((entry) => entry?.loader?.includes?.(target));
560
+ if (idx !== -1) return idx;
561
+ }
562
+ return -1;
563
+ };
564
+ }
565
+ function createLoaderAnchorFinders(appType) {
566
+ if (isMpx(appType)) return {
567
+ findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
568
+ findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
569
+ };
570
+ const fallbackFinder = createFinder(["postcss-loader"]);
571
+ return {
572
+ findRewriteAnchor: fallbackFinder,
573
+ findClassSetAnchor: fallbackFinder
574
+ };
575
+ }
576
+ //#endregion
577
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
578
+ function setupWebpackV5Loaders(options) {
579
+ const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
580
+ const isMpxApp = isMpx(appType);
581
+ if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
582
+ const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
583
+ const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
584
+ const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
585
+ const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
586
+ const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
587
+ pkgDir: weappTailwindcssPackageDir,
588
+ compilerOptions,
589
+ runtimeState,
590
+ ...appType === void 0 ? {} : { appType },
591
+ ...registerAutoCssSource === void 0 ? {} : { registerCssSource: registerAutoCssSource },
592
+ getRuntimeSet: getRuntimeSetInLoader,
593
+ ...markWebpackProcessedCssSource === void 0 ? {} : { markGeneratedCssSource: markWebpackProcessedCssSource }
594
+ } : void 0;
595
+ setWebpackLoaderRuntime(runtimeRegistryKey, {
596
+ classSet: {
597
+ getClassSet: getClassSetInLoader,
598
+ getWatchDependencies: getRuntimeWatchDependencies
599
+ },
600
+ ...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
601
+ });
602
+ const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
603
+ const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
604
+ if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
605
+ const createRuntimeClassSetLoaderEntry = () => ({
606
+ loader: runtimeClassSetLoader,
607
+ options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
608
+ ident: null,
609
+ type: null
610
+ });
611
+ const createCssImportRewriteLoaderEntry = () => {
612
+ if (!runtimeCssImportRewriteLoader || !cssImportRewriteLoaderOptions) return null;
613
+ return {
614
+ loader: runtimeCssImportRewriteLoader,
615
+ options: cssImportRewriteLoaderOptions,
616
+ ident: null,
617
+ type: null
618
+ };
619
+ };
620
+ const { NormalModule } = compiler.webpack;
621
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
622
+ NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
623
+ if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
624
+ patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && isMpxApp);
625
+ const loaderEntries = module.loaders || [];
626
+ let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
627
+ const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
628
+ const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
629
+ if (process.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
630
+ rewriteAnchorIdx,
631
+ classSetAnchorIdx
632
+ });
633
+ if (process.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.includes("app.css")) debug("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), {
634
+ rewriteAnchorIdx,
635
+ classSetAnchorIdx
636
+ });
637
+ else if (process.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.endsWith(".css")) debug("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
638
+ rewriteAnchorIdx,
639
+ classSetAnchorIdx
640
+ });
641
+ if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
642
+ const anchorlessInsert = (entry, position) => {
643
+ if (position === "after") loaderEntries.push(entry);
644
+ else loaderEntries.unshift(entry);
645
+ };
646
+ if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader) {
647
+ const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
648
+ const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
649
+ if (rewriteLoaderEntry) {
650
+ const anchorIndex = findRewriteAnchor(loaderEntries);
651
+ if (anchorIndex === -1) anchorlessInsert(rewriteLoaderEntry, "after");
652
+ else loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
653
+ rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
654
+ }
655
+ }
656
+ if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
657
+ const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
658
+ const anchorIndex = findClassSetAnchor(loaderEntries);
659
+ if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
660
+ else {
661
+ const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
662
+ loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
663
+ }
664
+ }
665
+ });
666
+ });
667
+ }
668
+ //#endregion
669
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
670
+ init_defineProperty();
671
+ const debug = createDebug();
672
+ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
673
+ /**
674
+ * @name WeappTailwindcss
675
+ * @description webpack5 核心转义插件
676
+ * @link https://tw.icebreaker.top/docs/intro
677
+ */
678
+ var WeappTailwindcss = class {
679
+ constructor(options = {}) {
680
+ _defineProperty(this, "options", void 0);
681
+ _defineProperty(this, "appType", void 0);
682
+ _defineProperty(this, "hasInitialTailwindCssRoots", void 0);
683
+ this.hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots(options);
684
+ this.options = getCompilerContext({
685
+ ...options,
686
+ __internalDeferMissingCssEntriesWarning: true
687
+ });
688
+ this.appType = this.options.appType;
689
+ }
690
+ apply(compiler) {
691
+ compiler.options = compiler.options || {};
692
+ const { disabled, onLoad, runtimeLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
693
+ const disabledOptions = resolvePluginDisabledState(disabled);
694
+ const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
695
+ const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(this.options.generator);
696
+ const shouldRewriteCssImports = isTailwindcssV4 || generatorOptions.target === "web";
697
+ const isMpxApp = isMpx(this.appType);
698
+ if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
699
+ if (disabledOptions.plugin) return;
700
+ const runtimeState = {
701
+ twPatcher: initialTwPatcher,
702
+ readyPromise: createTailwindRuntimeReadyPromise(initialTwPatcher),
703
+ refreshTailwindcssPatcher
704
+ };
705
+ let runtimeSetPrepared = false;
706
+ let runtimeSetSignature;
707
+ let runtimeRefreshRequiredForCompilation = false;
708
+ let watchRunObserved = false;
709
+ const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
710
+ const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
711
+ const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
712
+ let runtimeMetadataPrepared = false;
713
+ const updateRuntimeWatchDependencies = async () => {
714
+ runtimeWatchDependencyFiles.clear();
715
+ runtimeWatchDependencyContexts.clear();
716
+ const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
717
+ if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
718
+ for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
719
+ for (const source of tailwindOptions?.v4?.cssSources ?? []) {
720
+ if (source.file) runtimeWatchDependencyFiles.add(source.file);
721
+ for (const dependency of source.dependencies ?? []) runtimeWatchDependencyFiles.add(dependency);
722
+ }
723
+ for (const source of tailwindOptions?.v4?.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
724
+ if (typeof runtimeState.twPatcher.collectContentTokens !== "function") return;
725
+ try {
726
+ const report = await runtimeState.twPatcher.collectContentTokens();
727
+ for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
728
+ for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
729
+ } catch (error) {
730
+ debug("collect runtime watch dependencies failed: %O", error);
731
+ }
732
+ };
733
+ const ensureRuntimeMetadata = async (force = false) => {
734
+ if (runtimeMetadataPrepared && !force) return;
735
+ await updateRuntimeWatchDependencies();
736
+ runtimeMetadataPrepared = true;
737
+ };
738
+ const collectWatchChangedFiles = () => {
739
+ const compilerLike = compiler;
740
+ return new Set([...compilerLike.modifiedFiles ?? [], ...compilerLike.removedFiles ?? []]);
741
+ };
742
+ const hasRuntimeDependencyChanges = (files) => {
743
+ for (const file of files) if (isWatchFileInRuntimeDependencies(file, {
744
+ contexts: runtimeWatchDependencyContexts,
745
+ files: runtimeWatchDependencyFiles
746
+ })) return true;
747
+ return false;
748
+ };
749
+ const syncRuntimeRefreshRequirement = (markWatchRun = false) => {
750
+ if (markWatchRun) watchRunObserved = true;
751
+ const changedFiles = collectWatchChangedFiles();
752
+ runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges(changedFiles);
753
+ };
754
+ const resetRuntimePreparation = () => {
755
+ runtimeSetPrepared = false;
756
+ syncRuntimeRefreshRequirement();
757
+ };
758
+ const registerAutoCssSource = async (source) => {
759
+ if (this.hasInitialTailwindCssRoots || (runtimeState.twPatcher.majorVersion ?? 0) < 4 || !source.file) return;
760
+ if (!upsertTailwindV4CssSource(this.options, source)) return;
761
+ runtimeSetPrepared = false;
762
+ runtimeMetadataPrepared = false;
763
+ runtimeRefreshRequiredForCompilation = true;
764
+ await refreshTailwindRuntimeState(runtimeState, {
765
+ force: true,
766
+ clearCache: true
767
+ });
768
+ debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
769
+ };
770
+ const markWebpackProcessedCssSource = (file) => {
771
+ webpackProcessedCssSourceFiles.add(path.resolve(file));
772
+ };
773
+ compiler.hooks.invalid?.tap?.(pluginName, (fileName) => {
774
+ if (!fileName) return;
775
+ runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges([path.resolve(fileName)]);
776
+ });
777
+ compiler.hooks.watchRun?.tap?.(pluginName, () => syncRuntimeRefreshRequirement(true));
778
+ if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(pluginName, resetRuntimePreparation);
779
+ else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(pluginName, resetRuntimePreparation);
780
+ async function getClassSetInLoader() {
781
+ if (runtimeSetPrepared) return;
782
+ const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
783
+ const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
784
+ debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
785
+ runtimeSetPrepared = true;
786
+ await ensureRuntimeClassSet(runtimeState, {
787
+ forceRefresh,
788
+ forceCollect: forceRefresh || !watchRunObserved,
789
+ clearCache: forceRefresh,
790
+ allowEmpty: true
791
+ });
792
+ await ensureRuntimeMetadata(forceRefresh);
793
+ runtimeSetSignature = signature;
794
+ runtimeRefreshRequiredForCompilation = false;
795
+ }
796
+ async function getRuntimeSetInLoader() {
797
+ await getClassSetInLoader();
798
+ return ensureRuntimeClassSet(runtimeState, { allowEmpty: true });
799
+ }
800
+ onLoad();
801
+ setupWebpackV5Loaders({
802
+ compiler,
803
+ options: this.options,
804
+ appType: this.appType,
805
+ weappTailwindcssPackageDir,
806
+ shouldRewriteCssImports,
807
+ runtimeLoaderPath,
808
+ registerAutoCssSource,
809
+ runtimeState,
810
+ getClassSetInLoader,
811
+ getRuntimeSetInLoader,
812
+ markWebpackProcessedCssSource,
813
+ getRuntimeWatchDependencies() {
814
+ return {
815
+ files: runtimeWatchDependencyFiles,
816
+ contexts: runtimeWatchDependencyContexts
817
+ };
818
+ },
819
+ debug
820
+ });
821
+ setupWebpackV5ProcessAssetsHook({
822
+ compiler,
823
+ options: this.options,
824
+ appType: this.appType,
825
+ runtimeState,
826
+ getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
827
+ refreshRuntimeMetadata: ensureRuntimeMetadata,
828
+ isWebpackProcessedCssAsset(file, rawSource) {
829
+ return webpackProcessedCssSourceFiles.has(path.resolve(file)) || rawSource.includes("weapp-tailwindcss webpack-generated-css");
830
+ },
831
+ consumeRuntimeRefreshRequirement() {
832
+ runtimeRefreshRequiredForCompilation = false;
833
+ },
834
+ isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
835
+ runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
836
+ debug
837
+ });
838
+ }
839
+ };
840
+ //#endregion
841
+ export { weappTailwindcssPackageDir as n, WeappTailwindcss as t };