weapp-tailwindcss 5.0.0-next.10 → 5.0.0-next.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.
- package/dist/{bundle-state-EUbcdKqo.js → bundle-state-Bz8vLnCf.js} +42 -3
- package/dist/{bundle-state-BWqi5ZyX.mjs → bundle-state-CP2XS3Uj.mjs} +31 -4
- package/dist/bundlers/shared/cache.d.ts +6 -6
- package/dist/bundlers/shared/css-cleanup.d.ts +6 -1
- package/dist/bundlers/shared/css-imports.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/directives.d.ts +10 -3
- package/dist/bundlers/shared/generator-css/source-files.d.ts +9 -6
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +16 -2
- package/dist/bundlers/shared/generator-css.d.ts +5 -1
- package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
- package/dist/bundlers/shared/style-requests.d.ts +2 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -1
- package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +8 -1
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +5 -5
- package/dist/bundlers/vite/runtime-class-set.d.ts +4 -1
- package/dist/bundlers/vite/source-candidates.d.ts +13 -2
- package/dist/bundlers/vite/source-scan.d.ts +21 -3
- package/dist/bundlers/vite/static-config-content.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +3 -3
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +3 -3
- package/dist/cache/index.d.ts +6 -6
- package/dist/cli/context.d.ts +1 -11
- package/dist/cli/doctor/types.d.ts +11 -11
- package/dist/cli/vscode-entry.d.ts +3 -3
- package/dist/cli.js +468 -10
- package/dist/cli.mjs +466 -9
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/postcss.js +3 -2
- package/dist/css-macro/postcss.mjs +3 -2
- package/dist/css-macro.js +2 -2
- package/dist/css-macro.mjs +2 -2
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/escape.js +10 -2
- package/dist/escape.mjs +10 -2
- package/dist/generator/options.d.ts +8 -6
- package/dist/generator/types.d.ts +3 -3
- package/dist/generator-C9H44wEF.mjs +32 -0
- package/dist/generator-CRORPkpW.js +55 -0
- package/dist/generator.js +12 -11
- package/dist/generator.mjs +2 -1
- package/dist/gulp.js +57 -18
- package/dist/gulp.mjs +54 -15
- package/dist/{incremental-runtime-class-set-BYmzQ-_f.js → incremental-runtime-class-set-DN9KKjSi.js} +753 -155
- package/dist/{incremental-runtime-class-set-BgMW6wf2.mjs → incremental-runtime-class-set-Dbn4yPfZ.mjs} +724 -144
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/precheck.d.ts +2 -2
- package/dist/lightningcss/style-handler/selector-transform.d.ts +1 -1
- package/dist/lightningcss/style-handler.d.ts +3 -3
- package/dist/{postcss-Dg-_lyHS.js → postcss-Ab7YzAbs.js} +37 -23
- package/dist/postcss-CZE8k8oP.js +5483 -0
- package/dist/{postcss-C7efq3hr.mjs → postcss-CtlrNknb.mjs} +26 -12
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-B32p-gLI.js → precheck-CRX-pMKJ.js} +63 -37
- package/dist/{precheck-B4RH6ZNN.mjs → precheck-SG48aLG2.mjs} +56 -30
- package/dist/presets.js +11 -11
- package/dist/presets.mjs +11 -11
- package/dist/shared/mpx.d.ts +1 -0
- package/dist/source-candidates-C4YgmZ8A.js +274 -0
- package/dist/source-candidates-CyupdLKi.mjs +259 -0
- package/dist/tailwindcss/runtime/cache.d.ts +4 -3
- package/dist/tailwindcss/runtime.d.ts +9 -9
- package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
- package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
- package/dist/tailwindcss/v4/patcher.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/types.d.ts +14 -5
- package/dist/{tailwindcss-C5IgPlQ0.mjs → tailwindcss-BbTVeQkG.mjs} +52 -33
- package/dist/{tailwindcss-Bu-RWIHx.js → tailwindcss-DZ6jVYb4.js} +59 -40
- package/dist/types/index.d.ts +44 -40
- package/dist/types/user-defined-options/general.d.ts +21 -21
- package/dist/types/user-defined-options/important.d.ts +30 -27
- package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
- package/dist/types/user-defined-options/matcher.d.ts +6 -6
- package/dist/utils/object.d.ts +9 -0
- package/dist/{utils-Btw1iOVV.mjs → utils-CycMvPn_.mjs} +1 -1
- package/dist/{utils-BiShvil9.js → utils-D0MZP_tr.js} +1 -1
- package/dist/v3-engine-D61eilBl.mjs +3208 -0
- package/dist/v3-engine-DwV1E6rX.js +3461 -0
- package/dist/{vite-BU74SkOi.mjs → vite-Ti_qSctn.mjs} +434 -536
- package/dist/{vite-CKjx_5c3.js → vite-xKS6RvLR.js} +437 -542
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +143 -18
- package/dist/weapp-tw-runtime-classset-loader.js +44 -6
- package/dist/{webpack-CAk_ITq7.mjs → webpack-DvptFz7B.mjs} +111 -39
- package/dist/{webpack-damWiYqY.js → webpack-wfNutjMm.js} +115 -43
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +5 -5
- package/dist/cache-BVAiJV3J.js +0 -502
- package/dist/cache-CHs4DXui.mjs +0 -434
- package/dist/generator-DKkhJbOg.js +0 -1531
- package/dist/generator-UBmfduYg.mjs +0 -1432
- package/dist/runtime-patch-CwN5ya72.mjs +0 -71
- package/dist/runtime-patch-D6mBo_KB.js +0 -85
- package/dist/source-scan-BaYvNx-k.js +0 -293
- package/dist/source-scan-cGZxoJqP.mjs +0 -254
- /package/dist/{constants-BeeyfJ9k.js → constants-BoB_6lFw.js} +0 -0
- /package/dist/{constants-BG12WAKw.mjs → constants-E_loJC49.mjs} +0 -0
- /package/dist/{logger-EVNB9z7i.js → logger-BRy6XPQ2.js} +0 -0
- /package/dist/{logger-CZUxvJJD.mjs → logger-Bub1jggA.mjs} +0 -0
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
const require_chunk = require("./chunk-8l464Juk.js");
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
require("
|
|
12
|
-
|
|
13
|
-
postcss = require_chunk.__toESM(postcss);
|
|
2
|
+
const require_v3_engine = require("./v3-engine-DwV1E6rX.js");
|
|
3
|
+
const require_generator = require("./generator-CRORPkpW.js");
|
|
4
|
+
const require_incremental_runtime_class_set = require("./incremental-runtime-class-set-DN9KKjSi.js");
|
|
5
|
+
const require_precheck = require("./precheck-CRX-pMKJ.js");
|
|
6
|
+
const require_utils = require("./utils-D0MZP_tr.js");
|
|
7
|
+
const require_tailwindcss = require("./tailwindcss-DZ6jVYb4.js");
|
|
8
|
+
const require_source_candidates = require("./source-candidates-C4YgmZ8A.js");
|
|
9
|
+
const require_bundle_state = require("./bundle-state-Bz8vLnCf.js");
|
|
10
|
+
require("./logger-BRy6XPQ2.js");
|
|
11
|
+
let node_fs = require("node:fs");
|
|
12
|
+
node_fs = require_chunk.__toESM(node_fs);
|
|
14
13
|
let node_path = require("node:path");
|
|
15
14
|
node_path = require_chunk.__toESM(node_path);
|
|
16
15
|
let node_process = require("node:process");
|
|
17
16
|
node_process = require_chunk.__toESM(node_process);
|
|
18
17
|
let _weapp_tailwindcss_logger = require("@weapp-tailwindcss/logger");
|
|
19
18
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
20
|
-
let tailwindcss_patch = require("tailwindcss-patch");
|
|
21
|
-
let node_fs = require("node:fs");
|
|
22
|
-
node_fs = require_chunk.__toESM(node_fs);
|
|
23
19
|
let node_fs_promises = require("node:fs/promises");
|
|
24
20
|
let magic_string = require("magic-string");
|
|
25
21
|
magic_string = require_chunk.__toESM(magic_string);
|
|
26
22
|
let _weapp_tailwindcss_shared_extractors = require("@weapp-tailwindcss/shared/extractors");
|
|
27
|
-
let fast_glob = require("fast-glob");
|
|
28
|
-
fast_glob = require_chunk.__toESM(fast_glob);
|
|
29
|
-
let micromatch = require("micromatch");
|
|
30
|
-
micromatch = require_chunk.__toESM(micromatch);
|
|
31
23
|
let _weapp_tailwindcss_postcss_html_transform = require("@weapp-tailwindcss/postcss/html-transform");
|
|
32
24
|
_weapp_tailwindcss_postcss_html_transform = require_chunk.__toESM(_weapp_tailwindcss_postcss_html_transform);
|
|
33
25
|
let _vue_compiler_dom = require("@vue/compiler-dom");
|
|
@@ -289,7 +281,7 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
|
|
|
289
281
|
//#endregion
|
|
290
282
|
//#region src/bundlers/vite/query.ts
|
|
291
283
|
function parseVueRequest(id) {
|
|
292
|
-
const [filename, rawQuery] = id.split(`?`, 2);
|
|
284
|
+
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
293
285
|
const searchParams = new URLSearchParams(rawQuery);
|
|
294
286
|
const query = Object.fromEntries(searchParams);
|
|
295
287
|
if (query.vue != null) query.vue = true;
|
|
@@ -313,7 +305,7 @@ function slash(p) {
|
|
|
313
305
|
const isWindows = node_process.default.platform === "win32";
|
|
314
306
|
const cssLangRE = new RegExp(`\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`);
|
|
315
307
|
function isCSSRequest(request) {
|
|
316
|
-
return cssLangRE.test(request);
|
|
308
|
+
return cssLangRE.test(request) || require_bundle_state.isSourceStyleRequest(request);
|
|
317
309
|
}
|
|
318
310
|
function normalizePath(id) {
|
|
319
311
|
return node_path.default.posix.normalize(isWindows ? (0, _weapp_tailwindcss_shared.ensurePosix)(id) : id);
|
|
@@ -368,8 +360,8 @@ const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
|
|
|
368
360
|
function isPreprocessorRequest(id, lang) {
|
|
369
361
|
const normalizedLang = lang?.toLowerCase();
|
|
370
362
|
if (normalizedLang && preprocessorLangs.has(normalizedLang)) return true;
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
363
|
+
const inlineLang = id.match(INLINE_LANG_RE)?.[1];
|
|
364
|
+
if (inlineLang && preprocessorLangs.has(inlineLang.toLowerCase())) return true;
|
|
373
365
|
return PREPROCESSOR_EXT_RE.test(id);
|
|
374
366
|
}
|
|
375
367
|
function resolveUniAppXCssTarget(id) {
|
|
@@ -404,7 +396,7 @@ function createUniAppXPlugins(options) {
|
|
|
404
396
|
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
405
397
|
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
406
398
|
if (!styleHandlerOptions) {
|
|
407
|
-
styleHandlerOptions = {
|
|
399
|
+
styleHandlerOptions = require_v3_engine.omitUndefined({
|
|
408
400
|
isMainChunk: mainCssChunkMatcher(id, appType),
|
|
409
401
|
uniAppXCssTarget: resolveUniAppXCssTarget(id),
|
|
410
402
|
uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
|
|
@@ -416,7 +408,7 @@ function createUniAppXPlugins(options) {
|
|
|
416
408
|
sourcesContent: true
|
|
417
409
|
}
|
|
418
410
|
} }
|
|
419
|
-
};
|
|
411
|
+
});
|
|
420
412
|
cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
|
|
421
413
|
}
|
|
422
414
|
const postcssResult = await styleHandler(code, styleHandlerOptions);
|
|
@@ -537,11 +529,13 @@ function createCssHandlerOptions(opts, majorVersion, file) {
|
|
|
537
529
|
return {
|
|
538
530
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
539
531
|
postcssOptions: { options: { from: file } },
|
|
540
|
-
majorVersion
|
|
532
|
+
...majorVersion === void 0 ? {} : { majorVersion }
|
|
541
533
|
};
|
|
542
534
|
}
|
|
543
535
|
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
544
|
-
|
|
536
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
537
|
+
if (require_incremental_runtime_class_set.hasTailwindGeneratedCssMarkers(rawSource) || require_incremental_runtime_class_set.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
538
|
+
if (opts.twPatcher.majorVersion === 3) return false;
|
|
545
539
|
return processed && shouldFinalizeProcessedCssAsset(opts, file);
|
|
546
540
|
}
|
|
547
541
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
@@ -553,16 +547,20 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
553
547
|
generateBundle: {
|
|
554
548
|
order: "post",
|
|
555
549
|
async handler(_options, bundle) {
|
|
556
|
-
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, getRecordedGeneratorCandidates, getSourceCandidates, waitForSourceCandidateSyncs, rememberMainCssSource } = context;
|
|
550
|
+
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource } = context;
|
|
557
551
|
if (getResolvedConfig()?.command !== "build") return;
|
|
558
|
-
const
|
|
552
|
+
const isCssOutputAssetEntry = (entry) => {
|
|
553
|
+
const [, output] = entry;
|
|
554
|
+
return output.type === "asset" && opts.cssMatcher(output.fileName) && (!isCssAssetProcessed(output, output.fileName) || shouldFinalizeProcessedCssAsset(opts, output.fileName));
|
|
555
|
+
};
|
|
556
|
+
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
559
557
|
if (entries.length === 0) return;
|
|
560
558
|
await runtimeState.readyPromise;
|
|
561
559
|
await waitForSourceCandidateSyncs?.();
|
|
562
560
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
563
561
|
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
564
562
|
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
565
|
-
const generatorRuntime = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp" ?
|
|
563
|
+
const generatorRuntime = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp" ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
566
564
|
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
567
565
|
const file = output.fileName || bundleFile;
|
|
568
566
|
const rawSource = output.source.toString();
|
|
@@ -579,6 +577,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
579
577
|
file,
|
|
580
578
|
cssHandlerOptions,
|
|
581
579
|
cssUserHandlerOptions,
|
|
580
|
+
getSourceCandidatesForEntries,
|
|
582
581
|
styleHandler: opts.styleHandler,
|
|
583
582
|
debug
|
|
584
583
|
}) : void 0;
|
|
@@ -634,20 +633,25 @@ function createCssHandlerOptionsCache(options) {
|
|
|
634
633
|
const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
635
634
|
const getCssHandlerOptions = (file) => {
|
|
636
635
|
const majorVersion = options.getMajorVersion();
|
|
637
|
-
const
|
|
638
|
-
const
|
|
636
|
+
const appType = options.getAppType();
|
|
637
|
+
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
638
|
+
const outputRoot = options.getOutputRoot?.();
|
|
639
|
+
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}`;
|
|
639
640
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
640
641
|
if (cached) return cached;
|
|
641
642
|
const created = {
|
|
642
643
|
isMainChunk,
|
|
643
644
|
postcssOptions: { options: { from: file } },
|
|
644
|
-
majorVersion
|
|
645
|
+
majorVersion,
|
|
646
|
+
sourceOptions: { outputRoot }
|
|
645
647
|
};
|
|
646
648
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
647
649
|
return created;
|
|
648
650
|
};
|
|
649
651
|
const getCssUserHandlerOptions = (file) => {
|
|
650
|
-
const
|
|
652
|
+
const majorVersion = options.getMajorVersion();
|
|
653
|
+
const outputRoot = options.getOutputRoot?.();
|
|
654
|
+
const cacheKey = `${majorVersion ?? "unknown"}:${outputRoot ?? ""}:${file}`;
|
|
651
655
|
const cached = cssUserHandlerOptionsCache.get(cacheKey);
|
|
652
656
|
if (cached) return cached;
|
|
653
657
|
const created = {
|
|
@@ -686,6 +690,8 @@ function createCssTransformShareScope(file, rawSource) {
|
|
|
686
690
|
}
|
|
687
691
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
688
692
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${require_bundle_state.normalizeOutputPathKey(file)}`;
|
|
693
|
+
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
694
|
+
if (require_incremental_runtime_class_set.hasTailwindGeneratedCssMarkers(rawSource) || require_incremental_runtime_class_set.hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return `source:${require_bundle_state.normalizeOutputPathKey(file)}`;
|
|
689
695
|
return createCssTransformShareScope(file, rawSource);
|
|
690
696
|
}
|
|
691
697
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -877,33 +883,65 @@ function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
|
877
883
|
}
|
|
878
884
|
//#endregion
|
|
879
885
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
886
|
+
function addSiblingCssFile(files, file) {
|
|
887
|
+
if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
|
|
888
|
+
else if (file.endsWith(".js")) files.add(file.replace(/\.js$/, ".wxss"));
|
|
889
|
+
}
|
|
890
|
+
function collectRuntimeLinkedCssFiles(snapshot) {
|
|
891
|
+
const files = /* @__PURE__ */ new Set();
|
|
892
|
+
for (const file of snapshot.runtimeAffectingChangedByType.html) addSiblingCssFile(files, file);
|
|
893
|
+
for (const file of snapshot.runtimeAffectingChangedByType.js) addSiblingCssFile(files, file);
|
|
894
|
+
return files;
|
|
895
|
+
}
|
|
880
896
|
function createGenerateBundleHook(context) {
|
|
881
897
|
const state = require_bundle_state.createBundleBuildState();
|
|
898
|
+
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
899
|
+
let currentOutDir;
|
|
882
900
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
883
|
-
|
|
901
|
+
getAppType: () => context.opts.appType,
|
|
884
902
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
885
|
-
getMajorVersion: () => context.runtimeState.twPatcher.majorVersion
|
|
903
|
+
getMajorVersion: () => context.runtimeState.twPatcher.majorVersion,
|
|
904
|
+
getOutputRoot: () => currentOutDir
|
|
886
905
|
});
|
|
887
906
|
return async function generateBundle(_opt, bundle) {
|
|
888
907
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
889
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, recordCssAssetResult, getSourceCandidates, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSources, getRememberedMainCssSignature, setRememberedMainCssSignature, recordGeneratorCandidates } = context;
|
|
908
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, recordCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSources, getRememberedMainCssSignature, setRememberedMainCssSignature, recordGeneratorCandidates, hmrTimingRecorder } = context;
|
|
890
909
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
891
910
|
const generatorOptions = require_generator.normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
892
911
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
893
912
|
await runtimeState.readyPromise;
|
|
894
913
|
debug("start");
|
|
895
914
|
onStart();
|
|
915
|
+
const hmrTimingStartedAt = performance.now();
|
|
916
|
+
const timingDetails = {};
|
|
917
|
+
const recordTimingDetail = (name, startedAt) => {
|
|
918
|
+
timingDetails[name] = (timingDetails[name] ?? 0) + Math.max(0, performance.now() - startedAt);
|
|
919
|
+
};
|
|
920
|
+
const timeTask = async (name, task) => {
|
|
921
|
+
const start = performance.now();
|
|
922
|
+
try {
|
|
923
|
+
await task();
|
|
924
|
+
} finally {
|
|
925
|
+
recordTimingDetail(`tasks.${name}`, start);
|
|
926
|
+
}
|
|
927
|
+
};
|
|
896
928
|
const metrics = createEmptyMetrics();
|
|
897
|
-
const forceRuntimeRefreshByEnv = node_process.default.env
|
|
898
|
-
const disableDirtyOptimization = node_process.default.env
|
|
899
|
-
const disableJsPrecheck = node_process.default.env
|
|
900
|
-
const debugCssDiff = node_process.default.env
|
|
929
|
+
const forceRuntimeRefreshByEnv = node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
930
|
+
const disableDirtyOptimization = node_process.default.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1";
|
|
931
|
+
const disableJsPrecheck = node_process.default.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1";
|
|
932
|
+
const debugCssDiff = node_process.default.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
|
|
933
|
+
const disableV3OxideSourceRuntime = node_process.default.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
|
|
901
934
|
const resolvedConfig = getResolvedConfig();
|
|
902
935
|
const bundleFiles = Object.keys(bundle);
|
|
903
|
-
const
|
|
936
|
+
const buildCommand = resolvedConfig?.command === "build";
|
|
937
|
+
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
938
|
+
const useIncrementalMode = !buildCommand || hasPreviousBundleState || hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
904
939
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
905
940
|
const outDir = resolvedConfig?.build?.outDir ? node_path.default.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
941
|
+
currentOutDir = outDir;
|
|
942
|
+
const snapshotStart = performance.now();
|
|
906
943
|
const snapshot = require_bundle_state.buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode);
|
|
944
|
+
recordTimingDetail("snapshot", snapshotStart);
|
|
907
945
|
const useBundleRuntimeClassSet = useIncrementalMode || runtimeState.twPatcher.majorVersion === 4;
|
|
908
946
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
909
947
|
const processFiles = snapshot.processFiles;
|
|
@@ -913,20 +951,27 @@ function createGenerateBundleHook(context) {
|
|
|
913
951
|
useIncrementalMode,
|
|
914
952
|
iteration: state.iteration + 1
|
|
915
953
|
});
|
|
954
|
+
const sourceCandidateWaitStart = performance.now();
|
|
955
|
+
await waitForSourceCandidateSyncs?.();
|
|
956
|
+
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
957
|
+
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
916
958
|
const jsEntries = snapshot.jsEntries;
|
|
917
959
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
918
960
|
const moduleGraphOptions = require_bundle_state.createBundleModuleGraphOptions(outDir, jsEntries);
|
|
961
|
+
const hasCssAssetEntry = snapshot.entries.some((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
962
|
+
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
963
|
+
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !forceRuntimeRefreshByEnv && !disableV3OxideSourceRuntime;
|
|
919
964
|
const runtimeStart = performance.now();
|
|
920
|
-
const runtime =
|
|
965
|
+
const runtime = useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, {
|
|
966
|
+
allowBaselineOnlyInitialSync: true,
|
|
967
|
+
baseClassSet: sourceCandidates
|
|
968
|
+
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
969
|
+
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
921
970
|
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
922
|
-
await waitForSourceCandidateSyncs?.();
|
|
923
|
-
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
924
971
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
925
|
-
|
|
926
|
-
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
927
|
-
recordGeneratorCandidates?.(generatorRuntime);
|
|
972
|
+
let generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, shouldFilterTailwindV4MiniProgramCandidates ? require_v3_engine.filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates);
|
|
928
973
|
let transformRuntime = runtime;
|
|
929
|
-
if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size > 0) {
|
|
974
|
+
if (runtimeState.twPatcher.majorVersion === 3 && generatorRuntime.size > 0 && !useV3OxideSourceRuntime) {
|
|
930
975
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
931
976
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
932
977
|
if (mainCssEntry) {
|
|
@@ -941,14 +986,26 @@ function createGenerateBundleHook(context) {
|
|
|
941
986
|
styleHandler,
|
|
942
987
|
debug
|
|
943
988
|
});
|
|
944
|
-
if (validatedRuntime.size > 0)
|
|
989
|
+
if (validatedRuntime.size > 0) {
|
|
990
|
+
generatorRuntime = collectLegacyContainerCompatCandidates(sourceCandidates, validatedRuntime);
|
|
991
|
+
transformRuntime = generatorRuntime;
|
|
992
|
+
} else {
|
|
993
|
+
generatorRuntime = validatedRuntime;
|
|
994
|
+
transformRuntime = validatedRuntime;
|
|
995
|
+
}
|
|
945
996
|
}
|
|
946
997
|
}
|
|
998
|
+
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
999
|
+
const generatorCandidatesChanged = state.generatorCandidateSignature !== generatorCandidateSignature;
|
|
1000
|
+
const runtimeLinkedCssFiles = collectRuntimeLinkedCssFiles(snapshot);
|
|
1001
|
+
recordGeneratorCandidates?.(generatorRuntime);
|
|
947
1002
|
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
|
|
948
1003
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
1004
|
+
timingDetails.runtime = metrics.runtimeSet;
|
|
949
1005
|
if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
|
|
950
1006
|
debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
|
|
951
|
-
const runtimeSignature =
|
|
1007
|
+
const runtimeSignature = require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher) ?? "runtime:missing";
|
|
1008
|
+
const shouldProcessTailwindGeneration = !useIncrementalMode || hasRuntimeAffectingChanges || generatorCandidatesChanged || snapshot.processFiles.css.size > 0;
|
|
952
1009
|
const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
|
|
953
1010
|
jsEntries,
|
|
954
1011
|
onUpdate,
|
|
@@ -968,7 +1025,7 @@ function createGenerateBundleHook(context) {
|
|
|
968
1025
|
metrics.html.total++;
|
|
969
1026
|
if (!processFiles.html.has(file)) continue;
|
|
970
1027
|
const rawSource = originalEntrySource;
|
|
971
|
-
tasks.push(require_incremental_runtime_class_set.processCachedTask({
|
|
1028
|
+
tasks.push(timeTask("html", () => require_incremental_runtime_class_set.processCachedTask({
|
|
972
1029
|
cache,
|
|
973
1030
|
cacheKey: file,
|
|
974
1031
|
hashKey: `${file}:html:${runtimeSignature}`,
|
|
@@ -996,7 +1053,7 @@ function createGenerateBundleHook(context) {
|
|
|
996
1053
|
debug("html handle: %s", file);
|
|
997
1054
|
return { result: transformed };
|
|
998
1055
|
}
|
|
999
|
-
}));
|
|
1056
|
+
})));
|
|
1000
1057
|
continue;
|
|
1001
1058
|
}
|
|
1002
1059
|
if (type === "css" && originalSource.type === "asset") {
|
|
@@ -1005,15 +1062,28 @@ function createGenerateBundleHook(context) {
|
|
|
1005
1062
|
const cssRuntimeAffectingSignature = snapshot.runtimeAffectingSignatureByFile.get(file) ?? rawSource;
|
|
1006
1063
|
const cssShareScope = createCssTransformShareScopeKey(opts, file, rawSource);
|
|
1007
1064
|
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
1008
|
-
const
|
|
1065
|
+
const shouldTrackGeneratorRuntime = shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file));
|
|
1066
|
+
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? generatorCandidateSignature : "generator:stable";
|
|
1067
|
+
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
1009
1068
|
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}`;
|
|
1010
|
-
|
|
1069
|
+
if (!shouldTrackGeneratorRuntime) {
|
|
1070
|
+
const lastCss = lastCssResultByFile.get(file);
|
|
1071
|
+
if (lastCss != null) {
|
|
1072
|
+
originalSource.source = lastCss;
|
|
1073
|
+
markCssAssetProcessed?.(originalSource, file);
|
|
1074
|
+
metrics.css.cacheHits++;
|
|
1075
|
+
debug("css replay last result: %s", file);
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
tasks.push(timeTask("css", () => require_incremental_runtime_class_set.processCachedTask({
|
|
1011
1080
|
cache,
|
|
1012
1081
|
cacheKey: file,
|
|
1013
1082
|
hashKey: `${file}:css:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`,
|
|
1014
|
-
hash: `${getSnapshotHash(snapshot.runtimeAffectingHashByFile, file, cssRuntimeAffectingSignature)}:${
|
|
1083
|
+
hash: `${getSnapshotHash(snapshot.runtimeAffectingHashByFile, file, cssRuntimeAffectingSignature)}:${scopedGeneratorCandidateSignature}`,
|
|
1015
1084
|
applyResult(source) {
|
|
1016
1085
|
originalSource.source = source;
|
|
1086
|
+
lastCssResultByFile.set(file, source);
|
|
1017
1087
|
markCssAssetProcessed?.(originalSource, file);
|
|
1018
1088
|
if (cssHandlerOptions.isMainChunk) rememberMainCssSource?.(file, rawSource, cssRuntimeSignature);
|
|
1019
1089
|
},
|
|
@@ -1035,6 +1105,7 @@ function createGenerateBundleHook(context) {
|
|
|
1035
1105
|
const runTransform = async () => {
|
|
1036
1106
|
const start = performance.now();
|
|
1037
1107
|
await runtimeState.readyPromise;
|
|
1108
|
+
const previousCss = useIncrementalMode && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(file) : void 0;
|
|
1038
1109
|
const generated = await require_incremental_runtime_class_set.generateCssByGenerator({
|
|
1039
1110
|
opts,
|
|
1040
1111
|
runtimeState,
|
|
@@ -1043,8 +1114,10 @@ function createGenerateBundleHook(context) {
|
|
|
1043
1114
|
file,
|
|
1044
1115
|
cssHandlerOptions,
|
|
1045
1116
|
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
1117
|
+
getSourceCandidatesForEntries,
|
|
1046
1118
|
styleHandler,
|
|
1047
|
-
debug
|
|
1119
|
+
debug,
|
|
1120
|
+
previousCss
|
|
1048
1121
|
});
|
|
1049
1122
|
if (generated) {
|
|
1050
1123
|
registerGeneratorDependencies({ addWatchFile }, generated.dependencies);
|
|
@@ -1069,7 +1142,7 @@ function createGenerateBundleHook(context) {
|
|
|
1069
1142
|
debug("css handle: %s", file);
|
|
1070
1143
|
return { result: css };
|
|
1071
1144
|
}
|
|
1072
|
-
}));
|
|
1145
|
+
})));
|
|
1073
1146
|
continue;
|
|
1074
1147
|
}
|
|
1075
1148
|
if (type !== "js") continue;
|
|
@@ -1082,38 +1155,40 @@ function createGenerateBundleHook(context) {
|
|
|
1082
1155
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
1083
1156
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
1084
1157
|
jsTaskFactories.push(async () => {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1158
|
+
await timeTask("js", async () => {
|
|
1159
|
+
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
1160
|
+
await require_incremental_runtime_class_set.processCachedTask({
|
|
1161
|
+
cache,
|
|
1162
|
+
cacheKey: file,
|
|
1163
|
+
hashKey: `${file}:js`,
|
|
1164
|
+
hash: `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`,
|
|
1165
|
+
applyResult(source) {
|
|
1166
|
+
originalSource.code = source;
|
|
1167
|
+
},
|
|
1168
|
+
onCacheHit() {
|
|
1169
|
+
metrics.js.cacheHits++;
|
|
1170
|
+
debug("js cache hit: %s", file);
|
|
1171
|
+
},
|
|
1172
|
+
async transform() {
|
|
1173
|
+
const start = performance.now();
|
|
1174
|
+
const rawSource = originalSource.code;
|
|
1175
|
+
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
1176
|
+
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
1177
|
+
if (!disableJsPrecheck && require_precheck.shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
1178
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
1179
|
+
metrics.js.transformed++;
|
|
1180
|
+
return { result: rawSource };
|
|
1181
|
+
}
|
|
1182
|
+
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
1104
1183
|
metrics.js.elapsed += measureElapsed(start);
|
|
1105
1184
|
metrics.js.transformed++;
|
|
1106
|
-
|
|
1185
|
+
onUpdate(file, rawSource, code);
|
|
1186
|
+
debug("js handle: %s", file);
|
|
1187
|
+
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
1188
|
+
applyLinkedUpdates(linked);
|
|
1189
|
+
return { result: code };
|
|
1107
1190
|
}
|
|
1108
|
-
|
|
1109
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
1110
|
-
metrics.js.transformed++;
|
|
1111
|
-
onUpdate(file, rawSource, code);
|
|
1112
|
-
debug("js handle: %s", file);
|
|
1113
|
-
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
1114
|
-
applyLinkedUpdates(linked);
|
|
1115
|
-
return { result: code };
|
|
1116
|
-
}
|
|
1191
|
+
});
|
|
1117
1192
|
});
|
|
1118
1193
|
});
|
|
1119
1194
|
} else if (uniAppX && originalSource.type === "asset") {
|
|
@@ -1137,37 +1212,39 @@ function createGenerateBundleHook(context) {
|
|
|
1137
1212
|
uniAppX
|
|
1138
1213
|
});
|
|
1139
1214
|
jsTaskFactories.push(async () => {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1215
|
+
await timeTask("js", async () => {
|
|
1216
|
+
const start = performance.now();
|
|
1217
|
+
if (!shouldTransformJs) {
|
|
1218
|
+
debug("js skip transform (clean, uni-app-x), replay cache: %s", file);
|
|
1219
|
+
await factory();
|
|
1220
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
1221
|
+
metrics.js.transformed++;
|
|
1222
|
+
return;
|
|
1223
|
+
}
|
|
1224
|
+
const currentSource = originalEntrySource;
|
|
1225
|
+
const precheckOptions = createHandlerOptions(node_path.default.resolve(outDir, file), {
|
|
1226
|
+
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
1227
|
+
babelParserOptions: {
|
|
1228
|
+
plugins: ["typescript"],
|
|
1229
|
+
sourceType: "unambiguous"
|
|
1230
|
+
}
|
|
1231
|
+
});
|
|
1232
|
+
if (!disableJsPrecheck && require_precheck.shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
1233
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
1234
|
+
metrics.js.transformed++;
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1143
1237
|
await factory();
|
|
1144
1238
|
metrics.js.elapsed += measureElapsed(start);
|
|
1145
1239
|
metrics.js.transformed++;
|
|
1146
|
-
return;
|
|
1147
|
-
}
|
|
1148
|
-
const currentSource = originalEntrySource;
|
|
1149
|
-
const precheckOptions = createHandlerOptions(node_path.default.resolve(outDir, file), {
|
|
1150
|
-
uniAppX: resolveUniAppXJsTransformEnabled(uniAppX),
|
|
1151
|
-
babelParserOptions: {
|
|
1152
|
-
plugins: ["typescript"],
|
|
1153
|
-
sourceType: "unambiguous"
|
|
1154
|
-
}
|
|
1155
1240
|
});
|
|
1156
|
-
if (!disableJsPrecheck && require_precheck.shouldSkipJsTransform(currentSource, precheckOptions)) {
|
|
1157
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
1158
|
-
metrics.js.transformed++;
|
|
1159
|
-
return;
|
|
1160
|
-
}
|
|
1161
|
-
await factory();
|
|
1162
|
-
metrics.js.elapsed += measureElapsed(start);
|
|
1163
|
-
metrics.js.transformed++;
|
|
1164
1241
|
});
|
|
1165
1242
|
}
|
|
1166
1243
|
}
|
|
1167
1244
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature);
|
|
1168
1245
|
if (useIncrementalMode) for (const [file, rawSource] of getRememberedMainCssSources?.() ?? []) {
|
|
1169
1246
|
if (bundleFiles.includes(file) || getRememberedMainCssSignature?.(file) === cssRuntimeSignature) continue;
|
|
1170
|
-
tasks.push((async () => {
|
|
1247
|
+
tasks.push(timeTask("css.replay", async () => {
|
|
1171
1248
|
const start = performance.now();
|
|
1172
1249
|
const cssHandlerOptions = getCssHandlerOptions(file);
|
|
1173
1250
|
const generated = await require_incremental_runtime_class_set.generateCssByGenerator({
|
|
@@ -1178,6 +1255,7 @@ function createGenerateBundleHook(context) {
|
|
|
1178
1255
|
file,
|
|
1179
1256
|
cssHandlerOptions,
|
|
1180
1257
|
cssUserHandlerOptions: getCssUserHandlerOptions(file),
|
|
1258
|
+
getSourceCandidatesForEntries,
|
|
1181
1259
|
styleHandler,
|
|
1182
1260
|
debug
|
|
1183
1261
|
});
|
|
@@ -1200,13 +1278,22 @@ function createGenerateBundleHook(context) {
|
|
|
1200
1278
|
metrics.css.transformed++;
|
|
1201
1279
|
onUpdate(file, rawSource, css);
|
|
1202
1280
|
debug("css replay handle: %s", file);
|
|
1203
|
-
})
|
|
1281
|
+
}));
|
|
1204
1282
|
}
|
|
1205
1283
|
require_bundle_state.pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
1284
|
+
const tasksStart = performance.now();
|
|
1206
1285
|
await Promise.all(tasks);
|
|
1286
|
+
recordTimingDetail("tasks", tasksStart);
|
|
1207
1287
|
for (const apply of pendingLinkedUpdates) apply();
|
|
1288
|
+
const stateUpdateStart = performance.now();
|
|
1208
1289
|
require_bundle_state.updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
1290
|
+
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
1291
|
+
recordTimingDetail("state.update", stateUpdateStart);
|
|
1209
1292
|
debug("metrics iteration=%d runtime=%sms html(total=%d transform=%d hit=%d rate=%s elapsed=%sms) js(total=%d transform=%d hit=%d rate=%s elapsed=%sms) css(total=%d transform=%d hit=%d rate=%s elapsed=%sms)", useIncrementalMode ? state.iteration : 0, formatMs(metrics.runtimeSet), metrics.html.total, metrics.html.transformed, metrics.html.cacheHits, formatCacheHitRate(metrics.html), formatMs(metrics.html.elapsed), metrics.js.total, metrics.js.transformed, metrics.js.cacheHits, formatCacheHitRate(metrics.js), formatMs(metrics.js.elapsed), metrics.css.total, metrics.css.transformed, metrics.css.cacheHits, formatCacheHitRate(metrics.css), formatMs(metrics.css.elapsed));
|
|
1293
|
+
if (hmrTimingRecorder) {
|
|
1294
|
+
hmrTimingRecorder.record("generateBundle", performance.now() - hmrTimingStartedAt, timingDetails);
|
|
1295
|
+
hmrTimingRecorder.emitTotal();
|
|
1296
|
+
}
|
|
1210
1297
|
onEnd();
|
|
1211
1298
|
debug("end");
|
|
1212
1299
|
};
|
|
@@ -1359,20 +1446,20 @@ function resolveImplicitAppTypeFromViteRoot(root) {
|
|
|
1359
1446
|
}
|
|
1360
1447
|
//#endregion
|
|
1361
1448
|
//#region src/bundlers/shared/css-imports.ts
|
|
1362
|
-
const tailwindcssImportRE = /^tailwindcss(?:\/.*)?$/;
|
|
1363
|
-
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])(tailwindcss(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
1449
|
+
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
1450
|
+
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
1364
1451
|
function normalizeTailwindcssSpecifier(specifier) {
|
|
1365
|
-
if (specifier === "tailwindcss$"
|
|
1452
|
+
if (specifier === "tailwindcss$" || specifier === "weapp-tailwindcss$") return specifier.slice(0, -1);
|
|
1366
1453
|
return specifier;
|
|
1367
1454
|
}
|
|
1368
1455
|
function getTailwindcssSubpath(specifier) {
|
|
1369
|
-
if (specifier === "tailwindcss") return "index.css";
|
|
1370
|
-
return specifier.
|
|
1456
|
+
if (specifier === "tailwindcss" || specifier === "weapp-tailwindcss") return "index.css";
|
|
1457
|
+
return specifier.replace(/^(?:tailwindcss|weapp-tailwindcss)\//, "");
|
|
1371
1458
|
}
|
|
1372
1459
|
function resolveTailwindcssImport(specifier, pkgDir, options) {
|
|
1373
1460
|
const normalized = normalizeTailwindcssSpecifier(specifier);
|
|
1374
1461
|
if (!tailwindcssImportRE.test(normalized)) return null;
|
|
1375
|
-
if (normalized === "tailwindcss") return options?.rootImport ?? "
|
|
1462
|
+
if (normalized === "tailwindcss" || normalized === "weapp-tailwindcss") return options?.rootImport ?? (options?.join ?? node_path.default.join)(pkgDir, "index.css");
|
|
1376
1463
|
return (options?.join ?? node_path.default.join)(pkgDir, getTailwindcssSubpath(normalized));
|
|
1377
1464
|
}
|
|
1378
1465
|
function rewriteTailwindcssImportsInCode(code, pkgDir, options) {
|
|
@@ -1394,7 +1481,7 @@ function joinPosixPath(base, subpath) {
|
|
|
1394
1481
|
function isCssLikeImporter(importer) {
|
|
1395
1482
|
if (!importer) return false;
|
|
1396
1483
|
const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
|
|
1397
|
-
return isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
1484
|
+
return require_bundle_state.isSourceStyleRequest(importer) || isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
1398
1485
|
}
|
|
1399
1486
|
function stripTailwindConfigDirectives(code) {
|
|
1400
1487
|
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
@@ -1454,8 +1541,8 @@ function createViteRuntimeClassSet(options) {
|
|
|
1454
1541
|
let runtimeRefreshSignature;
|
|
1455
1542
|
let runtimeRefreshOptionsKey;
|
|
1456
1543
|
function resolveRuntimeRefreshOptions() {
|
|
1457
|
-
const configPath =
|
|
1458
|
-
const signature =
|
|
1544
|
+
const configPath = require_v3_engine.resolveTailwindcssOptions(runtimeState.twPatcher.options)?.config;
|
|
1545
|
+
const signature = require_v3_engine.getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
1459
1546
|
const optionsKey = JSON.stringify({
|
|
1460
1547
|
appType: opts.appType,
|
|
1461
1548
|
uniAppX: uniAppXEnabled,
|
|
@@ -1485,7 +1572,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
1485
1572
|
}
|
|
1486
1573
|
}
|
|
1487
1574
|
async function ensureRuntimeClassSet(force = false) {
|
|
1488
|
-
const forceRuntimeRefresh = force || node_process.default.env
|
|
1575
|
+
const forceRuntimeRefresh = force || node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
1489
1576
|
await refreshRuntimeState(force);
|
|
1490
1577
|
await runtimeState.readyPromise;
|
|
1491
1578
|
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
@@ -1505,8 +1592,8 @@ function createViteRuntimeClassSet(options) {
|
|
|
1505
1592
|
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
1506
1593
|
}
|
|
1507
1594
|
}
|
|
1508
|
-
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false) {
|
|
1509
|
-
const forceRuntimeRefresh = forceRefresh || node_process.default.env
|
|
1595
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, options = {}) {
|
|
1596
|
+
const forceRuntimeRefresh = forceRefresh || node_process.default.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
1510
1597
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
1511
1598
|
const shouldRefreshPatcher = forceRuntimeRefresh || invalidation.changed;
|
|
1512
1599
|
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
@@ -1525,6 +1612,23 @@ function createViteRuntimeClassSet(options) {
|
|
|
1525
1612
|
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
1526
1613
|
await bundleRuntimeClassSetManager.reset();
|
|
1527
1614
|
}
|
|
1615
|
+
if (runtimeState.twPatcher.majorVersion === 3 && !forceRuntimeRefresh) try {
|
|
1616
|
+
let baseClassSet = options.baseClassSet;
|
|
1617
|
+
if (!baseClassSet && (!runtimeSet || shouldRefreshPatcher)) baseClassSet = await require_precheck.collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
1618
|
+
force: true,
|
|
1619
|
+
skipRefresh: shouldRefreshPatcher,
|
|
1620
|
+
clearCache: shouldRefreshPatcher
|
|
1621
|
+
});
|
|
1622
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot, {
|
|
1623
|
+
baseClassSet: baseClassSet ?? (options.allowBaselineOnlyInitialSync === true ? runtimeSet : void 0),
|
|
1624
|
+
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync === true && Boolean(runtimeSet)
|
|
1625
|
+
});
|
|
1626
|
+
runtimeSet = nextRuntimeSet;
|
|
1627
|
+
return nextRuntimeSet;
|
|
1628
|
+
} catch (error) {
|
|
1629
|
+
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
1630
|
+
await bundleRuntimeClassSetManager.reset();
|
|
1631
|
+
}
|
|
1528
1632
|
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
1529
1633
|
const task = require_precheck.collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
1530
1634
|
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
@@ -1547,344 +1651,6 @@ function createViteRuntimeClassSet(options) {
|
|
|
1547
1651
|
};
|
|
1548
1652
|
}
|
|
1549
1653
|
//#endregion
|
|
1550
|
-
//#region src/bundlers/vite/source-candidates.ts
|
|
1551
|
-
const CLEAN_URL_RE = /[?#].*$/;
|
|
1552
|
-
const SOURCE_CANDIDATE_EXTENSIONS = [
|
|
1553
|
-
"js",
|
|
1554
|
-
"jsx",
|
|
1555
|
-
"mjs",
|
|
1556
|
-
"cjs",
|
|
1557
|
-
"ts",
|
|
1558
|
-
"tsx",
|
|
1559
|
-
"mts",
|
|
1560
|
-
"cts",
|
|
1561
|
-
"vue",
|
|
1562
|
-
"uvue",
|
|
1563
|
-
"nvue",
|
|
1564
|
-
"svelte",
|
|
1565
|
-
"mpx",
|
|
1566
|
-
"html",
|
|
1567
|
-
"wxml",
|
|
1568
|
-
"axml",
|
|
1569
|
-
"jxml",
|
|
1570
|
-
"ksml",
|
|
1571
|
-
"ttml",
|
|
1572
|
-
"qml",
|
|
1573
|
-
"tyml",
|
|
1574
|
-
"xhsml",
|
|
1575
|
-
"swan",
|
|
1576
|
-
"css",
|
|
1577
|
-
"wxss",
|
|
1578
|
-
"acss",
|
|
1579
|
-
"jxss",
|
|
1580
|
-
"ttss",
|
|
1581
|
-
"qss",
|
|
1582
|
-
"tyss",
|
|
1583
|
-
"scss",
|
|
1584
|
-
"sass",
|
|
1585
|
-
"less",
|
|
1586
|
-
"styl",
|
|
1587
|
-
"stylus"
|
|
1588
|
-
];
|
|
1589
|
-
const SOURCE_CANDIDATE_EXTENSION_RE = /\.(?:[cm]?[jt]sx?|vue|uvue|nvue|svelte|mpx|html|wxml|axml|jxml|ksml|ttml|qml|tyml|xhsml|swan|css|wxss|acss|jxss|ttss|qss|tyss|scss|sass|less|stylus?)$/;
|
|
1590
|
-
const CSS_SOURCE_CANDIDATE_EXTENSION_RE = /^(?:css|wxss|acss|jxss|ttss|qss|tyss|scss|sass|less|styl|stylus)$/;
|
|
1591
|
-
const SOURCE_CANDIDATE_GLOB = `**/*.{${SOURCE_CANDIDATE_EXTENSIONS.join(",")}}`;
|
|
1592
|
-
const DEFAULT_SCAN_IGNORE = ["**/node_modules/**", "**/.git/**"];
|
|
1593
|
-
function cleanUrl(id) {
|
|
1594
|
-
return id.replace(CLEAN_URL_RE, "");
|
|
1595
|
-
}
|
|
1596
|
-
function toPosixPath$1(value) {
|
|
1597
|
-
return value.split(node_path.default.sep).join("/");
|
|
1598
|
-
}
|
|
1599
|
-
function resolveOutDirIgnorePattern(root, outDir) {
|
|
1600
|
-
if (!outDir) return;
|
|
1601
|
-
const relative = node_path.default.relative(root, node_path.default.resolve(root, outDir));
|
|
1602
|
-
if (!relative || relative.startsWith("..") || node_path.default.isAbsolute(relative)) return;
|
|
1603
|
-
return `${toPosixPath$1(relative)}/**`;
|
|
1604
|
-
}
|
|
1605
|
-
function resolveSourceCandidateExtension(id) {
|
|
1606
|
-
const normalized = cleanUrl(id);
|
|
1607
|
-
return /\.([^.\\/]+)$/.exec(normalized)?.[1] ?? "html";
|
|
1608
|
-
}
|
|
1609
|
-
function isSourceCandidateRequest(id) {
|
|
1610
|
-
return SOURCE_CANDIDATE_EXTENSION_RE.test(cleanUrl(id));
|
|
1611
|
-
}
|
|
1612
|
-
function removeCandidateSet(candidateCount, candidates) {
|
|
1613
|
-
for (const candidate of candidates) {
|
|
1614
|
-
const count = candidateCount.get(candidate);
|
|
1615
|
-
if (count == null) continue;
|
|
1616
|
-
if (count <= 1) {
|
|
1617
|
-
candidateCount.delete(candidate);
|
|
1618
|
-
continue;
|
|
1619
|
-
}
|
|
1620
|
-
candidateCount.set(candidate, count - 1);
|
|
1621
|
-
}
|
|
1622
|
-
}
|
|
1623
|
-
function addCandidateSet(candidateCount, candidates) {
|
|
1624
|
-
for (const candidate of candidates) candidateCount.set(candidate, (candidateCount.get(candidate) ?? 0) + 1);
|
|
1625
|
-
}
|
|
1626
|
-
const CSS_APPLY_RE = /@apply\s+([^;{}]+)/g;
|
|
1627
|
-
const CSS_APPLY_IMPORTANT = "!important";
|
|
1628
|
-
function extractCssApplyCandidates(source) {
|
|
1629
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
1630
|
-
CSS_APPLY_RE.lastIndex = 0;
|
|
1631
|
-
let match = CSS_APPLY_RE.exec(source);
|
|
1632
|
-
while (match !== null) {
|
|
1633
|
-
const params = match[1] ?? "";
|
|
1634
|
-
for (const candidate of (0, _weapp_tailwindcss_shared_extractors.splitCode)(params, true)) {
|
|
1635
|
-
const normalized = candidate.trim();
|
|
1636
|
-
if (normalized && normalized !== CSS_APPLY_IMPORTANT) candidates.add(normalized);
|
|
1637
|
-
}
|
|
1638
|
-
match = CSS_APPLY_RE.exec(source);
|
|
1639
|
-
}
|
|
1640
|
-
return candidates;
|
|
1641
|
-
}
|
|
1642
|
-
function createSourceCandidateCollector() {
|
|
1643
|
-
const candidatesById = /* @__PURE__ */ new Map();
|
|
1644
|
-
const candidateCount = /* @__PURE__ */ new Map();
|
|
1645
|
-
let inlineIncludedCandidates = /* @__PURE__ */ new Set();
|
|
1646
|
-
let inlineExcludedCandidates = /* @__PURE__ */ new Set();
|
|
1647
|
-
async function sync(id, source) {
|
|
1648
|
-
const normalizedId = cleanUrl(id);
|
|
1649
|
-
const extension = resolveSourceCandidateExtension(normalizedId);
|
|
1650
|
-
const nextCandidates = /* @__PURE__ */ new Set();
|
|
1651
|
-
if (CSS_SOURCE_CANDIDATE_EXTENSION_RE.test(extension)) for (const candidate of extractCssApplyCandidates(source)) nextCandidates.add(candidate);
|
|
1652
|
-
else {
|
|
1653
|
-
const matches = await (0, tailwindcss_patch.extractRawCandidatesWithPositions)(source, extension);
|
|
1654
|
-
for (const match of matches) {
|
|
1655
|
-
const candidate = match.rawCandidate;
|
|
1656
|
-
if (typeof candidate === "string" && candidate.length > 0) nextCandidates.add(candidate);
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
remove(normalizedId);
|
|
1660
|
-
if (nextCandidates.size === 0) return;
|
|
1661
|
-
candidatesById.set(normalizedId, nextCandidates);
|
|
1662
|
-
addCandidateSet(candidateCount, nextCandidates);
|
|
1663
|
-
}
|
|
1664
|
-
async function syncFile(id) {
|
|
1665
|
-
const normalizedId = cleanUrl(id);
|
|
1666
|
-
await sync(normalizedId, await (0, node_fs_promises.readFile)(normalizedId, "utf8"));
|
|
1667
|
-
}
|
|
1668
|
-
async function scanRoot({ entries, root, outDir }) {
|
|
1669
|
-
const resolvedRoot = node_path.default.resolve(root);
|
|
1670
|
-
const outDirIgnore = resolveOutDirIgnorePattern(resolvedRoot, outDir);
|
|
1671
|
-
const ignore = outDirIgnore ? [...DEFAULT_SCAN_IGNORE, outDirIgnore] : DEFAULT_SCAN_IGNORE;
|
|
1672
|
-
const files = entries ? await require_source_scan.expandTailwindSourceEntries(entries, { ignore }) : await (0, fast_glob.default)(SOURCE_CANDIDATE_GLOB, {
|
|
1673
|
-
absolute: true,
|
|
1674
|
-
cwd: resolvedRoot,
|
|
1675
|
-
ignore,
|
|
1676
|
-
onlyFiles: true,
|
|
1677
|
-
unique: true
|
|
1678
|
-
});
|
|
1679
|
-
await Promise.all(files.map((file) => syncFile(file)));
|
|
1680
|
-
}
|
|
1681
|
-
function syncInline(inlineCandidates) {
|
|
1682
|
-
inlineIncludedCandidates = new Set(inlineCandidates?.included ?? []);
|
|
1683
|
-
inlineExcludedCandidates = new Set(inlineCandidates?.excluded ?? []);
|
|
1684
|
-
}
|
|
1685
|
-
function remove(id) {
|
|
1686
|
-
const normalizedId = cleanUrl(id);
|
|
1687
|
-
const previousCandidates = candidatesById.get(normalizedId);
|
|
1688
|
-
if (!previousCandidates) return;
|
|
1689
|
-
removeCandidateSet(candidateCount, previousCandidates);
|
|
1690
|
-
candidatesById.delete(normalizedId);
|
|
1691
|
-
}
|
|
1692
|
-
function values() {
|
|
1693
|
-
const values = new Set([...candidateCount.keys(), ...inlineIncludedCandidates]);
|
|
1694
|
-
for (const candidate of inlineExcludedCandidates) values.delete(candidate);
|
|
1695
|
-
return values;
|
|
1696
|
-
}
|
|
1697
|
-
function clear() {
|
|
1698
|
-
candidatesById.clear();
|
|
1699
|
-
candidateCount.clear();
|
|
1700
|
-
inlineIncludedCandidates.clear();
|
|
1701
|
-
inlineExcludedCandidates.clear();
|
|
1702
|
-
}
|
|
1703
|
-
return {
|
|
1704
|
-
sync,
|
|
1705
|
-
syncFile,
|
|
1706
|
-
scanRoot,
|
|
1707
|
-
syncInline,
|
|
1708
|
-
remove,
|
|
1709
|
-
values,
|
|
1710
|
-
clear
|
|
1711
|
-
};
|
|
1712
|
-
}
|
|
1713
|
-
//#endregion
|
|
1714
|
-
//#region src/bundlers/vite/source-scan.ts
|
|
1715
|
-
const VITE_SOURCE_CANDIDATE_PATTERN = require_source_scan.createSourceScanPattern([
|
|
1716
|
-
"js",
|
|
1717
|
-
"jsx",
|
|
1718
|
-
"mjs",
|
|
1719
|
-
"cjs",
|
|
1720
|
-
"ts",
|
|
1721
|
-
"tsx",
|
|
1722
|
-
"mts",
|
|
1723
|
-
"cts",
|
|
1724
|
-
"vue",
|
|
1725
|
-
"uvue",
|
|
1726
|
-
"nvue",
|
|
1727
|
-
"svelte",
|
|
1728
|
-
"mpx",
|
|
1729
|
-
"html",
|
|
1730
|
-
"wxml",
|
|
1731
|
-
"axml",
|
|
1732
|
-
"jxml",
|
|
1733
|
-
"ksml",
|
|
1734
|
-
"ttml",
|
|
1735
|
-
"qml",
|
|
1736
|
-
"tyml",
|
|
1737
|
-
"xhsml",
|
|
1738
|
-
"swan",
|
|
1739
|
-
"css",
|
|
1740
|
-
"wxss",
|
|
1741
|
-
"acss",
|
|
1742
|
-
"jxss",
|
|
1743
|
-
"ttss",
|
|
1744
|
-
"qss",
|
|
1745
|
-
"tyss",
|
|
1746
|
-
"scss",
|
|
1747
|
-
"sass",
|
|
1748
|
-
"less",
|
|
1749
|
-
"styl",
|
|
1750
|
-
"stylus"
|
|
1751
|
-
]);
|
|
1752
|
-
function parseImportSourceParam(params) {
|
|
1753
|
-
const match = /\bsource\(\s*(none|(['"])(.*?)\2)\s*\)/.exec(params);
|
|
1754
|
-
if (!match) return;
|
|
1755
|
-
return {
|
|
1756
|
-
none: match[1] === "none",
|
|
1757
|
-
sourcePath: match[3]
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
|
-
function isTailwindCssImport(params) {
|
|
1761
|
-
return /^\s*(['"])tailwindcss(?:\/[^'"]*)?\1/.test(params);
|
|
1762
|
-
}
|
|
1763
|
-
function resolveSourceBase(base, sourcePath) {
|
|
1764
|
-
return node_path.default.isAbsolute(sourcePath) ? sourcePath : node_path.default.resolve(base, sourcePath);
|
|
1765
|
-
}
|
|
1766
|
-
async function resolveTailwindV4EntriesFromCss(css, base) {
|
|
1767
|
-
let root;
|
|
1768
|
-
try {
|
|
1769
|
-
root = postcss.default.parse(css);
|
|
1770
|
-
} catch {
|
|
1771
|
-
return;
|
|
1772
|
-
}
|
|
1773
|
-
let importSourceBase;
|
|
1774
|
-
let hasSourceNone = false;
|
|
1775
|
-
const entries = await require_source_scan.resolveCssSourceEntries(root, base, VITE_SOURCE_CANDIDATE_PATTERN);
|
|
1776
|
-
const inlineCandidates = require_source_scan.collectCssInlineSourceCandidates(root);
|
|
1777
|
-
root.walkAtRules("import", (rule) => {
|
|
1778
|
-
if (!isTailwindCssImport(rule.params)) return;
|
|
1779
|
-
const sourceParam = parseImportSourceParam(rule.params);
|
|
1780
|
-
if (sourceParam?.none) hasSourceNone = true;
|
|
1781
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(base, sourceParam.sourcePath);
|
|
1782
|
-
});
|
|
1783
|
-
if (importSourceBase) return {
|
|
1784
|
-
entries: [{
|
|
1785
|
-
base: importSourceBase,
|
|
1786
|
-
negated: false,
|
|
1787
|
-
pattern: VITE_SOURCE_CANDIDATE_PATTERN
|
|
1788
|
-
}, ...entries],
|
|
1789
|
-
explicit: true,
|
|
1790
|
-
inlineCandidates
|
|
1791
|
-
};
|
|
1792
|
-
if (hasSourceNone) return {
|
|
1793
|
-
entries,
|
|
1794
|
-
explicit: true,
|
|
1795
|
-
inlineCandidates
|
|
1796
|
-
};
|
|
1797
|
-
return entries.length > 0 ? {
|
|
1798
|
-
entries,
|
|
1799
|
-
explicit: true,
|
|
1800
|
-
inlineCandidates
|
|
1801
|
-
} : inlineCandidates.included.size > 0 || inlineCandidates.excluded.size > 0 ? {
|
|
1802
|
-
entries: [],
|
|
1803
|
-
explicit: true,
|
|
1804
|
-
inlineCandidates
|
|
1805
|
-
} : void 0;
|
|
1806
|
-
}
|
|
1807
|
-
function collectExistingCssEntries(options) {
|
|
1808
|
-
return [
|
|
1809
|
-
...options.cssEntries ?? [],
|
|
1810
|
-
...options.tailwindcss?.v4?.cssEntries ?? [],
|
|
1811
|
-
...options.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries ?? []
|
|
1812
|
-
].filter((item) => typeof item === "string" && item.length > 0).map((item) => node_path.default.resolve(item)).filter((item) => (0, node_fs.existsSync)(item));
|
|
1813
|
-
}
|
|
1814
|
-
function mergeInlineCandidates(allInlineCandidates) {
|
|
1815
|
-
const merged = {
|
|
1816
|
-
included: /* @__PURE__ */ new Set(),
|
|
1817
|
-
excluded: /* @__PURE__ */ new Set()
|
|
1818
|
-
};
|
|
1819
|
-
for (const inlineCandidates of allInlineCandidates) {
|
|
1820
|
-
if (!inlineCandidates) continue;
|
|
1821
|
-
for (const candidate of inlineCandidates.included) if (!merged.excluded.has(candidate)) merged.included.add(candidate);
|
|
1822
|
-
for (const candidate of inlineCandidates.excluded) {
|
|
1823
|
-
merged.excluded.add(candidate);
|
|
1824
|
-
merged.included.delete(candidate);
|
|
1825
|
-
}
|
|
1826
|
-
}
|
|
1827
|
-
return merged.included.size > 0 || merged.excluded.size > 0 ? merged : void 0;
|
|
1828
|
-
}
|
|
1829
|
-
async function resolveViteSourceScanEntries(options, patcher) {
|
|
1830
|
-
if (patcher.majorVersion === 3) {
|
|
1831
|
-
const source = await require_generator.resolveTailwindV3SourceFromPatcher(patcher);
|
|
1832
|
-
const contentEntries = require_source_scan.normalizeLegacyContentEntries(source.configObject?.content, source.config ? node_path.default.dirname(source.config) : source.cwd);
|
|
1833
|
-
return contentEntries.length > 0 ? { entries: contentEntries } : void 0;
|
|
1834
|
-
}
|
|
1835
|
-
if (patcher.majorVersion === 4) {
|
|
1836
|
-
const sourceOptions = require_generator.resolveTailwindV4SourceOptionsFromPatcher(patcher);
|
|
1837
|
-
const cssEntries = collectExistingCssEntries(options);
|
|
1838
|
-
const entries = [];
|
|
1839
|
-
const cssInlineCandidates = [];
|
|
1840
|
-
for (const cssEntry of cssEntries) {
|
|
1841
|
-
const resolved = await resolveTailwindV4EntriesFromCss((0, node_fs.readFileSync)(cssEntry, "utf8"), node_path.default.dirname(cssEntry));
|
|
1842
|
-
if (resolved) {
|
|
1843
|
-
entries.push(...resolved.entries);
|
|
1844
|
-
cssInlineCandidates.push(resolved.inlineCandidates);
|
|
1845
|
-
}
|
|
1846
|
-
}
|
|
1847
|
-
const inlineCandidates = mergeInlineCandidates(cssInlineCandidates);
|
|
1848
|
-
if (entries.length > 0 || inlineCandidates) return {
|
|
1849
|
-
entries,
|
|
1850
|
-
inlineCandidates
|
|
1851
|
-
};
|
|
1852
|
-
if (typeof sourceOptions.css === "string" && sourceOptions.css.length > 0) {
|
|
1853
|
-
const resolved = await resolveTailwindV4EntriesFromCss(sourceOptions.css, sourceOptions.base ?? sourceOptions.projectRoot ?? node_process.default.cwd());
|
|
1854
|
-
return resolved ? {
|
|
1855
|
-
entries: resolved.entries,
|
|
1856
|
-
inlineCandidates: resolved.inlineCandidates
|
|
1857
|
-
} : void 0;
|
|
1858
|
-
}
|
|
1859
|
-
const source = await require_generator.resolveTailwindV4SourceFromPatcher(patcher);
|
|
1860
|
-
const resolved = await resolveTailwindV4EntriesFromCss(source.css, source.base);
|
|
1861
|
-
return resolved ? {
|
|
1862
|
-
entries: resolved.entries,
|
|
1863
|
-
inlineCandidates: resolved.inlineCandidates
|
|
1864
|
-
} : void 0;
|
|
1865
|
-
}
|
|
1866
|
-
}
|
|
1867
|
-
function toPosixPath(value) {
|
|
1868
|
-
return value.split(node_path.default.sep).join("/");
|
|
1869
|
-
}
|
|
1870
|
-
function createViteSourceScanMatcher(entries) {
|
|
1871
|
-
if (!entries?.length) return;
|
|
1872
|
-
const positiveEntries = entries.filter((entry) => !entry.negated);
|
|
1873
|
-
const negativeEntries = entries.filter((entry) => entry.negated);
|
|
1874
|
-
if (positiveEntries.length === 0) return () => false;
|
|
1875
|
-
return (file) => {
|
|
1876
|
-
const resolvedFile = node_path.default.resolve(file);
|
|
1877
|
-
if (!positiveEntries.some((entry) => {
|
|
1878
|
-
const relative = toPosixPath(node_path.default.relative(node_path.default.resolve(entry.base), resolvedFile));
|
|
1879
|
-
return relative && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, entry.pattern);
|
|
1880
|
-
})) return false;
|
|
1881
|
-
return !negativeEntries.some((entry) => {
|
|
1882
|
-
const relative = toPosixPath(node_path.default.relative(node_path.default.resolve(entry.base), resolvedFile));
|
|
1883
|
-
return relative && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, entry.pattern);
|
|
1884
|
-
});
|
|
1885
|
-
};
|
|
1886
|
-
}
|
|
1887
|
-
//#endregion
|
|
1888
1654
|
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
1889
1655
|
const PACKAGE_JSON_FILE = "package.json";
|
|
1890
1656
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
@@ -1898,17 +1664,18 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
1898
1664
|
if (parent === current) break;
|
|
1899
1665
|
current = parent;
|
|
1900
1666
|
}
|
|
1901
|
-
const tailwindConfigPath =
|
|
1667
|
+
const tailwindConfigPath = require_v3_engine.findTailwindConfig(searchRoots);
|
|
1902
1668
|
if (tailwindConfigPath) return node_path.default.dirname(tailwindConfigPath);
|
|
1903
|
-
const packageRoot =
|
|
1669
|
+
const packageRoot = require_v3_engine.findNearestPackageRoot(resolvedRoot);
|
|
1904
1670
|
if (packageRoot && (0, node_fs.existsSync)(node_path.default.join(packageRoot, PACKAGE_JSON_FILE))) return packageRoot;
|
|
1905
1671
|
return resolvedRoot;
|
|
1906
1672
|
}
|
|
1907
1673
|
//#endregion
|
|
1908
1674
|
//#region src/bundlers/vite/index.ts
|
|
1909
|
-
const debug =
|
|
1675
|
+
const debug = require_v3_engine.createDebug();
|
|
1910
1676
|
const weappTailwindcssPackageDir = require_bundle_state.resolvePackageDir("weapp-tailwindcss");
|
|
1911
1677
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
1678
|
+
const sourceCandidateScanSnapshotCache = /* @__PURE__ */ new Map();
|
|
1912
1679
|
function normalizeSignaturePath(value) {
|
|
1913
1680
|
return slash(node_path.default.resolve(value));
|
|
1914
1681
|
}
|
|
@@ -1932,7 +1699,8 @@ function createSourceCandidateScanSignature(input) {
|
|
|
1932
1699
|
roots: input.roots.map((root) => ({
|
|
1933
1700
|
entries: serializeSourceEntries(root.entries),
|
|
1934
1701
|
root: normalizeSignaturePath(root.root)
|
|
1935
|
-
}))
|
|
1702
|
+
})),
|
|
1703
|
+
scanAllSources: input.scanAllSources ?? false
|
|
1936
1704
|
});
|
|
1937
1705
|
}
|
|
1938
1706
|
/**
|
|
@@ -1960,23 +1728,53 @@ function WeappTailwindcss(options = {}) {
|
|
|
1960
1728
|
const autoCssSourceContent = /* @__PURE__ */ new Map();
|
|
1961
1729
|
let refreshRuntimeStateForAutoCssSources;
|
|
1962
1730
|
let autoCssSourcesRefresh;
|
|
1963
|
-
|
|
1731
|
+
let autoCssSourcesDiscovered = false;
|
|
1732
|
+
const registerAutoCssSource = async (id, css, options = {}) => {
|
|
1964
1733
|
if (tailwindcssMajorVersion < 4 || !shouldOwnTailwindGeneration || hasInitialTailwindCssRoots) return;
|
|
1965
1734
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
1966
1735
|
if (!node_path.default.isAbsolute(file)) return;
|
|
1967
1736
|
const sourceFile = node_path.default.normalize(file);
|
|
1968
|
-
|
|
1969
|
-
autoCssSourceContent.
|
|
1970
|
-
|
|
1737
|
+
const sourceCss = require_incremental_runtime_class_set.normalizeTailwindSourceForGenerator(css, { importFallback: true });
|
|
1738
|
+
if (autoCssSourceContent.get(sourceFile) === sourceCss) return;
|
|
1739
|
+
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
1740
|
+
const dependencies = await require_v3_engine.resolveViteTailwindV4CssDependencies(sourceCss, node_path.default.dirname(sourceFile));
|
|
1741
|
+
if (!require_tailwindcss.upsertTailwindV4CssSource(opts, {
|
|
1971
1742
|
file: sourceFile,
|
|
1972
|
-
|
|
1973
|
-
|
|
1743
|
+
base: node_path.default.dirname(sourceFile),
|
|
1744
|
+
css: sourceCss,
|
|
1745
|
+
dependencies
|
|
1746
|
+
})) return;
|
|
1747
|
+
invalidateSourceCandidateScan();
|
|
1974
1748
|
debug("detected tailwindcss v4 css source from vite css module: %s", sourceFile);
|
|
1749
|
+
if (options.refresh === false) return;
|
|
1975
1750
|
autoCssSourcesRefresh = (autoCssSourcesRefresh ?? Promise.resolve()).then(async () => {
|
|
1976
1751
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
1752
|
+
await syncSourceCandidateScan({ force: true });
|
|
1977
1753
|
});
|
|
1978
1754
|
await autoCssSourcesRefresh;
|
|
1979
1755
|
};
|
|
1756
|
+
const discoverAndRegisterAutoCssSources = async () => {
|
|
1757
|
+
if (tailwindcssMajorVersion < 4 || !shouldOwnTailwindGeneration || hasInitialTailwindCssRoots || !resolvedConfig?.root) return;
|
|
1758
|
+
const cssEntries = await require_v3_engine.discoverTailwindV4CssEntries(resolvedConfig.root, resolvedConfig.build?.outDir);
|
|
1759
|
+
autoCssSourcesDiscovered = true;
|
|
1760
|
+
let changed = false;
|
|
1761
|
+
for (const cssEntry of cssEntries) {
|
|
1762
|
+
const sourceFile = node_path.default.resolve(cssEntry);
|
|
1763
|
+
const sourceCss = require_incremental_runtime_class_set.normalizeTailwindSourceForGenerator(await (0, node_fs_promises.readFile)(sourceFile, "utf8"), { importFallback: true });
|
|
1764
|
+
if (autoCssSourceContent.get(sourceFile) === sourceCss) continue;
|
|
1765
|
+
autoCssSourceContent.set(sourceFile, sourceCss);
|
|
1766
|
+
const resolved = await require_v3_engine.resolveTailwindV4EntriesFromCssCached(sourceCss, node_path.default.dirname(sourceFile));
|
|
1767
|
+
changed = require_tailwindcss.upsertTailwindV4CssSource(opts, {
|
|
1768
|
+
file: sourceFile,
|
|
1769
|
+
base: node_path.default.dirname(sourceFile),
|
|
1770
|
+
css: sourceCss,
|
|
1771
|
+
dependencies: resolved?.dependencies ?? []
|
|
1772
|
+
}) || changed;
|
|
1773
|
+
}
|
|
1774
|
+
if (!changed) return;
|
|
1775
|
+
invalidateSourceCandidateScan();
|
|
1776
|
+
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
1777
|
+
};
|
|
1980
1778
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
1981
1779
|
getAppType: () => opts.appType,
|
|
1982
1780
|
rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
|
|
@@ -1989,11 +1787,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
1989
1787
|
const customAttributesEntities = require_precheck.toCustomAttributesEntities(customAttributes);
|
|
1990
1788
|
let resolvedConfig;
|
|
1991
1789
|
let recordedGeneratorCandidates;
|
|
1992
|
-
const sourceCandidateCollector = createSourceCandidateCollector();
|
|
1790
|
+
const sourceCandidateCollector = require_source_candidates.createSourceCandidateCollector();
|
|
1791
|
+
const sourceCandidateScanCache = /* @__PURE__ */ new Map();
|
|
1993
1792
|
let sourceScanEntries;
|
|
1994
1793
|
let sourceScanMatcher;
|
|
1794
|
+
let sourceScanDependencies = /* @__PURE__ */ new Set();
|
|
1795
|
+
let sourceScanExplicit = false;
|
|
1995
1796
|
let sourceCandidateScanSignature;
|
|
1797
|
+
let sourceCandidateScanInvalidated = true;
|
|
1996
1798
|
const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
|
|
1799
|
+
const pendingSourceCandidateSyncByFile = /* @__PURE__ */ new Map();
|
|
1997
1800
|
const processedCssAssets = /* @__PURE__ */ new WeakSet();
|
|
1998
1801
|
const processedCssAssetFiles = /* @__PURE__ */ new Set();
|
|
1999
1802
|
const rememberedMainCssSources = /* @__PURE__ */ new Map();
|
|
@@ -2007,6 +1810,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
2007
1810
|
disabledDefaultTemplateHandler,
|
|
2008
1811
|
debug
|
|
2009
1812
|
});
|
|
1813
|
+
const hmrTimingRecorder = require_incremental_runtime_class_set.createHmrTimingRecorder("vite");
|
|
2010
1814
|
refreshRuntimeStateForAutoCssSources = refreshRuntimeState;
|
|
2011
1815
|
onLoad();
|
|
2012
1816
|
const getResolvedConfig = () => resolvedConfig;
|
|
@@ -2022,8 +1826,21 @@ function WeappTailwindcss(options = {}) {
|
|
|
2022
1826
|
};
|
|
2023
1827
|
const getRecordedGeneratorCandidates = () => recordedGeneratorCandidates;
|
|
2024
1828
|
const getSourceCandidates = () => sourceCandidateCollector.values();
|
|
1829
|
+
const getSourceCandidatesForEntries = (entries) => sourceCandidateCollector.valuesForEntries(entries);
|
|
2025
1830
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
1831
|
+
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || node_process.default.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || node_process.default.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
1832
|
+
const hasSourceCandidateScanState = () => sourceCandidateScanSignature !== void 0;
|
|
1833
|
+
const normalizeSourceScanDependency = (file) => node_path.default.normalize(node_path.default.resolve((0, _weapp_tailwindcss_shared.cleanUrl)(file)));
|
|
1834
|
+
const isSourceScanDependency = (file) => sourceScanDependencies.has(normalizeSourceScanDependency(file));
|
|
1835
|
+
const invalidateSourceCandidateScan = () => {
|
|
1836
|
+
sourceCandidateScanInvalidated = true;
|
|
1837
|
+
};
|
|
2026
1838
|
const collectSourceCandidateScanRoots = (root, entries) => {
|
|
1839
|
+
if (entries?.length) return [{
|
|
1840
|
+
entries,
|
|
1841
|
+
root
|
|
1842
|
+
}];
|
|
1843
|
+
if (sourceScanExplicit) return [];
|
|
2027
1844
|
const roots = [{
|
|
2028
1845
|
entries,
|
|
2029
1846
|
root
|
|
@@ -2035,7 +1852,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
2035
1852
|
roots.push({ root: basedir });
|
|
2036
1853
|
seenRoots.add(basedir);
|
|
2037
1854
|
}
|
|
2038
|
-
for (const cssEntry of opts.tailwindcss?.cssEntries ?? []) {
|
|
1855
|
+
for (const cssEntry of opts.tailwindcss?.v4?.cssEntries ?? []) {
|
|
2039
1856
|
const cssEntryRoot = node_path.default.dirname(node_path.default.resolve(cssEntry));
|
|
2040
1857
|
if (seenRoots.has(cssEntryRoot)) continue;
|
|
2041
1858
|
roots.push({ root: cssEntryRoot });
|
|
@@ -2050,24 +1867,100 @@ function WeappTailwindcss(options = {}) {
|
|
|
2050
1867
|
outDir
|
|
2051
1868
|
})));
|
|
2052
1869
|
};
|
|
1870
|
+
const cacheCurrentSourceCandidateScan = () => {
|
|
1871
|
+
if (sourceCandidateScanSignature) {
|
|
1872
|
+
sourceCandidateScanCache.set(sourceCandidateScanSignature, sourceCandidateCollector.snapshot());
|
|
1873
|
+
sourceCandidateScanSnapshotCache.set(sourceCandidateScanSignature, sourceCandidateCollector.snapshot());
|
|
1874
|
+
}
|
|
1875
|
+
};
|
|
1876
|
+
const shouldDiscoverAutoCssSources = () => {
|
|
1877
|
+
if (!autoCssSourcesDiscovered) return true;
|
|
1878
|
+
if (!isWatchLikeBuild()) return true;
|
|
1879
|
+
return sourceCandidateScanInvalidated;
|
|
1880
|
+
};
|
|
1881
|
+
async function syncSourceCandidateScan(options = {}) {
|
|
1882
|
+
if (!shouldOwnTailwindGeneration) return;
|
|
1883
|
+
if (!options.force && isWatchLikeBuild() && hasSourceCandidateScanState() && !sourceCandidateScanInvalidated) {
|
|
1884
|
+
debug("reuse vite source candidate scan definition for watch rebuild");
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
const root = resolvedConfig?.root ?? node_process.default.cwd();
|
|
1888
|
+
const outDir = resolvedConfig?.build?.outDir;
|
|
1889
|
+
const sourceScan = await require_v3_engine.resolveViteSourceScanEntries(opts, runtimeState.twPatcher, {
|
|
1890
|
+
outDir,
|
|
1891
|
+
root
|
|
1892
|
+
});
|
|
1893
|
+
sourceScanEntries = sourceScan?.entries;
|
|
1894
|
+
sourceScanExplicit = sourceScan?.explicit ?? false;
|
|
1895
|
+
sourceScanMatcher = require_v3_engine.createViteSourceScanMatcher(sourceScanEntries);
|
|
1896
|
+
sourceScanDependencies = new Set((sourceScan?.dependencies ?? []).map(normalizeSourceScanDependency));
|
|
1897
|
+
const roots = collectSourceCandidateScanRoots(root, sourceScanEntries);
|
|
1898
|
+
const nextScanSignature = createSourceCandidateScanSignature({
|
|
1899
|
+
inlineCandidates: sourceScan?.inlineCandidates,
|
|
1900
|
+
outDir,
|
|
1901
|
+
roots,
|
|
1902
|
+
scanAllSources: !sourceScanExplicit
|
|
1903
|
+
});
|
|
1904
|
+
if (hasSourceCandidateScanState() && sourceCandidateScanSignature === nextScanSignature) {
|
|
1905
|
+
sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
1906
|
+
sourceCandidateScanCache.set(nextScanSignature, sourceCandidateCollector.snapshot());
|
|
1907
|
+
debug("reuse vite source candidate scan for watch rebuild");
|
|
1908
|
+
sourceCandidateScanInvalidated = false;
|
|
1909
|
+
return;
|
|
1910
|
+
}
|
|
1911
|
+
const cachedScan = isWatchLikeBuild() ? sourceCandidateScanCache.get(nextScanSignature) ?? sourceCandidateScanSnapshotCache.get(nextScanSignature) : void 0;
|
|
1912
|
+
if (cachedScan) {
|
|
1913
|
+
sourceCandidateCollector.restore(cachedScan);
|
|
1914
|
+
sourceCandidateScanSignature = nextScanSignature;
|
|
1915
|
+
debug("reuse cached vite source candidate scan for watch rebuild");
|
|
1916
|
+
sourceCandidateScanInvalidated = false;
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
sourceCandidateCollector.clear();
|
|
1920
|
+
sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
1921
|
+
await scanSourceCandidateRoots(roots, outDir);
|
|
1922
|
+
sourceCandidateScanSignature = nextScanSignature;
|
|
1923
|
+
sourceCandidateScanInvalidated = false;
|
|
1924
|
+
if (isWatchLikeBuild()) {
|
|
1925
|
+
sourceCandidateScanCache.set(nextScanSignature, sourceCandidateCollector.snapshot());
|
|
1926
|
+
sourceCandidateScanSnapshotCache.set(nextScanSignature, sourceCandidateCollector.snapshot());
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
2053
1929
|
const waitForSourceCandidateSyncs = async () => {
|
|
2054
1930
|
while (pendingSourceCandidateSyncs.size > 0) await Promise.all(pendingSourceCandidateSyncs);
|
|
2055
1931
|
};
|
|
2056
1932
|
const syncChangedSourceCandidateFile = (id) => {
|
|
2057
|
-
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return Promise.resolve();
|
|
1933
|
+
if (!shouldOwnTailwindGeneration || !require_source_candidates.isSourceCandidateRequest(id)) return Promise.resolve();
|
|
2058
1934
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
1935
|
+
if (isSourceScanDependency(file)) invalidateSourceCandidateScan();
|
|
2059
1936
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
2060
1937
|
sourceCandidateCollector.remove(file);
|
|
1938
|
+
cacheCurrentSourceCandidateScan();
|
|
2061
1939
|
return Promise.resolve();
|
|
2062
1940
|
}
|
|
1941
|
+
if (sourceScanExplicit && sourceScanEntries?.length === 0) {
|
|
1942
|
+
cacheCurrentSourceCandidateScan();
|
|
1943
|
+
return Promise.resolve();
|
|
1944
|
+
}
|
|
1945
|
+
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
1946
|
+
if (existingTask) return existingTask;
|
|
2063
1947
|
const task = sourceCandidateCollector.syncFile(id).catch((error) => {
|
|
2064
1948
|
debug("source candidate watch sync failed: %s %O", id, error);
|
|
1949
|
+
}).then(() => {
|
|
1950
|
+
cacheCurrentSourceCandidateScan();
|
|
2065
1951
|
}).finally(() => {
|
|
2066
1952
|
pendingSourceCandidateSyncs.delete(task);
|
|
1953
|
+
pendingSourceCandidateSyncByFile.delete(file);
|
|
2067
1954
|
});
|
|
2068
1955
|
pendingSourceCandidateSyncs.add(task);
|
|
1956
|
+
pendingSourceCandidateSyncByFile.set(file, task);
|
|
2069
1957
|
return task;
|
|
2070
1958
|
};
|
|
1959
|
+
const shouldCollectTransformedSourceCandidates = (id) => {
|
|
1960
|
+
if (id.search(/[?#]/) < 0) return true;
|
|
1961
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
1962
|
+
return !/\.(?:vue|uvue|nvue|svelte|mpx)$/i.test(file);
|
|
1963
|
+
};
|
|
2071
1964
|
const rememberMainCssSource = (file, rawSource, cssRuntimeSignature) => {
|
|
2072
1965
|
rememberedMainCssSources.set(file, rawSource);
|
|
2073
1966
|
if (cssRuntimeSignature) rememberedMainCssSignatureByFile.set(file, cssRuntimeSignature);
|
|
@@ -2086,12 +1979,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
2086
1979
|
getResolvedConfig,
|
|
2087
1980
|
markCssAssetProcessed,
|
|
2088
1981
|
getSourceCandidates,
|
|
1982
|
+
getSourceCandidatesForEntries,
|
|
2089
1983
|
waitForSourceCandidateSyncs,
|
|
2090
1984
|
rememberMainCssSource,
|
|
2091
1985
|
getRememberedMainCssSources,
|
|
2092
1986
|
getRememberedMainCssSignature,
|
|
2093
1987
|
setRememberedMainCssSignature,
|
|
2094
|
-
recordGeneratorCandidates
|
|
1988
|
+
recordGeneratorCandidates,
|
|
1989
|
+
hmrTimingRecorder
|
|
2095
1990
|
});
|
|
2096
1991
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
|
2097
1992
|
opts,
|
|
@@ -2103,6 +1998,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
2103
1998
|
isCssAssetProcessed,
|
|
2104
1999
|
getRecordedGeneratorCandidates,
|
|
2105
2000
|
getSourceCandidates,
|
|
2001
|
+
getSourceCandidatesForEntries,
|
|
2106
2002
|
waitForSourceCandidateSyncs,
|
|
2107
2003
|
rememberMainCssSource
|
|
2108
2004
|
});
|
|
@@ -2126,46 +2022,43 @@ function WeappTailwindcss(options = {}) {
|
|
|
2126
2022
|
name: `${require_precheck.vitePluginName}:source-candidates`,
|
|
2127
2023
|
enforce: "pre",
|
|
2128
2024
|
async transform(code, id) {
|
|
2129
|
-
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return;
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2025
|
+
if (!shouldOwnTailwindGeneration || !require_source_candidates.isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
|
|
2026
|
+
return hmrTimingRecorder.measure("sourceCandidates.transform", async () => {
|
|
2027
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
2028
|
+
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
2029
|
+
sourceCandidateCollector.remove(file);
|
|
2030
|
+
cacheCurrentSourceCandidateScan();
|
|
2031
|
+
return;
|
|
2032
|
+
}
|
|
2033
|
+
if (sourceScanExplicit && sourceScanEntries?.length === 0) {
|
|
2034
|
+
cacheCurrentSourceCandidateScan();
|
|
2035
|
+
return;
|
|
2036
|
+
}
|
|
2037
|
+
await sourceCandidateCollector.merge(id, code);
|
|
2038
|
+
cacheCurrentSourceCandidateScan();
|
|
2039
|
+
}, { emit: false });
|
|
2136
2040
|
},
|
|
2137
2041
|
async watchChange(id, change) {
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2042
|
+
await hmrTimingRecorder.measure("sourceCandidates.watchChange", async () => {
|
|
2043
|
+
if (isSourceScanDependency(id)) invalidateSourceCandidateScan();
|
|
2044
|
+
if (change.event === "delete") {
|
|
2045
|
+
sourceCandidateCollector.remove(id);
|
|
2046
|
+
cacheCurrentSourceCandidateScan();
|
|
2047
|
+
return;
|
|
2048
|
+
}
|
|
2049
|
+
await syncChangedSourceCandidateFile(id);
|
|
2050
|
+
}, { emit: false });
|
|
2143
2051
|
},
|
|
2144
2052
|
async handleHotUpdate(ctx) {
|
|
2145
|
-
await
|
|
2053
|
+
await hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
|
|
2054
|
+
await syncChangedSourceCandidateFile(ctx.file);
|
|
2055
|
+
}, { emit: false });
|
|
2146
2056
|
},
|
|
2147
2057
|
async buildStart() {
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
sourceScanEntries = sourceScan?.entries;
|
|
2153
|
-
sourceScanMatcher = createViteSourceScanMatcher(sourceScanEntries);
|
|
2154
|
-
const roots = collectSourceCandidateScanRoots(root, sourceScanEntries);
|
|
2155
|
-
const nextScanSignature = createSourceCandidateScanSignature({
|
|
2156
|
-
inlineCandidates: sourceScan?.inlineCandidates,
|
|
2157
|
-
outDir,
|
|
2158
|
-
roots
|
|
2159
|
-
});
|
|
2160
|
-
if (isWatchBuild() && sourceCandidateScanSignature === nextScanSignature) {
|
|
2161
|
-
sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
2162
|
-
debug("reuse vite source candidate scan for watch rebuild");
|
|
2163
|
-
return;
|
|
2164
|
-
}
|
|
2165
|
-
sourceCandidateCollector.clear();
|
|
2166
|
-
sourceCandidateCollector.syncInline(sourceScan?.inlineCandidates);
|
|
2167
|
-
await scanSourceCandidateRoots(roots, outDir);
|
|
2168
|
-
sourceCandidateScanSignature = nextScanSignature;
|
|
2058
|
+
await hmrTimingRecorder.measure("sourceCandidates.buildStart", async () => {
|
|
2059
|
+
if (shouldDiscoverAutoCssSources()) await discoverAndRegisterAutoCssSources();
|
|
2060
|
+
await syncSourceCandidateScan();
|
|
2061
|
+
}, { emit: false });
|
|
2169
2062
|
}
|
|
2170
2063
|
},
|
|
2171
2064
|
{
|
|
@@ -2196,45 +2089,47 @@ function WeappTailwindcss(options = {}) {
|
|
|
2196
2089
|
});
|
|
2197
2090
|
},
|
|
2198
2091
|
async configResolved(config) {
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
const resolvedRoot = config.root ? node_path.default.resolve(config.root) : void 0;
|
|
2205
|
-
let shouldRefreshRuntime = false;
|
|
2206
|
-
if (!hasExplicitTailwindcssBasedir && resolvedRoot) {
|
|
2207
|
-
const nextTailwindcssBasedir = resolveImplicitTailwindcssBasedirFromViteRoot(resolvedRoot);
|
|
2208
|
-
if (opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
|
|
2209
|
-
const previousBasedir = opts.tailwindcssBasedir;
|
|
2210
|
-
opts.tailwindcssBasedir = nextTailwindcssBasedir;
|
|
2211
|
-
debug("align tailwindcss basedir with vite root: %s -> %s", previousBasedir ?? "undefined", nextTailwindcssBasedir);
|
|
2212
|
-
shouldRefreshRuntime = true;
|
|
2092
|
+
await hmrTimingRecorder.measure("configResolved", async () => {
|
|
2093
|
+
resolvedConfig = config;
|
|
2094
|
+
if (shouldOwnTailwindGeneration) {
|
|
2095
|
+
const removed = Array.isArray(config.plugins) ? removeTailwindVitePlugins(config.plugins) : 0;
|
|
2096
|
+
if (removed > 0) debug("remove official tailwind vite plugins in generator mode: %d", removed);
|
|
2213
2097
|
}
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2098
|
+
const resolvedRoot = config.root ? node_path.default.resolve(config.root) : void 0;
|
|
2099
|
+
let shouldRefreshRuntime = false;
|
|
2100
|
+
if (!hasExplicitTailwindcssBasedir && resolvedRoot) {
|
|
2101
|
+
const nextTailwindcssBasedir = resolveImplicitTailwindcssBasedirFromViteRoot(resolvedRoot);
|
|
2102
|
+
if (opts.tailwindcssBasedir !== nextTailwindcssBasedir) {
|
|
2103
|
+
const previousBasedir = opts.tailwindcssBasedir;
|
|
2104
|
+
opts.tailwindcssBasedir = nextTailwindcssBasedir;
|
|
2105
|
+
debug("align tailwindcss basedir with vite root: %s -> %s", previousBasedir ?? "undefined", nextTailwindcssBasedir);
|
|
2106
|
+
shouldRefreshRuntime = true;
|
|
2107
|
+
}
|
|
2223
2108
|
}
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2109
|
+
if (!hasExplicitAppType && resolvedRoot) {
|
|
2110
|
+
const nextAppType = resolveImplicitAppTypeFromViteRoot(resolvedRoot);
|
|
2111
|
+
if (nextAppType && opts.appType !== nextAppType) {
|
|
2112
|
+
const previousAppType = opts.appType;
|
|
2113
|
+
opts.appType = nextAppType;
|
|
2114
|
+
_weapp_tailwindcss_logger.logger.info("根据 Vite 项目根目录自动推断 appType -> %s", nextAppType);
|
|
2115
|
+
debug("align appType with vite root: %s -> %s", previousAppType ?? "undefined", nextAppType);
|
|
2116
|
+
shouldRefreshRuntime = true;
|
|
2117
|
+
}
|
|
2231
2118
|
}
|
|
2232
|
-
|
|
2233
|
-
if (
|
|
2234
|
-
postcssPlugins
|
|
2235
|
-
|
|
2119
|
+
if (shouldRefreshRuntime) await refreshRuntimeState(true);
|
|
2120
|
+
if (typeof config.css.postcss === "object" && Array.isArray(config.css.postcss.plugins)) {
|
|
2121
|
+
const postcssPlugins = config.css.postcss.plugins;
|
|
2122
|
+
if (shouldOwnTailwindGeneration) {
|
|
2123
|
+
const removed = removeTailwindPostcssPlugins(postcssPlugins);
|
|
2124
|
+
if (removed > 0) debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
2125
|
+
}
|
|
2126
|
+
const idx = postcssPlugins.findIndex((x) => getPostcssPluginName(x) === "postcss-html-transform");
|
|
2127
|
+
if (idx > -1) {
|
|
2128
|
+
postcssPlugins.splice(idx, 1, (0, _weapp_tailwindcss_postcss_html_transform.default)());
|
|
2129
|
+
debug("remove postcss-html-transform plugin from vite config");
|
|
2130
|
+
}
|
|
2236
2131
|
}
|
|
2237
|
-
}
|
|
2132
|
+
}, { emit: false });
|
|
2238
2133
|
},
|
|
2239
2134
|
generateBundle: {
|
|
2240
2135
|
order: "post",
|