Skip to content

Commit c2f9b03

Browse files
committed
chore: add ctx type
1 parent f4c0895 commit c2f9b03

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

packages/tailwindcss-patch/src/exposeContext.ts

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import path from 'node:path'
22
import fs from 'node:fs'
3-
import type { Rule } from 'postcss'
3+
import type { TailwindcssClassCache, TailwindcssRuntimeContext } from './type'
44
import { requireResolve } from './utils'
55

6+
67
export function getTailwindcssEntry(basedir: string = process.cwd()) {
78
return requireResolve('tailwindcss')
89
}
910

10-
export function getContexts(basedir?: string) {
11+
export function getContexts(basedir?: string): TailwindcssRuntimeContext[] {
1112
const twPath = getTailwindcssEntry(basedir)
1213

1314
const distPath = path.dirname(twPath)
@@ -19,26 +20,17 @@ export function getContexts(basedir?: string) {
1920

2021
const mo = require(injectFilePath)
2122
if (mo.contextRef) {
22-
return mo.contextRef.value as any[]
23+
return mo.contextRef.value
2324
}
2425
return []
2526
}
2627

27-
export function getClassCaches(basedir?: string): Map<
28-
string,
29-
(
30-
| {
31-
layer: string
32-
options: Record<string, any>
33-
sort: Record<string, any>
34-
}
35-
| Rule
36-
)[]
37-
>[] {
28+
export function getClassCaches(basedir?: string): TailwindcssClassCache[] {
3829
const contexts = getContexts(basedir)
39-
return (contexts as any[]).map((x) => x.classCache)
30+
return contexts.map((x) => x.classCache)
4031
}
4132

33+
4234
export function getClassCacheSet(basedir?: string): Set<string> {
4335
const classCaches = getClassCaches(basedir)
4436
const classSet = new Set<string>()

packages/tailwindcss-patch/src/type.ts

+51
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { Rule, Node } from 'postcss'
2+
import type { Config } from 'tailwindcss'
13
export type CacheStrategy = 'merge' | 'overwrite'
24

35
export interface CacheOptions {
@@ -29,3 +31,52 @@ export interface TailwindcssPatcherOptions {
2931
cache?: CacheOptions | boolean
3032
patch?: PatchOptions
3133
}
34+
35+
36+
export type TailwindcssClassCache = Map<
37+
string,
38+
(
39+
| {
40+
layer: string
41+
options: Record<string, any>
42+
sort: Record<string, any>
43+
}
44+
| Rule
45+
)[]
46+
>
47+
48+
export type TailwindcssRuntimeContext = {
49+
applyClassCache: Map<any, any>
50+
candidateRuleCache: Map<string | String, Set<[{
51+
arbitrary: any
52+
index: any
53+
layer: string
54+
options: any[]
55+
parallelIndex: any
56+
parentLayer: string
57+
variants: any
58+
}, Node]>>
59+
candidateRuleMap: Map<string | String, [object, Node][]>
60+
changedContent: any[]
61+
classCache: TailwindcssClassCache
62+
disposables: any[]
63+
getClassList: Function
64+
getClassOrder: Function
65+
getVariants: Function
66+
markInvalidUtilityCandidate: Function
67+
markInvalidUtilityNode: Function
68+
notClassCache: Set<String>
69+
offsets: {
70+
layerPositions: object
71+
offsets: object
72+
reservedVariantBits: any
73+
variantOffsets: Map<string, any>
74+
}
75+
postCssNodeCache: Map<object, [Node]>
76+
ruleCache: Set<[object, Node]>
77+
stylesheetCache: Record<string, Set<any>>
78+
tailwindConfig: Config
79+
userConfigPath: string | null
80+
variantMap: Map<string, [[object, Function]]>
81+
variantOptions: Map<string, object>
82+
}

0 commit comments

Comments
 (0)