weapp-tailwindcss 5.1.15 → 5.1.16

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 (122) hide show
  1. package/dist/bundlers/gulp/shared/create-native-framework-plugins/cache-state.d.ts +71 -0
  2. package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +43 -0
  3. package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +2 -2
  4. package/dist/bundlers/shared/framework-postcss.d.ts +14 -0
  5. package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +18 -0
  6. package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +25 -0
  7. package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +30 -0
  8. package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +2 -0
  9. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +4 -72
  10. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +3 -1
  11. package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +14 -0
  12. package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +12 -0
  13. package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +12 -0
  14. package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +25 -0
  15. package/dist/bundlers/shared/generator-css/pipeline.d.ts +2 -0
  16. package/dist/bundlers/shared/generator-css/result-helpers.d.ts +6 -0
  17. package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -0
  18. package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +33 -0
  19. package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +4 -0
  20. package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +4 -0
  21. package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +16 -0
  22. package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +3 -0
  23. package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +5 -0
  24. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +3 -6
  25. package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +9 -0
  26. package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +3 -0
  27. package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +4 -0
  28. package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +9 -0
  29. package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +10 -0
  30. package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +15 -0
  31. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -33
  32. package/dist/bundlers/shared/generator-css.d.ts +1 -2
  33. package/dist/bundlers/shared/v4-generation-core.d.ts +3 -0
  34. package/dist/bundlers/vite/css-finalizer/options.d.ts +54 -0
  35. package/dist/bundlers/vite/css-finalizer/plugin.d.ts +3 -0
  36. package/dist/bundlers/vite/css-finalizer.d.ts +1 -43
  37. package/dist/bundlers/vite/generate-bundle/finalize/bundle.d.ts +2 -0
  38. package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +69 -0
  39. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -70
  40. package/dist/bundlers/vite/generate-bundle-runtime.d.ts +6 -0
  41. package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
  42. package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +12 -0
  43. package/dist/bundlers/vite/processed-css-assets/collector.d.ts +4 -0
  44. package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +34 -0
  45. package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +42 -0
  46. package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +89 -0
  47. package/dist/bundlers/vite/processed-css-assets/style-files.d.ts +3 -0
  48. package/dist/bundlers/vite/processed-css-assets.d.ts +4 -71
  49. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  50. package/dist/bundlers/vite/serve-css-generation.d.ts +1 -0
  51. package/dist/bundlers/vite/shared/create-framework-plugins-runtime.d.ts +2 -0
  52. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +4 -4
  53. package/dist/bundlers/vite/source-candidates/collector.d.ts +8 -0
  54. package/dist/bundlers/vite/source-candidates/store.d.ts +2 -0
  55. package/dist/bundlers/vite/source-candidates/types-and-cache.d.ts +69 -0
  56. package/dist/bundlers/vite/source-candidates.d.ts +4 -68
  57. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.d.ts +2 -0
  58. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.d.ts +3 -0
  59. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.d.ts +2 -0
  60. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.d.ts +5 -0
  61. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +30 -0
  62. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +8 -0
  63. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.d.ts +78 -0
  64. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +43 -0
  65. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.d.ts +30 -0
  66. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.d.ts +1 -0
  67. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +28 -0
  68. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -0
  69. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +21 -0
  70. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +9 -219
  71. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.d.ts +4 -0
  72. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -0
  73. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
  74. package/dist/bundlers/webpack/shared/create-framework-plugin/plugin.d.ts +20 -0
  75. package/dist/bundlers/webpack/shared/create-framework-plugin/watch-output.d.ts +13 -0
  76. package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +3 -21
  77. package/dist/cli.js +14 -18
  78. package/dist/cli.mjs +14 -18
  79. package/dist/{context-VeFq_8vW.js → context-BtLIID4m.js} +3 -3
  80. package/dist/{context-BgGWVAmN.mjs → context-JzwzSX36.mjs} +3 -3
  81. package/dist/core.js +1 -1
  82. package/dist/core.mjs +1 -1
  83. package/dist/{generator-CEnUsjed.js → generator-B91GhUJQ.js} +636 -505
  84. package/dist/{generator-CEo920So.mjs → generator-Bv7myuhY.mjs} +556 -431
  85. package/dist/generator.js +1 -1
  86. package/dist/generator.mjs +1 -1
  87. package/dist/{gulp-DP71z1jG.mjs → gulp-CKSklPlH.mjs} +217 -186
  88. package/dist/{gulp-3m1dAiig.js → gulp-Q1wITegn.js} +217 -186
  89. package/dist/gulp.js +1 -1
  90. package/dist/gulp.mjs +1 -1
  91. package/dist/{hmr-timing-1aS6--U7.mjs → hmr-timing-BXg7nI8N.mjs} +3411 -3276
  92. package/dist/{hmr-timing-B8p4f0ca.js → hmr-timing-CMPaWn9P.js} +3425 -3278
  93. package/dist/index.js +4 -4
  94. package/dist/index.mjs +4 -4
  95. package/dist/postcss.js +1 -1
  96. package/dist/postcss.mjs +1 -1
  97. package/dist/presets.js +1 -1
  98. package/dist/presets.mjs +1 -1
  99. package/dist/rspack.js +1 -1
  100. package/dist/rspack.mjs +1 -1
  101. package/dist/shared/mpx-plugin-owner.d.ts +2 -0
  102. package/dist/{source-candidate-scan-signature-BAahhiwb.js → source-candidate-scan-signature-BKZZk_e6.js} +144 -4
  103. package/dist/{source-candidate-scan-signature-Cf7259PR.mjs → source-candidate-scan-signature-CtK-mB_C.mjs} +127 -4
  104. package/dist/tailwindcss/v4-engine/generator/cache-stats.d.ts +26 -0
  105. package/dist/tailwindcss/v4-engine/generator/engine.d.ts +2 -0
  106. package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +52 -0
  107. package/dist/tailwindcss/v4-engine/generator.d.ts +2 -28
  108. package/dist/{tailwindcss-KBYPJ2DW.js → tailwindcss-B4phC0kB.js} +2 -2
  109. package/dist/{tailwindcss-xs704TRw.mjs → tailwindcss-BTcXX8Ka.mjs} +2 -2
  110. package/dist/{vite-nXZEiwG0.mjs → vite-BwQWl9ft.mjs} +806 -692
  111. package/dist/{vite-DUVjMduj.js → vite-DhVnXvAQ.js} +805 -691
  112. package/dist/vite.js +1 -1
  113. package/dist/vite.mjs +1 -1
  114. package/dist/weapp-tw-css-generation-loader.js +1 -1
  115. package/dist/{weapp-tw-css-import-rewrite-loader-DNk0IxAt.js → weapp-tw-css-import-rewrite-loader-B0tVkJLH.js} +2410 -2084
  116. package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
  117. package/dist/weapp-tw-runtime-classset-loader.js +10 -4
  118. package/dist/{webpack-C_UUFRgj.mjs → webpack-Bo1QrFPf.mjs} +1387 -1114
  119. package/dist/{webpack-nppysF4B.js → webpack-kh78iMSS.js} +1386 -1113
  120. package/dist/webpack.js +1 -1
  121. package/dist/webpack.mjs +1 -1
  122. package/package.json +9 -7
package/dist/generator.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_generator = require("./generator-CEnUsjed.js");
2
+ const require_generator = require("./generator-B91GhUJQ.js");
3
3
  exports.createWeappTailwindcssGenerator = require_generator.createWeappTailwindcssGenerator;
4
4
  exports.createWeappTailwindcssGeneratorFromRuntime = require_generator.createWeappTailwindcssGeneratorFromRuntime;
5
5
  exports.normalizeWeappTailwindcssGeneratorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions;
@@ -1,2 +1,2 @@
1
- import { bt as transformTailwindV4CssToWeapp, d as resolveTailwindV4SourceFromRuntime, f as resolveTailwindV4SourceFromRuntimeOptions, i as normalizeWeappTailwindcssGeneratorOptions, n as createWeappTailwindcssGeneratorFromRuntime, p as resolveTailwindV4SourceOptionsFromRuntime, r as resolveTailwindSourceFromRuntime, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source, yt as transformTailwindV4CssByTarget } from "./generator-CEo920So.mjs";
1
+ import { At as transformTailwindV4CssByTarget, d as resolveTailwindV4SourceFromRuntime, f as resolveTailwindV4SourceFromRuntimeOptions, i as normalizeWeappTailwindcssGeneratorOptions, jt as transformTailwindV4CssToWeapp, n as createWeappTailwindcssGeneratorFromRuntime, p as resolveTailwindV4SourceOptionsFromRuntime, r as resolveTailwindSourceFromRuntime, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source } from "./generator-Bv7myuhY.mjs";
2
2
  export { createWeappTailwindcssGenerator, createWeappTailwindcssGeneratorFromRuntime, normalizeWeappTailwindcssGeneratorOptions, resolveTailwindSourceFromRuntime, resolveTailwindV4Source, resolveTailwindV4SourceFromRuntime, resolveTailwindV4SourceFromRuntimeOptions, resolveTailwindV4SourceOptionsFromRuntime, transformTailwindV4CssByTarget, transformTailwindV4CssToWeapp };
@@ -1,8 +1,8 @@
1
- import { Q as normalizeTailwindConfigDirectives, X as hasTailwindRootDirectives, et as normalizeTailwindSourceForGenerator, g as upsertTailwindV4CssSource, gt as prependConfigDirective, h as hasConfiguredTailwindV4CssRoots, vt as getTailwindV4IncrementalGenerateCacheStats } from "./generator-CEo920So.mjs";
2
- import { l as getRuntimeClassSetSignature, p as resolveViteSourceScanEntries } from "./tailwindcss-xs704TRw.mjs";
1
+ import { $ as normalizeTailwindConfigDirectives, Nt as getTailwindV4IncrementalGenerateCacheStats, Z as hasTailwindRootDirectives, _t as prependConfigDirective, g as upsertTailwindV4CssSource, h as hasConfiguredTailwindV4CssRoots, tt as normalizeTailwindSourceForGenerator } from "./generator-Bv7myuhY.mjs";
2
+ import { l as getRuntimeClassSetSignature, p as resolveViteSourceScanEntries } from "./tailwindcss-BTcXX8Ka.mjs";
3
3
  import { y as createDebug } from "./wxml-DdGdeqaH.mjs";
4
- import { l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, t as getCompilerContext, u as ensureRuntimeClassSet } from "./context-BgGWVAmN.mjs";
5
- import { E as finalizeMiniProgramGeneratorCss, F as annotateCssSourceTrace, I as createCssSourceTraceCacheSignature, L as createCssTokenSourceMap, M as hasBundlerGeneratedCssMarker, P as stripBundlerGeneratedCssMarkers, S as splitLocalCssImports, c as createBundleRuntimeClassSetManager, d as generateCssByGenerator, j as createBundlerGeneratedCssMarker, n as emitHmrTiming, r as createSourceCandidateCollector, x as rewriteLocalCssImportRequestsForOutput, z as processCachedTask } from "./hmr-timing-1aS6--U7.mjs";
4
+ import { l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, t as getCompilerContext, u as ensureRuntimeClassSet } from "./context-JzwzSX36.mjs";
5
+ import { A as processCachedTask, B as rewriteLocalCssImportRequestsForOutput, C as hasBundlerGeneratedCssMarker, D as createCssSourceTraceCacheSignature, E as annotateCssSourceTrace, I as createBundleRuntimeClassSetManager, O as createCssTokenSourceMap, S as createBundlerGeneratedCssMarker, T as stripBundlerGeneratedCssMarkers, V as splitLocalCssImports, i as generateCssByGenerator, j as createSourceCandidateCollector, m as finalizeMiniProgramGeneratorCss, n as emitHmrTiming } from "./hmr-timing-BXg7nI8N.mjs";
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import process from "node:process";
@@ -103,29 +103,7 @@ function createGulpRuntimeSnapshot(runtimeSourcesByFile, changedFiles) {
103
103
  };
104
104
  }
105
105
  //#endregion
106
- //#region src/bundlers/gulp/vinyl-transform.ts
107
- const Transform = stream.Transform;
108
- function createVinylTransform(phase, handler, getTimingDetails) {
109
- return new Transform({
110
- objectMode: true,
111
- async transform(file, _encoding, callback) {
112
- const hmrTimingStartedAt = performance.now();
113
- try {
114
- await handler(file);
115
- emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, {
116
- file: file.relative || path.basename(file.path),
117
- ...getTimingDetails?.(file)
118
- });
119
- callback(null, file);
120
- } catch (error) {
121
- callback(error, file);
122
- }
123
- }
124
- });
125
- }
126
- //#endregion
127
- //#region src/bundlers/gulp/shared/create-native-framework-plugins.ts
128
- const debug = createDebug();
106
+ //#region src/bundlers/gulp/shared/create-native-framework-plugins/cache-state.ts
129
107
  const GULP_RUNTIME_SOURCE_CACHE_MAX = 256;
130
108
  const GULP_PROCESS_CACHE_MAX = 512;
131
109
  function toMb(bytes) {
@@ -186,6 +164,195 @@ function resolveGulpMemoryDebugStats(context) {
186
164
  tailwind: { v4: getTailwindV4IncrementalGenerateCacheStats() }
187
165
  };
188
166
  }
167
+ //#endregion
168
+ //#region src/bundlers/gulp/vinyl-transform.ts
169
+ const Transform = stream.Transform;
170
+ function createVinylTransform(phase, handler, getTimingDetails) {
171
+ return new Transform({
172
+ objectMode: true,
173
+ async transform(file, _encoding, callback) {
174
+ const hmrTimingStartedAt = performance.now();
175
+ try {
176
+ await handler(file);
177
+ emitHmrTiming("gulp", phase, performance.now() - hmrTimingStartedAt, {
178
+ file: file.relative || path.basename(file.path),
179
+ ...getTimingDetails?.(file)
180
+ });
181
+ callback(null, file);
182
+ } catch (error) {
183
+ callback(error, file);
184
+ }
185
+ }
186
+ });
187
+ }
188
+ //#endregion
189
+ //#region src/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.ts
190
+ function createGulpFileTransforms(context) {
191
+ const { cache, createRuntimeSetHash, debug, generatedCssPreflightModeByFile, getSourceCandidateGetter, getSourceCandidateSourceGetter, getRuntimeSet, gulpProcessCacheKeys, opts, refreshGulpV4SourceCandidates, refreshRuntimeSet, refreshRuntimeSetForSource, registerAutoCssSource, resolveGulpStyleOutputExtension, resolveGulpTransformTimingDetails, resolveModuleGraphOptions, resolveWxmlHandlerOptions, resolveWxssFileHandlerOptions, resolveWxssUserHandlerOptions, runtimeState } = context;
192
+ const { templateHandler, styleHandler, jsHandler } = opts;
193
+ function createWxssTransform(options, stage) {
194
+ return createVinylTransform(`css:${stage}`, async (file) => {
195
+ if (!file.contents) return;
196
+ const rawSource = file.contents.toString();
197
+ const cssSourceChanged = await registerAutoCssSource(file, rawSource);
198
+ const shouldUseGenerator = runtimeState.tailwindRuntime.majorVersion === 4;
199
+ let gulpSourceCandidateGetter = getSourceCandidateGetter();
200
+ if (shouldUseGenerator) gulpSourceCandidateGetter = await refreshGulpV4SourceCandidates(cssSourceChanged);
201
+ const nextRuntimeSet = await refreshRuntimeSet({
202
+ forceRefresh: cssSourceChanged,
203
+ forceCollect: cssSourceChanged,
204
+ clearCache: cssSourceChanged
205
+ });
206
+ const sourceCandidateSourceGetter = getSourceCandidateSourceGetter();
207
+ const sourceTraceTokenSources = sourceCandidateSourceGetter ? createCssTokenSourceMap(sourceCandidateSourceGetter(void 0), opts) : void 0;
208
+ const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
209
+ const sourceCandidateSignature = gulpSourceCandidateGetter ? `gulp-source-candidates:1:${[...gulpSourceCandidateGetter(void 0)].sort().join("\n")}` : void 0;
210
+ const styleOutputExtension = resolveGulpStyleOutputExtension(file);
211
+ const outputSignature = styleOutputExtension ? `gulp-output:1:${stage}:${styleOutputExtension}` : `gulp-output:0:${stage}`;
212
+ await processCachedTask({
213
+ cache,
214
+ cacheKey: file.path,
215
+ hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature, sourceCandidateSignature, outputSignature),
216
+ applyResult(source) {
217
+ file.contents = Buffer.from(source);
218
+ },
219
+ onCacheHit() {
220
+ debug("css cache hit: %s", file.path);
221
+ },
222
+ async transform() {
223
+ await runtimeState.readyPromise;
224
+ const cssHandlerOptions = resolveWxssFileHandlerOptions(file, rawSource, options);
225
+ const generated = shouldUseGenerator ? await generateCssByGenerator({
226
+ opts,
227
+ runtimeState,
228
+ runtime: nextRuntimeSet,
229
+ rawSource,
230
+ file: file.path,
231
+ cssHandlerOptions,
232
+ cssUserHandlerOptions: resolveWxssUserHandlerOptions(options),
233
+ getSourceCandidatesForEntries: gulpSourceCandidateGetter,
234
+ styleHandler,
235
+ debug,
236
+ deferCssAdaptation: stage === "generate"
237
+ }) : void 0;
238
+ const transformedCss = generated?.css ?? (stage === "generate" ? rawSource : (await styleHandler(rawSource, cssHandlerOptions)).css);
239
+ if (stage === "generate") {
240
+ const preflightMode = generated?.metadata?.preflightMode;
241
+ if (preflightMode) generatedCssPreflightModeByFile.set(file.path, preflightMode);
242
+ else generatedCssPreflightModeByFile.delete(file.path);
243
+ }
244
+ const css = annotateCssSourceTrace(transformedCss, {
245
+ opts,
246
+ tokenSources: sourceTraceTokenSources
247
+ });
248
+ const generatedCss = stage === "generate" && generated ? `${createBundlerGeneratedCssMarker("gulp", file.path)}\n${css}` : css;
249
+ const outputCss = stage === "generate" ? generatedCss : rewriteLocalCssImportRequestsForOutput(generatedCss, { styleOutputExtension });
250
+ debug("css handle: %s", file.path);
251
+ return { result: outputCss };
252
+ }
253
+ });
254
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
255
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
256
+ }, () => resolveGulpTransformTimingDetails(`css:${stage}`));
257
+ }
258
+ const generateWxss = (options = {}) => createWxssTransform(options, "generate");
259
+ const transformWxss = (options = {}) => createWxssTransform(options, "transform");
260
+ const adaptWxss = (options = {}) => createVinylTransform("css:adapt", async (file) => {
261
+ if (!file.contents) return;
262
+ const rawSource = file.contents.toString();
263
+ const generatedCss = hasBundlerGeneratedCssMarker(rawSource);
264
+ const source = generatedCss ? stripBundlerGeneratedCssMarkers(rawSource) : rawSource;
265
+ const styleOutputExtension = resolveGulpStyleOutputExtension(file);
266
+ const cssHandlerOptions = resolveWxssFileHandlerOptions(file, source, options);
267
+ const handled = await styleHandler(source, cssHandlerOptions);
268
+ const preflightMode = generatedCssPreflightModeByFile.get(file.path);
269
+ const finalized = generatedCss ? finalizeMiniProgramGeneratorCss(handled.css, "weapp", runtimeState.tailwindRuntime.majorVersion, opts.cssPreflight, {
270
+ injectPreflight: preflightMode?.inject ?? cssHandlerOptions.isMainChunk,
271
+ preservePreflight: preflightMode?.preserve ?? cssHandlerOptions.isMainChunk,
272
+ styleOptions: cssHandlerOptions
273
+ }) : handled.css;
274
+ file.contents = Buffer.from(rewriteLocalCssImportRequestsForOutput(finalized, { styleOutputExtension }));
275
+ debug("css adapt: %s", file.path);
276
+ }, () => resolveGulpTransformTimingDetails("css:adapt"));
277
+ const transformJs = (options = {}) => createVinylTransform("js", async (file) => {
278
+ if (!file.contents) return;
279
+ const filename = path.resolve(file.path);
280
+ const rawSource = file.contents.toString();
281
+ await refreshRuntimeSetForSource(file, rawSource, "js");
282
+ await runtimeState.readyPromise;
283
+ const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
284
+ const handlerOptions = {
285
+ ...options,
286
+ generateMap: false,
287
+ filename,
288
+ moduleGraph,
289
+ babelParserOptions: {
290
+ ...options?.babelParserOptions ?? {},
291
+ sourceFilename: filename
292
+ }
293
+ };
294
+ if (runtimeState.tailwindRuntime.majorVersion !== void 0) handlerOptions.tailwindcssMajorVersion = runtimeState.tailwindRuntime.majorVersion;
295
+ await processCachedTask({
296
+ cache,
297
+ cacheKey: file.path,
298
+ rawSource,
299
+ applyResult(source) {
300
+ file.contents = Buffer.from(source);
301
+ },
302
+ onCacheHit() {
303
+ debug("js cache hit: %s", file.path);
304
+ },
305
+ async transform() {
306
+ await runtimeState.readyPromise;
307
+ const currentSource = file.contents?.toString() ?? rawSource;
308
+ if (shouldSkipJsTransform(currentSource, {
309
+ ...handlerOptions,
310
+ classNameSet: getRuntimeSet()
311
+ })) return { result: currentSource };
312
+ const { code } = await jsHandler(currentSource, getRuntimeSet(), handlerOptions);
313
+ debug("js handle: %s", file.path);
314
+ return { result: code };
315
+ }
316
+ });
317
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
318
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
319
+ }, () => resolveGulpTransformTimingDetails("js"));
320
+ const transformWxml = (options = {}) => createVinylTransform("html", async (file) => {
321
+ if (!file.contents) return;
322
+ const rawSource = file.contents.toString();
323
+ await refreshRuntimeSetForSource(file, rawSource, "html");
324
+ await runtimeState.readyPromise;
325
+ await processCachedTask({
326
+ cache,
327
+ cacheKey: file.path,
328
+ rawSource,
329
+ applyResult(source) {
330
+ file.contents = Buffer.from(source);
331
+ },
332
+ onCacheHit() {
333
+ debug("html cache hit: %s", file.path);
334
+ },
335
+ async transform() {
336
+ await runtimeState.readyPromise;
337
+ const code = await templateHandler(rawSource, resolveWxmlHandlerOptions(options));
338
+ debug("html handle: %s", file.path);
339
+ return { result: code };
340
+ }
341
+ });
342
+ rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
343
+ pruneGulpProcessCache(cache, gulpProcessCacheKeys);
344
+ }, () => resolveGulpTransformTimingDetails("html"));
345
+ return {
346
+ adaptWxss,
347
+ generateWxss,
348
+ transformWxss,
349
+ transformWxml,
350
+ transformJs
351
+ };
352
+ }
353
+ //#endregion
354
+ //#region src/bundlers/gulp/shared/create-native-framework-plugins.ts
355
+ const debug = createDebug();
189
356
  /**
190
357
  * @name weapp-tw-gulp
191
358
  * @description native framework 的插件组合实现
@@ -197,7 +364,7 @@ function createNativeGulpPlugins(options = {}) {
197
364
  ...options,
198
365
  __internalDeferMissingCssEntriesWarning: true
199
366
  });
200
- const { templateHandler, styleHandler, jsHandler, cache } = opts;
367
+ const { cache } = opts;
201
368
  const initialTailwindRuntime = opts.tailwindRuntime;
202
369
  const refreshTailwindcssRuntime = opts.refreshTailwindcssRuntime;
203
370
  const readyPromise = createTailwindRuntimeReadyPromise(initialTailwindRuntime);
@@ -415,164 +582,28 @@ function createNativeGulpPlugins(options = {}) {
415
582
  runtimeSourcesByFile
416
583
  }) };
417
584
  }
418
- function createWxssTransform(options, stage) {
419
- return createVinylTransform(`css:${stage}`, async (file) => {
420
- if (!file.contents) return;
421
- const rawSource = file.contents.toString();
422
- const cssSourceChanged = await registerAutoCssSource(file, rawSource);
423
- const shouldUseGenerator = runtimeState.tailwindRuntime.majorVersion === 4;
424
- let gulpSourceCandidateGetter;
425
- if (shouldUseGenerator) gulpSourceCandidateGetter = await refreshGulpV4SourceCandidates(cssSourceChanged);
426
- const nextRuntimeSet = await refreshRuntimeSet({
427
- forceRefresh: cssSourceChanged,
428
- forceCollect: cssSourceChanged,
429
- clearCache: cssSourceChanged
430
- });
431
- const sourceTraceTokenSources = cachedGulpSourceCandidateSourceGetter ? createCssTokenSourceMap(cachedGulpSourceCandidateSourceGetter(void 0), opts) : void 0;
432
- const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
433
- const sourceCandidateSignature = cachedGulpSourceCandidateGetter ? `gulp-source-candidates:1:${[...cachedGulpSourceCandidateGetter(void 0)].sort().join("\n")}` : void 0;
434
- const styleOutputExtension = resolveGulpStyleOutputExtension(file);
435
- const outputSignature = styleOutputExtension ? `gulp-output:1:${stage}:${styleOutputExtension}` : `gulp-output:0:${stage}`;
436
- await processCachedTask({
437
- cache,
438
- cacheKey: file.path,
439
- hash: createRuntimeSetHash(rawSource, nextRuntimeSet, sourceTraceSignature, sourceCandidateSignature, outputSignature),
440
- applyResult(source) {
441
- file.contents = Buffer.from(source);
442
- },
443
- onCacheHit() {
444
- debug("css cache hit: %s", file.path);
445
- },
446
- async transform() {
447
- await runtimeState.readyPromise;
448
- const cssHandlerOptions = resolveWxssFileHandlerOptions(file, rawSource, options);
449
- const generated = shouldUseGenerator ? await generateCssByGenerator({
450
- opts,
451
- runtimeState,
452
- runtime: nextRuntimeSet,
453
- rawSource,
454
- file: file.path,
455
- cssHandlerOptions,
456
- cssUserHandlerOptions: resolveWxssUserHandlerOptions(options),
457
- getSourceCandidatesForEntries: gulpSourceCandidateGetter,
458
- styleHandler,
459
- debug,
460
- deferCssAdaptation: stage === "generate"
461
- }) : void 0;
462
- const transformedCss = generated?.css ?? (stage === "generate" ? rawSource : (await styleHandler(rawSource, cssHandlerOptions)).css);
463
- if (stage === "generate") {
464
- const preflightMode = generated?.metadata?.preflightMode;
465
- if (preflightMode) generatedCssPreflightModeByFile.set(file.path, preflightMode);
466
- else generatedCssPreflightModeByFile.delete(file.path);
467
- }
468
- const css = annotateCssSourceTrace(transformedCss, {
469
- opts,
470
- tokenSources: sourceTraceTokenSources
471
- });
472
- const generatedCss = stage === "generate" && generated ? `${createBundlerGeneratedCssMarker("gulp", file.path)}\n${css}` : css;
473
- const outputCss = stage === "generate" ? generatedCss : rewriteLocalCssImportRequestsForOutput(generatedCss, { styleOutputExtension });
474
- debug("css handle: %s", file.path);
475
- return { result: outputCss };
476
- }
477
- });
478
- rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
479
- pruneGulpProcessCache(cache, gulpProcessCacheKeys);
480
- }, () => resolveGulpTransformTimingDetails(`css:${stage}`));
481
- }
482
- const generateWxss = (options = {}) => createWxssTransform(options, "generate");
483
- const transformWxss = (options = {}) => createWxssTransform(options, "transform");
484
- const adaptWxss = (options = {}) => createVinylTransform("css:adapt", async (file) => {
485
- if (!file.contents) return;
486
- const rawSource = file.contents.toString();
487
- const generatedCss = hasBundlerGeneratedCssMarker(rawSource);
488
- const source = generatedCss ? stripBundlerGeneratedCssMarkers(rawSource) : rawSource;
489
- const styleOutputExtension = resolveGulpStyleOutputExtension(file);
490
- const cssHandlerOptions = resolveWxssFileHandlerOptions(file, source, options);
491
- const handled = await styleHandler(source, cssHandlerOptions);
492
- const preflightMode = generatedCssPreflightModeByFile.get(file.path);
493
- const finalized = generatedCss ? finalizeMiniProgramGeneratorCss(handled.css, "weapp", runtimeState.tailwindRuntime.majorVersion, opts.cssPreflight, {
494
- injectPreflight: preflightMode?.inject ?? cssHandlerOptions.isMainChunk,
495
- preservePreflight: preflightMode?.preserve ?? cssHandlerOptions.isMainChunk,
496
- styleOptions: cssHandlerOptions
497
- }) : handled.css;
498
- file.contents = Buffer.from(rewriteLocalCssImportRequestsForOutput(finalized, { styleOutputExtension }));
499
- debug("css adapt: %s", file.path);
500
- }, () => resolveGulpTransformTimingDetails("css:adapt"));
501
- const transformJs = (options = {}) => createVinylTransform("js", async (file) => {
502
- if (!file.contents) return;
503
- const filename = path.resolve(file.path);
504
- const rawSource = file.contents.toString();
505
- await refreshRuntimeSetForSource(file, rawSource, "js");
506
- await runtimeState.readyPromise;
507
- const moduleGraph = resolveModuleGraphOptions(options.moduleGraph);
508
- const handlerOptions = {
509
- ...options,
510
- generateMap: false,
511
- filename,
512
- moduleGraph,
513
- babelParserOptions: {
514
- ...options?.babelParserOptions ?? {},
515
- sourceFilename: filename
516
- }
517
- };
518
- if (runtimeState.tailwindRuntime.majorVersion !== void 0) handlerOptions.tailwindcssMajorVersion = runtimeState.tailwindRuntime.majorVersion;
519
- await processCachedTask({
520
- cache,
521
- cacheKey: file.path,
522
- rawSource,
523
- applyResult(source) {
524
- file.contents = Buffer.from(source);
525
- },
526
- onCacheHit() {
527
- debug("js cache hit: %s", file.path);
528
- },
529
- async transform() {
530
- await runtimeState.readyPromise;
531
- const currentSource = file.contents?.toString() ?? rawSource;
532
- if (shouldSkipJsTransform(currentSource, {
533
- ...handlerOptions,
534
- classNameSet: runtimeSet
535
- })) return { result: currentSource };
536
- const { code } = await jsHandler(currentSource, runtimeSet, handlerOptions);
537
- debug("js handle: %s", file.path);
538
- return { result: code };
539
- }
540
- });
541
- rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
542
- pruneGulpProcessCache(cache, gulpProcessCacheKeys);
543
- }, () => resolveGulpTransformTimingDetails("js"));
544
- const transformWxml = (options = {}) => createVinylTransform("html", async (file) => {
545
- if (!file.contents) return;
546
- const rawSource = file.contents.toString();
547
- await refreshRuntimeSetForSource(file, rawSource, "html");
548
- await runtimeState.readyPromise;
549
- await processCachedTask({
550
- cache,
551
- cacheKey: file.path,
552
- rawSource,
553
- applyResult(source) {
554
- file.contents = Buffer.from(source);
555
- },
556
- onCacheHit() {
557
- debug("html cache hit: %s", file.path);
558
- },
559
- async transform() {
560
- await runtimeState.readyPromise;
561
- const code = await templateHandler(rawSource, resolveWxmlHandlerOptions(options));
562
- debug("html handle: %s", file.path);
563
- return { result: code };
564
- }
565
- });
566
- rememberGulpProcessCacheKey(gulpProcessCacheKeys, file.path);
567
- pruneGulpProcessCache(cache, gulpProcessCacheKeys);
568
- }, () => resolveGulpTransformTimingDetails("html"));
569
- return {
570
- adaptWxss,
571
- generateWxss,
572
- transformWxss,
573
- transformWxml,
574
- transformJs
575
- };
585
+ return createGulpFileTransforms({
586
+ cache,
587
+ createRuntimeSetHash,
588
+ debug,
589
+ generatedCssPreflightModeByFile,
590
+ getSourceCandidateGetter: () => cachedGulpSourceCandidateGetter,
591
+ getSourceCandidateSourceGetter: () => cachedGulpSourceCandidateSourceGetter,
592
+ getRuntimeSet: () => runtimeSet,
593
+ gulpProcessCacheKeys,
594
+ opts,
595
+ refreshGulpV4SourceCandidates,
596
+ refreshRuntimeSet,
597
+ refreshRuntimeSetForSource,
598
+ registerAutoCssSource,
599
+ resolveGulpStyleOutputExtension,
600
+ resolveGulpTransformTimingDetails,
601
+ resolveModuleGraphOptions,
602
+ resolveWxmlHandlerOptions,
603
+ resolveWxssFileHandlerOptions,
604
+ resolveWxssUserHandlerOptions,
605
+ runtimeState
606
+ });
576
607
  }
577
608
  //#endregion
578
609
  //#region src/bundlers/gulp/frameworks/native/index.ts