weapp-tailwindcss 5.0.11 → 5.0.13

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 (109) hide show
  1. package/dist/{bundle-state-BwtEqxvU.js → bundle-state-CKWeTEhv.js} +2 -40
  2. package/dist/{bundle-state-CXzPknlT.mjs → bundle-state-zQ2MrDdi.mjs} +2 -34
  3. package/dist/bundlers/gulp/vinyl-transform.d.ts +1 -1
  4. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +7 -2
  5. package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
  6. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
  7. package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
  8. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +4 -0
  9. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
  11. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
  12. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +5 -22
  13. package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
  14. package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
  15. package/dist/bundlers/shared/hmr-timing.d.ts +1 -0
  16. package/dist/bundlers/vite/css-memory.d.ts +27 -0
  17. package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
  18. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
  19. package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
  20. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
  21. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +9 -7
  22. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +7 -0
  23. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +58 -0
  24. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
  25. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +77 -0
  26. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
  27. package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
  28. package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
  29. package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
  30. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
  31. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +29 -0
  32. package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
  33. package/dist/bundlers/vite/generate-bundle/types.d.ts +7 -0
  34. package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
  35. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
  36. package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
  37. package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
  38. package/dist/bundlers/vite/map-cache.d.ts +2 -0
  39. package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
  40. package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
  41. package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
  42. package/dist/bundlers/vite/source-candidates.d.ts +9 -0
  43. package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
  44. package/dist/bundlers/vite/source-scan.d.ts +1 -1
  45. package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -0
  46. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +11 -8
  47. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +2 -0
  48. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
  49. package/dist/cache/index.d.ts +4 -0
  50. package/dist/cli.js +9 -2
  51. package/dist/cli.mjs +8 -1
  52. package/dist/core.d.ts +7 -0
  53. package/dist/core.js +8 -5
  54. package/dist/core.mjs +8 -5
  55. package/dist/css-macro.js +1 -1
  56. package/dist/css-macro.mjs +1 -1
  57. package/dist/{defaults-DH0ZQRhy.mjs → defaults-Bqx18S1f.mjs} +2 -35
  58. package/dist/{defaults-Boc26eel.js → defaults-C_J_kBpw.js} +2 -35
  59. package/dist/defaults.js +1 -1
  60. package/dist/defaults.mjs +1 -1
  61. package/dist/framework/index.d.ts +59 -0
  62. package/dist/framework.d.ts +1 -0
  63. package/dist/framework.js +198 -0
  64. package/dist/framework.mjs +180 -0
  65. package/dist/{generator-ChgOWNOj.js → generator-CzpArpCL.js} +1 -1
  66. package/dist/{generator-h2XRiJ9-.mjs → generator-ITLd7PTl.mjs} +1 -1
  67. package/dist/generator.js +2 -2
  68. package/dist/generator.mjs +2 -2
  69. package/dist/{gulp-Be88jhoY.mjs → gulp-DfOQERcV.mjs} +137 -23
  70. package/dist/{gulp-CHtZF-oT.js → gulp-XT8Jc7lH.js} +137 -23
  71. package/dist/gulp.js +1 -1
  72. package/dist/gulp.mjs +1 -1
  73. package/dist/{hmr-timing-BkivBZvN.js → hmr-timing-BMftW7Us.js} +354 -225
  74. package/dist/{hmr-timing-Ct5w4hdM.mjs → hmr-timing-DQIP_8qP.mjs} +341 -225
  75. package/dist/index.d.ts +1 -0
  76. package/dist/index.js +20 -4
  77. package/dist/index.mjs +6 -5
  78. package/dist/postcss.js +9 -10
  79. package/dist/postcss.mjs +7 -5
  80. package/dist/{precheck-CY9oaH49.js → precheck-B0Z8yW7E.js} +108 -27
  81. package/dist/{precheck-BpHxsWRd.mjs → precheck-CRI90iL1.mjs} +109 -28
  82. package/dist/presets.js +3 -3
  83. package/dist/presets.mjs +3 -3
  84. package/dist/tailwindcss/source-scan.d.ts +1 -0
  85. package/dist/tailwindcss/v3-engine/generator.d.ts +17 -0
  86. package/dist/tailwindcss/v3-engine/index.d.ts +1 -1
  87. package/dist/tailwindcss/v3-engine/types.d.ts +1 -0
  88. package/dist/tailwindcss/v4-engine/generator.d.ts +19 -0
  89. package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
  90. package/dist/{tailwindcss-Bfy2egdX.mjs → tailwindcss-DTq3uYBK.mjs} +2 -2
  91. package/dist/{tailwindcss-DbbAKAZP.js → tailwindcss-DZEwT3C_.js} +3 -3
  92. package/dist/{transform-r5evL6Hn.mjs → transform-DfcEjsZF.mjs} +29 -21
  93. package/dist/{transform-Cd634UZV.js → transform-YmrmxuF3.js} +29 -21
  94. package/dist/types/user-defined-options/general.d.ts +3 -1
  95. package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
  96. package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
  97. package/dist/{v3-engine-D0yA9ZkF.js → v3-engine-2rrgylhn.js} +194 -34
  98. package/dist/{v3-engine-CFkP6dWF.mjs → v3-engine-C6eJ0YzK.mjs} +176 -34
  99. package/dist/{vite-j9cB2Ff1.js → vite-CXHVsHmX.js} +2071 -1160
  100. package/dist/{vite-Bd8qf9dK.mjs → vite-DjI09vVN.mjs} +2071 -1160
  101. package/dist/vite.js +1 -1
  102. package/dist/vite.mjs +1 -1
  103. package/dist/weapp-tw-css-import-rewrite-loader.js +476 -217
  104. package/dist/weapp-tw-runtime-classset-loader.js +25 -0
  105. package/dist/{webpack-DPdrcC2X.mjs → webpack-BcPpnT90.mjs} +251 -40
  106. package/dist/{webpack-CJAOcYEO.js → webpack-CfkUkMXG.js} +254 -43
  107. package/dist/webpack.js +1 -1
  108. package/dist/webpack.mjs +1 -1
  109. package/package.json +10 -5
@@ -1,7 +1,7 @@
1
- import { D as normalizeTailwindConfigDirectives, T as hasTailwindRootDirectives, k as normalizeTailwindSourceForGenerator, l as getRuntimeClassSetSignature, m as resolveViteSourceScanEntries, rt as createDebug } from "./v3-engine-CFkP6dWF.mjs";
2
- import { n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise, y as ensureRuntimeClassSet } from "./precheck-BpHxsWRd.mjs";
3
- import { c as hasConfiguredTailwindV4CssRoots, l as upsertTailwindV4CssSource } from "./tailwindcss-Bfy2egdX.mjs";
4
- import { a as createTailwindV3DefaultExtractor, g as createCssTokenSourceMap, h as createCssSourceTraceCacheSignature, m as annotateCssSourceTrace, n as emitHmrTiming, o as createBundleRuntimeClassSetManager, r as createSourceCandidateCollector, s as generateCssByGenerator, v as processCachedTask } from "./hmr-timing-Ct5w4hdM.mjs";
1
+ import { D as hasTailwindRootDirectives, Y as getTailwindV4IncrementalGenerateCacheStats, a as getTailwindV3IncrementalGenerateCacheStats, h as resolveViteSourceScanEntries, j as normalizeTailwindSourceForGenerator, k as normalizeTailwindConfigDirectives, ot as createDebug, u as getRuntimeClassSetSignature } from "./v3-engine-C6eJ0YzK.mjs";
2
+ import { n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise, y as ensureRuntimeClassSet } from "./precheck-CRI90iL1.mjs";
3
+ import { c as hasConfiguredTailwindV4CssRoots, l as upsertTailwindV4CssSource } from "./tailwindcss-DTq3uYBK.mjs";
4
+ import { _ as createCssSourceTraceCacheSignature, a as createTailwindV3DefaultExtractor, b as processCachedTask, g as annotateCssSourceTrace, n as emitHmrTiming, o as createBundleRuntimeClassSetManager, r as createSourceCandidateCollector, s as generateCssByGenerator, v as createCssTokenSourceMap } from "./hmr-timing-DQIP_8qP.mjs";
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import process from "node:process";
@@ -53,7 +53,7 @@ function createGulpModuleGraphOptions(opts) {
53
53
  },
54
54
  filter(id) {
55
55
  const relative = path.relative(process.cwd(), id);
56
- return opts.jsMatcher(relative) || opts.wxsMatcher(relative);
56
+ return opts.jsMatcher?.(relative) === true || opts.wxsMatcher?.(relative) === true;
57
57
  }
58
58
  };
59
59
  }
@@ -104,14 +104,17 @@ function createGulpRuntimeSnapshot(runtimeSourcesByFile, changedFiles) {
104
104
  //#endregion
105
105
  //#region src/bundlers/gulp/vinyl-transform.ts
106
106
  const Transform = stream.Transform;
107
- function createVinylTransform(phase, handler) {
107
+ function createVinylTransform(phase, handler, getTimingDetails) {
108
108
  return new Transform({
109
109
  objectMode: true,
110
110
  async transform(file, _encoding, callback) {
111
111
  const hmrTimingStartedAt = performance.now();
112
112
  try {
113
113
  await handler(file);
114
- emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, { file: file.relative || path.basename(file.path) });
114
+ emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, {
115
+ file: file.relative || path.basename(file.path),
116
+ ...getTimingDetails?.(file)
117
+ });
115
118
  callback(null, file);
116
119
  } catch (error) {
117
120
  callback(error, file);
@@ -122,6 +125,69 @@ function createVinylTransform(phase, handler) {
122
125
  //#endregion
123
126
  //#region src/bundlers/gulp/index.ts
124
127
  const debug = createDebug();
128
+ const GULP_RUNTIME_SOURCE_CACHE_MAX = 256;
129
+ const GULP_PROCESS_CACHE_MAX = 512;
130
+ function toMb(bytes) {
131
+ return Math.round(bytes / 1024 / 1024);
132
+ }
133
+ function touchMapEntry(map, key, value) {
134
+ map.delete(key);
135
+ map.set(key, value);
136
+ }
137
+ function pruneGulpRuntimeSourceCaches(sourceHashByFile, sourcesByFile) {
138
+ while (sourcesByFile.size > GULP_RUNTIME_SOURCE_CACHE_MAX) {
139
+ const oldestKey = sourcesByFile.keys().next().value;
140
+ if (typeof oldestKey !== "string") break;
141
+ sourcesByFile.delete(oldestKey);
142
+ sourceHashByFile.delete(oldestKey);
143
+ }
144
+ }
145
+ function rememberGulpProcessCacheKey(cacheKeys, key) {
146
+ cacheKeys.delete(key);
147
+ cacheKeys.add(key);
148
+ while (cacheKeys.size > GULP_PROCESS_CACHE_MAX) {
149
+ const oldestKey = cacheKeys.keys().next().value;
150
+ if (typeof oldestKey !== "string") break;
151
+ cacheKeys.delete(oldestKey);
152
+ }
153
+ }
154
+ function pruneGulpProcessCache(cache, cacheKeys) {
155
+ cache.prune?.({
156
+ cacheKeys,
157
+ hashKeys: cacheKeys
158
+ });
159
+ }
160
+ function resolveGulpMemoryDebugStats(context) {
161
+ if (process.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
162
+ const memory = process.memoryUsage();
163
+ return {
164
+ phase: context.phase,
165
+ process: {
166
+ rssMb: toMb(memory.rss),
167
+ heapTotalMb: toMb(memory.heapTotal),
168
+ heapUsedMb: toMb(memory.heapUsed),
169
+ externalMb: toMb(memory.external),
170
+ arrayBuffersMb: toMb(memory.arrayBuffers)
171
+ },
172
+ runtime: {
173
+ runtimeSet: context.runtimeSet.size,
174
+ runtimeSourceHashByFile: context.runtimeSourceHashByFile.size,
175
+ runtimeSourcesByFile: context.runtimeSourcesByFile.size,
176
+ maxRuntimeSources: GULP_RUNTIME_SOURCE_CACHE_MAX
177
+ },
178
+ processCache: {
179
+ instance: context.cache.instance.size,
180
+ hashMap: context.cache.hashMap.size,
181
+ activeCacheKeys: context.gulpProcessCacheKeys.size,
182
+ maxCacheKeys: GULP_PROCESS_CACHE_MAX
183
+ },
184
+ gulpOptions: { defaultStyleHandlerOptions: context.defaultStyleHandlerOptionsCache.size },
185
+ tailwind: {
186
+ v3: getTailwindV3IncrementalGenerateCacheStats(),
187
+ v4: getTailwindV4IncrementalGenerateCacheStats()
188
+ }
189
+ };
190
+ }
125
191
  /**
126
192
  * @name weapp-tw-gulp
127
193
  * @description gulp版本weapp-tw插件
@@ -153,6 +219,7 @@ function createPlugins(options = {}) {
153
219
  const runtimeSourcesByFile = /* @__PURE__ */ new Map();
154
220
  let cachedGulpSourceCandidates;
155
221
  let cachedGulpSourceCandidateSignature;
222
+ const gulpProcessCacheKeys = /* @__PURE__ */ new Set();
156
223
  const sourceCandidateExtractor = initialTwPatcher.majorVersion === 3 ? createTailwindV3DefaultExtractor() : void 0;
157
224
  const bundleRuntimeClassSetManager = options.__internalGulpRuntimeClassSetManager ?? createBundleRuntimeClassSetManager();
158
225
  function invalidateGulpSourceCandidates() {
@@ -185,12 +252,14 @@ function createPlugins(options = {}) {
185
252
  const filename = path.resolve(file.path);
186
253
  const hash = cache.computeHash(rawSource);
187
254
  const changed = runtimeSourceHashByFile.get(filename) !== hash;
255
+ runtimeSourceHashByFile.delete(filename);
188
256
  runtimeSourceHashByFile.set(filename, hash);
189
- runtimeSourcesByFile.set(filename, {
257
+ touchMapEntry(runtimeSourcesByFile, filename, {
190
258
  source: rawSource,
191
259
  type
192
260
  });
193
- if (changed && runtimeState.twPatcher.majorVersion === 4) invalidateGulpSourceCandidates();
261
+ pruneGulpRuntimeSourceCaches(runtimeSourceHashByFile, runtimeSourcesByFile);
262
+ if (changed) invalidateGulpSourceCandidates();
194
263
  if (!changed && runtimeSetInitialized) return runtimeSet;
195
264
  if (runtimeState.twPatcher.majorVersion === 4 && !runtimeSetDirty) try {
196
265
  runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, createGulpRuntimeSnapshot(runtimeSourcesByFile, [filename]));
@@ -263,12 +332,13 @@ function createPlugins(options = {}) {
263
332
  cachedGulpSourceCandidateSourceGetter = (entries) => collector.sourcesForEntries(entries);
264
333
  return cachedGulpSourceCandidateGetter;
265
334
  }
266
- function createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature) {
335
+ function createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature, sourceCandidateSignature) {
267
336
  return cache.computeHash([
268
337
  rawSource,
269
338
  getRuntimeClassSetSignature(runtimeState.twPatcher),
270
339
  [...nextRuntimeSet].sort().join("\n"),
271
- sourceTraceSignature ?? "css-source-trace:0"
340
+ sourceTraceSignature ?? "css-source-trace:0",
341
+ sourceCandidateSignature ?? "gulp-source-candidates:0"
272
342
  ].join("\n\n"));
273
343
  }
274
344
  async function registerAutoCssSource(file, rawSource) {
@@ -309,12 +379,36 @@ function createPlugins(options = {}) {
309
379
  function resolveGulpMatcherName(file) {
310
380
  return (file.relative || path.basename(file.path)).replaceAll(path.sep, "/");
311
381
  }
312
- function resolveWxssFileHandlerOptions(file, options) {
382
+ function resolveWxssFileHandlerOptions(file, rawSource, options) {
313
383
  const resolved = resolveWxssHandlerOptions(options);
314
- if (resolved.isMainChunk !== void 0) return resolved;
384
+ const sourceFile = file.path ? path.resolve(file.path) : void 0;
385
+ const sourceOptions = sourceFile ? {
386
+ outputRoot: path.resolve(file.cwd ?? process.cwd()),
387
+ sourceCss: rawSource,
388
+ sourceFile
389
+ } : void 0;
390
+ if (resolved.isMainChunk !== void 0) return {
391
+ ...resolved,
392
+ postcssOptions: {
393
+ ...resolved.postcssOptions,
394
+ options: {
395
+ ...resolved.postcssOptions?.options,
396
+ ...sourceFile ? { from: sourceFile } : {}
397
+ }
398
+ },
399
+ ...sourceOptions ? { sourceOptions } : {}
400
+ };
315
401
  return {
316
402
  ...resolved,
317
- isMainChunk: opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType)
403
+ isMainChunk: opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType),
404
+ postcssOptions: {
405
+ ...resolved.postcssOptions,
406
+ options: {
407
+ ...resolved.postcssOptions?.options,
408
+ ...sourceFile ? { from: sourceFile } : {}
409
+ }
410
+ },
411
+ ...sourceOptions ? { sourceOptions } : {}
318
412
  };
319
413
  }
320
414
  function resolveWxssUserHandlerOptions(options) {
@@ -336,20 +430,33 @@ function createPlugins(options = {}) {
336
430
  ...options
337
431
  };
338
432
  }
433
+ function resolveGulpTransformTimingDetails(phase) {
434
+ return { memoryDebug: resolveGulpMemoryDebugStats({
435
+ cache,
436
+ defaultStyleHandlerOptionsCache,
437
+ gulpProcessCacheKeys,
438
+ phase,
439
+ runtimeSet,
440
+ runtimeSourceHashByFile,
441
+ runtimeSourcesByFile
442
+ }) };
443
+ }
339
444
  const transformWxss = (options = {}) => createVinylTransform("css", async (file) => {
340
445
  if (!file.contents) return;
341
446
  const rawSource = file.contents.toString();
342
447
  const cssSourceChanged = await registerAutoCssSource(file, rawSource);
343
448
  const isMainChunk = opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType);
344
449
  const shouldUseGenerator = runtimeState.twPatcher.majorVersion !== 3 || hasTailwindRootDirectives(rawSource);
345
- const gulpV4SourceCandidates = shouldUseGenerator && runtimeState.twPatcher.majorVersion === 4 ? await refreshGulpV4SourceCandidates(cssSourceChanged) : void 0;
450
+ let gulpSourceCandidateGetter;
451
+ if (shouldUseGenerator && runtimeState.twPatcher.majorVersion === 4) gulpSourceCandidateGetter = await refreshGulpV4SourceCandidates(cssSourceChanged);
346
452
  let nextRuntimeSet = await refreshRuntimeSet({
347
453
  forceRefresh: cssSourceChanged,
348
454
  forceCollect: cssSourceChanged || runtimeState.twPatcher.majorVersion !== 4 && isMainChunk,
349
455
  clearCache: cssSourceChanged
350
456
  });
351
- if (runtimeState.twPatcher.majorVersion === 3 && isMainChunk && shouldUseGenerator) {
352
- const sourceCandidates = await refreshGulpSourceCandidates(cssSourceChanged);
457
+ if (runtimeState.twPatcher.majorVersion === 3 && shouldUseGenerator) {
458
+ const sourceCandidates = await refreshGulpSourceCandidates(cssSourceChanged || isMainChunk);
459
+ gulpSourceCandidateGetter = cachedGulpSourceCandidateGetter;
353
460
  if (sourceCandidates.size > 0) {
354
461
  nextRuntimeSet = new Set([...nextRuntimeSet, ...sourceCandidates]);
355
462
  runtimeSet = nextRuntimeSet;
@@ -357,10 +464,11 @@ function createPlugins(options = {}) {
357
464
  }
358
465
  const sourceTraceTokenSources = cachedGulpSourceCandidateSourceGetter ? createCssTokenSourceMap(cachedGulpSourceCandidateSourceGetter(void 0), opts) : void 0;
359
466
  const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
467
+ const sourceCandidateSignature = cachedGulpSourceCandidateGetter ? `gulp-source-candidates:1:${[...cachedGulpSourceCandidateGetter(void 0)].sort().join("\n")}` : void 0;
360
468
  await processCachedTask({
361
469
  cache,
362
470
  cacheKey: file.path,
363
- hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature),
471
+ hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature, sourceCandidateSignature),
364
472
  applyResult(source) {
365
473
  file.contents = Buffer.from(source);
366
474
  },
@@ -369,7 +477,7 @@ function createPlugins(options = {}) {
369
477
  },
370
478
  async transform() {
371
479
  await runtimeState.readyPromise;
372
- const cssHandlerOptions = resolveWxssFileHandlerOptions(file, options);
480
+ const cssHandlerOptions = resolveWxssFileHandlerOptions(file, rawSource, options);
373
481
  const css = annotateCssSourceTrace((shouldUseGenerator ? await generateCssByGenerator({
374
482
  opts,
375
483
  runtimeState,
@@ -378,7 +486,7 @@ function createPlugins(options = {}) {
378
486
  file: file.path,
379
487
  cssHandlerOptions,
380
488
  cssUserHandlerOptions: resolveWxssUserHandlerOptions(options),
381
- getSourceCandidatesForEntries: gulpV4SourceCandidates,
489
+ getSourceCandidatesForEntries: gulpSourceCandidateGetter,
382
490
  styleHandler,
383
491
  debug
384
492
  }) : void 0)?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css, {
@@ -389,7 +497,9 @@ function createPlugins(options = {}) {
389
497
  return { result: css };
390
498
  }
391
499
  });
392
- });
500
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
501
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
502
+ }, () => resolveGulpTransformTimingDetails("css"));
393
503
  const transformJs = (options = {}) => createVinylTransform("js", async (file) => {
394
504
  if (!file.contents) return;
395
505
  const filename = path.resolve(file.path);
@@ -429,7 +539,9 @@ function createPlugins(options = {}) {
429
539
  return { result: code };
430
540
  }
431
541
  });
432
- });
542
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
543
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
544
+ }, () => resolveGulpTransformTimingDetails("js"));
433
545
  const transformWxml = (options = {}) => createVinylTransform("html", async (file) => {
434
546
  if (!file.contents) return;
435
547
  const rawSource = file.contents.toString();
@@ -452,7 +564,9 @@ function createPlugins(options = {}) {
452
564
  return { result: code };
453
565
  }
454
566
  });
455
- });
567
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
568
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
569
+ }, () => resolveGulpTransformTimingDetails("html"));
456
570
  return {
457
571
  transformWxss,
458
572
  transformWxml,
@@ -1,8 +1,8 @@
1
1
  const require_chunk = require("./chunk-emK7D4bc.js");
2
- const require_v3_engine = require("./v3-engine-D0yA9ZkF.js");
3
- const require_precheck = require("./precheck-CY9oaH49.js");
4
- const require_tailwindcss = require("./tailwindcss-DbbAKAZP.js");
5
- const require_hmr_timing = require("./hmr-timing-BkivBZvN.js");
2
+ const require_v3_engine = require("./v3-engine-2rrgylhn.js");
3
+ const require_precheck = require("./precheck-B0Z8yW7E.js");
4
+ const require_tailwindcss = require("./tailwindcss-DZEwT3C_.js");
5
+ const require_hmr_timing = require("./hmr-timing-BMftW7Us.js");
6
6
  let node_fs = require("node:fs");
7
7
  node_fs = require_chunk.__toESM(node_fs);
8
8
  let node_path = require("node:path");
@@ -58,7 +58,7 @@ function createGulpModuleGraphOptions(opts) {
58
58
  },
59
59
  filter(id) {
60
60
  const relative = node_path.default.relative(node_process.default.cwd(), id);
61
- return opts.jsMatcher(relative) || opts.wxsMatcher(relative);
61
+ return opts.jsMatcher?.(relative) === true || opts.wxsMatcher?.(relative) === true;
62
62
  }
63
63
  };
64
64
  }
@@ -109,14 +109,17 @@ function createGulpRuntimeSnapshot(runtimeSourcesByFile, changedFiles) {
109
109
  //#endregion
110
110
  //#region src/bundlers/gulp/vinyl-transform.ts
111
111
  const Transform = node_stream.default.Transform;
112
- function createVinylTransform(phase, handler) {
112
+ function createVinylTransform(phase, handler, getTimingDetails) {
113
113
  return new Transform({
114
114
  objectMode: true,
115
115
  async transform(file, _encoding, callback) {
116
116
  const hmrTimingStartedAt = performance.now();
117
117
  try {
118
118
  await handler(file);
119
- require_hmr_timing.emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, { file: file.relative || node_path.default.basename(file.path) });
119
+ require_hmr_timing.emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, {
120
+ file: file.relative || node_path.default.basename(file.path),
121
+ ...getTimingDetails?.(file)
122
+ });
120
123
  callback(null, file);
121
124
  } catch (error) {
122
125
  callback(error, file);
@@ -127,6 +130,69 @@ function createVinylTransform(phase, handler) {
127
130
  //#endregion
128
131
  //#region src/bundlers/gulp/index.ts
129
132
  const debug = require_v3_engine.createDebug();
133
+ const GULP_RUNTIME_SOURCE_CACHE_MAX = 256;
134
+ const GULP_PROCESS_CACHE_MAX = 512;
135
+ function toMb(bytes) {
136
+ return Math.round(bytes / 1024 / 1024);
137
+ }
138
+ function touchMapEntry(map, key, value) {
139
+ map.delete(key);
140
+ map.set(key, value);
141
+ }
142
+ function pruneGulpRuntimeSourceCaches(sourceHashByFile, sourcesByFile) {
143
+ while (sourcesByFile.size > GULP_RUNTIME_SOURCE_CACHE_MAX) {
144
+ const oldestKey = sourcesByFile.keys().next().value;
145
+ if (typeof oldestKey !== "string") break;
146
+ sourcesByFile.delete(oldestKey);
147
+ sourceHashByFile.delete(oldestKey);
148
+ }
149
+ }
150
+ function rememberGulpProcessCacheKey(cacheKeys, key) {
151
+ cacheKeys.delete(key);
152
+ cacheKeys.add(key);
153
+ while (cacheKeys.size > GULP_PROCESS_CACHE_MAX) {
154
+ const oldestKey = cacheKeys.keys().next().value;
155
+ if (typeof oldestKey !== "string") break;
156
+ cacheKeys.delete(oldestKey);
157
+ }
158
+ }
159
+ function pruneGulpProcessCache(cache, cacheKeys) {
160
+ cache.prune?.({
161
+ cacheKeys,
162
+ hashKeys: cacheKeys
163
+ });
164
+ }
165
+ function resolveGulpMemoryDebugStats(context) {
166
+ if (node_process.default.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
167
+ const memory = node_process.default.memoryUsage();
168
+ return {
169
+ phase: context.phase,
170
+ process: {
171
+ rssMb: toMb(memory.rss),
172
+ heapTotalMb: toMb(memory.heapTotal),
173
+ heapUsedMb: toMb(memory.heapUsed),
174
+ externalMb: toMb(memory.external),
175
+ arrayBuffersMb: toMb(memory.arrayBuffers)
176
+ },
177
+ runtime: {
178
+ runtimeSet: context.runtimeSet.size,
179
+ runtimeSourceHashByFile: context.runtimeSourceHashByFile.size,
180
+ runtimeSourcesByFile: context.runtimeSourcesByFile.size,
181
+ maxRuntimeSources: GULP_RUNTIME_SOURCE_CACHE_MAX
182
+ },
183
+ processCache: {
184
+ instance: context.cache.instance.size,
185
+ hashMap: context.cache.hashMap.size,
186
+ activeCacheKeys: context.gulpProcessCacheKeys.size,
187
+ maxCacheKeys: GULP_PROCESS_CACHE_MAX
188
+ },
189
+ gulpOptions: { defaultStyleHandlerOptions: context.defaultStyleHandlerOptionsCache.size },
190
+ tailwind: {
191
+ v3: require_v3_engine.getTailwindV3IncrementalGenerateCacheStats(),
192
+ v4: require_v3_engine.getTailwindV4IncrementalGenerateCacheStats()
193
+ }
194
+ };
195
+ }
130
196
  /**
131
197
  * @name weapp-tw-gulp
132
198
  * @description gulp版本weapp-tw插件
@@ -158,6 +224,7 @@ function createPlugins(options = {}) {
158
224
  const runtimeSourcesByFile = /* @__PURE__ */ new Map();
159
225
  let cachedGulpSourceCandidates;
160
226
  let cachedGulpSourceCandidateSignature;
227
+ const gulpProcessCacheKeys = /* @__PURE__ */ new Set();
161
228
  const sourceCandidateExtractor = initialTwPatcher.majorVersion === 3 ? require_hmr_timing.createTailwindV3DefaultExtractor() : void 0;
162
229
  const bundleRuntimeClassSetManager = options.__internalGulpRuntimeClassSetManager ?? require_hmr_timing.createBundleRuntimeClassSetManager();
163
230
  function invalidateGulpSourceCandidates() {
@@ -190,12 +257,14 @@ function createPlugins(options = {}) {
190
257
  const filename = node_path.default.resolve(file.path);
191
258
  const hash = cache.computeHash(rawSource);
192
259
  const changed = runtimeSourceHashByFile.get(filename) !== hash;
260
+ runtimeSourceHashByFile.delete(filename);
193
261
  runtimeSourceHashByFile.set(filename, hash);
194
- runtimeSourcesByFile.set(filename, {
262
+ touchMapEntry(runtimeSourcesByFile, filename, {
195
263
  source: rawSource,
196
264
  type
197
265
  });
198
- if (changed && runtimeState.twPatcher.majorVersion === 4) invalidateGulpSourceCandidates();
266
+ pruneGulpRuntimeSourceCaches(runtimeSourceHashByFile, runtimeSourcesByFile);
267
+ if (changed) invalidateGulpSourceCandidates();
199
268
  if (!changed && runtimeSetInitialized) return runtimeSet;
200
269
  if (runtimeState.twPatcher.majorVersion === 4 && !runtimeSetDirty) try {
201
270
  runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, createGulpRuntimeSnapshot(runtimeSourcesByFile, [filename]));
@@ -268,12 +337,13 @@ function createPlugins(options = {}) {
268
337
  cachedGulpSourceCandidateSourceGetter = (entries) => collector.sourcesForEntries(entries);
269
338
  return cachedGulpSourceCandidateGetter;
270
339
  }
271
- function createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature) {
340
+ function createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature, sourceCandidateSignature) {
272
341
  return cache.computeHash([
273
342
  rawSource,
274
343
  require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher),
275
344
  [...nextRuntimeSet].sort().join("\n"),
276
- sourceTraceSignature ?? "css-source-trace:0"
345
+ sourceTraceSignature ?? "css-source-trace:0",
346
+ sourceCandidateSignature ?? "gulp-source-candidates:0"
277
347
  ].join("\n\n"));
278
348
  }
279
349
  async function registerAutoCssSource(file, rawSource) {
@@ -314,12 +384,36 @@ function createPlugins(options = {}) {
314
384
  function resolveGulpMatcherName(file) {
315
385
  return (file.relative || node_path.default.basename(file.path)).replaceAll(node_path.default.sep, "/");
316
386
  }
317
- function resolveWxssFileHandlerOptions(file, options) {
387
+ function resolveWxssFileHandlerOptions(file, rawSource, options) {
318
388
  const resolved = resolveWxssHandlerOptions(options);
319
- if (resolved.isMainChunk !== void 0) return resolved;
389
+ const sourceFile = file.path ? node_path.default.resolve(file.path) : void 0;
390
+ const sourceOptions = sourceFile ? {
391
+ outputRoot: node_path.default.resolve(file.cwd ?? node_process.default.cwd()),
392
+ sourceCss: rawSource,
393
+ sourceFile
394
+ } : void 0;
395
+ if (resolved.isMainChunk !== void 0) return {
396
+ ...resolved,
397
+ postcssOptions: {
398
+ ...resolved.postcssOptions,
399
+ options: {
400
+ ...resolved.postcssOptions?.options,
401
+ ...sourceFile ? { from: sourceFile } : {}
402
+ }
403
+ },
404
+ ...sourceOptions ? { sourceOptions } : {}
405
+ };
320
406
  return {
321
407
  ...resolved,
322
- isMainChunk: opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType)
408
+ isMainChunk: opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType),
409
+ postcssOptions: {
410
+ ...resolved.postcssOptions,
411
+ options: {
412
+ ...resolved.postcssOptions?.options,
413
+ ...sourceFile ? { from: sourceFile } : {}
414
+ }
415
+ },
416
+ ...sourceOptions ? { sourceOptions } : {}
323
417
  };
324
418
  }
325
419
  function resolveWxssUserHandlerOptions(options) {
@@ -341,20 +435,33 @@ function createPlugins(options = {}) {
341
435
  ...options
342
436
  };
343
437
  }
438
+ function resolveGulpTransformTimingDetails(phase) {
439
+ return { memoryDebug: resolveGulpMemoryDebugStats({
440
+ cache,
441
+ defaultStyleHandlerOptionsCache,
442
+ gulpProcessCacheKeys,
443
+ phase,
444
+ runtimeSet,
445
+ runtimeSourceHashByFile,
446
+ runtimeSourcesByFile
447
+ }) };
448
+ }
344
449
  const transformWxss = (options = {}) => createVinylTransform("css", async (file) => {
345
450
  if (!file.contents) return;
346
451
  const rawSource = file.contents.toString();
347
452
  const cssSourceChanged = await registerAutoCssSource(file, rawSource);
348
453
  const isMainChunk = opts.mainCssChunkMatcher(resolveGulpMatcherName(file), opts.appType);
349
454
  const shouldUseGenerator = runtimeState.twPatcher.majorVersion !== 3 || require_v3_engine.hasTailwindRootDirectives(rawSource);
350
- const gulpV4SourceCandidates = shouldUseGenerator && runtimeState.twPatcher.majorVersion === 4 ? await refreshGulpV4SourceCandidates(cssSourceChanged) : void 0;
455
+ let gulpSourceCandidateGetter;
456
+ if (shouldUseGenerator && runtimeState.twPatcher.majorVersion === 4) gulpSourceCandidateGetter = await refreshGulpV4SourceCandidates(cssSourceChanged);
351
457
  let nextRuntimeSet = await refreshRuntimeSet({
352
458
  forceRefresh: cssSourceChanged,
353
459
  forceCollect: cssSourceChanged || runtimeState.twPatcher.majorVersion !== 4 && isMainChunk,
354
460
  clearCache: cssSourceChanged
355
461
  });
356
- if (runtimeState.twPatcher.majorVersion === 3 && isMainChunk && shouldUseGenerator) {
357
- const sourceCandidates = await refreshGulpSourceCandidates(cssSourceChanged);
462
+ if (runtimeState.twPatcher.majorVersion === 3 && shouldUseGenerator) {
463
+ const sourceCandidates = await refreshGulpSourceCandidates(cssSourceChanged || isMainChunk);
464
+ gulpSourceCandidateGetter = cachedGulpSourceCandidateGetter;
358
465
  if (sourceCandidates.size > 0) {
359
466
  nextRuntimeSet = new Set([...nextRuntimeSet, ...sourceCandidates]);
360
467
  runtimeSet = nextRuntimeSet;
@@ -362,10 +469,11 @@ function createPlugins(options = {}) {
362
469
  }
363
470
  const sourceTraceTokenSources = cachedGulpSourceCandidateSourceGetter ? require_hmr_timing.createCssTokenSourceMap(cachedGulpSourceCandidateSourceGetter(void 0), opts) : void 0;
364
471
  const sourceTraceSignature = require_hmr_timing.createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
472
+ const sourceCandidateSignature = cachedGulpSourceCandidateGetter ? `gulp-source-candidates:1:${[...cachedGulpSourceCandidateGetter(void 0)].sort().join("\n")}` : void 0;
365
473
  await require_hmr_timing.processCachedTask({
366
474
  cache,
367
475
  cacheKey: file.path,
368
- hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature),
476
+ hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature, sourceCandidateSignature),
369
477
  applyResult(source) {
370
478
  file.contents = node_buffer.Buffer.from(source);
371
479
  },
@@ -374,7 +482,7 @@ function createPlugins(options = {}) {
374
482
  },
375
483
  async transform() {
376
484
  await runtimeState.readyPromise;
377
- const cssHandlerOptions = resolveWxssFileHandlerOptions(file, options);
485
+ const cssHandlerOptions = resolveWxssFileHandlerOptions(file, rawSource, options);
378
486
  const css = require_hmr_timing.annotateCssSourceTrace((shouldUseGenerator ? await require_hmr_timing.generateCssByGenerator({
379
487
  opts,
380
488
  runtimeState,
@@ -383,7 +491,7 @@ function createPlugins(options = {}) {
383
491
  file: file.path,
384
492
  cssHandlerOptions,
385
493
  cssUserHandlerOptions: resolveWxssUserHandlerOptions(options),
386
- getSourceCandidatesForEntries: gulpV4SourceCandidates,
494
+ getSourceCandidatesForEntries: gulpSourceCandidateGetter,
387
495
  styleHandler,
388
496
  debug
389
497
  }) : void 0)?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css, {
@@ -394,7 +502,9 @@ function createPlugins(options = {}) {
394
502
  return { result: css };
395
503
  }
396
504
  });
397
- });
505
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
506
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
507
+ }, () => resolveGulpTransformTimingDetails("css"));
398
508
  const transformJs = (options = {}) => createVinylTransform("js", async (file) => {
399
509
  if (!file.contents) return;
400
510
  const filename = node_path.default.resolve(file.path);
@@ -434,7 +544,9 @@ function createPlugins(options = {}) {
434
544
  return { result: code };
435
545
  }
436
546
  });
437
- });
547
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
548
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
549
+ }, () => resolveGulpTransformTimingDetails("js"));
438
550
  const transformWxml = (options = {}) => createVinylTransform("html", async (file) => {
439
551
  if (!file.contents) return;
440
552
  const rawSource = file.contents.toString();
@@ -457,7 +569,9 @@ function createPlugins(options = {}) {
457
569
  return { result: code };
458
570
  }
459
571
  });
460
- });
572
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
573
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
574
+ }, () => resolveGulpTransformTimingDetails("html"));
461
575
  return {
462
576
  transformWxss,
463
577
  transformWxml,
package/dist/gulp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_gulp = require("./gulp-CHtZF-oT.js");
2
+ const require_gulp = require("./gulp-XT8Jc7lH.js");
3
3
  exports.WeappTailwindcss = require_gulp.createPlugins;
4
4
  exports.createPlugins = require_gulp.createPlugins;
5
5
  exports.weappTailwindcss = require_gulp.createPlugins;
package/dist/gulp.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { t as createPlugins } from "./gulp-Be88jhoY.mjs";
1
+ import { t as createPlugins } from "./gulp-DfOQERcV.mjs";
2
2
  export { createPlugins as WeappTailwindcss, createPlugins, createPlugins as weappTailwindcss };