Skip to content

Commit bcbebab

Browse files
committed
chore(tailwindcss-patch): commit patches foldor
1 parent e80eb67 commit bcbebab

File tree

9 files changed

+83
-74
lines changed

9 files changed

+83
-74
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export * from './tw-patcher'
2-
export * from './inspector'
2+
export * from './patches'
33
export * from './runtime-patcher'
44
export * from './cache'
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import path from 'node:path'
2+
import fs from 'node:fs'
3+
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from './postcss'
4+
import { inspectPostcssPlugin as inspectPostcssPluginCompat, inspectProcessTailwindFeaturesReturnContext as inspectProcessTailwindFeaturesReturnContextCompat } from './postcss-compat'
5+
import type { InternalPatchOptions } from '@/types'
6+
import { ensureFileContent } from '@/utils'
7+
8+
export function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions) {
9+
const processTailwindFeaturesFilePath = path.resolve(twDir, 'lib/processTailwindFeatures.js')
10+
11+
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath)
12+
const result: { processTailwindFeatures?: string, plugin?: string } & Record<string, any> = {}
13+
if (processTailwindFeaturesContent) {
14+
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent)
15+
if (!hasPatched && opt.overwrite) {
16+
fs.writeFileSync(processTailwindFeaturesFilePath, code, {
17+
encoding: 'utf8',
18+
})
19+
console.log('patch tailwindcss processTailwindFeatures for return content successfully!')
20+
}
21+
result.processTailwindFeatures = code
22+
}
23+
24+
const pluginFilePath = path.resolve(twDir, 'lib/plugin.js')
25+
const indexFilePath = path.resolve(twDir, 'lib/index.js')
26+
const pluginContent = ensureFileContent([pluginFilePath, indexFilePath])
27+
if (pluginContent) {
28+
const { code, hasPatched } = inspectPostcssPlugin(pluginContent)
29+
if (!hasPatched && opt.overwrite) {
30+
fs.writeFileSync(pluginFilePath, code, {
31+
encoding: 'utf8',
32+
})
33+
console.log('patch tailwindcss for expose runtime content successfully!')
34+
}
35+
result.plugin = code
36+
}
37+
38+
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result)
39+
return result
40+
}
41+
42+
export function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions) {
43+
const processTailwindFeaturesFilePath = path.resolve(twDir, 'lib/jit/processTailwindFeatures.js')
44+
45+
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath)
46+
const result: { processTailwindFeatures?: string, plugin?: string } & Record<string, any> = {}
47+
if (processTailwindFeaturesContent) {
48+
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContextCompat(processTailwindFeaturesContent)
49+
if (!hasPatched && opt.overwrite) {
50+
fs.writeFileSync(processTailwindFeaturesFilePath, code, {
51+
encoding: 'utf8',
52+
})
53+
console.log('patch tailwindcss processTailwindFeatures for return content successfully!')
54+
}
55+
result.processTailwindFeatures = code
56+
}
57+
58+
const indexFilePath = path.resolve(twDir, 'lib/jit/index.js')
59+
const pluginContent = ensureFileContent([indexFilePath])
60+
if (pluginContent) {
61+
const { code, hasPatched } = inspectPostcssPluginCompat(pluginContent)
62+
if (!hasPatched && opt.overwrite) {
63+
fs.writeFileSync(indexFilePath, code, {
64+
encoding: 'utf8',
65+
})
66+
console.log('patch tailwindcss for expose runtime content successfully!')
67+
}
68+
result.plugin = code
69+
}
70+
71+
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result)
72+
return result
73+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './exportContext'

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

Lines changed: 2 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,9 @@
11
import path from 'node:path'
2-
import fs from 'node:fs'
32
import { gte } from 'semver'
43
import type { PackageJson } from 'pkg-types'
5-
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from './inspector'
6-
import { inspectPostcssPlugin as inspectPostcssPluginCompat, inspectProcessTailwindFeaturesReturnContext as inspectProcessTailwindFeaturesReturnContextCompat } from './inspector-postcss7-compat'
7-
import type { InternalPatchOptions } from '@/types'
8-
import { ensureFileContent } from '@/utils'
9-
10-
export function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions) {
11-
const processTailwindFeaturesFilePath = path.resolve(twDir, 'lib/processTailwindFeatures.js')
12-
13-
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath)
14-
const result: { processTailwindFeatures?: string, plugin?: string } & Record<string, any> = {}
15-
if (processTailwindFeaturesContent) {
16-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContext(processTailwindFeaturesContent)
17-
if (!hasPatched && opt.overwrite) {
18-
fs.writeFileSync(processTailwindFeaturesFilePath, code, {
19-
encoding: 'utf8',
20-
})
21-
console.log('patch tailwindcss processTailwindFeatures for return content successfully!')
22-
}
23-
result.processTailwindFeatures = code
24-
}
25-
26-
const pluginFilePath = path.resolve(twDir, 'lib/plugin.js')
27-
const indexFilePath = path.resolve(twDir, 'lib/index.js')
28-
const pluginContent = ensureFileContent([pluginFilePath, indexFilePath])
29-
if (pluginContent) {
30-
const { code, hasPatched } = inspectPostcssPlugin(pluginContent)
31-
if (!hasPatched && opt.overwrite) {
32-
fs.writeFileSync(pluginFilePath, code, {
33-
encoding: 'utf8',
34-
})
35-
console.log('patch tailwindcss for expose runtime content successfully!')
36-
}
37-
result.plugin = code
38-
}
39-
40-
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result)
41-
return result
42-
}
4+
import { monkeyPatchForExposingContextV2, monkeyPatchForExposingContextV3 } from './patches'
435

44-
export function monkeyPatchForExposingContextV2(twDir: string, opt: InternalPatchOptions) {
45-
const processTailwindFeaturesFilePath = path.resolve(twDir, 'lib/jit/processTailwindFeatures.js')
46-
47-
const processTailwindFeaturesContent = ensureFileContent(processTailwindFeaturesFilePath)
48-
const result: { processTailwindFeatures?: string, plugin?: string } & Record<string, any> = {}
49-
if (processTailwindFeaturesContent) {
50-
const { code, hasPatched } = inspectProcessTailwindFeaturesReturnContextCompat(processTailwindFeaturesContent)
51-
if (!hasPatched && opt.overwrite) {
52-
fs.writeFileSync(processTailwindFeaturesFilePath, code, {
53-
encoding: 'utf8',
54-
})
55-
console.log('patch tailwindcss processTailwindFeatures for return content successfully!')
56-
}
57-
result.processTailwindFeatures = code
58-
}
59-
60-
const indexFilePath = path.resolve(twDir, 'lib/jit/index.js')
61-
const pluginContent = ensureFileContent([indexFilePath])
62-
if (pluginContent) {
63-
const { code, hasPatched } = inspectPostcssPluginCompat(pluginContent)
64-
if (!hasPatched && opt.overwrite) {
65-
fs.writeFileSync(indexFilePath, code, {
66-
encoding: 'utf8',
67-
})
68-
console.log('patch tailwindcss for expose runtime content successfully!')
69-
}
70-
result.plugin = code
71-
}
72-
73-
opt.custom && typeof opt.custom === 'function' && opt.custom(twDir, result)
74-
return result
75-
}
6+
import type { InternalPatchOptions } from '@/types'
767

778
export function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined {
789
if (pkgJsonPath) {

packages/tailwindcss-patch/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export interface PatchOptions {
2525
paths?: string[]
2626
basedir?: string
2727
custom?: (dir: string, ctx: Record<string, any>) => void
28+
applyPatches?: {
29+
exportContext?: boolean
30+
extendLengthUnits?: boolean
31+
}
2832
}
2933

3034
export interface InternalPatchOptions {

packages/tailwindcss-patch/test/inspector.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import path from 'node:path'
22
import fs from 'node:fs'
3-
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from '@/core'
3+
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from '@/core/patches/exportContext/postcss'
44

55
const tailwindcssCasePath = path.resolve(__dirname, 'fixtures')
66
const twltsLibPath = path.resolve(tailwindcssCasePath, 'versions/3.3.1/lib')

packages/tailwindcss-patch/test/postcss7-compat.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getTestCase } from './utils'
2-
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from '@/core/inspector-postcss7-compat'
2+
import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from '@/core/patches/exportContext/postcss-compat'
33

44
describe('postcss7-compat', () => {
55
it('processTailwindFeatures patch', async () => {

0 commit comments

Comments
 (0)