weapp-tailwindcss 5.4.2 → 5.5.1
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/README.md +13 -1
- package/README.zh-CN.md +13 -1
- package/dist/bundlers/shared/final-css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/v4-generation-core.d.ts +1 -0
- package/dist/bundlers/vite/capability-profile.d.ts +1 -0
- package/dist/bundlers/vite/css-finalizer/web-plugin.d.ts +3 -0
- package/dist/bundlers/vite/css-handler-options.d.ts +32 -0
- package/dist/bundlers/vite/{generate-bundle/css-output.d.ts → css-output.d.ts} +1 -1
- package/dist/bundlers/vite/frameworks/generic/web.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +2 -32
- package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +2 -2
- package/dist/bundlers/vite/generate-bundle/runtime.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/runtime-class-set.d.ts +1 -5
- package/dist/bundlers/vite/shared/create-css-only-plugins-runtime.d.ts +3 -0
- package/dist/cache-CBJFB1HN.cjs +223 -0
- package/dist/compiler/events.d.ts +32 -0
- package/dist/compiler/host.d.ts +13 -0
- package/dist/compiler/index.d.ts +3 -0
- package/dist/compiler/runtime-state.d.ts +17 -0
- package/dist/compiler-B0YSc0DY.js +4877 -0
- package/dist/{wxml-o-CUulAM.cjs → compiler-D2ZJc3uA.cjs} +3649 -283
- package/dist/core.cjs +6 -3
- package/dist/core.d.ts +2 -0
- package/dist/core.js +4 -4
- package/dist/defaults-B5ep0ojb.js +120 -0
- package/dist/defaults-BI9j1znS.cjs +156 -0
- package/dist/defaults.cjs +5 -121
- package/dist/defaults.js +1 -116
- package/dist/final-css-cleanup-B0HUBtiE.js +308 -0
- package/dist/final-css-cleanup-DSjczga3.cjs +138 -0
- package/dist/{generator-WlhrtNa3.cjs → generator-DsrQ9txU.cjs} +62 -5
- package/dist/{generator-BjK5PRR-.js → generator-DyXTBPmE.js} +47 -2
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/dist/{gulp-ChecVI6A.cjs → gulp-C9ENAx3f.cjs} +30 -28
- package/dist/{gulp-D6LcfRz_.js → gulp-DXeQfvVC.js} +7 -7
- package/dist/gulp.cjs +1 -1
- package/dist/gulp.js +1 -1
- package/dist/{hmr-timing-afnWvy7u.cjs → hmr-timing-Cz4IesEM.cjs} +6 -229
- package/dist/{hmr-timing-CqDfjvqE.js → hmr-timing-DNxQm-bN.js} +6 -1258
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/dist/{pipeline-helpers-DxPFMGxz.cjs → pipeline-helpers-CSGnR5gh.cjs} +6 -5
- package/dist/postcss.cjs +1 -1
- package/dist/postcss.js +1 -1
- package/dist/presets.cjs +4 -4
- package/dist/presets.js +2 -2
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +2 -2
- package/dist/runtime-state-BBQcA0n5.cjs +54 -0
- package/dist/{source-candidate-scan-signature-FywFU3Rg.cjs → scoped-generator-TVjEaOeP.cjs} +5 -123
- package/dist/{source-candidate-scan-signature-BVScymyM.js → scoped-generator-kRj_5Axx.js} +4 -92
- package/dist/source-candidate-scan-signature-B7cUxqqX.cjs +129 -0
- package/dist/source-candidate-scan-signature-CsP4BQNa.js +92 -0
- package/dist/style-injector/internal.d.ts +1 -1
- package/dist/style-injector/vite-web.d.ts +3 -0
- package/dist/{tailwindcss-9xmoCkaR.js → tailwindcss-BK9S7zuq.js} +1 -2
- package/dist/{tailwindcss-D3jltF7M.cjs → tailwindcss-C-jBBQfw.cjs} +8 -9
- package/dist/{transform-DQhgAarN.js → transform-CfOzh007.js} +3 -3
- package/dist/{transform-C6k9zTQR.cjs → transform-DUPOPZ54.cjs} +27 -27
- package/dist/uni-app-x/vite/style-source.d.ts +11 -0
- package/dist/{v4-generation-core-CPKNwzjz.cjs → v4-generation-core-CRNUU_Rr.cjs} +29 -1172
- package/dist/vite/web.cjs +27 -0
- package/dist/vite/web.d.ts +1 -0
- package/dist/vite/web.js +25 -0
- package/dist/{vite-D3aCtpmv.js → vite-BXe-axax.js} +263 -3587
- package/dist/{vite-D-gmOkPN.cjs → vite-D_mAIfTU.cjs} +514 -3798
- package/dist/vite-web.d.ts +4 -0
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/weapp-tw-css-generation-loader.cjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.cjs +5 -5
- package/dist/web-B2Ea9K4B.cjs +4361 -0
- package/dist/web-Cv7ualrU.js +3796 -0
- package/dist/{webpack-B-6a8Z8F.js → webpack-7Um2GFtx.js} +13 -12
- package/dist/{webpack-yAne9ZYu.cjs → webpack-Ce04-btG.cjs} +51 -49
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +13 -4
- package/dist/cache-options-DavPxrhC.cjs +0 -16
- package/dist/cache-options-DwBtLwQe.js +0 -5
- package/dist/compiler-B-m9VGqj.cjs +0 -2316
- package/dist/compiler-BgMj2E5l.js +0 -2051
- package/dist/local-style-matcher-DRpFEu1s.cjs +0 -34
- package/dist/local-style-matcher-DsiI2wIc.js +0 -17
- package/dist/object-B-8IHefx.js +0 -47
- package/dist/object-DbHtAXRk.cjs +0 -58
- package/dist/wxml-CvKyV69S.js +0 -1822
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as hasTailwindRootDirectives, At as resolveTailwindV4CssSourceBase, B as removeUnsupportedMiniProgramAtRules, F as stripTailwindSourceMediaFragments, G as shouldFilterApplyOnlyGeneratedCss, H as removeTailwindV4GeneratedUserCssArtifacts, I as stripUnmatchedTailwindSourceMediaCloseFragments, J as splitUserCssLayerBlocks, K as extractGeneratedCssForUserLayerSelectors, L as finalizeMiniProgramCss$1, Lt as filterUnsupportedMiniProgramTailwindV4Candidates, M as isCommentOnlyCss, P as removeTailwindV4GeneratorAtRules, T as omitUndefined, Tt as isFileMatchedByTailwindSourceEntries, U as filterApplyOnlyGeneratedCss, W as normalizeEmptyTailwindCustomVariants, Y as preferScopedGeneratedCssRules, Z as hasTailwindApplyDirective, _t as stripTailwindBanners, a as resolveGeneratorRuntimeBranch, at as removeTailwindSourceDirectives, ct as VITE_MARKER_RE, d as resolveTailwindV4SourceFromRuntime, dt as hasTailwindGeneratedCssMarkers, et as hasTailwindSourceDirectives, ft as splitGeneratorPlaceholderCssBySourceOrder, gt as stripTailwindBanner, ht as stripGeneratorPlaceholderMarkers, i as normalizeWeappTailwindcssGeneratorOptions, it as parseImportRequest, j as transformGeneratorUserCss, jt as toPosixPath, kt as resolveSourceScanPath, lt as createCssAppend, mt as splitTailwindV4GeneratedCssBySourceOrder, nt as normalizeTailwindSourceDirectives, ot as resolveCssEntrySource, p as resolveTailwindV4SourceOptionsFromRuntime, pt as splitTailwindGeneratedCssByBanner, q as hasUserCssLayerBlocks, s as shouldUseMiniProgramCssBranch, st as GENERATOR_PLACEHOLDER_MARKER_RE, u as resolveTailwindV4Source$1, ut as hasTailwindGeneratedCss, vt as normalizeConfigDirective, wt as isFileExcludedByTailwindSourceEntries, xt as FULL_SOURCE_SCAN_EXTENSION_RE, yt as prependConfigDirective, zt as loadTailwindV4DesignSystem } from "./generator-DyXTBPmE.js";
|
|
2
2
|
import { o as transformCssMacroCss, r as hasCssMacroTailwindV4InternalAtRules, t as hasCssMacroStyleOptions } from "./auto-2dg_uhEJ.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { _ as md5Hash, g as traverse, h as babelParse, m as createDebug, p as replaceWxml, r as createAttributeMatcher } from "./wxml-CvKyV69S.js";
|
|
6
|
-
import { g as DefaultCompilationSession, i as resolveStyleOptionsFromContext, t as createCompiler } from "./compiler-BgMj2E5l.js";
|
|
3
|
+
import { _ as includesTailwindV4PreflightDirective, h as resolveTailwindV4EntriesFromCss, l as getRuntimeClassSetSignature, r as isUniAppXEnabled, v as collectCssInlineSourceCandidates } from "./tailwindcss-BK9S7zuq.js";
|
|
4
|
+
import { A as consumeCompilationScopeChanges, B as createGenerationArtifact, F as getCompilationSessionPool, G as replaceWxml, I as runCompilerOwnerActivity, J as traverse, K as createDebug, P as getTailwindGenerationSessionPool, R as mergeCompilationDependencyChanges, V as createAttributeMatcher, Y as md5Hash, k as composeGenerationArtifact, l as recordCompilerShadowReport, m as resolveStyleOptionsFromContext, o as completeCompilerShadowReportRun, q as babelParse, r as createStylePlatformAdapter, s as getCompilerShadowRunRevision, u as getFrameworkCompilerSession, z as createCssFragment } from "./compiler-B0YSc0DY.js";
|
|
7
5
|
import { existsSync, readFileSync } from "node:fs";
|
|
8
6
|
import path from "node:path";
|
|
9
7
|
import process from "node:process";
|
|
10
8
|
import { extractRawCandidatesWithPositions, extractSourceCandidates, extractValidCandidates, resolveProjectSourceFiles, resolveValidTailwindV4Candidates, splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
11
|
-
import { cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, filterExistingCssRules, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, normalizeMiniProgramGeneratedCssForPostcss, postcss,
|
|
9
|
+
import { cleanLocalCssImportWrapperTailwindDirectives, cleanLocalCssImportWrapperTailwindDirectivesRoot, filterExistingCssRules, isPureLocalCssImportWrapper, isPureLocalCssImportWrapperRoot, normalizeMiniProgramGeneratedCssForPostcss, postcss, removeMatchingLocalCssImports, removeTailwindPostcssPlugins, restoreLocalCssImports, rewriteLocalCssImportRequestsForOutput, splitLocalCssImports, splitLocalCssImportsRoot, transformWebCssCompat } from "@weapp-tailwindcss/postcss";
|
|
12
10
|
import { LRUCache } from "lru-cache";
|
|
13
11
|
import { readFile } from "node:fs/promises";
|
|
14
12
|
import { Parser } from "htmlparser2";
|
|
15
13
|
import { MappingChars2String, unescape } from "@weapp-core/escape";
|
|
16
|
-
import { Buffer } from "node:buffer";
|
|
17
14
|
//#region src/bundlers/shared/source-candidates/scan-root.ts
|
|
18
15
|
const TAILWIND_V4_IGNORED_CONTENT_DIRS = [
|
|
19
16
|
".git",
|
|
@@ -741,730 +738,6 @@ function createSourceCandidateCollector(options = {}) {
|
|
|
741
738
|
return createSourceCandidateStore(options);
|
|
742
739
|
}
|
|
743
740
|
//#endregion
|
|
744
|
-
//#region src/compiler/artifact.ts
|
|
745
|
-
function createCssFragment(options) {
|
|
746
|
-
return {
|
|
747
|
-
id: options.id,
|
|
748
|
-
kind: options.kind,
|
|
749
|
-
root: postcss.parse(options.css, { from: options.sourceId }),
|
|
750
|
-
sourceId: options.sourceId,
|
|
751
|
-
scope: options.scope,
|
|
752
|
-
order: options.order ?? 0,
|
|
753
|
-
stage: options.stage ?? "raw"
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
function cloneCssFragment(fragment) {
|
|
757
|
-
return {
|
|
758
|
-
...fragment,
|
|
759
|
-
root: fragment.root.clone(),
|
|
760
|
-
scope: { ...fragment.scope }
|
|
761
|
-
};
|
|
762
|
-
}
|
|
763
|
-
function cloneGenerationArtifact(artifact) {
|
|
764
|
-
return {
|
|
765
|
-
fragments: artifact.fragments.map(cloneCssFragment),
|
|
766
|
-
classSet: new Set(artifact.classSet),
|
|
767
|
-
rawCandidates: new Set(artifact.rawCandidates),
|
|
768
|
-
dependencies: [...artifact.dependencies],
|
|
769
|
-
sourceEntries: [...artifact.sourceEntries],
|
|
770
|
-
...artifact.revision === void 0 ? {} : { revision: artifact.revision }
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
function createGenerationArtifact(fragments, options) {
|
|
774
|
-
return cloneGenerationArtifact({
|
|
775
|
-
fragments,
|
|
776
|
-
...options
|
|
777
|
-
});
|
|
778
|
-
}
|
|
779
|
-
//#endregion
|
|
780
|
-
//#region src/compiler/compilation-scope-graph.ts
|
|
781
|
-
function sourceNodeId(sourceId) {
|
|
782
|
-
return `source:${sourceId}`;
|
|
783
|
-
}
|
|
784
|
-
function dependencyNodeId(dependencyId) {
|
|
785
|
-
return `dependency:${dependencyId}`;
|
|
786
|
-
}
|
|
787
|
-
function createCompilationDependencyChanges(dependencyIds, type = "dependency-changed") {
|
|
788
|
-
return [...new Set(dependencyIds)].map((id) => ({
|
|
789
|
-
id,
|
|
790
|
-
type
|
|
791
|
-
}));
|
|
792
|
-
}
|
|
793
|
-
function mergeCompilationDependencyChanges(...groups) {
|
|
794
|
-
const changes = /* @__PURE__ */ new Map();
|
|
795
|
-
for (const group of groups) for (const change of group ?? []) {
|
|
796
|
-
const previous = changes.get(change.id);
|
|
797
|
-
changes.set(change.id, {
|
|
798
|
-
id: change.id,
|
|
799
|
-
type: previous?.type === "config-changed" ? previous.type : change.type
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
return [...changes.values()];
|
|
803
|
-
}
|
|
804
|
-
function mergeCompilationScopeDependencies(...groups) {
|
|
805
|
-
const dependencies = /* @__PURE__ */ new Map();
|
|
806
|
-
for (const group of groups) for (const dependency of group ?? []) {
|
|
807
|
-
const previous = dependencies.get(dependency.id);
|
|
808
|
-
if (previous && previous.kind !== dependency.kind) throw new Error(`同一个依赖不能对应不同类型:${dependency.id}`);
|
|
809
|
-
dependencies.set(dependency.id, { ...dependency });
|
|
810
|
-
}
|
|
811
|
-
return [...dependencies.values()];
|
|
812
|
-
}
|
|
813
|
-
function dependencySignature(source) {
|
|
814
|
-
return mergeCompilationScopeDependencies(source.dependencies).map((dependency) => `${dependency.kind}\0${dependency.id}`).sort().join("\0");
|
|
815
|
-
}
|
|
816
|
-
function createCompilationScopeGraph(scope, outputId, sources) {
|
|
817
|
-
const normalizedSources = [...sources].map((source) => ({
|
|
818
|
-
...source,
|
|
819
|
-
dependencies: mergeCompilationScopeDependencies(source.dependencies)
|
|
820
|
-
}));
|
|
821
|
-
const dependencies = mergeCompilationScopeDependencies(...normalizedSources.map((source) => source.dependencies));
|
|
822
|
-
const outputNodeId = `asset:${outputId}`;
|
|
823
|
-
return {
|
|
824
|
-
nodes: [
|
|
825
|
-
...normalizedSources.map((source) => ({
|
|
826
|
-
id: sourceNodeId(source.id),
|
|
827
|
-
kind: source.kind,
|
|
828
|
-
scope: { ...scope },
|
|
829
|
-
...source.content === void 0 ? {} : { content: source.content }
|
|
830
|
-
})),
|
|
831
|
-
...dependencies.map((dependency) => ({
|
|
832
|
-
id: dependencyNodeId(dependency.id),
|
|
833
|
-
kind: dependency.kind,
|
|
834
|
-
scope: { ...scope }
|
|
835
|
-
})),
|
|
836
|
-
{
|
|
837
|
-
id: outputNodeId,
|
|
838
|
-
kind: "asset",
|
|
839
|
-
scope: { ...scope }
|
|
840
|
-
}
|
|
841
|
-
],
|
|
842
|
-
edges: normalizedSources.flatMap((source) => [{
|
|
843
|
-
from: sourceNodeId(source.id),
|
|
844
|
-
to: outputNodeId,
|
|
845
|
-
kind: "emits-to"
|
|
846
|
-
}, ...source.dependencies.map((dependency) => ({
|
|
847
|
-
from: sourceNodeId(source.id),
|
|
848
|
-
to: dependencyNodeId(dependency.id),
|
|
849
|
-
kind: "depends-on"
|
|
850
|
-
}))])
|
|
851
|
-
};
|
|
852
|
-
}
|
|
853
|
-
function createCompilationScopeSnapshot(scope, outputId, sources, options = {}) {
|
|
854
|
-
const normalizedSources = [...sources];
|
|
855
|
-
return {
|
|
856
|
-
...createCompilationScopeGraph(scope, outputId, normalizedSources),
|
|
857
|
-
candidatesBySource: normalizedSources.map((source) => [sourceNodeId(source.id), source.candidates]),
|
|
858
|
-
...options.changes === void 0 ? {} : { changes: options.changes },
|
|
859
|
-
...options.preserveDeletedCss === void 0 ? {} : { preserveDeletedCss: options.preserveDeletedCss },
|
|
860
|
-
...options.validatedClassSet === void 0 ? {} : { validatedClassSet: options.validatedClassSet }
|
|
861
|
-
};
|
|
862
|
-
}
|
|
863
|
-
//#endregion
|
|
864
|
-
//#region src/compiler/compilation-dependency-state.ts
|
|
865
|
-
var CompilationDependencyState = class {
|
|
866
|
-
constructor() {
|
|
867
|
-
_defineProperty(this, "revisions", /* @__PURE__ */ new Map());
|
|
868
|
-
}
|
|
869
|
-
getAffectedScopes(entries, changes) {
|
|
870
|
-
return new Set(this.getAffectedScopeChanges(entries, changes).keys());
|
|
871
|
-
}
|
|
872
|
-
getAffectedScopeChanges(entries, changes) {
|
|
873
|
-
const changesByNodeId = new Map([...changes].map((change) => [dependencyNodeId(change.id), change]));
|
|
874
|
-
const affectedScopeChanges = /* @__PURE__ */ new Map();
|
|
875
|
-
for (const entry of entries) {
|
|
876
|
-
const scopeChanges = entry.latest?.graphNodes.map((node) => changesByNodeId.get(node.id)).filter((change) => change !== void 0);
|
|
877
|
-
if (scopeChanges && scopeChanges.length > 0) affectedScopeChanges.set(entry.scope.id, scopeChanges.map((change) => ({ ...change })));
|
|
878
|
-
}
|
|
879
|
-
return affectedScopeChanges;
|
|
880
|
-
}
|
|
881
|
-
record(entries, changes) {
|
|
882
|
-
const affectedScopes = this.getAffectedScopes(entries, changes);
|
|
883
|
-
this.recordScopes(affectedScopes);
|
|
884
|
-
return affectedScopes;
|
|
885
|
-
}
|
|
886
|
-
recordScopes(scopeIds) {
|
|
887
|
-
for (const scopeId of scopeIds) this.revisions.set(scopeId, (this.revisions.get(scopeId) ?? 0) + 1);
|
|
888
|
-
}
|
|
889
|
-
getRevision(scopeId) {
|
|
890
|
-
return this.revisions.get(scopeId) ?? 0;
|
|
891
|
-
}
|
|
892
|
-
delete(scopeId) {
|
|
893
|
-
this.revisions.delete(scopeId);
|
|
894
|
-
}
|
|
895
|
-
clear() {
|
|
896
|
-
this.revisions.clear();
|
|
897
|
-
}
|
|
898
|
-
};
|
|
899
|
-
//#endregion
|
|
900
|
-
//#region src/compiler/compiler-owner-state.ts
|
|
901
|
-
const compilerOwnerDisposals = /* @__PURE__ */ new WeakMap();
|
|
902
|
-
const compilerOwnerActivities = /* @__PURE__ */ new WeakMap();
|
|
903
|
-
function ensureCompilerOwnerActive(owner) {
|
|
904
|
-
if (compilerOwnerDisposals.has(owner)) throw new Error("Compiler owner 正在释放,不能创建新的编译状态。");
|
|
905
|
-
}
|
|
906
|
-
function acquireCompilerOwnerActivity(owner) {
|
|
907
|
-
const currentDisposal = compilerOwnerDisposals.get(owner);
|
|
908
|
-
if (currentDisposal) return currentDisposal.then(() => acquireCompilerOwnerActivity(owner));
|
|
909
|
-
let state = compilerOwnerActivities.get(owner);
|
|
910
|
-
if (!state) {
|
|
911
|
-
state = {
|
|
912
|
-
active: 0,
|
|
913
|
-
idleWaiters: /* @__PURE__ */ new Set()
|
|
914
|
-
};
|
|
915
|
-
compilerOwnerActivities.set(owner, state);
|
|
916
|
-
}
|
|
917
|
-
state.active += 1;
|
|
918
|
-
let released = false;
|
|
919
|
-
return () => {
|
|
920
|
-
if (released) return;
|
|
921
|
-
released = true;
|
|
922
|
-
state.active -= 1;
|
|
923
|
-
if (state.active > 0) return;
|
|
924
|
-
compilerOwnerActivities.delete(owner);
|
|
925
|
-
for (const resolve of state.idleWaiters) resolve();
|
|
926
|
-
state.idleWaiters.clear();
|
|
927
|
-
};
|
|
928
|
-
}
|
|
929
|
-
function waitForCompilerOwnerIdle(owner) {
|
|
930
|
-
const state = compilerOwnerActivities.get(owner);
|
|
931
|
-
if (!state || state.active === 0) return Promise.resolve();
|
|
932
|
-
return new Promise((resolve) => {
|
|
933
|
-
state.idleWaiters.add(resolve);
|
|
934
|
-
});
|
|
935
|
-
}
|
|
936
|
-
function runCompilerOwnerActivity(owner, activity) {
|
|
937
|
-
const acquired = acquireCompilerOwnerActivity(owner);
|
|
938
|
-
if (typeof acquired !== "function") return acquired.then((release) => runCompilerOwnerActivityWithRelease(activity, release));
|
|
939
|
-
return runCompilerOwnerActivityWithRelease(activity, acquired);
|
|
940
|
-
}
|
|
941
|
-
function runCompilerOwnerActivityWithRelease(activity, release) {
|
|
942
|
-
try {
|
|
943
|
-
return Promise.resolve(activity()).finally(release);
|
|
944
|
-
} catch (error) {
|
|
945
|
-
release();
|
|
946
|
-
return Promise.reject(error);
|
|
947
|
-
}
|
|
948
|
-
}
|
|
949
|
-
function runCompilerOwnerDisposal(owner, dispose) {
|
|
950
|
-
const currentDisposal = compilerOwnerDisposals.get(owner);
|
|
951
|
-
if (currentDisposal) return currentDisposal;
|
|
952
|
-
const disposal = Promise.resolve().then(async () => {
|
|
953
|
-
await waitForCompilerOwnerIdle(owner);
|
|
954
|
-
await dispose();
|
|
955
|
-
}).finally(() => {
|
|
956
|
-
if (compilerOwnerDisposals.get(owner) === disposal) compilerOwnerDisposals.delete(owner);
|
|
957
|
-
});
|
|
958
|
-
compilerOwnerDisposals.set(owner, disposal);
|
|
959
|
-
return disposal;
|
|
960
|
-
}
|
|
961
|
-
//#endregion
|
|
962
|
-
//#region src/compiler/compilation-session-pool.ts
|
|
963
|
-
const COMPILATION_SCOPE_CACHE_MAX = 128;
|
|
964
|
-
function cloneScopeSource(source) {
|
|
965
|
-
return {
|
|
966
|
-
...source,
|
|
967
|
-
candidates: new Set(source.candidates),
|
|
968
|
-
dependencies: source.dependencies?.map((dependency) => ({ ...dependency }))
|
|
969
|
-
};
|
|
970
|
-
}
|
|
971
|
-
var CompilationSessionPool = class {
|
|
972
|
-
constructor() {
|
|
973
|
-
_defineProperty(this, "dependencyState", new CompilationDependencyState());
|
|
974
|
-
_defineProperty(this, "entries", /* @__PURE__ */ new Map());
|
|
975
|
-
_defineProperty(this, "disposed", false);
|
|
976
|
-
}
|
|
977
|
-
run(request, compile) {
|
|
978
|
-
const entry = this.getEntry(request.scope);
|
|
979
|
-
const execution = this.runEntry(entry, request, compile);
|
|
980
|
-
entry.executions.add(execution);
|
|
981
|
-
execution.then(() => entry.executions.delete(execution), () => entry.executions.delete(execution));
|
|
982
|
-
return execution;
|
|
983
|
-
}
|
|
984
|
-
invalidateScope(scopeId) {
|
|
985
|
-
const entry = this.entries.get(scopeId);
|
|
986
|
-
if (!entry) return;
|
|
987
|
-
entry.active = false;
|
|
988
|
-
this.disposeEntry(entry);
|
|
989
|
-
this.entries.delete(scopeId);
|
|
990
|
-
this.dependencyState.delete(scopeId);
|
|
991
|
-
}
|
|
992
|
-
dispose() {
|
|
993
|
-
if (this.disposed) return Promise.resolve();
|
|
994
|
-
this.disposed = true;
|
|
995
|
-
const entries = [...this.entries.values()];
|
|
996
|
-
for (const entry of entries) entry.active = false;
|
|
997
|
-
this.entries.clear();
|
|
998
|
-
this.dependencyState.clear();
|
|
999
|
-
return Promise.all(entries.map((entry) => this.disposeEntry(entry))).then(() => void 0);
|
|
1000
|
-
}
|
|
1001
|
-
get size() {
|
|
1002
|
-
return this.entries.size;
|
|
1003
|
-
}
|
|
1004
|
-
getAffectedScopes(changes) {
|
|
1005
|
-
return this.dependencyState.getAffectedScopes(this.entries.values(), changes);
|
|
1006
|
-
}
|
|
1007
|
-
getAffectedScopeChanges(changes) {
|
|
1008
|
-
return this.dependencyState.getAffectedScopeChanges(this.entries.values(), changes);
|
|
1009
|
-
}
|
|
1010
|
-
recordDependencyChanges(changes) {
|
|
1011
|
-
return this.dependencyState.record(this.entries.values(), changes);
|
|
1012
|
-
}
|
|
1013
|
-
recordAffectedScopes(scopeIds) {
|
|
1014
|
-
this.dependencyState.recordScopes(scopeIds);
|
|
1015
|
-
}
|
|
1016
|
-
getScopeDependencyRevision(scopeId) {
|
|
1017
|
-
return this.dependencyState.getRevision(scopeId);
|
|
1018
|
-
}
|
|
1019
|
-
getEntry(scope) {
|
|
1020
|
-
if (this.disposed) throw new Error("CompilationSessionPool 已释放。");
|
|
1021
|
-
const cached = this.entries.get(scope.id);
|
|
1022
|
-
if (cached) {
|
|
1023
|
-
if (cached.scope.kind !== scope.kind) throw new Error(`同一个 scope id 不能对应不同类型:${scope.id}`);
|
|
1024
|
-
this.entries.delete(scope.id);
|
|
1025
|
-
this.entries.set(scope.id, cached);
|
|
1026
|
-
return cached;
|
|
1027
|
-
}
|
|
1028
|
-
const entry = {
|
|
1029
|
-
active: true,
|
|
1030
|
-
executions: /* @__PURE__ */ new Set(),
|
|
1031
|
-
pending: Promise.resolve(),
|
|
1032
|
-
scope: { ...scope },
|
|
1033
|
-
session: new DefaultCompilationSession(),
|
|
1034
|
-
generatedDependencies: /* @__PURE__ */ new Map(),
|
|
1035
|
-
sources: /* @__PURE__ */ new Map()
|
|
1036
|
-
};
|
|
1037
|
-
this.entries.set(scope.id, entry);
|
|
1038
|
-
while (this.entries.size > COMPILATION_SCOPE_CACHE_MAX) {
|
|
1039
|
-
const oldestScopeId = this.entries.keys().next().value;
|
|
1040
|
-
if (oldestScopeId === void 0 || oldestScopeId === scope.id) break;
|
|
1041
|
-
this.invalidateScope(oldestScopeId);
|
|
1042
|
-
}
|
|
1043
|
-
return entry;
|
|
1044
|
-
}
|
|
1045
|
-
async disposeEntry(entry) {
|
|
1046
|
-
await Promise.allSettled([...entry.executions]);
|
|
1047
|
-
await entry.pending;
|
|
1048
|
-
entry.session.dispose();
|
|
1049
|
-
}
|
|
1050
|
-
async runEntry(entry, request, compile) {
|
|
1051
|
-
const prepared = await this.enqueue(entry, () => this.prepareEntry(entry, request));
|
|
1052
|
-
const value = await compile(prepared.compilation);
|
|
1053
|
-
const validatedClassSet = request.preserveDeletedCss ? /* @__PURE__ */ new Set([...prepared.compilation.validatedClassSet, ...value?.classSet ?? []]) : new Set(value?.classSet ?? []);
|
|
1054
|
-
const generatedDependencies = value?.dependenciesBySource === void 0 ? void 0 : this.normalizeGeneratedDependencies(value.dependenciesBySource, prepared.sources);
|
|
1055
|
-
let committed = false;
|
|
1056
|
-
let committedCompilation;
|
|
1057
|
-
await this.enqueue(entry, () => {
|
|
1058
|
-
if (!entry.active || entry.latest?.revision !== prepared.compilation.revision) return;
|
|
1059
|
-
if (generatedDependencies) entry.generatedDependencies = generatedDependencies;
|
|
1060
|
-
entry.latest = entry.session.commitValidation(prepared.compilation.revision, validatedClassSet, createCompilationScopeGraph(request.scope, request.outputId, this.createGraphSources(prepared.sources, entry.generatedDependencies)));
|
|
1061
|
-
committedCompilation = this.toScopeState(entry.latest, prepared.sources);
|
|
1062
|
-
committed = true;
|
|
1063
|
-
});
|
|
1064
|
-
const compilation = committedCompilation ?? {
|
|
1065
|
-
...prepared.compilation,
|
|
1066
|
-
validatedClassSet
|
|
1067
|
-
};
|
|
1068
|
-
return committed ? {
|
|
1069
|
-
committed,
|
|
1070
|
-
compilation,
|
|
1071
|
-
value
|
|
1072
|
-
} : {
|
|
1073
|
-
committed,
|
|
1074
|
-
compilation
|
|
1075
|
-
};
|
|
1076
|
-
}
|
|
1077
|
-
prepareEntry(entry, request) {
|
|
1078
|
-
const nextSources = new Map(request.sources.map((source) => [source.id, cloneScopeSource(source)]));
|
|
1079
|
-
const changes = [...request.changes ?? []].map((change) => ({
|
|
1080
|
-
sourceId: dependencyNodeId(change.id),
|
|
1081
|
-
type: change.type
|
|
1082
|
-
}));
|
|
1083
|
-
for (const sourceId of entry.sources.keys()) if (!nextSources.has(sourceId)) changes.push({
|
|
1084
|
-
sourceId: sourceNodeId(sourceId),
|
|
1085
|
-
type: "source-removed"
|
|
1086
|
-
});
|
|
1087
|
-
for (const [sourceId, source] of nextSources) {
|
|
1088
|
-
const previous = entry.sources.get(sourceId);
|
|
1089
|
-
if (previous && (previous.content !== source.content || dependencySignature(previous) !== dependencySignature(source))) changes.push({
|
|
1090
|
-
sourceId: sourceNodeId(sourceId),
|
|
1091
|
-
type: "dependency-changed"
|
|
1092
|
-
});
|
|
1093
|
-
}
|
|
1094
|
-
entry.sources = nextSources;
|
|
1095
|
-
entry.generatedDependencies = new Map([...entry.generatedDependencies].filter(([sourceId]) => nextSources.has(sourceId)));
|
|
1096
|
-
entry.latest = entry.session.update(createCompilationScopeSnapshot(request.scope, request.outputId, this.createGraphSources(nextSources, entry.generatedDependencies), {
|
|
1097
|
-
changes,
|
|
1098
|
-
preserveDeletedCss: request.preserveDeletedCss
|
|
1099
|
-
}));
|
|
1100
|
-
return {
|
|
1101
|
-
compilation: this.toScopeState(entry.latest, nextSources),
|
|
1102
|
-
sources: nextSources
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
createGraphSources(sources, generatedDependencies) {
|
|
1106
|
-
return [...sources.values()].map((source) => ({
|
|
1107
|
-
...source,
|
|
1108
|
-
dependencies: mergeCompilationScopeDependencies(source.dependencies, generatedDependencies.get(source.id))
|
|
1109
|
-
}));
|
|
1110
|
-
}
|
|
1111
|
-
normalizeGeneratedDependencies(dependenciesBySource, sources) {
|
|
1112
|
-
const normalized = /* @__PURE__ */ new Map();
|
|
1113
|
-
for (const [sourceId, dependencies] of dependenciesBySource) {
|
|
1114
|
-
if (!sources.has(sourceId)) throw new Error(`生成结果引用了未知 source:${sourceId}`);
|
|
1115
|
-
normalized.set(sourceId, mergeCompilationScopeDependencies(normalized.get(sourceId), dependencies));
|
|
1116
|
-
}
|
|
1117
|
-
return normalized;
|
|
1118
|
-
}
|
|
1119
|
-
enqueue(entry, task) {
|
|
1120
|
-
const execution = entry.pending.then(task);
|
|
1121
|
-
entry.pending = execution.then(() => void 0, () => void 0);
|
|
1122
|
-
return execution;
|
|
1123
|
-
}
|
|
1124
|
-
toScopeState(compilation, sources) {
|
|
1125
|
-
return {
|
|
1126
|
-
...compilation,
|
|
1127
|
-
candidatesBySource: new Map([...sources.keys()].map((sourceId) => [sourceId, compilation.candidatesBySource.get(sourceNodeId(sourceId)) ?? /* @__PURE__ */ new Set()]))
|
|
1128
|
-
};
|
|
1129
|
-
}
|
|
1130
|
-
};
|
|
1131
|
-
const compilationSessionPools = /* @__PURE__ */ new WeakMap();
|
|
1132
|
-
function getCompilationSessionPool(owner) {
|
|
1133
|
-
ensureCompilerOwnerActive(owner);
|
|
1134
|
-
let pool = compilationSessionPools.get(owner);
|
|
1135
|
-
if (!pool) {
|
|
1136
|
-
pool = new CompilationSessionPool();
|
|
1137
|
-
compilationSessionPools.set(owner, pool);
|
|
1138
|
-
}
|
|
1139
|
-
return pool;
|
|
1140
|
-
}
|
|
1141
|
-
function disposeCompilationSessionPool(owner) {
|
|
1142
|
-
const pool = compilationSessionPools.get(owner);
|
|
1143
|
-
if (!pool) return Promise.resolve();
|
|
1144
|
-
compilationSessionPools.delete(owner);
|
|
1145
|
-
return pool.dispose();
|
|
1146
|
-
}
|
|
1147
|
-
//#endregion
|
|
1148
|
-
//#region src/compiler/tailwind-generation-session-pool.ts
|
|
1149
|
-
const SESSION_ENGINE_CACHE_MAX = 32;
|
|
1150
|
-
function createSourceKey(source) {
|
|
1151
|
-
return md5Hash([
|
|
1152
|
-
source.projectRoot,
|
|
1153
|
-
source.base,
|
|
1154
|
-
source.baseFallbacks.join("\0"),
|
|
1155
|
-
source.css,
|
|
1156
|
-
source.dependencies.join("\0")
|
|
1157
|
-
].join("\0"));
|
|
1158
|
-
}
|
|
1159
|
-
function disposeGenerator(generator) {
|
|
1160
|
-
generator?.dispose?.();
|
|
1161
|
-
}
|
|
1162
|
-
var TailwindGenerationSessionPool = class {
|
|
1163
|
-
constructor() {
|
|
1164
|
-
_defineProperty(this, "generators", /* @__PURE__ */ new Map());
|
|
1165
|
-
_defineProperty(this, "disposed", false);
|
|
1166
|
-
}
|
|
1167
|
-
async generate(source, options) {
|
|
1168
|
-
return this.getGenerator(source).generate(options);
|
|
1169
|
-
}
|
|
1170
|
-
async validateCandidates(source, candidates) {
|
|
1171
|
-
return this.getGenerator(source).validateCandidates(candidates);
|
|
1172
|
-
}
|
|
1173
|
-
invalidate(change) {
|
|
1174
|
-
if (change.type === "all" || change.type === "dependencies") {
|
|
1175
|
-
for (const generator of this.generators.values()) disposeGenerator(generator);
|
|
1176
|
-
this.generators.clear();
|
|
1177
|
-
return;
|
|
1178
|
-
}
|
|
1179
|
-
const key = createSourceKey(change.source);
|
|
1180
|
-
disposeGenerator(this.generators.get(key));
|
|
1181
|
-
this.generators.delete(key);
|
|
1182
|
-
}
|
|
1183
|
-
dispose() {
|
|
1184
|
-
for (const generator of this.generators.values()) disposeGenerator(generator);
|
|
1185
|
-
this.generators.clear();
|
|
1186
|
-
this.disposed = true;
|
|
1187
|
-
}
|
|
1188
|
-
get size() {
|
|
1189
|
-
return this.generators.size;
|
|
1190
|
-
}
|
|
1191
|
-
getGenerator(source) {
|
|
1192
|
-
if (this.disposed) throw new Error("TailwindGenerationSessionPool 已释放。");
|
|
1193
|
-
const key = createSourceKey(source);
|
|
1194
|
-
const cached = this.generators.get(key);
|
|
1195
|
-
if (cached) {
|
|
1196
|
-
this.generators.delete(key);
|
|
1197
|
-
this.generators.set(key, cached);
|
|
1198
|
-
return cached;
|
|
1199
|
-
}
|
|
1200
|
-
const generator = createWeappTailwindcssGenerator(source);
|
|
1201
|
-
this.generators.set(key, generator);
|
|
1202
|
-
while (this.generators.size > SESSION_ENGINE_CACHE_MAX) {
|
|
1203
|
-
const oldest = this.generators.keys().next().value;
|
|
1204
|
-
if (oldest === void 0) break;
|
|
1205
|
-
disposeGenerator(this.generators.get(oldest));
|
|
1206
|
-
this.generators.delete(oldest);
|
|
1207
|
-
}
|
|
1208
|
-
return generator;
|
|
1209
|
-
}
|
|
1210
|
-
};
|
|
1211
|
-
const sessionPools = /* @__PURE__ */ new WeakMap();
|
|
1212
|
-
function getTailwindGenerationSessionPool(owner) {
|
|
1213
|
-
ensureCompilerOwnerActive(owner);
|
|
1214
|
-
let pool = sessionPools.get(owner);
|
|
1215
|
-
if (!pool) {
|
|
1216
|
-
pool = new TailwindGenerationSessionPool();
|
|
1217
|
-
sessionPools.set(owner, pool);
|
|
1218
|
-
}
|
|
1219
|
-
return pool;
|
|
1220
|
-
}
|
|
1221
|
-
function disposeTailwindGenerationSessionPool(owner) {
|
|
1222
|
-
const pool = sessionPools.get(owner);
|
|
1223
|
-
if (!pool) return;
|
|
1224
|
-
sessionPools.delete(owner);
|
|
1225
|
-
pool.dispose();
|
|
1226
|
-
}
|
|
1227
|
-
//#endregion
|
|
1228
|
-
//#region src/compiler/compilation-change-coordinator.ts
|
|
1229
|
-
var CompilationChangeCoordinator = class {
|
|
1230
|
-
constructor(compilationPool, generationPool) {
|
|
1231
|
-
this.compilationPool = compilationPool;
|
|
1232
|
-
this.generationPool = generationPool;
|
|
1233
|
-
_defineProperty(this, "pendingChangesByScope", /* @__PURE__ */ new Map());
|
|
1234
|
-
_defineProperty(this, "disposed", false);
|
|
1235
|
-
}
|
|
1236
|
-
record(changes) {
|
|
1237
|
-
this.ensureActive();
|
|
1238
|
-
const normalizedChanges = mergeCompilationDependencyChanges(changes);
|
|
1239
|
-
if (normalizedChanges.length === 0) return /* @__PURE__ */ new Set();
|
|
1240
|
-
const affectedScopeChanges = this.compilationPool.getAffectedScopeChanges(normalizedChanges);
|
|
1241
|
-
const affectedScopes = new Set(affectedScopeChanges.keys());
|
|
1242
|
-
const newlyPendingScopes = /* @__PURE__ */ new Set();
|
|
1243
|
-
const invalidatedPaths = /* @__PURE__ */ new Set();
|
|
1244
|
-
for (const [scopeId, scopeChanges] of affectedScopeChanges) {
|
|
1245
|
-
let pendingChanges = this.pendingChangesByScope.get(scopeId);
|
|
1246
|
-
if (!pendingChanges) {
|
|
1247
|
-
pendingChanges = /* @__PURE__ */ new Map();
|
|
1248
|
-
this.pendingChangesByScope.set(scopeId, pendingChanges);
|
|
1249
|
-
newlyPendingScopes.add(scopeId);
|
|
1250
|
-
}
|
|
1251
|
-
for (const change of scopeChanges) {
|
|
1252
|
-
const previous = pendingChanges.get(change.id);
|
|
1253
|
-
const mergedChange = mergeCompilationDependencyChanges(previous ? [previous] : void 0, [change])[0];
|
|
1254
|
-
if (!previous || previous.type !== mergedChange.type) {
|
|
1255
|
-
pendingChanges.set(change.id, mergedChange);
|
|
1256
|
-
invalidatedPaths.add(change.id);
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
}
|
|
1260
|
-
if (newlyPendingScopes.size > 0) this.compilationPool.recordAffectedScopes(newlyPendingScopes);
|
|
1261
|
-
if (invalidatedPaths.size > 0) this.generationPool.invalidate({
|
|
1262
|
-
type: "dependencies",
|
|
1263
|
-
paths: invalidatedPaths
|
|
1264
|
-
});
|
|
1265
|
-
return affectedScopes;
|
|
1266
|
-
}
|
|
1267
|
-
consume(scopeId) {
|
|
1268
|
-
this.ensureActive();
|
|
1269
|
-
const pendingChanges = this.pendingChangesByScope.get(scopeId);
|
|
1270
|
-
if (!pendingChanges) return;
|
|
1271
|
-
this.pendingChangesByScope.delete(scopeId);
|
|
1272
|
-
return [...pendingChanges.values()].map((change) => ({ ...change }));
|
|
1273
|
-
}
|
|
1274
|
-
invalidateScope(scopeId) {
|
|
1275
|
-
this.ensureActive();
|
|
1276
|
-
this.pendingChangesByScope.delete(scopeId);
|
|
1277
|
-
this.compilationPool.invalidateScope(scopeId);
|
|
1278
|
-
}
|
|
1279
|
-
getScopeDependencyRevision(scopeId) {
|
|
1280
|
-
this.ensureActive();
|
|
1281
|
-
return this.compilationPool.getScopeDependencyRevision(scopeId);
|
|
1282
|
-
}
|
|
1283
|
-
dispose() {
|
|
1284
|
-
this.pendingChangesByScope.clear();
|
|
1285
|
-
this.disposed = true;
|
|
1286
|
-
}
|
|
1287
|
-
ensureActive() {
|
|
1288
|
-
if (this.disposed) throw new Error("CompilationChangeCoordinator 已释放。");
|
|
1289
|
-
}
|
|
1290
|
-
};
|
|
1291
|
-
const compilationChangeCoordinators = /* @__PURE__ */ new WeakMap();
|
|
1292
|
-
function getCompilationChangeCoordinator(owner) {
|
|
1293
|
-
ensureCompilerOwnerActive(owner);
|
|
1294
|
-
let coordinator = compilationChangeCoordinators.get(owner);
|
|
1295
|
-
if (!coordinator) {
|
|
1296
|
-
coordinator = new CompilationChangeCoordinator(getCompilationSessionPool(owner), getTailwindGenerationSessionPool(owner));
|
|
1297
|
-
compilationChangeCoordinators.set(owner, coordinator);
|
|
1298
|
-
}
|
|
1299
|
-
return coordinator;
|
|
1300
|
-
}
|
|
1301
|
-
function recordCompilationDependencyChanges(owner, changes) {
|
|
1302
|
-
return getCompilationChangeCoordinator(owner).record(changes);
|
|
1303
|
-
}
|
|
1304
|
-
function consumeCompilationScopeChanges(owner, scopeId) {
|
|
1305
|
-
return getCompilationChangeCoordinator(owner).consume(scopeId);
|
|
1306
|
-
}
|
|
1307
|
-
function getCompilationScopeDependencyRevision(owner, scopeId) {
|
|
1308
|
-
return getCompilationChangeCoordinator(owner).getScopeDependencyRevision(scopeId);
|
|
1309
|
-
}
|
|
1310
|
-
function invalidateCompilationScope(owner, scopeId) {
|
|
1311
|
-
getCompilationChangeCoordinator(owner).invalidateScope(scopeId);
|
|
1312
|
-
}
|
|
1313
|
-
function disposeCompilationChangeCoordinator(owner) {
|
|
1314
|
-
const coordinator = compilationChangeCoordinators.get(owner);
|
|
1315
|
-
if (!coordinator) return;
|
|
1316
|
-
compilationChangeCoordinators.delete(owner);
|
|
1317
|
-
coordinator.dispose();
|
|
1318
|
-
}
|
|
1319
|
-
//#endregion
|
|
1320
|
-
//#region src/compiler/composition.ts
|
|
1321
|
-
function orderCssFragments(fragments) {
|
|
1322
|
-
return [...fragments].sort((left, right) => left.order - right.order || left.id.localeCompare(right.id));
|
|
1323
|
-
}
|
|
1324
|
-
function composeGenerationArtifact(artifact) {
|
|
1325
|
-
const cloned = cloneGenerationArtifact(artifact);
|
|
1326
|
-
const root = postcss.root();
|
|
1327
|
-
for (const fragment of orderCssFragments(cloned.fragments)) root.append(fragment.root.nodes.map((node) => node.clone()));
|
|
1328
|
-
return {
|
|
1329
|
-
artifact: cloned,
|
|
1330
|
-
root,
|
|
1331
|
-
css: root.toString()
|
|
1332
|
-
};
|
|
1333
|
-
}
|
|
1334
|
-
//#endregion
|
|
1335
|
-
//#region src/compiler/emission-plan.ts
|
|
1336
|
-
var AssetEmissionPlan = class {
|
|
1337
|
-
constructor() {
|
|
1338
|
-
_defineProperty(this, "emissions", /* @__PURE__ */ new Map());
|
|
1339
|
-
_defineProperty(this, "assetOperations", []);
|
|
1340
|
-
}
|
|
1341
|
-
upsert(assetId, artifact) {
|
|
1342
|
-
this.emissions.set(assetId, cloneGenerationArtifact(artifact));
|
|
1343
|
-
}
|
|
1344
|
-
get(assetId) {
|
|
1345
|
-
const artifact = this.emissions.get(assetId);
|
|
1346
|
-
return artifact ? cloneGenerationArtifact(artifact) : void 0;
|
|
1347
|
-
}
|
|
1348
|
-
entries() {
|
|
1349
|
-
return [...this.emissions].map(([assetId, artifact]) => ({
|
|
1350
|
-
assetId,
|
|
1351
|
-
artifact: cloneGenerationArtifact(artifact)
|
|
1352
|
-
}));
|
|
1353
|
-
}
|
|
1354
|
-
write(assetId, source) {
|
|
1355
|
-
this.assetOperations.push({
|
|
1356
|
-
assetId,
|
|
1357
|
-
kind: "write",
|
|
1358
|
-
source
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
remove(assetId) {
|
|
1362
|
-
this.assetOperations.push({
|
|
1363
|
-
assetId,
|
|
1364
|
-
kind: "delete"
|
|
1365
|
-
});
|
|
1366
|
-
}
|
|
1367
|
-
operations() {
|
|
1368
|
-
return this.assetOperations.map((operation) => ({ ...operation }));
|
|
1369
|
-
}
|
|
1370
|
-
clear() {
|
|
1371
|
-
this.emissions.clear();
|
|
1372
|
-
this.assetOperations.length = 0;
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
//#endregion
|
|
1376
|
-
//#region src/compiler/framework-compiler-session.ts
|
|
1377
|
-
/**
|
|
1378
|
-
* 官方 bundler 共享的 compiler 生命周期边界。
|
|
1379
|
-
*
|
|
1380
|
-
* bundler 继续拥有模块图和 scope 投影;本层只负责把逻辑 source root
|
|
1381
|
-
* 映射到一个长期复用的 compiler,并保证 root 删除与 owner 释放可等待。
|
|
1382
|
-
*/
|
|
1383
|
-
var FrameworkCompilerSession = class {
|
|
1384
|
-
constructor(options) {
|
|
1385
|
-
_defineProperty(this, "compiler", void 0);
|
|
1386
|
-
_defineProperty(this, "scopeRoots", /* @__PURE__ */ new Map());
|
|
1387
|
-
_defineProperty(this, "activeRoots", /* @__PURE__ */ new Set());
|
|
1388
|
-
_defineProperty(this, "transactionId", 0);
|
|
1389
|
-
_defineProperty(this, "disposed", false);
|
|
1390
|
-
this.compiler = createCompiler(options);
|
|
1391
|
-
}
|
|
1392
|
-
rootId(scopeId, sourceId) {
|
|
1393
|
-
return `framework:${this.encode(scopeId)}:${this.encode(sourceId)}`;
|
|
1394
|
-
}
|
|
1395
|
-
async generate(scopeId, sourceId, source, request) {
|
|
1396
|
-
if (this.disposed) throw new Error("FrameworkCompilerSession 已释放。");
|
|
1397
|
-
const stableId = this.rootId(scopeId, sourceId);
|
|
1398
|
-
const id = this.activeRoots.has(stableId) ? `${stableId}:transaction-${++this.transactionId}` : stableId;
|
|
1399
|
-
let roots = this.scopeRoots.get(scopeId);
|
|
1400
|
-
if (!roots) {
|
|
1401
|
-
roots = /* @__PURE__ */ new Set();
|
|
1402
|
-
this.scopeRoots.set(scopeId, roots);
|
|
1403
|
-
}
|
|
1404
|
-
roots.add(stableId);
|
|
1405
|
-
this.activeRoots.add(stableId);
|
|
1406
|
-
try {
|
|
1407
|
-
return await this.compiler.generate({
|
|
1408
|
-
...request,
|
|
1409
|
-
id,
|
|
1410
|
-
source: {
|
|
1411
|
-
...source,
|
|
1412
|
-
dependencies: source.dependencies ?? []
|
|
1413
|
-
}
|
|
1414
|
-
});
|
|
1415
|
-
} finally {
|
|
1416
|
-
this.activeRoots.delete(stableId);
|
|
1417
|
-
if (id !== stableId) await this.compiler.remove(id);
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
async syncScope(scopeId, sourceIds) {
|
|
1421
|
-
if (this.disposed) return;
|
|
1422
|
-
const roots = this.scopeRoots.get(scopeId);
|
|
1423
|
-
if (!roots) return;
|
|
1424
|
-
const active = new Set([...sourceIds].map((sourceId) => this.rootId(scopeId, sourceId)));
|
|
1425
|
-
const removed = [...roots].filter((rootId) => !active.has(rootId));
|
|
1426
|
-
await Promise.all(removed.map((rootId) => this.compiler.remove(rootId)));
|
|
1427
|
-
for (const rootId of removed) roots.delete(rootId);
|
|
1428
|
-
if (roots.size === 0) this.scopeRoots.delete(scopeId);
|
|
1429
|
-
}
|
|
1430
|
-
async removeScope(scopeId) {
|
|
1431
|
-
const roots = this.scopeRoots.get(scopeId);
|
|
1432
|
-
if (!roots) return;
|
|
1433
|
-
this.scopeRoots.delete(scopeId);
|
|
1434
|
-
await Promise.all([...roots].map((rootId) => this.compiler.remove(rootId)));
|
|
1435
|
-
}
|
|
1436
|
-
invalidate(ids) {
|
|
1437
|
-
return this.compiler.invalidate(ids);
|
|
1438
|
-
}
|
|
1439
|
-
mergeSnapshots(snapshots) {
|
|
1440
|
-
return this.compiler.mergeSnapshots(snapshots);
|
|
1441
|
-
}
|
|
1442
|
-
dispose() {
|
|
1443
|
-
if (this.disposed) return Promise.resolve();
|
|
1444
|
-
this.disposed = true;
|
|
1445
|
-
this.scopeRoots.clear();
|
|
1446
|
-
return this.compiler.dispose();
|
|
1447
|
-
}
|
|
1448
|
-
encode(value) {
|
|
1449
|
-
return Buffer.from(value, "utf8").toString("base64url");
|
|
1450
|
-
}
|
|
1451
|
-
};
|
|
1452
|
-
const frameworkCompilerSessions = /* @__PURE__ */ new WeakMap();
|
|
1453
|
-
function getFrameworkCompilerSession(owner, options) {
|
|
1454
|
-
let session = frameworkCompilerSessions.get(owner);
|
|
1455
|
-
if (!session) {
|
|
1456
|
-
session = new FrameworkCompilerSession(options);
|
|
1457
|
-
frameworkCompilerSessions.set(owner, session);
|
|
1458
|
-
}
|
|
1459
|
-
return session;
|
|
1460
|
-
}
|
|
1461
|
-
function disposeFrameworkCompilerSession(owner) {
|
|
1462
|
-
const session = frameworkCompilerSessions.get(owner);
|
|
1463
|
-
if (!session) return Promise.resolve();
|
|
1464
|
-
frameworkCompilerSessions.delete(owner);
|
|
1465
|
-
return session.dispose();
|
|
1466
|
-
}
|
|
1467
|
-
//#endregion
|
|
1468
741
|
//#region src/compiler/mode.ts
|
|
1469
742
|
const COMPILER_MODE_ENV = "WEAPP_TAILWINDCSS_COMPILER";
|
|
1470
743
|
function resolveCompilerMode(env = process.env) {
|
|
@@ -1472,414 +745,6 @@ function resolveCompilerMode(env = process.env) {
|
|
|
1472
745
|
return value === "legacy" || value === "shadow" || value === "graph" ? value : "graph";
|
|
1473
746
|
}
|
|
1474
747
|
//#endregion
|
|
1475
|
-
//#region src/compiler/shadow-report-session.ts
|
|
1476
|
-
const COMPILER_SHADOW_REPORT_CACHE_MAX = 512;
|
|
1477
|
-
function cloneSemanticValue(value) {
|
|
1478
|
-
if (Array.isArray(value)) return value.map(cloneSemanticValue);
|
|
1479
|
-
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, cloneSemanticValue(entry)]));
|
|
1480
|
-
return value;
|
|
1481
|
-
}
|
|
1482
|
-
function cloneCompilerShadowReport(report) {
|
|
1483
|
-
return {
|
|
1484
|
-
file: report.file,
|
|
1485
|
-
scopeId: report.scopeId,
|
|
1486
|
-
equal: report.equal,
|
|
1487
|
-
differences: report.differences.map((difference) => ({
|
|
1488
|
-
kind: difference.kind,
|
|
1489
|
-
path: difference.path,
|
|
1490
|
-
..."left" in difference ? { left: cloneSemanticValue(difference.left) } : {},
|
|
1491
|
-
..."right" in difference ? { right: cloneSemanticValue(difference.right) } : {}
|
|
1492
|
-
})),
|
|
1493
|
-
truncated: report.truncated,
|
|
1494
|
-
legacy: { ...report.legacy },
|
|
1495
|
-
graph: { ...report.graph }
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
var CompilerShadowReportSession = class {
|
|
1499
|
-
constructor(maxReports = COMPILER_SHADOW_REPORT_CACHE_MAX) {
|
|
1500
|
-
this.maxReports = maxReports;
|
|
1501
|
-
_defineProperty(this, "reportsByScope", /* @__PURE__ */ new Map());
|
|
1502
|
-
_defineProperty(this, "revision", 0);
|
|
1503
|
-
_defineProperty(this, "dropped", 0);
|
|
1504
|
-
_defineProperty(this, "completed", false);
|
|
1505
|
-
_defineProperty(this, "disposed", false);
|
|
1506
|
-
if (!Number.isInteger(maxReports) || maxReports <= 0) throw new Error("CompilerShadowReportSession 的 maxReports 必须是正整数。");
|
|
1507
|
-
}
|
|
1508
|
-
beginRun() {
|
|
1509
|
-
this.ensureActive();
|
|
1510
|
-
this.revision += 1;
|
|
1511
|
-
this.reportsByScope.clear();
|
|
1512
|
-
this.dropped = 0;
|
|
1513
|
-
this.completed = false;
|
|
1514
|
-
return this.revision;
|
|
1515
|
-
}
|
|
1516
|
-
record(report, revision = this.revision) {
|
|
1517
|
-
this.ensureActive();
|
|
1518
|
-
if (revision !== this.revision || this.completed) return false;
|
|
1519
|
-
const cloned = cloneCompilerShadowReport(report);
|
|
1520
|
-
this.reportsByScope.delete(cloned.scopeId);
|
|
1521
|
-
this.reportsByScope.set(cloned.scopeId, cloned);
|
|
1522
|
-
while (this.reportsByScope.size > this.maxReports) {
|
|
1523
|
-
const oldestScopeId = this.reportsByScope.keys().next().value;
|
|
1524
|
-
if (oldestScopeId === void 0) break;
|
|
1525
|
-
this.reportsByScope.delete(oldestScopeId);
|
|
1526
|
-
this.dropped += 1;
|
|
1527
|
-
}
|
|
1528
|
-
return true;
|
|
1529
|
-
}
|
|
1530
|
-
getRevision() {
|
|
1531
|
-
this.ensureActive();
|
|
1532
|
-
return this.revision;
|
|
1533
|
-
}
|
|
1534
|
-
completeRun(revision = this.revision) {
|
|
1535
|
-
this.ensureActive();
|
|
1536
|
-
if (revision !== this.revision) return;
|
|
1537
|
-
this.completed = true;
|
|
1538
|
-
return this.snapshot();
|
|
1539
|
-
}
|
|
1540
|
-
snapshot() {
|
|
1541
|
-
this.ensureActive();
|
|
1542
|
-
const reports = [...this.reportsByScope.values()].sort((left, right) => left.scopeId.localeCompare(right.scopeId)).map(cloneCompilerShadowReport);
|
|
1543
|
-
return {
|
|
1544
|
-
revision: this.revision,
|
|
1545
|
-
completed: this.completed,
|
|
1546
|
-
reports,
|
|
1547
|
-
summary: {
|
|
1548
|
-
total: reports.length,
|
|
1549
|
-
matched: reports.filter((report) => report.equal).length,
|
|
1550
|
-
mismatched: reports.filter((report) => !report.equal).length,
|
|
1551
|
-
truncated: reports.filter((report) => report.truncated).length,
|
|
1552
|
-
dropped: this.dropped
|
|
1553
|
-
}
|
|
1554
|
-
};
|
|
1555
|
-
}
|
|
1556
|
-
dispose() {
|
|
1557
|
-
this.reportsByScope.clear();
|
|
1558
|
-
this.dropped = 0;
|
|
1559
|
-
this.completed = true;
|
|
1560
|
-
this.disposed = true;
|
|
1561
|
-
}
|
|
1562
|
-
ensureActive() {
|
|
1563
|
-
if (this.disposed) throw new Error("CompilerShadowReportSession 已释放。");
|
|
1564
|
-
}
|
|
1565
|
-
};
|
|
1566
|
-
const compilerShadowReportSessions = /* @__PURE__ */ new WeakMap();
|
|
1567
|
-
function getCompilerShadowReportSession(owner) {
|
|
1568
|
-
ensureCompilerOwnerActive(owner);
|
|
1569
|
-
let session = compilerShadowReportSessions.get(owner);
|
|
1570
|
-
if (!session) {
|
|
1571
|
-
session = new CompilerShadowReportSession();
|
|
1572
|
-
compilerShadowReportSessions.set(owner, session);
|
|
1573
|
-
}
|
|
1574
|
-
return session;
|
|
1575
|
-
}
|
|
1576
|
-
function beginCompilerShadowRun(owner) {
|
|
1577
|
-
return getCompilerShadowReportSession(owner).beginRun();
|
|
1578
|
-
}
|
|
1579
|
-
function getCompilerShadowRunRevision(owner) {
|
|
1580
|
-
return getCompilerShadowReportSession(owner).getRevision();
|
|
1581
|
-
}
|
|
1582
|
-
function recordCompilerShadowReport(owner, report, revision) {
|
|
1583
|
-
return getCompilerShadowReportSession(owner).record(report, revision);
|
|
1584
|
-
}
|
|
1585
|
-
function getCompilerShadowRunSnapshot(owner) {
|
|
1586
|
-
return getCompilerShadowReportSession(owner).snapshot();
|
|
1587
|
-
}
|
|
1588
|
-
function completeCompilerShadowReportRun(owner, revision) {
|
|
1589
|
-
return getCompilerShadowReportSession(owner).completeRun(revision);
|
|
1590
|
-
}
|
|
1591
|
-
function disposeCompilerShadowReportSession(owner) {
|
|
1592
|
-
const session = compilerShadowReportSessions.get(owner);
|
|
1593
|
-
if (!session) return;
|
|
1594
|
-
compilerShadowReportSessions.delete(owner);
|
|
1595
|
-
session.dispose();
|
|
1596
|
-
}
|
|
1597
|
-
//#endregion
|
|
1598
|
-
//#region src/compiler/owner-lifecycle.ts
|
|
1599
|
-
async function disposeCompilerOwnerResources(owner) {
|
|
1600
|
-
disposeCompilationChangeCoordinator(owner);
|
|
1601
|
-
await disposeCompilationSessionPool(owner);
|
|
1602
|
-
await disposeFrameworkCompilerSession(owner);
|
|
1603
|
-
disposeTailwindGenerationSessionPool(owner);
|
|
1604
|
-
disposeCompilerShadowReportSession(owner);
|
|
1605
|
-
}
|
|
1606
|
-
function disposeCompilerOwner(owner) {
|
|
1607
|
-
return runCompilerOwnerDisposal(owner, () => disposeCompilerOwnerResources(owner));
|
|
1608
|
-
}
|
|
1609
|
-
//#endregion
|
|
1610
|
-
//#region src/compiler/platform-adapter.ts
|
|
1611
|
-
function createStylePlatformAdapter(options) {
|
|
1612
|
-
return {
|
|
1613
|
-
id: options.id,
|
|
1614
|
-
prepare(request) {
|
|
1615
|
-
return {
|
|
1616
|
-
...request,
|
|
1617
|
-
candidates: new Set(request.candidates),
|
|
1618
|
-
scope: { ...request.scope }
|
|
1619
|
-
};
|
|
1620
|
-
},
|
|
1621
|
-
async transform(artifact, context) {
|
|
1622
|
-
const transformed = cloneGenerationArtifact(artifact);
|
|
1623
|
-
for (const fragment of transformed.fragments) {
|
|
1624
|
-
fragment.root = (await options.styleHandler.transformRoot(fragment.root, options.styleOptions)).root.clone();
|
|
1625
|
-
fragment.stage = context.stage;
|
|
1626
|
-
}
|
|
1627
|
-
return transformed;
|
|
1628
|
-
}
|
|
1629
|
-
};
|
|
1630
|
-
}
|
|
1631
|
-
//#endregion
|
|
1632
|
-
//#region src/compiler/runtime-affecting-signature.ts
|
|
1633
|
-
const CSS_BLOCK_COMMENT_RE = /\/\*[\s\S]*?\*\//g;
|
|
1634
|
-
const CSS_AROUND_PUNCTUATION_RE = /\s*([{}:;,>+~()])\s*/g;
|
|
1635
|
-
const CSS_TRAILING_DECLARATION_SEMICOLON_RE = /;\}/g;
|
|
1636
|
-
const CSS_WHITESPACE_RE = /\s+/g;
|
|
1637
|
-
const JS_RUNTIME_AFFECTING_TEXT_HINT_RE = /["'`/]/;
|
|
1638
|
-
const JS_INCOMPLETE_TRAILING_OPERATOR_RE = /(?:=>|[=+\-*%&|^!~?:,.({[\]])\s*$/;
|
|
1639
|
-
const JS_AST_IGNORED_KEYS = /* @__PURE__ */ new Set([
|
|
1640
|
-
"comments",
|
|
1641
|
-
"errors",
|
|
1642
|
-
"extra",
|
|
1643
|
-
"innerComments",
|
|
1644
|
-
"leadingComments",
|
|
1645
|
-
"loc",
|
|
1646
|
-
"tokens",
|
|
1647
|
-
"trailingComments"
|
|
1648
|
-
]);
|
|
1649
|
-
function isAstNode(value) {
|
|
1650
|
-
return Boolean(value && typeof value === "object" && typeof value.type === "string");
|
|
1651
|
-
}
|
|
1652
|
-
function createHtmlRuntimeAffectingSignature(source) {
|
|
1653
|
-
try {
|
|
1654
|
-
const parts = [];
|
|
1655
|
-
const parser = new Parser({
|
|
1656
|
-
onattribute(name, value) {
|
|
1657
|
-
parts.push(`a:${name}=${value}`);
|
|
1658
|
-
},
|
|
1659
|
-
oncomment(data) {
|
|
1660
|
-
parts.push(`c:${data}`);
|
|
1661
|
-
},
|
|
1662
|
-
ontext(data) {
|
|
1663
|
-
const value = data.trim();
|
|
1664
|
-
if (value.length > 0) parts.push(`t:${value}`);
|
|
1665
|
-
}
|
|
1666
|
-
}, { xmlMode: true });
|
|
1667
|
-
parser.write(source);
|
|
1668
|
-
parser.end();
|
|
1669
|
-
return parts.join("\n");
|
|
1670
|
-
} catch {
|
|
1671
|
-
return source;
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
function createJsRuntimeAffectingSignature(source) {
|
|
1675
|
-
if (!JS_RUNTIME_AFFECTING_TEXT_HINT_RE.test(source) && !JS_INCOMPLETE_TRAILING_OPERATOR_RE.test(source)) return "";
|
|
1676
|
-
try {
|
|
1677
|
-
const ast = babelParse(source, {
|
|
1678
|
-
cache: true,
|
|
1679
|
-
cacheKey: "st:unambiguous",
|
|
1680
|
-
plugins: ["jsx", "typescript"],
|
|
1681
|
-
sourceType: "unambiguous"
|
|
1682
|
-
});
|
|
1683
|
-
const parts = [];
|
|
1684
|
-
const stack = [ast];
|
|
1685
|
-
while (stack.length > 0) {
|
|
1686
|
-
const node = stack.pop();
|
|
1687
|
-
if (node.type === "StringLiteral" && typeof node.value === "string") parts.push(`s:${node.value}`);
|
|
1688
|
-
else if (node.type === "TemplateElement" && node.value && typeof node.value === "object" && "raw" in node.value && typeof node.value.raw === "string") parts.push(`t:${node.value.raw}`);
|
|
1689
|
-
else if (node.type === "JSXText" && typeof node.value === "string") {
|
|
1690
|
-
const value = node.value.trim();
|
|
1691
|
-
if (value.length > 0) parts.push(`x:${value}`);
|
|
1692
|
-
}
|
|
1693
|
-
const children = [];
|
|
1694
|
-
for (const [key, value] of Object.entries(node)) {
|
|
1695
|
-
if (JS_AST_IGNORED_KEYS.has(key)) continue;
|
|
1696
|
-
if (Array.isArray(value)) {
|
|
1697
|
-
for (const item of value) if (isAstNode(item)) children.push(item);
|
|
1698
|
-
} else if (isAstNode(value)) children.push(value);
|
|
1699
|
-
}
|
|
1700
|
-
for (let index = children.length - 1; index >= 0; index--) stack.push(children[index]);
|
|
1701
|
-
}
|
|
1702
|
-
const comments = ast.comments;
|
|
1703
|
-
if (Array.isArray(comments)) {
|
|
1704
|
-
for (const comment of comments) if (typeof comment?.value === "string" && comment.value.length > 0) parts.push(`c:${comment.value}`);
|
|
1705
|
-
}
|
|
1706
|
-
return parts.join("\n");
|
|
1707
|
-
} catch {
|
|
1708
|
-
return source;
|
|
1709
|
-
}
|
|
1710
|
-
}
|
|
1711
|
-
function createCssRuntimeAffectingSignature(source) {
|
|
1712
|
-
return source.replace(CSS_BLOCK_COMMENT_RE, "").replace(CSS_AROUND_PUNCTUATION_RE, "$1").replace(CSS_TRAILING_DECLARATION_SEMICOLON_RE, "}").replace(CSS_WHITESPACE_RE, " ").trim();
|
|
1713
|
-
}
|
|
1714
|
-
function createRuntimeAffectingSourceSignature(source, type) {
|
|
1715
|
-
if (type === "html") return createHtmlRuntimeAffectingSignature(source);
|
|
1716
|
-
if (type === "js") return createJsRuntimeAffectingSignature(source);
|
|
1717
|
-
if (type === "css") return createCssRuntimeAffectingSignature(source);
|
|
1718
|
-
return source;
|
|
1719
|
-
}
|
|
1720
|
-
//#endregion
|
|
1721
|
-
//#region src/compiler/runtime-build-state.ts
|
|
1722
|
-
function invertLinkedByEntry(linkedByEntry) {
|
|
1723
|
-
const dependentsByLinkedFile = /* @__PURE__ */ new Map();
|
|
1724
|
-
for (const [entryFile, linkedFiles] of linkedByEntry.entries()) for (const linkedFile of linkedFiles) {
|
|
1725
|
-
let dependents = dependentsByLinkedFile.get(linkedFile);
|
|
1726
|
-
if (!dependents) {
|
|
1727
|
-
dependents = /* @__PURE__ */ new Set();
|
|
1728
|
-
dependentsByLinkedFile.set(linkedFile, dependents);
|
|
1729
|
-
}
|
|
1730
|
-
dependents.add(entryFile);
|
|
1731
|
-
}
|
|
1732
|
-
return dependentsByLinkedFile;
|
|
1733
|
-
}
|
|
1734
|
-
function replaceMapEntries(target, source) {
|
|
1735
|
-
target.clear();
|
|
1736
|
-
for (const [key, value] of source) target.set(key, value);
|
|
1737
|
-
return target;
|
|
1738
|
-
}
|
|
1739
|
-
function mergeMapEntries(target, source) {
|
|
1740
|
-
for (const [key, value] of source) target.set(key, value);
|
|
1741
|
-
return target;
|
|
1742
|
-
}
|
|
1743
|
-
function createRuntimeCompilationBuildState() {
|
|
1744
|
-
return {
|
|
1745
|
-
iteration: 0,
|
|
1746
|
-
sourceHashByFile: /* @__PURE__ */ new Map(),
|
|
1747
|
-
runtimeAffectingSignatureByFile: /* @__PURE__ */ new Map(),
|
|
1748
|
-
runtimeAffectingHashByFile: /* @__PURE__ */ new Map(),
|
|
1749
|
-
linkedByEntry: /* @__PURE__ */ new Map(),
|
|
1750
|
-
dependentsByLinkedFile: /* @__PURE__ */ new Map(),
|
|
1751
|
-
bundleMarkupCandidatesByFile: /* @__PURE__ */ new Map(),
|
|
1752
|
-
generatorCandidateSignature: void 0
|
|
1753
|
-
};
|
|
1754
|
-
}
|
|
1755
|
-
function updateRuntimeCompilationBuildState(state, snapshot, linkedByEntry, options = {}) {
|
|
1756
|
-
const incremental = options.incremental === true;
|
|
1757
|
-
removeRuntimeCompilationBuildStateFiles(state, snapshot.removedFiles);
|
|
1758
|
-
state.iteration += 1;
|
|
1759
|
-
state.sourceHashByFile = incremental ? mergeMapEntries(state.sourceHashByFile, snapshot.sourceHashByFile) : replaceMapEntries(state.sourceHashByFile, snapshot.sourceHashByFile);
|
|
1760
|
-
state.runtimeAffectingSignatureByFile.clear();
|
|
1761
|
-
state.runtimeAffectingHashByFile = incremental ? mergeMapEntries(state.runtimeAffectingHashByFile, snapshot.runtimeAffectingHashByFile) : replaceMapEntries(state.runtimeAffectingHashByFile, snapshot.runtimeAffectingHashByFile);
|
|
1762
|
-
state.linkedByEntry = incremental ? mergeMapEntries(state.linkedByEntry, linkedByEntry) : replaceMapEntries(state.linkedByEntry, linkedByEntry);
|
|
1763
|
-
state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
|
|
1764
|
-
}
|
|
1765
|
-
function removeRuntimeCompilationBuildStateFiles(state, files) {
|
|
1766
|
-
const removedFiles = new Set(files);
|
|
1767
|
-
if (removedFiles.size === 0) return;
|
|
1768
|
-
for (const file of removedFiles) {
|
|
1769
|
-
state.sourceHashByFile.delete(file);
|
|
1770
|
-
state.runtimeAffectingSignatureByFile.delete(file);
|
|
1771
|
-
state.runtimeAffectingHashByFile.delete(file);
|
|
1772
|
-
state.bundleMarkupCandidatesByFile.delete(file);
|
|
1773
|
-
state.linkedByEntry.delete(file);
|
|
1774
|
-
}
|
|
1775
|
-
for (const linkedFiles of state.linkedByEntry.values()) for (const file of removedFiles) linkedFiles.delete(file);
|
|
1776
|
-
state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
|
|
1777
|
-
}
|
|
1778
|
-
function resetRuntimeCompilationBuildState(state) {
|
|
1779
|
-
state.iteration = 0;
|
|
1780
|
-
state.sourceHashByFile.clear();
|
|
1781
|
-
state.runtimeAffectingSignatureByFile.clear();
|
|
1782
|
-
state.runtimeAffectingHashByFile.clear();
|
|
1783
|
-
state.linkedByEntry.clear();
|
|
1784
|
-
state.dependentsByLinkedFile.clear();
|
|
1785
|
-
state.bundleMarkupCandidatesByFile.clear();
|
|
1786
|
-
state.generatorCandidateSignature = void 0;
|
|
1787
|
-
}
|
|
1788
|
-
function createRuntimeCompilationAffectingSignature(snapshot, computeHash) {
|
|
1789
|
-
const entries = [...snapshot.runtimeAffectingHashByFile].sort(([first], [second]) => first.localeCompare(second)).map(([file, hash]) => `${file}:${hash}`);
|
|
1790
|
-
return entries.length === 0 ? "runtime-affecting:0" : `runtime-affecting:1:${computeHash(entries.join("\n"))}`;
|
|
1791
|
-
}
|
|
1792
|
-
//#endregion
|
|
1793
|
-
//#region src/compiler/runtime-snapshot.ts
|
|
1794
|
-
function createChangedByType() {
|
|
1795
|
-
return {
|
|
1796
|
-
html: /* @__PURE__ */ new Set(),
|
|
1797
|
-
js: /* @__PURE__ */ new Set(),
|
|
1798
|
-
css: /* @__PURE__ */ new Set(),
|
|
1799
|
-
other: /* @__PURE__ */ new Set()
|
|
1800
|
-
};
|
|
1801
|
-
}
|
|
1802
|
-
function createProcessFiles() {
|
|
1803
|
-
return {
|
|
1804
|
-
html: /* @__PURE__ */ new Set(),
|
|
1805
|
-
js: /* @__PURE__ */ new Set(),
|
|
1806
|
-
css: /* @__PURE__ */ new Set()
|
|
1807
|
-
};
|
|
1808
|
-
}
|
|
1809
|
-
function markProcessFile(type, file, processFiles) {
|
|
1810
|
-
if (type === "html" || type === "js" || type === "css") processFiles[type].add(file);
|
|
1811
|
-
}
|
|
1812
|
-
function markFilesByEntryType(files, entriesByFile, target) {
|
|
1813
|
-
for (const file of files ?? []) {
|
|
1814
|
-
const entry = entriesByFile.get(file);
|
|
1815
|
-
if (entry) target[entry.type].add(file);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
function createRuntimeCompilationSnapshot(entries, options = {}) {
|
|
1819
|
-
const changedByType = createChangedByType();
|
|
1820
|
-
const runtimeAffectingChangedByType = createChangedByType();
|
|
1821
|
-
const processFiles = createProcessFiles();
|
|
1822
|
-
const entriesByFile = new Map(entries.map((entry) => [entry.file, entry]));
|
|
1823
|
-
markFilesByEntryType(options.changedFiles, entriesByFile, changedByType);
|
|
1824
|
-
markFilesByEntryType(options.runtimeAffectingChangedFiles, entriesByFile, runtimeAffectingChangedByType);
|
|
1825
|
-
for (const file of options.processFiles ?? []) {
|
|
1826
|
-
const entry = entriesByFile.get(file);
|
|
1827
|
-
if (entry) markProcessFile(entry.type, file, processFiles);
|
|
1828
|
-
}
|
|
1829
|
-
return {
|
|
1830
|
-
entries,
|
|
1831
|
-
sourceHashByFile: /* @__PURE__ */ new Map(),
|
|
1832
|
-
runtimeAffectingSignatureByFile: /* @__PURE__ */ new Map(),
|
|
1833
|
-
runtimeAffectingHashByFile: /* @__PURE__ */ new Map(),
|
|
1834
|
-
hasOmittedKnownFiles: options.hasOmittedKnownFiles === true,
|
|
1835
|
-
removedFiles: new Set([...options.removedFiles ?? []].filter((file) => !entriesByFile.has(file))),
|
|
1836
|
-
changedByType,
|
|
1837
|
-
runtimeAffectingChangedByType,
|
|
1838
|
-
processFiles,
|
|
1839
|
-
linkedImpactsByEntry: /* @__PURE__ */ new Map()
|
|
1840
|
-
};
|
|
1841
|
-
}
|
|
1842
|
-
function buildRuntimeCompilationSnapshot(entries, state, options) {
|
|
1843
|
-
const snapshot = createRuntimeCompilationSnapshot(entries, {
|
|
1844
|
-
hasOmittedKnownFiles: options.hasOmittedKnownFiles,
|
|
1845
|
-
removedFiles: options.removedFiles
|
|
1846
|
-
});
|
|
1847
|
-
const firstRun = state.iteration === 0 && state.sourceHashByFile.size === 0;
|
|
1848
|
-
for (const entry of entries) {
|
|
1849
|
-
const { file, source, type } = entry;
|
|
1850
|
-
const hash = options.computeHash(source);
|
|
1851
|
-
snapshot.sourceHashByFile.set(file, hash);
|
|
1852
|
-
const previousHash = state.sourceHashByFile.get(file);
|
|
1853
|
-
const changed = previousHash == null || previousHash !== hash;
|
|
1854
|
-
const previousRuntimeAffectingHash = state.runtimeAffectingHashByFile.get(file);
|
|
1855
|
-
const runtimeAffectingHash = !changed && previousRuntimeAffectingHash != null ? previousRuntimeAffectingHash : (() => {
|
|
1856
|
-
const signature = options.createRuntimeAffectingSignature(source, type);
|
|
1857
|
-
snapshot.runtimeAffectingSignatureByFile.set(file, signature);
|
|
1858
|
-
return options.computeHash(signature);
|
|
1859
|
-
})();
|
|
1860
|
-
snapshot.runtimeAffectingHashByFile.set(file, runtimeAffectingHash);
|
|
1861
|
-
if (changed) snapshot.changedByType[type].add(file);
|
|
1862
|
-
if (previousRuntimeAffectingHash == null || previousRuntimeAffectingHash !== runtimeAffectingHash) snapshot.runtimeAffectingChangedByType[type].add(file);
|
|
1863
|
-
if (options.forceAll || firstRun) markProcessFile(type, file, snapshot.processFiles);
|
|
1864
|
-
else if (type === "html") snapshot.processFiles.html.add(file);
|
|
1865
|
-
else if (changed && (type === "js" || type === "css")) snapshot.processFiles[type].add(file);
|
|
1866
|
-
}
|
|
1867
|
-
if (!options.forceAll && !firstRun) for (const changedFile of snapshot.changedByType.js) {
|
|
1868
|
-
const dependents = state.dependentsByLinkedFile.get(changedFile);
|
|
1869
|
-
if (!dependents) continue;
|
|
1870
|
-
for (const entryFile of dependents) {
|
|
1871
|
-
snapshot.processFiles.js.add(entryFile);
|
|
1872
|
-
let impacts = snapshot.linkedImpactsByEntry.get(entryFile);
|
|
1873
|
-
if (!impacts) {
|
|
1874
|
-
impacts = /* @__PURE__ */ new Set();
|
|
1875
|
-
snapshot.linkedImpactsByEntry.set(entryFile, impacts);
|
|
1876
|
-
}
|
|
1877
|
-
impacts.add(changedFile);
|
|
1878
|
-
}
|
|
1879
|
-
}
|
|
1880
|
-
return snapshot;
|
|
1881
|
-
}
|
|
1882
|
-
//#endregion
|
|
1883
748
|
//#region src/compiler/semantic-css.ts
|
|
1884
749
|
const defaultMaxDifferences = 50;
|
|
1885
750
|
function isSemanticCssNode(node) {
|
|
@@ -2414,25 +1279,6 @@ function createRuntimeClassSetManager(options = {}) {
|
|
|
2414
1279
|
};
|
|
2415
1280
|
}
|
|
2416
1281
|
//#endregion
|
|
2417
|
-
//#region src/bundlers/shared/cache.ts
|
|
2418
|
-
async function processCachedTask({ cache, cacheKey, hashKey = cacheKey, rawSource, hash, readCache, applyResult, transform, onCacheHit }) {
|
|
2419
|
-
let cacheHit = false;
|
|
2420
|
-
const result = await cache.process({
|
|
2421
|
-
key: cacheKey,
|
|
2422
|
-
hashKey,
|
|
2423
|
-
rawSource,
|
|
2424
|
-
hash,
|
|
2425
|
-
resolveCache: readCache,
|
|
2426
|
-
async onCacheHit(value) {
|
|
2427
|
-
cacheHit = true;
|
|
2428
|
-
await applyResult(value, { cacheHit: true });
|
|
2429
|
-
onCacheHit?.();
|
|
2430
|
-
},
|
|
2431
|
-
transform
|
|
2432
|
-
});
|
|
2433
|
-
if (!cacheHit) await applyResult(result, { cacheHit: false });
|
|
2434
|
-
}
|
|
2435
|
-
//#endregion
|
|
2436
1282
|
//#region src/bundlers/shared/css-source-trace.ts
|
|
2437
1283
|
const CSS_SOURCE_TRACE_COMMENT_RE = /^\s*tokens:\s/;
|
|
2438
1284
|
const TAILWIND_GENERATED_CONTAINER_TRACE_COMMENT_RE = /^\s*tokens:\s*container\s*<=\s*<tailwind generated>\s*$/i;
|
|
@@ -2532,104 +1378,6 @@ function annotateCssSourceTrace(css, options) {
|
|
|
2532
1378
|
}
|
|
2533
1379
|
}
|
|
2534
1380
|
//#endregion
|
|
2535
|
-
//#region src/bundlers/shared/final-css-cleanup.ts
|
|
2536
|
-
function isAtRuleNameCharacter(code) {
|
|
2537
|
-
return code === 45 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
2538
|
-
}
|
|
2539
|
-
function isCssWhitespace(code) {
|
|
2540
|
-
return code === 9 || code === 10 || code === 12 || code === 13 || code === 32;
|
|
2541
|
-
}
|
|
2542
|
-
function findAtRuleBlockStart(css, start) {
|
|
2543
|
-
let parenthesisDepth = 0;
|
|
2544
|
-
let quote = 0;
|
|
2545
|
-
let squareBracketDepth = 0;
|
|
2546
|
-
for (let index = start; index < css.length; index++) {
|
|
2547
|
-
const code = css.charCodeAt(index);
|
|
2548
|
-
if (quote !== 0) {
|
|
2549
|
-
if (code === 92) index++;
|
|
2550
|
-
else if (code === quote) quote = 0;
|
|
2551
|
-
continue;
|
|
2552
|
-
}
|
|
2553
|
-
if (code === 34 || code === 39) {
|
|
2554
|
-
quote = code;
|
|
2555
|
-
continue;
|
|
2556
|
-
}
|
|
2557
|
-
if (code === 92) {
|
|
2558
|
-
index++;
|
|
2559
|
-
continue;
|
|
2560
|
-
}
|
|
2561
|
-
if (code === 47 && css.charCodeAt(index + 1) === 42) {
|
|
2562
|
-
const commentEnd = css.indexOf("*/", index + 2);
|
|
2563
|
-
if (commentEnd < 0) return -1;
|
|
2564
|
-
index = commentEnd + 1;
|
|
2565
|
-
continue;
|
|
2566
|
-
}
|
|
2567
|
-
if (code === 40) {
|
|
2568
|
-
parenthesisDepth++;
|
|
2569
|
-
continue;
|
|
2570
|
-
}
|
|
2571
|
-
if (code === 41 && parenthesisDepth > 0) {
|
|
2572
|
-
parenthesisDepth--;
|
|
2573
|
-
continue;
|
|
2574
|
-
}
|
|
2575
|
-
if (code === 91) {
|
|
2576
|
-
squareBracketDepth++;
|
|
2577
|
-
continue;
|
|
2578
|
-
}
|
|
2579
|
-
if (code === 93 && squareBracketDepth > 0) {
|
|
2580
|
-
squareBracketDepth--;
|
|
2581
|
-
continue;
|
|
2582
|
-
}
|
|
2583
|
-
if (code === 123 && parenthesisDepth === 0 && squareBracketDepth === 0) return index;
|
|
2584
|
-
if ((code === 59 || code === 125) && parenthesisDepth === 0 && squareBracketDepth === 0) return -1;
|
|
2585
|
-
}
|
|
2586
|
-
return -1;
|
|
2587
|
-
}
|
|
2588
|
-
function isEmptyAtRuleBody(css, blockStart) {
|
|
2589
|
-
for (let index = blockStart + 1; index < css.length; index++) {
|
|
2590
|
-
const code = css.charCodeAt(index);
|
|
2591
|
-
if (isCssWhitespace(code)) continue;
|
|
2592
|
-
if (code === 47 && css.charCodeAt(index + 1) === 42) {
|
|
2593
|
-
const commentEnd = css.indexOf("*/", index + 2);
|
|
2594
|
-
if (commentEnd < 0) return false;
|
|
2595
|
-
index = commentEnd + 1;
|
|
2596
|
-
continue;
|
|
2597
|
-
}
|
|
2598
|
-
return code === 125;
|
|
2599
|
-
}
|
|
2600
|
-
return false;
|
|
2601
|
-
}
|
|
2602
|
-
function hasEmptyAtRuleBlockCandidate(css) {
|
|
2603
|
-
let searchFrom = 0;
|
|
2604
|
-
while (searchFrom < css.length) {
|
|
2605
|
-
const atRuleStart = css.indexOf("@", searchFrom);
|
|
2606
|
-
if (atRuleStart < 0) return false;
|
|
2607
|
-
searchFrom = atRuleStart + 1;
|
|
2608
|
-
if (!isAtRuleNameCharacter(css.charCodeAt(searchFrom))) continue;
|
|
2609
|
-
const blockStart = findAtRuleBlockStart(css, searchFrom + 1);
|
|
2610
|
-
if (blockStart >= 0 && isEmptyAtRuleBody(css, blockStart)) return true;
|
|
2611
|
-
}
|
|
2612
|
-
return false;
|
|
2613
|
-
}
|
|
2614
|
-
/**
|
|
2615
|
-
* 在小程序样式进入最终产物图时递归清理空的块级 at-rule。
|
|
2616
|
-
*/
|
|
2617
|
-
function finalizeMiniProgramCssStructure(css) {
|
|
2618
|
-
if (!hasEmptyAtRuleBlockCandidate(css)) return css;
|
|
2619
|
-
try {
|
|
2620
|
-
const root = postcss.parse(css);
|
|
2621
|
-
let removed = 0;
|
|
2622
|
-
let passRemoved = 0;
|
|
2623
|
-
do {
|
|
2624
|
-
passRemoved = removeEmptyAtRules(root);
|
|
2625
|
-
removed += passRemoved;
|
|
2626
|
-
} while (passRemoved > 0);
|
|
2627
|
-
return removed > 0 ? root.toString() : css;
|
|
2628
|
-
} catch {
|
|
2629
|
-
return css;
|
|
2630
|
-
}
|
|
2631
|
-
}
|
|
2632
|
-
//#endregion
|
|
2633
1381
|
//#region src/bundlers/shared/generated-css-marker.ts
|
|
2634
1382
|
const BUNDLER_GENERATED_CSS_MARKER_RE = /\/\*!?\s*weapp-tailwindcss (?:gulp|vite|webpack)-generated-css(?:\s*:\s*[^\s*]+)?\s*\*\/\s*/i;
|
|
2635
1383
|
const BUNDLER_GENERATED_CSS_MARKER_GLOBAL_RE = /\/\*!?\s*weapp-tailwindcss (?:gulp|vite|webpack)-generated-css(?:\s*:\s*[^\s*]+)?\s*\*\/\s*/gi;
|
|
@@ -5836,7 +4584,7 @@ async function generateTailwindV4CssWithImplementation(options, implementation)
|
|
|
5836
4584
|
};
|
|
5837
4585
|
}
|
|
5838
4586
|
async function generateTailwindV4Css(options) {
|
|
5839
|
-
const mode = resolveCompilerMode();
|
|
4587
|
+
const mode = options.compilerMode ?? resolveCompilerMode();
|
|
5840
4588
|
const generationOptions = resolveGenerationOptions(options, mode);
|
|
5841
4589
|
if (mode === "legacy") return generateTailwindV4CssWithImplementation(generationOptions, {
|
|
5842
4590
|
emitArtifact: false,
|
|
@@ -5943,4 +4691,4 @@ function createHmrTimingRecorder(bundler) {
|
|
|
5943
4691
|
};
|
|
5944
4692
|
}
|
|
5945
4693
|
//#endregion
|
|
5946
|
-
export {
|
|
4694
|
+
export { createCssSourceTraceCacheSignature as A, createSourceCandidateCollector as B, isSourceStyleRequest as C, parseBundlerGeneratedCssMarkerBlocks as D, hasBundlerGeneratedCssMarker as E, createEscapeFragments as F, resolveSourceCandidateScanFiles as G, isSourceCandidateRequest as H, isPureLocalCssImportWrapper as I, rewriteLocalCssImportRequestsForOutput as L, isCssSourceTraceEnabled as M, createRuntimeClassSetManager as N, stripBundlerGeneratedCssMarkers as O, collectStrictEscapedRuntimeCandidates as P, splitLocalCssImports as R, isSourcePreprocessorRequest as S, createBundlerGeneratedCssMarker as T, extractCandidatesFromSource as U, createSourceCandidateStore as V, createSourceCandidateEligibilityMatcher as W, captureResolvedFrameworkPostcssOptions as _, extractMarkedUserLayerComponentsCss as a, finalizeMiniProgramGeneratorCss as b, collectRawSourceClassSelectors as c, runWithConcurrency as d, normalizeMiniProgramGeneratorCssSource as f, captureFrameworkPostcssOptions as g, removeGeneratedSelectorCompatCss as h, validateCandidatesByGenerator as i, createCssTokenSourceMap as j, annotateCssSourceTrace as k, pushConcurrentTaskFactories as l, scoreTailwindV4CssSourceFileMatch as m, emitHmrTiming as n, mergeMarkedUserLayerComponentsCss as o, normalizeMiniProgramImportShell as p, generateTailwindV4Css as r, collectGeneratedRawSourceCandidatesFromCss as s, createHmrTimingRecorder as t, resolveTaskConcurrency as u, collectFrameworkPostcssOptionsFromLoaderEntries as v, stripRequestQuery as w, hasMiniProgramTailwindV4PreflightReset as x, createCssSourceOrderAppend as y, finalizeCompilerShadowRun as z };
|