@weapp-tailwindcss/engine 0.1.1 → 0.1.3

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/index.cjs CHANGED
@@ -1,13 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_v4 = require("./v4-DVqsqn8b.cjs");
2
+ const require_v4 = require("./v4-CgRRASej.cjs");
3
3
  let node_process = require("node:process");
4
4
  node_process = require_v4.__toESM(node_process, 1);
5
5
  let _weapp_tailwindcss_source_scan = require("@weapp-tailwindcss/source-scan");
6
6
  //#region src/extraction/candidate-extractor/valid.ts
7
- const designSystemCandidateCache = /* @__PURE__ */ new Map();
8
- function createCandidateCacheKey(designSystemKey, options) {
9
- if (options.bareArbitraryValues == null || options.bareArbitraryValues === false) return designSystemKey;
10
- return `${designSystemKey}:bare-arbitrary:${JSON.stringify(options.bareArbitraryValues)}`;
7
+ const designSystemCandidateCache = /* @__PURE__ */ new WeakMap();
8
+ function createCandidateCacheKey(options) {
9
+ if (options.bareArbitraryValues == null || options.bareArbitraryValues === false) return "default";
10
+ return `bare-arbitrary:${JSON.stringify(options.bareArbitraryValues)}`;
11
11
  }
12
12
  async function extractValidCandidates(options) {
13
13
  const providedOptions = options ?? {};
@@ -24,18 +24,18 @@ async function extractValidCandidates(options) {
24
24
  pattern: source.pattern,
25
25
  negated: source.negated
26
26
  }));
27
- const source = {
27
+ const designSystem = await require_v4.loadTailwindV4DesignSystem({
28
28
  projectRoot: defaultCwd,
29
29
  base,
30
30
  baseFallbacks,
31
31
  css,
32
32
  dependencies: []
33
- };
34
- const designSystemKey = require_v4.getTailwindV4DesignSystemCacheKey(source);
35
- const designSystem = await require_v4.loadTailwindV4DesignSystem(source);
36
- const candidateCacheKey = createCandidateCacheKey(designSystemKey, providedOptions);
37
- const candidateCache = designSystemCandidateCache.get(candidateCacheKey) ?? /* @__PURE__ */ new Map();
38
- designSystemCandidateCache.set(candidateCacheKey, candidateCache);
33
+ });
34
+ const candidateCacheKey = createCandidateCacheKey(providedOptions);
35
+ const caches = designSystemCandidateCache.get(designSystem) ?? /* @__PURE__ */ new Map();
36
+ designSystemCandidateCache.set(designSystem, caches);
37
+ const candidateCache = caches.get(candidateCacheKey) ?? /* @__PURE__ */ new Map();
38
+ caches.set(candidateCacheKey, candidateCache);
39
39
  const candidates = await require_v4.extractRawCandidates(sources, providedOptions.bareArbitraryValues === void 0 ? void 0 : { bareArbitraryValues: providedOptions.bareArbitraryValues });
40
40
  const inlineSources = require_v4.extractTailwindV4InlineSourceCandidates(css);
41
41
  for (const candidate of inlineSources.included) candidates.push(candidate);
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import { A as expandTailwindV4SourceEntryBraces, B as expandTailwindV4SourceEntries, C as TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, D as createTailwindV4CompiledSourceEntries, E as TAILWIND_V4_IGNORED_FILES, F as resolveTailwindV4SourceBaseCandidates, G as compileTailwindV4Source, H as isFileExcludedByTailwindV4SourceEntries, I as resolveTailwindV4SourceEntry, J as loadTailwindV4NodeModule, K as getTailwindV4DesignSystemCacheKey, L as toPosixPath, M as normalizeTailwindV4ScannerSources, N as normalizeTailwindV4SourceEntries, O as createTailwindV4DefaultIgnoreSources, P as resolveSourceScanPath, R as createTailwindV4SourceEntryMatcher, S as resolveProjectSourceFiles, T as TAILWIND_V4_IGNORED_EXTENSIONS, U as isFileMatchedByTailwindV4SourceEntries, V as groupTailwindV4SourceEntriesByBase, W as mergeTailwindV4SourceEntries, _ as isBareArbitraryValuesEnabled, a as createTailwindGenerationSession, b as extractProjectCandidatesWithPositions, c as replaceBareArbitraryValueSelectors, d as extractRawCandidates, f as extractRawCandidatesWithPositions, g as extractBareArbitraryValueSourceCandidatesWithPositions, h as extractBareArbitraryValueSourceCandidates, i as createTailwindV4Engine, j as normalizeGlobPattern, k as createTailwindV4RootSources, l as resolveValidTailwindV4Candidates, m as extractSourceCandidatesWithPositions, n as generateTailwindV4Style, o as collectTailwindStyleCandidates, p as extractSourceCandidates, q as loadTailwindV4DesignSystem, r as resolveTailwindV4Source, s as canonicalizeBareArbitraryValueCandidates, t as collectTailwindV4StyleCandidates, u as extractTailwindV4InlineSourceCandidates, v as resolveBareArbitraryValueCandidate, w as TAILWIND_V4_IGNORED_CONTENT_DIRS, x as groupTokensByFile, y as escapeCssClassName, z as createTailwindV4SourceExclusionMatcher } from "./v4-D46xWjyQ.js";
1
+ import { A as expandTailwindV4SourceEntryBraces, B as expandTailwindV4SourceEntries, C as TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, D as createTailwindV4CompiledSourceEntries, E as TAILWIND_V4_IGNORED_FILES, F as resolveTailwindV4SourceBaseCandidates, G as compileTailwindV4Source, H as isFileExcludedByTailwindV4SourceEntries, I as resolveTailwindV4SourceEntry, J as loadTailwindV4NodeModule, K as getTailwindV4DesignSystemCacheKey, L as toPosixPath, M as normalizeTailwindV4ScannerSources, N as normalizeTailwindV4SourceEntries, O as createTailwindV4DefaultIgnoreSources, P as resolveSourceScanPath, R as createTailwindV4SourceEntryMatcher, S as resolveProjectSourceFiles, T as TAILWIND_V4_IGNORED_EXTENSIONS, U as isFileMatchedByTailwindV4SourceEntries, V as groupTailwindV4SourceEntriesByBase, W as mergeTailwindV4SourceEntries, _ as isBareArbitraryValuesEnabled, a as createTailwindGenerationSession, b as extractProjectCandidatesWithPositions, c as replaceBareArbitraryValueSelectors, d as extractRawCandidates, f as extractRawCandidatesWithPositions, g as extractBareArbitraryValueSourceCandidatesWithPositions, h as extractBareArbitraryValueSourceCandidates, i as createTailwindV4Engine, j as normalizeGlobPattern, k as createTailwindV4RootSources, l as resolveValidTailwindV4Candidates, m as extractSourceCandidatesWithPositions, n as generateTailwindV4Style, o as collectTailwindStyleCandidates, p as extractSourceCandidates, q as loadTailwindV4DesignSystem, r as resolveTailwindV4Source, s as canonicalizeBareArbitraryValueCandidates, t as collectTailwindV4StyleCandidates, u as extractTailwindV4InlineSourceCandidates, v as resolveBareArbitraryValueCandidate, w as TAILWIND_V4_IGNORED_CONTENT_DIRS, x as groupTokensByFile, y as escapeCssClassName, z as createTailwindV4SourceExclusionMatcher } from "./v4-DXSYux_T.js";
2
2
  import process from "node:process";
3
3
  //#region src/extraction/candidate-extractor/valid.ts
4
- const designSystemCandidateCache = /* @__PURE__ */ new Map();
5
- function createCandidateCacheKey(designSystemKey, options) {
6
- if (options.bareArbitraryValues == null || options.bareArbitraryValues === false) return designSystemKey;
7
- return `${designSystemKey}:bare-arbitrary:${JSON.stringify(options.bareArbitraryValues)}`;
4
+ const designSystemCandidateCache = /* @__PURE__ */ new WeakMap();
5
+ function createCandidateCacheKey(options) {
6
+ if (options.bareArbitraryValues == null || options.bareArbitraryValues === false) return "default";
7
+ return `bare-arbitrary:${JSON.stringify(options.bareArbitraryValues)}`;
8
8
  }
9
9
  async function extractValidCandidates(options) {
10
10
  const providedOptions = options ?? {};
@@ -21,18 +21,18 @@ async function extractValidCandidates(options) {
21
21
  pattern: source.pattern,
22
22
  negated: source.negated
23
23
  }));
24
- const source = {
24
+ const designSystem = await loadTailwindV4DesignSystem({
25
25
  projectRoot: defaultCwd,
26
26
  base,
27
27
  baseFallbacks,
28
28
  css,
29
29
  dependencies: []
30
- };
31
- const designSystemKey = getTailwindV4DesignSystemCacheKey(source);
32
- const designSystem = await loadTailwindV4DesignSystem(source);
33
- const candidateCacheKey = createCandidateCacheKey(designSystemKey, providedOptions);
34
- const candidateCache = designSystemCandidateCache.get(candidateCacheKey) ?? /* @__PURE__ */ new Map();
35
- designSystemCandidateCache.set(candidateCacheKey, candidateCache);
30
+ });
31
+ const candidateCacheKey = createCandidateCacheKey(providedOptions);
32
+ const caches = designSystemCandidateCache.get(designSystem) ?? /* @__PURE__ */ new Map();
33
+ designSystemCandidateCache.set(designSystem, caches);
34
+ const candidateCache = caches.get(candidateCacheKey) ?? /* @__PURE__ */ new Map();
35
+ caches.set(candidateCacheKey, candidateCache);
36
36
  const candidates = await extractRawCandidates(sources, providedOptions.bareArbitraryValues === void 0 ? void 0 : { bareArbitraryValues: providedOptions.bareArbitraryValues });
37
37
  const inlineSources = extractTailwindV4InlineSourceCandidates(css);
38
38
  for (const candidate of inlineSources.included) candidates.push(candidate);
package/dist/v4/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_v4 = require("../v4-DVqsqn8b.cjs");
2
+ const require_v4 = require("../v4-CgRRASej.cjs");
3
3
  let _weapp_tailwindcss_source_scan = require("@weapp-tailwindcss/source-scan");
4
4
  exports.TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN = require_v4.TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN;
5
5
  exports.TAILWIND_V4_IGNORED_CONTENT_DIRS = require_v4.TAILWIND_V4_IGNORED_CONTENT_DIRS;
package/dist/v4/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { A as expandTailwindV4SourceEntryBraces, B as expandTailwindV4SourceEntries, C as TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, D as createTailwindV4CompiledSourceEntries, E as TAILWIND_V4_IGNORED_FILES, F as resolveTailwindV4SourceBaseCandidates, G as compileTailwindV4Source, H as isFileExcludedByTailwindV4SourceEntries, I as resolveTailwindV4SourceEntry, J as loadTailwindV4NodeModule, K as getTailwindV4DesignSystemCacheKey, L as toPosixPath, M as normalizeTailwindV4ScannerSources, N as normalizeTailwindV4SourceEntries, O as createTailwindV4DefaultIgnoreSources, P as resolveSourceScanPath, R as createTailwindV4SourceEntryMatcher, T as TAILWIND_V4_IGNORED_EXTENSIONS, U as isFileMatchedByTailwindV4SourceEntries, V as groupTailwindV4SourceEntriesByBase, W as mergeTailwindV4SourceEntries, _ as isBareArbitraryValuesEnabled, a as createTailwindGenerationSession, c as replaceBareArbitraryValueSelectors, g as extractBareArbitraryValueSourceCandidatesWithPositions, h as extractBareArbitraryValueSourceCandidates, i as createTailwindV4Engine, j as normalizeGlobPattern, k as createTailwindV4RootSources, l as resolveValidTailwindV4Candidates, n as generateTailwindV4Style, q as loadTailwindV4DesignSystem, r as resolveTailwindV4Source, s as canonicalizeBareArbitraryValueCandidates, t as collectTailwindV4StyleCandidates, u as extractTailwindV4InlineSourceCandidates, v as resolveBareArbitraryValueCandidate, w as TAILWIND_V4_IGNORED_CONTENT_DIRS, y as escapeCssClassName, z as createTailwindV4SourceExclusionMatcher } from "../v4-D46xWjyQ.js";
1
+ import { A as expandTailwindV4SourceEntryBraces, B as expandTailwindV4SourceEntries, C as TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, D as createTailwindV4CompiledSourceEntries, E as TAILWIND_V4_IGNORED_FILES, F as resolveTailwindV4SourceBaseCandidates, G as compileTailwindV4Source, H as isFileExcludedByTailwindV4SourceEntries, I as resolveTailwindV4SourceEntry, J as loadTailwindV4NodeModule, K as getTailwindV4DesignSystemCacheKey, L as toPosixPath, M as normalizeTailwindV4ScannerSources, N as normalizeTailwindV4SourceEntries, O as createTailwindV4DefaultIgnoreSources, P as resolveSourceScanPath, R as createTailwindV4SourceEntryMatcher, T as TAILWIND_V4_IGNORED_EXTENSIONS, U as isFileMatchedByTailwindV4SourceEntries, V as groupTailwindV4SourceEntriesByBase, W as mergeTailwindV4SourceEntries, _ as isBareArbitraryValuesEnabled, a as createTailwindGenerationSession, c as replaceBareArbitraryValueSelectors, g as extractBareArbitraryValueSourceCandidatesWithPositions, h as extractBareArbitraryValueSourceCandidates, i as createTailwindV4Engine, j as normalizeGlobPattern, k as createTailwindV4RootSources, l as resolveValidTailwindV4Candidates, n as generateTailwindV4Style, q as loadTailwindV4DesignSystem, r as resolveTailwindV4Source, s as canonicalizeBareArbitraryValueCandidates, t as collectTailwindV4StyleCandidates, u as extractTailwindV4InlineSourceCandidates, v as resolveBareArbitraryValueCandidate, w as TAILWIND_V4_IGNORED_CONTENT_DIRS, y as escapeCssClassName, z as createTailwindV4SourceExclusionMatcher } from "../v4-DXSYux_T.js";
2
2
  export { TAILWIND_V4_AUTO_SOURCE_SCAN_PATTERN, TAILWIND_V4_IGNORED_CONTENT_DIRS, TAILWIND_V4_IGNORED_EXTENSIONS, TAILWIND_V4_IGNORED_FILES, canonicalizeBareArbitraryValueCandidates, collectTailwindV4StyleCandidates, compileTailwindV4Source, createTailwindGenerationSession, createTailwindV4CompiledSourceEntries, createTailwindV4DefaultIgnoreSources, createTailwindV4Engine, createTailwindV4RootSources, createTailwindV4SourceEntryMatcher, createTailwindV4SourceExclusionMatcher, escapeCssClassName, expandTailwindV4SourceEntries, expandTailwindV4SourceEntryBraces, extractBareArbitraryValueSourceCandidates, extractBareArbitraryValueSourceCandidatesWithPositions, extractTailwindV4InlineSourceCandidates, generateTailwindV4Style, getTailwindV4DesignSystemCacheKey, groupTailwindV4SourceEntriesByBase, isBareArbitraryValuesEnabled, isFileExcludedByTailwindV4SourceEntries, isFileMatchedByTailwindV4SourceEntries, loadTailwindV4DesignSystem, loadTailwindV4NodeModule, mergeTailwindV4SourceEntries, normalizeGlobPattern, normalizeTailwindV4ScannerSources, normalizeTailwindV4SourceEntries, replaceBareArbitraryValueSelectors, resolveBareArbitraryValueCandidate, resolveSourceScanPath, resolveTailwindV4Source, resolveTailwindV4SourceBaseCandidates, resolveTailwindV4SourceEntry, resolveValidTailwindV4Candidates, toPosixPath };
@@ -25,10 +25,10 @@ let node_path = require("node:path");
25
25
  node_path = __toESM(node_path, 1);
26
26
  let node_process = require("node:process");
27
27
  node_process = __toESM(node_process, 1);
28
+ let node_crypto = require("node:crypto");
28
29
  let node_module = require("node:module");
29
30
  let node_url = require("node:url");
30
31
  let node_async_hooks = require("node:async_hooks");
31
- let node_crypto = require("node:crypto");
32
32
  let _tailwindcss_node_require_cache = require("@tailwindcss/node/require-cache");
33
33
  let _weapp_tailwindcss_source_scan = require("@weapp-tailwindcss/source-scan");
34
34
  let postcss = require("postcss");
@@ -193,9 +193,45 @@ function prepareGenerationModuleRequests(css, base) {
193
193
  };
194
194
  }
195
195
  //#endregion
196
+ //#region src/v4/node-adapter/cache.ts
197
+ /** 模块与 design system 的跨会话复用有界,命中时更新最近使用顺序。 */
198
+ var BoundedCache = class extends Map {
199
+ limit;
200
+ constructor(limit) {
201
+ super();
202
+ this.limit = limit;
203
+ }
204
+ get(key) {
205
+ const value = super.get(key);
206
+ if (super.has(key)) {
207
+ super.delete(key);
208
+ super.set(key, value);
209
+ }
210
+ return value;
211
+ }
212
+ set(key, value) {
213
+ super.delete(key);
214
+ super.set(key, value);
215
+ while (this.size > this.limit) super.delete(this.keys().next().value);
216
+ return this;
217
+ }
218
+ };
219
+ //#endregion
196
220
  //#region src/v4/node-adapter.ts
197
- const nodeModulePromiseCache = /* @__PURE__ */ new Map();
198
- const designSystemPromiseCache = /* @__PURE__ */ new Map();
221
+ const nodeModulePromiseCache = new BoundedCache(64);
222
+ const designSystemPromiseCache = new BoundedCache(64);
223
+ function fingerprintDesignDependencies(files) {
224
+ const hash = (0, node_crypto.createHash)("sha256");
225
+ for (const file of [...files].sort()) {
226
+ hash.update(file);
227
+ try {
228
+ hash.update((0, node_fs.readFileSync)(file));
229
+ } catch {
230
+ hash.update("missing");
231
+ }
232
+ }
233
+ return hash.digest("hex");
234
+ }
199
235
  function unique(values) {
200
236
  return Array.from(new Set(Array.from(values).filter(Boolean).map((value) => node_path.default.resolve(value))));
201
237
  }
@@ -267,14 +303,14 @@ function createDesignSystemCacheKey(css, bases) {
267
303
  function getTailwindV4DesignSystemCacheKey(source) {
268
304
  return createDesignSystemCacheKey(source.css, [source.base, ...source.baseFallbacks]);
269
305
  }
270
- async function createTailwindV4DesignSystem(source) {
306
+ async function createTailwindV4DesignSystem(source, onDependency) {
271
307
  const bases = unique([source.base, ...source.baseFallbacks]);
272
308
  if (bases.length === 0) throw new Error("No base directories provided for Tailwind CSS v4 design system.");
273
309
  const node = await loadTailwindV4NodeModule([source.projectRoot, ...bases]);
274
310
  let lastError;
275
311
  for (const base of bases) try {
276
312
  const prepared = prepareGenerationModuleRequests(source.css, base);
277
- return await withGenerationModuleCache(node, () => node.__unstable__loadDesignSystem(prepared.css, { base }), prepared.files);
313
+ return await withGenerationModuleCache(node, () => node.__unstable__loadDesignSystem(prepared.css, { base }), prepared.files, onDependency);
278
314
  } catch (error) {
279
315
  lastError = error;
280
316
  }
@@ -283,13 +319,20 @@ async function createTailwindV4DesignSystem(source) {
283
319
  }
284
320
  async function loadTailwindV4DesignSystem(source, options) {
285
321
  if (options?.cache === false) return createTailwindV4DesignSystem(source);
286
- const cacheKey = getTailwindV4DesignSystemCacheKey(source);
322
+ const cacheKey = JSON.stringify([source.projectRoot, getTailwindV4DesignSystemCacheKey(source)]);
287
323
  const cached = designSystemPromiseCache.get(cacheKey);
288
- if (cached) return cached;
289
- const promise = createTailwindV4DesignSystem(source);
290
- designSystemPromiseCache.set(cacheKey, promise);
291
- promise.catch(() => {
292
- if (designSystemPromiseCache.get(cacheKey) === promise) designSystemPromiseCache.delete(cacheKey);
324
+ if (cached && (cached.fingerprint === void 0 || cached.fingerprint === fingerprintDesignDependencies(cached.dependencies))) return cached.promise;
325
+ const dependencies = new Set(source.dependencies);
326
+ const promise = createTailwindV4DesignSystem(source, (file) => dependencies.add(file));
327
+ const entry = {
328
+ promise,
329
+ dependencies
330
+ };
331
+ designSystemPromiseCache.set(cacheKey, entry);
332
+ promise.then(() => {
333
+ entry.fingerprint = fingerprintDesignDependencies(dependencies);
334
+ }, () => {
335
+ if (designSystemPromiseCache.get(cacheKey) === entry) designSystemPromiseCache.delete(cacheKey);
293
336
  });
294
337
  return promise;
295
338
  }
@@ -2,9 +2,9 @@ import { createRequire, findPackageJSON } from "node:module";
2
2
  import { promises, readFileSync } from "node:fs";
3
3
  import path from "node:path";
4
4
  import process from "node:process";
5
+ import { createHash } from "node:crypto";
5
6
  import { fileURLToPath, pathToFileURL } from "node:url";
6
7
  import { AsyncLocalStorage } from "node:async_hooks";
7
- import { createHash } from "node:crypto";
8
8
  import { clearRequireCache } from "@tailwindcss/node/require-cache";
9
9
  import { createSourceScanPlan, expandSourceEntries as expandTailwindV4SourceEntries, expandSourceEntryBraces, expandSourceEntryBraces as expandTailwindV4SourceEntryBraces, groupSourceEntriesByBase as groupTailwindV4SourceEntriesByBase, isFileExcludedByTailwindSourceEntries, isFileExcludedByTailwindSourceEntries as isFileExcludedByTailwindV4SourceEntries, isFileMatchedByTailwindSourceEntries, mergeSourceEntries as mergeTailwindV4SourceEntries, normalizeGlobPattern, resolveSourceScanPath, resolveSourceScanPath as resolveSourceScanPath$1, resolveTailwindSourceEntry, toPosixPath } from "@weapp-tailwindcss/source-scan";
10
10
  import postcss from "postcss";
@@ -168,9 +168,45 @@ function prepareGenerationModuleRequests(css, base) {
168
168
  };
169
169
  }
170
170
  //#endregion
171
+ //#region src/v4/node-adapter/cache.ts
172
+ /** 模块与 design system 的跨会话复用有界,命中时更新最近使用顺序。 */
173
+ var BoundedCache = class extends Map {
174
+ limit;
175
+ constructor(limit) {
176
+ super();
177
+ this.limit = limit;
178
+ }
179
+ get(key) {
180
+ const value = super.get(key);
181
+ if (super.has(key)) {
182
+ super.delete(key);
183
+ super.set(key, value);
184
+ }
185
+ return value;
186
+ }
187
+ set(key, value) {
188
+ super.delete(key);
189
+ super.set(key, value);
190
+ while (this.size > this.limit) super.delete(this.keys().next().value);
191
+ return this;
192
+ }
193
+ };
194
+ //#endregion
171
195
  //#region src/v4/node-adapter.ts
172
- const nodeModulePromiseCache = /* @__PURE__ */ new Map();
173
- const designSystemPromiseCache = /* @__PURE__ */ new Map();
196
+ const nodeModulePromiseCache = new BoundedCache(64);
197
+ const designSystemPromiseCache = new BoundedCache(64);
198
+ function fingerprintDesignDependencies(files) {
199
+ const hash = createHash("sha256");
200
+ for (const file of [...files].sort()) {
201
+ hash.update(file);
202
+ try {
203
+ hash.update(readFileSync(file));
204
+ } catch {
205
+ hash.update("missing");
206
+ }
207
+ }
208
+ return hash.digest("hex");
209
+ }
174
210
  function unique(values) {
175
211
  return Array.from(new Set(Array.from(values).filter(Boolean).map((value) => path.resolve(value))));
176
212
  }
@@ -242,14 +278,14 @@ function createDesignSystemCacheKey(css, bases) {
242
278
  function getTailwindV4DesignSystemCacheKey(source) {
243
279
  return createDesignSystemCacheKey(source.css, [source.base, ...source.baseFallbacks]);
244
280
  }
245
- async function createTailwindV4DesignSystem(source) {
281
+ async function createTailwindV4DesignSystem(source, onDependency) {
246
282
  const bases = unique([source.base, ...source.baseFallbacks]);
247
283
  if (bases.length === 0) throw new Error("No base directories provided for Tailwind CSS v4 design system.");
248
284
  const node = await loadTailwindV4NodeModule([source.projectRoot, ...bases]);
249
285
  let lastError;
250
286
  for (const base of bases) try {
251
287
  const prepared = prepareGenerationModuleRequests(source.css, base);
252
- return await withGenerationModuleCache(node, () => node.__unstable__loadDesignSystem(prepared.css, { base }), prepared.files);
288
+ return await withGenerationModuleCache(node, () => node.__unstable__loadDesignSystem(prepared.css, { base }), prepared.files, onDependency);
253
289
  } catch (error) {
254
290
  lastError = error;
255
291
  }
@@ -258,13 +294,20 @@ async function createTailwindV4DesignSystem(source) {
258
294
  }
259
295
  async function loadTailwindV4DesignSystem(source, options) {
260
296
  if (options?.cache === false) return createTailwindV4DesignSystem(source);
261
- const cacheKey = getTailwindV4DesignSystemCacheKey(source);
297
+ const cacheKey = JSON.stringify([source.projectRoot, getTailwindV4DesignSystemCacheKey(source)]);
262
298
  const cached = designSystemPromiseCache.get(cacheKey);
263
- if (cached) return cached;
264
- const promise = createTailwindV4DesignSystem(source);
265
- designSystemPromiseCache.set(cacheKey, promise);
266
- promise.catch(() => {
267
- if (designSystemPromiseCache.get(cacheKey) === promise) designSystemPromiseCache.delete(cacheKey);
299
+ if (cached && (cached.fingerprint === void 0 || cached.fingerprint === fingerprintDesignDependencies(cached.dependencies))) return cached.promise;
300
+ const dependencies = new Set(source.dependencies);
301
+ const promise = createTailwindV4DesignSystem(source, (file) => dependencies.add(file));
302
+ const entry = {
303
+ promise,
304
+ dependencies
305
+ };
306
+ designSystemPromiseCache.set(cacheKey, entry);
307
+ promise.then(() => {
308
+ entry.fingerprint = fingerprintDesignDependencies(dependencies);
309
+ }, () => {
310
+ if (designSystemPromiseCache.get(cacheKey) === entry) designSystemPromiseCache.delete(cacheKey);
268
311
  });
269
312
  return promise;
270
313
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/engine",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "description": "Tailwind CSS 4 候选提取、源码扫描与样式生成引擎。",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",