8000 chore(deps): upgrade · sonofmagic/tailwindcss-mangle@0c1c9c4 · GitHub
Skip to content

Commit 0c1c9c4

Browse files
committed
chore(deps): upgrade
1 parent f0052ae commit 0c1c9c4

File tree

14 files changed

+273
-202
lines changed

14 files changed

+273
-202
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
"postcss7": "npm:postcss@7",
9595
"prettier": "^3.5.1",
9696
"rimraf": "^6.0.1",
97-
"rollup": "^4.34.7",
97+
"rollup": "^4.34.8",
9898
"set-value": "^4.1.0",
9999
"tailwindcss": "^3.4.17",
100100
"tailwindcss-patch": "workspace:*",

packages/config/src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { UserConfig } from './types'
22
import { createDefineConfig, loadConfig } from 'c12'
33
import fs from 'fs-extra'
44
import path from 'pathe'
5-
import { configName } from './constants'
5+
import { CONFIG_NAME } from './constants'
66
import { getDefaultUserConfig } from './defaults'
77

88
export function getConfig(cwd?: string) {
99
return loadConfig<UserConfig>({
10-
name: configName,
10+
name: CONFIG_NAME,
1111
defaults: {
1212
...getDefaultUserConfig(),
1313
},
@@ -19,7 +19,7 @@ export const defineConfig = createDefineConfig<UserConfig>()
1919

2020
export function initConfig(cwd: string) {
2121
return fs.outputFile(
22-
path.resolve(cwd, `${configName}.config.ts`),
22+
path.resolve(cwd, `${CONFIG_NAME}.config.ts`),
2323
`import { defineConfig } from 'tailwindcss-patch'
2424
2525
export default defineConfig({})

packages/config/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const configName = 'tailwindcss-mangle'
1+
export const CONFIG_NAME = 'tailwindcss-mangle'

packages/config/src/types.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,28 @@ export interface MangleUserConfig {
2424
preserveFunction?: string[]
2525
}
2626

27+
export interface TailwindcssV2PatchConfig {
28+
cwd?: string
29+
config?: string
30+
}
31+
export interface TailwindcssV3PatchConfig {
32+
cwd?: string
33+
config?: string
34+
}
35+
36+
export interface GlobEntry {
37+
/** Base path of the glob */
38+
base?: string
39+
/** Glob pattern */
40+
pattern: string
41+
}
42+
export interface TailwindcssV4PatchConfig {
43+
sources?: GlobEntry[]
44+
base?: string
45+
css?: string
46+
cssEntries?: string[]
47+
}
48+
2749
export interface PatchUserConfig {
2850
output?: {
2951
filename?: string
@@ -35,8 +57,10 @@ export interface PatchUserConfig {
3557
removeUniversalSelector?: boolean
3658
}
3759
tailwindcss?: {
38-
cwd?: string
39-
config?: string
60+
// only support jit mode
61+
v2?: TailwindcssV2PatchConfig
62+
v3?: TailwindcssV3PatchConfig
63+
v4?: TailwindcssV4PatchConfig
4064
}
4165
}
4266

packages/config/test/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { resolve } from 'pathe'
2-
import { configName } from '@/constants'
1+
import { CONFIG_NAME } from '@/constants'
32
import { getDefaultMangleUserConfig, getDefaultUserConfig } from '@/defaults'
43
import { getConfig, initConfig } from '@/index'
54
import { deleteAsync } from 'del'
65
import { existsSync } from 'fs-extra'
6+
import { resolve } from 'pathe'
77
import { fixturesRoot } from './utils'
88

99
describe('config', () => {
1010
it('0.default', async () => {
1111
const cwd = resolve(fixturesRoot, './config/0.default')
12-
const configPath = resolve(cwd, `${configName}.config.ts`)
12+
const configPath = resolve(cwd, `${CONFIG_NAME}.config.ts`)
1313
if (existsSync(configPath)) {
1414
await deleteAsync(configPath)
1515
}

packages/tailwindcss-patch/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"cac": "^6.7.14",
8080
"consola": "^3.4.0",
8181
"fs-extra": "^11.3.0",
82+
"local-pkg": "^1.0.0",
8283
"pathe": "^2.0.3",
8384
"postcss": "^8.5.2",
8485
"semver": "^7.7.1",

packages/tailwindcss-patch/src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import process from 'node:process'
2+
import { CONFIG_NAME, getConfig, initConfig } from '@tailwindcss-mangle/config'
23
import cac from 'cac'
3-
import { configName, getConfig, initConfig } from './config'
44
import { TailwindcssPatcher } from './core'
55
import { getPatchOptions } from './defaults'
66
import logger from './logger'
@@ -21,7 +21,7 @@ cli.command('install', 'patch install').action(() => {
2121

2222
cli.command('init').action(async () => {
2323
await init()
24-
logger.success(`✨ ${configName}.config.ts initialized!`)
24+
logger.success(`✨ ${CONFIG_NAME}.config.ts initialized!`)
2525
})
2626

2727
cli.command('extract').action(async () => {

packages/tailwindcss-patch/src/config.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/tailwindcss-patch/src/core/patcher.ts

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import type { UserConfig } from '../config'
1+
import type { UserConfig } from '@tailwindcss-mangle/config'
22
import type { CacheStrategy, InternalCacheOptions, InternalPatchOptions, PackageInfo, TailwindcssClassCache, TailwindcssPatcherOptions, TailwindcssRuntimeContext } from '../types'
33
import type { ExtractValidCandidatesOption } from './candidates'
44
import { createRequire } from 'node:module'
5+
import process from 'node:process'
56
import fs from 'fs-extra'
67
import { getPackageInfoSync } from 'local-pkg'
78
import path from 'pathe'
@@ -89,16 +90,55 @@ export class TailwindcssPatcher {
8990
return contexts.filter(x => isObject(x)).map(x => x.classCache)
9091
}
9192

92-
async getClassCacheSet(options?: { removeUniversalSelector?: boolean } & Partial<ExtractValidCandidatesOption>): Promise<Set<string>> {
93+
async getClassCacheSet(options?: UserConfig['patch']): Promise<Set<string>> {
9394
const classSet = new Set<string>()
95+
const { output, tailwindcss } = options ?? {}
9496
if (this.majorVersion === 4) {
95-
const candidates = await extractValidCandidates({
96-
base: options?.base,
97-
css: options?.css,
98-
sources: options?.sources,
99-
})
100-
for (const candidate of candidates) {
101-
classSet.add(candidate)
97+
const { v4 } = tailwindcss ?? {}
98+
if (Array.isArray(v4?.cssEntries)) {
99+
const results = (
100+
await Promise.all(
101+
v4
102+
.cssEntries
103+
.map(async (x) => {
104+
if (await fs.exists(x)) {
105+
const css = await fs.readFile(x, 'utf8')
106+
return css
107+
}
108+
return false
109+
}),
110+
)
111+
).filter(x => x) as string[]
112+
for (const css of results) {
113+
const candidates = await extractValidCandidates({
114+
base: v4?.base,
115+
css,
116+
sources: v4?.sources?.map((x) => {
117+
return {
118+
base: x.base ?? v4?.base ?? process.cwd(),
119+
pattern: x.pattern,
120+
}
121+
}),
122+
})
123+
for (const candidate of candidates) {
124+
classSet.add(candidate)
125+
}
126+
}
127+
}
128+
else {
129+
const candidates = await extractValidCandidates({
130+
base: v4?.base,
131+
css: v4?.css,
132+
sources: v4?.sources?.map((x) => {
133+
return {
134+
base: x.base ?? v4?.base ?? process.cwd(),
135+
pattern: x.pattern,
136+
}
137+
}),
138+
})
139+
for (const candidate of candidates) {
140+
classSet.add(candidate)
141+
}
102142
}
103143
}
104144
else {
@@ -108,7 +148,7 @@ export class TailwindcssPatcher {
108148
const keys = classCacheMap.keys()
109149
for (const key of keys) {
110150
const v = key.toString()
111-
if (options?.removeUniversalSelector && v === '*') {
151+
if (output?.removeUniversalSelector && v === '*') {
112152
continue
113153
}
114154
classSet.add(v)
@@ -122,10 +162,12 @@ export class TailwindcssPatcher {
122162
/**
123163
* @description 在多个 tailwindcss 上下文时,这个方法将被执行多次,所以策略上应该使用 append
124164
*/
125-
async getClassSet(options?: { cacheStrategy?: CacheStrategy, removeUniversalSelector?: boolean }) {
126-
const { cacheStrategy = this.cacheOptions.strategy ?? 'merge', removeUniversalSelector = true } = options ?? {}
165+
async getClassSet(options?: UserConfig['patch']) {
166+
const { output, tailwindcss } = options ?? {}
167+
const cacheStrategy = this.cacheOptions.strategy ?? 'merge'
127168
const set = await this.getClassCacheSet({
128-
removeUniversalSelector,
169+
output,
170+
tailwindcss,
129171
})
130172
if (cacheStrategy === 'overwrite') {
131173
set.size > 0 && this.setCache(set)
@@ -146,7 +188,7 @@ export class TailwindcssPatcher {
146188
async extract(options?: UserConfig['patch']) {
147189
const { output, tailwindcss } = options ?? {}
148190
if (output && tailwindcss) {
149-
const { removeUniversalSelector, filename, loose } = output
191+
const { filename, loose } = output
150192

151193
if (this.majorVersion === 3) {
152194
await processTailwindcss({
@@ -156,7 +198,8 @@ export class TailwindcssPatcher {
156198
}
157199

158200
const set = await this.getClassSet({
159-
removeUniversalSelector,
201+
output,
202+
tailwindcss,
160203
})
161204
if (filename) {
162205
const classList = [...set]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { defineConfig } from './config'
21
export * from './core'
32
export { default as logger } from './logger'
43
export * from './types'
4+
export { defineConfig } from '@tailwindcss-mangle/config'
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[
2-
"text-[99px]",
32
"*",
3+
"text-[99px]",
44
"text-[100px]"
55
]

packages/tailwindcss-patch/tsup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export default defineConfig({
88
dts: true,
99
cjsInterop: true,
1010
splitting: true,
11+
external: ['tailwindcss', '@tailwindcss/node', '@tailwindcss/oxide'],
1112
})

0 commit comments

Comments
 (0)