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
package/dist/webpack4.mjs DELETED
@@ -1,379 +0,0 @@
1
- import { g as ensureRuntimeClassSet, n as shouldSkipJsTransform, p as pluginName, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-XdFvVASS.mjs";
2
- import { r as getGroupedEntries } from "./utils-7DUGTFED.mjs";
3
- import { d as getRuntimeClassSetSignature } from "./logger-BoVx1Dbt.mjs";
4
- import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-Bwy_Uz89.mjs";
5
- import { a as resolveDisabledOptions, c as toAbsoluteOutputPath, i as resolvePackageDir, r as pushConcurrentTaskFactories, s as resolveOutputSpecifier } from "./css-imports-CSdPq_Sc.mjs";
6
- import { a as hasLoaderEntry, c as applyTailwindcssCssImportRewrite, d as isMpx, f as patchMpxLoaderResolve, i as getCacheKey, l as ensureMpxTailwindcssAliases, n as __dirname, p as setupMpxTailwindcssRedirect, r as createAssetHashByChunkMap, s as isCssLikeModuleResource, t as createLoaderAnchorFinders, u as injectMpxCssRewritePreRules } from "./loader-anchors-1MumTAtA.mjs";
7
- import path from "node:path";
8
- import process from "node:process";
9
- import fs from "node:fs";
10
- import { ConcatSource } from "webpack-sources";
11
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v4-assets.ts
12
- function resolveWebpackStaleClassNameFallback(option, _compiler) {
13
- if (typeof option === "boolean") return option;
14
- return false;
15
- }
16
- function toWebpackV4AssetCompilation(compilation) {
17
- return compilation;
18
- }
19
- function readWebpackV4AssetSource(asset) {
20
- const source = asset.source();
21
- return typeof source === "string" ? source : source.toString();
22
- }
23
- function setupWebpackV4EmitHook(options) {
24
- const { compiler, options: compilerOptions, appType, runtimeState, debug } = options;
25
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
26
- const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
27
- compiler.hooks.emit.tapPromise(pluginName, async (compilation) => {
28
- await runtimeState.patchPromise;
29
- compilerOptions.onStart();
30
- debug("start");
31
- for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
32
- const assetCompilation = toWebpackV4AssetCompilation(compilation);
33
- const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
34
- const assets = assetCompilation.assets;
35
- const entries = Object.entries(assets);
36
- const outputDir = compiler.options?.output?.path ? path.resolve(compiler.options.output.path) : process.cwd();
37
- const jsAssets = /* @__PURE__ */ new Map();
38
- for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
39
- const absolute = toAbsoluteOutputPath(file, outputDir);
40
- jsAssets.set(absolute, file);
41
- }
42
- const moduleGraphOptions = {
43
- resolve(specifier, importer) {
44
- return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
45
- },
46
- load: (id) => {
47
- const assetName = jsAssets.get(id);
48
- if (!assetName) return;
49
- const assetSource = assetCompilation.assets[assetName];
50
- if (!assetSource) return;
51
- return readWebpackV4AssetSource(assetSource);
52
- },
53
- filter(id) {
54
- return jsAssets.has(id);
55
- }
56
- };
57
- const applyLinkedResults = (linked) => {
58
- if (!linked) return;
59
- for (const [id, { code }] of Object.entries(linked)) {
60
- const assetName = jsAssets.get(id);
61
- if (!assetName) continue;
62
- const assetSource = assetCompilation.assets[assetName];
63
- if (!assetSource) continue;
64
- const previous = readWebpackV4AssetSource(assetSource);
65
- if (previous === code) continue;
66
- const source = new ConcatSource(code);
67
- assetCompilation.updateAsset(assetName, source);
68
- compilerOptions.onUpdate(assetName, previous, code);
69
- debug("js linked handle: %s", assetName);
70
- }
71
- };
72
- const groupedEntries = getGroupedEntries(entries, compilerOptions);
73
- const getCssHandlerOptions = (file) => {
74
- const majorVersion = runtimeState.twPatcher.majorVersion;
75
- const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
76
- const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
77
- const cached = cssHandlerOptionsCache.get(cacheKey);
78
- if (cached) return cached;
79
- const created = {
80
- isMainChunk,
81
- postcssOptions: { options: { from: file } },
82
- majorVersion
83
- };
84
- cssHandlerOptionsCache.set(cacheKey, created);
85
- return created;
86
- };
87
- const getCssUserHandlerOptions = (file) => {
88
- const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
89
- const cached = cssUserHandlerOptionsCache.get(cacheKey);
90
- if (cached) return cached;
91
- const created = {
92
- ...getCssHandlerOptions(file),
93
- isMainChunk: false
94
- };
95
- cssUserHandlerOptionsCache.set(cacheKey, created);
96
- return created;
97
- };
98
- const staleClassNameFallback = resolveWebpackStaleClassNameFallback(compilerOptions.staleClassNameFallback, compiler);
99
- const runtimeSet = await ensureRuntimeClassSet(runtimeState, {
100
- forceCollect: true,
101
- allowEmpty: false
102
- });
103
- const defaultTemplateHandlerOptions = { runtimeSet };
104
- debug("get runtimeSet, class count: %d", runtimeSet.size);
105
- const tasks = [];
106
- if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
107
- const [file, originalSource] = element;
108
- const rawSource = readWebpackV4AssetSource(originalSource);
109
- const cacheKey = file;
110
- const chunkHash = assetHashByChunk.get(file);
111
- tasks.push(processCachedTask({
112
- cache: compilerOptions.cache,
113
- cacheKey,
114
- hashKey: `${file}:asset`,
115
- rawSource,
116
- hash: chunkHash,
117
- applyResult(source) {
118
- assetCompilation.updateAsset(file, source);
119
- },
120
- onCacheHit() {
121
- debug("html cache hit: %s", file);
122
- },
123
- transform: async () => {
124
- const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
125
- const source = new ConcatSource(wxml);
126
- compilerOptions.onUpdate(file, rawSource, wxml);
127
- debug("html handle: %s", file);
128
- return { result: source };
129
- }
130
- }));
131
- }
132
- const jsTaskFactories = [];
133
- if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
134
- const cacheKey = getCacheKey(file);
135
- const assetSource = assetCompilation.assets[file];
136
- if (!assetSource) continue;
137
- const initialRawSource = readWebpackV4AssetSource(assetSource);
138
- const absoluteFile = toAbsoluteOutputPath(file, outputDir);
139
- const chunkHash = assetHashByChunk.get(file);
140
- const sourceAwareHash = chunkHash ? `${chunkHash}:${compilerOptions.cache.computeHash(initialRawSource)}` : void 0;
141
- jsTaskFactories.push(async () => {
142
- await processCachedTask({
143
- cache: compilerOptions.cache,
144
- cacheKey,
145
- hashKey: `${file}:asset`,
146
- rawSource: initialRawSource,
147
- hash: sourceAwareHash,
148
- applyResult(source) {
149
- assetCompilation.updateAsset(file, source);
150
- },
151
- onCacheHit() {
152
- debug("js cache hit: %s", file);
153
- },
154
- transform: async () => {
155
- const currentAsset = assetCompilation.assets[file];
156
- const currentSource = currentAsset ? readWebpackV4AssetSource(currentAsset) : "";
157
- const handlerOptions = {
158
- staleClassNameFallback,
159
- tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
160
- filename: absoluteFile,
161
- moduleGraph: moduleGraphOptions,
162
- babelParserOptions: { sourceFilename: absoluteFile }
163
- };
164
- if (shouldSkipJsTransform(currentSource, handlerOptions)) return { result: new ConcatSource(currentSource) };
165
- const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
166
- const source = new ConcatSource(code);
167
- compilerOptions.onUpdate(file, currentSource, code);
168
- debug("js handle: %s", file);
169
- applyLinkedResults(linked);
170
- return { result: source };
171
- }
172
- });
173
- });
174
- }
175
- if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
176
- const [file, originalSource] = element;
177
- const rawSource = readWebpackV4AssetSource(originalSource);
178
- const cacheKey = file;
179
- const chunkHash = assetHashByChunk.get(file);
180
- tasks.push(processCachedTask({
181
- cache: compilerOptions.cache,
182
- cacheKey,
183
- hashKey: `${file}:asset`,
184
- rawSource,
185
- hash: chunkHash,
186
- applyResult(source) {
187
- assetCompilation.updateAsset(file, source);
188
- },
189
- onCacheHit() {
190
- debug("css cache hit: %s", file);
191
- },
192
- transform: async () => {
193
- await runtimeState.patchPromise;
194
- const cssHandlerOptions = getCssHandlerOptions(file);
195
- const generated = await generateCssByGenerator({
196
- opts: compilerOptions,
197
- runtimeState,
198
- runtime: runtimeSet,
199
- rawSource,
200
- file,
201
- cssHandlerOptions,
202
- cssUserHandlerOptions: getCssUserHandlerOptions(file),
203
- styleHandler: compilerOptions.styleHandler,
204
- debug
205
- });
206
- const css = generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css;
207
- const source = new ConcatSource(css);
208
- compilerOptions.onUpdate(file, rawSource, css);
209
- if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
210
- else debug("css handle: %s", file);
211
- return { result: source };
212
- }
213
- }));
214
- }
215
- pushConcurrentTaskFactories(tasks, jsTaskFactories);
216
- await Promise.all(tasks);
217
- debug("end");
218
- compilerOptions.onEnd();
219
- });
220
- }
221
- //#endregion
222
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.ts
223
- function setupWebpackV4Loaders(options) {
224
- const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, getClassSetInLoader, debug } = options;
225
- const isMpxApp = isMpx(appType);
226
- if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
227
- const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
228
- const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
229
- const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
230
- const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
231
- const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
232
- pkgDir: weappTailwindcssPackageDir,
233
- appType
234
- } : void 0;
235
- const classSetLoaderOptions = { getClassSet: getClassSetInLoader };
236
- const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
237
- const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { rewriteCssImports: runtimeLoaderRewriteOptions } : void 0;
238
- if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
239
- const createRuntimeClassSetLoaderEntry = () => ({
240
- loader: runtimeClassSetLoader,
241
- options: classSetLoaderOptions,
242
- ident: null,
243
- type: null
244
- });
245
- const createCssImportRewriteLoaderEntry = () => {
246
- if (!runtimeCssImportRewriteLoader) return null;
247
- return {
248
- loader: runtimeCssImportRewriteLoader,
249
- options: cssImportRewriteLoaderOptions,
250
- ident: null,
251
- type: null
252
- };
253
- };
254
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
255
- compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
256
- if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
257
- if (shouldRewriteCssImports && isMpx(appType) && typeof _loaderContext.resolve === "function") patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, true);
258
- const loaderEntries = module.loaders || [];
259
- let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
260
- const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
261
- const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
262
- 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), {
263
- rewriteAnchorIdx,
264
- classSetAnchorIdx
265
- });
266
- 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), {
267
- rewriteAnchorIdx,
268
- classSetAnchorIdx
269
- });
270
- 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), {
271
- rewriteAnchorIdx,
272
- classSetAnchorIdx
273
- });
274
- if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
275
- const anchorlessInsert = (entry, position) => {
276
- if (position === "after") loaderEntries.push(entry);
277
- else loaderEntries.unshift(entry);
278
- };
279
- if (runtimeLoaderRewriteOptions && runtimeCssImportRewriteLoaderExists && cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoader) {
280
- const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
281
- const rewriteEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
282
- if (rewriteEntry) {
283
- const anchorIndex = findRewriteAnchor(loaderEntries);
284
- if (anchorIndex === -1) anchorlessInsert(rewriteEntry, "after");
285
- else loaderEntries.splice(anchorIndex + 1, 0, rewriteEntry);
286
- rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
287
- }
288
- }
289
- if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
290
- const anchorIndex = findClassSetAnchor(loaderEntries);
291
- if (anchorIndex === -1) anchorlessInsert(createRuntimeClassSetLoaderEntry(), "before");
292
- else {
293
- const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
294
- loaderEntries.splice(insertIndex, 0, createRuntimeClassSetLoaderEntry());
295
- }
296
- }
297
- });
298
- });
299
- }
300
- //#endregion
301
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
302
- const debug = createDebug();
303
- const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
304
- /**
305
- * @name UnifiedWebpackPluginV4
306
- * @description webpack4 核心转义插件
307
- * @link https://tw.icebreaker.top/docs/intro
308
- */
309
- var UnifiedWebpackPluginV4 = class {
310
- constructor(options = {}) {
311
- this.options = getCompilerContext(options);
312
- this.appType = this.options.appType;
313
- }
314
- apply(compiler) {
315
- compiler.options = compiler.options || {};
316
- const { disabled, onLoad, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
317
- const disabledOptions = resolveDisabledOptions(disabled);
318
- const shouldRewriteCssImports = (initialTwPatcher.majorVersion ?? 0) >= 4 && this.options.rewriteCssImports !== false && !disabledOptions.rewriteCssImports;
319
- const isMpxApp = isMpx(this.appType);
320
- if (shouldRewriteCssImports) {
321
- applyTailwindcssCssImportRewrite(compiler, {
322
- pkgDir: weappTailwindcssPackageDir,
323
- enabled: true,
324
- appType: this.appType
325
- });
326
- setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
327
- }
328
- if (disabledOptions.plugin) return;
329
- const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
330
- source: "runtime",
331
- cwd: this.options.tailwindcssBasedir ?? process.cwd()
332
- });
333
- const runtimeState = {
334
- twPatcher: initialTwPatcher,
335
- patchPromise: patchRecorderState.patchPromise,
336
- refreshTailwindcssPatcher,
337
- onPatchCompleted: patchRecorderState.onPatchCompleted
338
- };
339
- let runtimeSetPrepared = false;
340
- let runtimeSetSignature;
341
- compiler.hooks.compilation.tap(pluginName, () => {
342
- runtimeSetPrepared = false;
343
- });
344
- async function getClassSetInLoader() {
345
- if (runtimeSetPrepared) return;
346
- const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
347
- const forceRefresh = signature !== runtimeSetSignature;
348
- runtimeSetPrepared = true;
349
- await ensureRuntimeClassSet(runtimeState, {
350
- forceRefresh,
351
- forceCollect: true,
352
- clearCache: forceRefresh,
353
- allowEmpty: true
354
- });
355
- runtimeSetSignature = signature;
356
- }
357
- onLoad();
358
- setupWebpackV4Loaders({
359
- compiler,
360
- options: this.options,
361
- appType: this.appType,
362
- weappTailwindcssPackageDir,
363
- shouldRewriteCssImports,
364
- runtimeLoaderPath,
365
- runtimeCssImportRewriteLoaderPath,
366
- getClassSetInLoader,
367
- debug
368
- });
369
- setupWebpackV4EmitHook({
370
- compiler,
371
- options: this.options,
372
- appType: this.appType,
373
- runtimeState,
374
- debug
375
- });
376
- }
377
- };
378
- //#endregion
379
- export { UnifiedWebpackPluginV4, UnifiedWebpackPluginV4 as WeappTailwindcss, UnifiedWebpackPluginV4 as weappTailwindcss, weappTailwindcssPackageDir };
@@ -1,59 +0,0 @@
1
- import { spawnSync } from 'node:child_process'
2
- import process from 'node:process'
3
- import { fileURLToPath, pathToFileURL } from 'node:url'
4
-
5
- const cliPath = fileURLToPath(new URL('../bin/weapp-tailwindcss.js', import.meta.url))
6
- const missingRuntimeModuleMessage = `${[
7
- '[weapp-tailwindcss] postinstall patch skipped because a runtime module is missing.',
8
- 'Run `pnpm --filter weapp-tailwindcss build` before strict CLI validation.',
9
- ].join(' ')}\n`
10
-
11
- export function isMissingRuntimeModuleOutput(output) {
12
- return /MODULE_NOT_FOUND|Cannot find module/.test(output)
13
- }
14
-
15
- export function resolvePostinstallPatchExitCode(result) {
16
- if (result.error) {
17
- return {
18
- code: 0,
19
- message: `[weapp-tailwindcss] postinstall patch skipped: ${result.error.message}\n`,
20
- }
21
- }
22
-
23
- if (result.status && isMissingRuntimeModuleOutput(`${result.stderr ?? ''}\n${result.stdout ?? ''}`)) {
24
- return {
25
- code: 0,
26
- message: missingRuntimeModuleMessage,
27
- }
28
- }
29
-
30
- return {
31
- code: result.status ?? 0,
32
- }
33
- }
34
-
35
- export function runPostinstallPatch() {
36
- const result = spawnSync(process.execPath, [cliPath, 'patch'], {
37
- encoding: 'utf8',
38
- })
39
-
40
- if (result.stdout) {
41
- process.stdout.write(result.stdout)
42
- }
43
-
44
- if (result.stderr) {
45
- process.stderr.write(result.stderr)
46
- }
47
-
48
- const resolved = resolvePostinstallPatchExitCode(result)
49
- if (resolved.message) {
50
- process.stderr.write(resolved.message)
51
- }
52
-
53
- process.exitCode = resolved.code
54
- }
55
-
56
- const entryPoint = process.argv[1] ? pathToFileURL(process.argv[1]).href : undefined
57
- if (import.meta.url === entryPoint) {
58
- runPostinstallPatch()
59
- }