weapp-tailwindcss 5.5.3 → 5.5.5
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/compiler/cache-telemetry.d.ts +30 -0
- package/dist/compiler/candidate-index.d.ts +3 -0
- package/dist/compiler/capabilities.d.ts +37 -0
- package/dist/compiler/events.d.ts +38 -1
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/runtime-state.d.ts +2 -1
- package/dist/{compiler-DMPaUcH6.cjs → compiler-Cc0JXfbw.cjs} +40096 -16978
- package/dist/{compiler-C9X5Afn4.js → compiler-D_vxtEdw.js} +70 -22
- package/dist/core/compiler/types.d.ts +2 -0
- package/dist/core.cjs +57 -8
- package/dist/core.d.ts +3 -0
- package/dist/core.js +56 -7
- package/dist/{css-imports-DXplvodk.cjs → css-imports-FRZwX4P6.cjs} +1 -1
- package/dist/{generator-BoZIiZD5.cjs → generator-BdSIvFEO.cjs} +86 -56
- package/dist/{generator-C2aWns8n.js → generator-CAOx1Sqm.js} +86 -56
- package/dist/generator.cjs +1 -1
- package/dist/generator.js +1 -1
- package/dist/{gulp-COAAztkm.js → gulp-B1mPTMqw.js} +14 -4
- package/dist/{gulp-D50z06nw.cjs → gulp-Dnt8VL8D.cjs} +16 -6
- package/dist/gulp.cjs +1 -1
- package/dist/gulp.js +1 -1
- package/dist/{hmr-timing-DK0MJKpl.cjs → hmr-timing-qpX410qU.cjs} +4 -4
- package/dist/{hmr-timing-CTk1uZr9.js → hmr-timing-wAt0LavM.js} +3 -3
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/dist/{pipeline-helpers-BzjYXNTa.cjs → pipeline-helpers-BHagysZY.cjs} +3 -3
- package/dist/postcss.cjs +1 -1
- package/dist/postcss.js +1 -1
- package/dist/presets.cjs +2 -2
- package/dist/presets.js +2 -2
- package/dist/rspack.cjs +2 -2
- package/dist/rspack.js +2 -2
- package/dist/{runtime-state-BBQcA0n5.cjs → runtime-state-XYSycuGu.cjs} +6 -0
- package/dist/{scoped-generator-C21A7fis.js → scoped-generator-BqxVxNp9.js} +3 -3
- package/dist/{scoped-generator-CTkuf9Ae.cjs → scoped-generator-CtetE5rm.cjs} +3 -3
- package/dist/{source-candidate-scan-signature-4mZDDaKT.cjs → source-candidate-scan-signature-BDGB9nKZ.cjs} +2 -2
- package/dist/{source-candidate-scan-signature-BB5DfjO2.js → source-candidate-scan-signature-Lm32zKVA.js} +2 -2
- package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/generator/style-context.d.ts +6 -0
- package/dist/{tailwindcss-Bji4u8In.cjs → tailwindcss-9e6ZuYgS.cjs} +1 -1
- package/dist/{tailwindcss-c4PkOe1F.js → tailwindcss-DTV9MoJT.js} +1 -1
- package/dist/{transform-DmLonqPE.js → transform-BbbZvFQq.js} +3 -3
- package/dist/{transform-Cy0ddBWf.cjs → transform-D21f8Dm8.cjs} +3 -3
- package/dist/{v4-generation-core-DQeiq-g1.cjs → v4-generation-core-DJBWZ_D0.cjs} +3 -3
- package/dist/vite/web.cjs +1 -1
- package/dist/vite/web.js +1 -1
- package/dist/{vite-OG66oLpb.cjs → vite-CaH7WjX6.cjs} +9 -9
- package/dist/{vite-CaUxtQx5.js → vite-CuYntLZP.js} +8 -8
- package/dist/vite.cjs +1 -1
- package/dist/vite.js +1 -1
- package/dist/weapp-tw-css-generation-loader.cjs +2 -2
- package/dist/weapp-tw-css-import-rewrite-loader.cjs +6 -6
- package/dist/{web-CZKIefdl.cjs → web-CYs2Kcaa.cjs} +53 -16
- package/dist/{web-Bd-9OHFE.js → web-CdXkY_VO.js} +50 -13
- package/dist/{webpack-DJGgU27Y.cjs → webpack-BQNnpQPC.cjs} +19 -9
- package/dist/{webpack-Cyvq3H7Z.js → webpack-BnCSOUuu.js} +16 -6
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +4 -4
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveMpxPlatform } from "./framework.js";
|
|
2
|
-
import { A as resolveBooleanObjectOption, Bt as shouldUseUniAppWebRpxCompatibility, Ht as resolveValidTailwindV4Candidates$1, Lt as resolveCssMacroTailwindV4Source, Mt as _defineProperty, T as omitUndefined, Tt as isFileMatchedByTailwindSourceEntries, Vt as loadTailwindV4DesignSystem, a as resolveGeneratorRuntimeBranch, bt as createTailwindV4Engine$1, d as resolveTailwindV4SourceFromRuntime, i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source$1 } from "./generator-
|
|
3
|
-
import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-
|
|
2
|
+
import { A as resolveBooleanObjectOption, Bt as shouldUseUniAppWebRpxCompatibility, Ht as resolveValidTailwindV4Candidates$1, Lt as resolveCssMacroTailwindV4Source, Mt as _defineProperty, T as omitUndefined, Tt as isFileMatchedByTailwindSourceEntries, Vt as loadTailwindV4DesignSystem, a as resolveGeneratorRuntimeBranch, bt as createTailwindV4Engine$1, d as resolveTailwindV4SourceFromRuntime, i as normalizeWeappTailwindcssGeneratorOptions, t as createWeappTailwindcssGenerator, u as resolveTailwindV4Source$1 } from "./generator-CAOx1Sqm.js";
|
|
3
|
+
import { c as getRuntimeClassSetCacheEntry, d as invalidateRuntimeClassSet, i as resolveUniAppXOptions, o as applyV4CssCalcDefaults, s as warnMissingCssEntries, t as createTailwindcssRuntimeFromContext, u as getRuntimeClassSetSignatureWithSources } from "./tailwindcss-DTV9MoJT.js";
|
|
4
4
|
import { i as isMap, n as defuOverrideArray$1 } from "./utils-MVwpU07P.js";
|
|
5
5
|
import { a as DEFAULT_PARSE_CACHE_MAX_SOURCE_LENGTH, i as resolveDefaultCssPreflight, o as HARD_PARSE_CACHE_MAX_ENTRIES, r as getDefaultOptions } from "./defaults-CKx-4LcW.js";
|
|
6
6
|
import { createRequire } from "node:module";
|
|
@@ -1527,9 +1527,28 @@ function createGenerationArtifact(fragments, options) {
|
|
|
1527
1527
|
});
|
|
1528
1528
|
}
|
|
1529
1529
|
//#endregion
|
|
1530
|
+
//#region src/core/compiler/source-fingerprint.ts
|
|
1531
|
+
function stableSerialize(value, stack = /* @__PURE__ */ new WeakSet()) {
|
|
1532
|
+
if (value == null || typeof value === "number" || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
|
|
1533
|
+
if (typeof value === "function") return `[Function:${value.name}]`;
|
|
1534
|
+
if (typeof value !== "object") return String(value);
|
|
1535
|
+
if (stack.has(value)) return "[Circular]";
|
|
1536
|
+
stack.add(value);
|
|
1537
|
+
const serialized = Array.isArray(value) ? `[${value.map((item) => stableSerialize(item, stack)).join(",")}]` : `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableSerialize(value[key], stack)}`).join(",")}}`;
|
|
1538
|
+
stack.delete(value);
|
|
1539
|
+
return serialized;
|
|
1540
|
+
}
|
|
1541
|
+
function createSourceFingerprint(source) {
|
|
1542
|
+
return createCompilerValueFingerprint(source);
|
|
1543
|
+
}
|
|
1544
|
+
function createCompilerValueFingerprint(value) {
|
|
1545
|
+
return md5Hash(stableSerialize(value));
|
|
1546
|
+
}
|
|
1547
|
+
//#endregion
|
|
1530
1548
|
//#region src/compiler/candidate-index.ts
|
|
1531
1549
|
var CandidateIndex = class {
|
|
1532
|
-
constructor() {
|
|
1550
|
+
constructor(telemetry) {
|
|
1551
|
+
this.telemetry = telemetry;
|
|
1533
1552
|
_defineProperty(this, "candidatesBySource", /* @__PURE__ */ new Map());
|
|
1534
1553
|
}
|
|
1535
1554
|
sync(sourceId, candidates) {
|
|
@@ -1538,6 +1557,14 @@ var CandidateIndex = class {
|
|
|
1538
1557
|
const addedCandidates = new Set([...next].filter((candidate) => !previous.has(candidate)));
|
|
1539
1558
|
const removedCandidates = new Set([...previous].filter((candidate) => !next.has(candidate)));
|
|
1540
1559
|
this.candidatesBySource.set(sourceId, next);
|
|
1560
|
+
this.telemetry?.record({
|
|
1561
|
+
layer: "candidate-index",
|
|
1562
|
+
keyFingerprint: createCompilerValueFingerprint(sourceId),
|
|
1563
|
+
hit: addedCandidates.size === 0 && removedCandidates.size === 0,
|
|
1564
|
+
invalidationReason: addedCandidates.size || removedCandidates.size ? "source-change" : void 0,
|
|
1565
|
+
entries: this.candidatesBySource.size,
|
|
1566
|
+
memoryBytes: [...this.candidatesBySource.values()].reduce((total, values) => total + values.size * 32, 0)
|
|
1567
|
+
});
|
|
1541
1568
|
return {
|
|
1542
1569
|
sourceId,
|
|
1543
1570
|
addedCandidates,
|
|
@@ -1547,6 +1574,14 @@ var CandidateIndex = class {
|
|
|
1547
1574
|
remove(sourceId) {
|
|
1548
1575
|
const previous = this.candidatesBySource.get(sourceId) ?? /* @__PURE__ */ new Set();
|
|
1549
1576
|
this.candidatesBySource.delete(sourceId);
|
|
1577
|
+
this.telemetry?.record({
|
|
1578
|
+
layer: "candidate-index",
|
|
1579
|
+
keyFingerprint: createCompilerValueFingerprint(sourceId),
|
|
1580
|
+
hit: false,
|
|
1581
|
+
invalidationReason: "source-change",
|
|
1582
|
+
evicted: true,
|
|
1583
|
+
entries: this.candidatesBySource.size
|
|
1584
|
+
});
|
|
1550
1585
|
return {
|
|
1551
1586
|
sourceId,
|
|
1552
1587
|
addedCandidates: /* @__PURE__ */ new Set(),
|
|
@@ -1569,6 +1604,25 @@ var CandidateIndex = class {
|
|
|
1569
1604
|
}
|
|
1570
1605
|
};
|
|
1571
1606
|
//#endregion
|
|
1607
|
+
//#region src/compiler/capabilities.ts
|
|
1608
|
+
/** 为适配器声明能力,便于统一契约检查并保持旧适配器兼容。 */
|
|
1609
|
+
function createAdapterCapabilities(adapter, overrides = {}) {
|
|
1610
|
+
return {
|
|
1611
|
+
adapter,
|
|
1612
|
+
version: "1.0",
|
|
1613
|
+
capabilities: [
|
|
1614
|
+
"compilerHost",
|
|
1615
|
+
"sourceCandidates",
|
|
1616
|
+
"cssGeneration",
|
|
1617
|
+
"assetEmission",
|
|
1618
|
+
"watchUpdate",
|
|
1619
|
+
"diagnostics"
|
|
1620
|
+
],
|
|
1621
|
+
...overrides
|
|
1622
|
+
};
|
|
1623
|
+
}
|
|
1624
|
+
createAdapterCapabilities("vite"), createAdapterCapabilities("webpack"), createAdapterCapabilities("rspack"), createAdapterCapabilities("gulp");
|
|
1625
|
+
//#endregion
|
|
1572
1626
|
//#region src/compiler/compilation-scope-graph.ts
|
|
1573
1627
|
function sourceNodeId(sourceId) {
|
|
1574
1628
|
return `source:${sourceId}`;
|
|
@@ -2307,24 +2361,6 @@ function createCompilationEventBus() {
|
|
|
2307
2361
|
};
|
|
2308
2362
|
}
|
|
2309
2363
|
//#endregion
|
|
2310
|
-
//#region src/core/compiler/source-fingerprint.ts
|
|
2311
|
-
function stableSerialize(value, stack = /* @__PURE__ */ new WeakSet()) {
|
|
2312
|
-
if (value == null || typeof value === "number" || typeof value === "boolean" || typeof value === "string") return JSON.stringify(value);
|
|
2313
|
-
if (typeof value === "function") return `[Function:${value.name}]`;
|
|
2314
|
-
if (typeof value !== "object") return String(value);
|
|
2315
|
-
if (stack.has(value)) return "[Circular]";
|
|
2316
|
-
stack.add(value);
|
|
2317
|
-
const serialized = Array.isArray(value) ? `[${value.map((item) => stableSerialize(item, stack)).join(",")}]` : `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableSerialize(value[key], stack)}`).join(",")}}`;
|
|
2318
|
-
stack.delete(value);
|
|
2319
|
-
return serialized;
|
|
2320
|
-
}
|
|
2321
|
-
function createSourceFingerprint(source) {
|
|
2322
|
-
return createCompilerValueFingerprint(source);
|
|
2323
|
-
}
|
|
2324
|
-
function createCompilerValueFingerprint(value) {
|
|
2325
|
-
return md5Hash(stableSerialize(value));
|
|
2326
|
-
}
|
|
2327
|
-
//#endregion
|
|
2328
2364
|
//#region src/core/compiler/generation-cache.ts
|
|
2329
2365
|
function createCompilerGenerationCacheKey(request, candidates, target) {
|
|
2330
2366
|
return {
|
|
@@ -4352,7 +4388,9 @@ function createCompilerTransforms({ ensureActive, track, userOptions }) {
|
|
|
4352
4388
|
const DEFAULT_MAX_ROOTS = 128;
|
|
4353
4389
|
function createCompiler(options = {}) {
|
|
4354
4390
|
const { compiler: compilerOptions, ...userOptions } = options;
|
|
4355
|
-
const
|
|
4391
|
+
const maxRoots = Math.max(1, Math.floor(compilerOptions?.maxRoots ?? DEFAULT_MAX_ROOTS));
|
|
4392
|
+
const cacheTelemetry = compilerOptions?.cacheTelemetry;
|
|
4393
|
+
const rootStore = new CompilerRootStore(maxRoots, compilerOptions?.onRootEvicted);
|
|
4356
4394
|
const activeTasks = /* @__PURE__ */ new Set();
|
|
4357
4395
|
let lifecycle = "active";
|
|
4358
4396
|
let disposePromise;
|
|
@@ -4391,6 +4429,15 @@ function createCompiler(options = {}) {
|
|
|
4391
4429
|
const prepared = prepareCompilerGeneration(entry, request, source, !sourceReused || entry.appliedInvalidation !== invalidation);
|
|
4392
4430
|
const generationCacheKey = createCompilerGenerationCacheKey(request, prepared.compilation.candidates, target);
|
|
4393
4431
|
const reusableGeneration = engineReused && entry.generationCache && isSameCompilerGenerationCacheKey(entry.generationCache.key, generationCacheKey) ? entry.generationCache.result : void 0;
|
|
4432
|
+
cacheTelemetry?.record({
|
|
4433
|
+
layer: "tailwind-generation",
|
|
4434
|
+
keyFingerprint: generationCacheKey.candidateSignature,
|
|
4435
|
+
hit: reusableGeneration !== void 0,
|
|
4436
|
+
invalidationReason: reusableGeneration === void 0 && !engineReused ? "source-change" : void 0,
|
|
4437
|
+
entries: entry.generationCache ? 1 : 0,
|
|
4438
|
+
revision: getLatestRevision(entry),
|
|
4439
|
+
operationId: entry.id
|
|
4440
|
+
});
|
|
4394
4441
|
try {
|
|
4395
4442
|
const generated = reusableGeneration ? reuseCompilerGenerationResult(reusableGeneration) : await generator.generate({
|
|
4396
4443
|
...generateOptions,
|
|
@@ -4860,6 +4907,7 @@ function createRuntimeAffectingSourceSignature(source, type) {
|
|
|
4860
4907
|
/** 创建构建器无关的 runtime state,并保留旧字段供现有插件继续使用。 */
|
|
4861
4908
|
function createCompilerRuntimeState(options) {
|
|
4862
4909
|
const events = options.events ?? createCompilationEventBus();
|
|
4910
|
+
if (options.reporter) events.subscribe(options.reporter);
|
|
4863
4911
|
return {
|
|
4864
4912
|
tailwindRuntime: options.tailwindRuntime,
|
|
4865
4913
|
readyPromise: options.readyPromise ?? Promise.resolve(),
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Document, FinalizeMiniProgramCssOptions, IStyleHandlerOptions, Result as PostcssResult, Root } from '@weapp-tailwindcss/postcss';
|
|
2
|
+
import type { CacheTelemetryCollector } from '../../compiler/cache-telemetry.js';
|
|
2
3
|
import type { TailwindV4ResolvedSource, TailwindV4SourceOptions, WeappTailwindcssGenerateOptions, WeappTailwindcssGenerateResult } from '../../generator/index.js';
|
|
3
4
|
import type { CreateJsHandlerOptions, ITemplateHandlerOptions, JsHandlerResult, UserDefinedOptions } from '../../types/index.js';
|
|
4
5
|
export type CompilerTarget = 'tailwind' | 'weapp' | 'web';
|
|
@@ -56,6 +57,7 @@ export type CreateCompilerOptions = UserDefinedOptions & {
|
|
|
56
57
|
compiler?: {
|
|
57
58
|
maxRoots?: number | undefined;
|
|
58
59
|
onRootEvicted?: ((id: string) => void) | undefined;
|
|
60
|
+
cacheTelemetry?: CacheTelemetryCollector | undefined;
|
|
59
61
|
} | undefined;
|
|
60
62
|
};
|
|
61
63
|
export interface Compiler {
|
package/dist/core.cjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_compiler = require("./compiler-
|
|
3
|
-
const require_runtime_state = require("./runtime-state-
|
|
2
|
+
const require_compiler = require("./compiler-Cc0JXfbw.cjs");
|
|
3
|
+
const require_runtime_state = require("./runtime-state-XYSycuGu.cjs");
|
|
4
4
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
5
5
|
let _weapp_tailwindcss_shared = require("@weapp-tailwindcss/shared");
|
|
6
|
+
let node_perf_hooks = require("node:perf_hooks");
|
|
6
7
|
//#region src/core.ts
|
|
7
8
|
const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
|
|
8
9
|
function resolveTransformWxssOptions(options) {
|
|
@@ -28,6 +29,26 @@ function createContext(options = {}) {
|
|
|
28
29
|
refreshTailwindcssRuntime
|
|
29
30
|
});
|
|
30
31
|
const defaultJsHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
32
|
+
const diagnosticEvents = [];
|
|
33
|
+
runtimeState.events.subscribe((event) => {
|
|
34
|
+
if (event.type === "diagnostic") diagnosticEvents.push(event);
|
|
35
|
+
});
|
|
36
|
+
async function emitDiagnostic(phase, startedAt, operationId, error) {
|
|
37
|
+
await runtimeState.events.emit({
|
|
38
|
+
schemaVersion: 1,
|
|
39
|
+
type: "diagnostic",
|
|
40
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
41
|
+
compilerId: "weapp-tailwindcss",
|
|
42
|
+
phase,
|
|
43
|
+
revision: runtimeState.revision,
|
|
44
|
+
operationId,
|
|
45
|
+
durationMs: node_perf_hooks.performance.now() - startedAt,
|
|
46
|
+
error: error ? {
|
|
47
|
+
name: error instanceof Error ? error.name : void 0,
|
|
48
|
+
message: error instanceof Error ? error.message : String(error)
|
|
49
|
+
} : void 0
|
|
50
|
+
});
|
|
51
|
+
}
|
|
31
52
|
function getDefaultJsHandlerOptions(majorVersion = runtimeState.tailwindRuntime.majorVersion) {
|
|
32
53
|
if (typeof majorVersion !== "number") return;
|
|
33
54
|
let cached = defaultJsHandlerOptionsCache.get(majorVersion);
|
|
@@ -110,9 +131,17 @@ function createContext(options = {}) {
|
|
|
110
131
|
}
|
|
111
132
|
async function transformWxss(rawCss, options) {
|
|
112
133
|
await runtimeState.readyPromise;
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
const startedAt = node_perf_hooks.performance.now();
|
|
135
|
+
const operationId = `css-${Date.now()}-${runtimeState.revision}`;
|
|
136
|
+
try {
|
|
137
|
+
const result = await styleHandler(rawCss, resolveTransformWxssOptions(options));
|
|
138
|
+
runtimeSet = await require_compiler.ensureRuntimeClassSet(runtimeState);
|
|
139
|
+
await emitDiagnostic("postcss", startedAt, operationId);
|
|
140
|
+
return result;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
await emitDiagnostic("postcss", startedAt, operationId, error);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
116
145
|
}
|
|
117
146
|
async function getRuntimeSet(options) {
|
|
118
147
|
await runtimeState.readyPromise;
|
|
@@ -125,18 +154,38 @@ function createContext(options = {}) {
|
|
|
125
154
|
else if (runtimeSet.size === 0) runtimeSet = await require_compiler.ensureRuntimeClassSet(runtimeState, { forceCollect: true });
|
|
126
155
|
const resolvedOptions = resolveTransformJsOptions(options);
|
|
127
156
|
if (require_compiler.shouldSkipJsTransform(rawJs, resolvedOptions)) return { code: rawJs };
|
|
128
|
-
|
|
157
|
+
const startedAt = node_perf_hooks.performance.now();
|
|
158
|
+
const operationId = `js-${Date.now()}-${runtimeState.revision}`;
|
|
159
|
+
try {
|
|
160
|
+
const result = await jsHandler(rawJs, runtimeSet, resolvedOptions);
|
|
161
|
+
await emitDiagnostic("candidate", startedAt, operationId);
|
|
162
|
+
return result;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
await emitDiagnostic("candidate", startedAt, operationId, error);
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
129
167
|
}
|
|
130
168
|
async function transformWxml(rawWxml, options) {
|
|
131
169
|
await runtimeState.readyPromise;
|
|
132
170
|
if (!options?.runtimeSet && runtimeSet.size === 0) runtimeSet = await require_compiler.ensureRuntimeClassSet(runtimeState, { forceCollect: true });
|
|
133
|
-
|
|
171
|
+
const startedAt = node_perf_hooks.performance.now();
|
|
172
|
+
const operationId = `template-${Date.now()}-${runtimeState.revision}`;
|
|
173
|
+
try {
|
|
174
|
+
const result = templateHandler(rawWxml, resolveTransformWxmlOptions(options));
|
|
175
|
+
await emitDiagnostic("scan", startedAt, operationId);
|
|
176
|
+
return result;
|
|
177
|
+
} catch (error) {
|
|
178
|
+
await emitDiagnostic("scan", startedAt, operationId, error);
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
134
181
|
}
|
|
135
182
|
return {
|
|
136
183
|
getRuntimeSet,
|
|
137
184
|
transformWxss,
|
|
138
185
|
transformWxml,
|
|
139
|
-
transformJs
|
|
186
|
+
transformJs,
|
|
187
|
+
events: runtimeState.events,
|
|
188
|
+
getDiagnosticEvents: () => diagnosticEvents.slice()
|
|
140
189
|
};
|
|
141
190
|
}
|
|
142
191
|
//#endregion
|
package/dist/core.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CompilationDiagnosticEvent } from './compiler/events.js';
|
|
1
2
|
import type { CreateJsHandlerOptions, IStyleHandlerOptions, ITemplateHandlerOptions, UserDefinedOptions } from './types/index.js';
|
|
2
3
|
export { createCompilationEventBus, createCompilerRuntimeState } from './compiler/index.js';
|
|
3
4
|
export type { CompilationEvent, CompilerHost, CompilerRuntimeState } from './compiler/index.js';
|
|
@@ -19,4 +20,6 @@ export declare function createContext(options?: UserDefinedOptions): {
|
|
|
19
20
|
transformWxss: (rawCss: string, options?: Partial<IStyleHandlerOptions>) => Promise<import("postcss").Result<import("postcss").Document | import("postcss").Root>>;
|
|
20
21
|
transformWxml: (rawWxml: string, options?: ITemplateHandlerOptions) => Promise<string>;
|
|
21
22
|
transformJs: (rawJs: string, options?: RuntimeJsTransformOptions) => Promise<import("./types/index.js").JsHandlerResult>;
|
|
23
|
+
events: import("./compiler/index.js").CompilationEventBus;
|
|
24
|
+
getDiagnosticEvents: () => CompilationDiagnosticEvent[];
|
|
22
25
|
};
|
package/dist/core.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { C as createTailwindRuntimeReadyPromise, D as createCompilationEventBus, d as createCompiler, f as getCompilerContext, t as createCompilerRuntimeState, v as shouldSkipJsTransform, w as ensureRuntimeClassSet } from "./compiler-
|
|
1
|
+
import { C as createTailwindRuntimeReadyPromise, D as createCompilationEventBus, d as createCompiler, f as getCompilerContext, t as createCompilerRuntimeState, v as shouldSkipJsTransform, w as ensureRuntimeClassSet } from "./compiler-D_vxtEdw.js";
|
|
2
2
|
import { finalizeMiniProgramCss, finalizeMiniProgramCssRoot, postcss, removeTailwindSourceDirectivesRoot } from "@weapp-tailwindcss/postcss";
|
|
3
3
|
import { defuOverrideArray } from "@weapp-tailwindcss/shared";
|
|
4
|
+
import { performance } from "node:perf_hooks";
|
|
4
5
|
//#region src/core.ts
|
|
5
6
|
const DEFAULT_MAIN_CHUNK_STYLE_OPTIONS = Object.freeze({ isMainChunk: true });
|
|
6
7
|
function resolveTransformWxssOptions(options) {
|
|
@@ -26,6 +27,26 @@ function createContext(options = {}) {
|
|
|
26
27
|
refreshTailwindcssRuntime
|
|
27
28
|
});
|
|
28
29
|
const defaultJsHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
30
|
+
const diagnosticEvents = [];
|
|
31
|
+
runtimeState.events.subscribe((event) => {
|
|
32
|
+
if (event.type === "diagnostic") diagnosticEvents.push(event);
|
|
33
|
+
});
|
|
34
|
+
async function emitDiagnostic(phase, startedAt, operationId, error) {
|
|
35
|
+
await runtimeState.events.emit({
|
|
36
|
+
schemaVersion: 1,
|
|
37
|
+
type: "diagnostic",
|
|
38
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
39
|
+
compilerId: "weapp-tailwindcss",
|
|
40
|
+
phase,
|
|
41
|
+
revision: runtimeState.revision,
|
|
42
|
+
operationId,
|
|
43
|
+
durationMs: performance.now() - startedAt,
|
|
44
|
+
error: error ? {
|
|
45
|
+
name: error instanceof Error ? error.name : void 0,
|
|
46
|
+
message: error instanceof Error ? error.message : String(error)
|
|
47
|
+
} : void 0
|
|
48
|
+
});
|
|
49
|
+
}
|
|
29
50
|
function getDefaultJsHandlerOptions(majorVersion = runtimeState.tailwindRuntime.majorVersion) {
|
|
30
51
|
if (typeof majorVersion !== "number") return;
|
|
31
52
|
let cached = defaultJsHandlerOptionsCache.get(majorVersion);
|
|
@@ -108,9 +129,17 @@ function createContext(options = {}) {
|
|
|
108
129
|
}
|
|
109
130
|
async function transformWxss(rawCss, options) {
|
|
110
131
|
await runtimeState.readyPromise;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
132
|
+
const startedAt = performance.now();
|
|
133
|
+
const operationId = `css-${Date.now()}-${runtimeState.revision}`;
|
|
134
|
+
try {
|
|
135
|
+
const result = await styleHandler(rawCss, resolveTransformWxssOptions(options));
|
|
136
|
+
runtimeSet = await ensureRuntimeClassSet(runtimeState);
|
|
137
|
+
await emitDiagnostic("postcss", startedAt, operationId);
|
|
138
|
+
return result;
|
|
139
|
+
} catch (error) {
|
|
140
|
+
await emitDiagnostic("postcss", startedAt, operationId, error);
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
114
143
|
}
|
|
115
144
|
async function getRuntimeSet(options) {
|
|
116
145
|
await runtimeState.readyPromise;
|
|
@@ -123,18 +152,38 @@ function createContext(options = {}) {
|
|
|
123
152
|
else if (runtimeSet.size === 0) runtimeSet = await ensureRuntimeClassSet(runtimeState, { forceCollect: true });
|
|
124
153
|
const resolvedOptions = resolveTransformJsOptions(options);
|
|
125
154
|
if (shouldSkipJsTransform(rawJs, resolvedOptions)) return { code: rawJs };
|
|
126
|
-
|
|
155
|
+
const startedAt = performance.now();
|
|
156
|
+
const operationId = `js-${Date.now()}-${runtimeState.revision}`;
|
|
157
|
+
try {
|
|
158
|
+
const result = await jsHandler(rawJs, runtimeSet, resolvedOptions);
|
|
159
|
+
await emitDiagnostic("candidate", startedAt, operationId);
|
|
160
|
+
return result;
|
|
161
|
+
} catch (error) {
|
|
162
|
+
await emitDiagnostic("candidate", startedAt, operationId, error);
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
127
165
|
}
|
|
128
166
|
async function transformWxml(rawWxml, options) {
|
|
129
167
|
await runtimeState.readyPromise;
|
|
130
168
|
if (!options?.runtimeSet && runtimeSet.size === 0) runtimeSet = await ensureRuntimeClassSet(runtimeState, { forceCollect: true });
|
|
131
|
-
|
|
169
|
+
const startedAt = performance.now();
|
|
170
|
+
const operationId = `template-${Date.now()}-${runtimeState.revision}`;
|
|
171
|
+
try {
|
|
172
|
+
const result = templateHandler(rawWxml, resolveTransformWxmlOptions(options));
|
|
173
|
+
await emitDiagnostic("scan", startedAt, operationId);
|
|
174
|
+
return result;
|
|
175
|
+
} catch (error) {
|
|
176
|
+
await emitDiagnostic("scan", startedAt, operationId, error);
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
132
179
|
}
|
|
133
180
|
return {
|
|
134
181
|
getRuntimeSet,
|
|
135
182
|
transformWxss,
|
|
136
183
|
transformWxml,
|
|
137
|
-
transformJs
|
|
184
|
+
transformJs,
|
|
185
|
+
events: runtimeState.events,
|
|
186
|
+
getDiagnosticEvents: () => diagnosticEvents.slice()
|
|
138
187
|
};
|
|
139
188
|
}
|
|
140
189
|
//#endregion
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-Ctb5zv51.cjs");
|
|
2
|
-
const require_generator = require("./generator-
|
|
2
|
+
const require_generator = require("./generator-BdSIvFEO.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
5
5
|
let _weapp_tailwindcss_postcss = require("@weapp-tailwindcss/postcss");
|
|
@@ -1269,23 +1269,38 @@ async function resolveCssDefinedScanSources(source) {
|
|
|
1269
1269
|
let importSourceBase;
|
|
1270
1270
|
let hasSourceNone = false;
|
|
1271
1271
|
let hasTailwindImport = false;
|
|
1272
|
-
const
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1272
|
+
const sourcePatterns = [];
|
|
1273
|
+
const definitions = [{
|
|
1274
|
+
css: source.css,
|
|
1275
|
+
base: source.base,
|
|
1276
|
+
from: source.dependencies[0]
|
|
1277
|
+
}];
|
|
1278
|
+
for (const dependency of source.dependencies.slice(1)) {
|
|
1279
|
+
if (!(0, node_fs.existsSync)(dependency)) continue;
|
|
1280
|
+
try {
|
|
1281
|
+
definitions.push({
|
|
1282
|
+
css: (0, node_fs.readFileSync)(dependency, "utf8"),
|
|
1283
|
+
base: node_path.default.dirname(dependency),
|
|
1284
|
+
from: dependency
|
|
1285
|
+
});
|
|
1286
|
+
} catch {}
|
|
1278
1287
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1288
|
+
for (const definition of definitions) {
|
|
1289
|
+
let root;
|
|
1290
|
+
try {
|
|
1291
|
+
root = _weapp_tailwindcss_postcss.postcss.parse(definition.css, { from: definition.from });
|
|
1292
|
+
} catch {
|
|
1293
|
+
continue;
|
|
1294
|
+
}
|
|
1295
|
+
root.walkAtRules((rule) => {
|
|
1296
|
+
if (rule.name !== "import" || !isTailwindCssImport(rule.params)) return;
|
|
1282
1297
|
hasTailwindImport = true;
|
|
1283
1298
|
const sourceParam = parseImportSourceParam(rule.params);
|
|
1284
1299
|
if (sourceParam?.none) hasSourceNone = true;
|
|
1285
|
-
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(
|
|
1286
|
-
}
|
|
1287
|
-
|
|
1288
|
-
|
|
1300
|
+
if (sourceParam?.sourcePath) importSourceBase = resolveSourceBase(definition.base, sourceParam.sourcePath);
|
|
1301
|
+
});
|
|
1302
|
+
sourcePatterns.push(...await resolveCssSourceEntries(root, definition.base, "**/*"));
|
|
1303
|
+
}
|
|
1289
1304
|
if (!importSourceBase) {
|
|
1290
1305
|
if (sourcePatterns.length > 0) return [...normalizeCssDefinedScanSources(source.base, sourcePatterns), ...createDefaultIgnoredScanSources(source.base)];
|
|
1291
1306
|
if (hasSourceNone) return false;
|
|
@@ -1327,6 +1342,20 @@ function resolveCompiledSourceRoot(source) {
|
|
|
1327
1342
|
return root;
|
|
1328
1343
|
}
|
|
1329
1344
|
//#endregion
|
|
1345
|
+
//#region src/tailwindcss/v4-engine/generator/style-context.ts
|
|
1346
|
+
function resolveGenerationStyleContext(sourceCss, generatedCss, options) {
|
|
1347
|
+
const calc = options?.cssOptions?.cssCalc ?? options?.cssCalc;
|
|
1348
|
+
const include = Array.isArray(calc) ? calc : calc && typeof calc === "object" ? calc.includeCustomProperties : void 0;
|
|
1349
|
+
if (calc !== true && !include?.length) return options;
|
|
1350
|
+
const customPropertyValues = collectCustomPropertyValues(sourceCss);
|
|
1351
|
+
mergeCustomPropertyValues(customPropertyValues, generatedCss);
|
|
1352
|
+
for (const [name, value] of options?.customPropertyValues ?? []) customPropertyValues.set(name, value);
|
|
1353
|
+
return {
|
|
1354
|
+
...options,
|
|
1355
|
+
customPropertyValues
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
//#endregion
|
|
1330
1359
|
//#region src/tailwindcss/v4-engine/generator/engine.ts
|
|
1331
1360
|
function isCssSyntaxError(error) {
|
|
1332
1361
|
return error instanceof Error && error.name === "CssSyntaxError";
|
|
@@ -1373,7 +1402,7 @@ function createTailwindV4Engine(source) {
|
|
|
1373
1402
|
}
|
|
1374
1403
|
const sources = Array.isArray(resolvedScanSources) ? resolvedScanSources : [];
|
|
1375
1404
|
const rawCss = restoreRpxLengthCssSelectors(generatedCss, normalizedCandidates.restoreCandidates);
|
|
1376
|
-
const css = await transformTailwindV4CssByTarget(rawCss, target, resolvedStyleOptions);
|
|
1405
|
+
const css = await transformTailwindV4CssByTarget(rawCss, target, resolveGenerationStyleContext(compatibleSource.css, rawCss, resolvedStyleOptions));
|
|
1377
1406
|
return {
|
|
1378
1407
|
classSet: restoreRpxLengthCandidates(classSet, normalizedCandidates.restoreCandidates),
|
|
1379
1408
|
rawCandidates: restoreRpxLengthCandidates(rawCandidates, normalizedCandidates.restoreCandidates),
|
|
@@ -2969,6 +2998,10 @@ function isPostcssPluginImportTarget(value) {
|
|
|
2969
2998
|
function uniqueDefined(values) {
|
|
2970
2999
|
return [...new Set(values.filter((value) => typeof value === "string" && value.length > 0))];
|
|
2971
3000
|
}
|
|
3001
|
+
function resolveCssImportFile(base, specifier) {
|
|
3002
|
+
const normalizedSpecifier = node_path.default.sep === "\\" ? specifier.replaceAll("/", "\\") : specifier.replaceAll("\\", "/");
|
|
3003
|
+
return node_path.default.resolve(base, normalizedSpecifier);
|
|
3004
|
+
}
|
|
2972
3005
|
function getProjectRoot(runtime) {
|
|
2973
3006
|
return runtime.options?.projectRoot ?? node_process.default.cwd();
|
|
2974
3007
|
}
|
|
@@ -3012,27 +3045,6 @@ function normalizeTailwindV4CssPackageImports(css, packageName) {
|
|
|
3012
3045
|
});
|
|
3013
3046
|
return changed ? root.toString() : css;
|
|
3014
3047
|
}
|
|
3015
|
-
function normalizeTailwindV4CssSourceDirectives(css, base) {
|
|
3016
|
-
if (!css.includes("@source")) return css;
|
|
3017
|
-
let root;
|
|
3018
|
-
try {
|
|
3019
|
-
root = _weapp_tailwindcss_postcss.postcss.parse(css);
|
|
3020
|
-
} catch {
|
|
3021
|
-
return css;
|
|
3022
|
-
}
|
|
3023
|
-
let changed = false;
|
|
3024
|
-
root.walkAtRules("source", (rule) => {
|
|
3025
|
-
const match = rule.params.match(/^(not\s+)?("([^"\\]*(?:\\.[^"\\]*)*)"|'([^'\\]*(?:\\.[^'\\]*)*)')(.*)$/);
|
|
3026
|
-
if (!match) return;
|
|
3027
|
-
const specifier = match[3] ?? match[4];
|
|
3028
|
-
if (!specifier?.startsWith(".")) return;
|
|
3029
|
-
const resolved = node_path.default.resolve(base, specifier);
|
|
3030
|
-
const quote = match[2] === void 0 ? "'" : "\"";
|
|
3031
|
-
rule.params = `${match[1] ?? ""}${quote}${resolved}${quote}${match[5] ?? ""}`;
|
|
3032
|
-
changed = true;
|
|
3033
|
-
});
|
|
3034
|
-
return changed ? root.toString() : css;
|
|
3035
|
-
}
|
|
3036
3048
|
function normalizeTailwindV4CssSources(cssSources, packageName, projectRoot) {
|
|
3037
3049
|
if (!cssSources?.length) return cssSources;
|
|
3038
3050
|
let changed = false;
|
|
@@ -3065,32 +3077,26 @@ function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
|
|
|
3065
3077
|
if (!cssEntries?.length) return;
|
|
3066
3078
|
const remainingCssEntries = [];
|
|
3067
3079
|
const cssSources = [];
|
|
3068
|
-
const
|
|
3069
|
-
const
|
|
3080
|
+
const graphs = /* @__PURE__ */ new Map();
|
|
3081
|
+
const collectCssGraph = (file, visiting = /* @__PURE__ */ new Set()) => {
|
|
3070
3082
|
const normalizedFile = node_path.default.resolve(file);
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
const
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
const
|
|
3077
|
-
const css = normalizeTailwindV4CssPackageImports(nested ? normalizeTailwindV4CssSourceDirectives(normalizeEmptyTailwindCustomVariants(normalizeConfigDirective(rawCss, config)), base) : normalizeEmptyTailwindCustomVariants(normalizeConfigDirective(rawCss, config)), packageName);
|
|
3078
|
-
cssSources.push({
|
|
3079
|
-
file: normalizedFile,
|
|
3080
|
-
base,
|
|
3081
|
-
css,
|
|
3082
|
-
dependencies: [normalizedFile]
|
|
3083
|
-
});
|
|
3083
|
+
const cached = graphs.get(normalizedFile);
|
|
3084
|
+
if (cached) return cached;
|
|
3085
|
+
const graph = /* @__PURE__ */ new Set([normalizedFile]);
|
|
3086
|
+
graphs.set(normalizedFile, graph);
|
|
3087
|
+
if (visiting.has(normalizedFile) || !(0, node_fs.existsSync)(normalizedFile)) return graph;
|
|
3088
|
+
const nextVisiting = new Set(visiting).add(normalizedFile);
|
|
3084
3089
|
let root;
|
|
3085
3090
|
try {
|
|
3086
|
-
root = _weapp_tailwindcss_postcss.postcss.parse(
|
|
3091
|
+
root = _weapp_tailwindcss_postcss.postcss.parse((0, node_fs.readFileSync)(normalizedFile, "utf8"));
|
|
3087
3092
|
} catch {
|
|
3088
|
-
return;
|
|
3093
|
+
return graph;
|
|
3089
3094
|
}
|
|
3095
|
+
const base = node_path.default.dirname(normalizedFile);
|
|
3090
3096
|
root.walkAtRules("import", (rule) => {
|
|
3091
3097
|
const parsed = parseCssImportSpecifier(rule.params);
|
|
3092
|
-
if (!parsed || !parsed.specifier.startsWith(".")
|
|
3093
|
-
const importedFile =
|
|
3098
|
+
if (!parsed || !parsed.specifier.startsWith(".")) return;
|
|
3099
|
+
const importedFile = resolveCssImportFile(base, parsed.specifier);
|
|
3094
3100
|
const resolved = (node_path.default.extname(importedFile) ? [importedFile] : [
|
|
3095
3101
|
importedFile,
|
|
3096
3102
|
`${importedFile}.css`,
|
|
@@ -3098,9 +3104,24 @@ function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
|
|
|
3098
3104
|
`${importedFile}.scss`,
|
|
3099
3105
|
`${importedFile}.sass`
|
|
3100
3106
|
]).find((candidate) => (0, node_fs.existsSync)(candidate));
|
|
3101
|
-
if (resolved)
|
|
3107
|
+
if (!resolved) return;
|
|
3108
|
+
for (const dependency of collectCssGraph(resolved, nextVisiting)) graph.add(dependency);
|
|
3102
3109
|
});
|
|
3110
|
+
return graph;
|
|
3111
|
+
};
|
|
3112
|
+
const createCssSource = (file, dependencies) => {
|
|
3113
|
+
const normalizedFile = node_path.default.resolve(file);
|
|
3114
|
+
const base = node_path.default.dirname(normalizedFile);
|
|
3115
|
+
const rawCss = (0, node_fs.readFileSync)(normalizedFile, "utf8");
|
|
3116
|
+
const entrySource = resolveCssEntrySource(rawCss, base, { removeConfig: false });
|
|
3117
|
+
return {
|
|
3118
|
+
file: normalizedFile,
|
|
3119
|
+
base,
|
|
3120
|
+
css: normalizeTailwindV4CssPackageImports(normalizeEmptyTailwindCustomVariants(normalizeConfigDirective(rawCss, entrySource?.config && (0, node_fs.existsSync)(entrySource.config) ? entrySource.config : entrySource?.configRequest && !node_path.default.isAbsolute(entrySource.configRequest) && !isPackageJsonImportSpecifier(entrySource.configRequest) ? node_path.default.resolve(base, entrySource.configRequest) : entrySource?.config)), packageName),
|
|
3121
|
+
dependencies: [...dependencies]
|
|
3122
|
+
};
|
|
3103
3123
|
};
|
|
3124
|
+
const rootEntries = [];
|
|
3104
3125
|
for (const cssEntry of cssEntries) {
|
|
3105
3126
|
const normalizedCssEntry = cssEntry.replace(/[?#].*$/, "");
|
|
3106
3127
|
const file = node_path.default.resolve(normalizedCssEntry);
|
|
@@ -3108,8 +3129,17 @@ function normalizeTailwindV4CssEntrySources(cssEntries, packageName) {
|
|
|
3108
3129
|
remainingCssEntries.push(normalizedCssEntry);
|
|
3109
3130
|
continue;
|
|
3110
3131
|
}
|
|
3111
|
-
|
|
3132
|
+
rootEntries.push(file);
|
|
3133
|
+
}
|
|
3134
|
+
const entryGraphs = rootEntries.map((entry) => [entry, collectCssGraph(entry)]);
|
|
3135
|
+
const nestedEntries = /* @__PURE__ */ new Set();
|
|
3136
|
+
for (const [entry] of entryGraphs) for (const [otherEntry, otherGraph] of entryGraphs) if (entry !== otherEntry && otherGraph.has(entry)) {
|
|
3137
|
+
nestedEntries.add(entry);
|
|
3138
|
+
break;
|
|
3112
3139
|
}
|
|
3140
|
+
const selectedEntries = entryGraphs.filter(([entry]) => !nestedEntries.has(entry));
|
|
3141
|
+
const roots = selectedEntries.length > 0 ? selectedEntries : entryGraphs.slice(0, 1);
|
|
3142
|
+
for (const [rootEntry, dependencies] of roots) cssSources.push(createCssSource(rootEntry, dependencies));
|
|
3113
3143
|
return {
|
|
3114
3144
|
cssEntries: remainingCssEntries,
|
|
3115
3145
|
cssSources
|