weapp-tailwindcss 5.0.0-next.5 → 5.0.0-next.8

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 (131) hide show
  1. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +2 -0
  2. package/dist/bundlers/shared/css-cleanup/color-gamut.d.ts +3 -0
  3. package/dist/bundlers/shared/css-cleanup/root-cleanups.d.ts +4 -0
  4. package/dist/bundlers/shared/css-cleanup/selectors.d.ts +8 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -2
  6. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  7. package/dist/bundlers/shared/generator-css/directives.d.ts +12 -0
  8. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  9. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  10. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  11. package/dist/bundlers/shared/generator-css/markers.d.ts +16 -0
  12. package/dist/bundlers/shared/generator-css/source-files.d.ts +11 -0
  13. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +10 -0
  14. package/dist/bundlers/shared/generator-css.d.ts +10 -23
  15. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  16. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  17. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +20 -0
  18. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +3 -0
  19. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  20. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  21. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  22. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  23. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  24. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  25. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  26. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  27. package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
  28. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  29. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  30. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  31. package/dist/bundlers/vite/runtime-class-set.d.ts +22 -0
  32. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  33. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +1 -0
  34. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -1
  35. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
  36. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +1 -0
  37. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -0
  38. package/dist/cache-BVAiJV3J.js +502 -0
  39. package/dist/cache-CHs4DXui.mjs +434 -0
  40. package/dist/cli/helpers.d.ts +1 -2
  41. package/dist/cli/mount-options.d.ts +2 -2
  42. package/dist/cli/types.d.ts +0 -2
  43. package/dist/cli.js +107 -603
  44. package/dist/cli.mjs +118 -613
  45. package/dist/constants.d.ts +0 -1
  46. package/dist/context/tailwindcss.d.ts +1 -1
  47. package/dist/core.js +13 -20
  48. package/dist/core.mjs +8 -14
  49. package/dist/css-macro/postcss.js +1 -1
  50. package/dist/css-macro/postcss.mjs +1 -1
  51. package/dist/css-macro.js +2 -2
  52. package/dist/css-macro.mjs +2 -2
  53. package/dist/defaults.d.ts +15 -1
  54. package/dist/defaults.js +28 -7
  55. package/dist/defaults.mjs +25 -8
  56. package/dist/{generator-9UEp8OoQ.js → generator-DKkhJbOg.js} +24 -7
  57. package/dist/{generator-Dpp-5s8z.mjs → generator-UBmfduYg.mjs} +20 -3
  58. package/dist/{generator-css-MyjZhF0z.mjs → generator-css-BIapP56i.mjs} +691 -606
  59. package/dist/{generator-css-CGueCYbX.js → generator-css-Mksw8PgB.js} +703 -606
  60. package/dist/generator.js +1 -1
  61. package/dist/generator.mjs +1 -1
  62. package/dist/gulp.js +33 -21
  63. package/dist/gulp.mjs +29 -17
  64. package/dist/index.js +5 -5
  65. package/dist/index.mjs +4 -4
  66. package/dist/logger-BRy6XPQ2.js +1 -0
  67. package/dist/logger-Bub1jggA.mjs +2 -0
  68. package/dist/postcss/config-directive.d.ts +1 -0
  69. package/dist/postcss/context.d.ts +9 -0
  70. package/dist/postcss/source-files.d.ts +8 -0
  71. package/dist/postcss/tailwind-version.d.ts +3 -0
  72. package/dist/postcss-QIXwT40c.js +298 -0
  73. package/dist/postcss-w48mGIhe.mjs +288 -0
  74. package/dist/postcss.js +3 -285
  75. package/dist/postcss.mjs +1 -278
  76. package/dist/{recorder-D4BKt75Q.js → precheck-B32p-gLI.js} +139 -274
  77. package/dist/{recorder-BIW3Kuke.mjs → precheck-B4RH6ZNN.mjs} +105 -239
  78. package/dist/presets.js +6 -4
  79. package/dist/presets.mjs +4 -2
  80. package/dist/runtime-patch-CwN5ya72.mjs +71 -0
  81. package/dist/runtime-patch-D6mBo_KB.js +85 -0
  82. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  83. package/dist/tailwindcss/runtime.d.ts +2 -3
  84. package/dist/tailwindcss/targets.d.ts +1 -5
  85. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  86. package/dist/tailwindcss/v4/patcher.d.ts +1 -1
  87. package/dist/{logger-D9clu_3f.js → tailwindcss-Bu-RWIHx.js} +70 -413
  88. package/dist/{logger-1gx9UllH.mjs → tailwindcss-C5IgPlQ0.mjs} +56 -382
  89. package/dist/types/index.d.ts +1 -6
  90. package/dist/uni-app-x/vite.d.ts +1 -1
  91. package/dist/{vite-fDM-UQpR.mjs → vite-BwgRVgxH.mjs} +677 -525
  92. package/dist/{vite-BkMGwDeH.js → vite-DyZuiyap.js} +704 -552
  93. package/dist/vite.js +1 -1
  94. package/dist/vite.mjs +1 -1
  95. package/dist/weapp-tw-css-import-rewrite-loader.js +10 -1
  96. package/dist/{webpack-CICGEKT9.js → webpack-CNV2dx3Q.js} +72 -37
  97. package/dist/{webpack-D2Wdk28V.mjs → webpack-CT6EEENx.mjs} +58 -23
  98. package/dist/webpack.js +1 -1
  99. package/dist/webpack.mjs +1 -1
  100. package/package.json +6 -9
  101. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  102. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  103. package/dist/cli/config.d.ts +0 -5
  104. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  105. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  106. package/dist/cli/patch-options.d.ts +0 -6
  107. package/dist/cli/tokens.d.ts +0 -4
  108. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  109. package/dist/cli/workspace/patch-package.d.ts +0 -3
  110. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  111. package/dist/cli/workspace/types.d.ts +0 -11
  112. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  113. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  114. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  115. package/dist/cli/workspace.d.ts +0 -2
  116. package/dist/js/syntax.d.ts +0 -10
  117. package/dist/patcher-options-DnqazL9E.js +0 -34
  118. package/dist/patcher-options-GuOwX0-k.mjs +0 -17
  119. package/dist/tailwindcss/recorder.d.ts +0 -13
  120. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  121. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  122. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  123. package/dist/tailwindcss/targets/types.d.ts +0 -35
  124. package/dist/version-CWBxRFPB.js +0 -56
  125. package/dist/version-WNz3MwRv.mjs +0 -49
  126. /package/dist/{constants-p1dyh1x1.js → constants-BoB_6lFw.js} +0 -0
  127. /package/dist/{constants-B-_T5UnW.mjs → constants-E_loJC49.mjs} +0 -0
  128. /package/dist/{run-tasks-Cq5A5nVD.js → run-tasks-B50A3pxt.js} +0 -0
  129. /package/dist/{run-tasks-DUVrDJGl.mjs → run-tasks-DdNi-hkk.mjs} +0 -0
  130. /package/dist/{utils-DmC9_In3.js → utils-BiShvil9.js} +0 -0
  131. /package/dist/{utils-7DUGTFED.mjs → utils-Btw1iOVV.mjs} +0 -0
package/dist/generator.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("./chunk-8l464Juk.js");
3
- const require_generator = require("./generator-9UEp8OoQ.js");
3
+ const require_generator = require("./generator-DKkhJbOg.js");
4
4
  let tailwindcss_patch = require("tailwindcss-patch");
5
5
  exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
6
6
  exports.createWeappTailwindcssGeneratorFromPatcher = require_generator.createWeappTailwindcssGeneratorFromPatcher;
@@ -1,2 +1,2 @@
1
- import { _ as transformTailwindV3CssToWeapp, a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, g as transformTailwindV3CssByTarget, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, l as transformTailwindV4CssByTarget, m as resolveTailwindV3SourceFromPatcher, n as createWeappTailwindcssGeneratorFromPatcher, o as resolveTailwindV4SourceFromPatchOptions, p as resolveTailwindV3Source, r as resolveTailwindSourceFromPatcher, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, u as transformTailwindV4CssToWeapp } from "./generator-Dpp-5s8z.mjs";
1
+ import { _ as transformTailwindV3CssToWeapp, a as resolveTailwindV4Source, c as resolveTailwindV4SourceOptionsFromPatcher, g as transformTailwindV3CssByTarget, h as resolveTailwindV3SourceOptionsFromPatcher, i as normalizeWeappTailwindcssGeneratorOptions, l as transformTailwindV4CssByTarget, m as resolveTailwindV3SourceFromPatcher, n as createWeappTailwindcssGeneratorFromPatcher, o as resolveTailwindV4SourceFromPatchOptions, p as resolveTailwindV3Source, r as resolveTailwindSourceFromPatcher, s as resolveTailwindV4SourceFromPatcher, t as createWeappTailwindcssGenerator, u as transformTailwindV4CssToWeapp } from "./generator-UBmfduYg.mjs";
2
2
  export { createWeappTailwindcssGenerator, createWeappTailwindcssGeneratorFromPatcher, normalizeWeappTailwindcssGeneratorOptions, resolveTailwindSourceFromPatcher, resolveTailwindV3Source, resolveTailwindV3SourceFromPatcher, resolveTailwindV3SourceOptionsFromPatcher, resolveTailwindV4Source, resolveTailwindV4SourceFromPatchOptions, resolveTailwindV4SourceFromPatcher, resolveTailwindV4SourceOptionsFromPatcher, transformTailwindV3CssByTarget, transformTailwindV3CssToWeapp, transformTailwindV4CssByTarget, transformTailwindV4CssToWeapp };
package/dist/gulp.js CHANGED
@@ -1,19 +1,21 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-8l464Juk.js");
3
- const require_recorder = require("./recorder-D4BKt75Q.js");
4
- const require_logger = require("./logger-D9clu_3f.js");
5
- const require_generator_css = require("./generator-css-CGueCYbX.js");
3
+ const require_cache = require("./cache-BVAiJV3J.js");
4
+ const require_runtime_patch = require("./runtime-patch-D6mBo_KB.js");
5
+ const require_generator_css = require("./generator-css-Mksw8PgB.js");
6
+ const require_precheck = require("./precheck-B32p-gLI.js");
7
+ const require_tailwindcss = require("./tailwindcss-Bu-RWIHx.js");
6
8
  let node_path = require("node:path");
7
9
  node_path = require_chunk.__toESM(node_path);
8
10
  let node_process = require("node:process");
9
11
  node_process = require_chunk.__toESM(node_process);
10
- let node_buffer = require("node:buffer");
11
12
  let node_fs = require("node:fs");
12
13
  node_fs = require_chunk.__toESM(node_fs);
14
+ let node_buffer = require("node:buffer");
13
15
  let node_stream = require("node:stream");
14
16
  node_stream = require_chunk.__toESM(node_stream);
15
17
  //#region src/bundlers/gulp/index.ts
16
- const debug = require_recorder.createDebug();
18
+ const debug = require_runtime_patch.createDebug();
17
19
  const Transform = node_stream.default.Transform;
18
20
  /**
19
21
  * @name weapp-tw-gulp
@@ -21,18 +23,18 @@ const Transform = node_stream.default.Transform;
21
23
  * @link https://tw.icebreaker.top/docs/quick-start/frameworks/native
22
24
  */
23
25
  function createPlugins(options = {}) {
24
- const opts = require_recorder.getCompilerContext(options);
25
- const { templateHandler, styleHandler, jsHandler, cache, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
26
- const patchRecorderState = require_recorder.setupPatchRecorder(initialTwPatcher, opts.tailwindcssBasedir, {
27
- source: "runtime",
28
- cwd: opts.tailwindcssBasedir ?? node_process.default.cwd()
26
+ const hasInitialTailwindCssRoots = require_tailwindcss.hasConfiguredTailwindV4CssRoots(options);
27
+ const opts = require_precheck.getCompilerContext({
28
+ ...options,
29
+ __internalDeferMissingCssEntriesWarning: true
29
30
  });
31
+ const { templateHandler, styleHandler, jsHandler, cache, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
32
+ const readyPromise = require_precheck.createTailwindRuntimeReadyPromise(initialTwPatcher);
30
33
  let runtimeSet = /* @__PURE__ */ new Set();
31
34
  const runtimeState = {
32
35
  twPatcher: initialTwPatcher,
33
- patchPromise: patchRecorderState.patchPromise,
34
- refreshTailwindcssPatcher,
35
- onPatchCompleted: patchRecorderState.onPatchCompleted
36
+ readyPromise,
37
+ refreshTailwindcssPatcher
36
38
  };
37
39
  const defaultStyleHandlerOptionsCache = /* @__PURE__ */ new Map();
38
40
  let cachedDefaultTemplateHandlerOptions;
@@ -49,7 +51,7 @@ function createPlugins(options = {}) {
49
51
  let runtimeSetInitialized = false;
50
52
  async function refreshRuntimeSet(force = false) {
51
53
  if (!force && runtimeSetInitialized) return runtimeSet;
52
- runtimeSet = await require_recorder.ensureRuntimeClassSet(runtimeState, {
54
+ runtimeSet = await require_precheck.ensureRuntimeClassSet(runtimeState, {
53
55
  forceRefresh: force,
54
56
  forceCollect: force,
55
57
  clearCache: force,
@@ -61,10 +63,19 @@ function createPlugins(options = {}) {
61
63
  function createRuntimeSetHash(rawSource, nextRuntimeSet) {
62
64
  return cache.computeHash([
63
65
  rawSource,
64
- require_logger.getRuntimeClassSetSignature(runtimeState.twPatcher),
66
+ require_cache.getRuntimeClassSetSignature(runtimeState.twPatcher),
65
67
  [...nextRuntimeSet].sort().join("\n")
66
68
  ].join("\n\n"));
67
69
  }
70
+ async function registerAutoCssSource(file, rawSource) {
71
+ if (hasInitialTailwindCssRoots || (runtimeState.twPatcher.majorVersion ?? 0) < 4 || !file.path || !require_generator_css.hasTailwindRootDirectives(rawSource)) return;
72
+ if (!require_tailwindcss.upsertTailwindV4CssSource(opts, {
73
+ file: node_path.default.resolve(file.path),
74
+ css: rawSource
75
+ })) return;
76
+ runtimeSetInitialized = false;
77
+ debug("detected tailwindcss v4 css source from gulp css file: %s", file.path);
78
+ }
68
79
  function resolveWithExtensions(base) {
69
80
  for (const ext of MODULE_EXTENSIONS) {
70
81
  const candidate = `${base}${ext}`;
@@ -172,6 +183,7 @@ function createPlugins(options = {}) {
172
183
  const transformWxss = (options = {}) => createVinylTransform(async (file) => {
173
184
  if (!file.contents) return;
174
185
  const rawSource = file.contents.toString();
186
+ await registerAutoCssSource(file, rawSource);
175
187
  const nextRuntimeSet = await refreshRuntimeSet(true);
176
188
  await require_generator_css.processCachedTask({
177
189
  cache,
@@ -184,7 +196,7 @@ function createPlugins(options = {}) {
184
196
  debug("css cache hit: %s", file.path);
185
197
  },
186
198
  async transform() {
187
- await runtimeState.patchPromise;
199
+ await runtimeState.readyPromise;
188
200
  const cssHandlerOptions = resolveWxssFileHandlerOptions(file, options);
189
201
  const css = (await require_generator_css.generateCssByGenerator({
190
202
  opts,
@@ -205,7 +217,7 @@ function createPlugins(options = {}) {
205
217
  const transformJs = (options = {}) => createVinylTransform(async (file) => {
206
218
  if (!file.contents) return;
207
219
  await refreshRuntimeSet(true);
208
- await runtimeState.patchPromise;
220
+ await runtimeState.readyPromise;
209
221
  const filename = node_path.default.resolve(file.path);
210
222
  const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
211
223
  const handlerOptions = {
@@ -230,9 +242,9 @@ function createPlugins(options = {}) {
230
242
  debug("js cache hit: %s", file.path);
231
243
  },
232
244
  async transform() {
233
- await runtimeState.patchPromise;
245
+ await runtimeState.readyPromise;
234
246
  const currentSource = file.contents?.toString() ?? rawSource;
235
- if (require_recorder.shouldSkipJsTransform(currentSource, handlerOptions)) return { result: currentSource };
247
+ if (require_precheck.shouldSkipJsTransform(currentSource, handlerOptions)) return { result: currentSource };
236
248
  const { code } = await jsHandler(currentSource, runtimeSet, handlerOptions);
237
249
  debug("js handle: %s", file.path);
238
250
  return { result: code };
@@ -242,7 +254,7 @@ function createPlugins(options = {}) {
242
254
  const transformWxml = (options = {}) => createVinylTransform(async (file) => {
243
255
  if (!file.contents) return;
244
256
  await refreshRuntimeSet(true);
245
- await runtimeState.patchPromise;
257
+ await runtimeState.readyPromise;
246
258
  const rawSource = file.contents.toString();
247
259
  await require_generator_css.processCachedTask({
248
260
  cache,
@@ -255,7 +267,7 @@ function createPlugins(options = {}) {
255
267
  debug("html cache hit: %s", file.path);
256
268
  },
257
269
  async transform() {
258
- await runtimeState.patchPromise;
270
+ await runtimeState.readyPromise;
259
271
  const code = await templateHandler(rawSource, resolveWxmlHandlerOptions(options));
260
272
  debug("html handle: %s", file.path);
261
273
  return { result: code };
package/dist/gulp.mjs CHANGED
@@ -1,10 +1,12 @@
1
- import { g as ensureRuntimeClassSet, n as shouldSkipJsTransform, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-BIW3Kuke.mjs";
2
- import { d as getRuntimeClassSetSignature } from "./logger-1gx9UllH.mjs";
3
- import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-MyjZhF0z.mjs";
1
+ import { n as getRuntimeClassSetSignature } from "./cache-CHs4DXui.mjs";
2
+ import { n as createDebug } from "./runtime-patch-CwN5ya72.mjs";
3
+ import { i as hasTailwindRootDirectives, r as processCachedTask, t as generateCssByGenerator } from "./generator-css-BIapP56i.mjs";
4
+ import { _ as ensureRuntimeClassSet, g as createTailwindRuntimeReadyPromise, n as getCompilerContext, t as shouldSkipJsTransform } from "./precheck-B4RH6ZNN.mjs";
5
+ import { c as upsertTailwindV4CssSource, s as hasConfiguredTailwindV4CssRoots } from "./tailwindcss-C5IgPlQ0.mjs";
4
6
  import path from "node:path";
5
7
  import process from "node:process";
6
- import { Buffer } from "node:buffer";
7
8
  import fs from "node:fs";
9
+ import { Buffer } from "node:buffer";
8
10
  import stream from "node:stream";
9
11
  //#region src/bundlers/gulp/index.ts
10
12
  const debug = createDebug();
@@ -15,18 +17,18 @@ const Transform = stream.Transform;
15
17
  * @link https://tw.icebreaker.top/docs/quick-start/frameworks/native
16
18
  */
17
19
  function createPlugins(options = {}) {
18
- const opts = getCompilerContext(options);
19
- const { templateHandler, styleHandler, jsHandler, cache, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
20
- const patchRecorderState = setupPatchRecorder(initialTwPatcher, opts.tailwindcssBasedir, {
21
- source: "runtime",
22
- cwd: opts.tailwindcssBasedir ?? process.cwd()
20
+ const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots(options);
21
+ const opts = getCompilerContext({
22
+ ...options,
23
+ __internalDeferMissingCssEntriesWarning: true
23
24
  });
25
+ const { templateHandler, styleHandler, jsHandler, cache, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = opts;
26
+ const readyPromise = createTailwindRuntimeReadyPromise(initialTwPatcher);
24
27
  let runtimeSet = /* @__PURE__ */ new Set();
25
28
  const runtimeState = {
26
29
  twPatcher: initialTwPatcher,
27
- patchPromise: patchRecorderState.patchPromise,
28
- refreshTailwindcssPatcher,
29
- onPatchCompleted: patchRecorderState.onPatchCompleted
30
+ readyPromise,
31
+ refreshTailwindcssPatcher
30
32
  };
31
33
  const defaultStyleHandlerOptionsCache = /* @__PURE__ */ new Map();
32
34
  let cachedDefaultTemplateHandlerOptions;
@@ -59,6 +61,15 @@ function createPlugins(options = {}) {
59
61
  [...nextRuntimeSet].sort().join("\n")
60
62
  ].join("\n\n"));
61
63
  }
64
+ async function registerAutoCssSource(file, rawSource) {
65
+ if (hasInitialTailwindCssRoots || (runtimeState.twPatcher.majorVersion ?? 0) < 4 || !file.path || !hasTailwindRootDirectives(rawSource)) return;
66
+ if (!upsertTailwindV4CssSource(opts, {
67
+ file: path.resolve(file.path),
68
+ css: rawSource
69
+ })) return;
70
+ runtimeSetInitialized = false;
71
+ debug("detected tailwindcss v4 css source from gulp css file: %s", file.path);
72
+ }
62
73
  function resolveWithExtensions(base) {
63
74
  for (const ext of MODULE_EXTENSIONS) {
64
75
  const candidate = `${base}${ext}`;
@@ -166,6 +177,7 @@ function createPlugins(options = {}) {
166
177
  const transformWxss = (options = {}) => createVinylTransform(async (file) => {
167
178
  if (!file.contents) return;
168
179
  const rawSource = file.contents.toString();
180
+ await registerAutoCssSource(file, rawSource);
169
181
  const nextRuntimeSet = await refreshRuntimeSet(true);
170
182
  await processCachedTask({
171
183
  cache,
@@ -178,7 +190,7 @@ function createPlugins(options = {}) {
178
190
  debug("css cache hit: %s", file.path);
179
191
  },
180
192
  async transform() {
181
- await runtimeState.patchPromise;
193
+ await runtimeState.readyPromise;
182
194
  const cssHandlerOptions = resolveWxssFileHandlerOptions(file, options);
183
195
  const css = (await generateCssByGenerator({
184
196
  opts,
@@ -199,7 +211,7 @@ function createPlugins(options = {}) {
199
211
  const transformJs = (options = {}) => createVinylTransform(async (file) => {
200
212
  if (!file.contents) return;
201
213
  await refreshRuntimeSet(true);
202
- await runtimeState.patchPromise;
214
+ await runtimeState.readyPromise;
203
215
  const filename = path.resolve(file.path);
204
216
  const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
205
217
  const handlerOptions = {
@@ -224,7 +236,7 @@ function createPlugins(options = {}) {
224
236
  debug("js cache hit: %s", file.path);
225
237
  },
226
238
  async transform() {
227
- await runtimeState.patchPromise;
239
+ await runtimeState.readyPromise;
228
240
  const currentSource = file.contents?.toString() ?? rawSource;
229
241
  if (shouldSkipJsTransform(currentSource, handlerOptions)) return { result: currentSource };
230
242
  const { code } = await jsHandler(currentSource, runtimeSet, handlerOptions);
@@ -236,7 +248,7 @@ function createPlugins(options = {}) {
236
248
  const transformWxml = (options = {}) => createVinylTransform(async (file) => {
237
249
  if (!file.contents) return;
238
250
  await refreshRuntimeSet(true);
239
- await runtimeState.patchPromise;
251
+ await runtimeState.readyPromise;
240
252
  const rawSource = file.contents.toString();
241
253
  await processCachedTask({
242
254
  cache,
@@ -249,7 +261,7 @@ function createPlugins(options = {}) {
249
261
  debug("html cache hit: %s", file.path);
250
262
  },
251
263
  async transform() {
252
- await runtimeState.patchPromise;
264
+ await runtimeState.readyPromise;
253
265
  const code = await templateHandler(rawSource, resolveWxmlHandlerOptions(options));
254
266
  debug("html handle: %s", file.path);
255
267
  return { result: code };
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generator = require("./generator-9UEp8OoQ.js");
2
+ const require_generator = require("./generator-DKkhJbOg.js");
3
3
  const require_gulp = require("./gulp.js");
4
- const require_postcss = require("./postcss.js");
5
- const require_vite = require("./vite-BkMGwDeH.js");
6
- const require_webpack = require("./webpack-CICGEKT9.js");
4
+ const require_postcss = require("./postcss-QIXwT40c.js");
5
+ const require_vite = require("./vite-DyZuiyap.js");
6
+ const require_webpack = require("./webpack-CNV2dx3Q.js");
7
7
  exports.UnifiedWebpackPluginV5 = require_webpack.UnifiedWebpackPluginV5;
8
8
  exports.WeappTailwindcss = require_vite.WeappTailwindcss;
9
9
  exports.createPlugins = require_gulp.createPlugins;
10
10
  exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
11
11
  exports.weappTailwindcssPackageDir = require_webpack.weappTailwindcssPackageDir;
12
- exports.weappTailwindcssPostcssPlugin = require_postcss;
12
+ exports.weappTailwindcssPostcssPlugin = require_postcss.weappTailwindcssPostcssPlugin;
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { t as createWeappTailwindcssGenerator } from "./generator-Dpp-5s8z.mjs";
1
+ import { t as createWeappTailwindcssGenerator } from "./generator-UBmfduYg.mjs";
2
2
  import { WeappTailwindcss as createPlugins } from "./gulp.mjs";
3
- import weappTailwindcssPostcssPlugin from "./postcss.mjs";
4
- import { t as WeappTailwindcss } from "./vite-fDM-UQpR.mjs";
5
- import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-D2Wdk28V.mjs";
3
+ import { t as weappTailwindcssPostcssPlugin } from "./postcss-w48mGIhe.mjs";
4
+ import { t as WeappTailwindcss } from "./vite-BwgRVgxH.mjs";
5
+ import { n as weappTailwindcssPackageDir, t as UnifiedWebpackPluginV5 } from "./webpack-CT6EEENx.mjs";
6
6
  export { UnifiedWebpackPluginV5, WeappTailwindcss, createPlugins, createWeappTailwindcssGenerator, weappTailwindcssPackageDir, weappTailwindcssPostcssPlugin };
@@ -0,0 +1 @@
1
+ require("@weapp-tailwindcss/logger");
@@ -0,0 +1,2 @@
1
+ import { logger as logger$1 } from "@weapp-tailwindcss/logger";
2
+ export { logger$1 as t };
@@ -0,0 +1 @@
1
+ export declare function prependConfigDirective(css: string, config: string | undefined): string;
@@ -0,0 +1,9 @@
1
+ import type { Result, Root } from 'postcss';
2
+ import type { WeappTailwindcssGenerateResult } from '../generator';
3
+ import type { WeappTailwindcssPostcssPluginOptions } from '../postcss';
4
+ export declare function resolveInputFile(result: Result): string | undefined;
5
+ export declare function resolvePostcssBase(result: Result, options: WeappTailwindcssPostcssPluginOptions): string;
6
+ export declare function resolvePostcssProjectRoot(result: Result, options: WeappTailwindcssPostcssPluginOptions): string;
7
+ export declare function replaceRootCss(root: Root, css: string, result: Result): void;
8
+ export declare function addDependencyMessages(result: Result, generated: WeappTailwindcssGenerateResult): void;
9
+ export declare function addSourceDependencyMessages(result: Result, files: string[]): void;
@@ -0,0 +1,8 @@
1
+ import type { Result, Root } from 'postcss';
2
+ import type { TailwindV4CandidateSource } from '../generator';
3
+ import type { WeappTailwindcssPostcssPluginOptions } from '../postcss';
4
+ export declare function collectAutoTailwindCandidates(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions): Promise<Set<string>>;
5
+ export declare function collectPostcssLocalSources(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions): Promise<{
6
+ files: string[];
7
+ sources: TailwindV4CandidateSource[];
8
+ }>;
@@ -0,0 +1,3 @@
1
+ import type { Result, Root } from 'postcss';
2
+ import type { WeappTailwindcssPostcssPluginOptions } from '../postcss';
3
+ export declare function resolvePostcssTailwindVersion(root: Root, result: Result, options: WeappTailwindcssPostcssPluginOptions): import("../tailwindcss/version").SupportedTailwindcssMajorVersion;
@@ -0,0 +1,298 @@
1
+ const require_chunk = require("./chunk-8l464Juk.js");
2
+ const require_cache = require("./cache-BVAiJV3J.js");
3
+ const require_generator = require("./generator-DKkhJbOg.js");
4
+ let postcss = require("postcss");
5
+ postcss = require_chunk.__toESM(postcss);
6
+ let node_path = require("node:path");
7
+ node_path = require_chunk.__toESM(node_path);
8
+ let node_process = require("node:process");
9
+ node_process = require_chunk.__toESM(node_process);
10
+ let tailwindcss_patch = require("tailwindcss-patch");
11
+ let tailwindcss_config = require("tailwindcss-config");
12
+ let node_fs_promises = require("node:fs/promises");
13
+ let fast_glob = require("fast-glob");
14
+ fast_glob = require_chunk.__toESM(fast_glob);
15
+ //#region src/postcss/config-directive.ts
16
+ function quoteCssString(value) {
17
+ return value.replaceAll("\\", "\\\\").replaceAll("\"", "\\\"");
18
+ }
19
+ function toCssPath(value) {
20
+ return value.replaceAll("\\", "/");
21
+ }
22
+ function prependConfigDirective(css, config) {
23
+ if (!config || /@config\s+/.test(css)) return css;
24
+ return `@config "${quoteCssString(toCssPath(config))}";\n${css}`;
25
+ }
26
+ //#endregion
27
+ //#region src/postcss/context.ts
28
+ const PLUGIN_NAME$1 = "weapp-tailwindcss";
29
+ function resolveInputFile(result) {
30
+ const from = result.opts.from;
31
+ if (typeof from !== "string" || from.length === 0) return;
32
+ return node_path.default.isAbsolute(from) ? from : node_path.default.resolve(node_process.default.cwd(), from);
33
+ }
34
+ function resolvePostcssBase(result, options) {
35
+ if (options.base) return options.base;
36
+ const inputFile = resolveInputFile(result);
37
+ return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
38
+ }
39
+ function resolvePostcssProjectRoot(result, options) {
40
+ if (options.projectRoot) return options.projectRoot;
41
+ const inputFile = resolveInputFile(result);
42
+ return inputFile ? node_path.default.dirname(inputFile) : node_process.default.cwd();
43
+ }
44
+ function replaceRootCss(root, css, result) {
45
+ root.removeAll();
46
+ try {
47
+ const nextRoot = postcss.default.parse(css, { from: resolveInputFile(result) });
48
+ root.append(nextRoot.nodes);
49
+ } catch {
50
+ root.raws = { after: css };
51
+ }
52
+ }
53
+ function addDependencyMessages(result, generated) {
54
+ for (const file of generated.dependencies) result.messages.push({
55
+ type: "dependency",
56
+ plugin: PLUGIN_NAME$1,
57
+ file
58
+ });
59
+ }
60
+ function addSourceDependencyMessages(result, files) {
61
+ for (const file of files) result.messages.push({
62
+ type: "dependency",
63
+ plugin: PLUGIN_NAME$1,
64
+ file
65
+ });
66
+ }
67
+ //#endregion
68
+ //#region src/postcss/source-files.ts
69
+ const POSTCSS_SOURCE_PATTERN = `**/*.{${[
70
+ "html",
71
+ "wxml",
72
+ "axml",
73
+ "jxml",
74
+ "ksml",
75
+ "ttml",
76
+ "qml",
77
+ "tyml",
78
+ "xhsml",
79
+ "swan",
80
+ "vue",
81
+ "mpx",
82
+ "js",
83
+ "jsx",
84
+ "ts",
85
+ "tsx"
86
+ ].join(",")}}`;
87
+ function parseLocalSourceParam(params) {
88
+ const value = params.trim();
89
+ if (!value || value === "none" || value.startsWith("not ") || value.startsWith("inline(")) return;
90
+ return /^(['"])(.+)\1$/.exec(value)?.[2];
91
+ }
92
+ function parseConfigParam(params) {
93
+ const value = params.trim();
94
+ return /^(['"])(.+)\1$/.exec(value)?.[2];
95
+ }
96
+ function parseSourceFileParam(params) {
97
+ const value = params.trim();
98
+ if (!value || value === "none" || value.startsWith("inline(")) return;
99
+ const negated = value.startsWith("not ");
100
+ const sourceValue = negated ? value.slice(4).trim() : value;
101
+ const match = /^(['"])(.+)\1$/.exec(sourceValue);
102
+ return match?.[2] ? {
103
+ negated,
104
+ sourcePath: match[2]
105
+ } : void 0;
106
+ }
107
+ function getSourceExtension(file) {
108
+ return node_path.default.extname(file).slice(1) || void 0;
109
+ }
110
+ async function pathExistsAsDirectory(file) {
111
+ try {
112
+ return (await (0, node_fs_promises.stat)(file)).isDirectory();
113
+ } catch {
114
+ return false;
115
+ }
116
+ }
117
+ async function expandLocalSourceFiles(sourcePath, base) {
118
+ const absoluteSource = node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
119
+ if (await pathExistsAsDirectory(absoluteSource)) return (0, fast_glob.default)(POSTCSS_SOURCE_PATTERN, {
120
+ absolute: true,
121
+ cwd: absoluteSource,
122
+ onlyFiles: true
123
+ });
124
+ return (0, fast_glob.default)(sourcePath, {
125
+ absolute: true,
126
+ cwd: base,
127
+ onlyFiles: true
128
+ });
129
+ }
130
+ async function resolveTailwindSourceEntry(sourcePath, base, negated) {
131
+ const absoluteSource = node_path.default.isAbsolute(sourcePath) ? node_path.default.resolve(sourcePath) : node_path.default.resolve(base, sourcePath);
132
+ if (await pathExistsAsDirectory(absoluteSource)) return {
133
+ base: absoluteSource,
134
+ negated,
135
+ pattern: POSTCSS_SOURCE_PATTERN
136
+ };
137
+ if (node_path.default.isAbsolute(sourcePath)) return {
138
+ base: node_path.default.dirname(absoluteSource),
139
+ negated,
140
+ pattern: node_path.default.basename(absoluteSource)
141
+ };
142
+ return {
143
+ base,
144
+ negated,
145
+ pattern: sourcePath
146
+ };
147
+ }
148
+ function collectConfigPaths(root, base) {
149
+ const configPaths = [];
150
+ root.walkAtRules("config", (rule) => {
151
+ const configPath = parseConfigParam(rule.params);
152
+ if (configPath) configPaths.push(node_path.default.isAbsolute(configPath) ? configPath : node_path.default.resolve(base, configPath));
153
+ });
154
+ return [...new Set(configPaths)];
155
+ }
156
+ function normalizeContentFiles(content) {
157
+ if (typeof content === "string") return [content];
158
+ if (Array.isArray(content)) return content.flatMap((item) => normalizeContentFiles(item));
159
+ if (typeof content === "object" && content !== null && "files" in content) return normalizeContentFiles(content.files);
160
+ return [];
161
+ }
162
+ async function collectConfigContentFiles(root, base) {
163
+ const configPaths = collectConfigPaths(root, base);
164
+ const files = [];
165
+ for (const configPath of configPaths) {
166
+ const contentFiles = normalizeContentFiles((await (0, tailwindcss_config.loadConfig)({
167
+ config: configPath,
168
+ cwd: node_path.default.dirname(configPath)
169
+ }))?.config.content);
170
+ for (const contentFile of contentFiles) files.push(...await expandLocalSourceFiles(contentFile, node_path.default.dirname(configPath)));
171
+ }
172
+ return {
173
+ configPaths,
174
+ files: [...new Set(files)]
175
+ };
176
+ }
177
+ async function collectAutoTailwindCandidates(root, result, options) {
178
+ if (options.scanSources === false) return /* @__PURE__ */ new Set();
179
+ const base = resolvePostcssBase(result, options);
180
+ const projectRoot = resolvePostcssProjectRoot(result, options);
181
+ const sourceEntryTasks = [];
182
+ if (!root.toString().includes("source(none)")) sourceEntryTasks.push(Promise.resolve({
183
+ base,
184
+ negated: false,
185
+ pattern: POSTCSS_SOURCE_PATTERN
186
+ }));
187
+ root.walkAtRules("source", (rule) => {
188
+ const parsed = parseSourceFileParam(rule.params);
189
+ if (!parsed) return;
190
+ sourceEntryTasks.push(resolveTailwindSourceEntry(parsed.sourcePath, base, parsed.negated));
191
+ });
192
+ const sourceEntries = await Promise.all(sourceEntryTasks);
193
+ if (sourceEntries.length === 0) return /* @__PURE__ */ new Set();
194
+ const candidates = await (0, tailwindcss_patch.extractValidCandidates)({
195
+ base,
196
+ css: root.toString(),
197
+ cwd: projectRoot,
198
+ sources: sourceEntries
199
+ });
200
+ return new Set(candidates);
201
+ }
202
+ async function collectPostcssLocalSources(root, result, options) {
203
+ const base = resolvePostcssBase(result, options);
204
+ const sourcePaths = [];
205
+ root.walkAtRules("source", (rule) => {
206
+ const sourcePath = parseLocalSourceParam(rule.params);
207
+ if (sourcePath) sourcePaths.push(sourcePath);
208
+ });
209
+ const configContentFiles = await collectConfigContentFiles(root, base);
210
+ const files = [...new Set((await Promise.all(sourcePaths.map((sourcePath) => expandLocalSourceFiles(sourcePath, base)))).flat().concat(configContentFiles.files))];
211
+ const sources = await Promise.all(files.map(async (file) => ({
212
+ content: await (0, node_fs_promises.readFile)(file, "utf8"),
213
+ extension: getSourceExtension(file)
214
+ })));
215
+ return {
216
+ files: [...files, ...configContentFiles.configPaths],
217
+ sources
218
+ };
219
+ }
220
+ //#endregion
221
+ //#region src/postcss/tailwind-version.ts
222
+ function hasTailwindV4CssSyntax(root) {
223
+ let hasV4Syntax = false;
224
+ root.walkAtRules((rule) => {
225
+ if (rule.name === "theme" || rule.name === "source" || rule.name === "custom-variant") hasV4Syntax = true;
226
+ if (rule.name === "import" && /(['"])tailwindcss\1/.test(rule.params)) hasV4Syntax = true;
227
+ });
228
+ return hasV4Syntax;
229
+ }
230
+ function resolvePostcssTailwindVersion(root, result, options) {
231
+ const packageName = options.packageName ?? "tailwindcss";
232
+ const installedVersion = require_cache.readInstalledPackageMajorVersion(packageName, resolvePostcssProjectRoot(result, options));
233
+ if (installedVersion) return installedVersion;
234
+ if (options.version) return options.version;
235
+ if (packageName === "@tailwindcss/postcss" || packageName.includes("tailwindcss4")) return 4;
236
+ if (packageName.includes("tailwindcss3")) return 3;
237
+ if (hasTailwindV4CssSyntax(root)) return 4;
238
+ return 4;
239
+ }
240
+ //#endregion
241
+ //#region src/postcss.ts
242
+ const PLUGIN_NAME = "weapp-tailwindcss";
243
+ const weappTailwindcssPostcssPlugin = (options = {}) => {
244
+ return {
245
+ postcssPlugin: PLUGIN_NAME,
246
+ async Once(root, { result }) {
247
+ const { candidates, generator: userGeneratorOptions, scanSources, sources, styleOptions, ...sourceOptions } = options;
248
+ const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(userGeneratorOptions);
249
+ const tailwindVersion = resolvePostcssTailwindVersion(root, result, options);
250
+ const [collectedSources, autoCandidates] = await Promise.all([collectPostcssLocalSources(root, result, options), collectAutoTailwindCandidates(root, result, options)]);
251
+ const generatorConfig = generatorOptions.config ?? options.config;
252
+ const generator = require_generator.createWeappTailwindcssGenerator(tailwindVersion === 3 ? await require_generator.resolveTailwindV3Source({
253
+ config: generatorConfig,
254
+ css: sourceOptions.css ?? root.toString(),
255
+ base: resolvePostcssBase(result, options),
256
+ cwd: resolvePostcssProjectRoot(result, options),
257
+ projectRoot: resolvePostcssProjectRoot(result, options),
258
+ packageName: options.packageName,
259
+ postcssPlugin: options.postcssPlugin
260
+ }) : await require_generator.resolveTailwindV4Source({
261
+ ...sourceOptions,
262
+ css: prependConfigDirective(sourceOptions.css ?? root.toString(), generatorConfig),
263
+ base: resolvePostcssBase(result, options),
264
+ projectRoot: resolvePostcssProjectRoot(result, options)
265
+ }));
266
+ const generateOptions = {
267
+ candidates: new Set([...autoCandidates, ...candidates ?? []]),
268
+ scanSources: scanSources ?? false,
269
+ sources: [...collectedSources.sources, ...sources ?? []],
270
+ styleOptions: {
271
+ ...generatorOptions.styleOptions,
272
+ ...styleOptions
273
+ },
274
+ tailwindcssV3Compatibility: generatorOptions.tailwindcssV3Compatibility,
275
+ target: generatorOptions.target
276
+ };
277
+ const generated = await generator.generate(generateOptions);
278
+ replaceRootCss(root, generated.css, result);
279
+ addDependencyMessages(result, generated);
280
+ addSourceDependencyMessages(result, collectedSources.files);
281
+ result.messages.push({
282
+ type: "weapp-tailwindcss:generated",
283
+ plugin: PLUGIN_NAME,
284
+ target: generated.target,
285
+ classSet: generated.classSet,
286
+ rawCss: generated.rawCss
287
+ });
288
+ }
289
+ };
290
+ };
291
+ weappTailwindcssPostcssPlugin.postcss = true;
292
+ //#endregion
293
+ Object.defineProperty(exports, "weappTailwindcssPostcssPlugin", {
294
+ enumerable: true,
295
+ get: function() {
296
+ return weappTailwindcssPostcssPlugin;
297
+ }
298
+ });