|
1 | 1 | import path from 'node:path'
|
2 |
| -import fs from 'node:fs' |
3 | 2 | import { gte } from 'semver'
|
4 | 3 | 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' |
43 | 5 |
|
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' |
76 | 7 |
|
77 | 8 | export function internalPatch(pkgJsonPath: string | undefined, options: InternalPatchOptions): any | undefined {
|
78 | 9 | if (pkgJsonPath) {
|
|
0 commit comments