|
1 | 1 | import path from 'node:path'
|
2 | 2 | import fs from 'node:fs'
|
3 |
| -import process from 'node:process' |
4 | 3 | import { gte } from 'semver'
|
5 | 4 | import type { PackageJson } from 'pkg-types'
|
6 |
| -import { defu } from 'defu' |
7 | 5 | import { inspectPostcssPlugin, inspectProcessTailwindFeaturesReturnContext } from './inspector'
|
8 | 6 | import { inspectPostcssPlugin as inspectPostcssPluginCompat, inspectProcessTailwindFeaturesReturnContext as inspectProcessTailwindFeaturesReturnContextCompat } from './inspector-postcss7-compat'
|
9 |
| -import type { InternalPatchOptions, PatchOptions } from '@/types' |
10 |
| -import { getDefaultPatchOptions } from '@/defaults' |
11 |
| -import { ensureFileContent, requireResolve } from '@/utils' |
12 |
| - |
13 |
| -export function getInstalledPkgJsonPath(options: PatchOptions = {}) { |
14 |
| - try { |
15 |
| - // const cwd = process.cwd() |
16 |
| - const tmpJsonPath = requireResolve(`tailwindcss/package.json`, { |
17 |
| - paths: options.paths, |
18 |
| - basedir: options.basedir, |
19 |
| - }) |
20 |
| - |
21 |
| - return tmpJsonPath |
22 |
| - // https://github.com/sonofmagic/weapp-tailwindcss-webpack-plugin |
23 |
| - // only tailwindcss version > 3.0.0 |
24 |
| - } |
25 |
| - catch (error) { |
26 |
| - if ((<Error & { code: string }>error).code === 'MODULE_NOT_FOUND') { |
27 |
| - console.warn('Can\'t find npm pkg: `tailwindcss`, Please ensure it has been installed!') |
28 |
| - } |
29 |
| - } |
30 |
| -} |
31 |
| - |
32 |
| -export function getPatchOptions(options: PatchOptions = {}) { |
33 |
| - return defu( |
34 |
| - options, |
35 |
| - { |
36 |
| - basedir: process.cwd(), |
37 |
| - }, |
38 |
| - getDefaultPatchOptions(), |
39 |
| - ) as InternalPatchOptions |
40 |
| -} |
41 |
| - |
42 |
| -export function createPatch(opt: InternalPatchOptions) { |
43 |
| - return () => { |
44 |
| - try { |
45 |
| - const pkgJsonPath = getInstalledPkgJsonPath(opt) |
46 |
| - return internalPatch(pkgJsonPath, opt) |
47 |
| - } |
48 |
| - catch (error) { |
49 |
| - console.warn(`patch tailwindcss failed:${(<Error>error).message}`) |
50 |
| - } |
51 |
| - } |
52 |
| -} |
| 7 | +import type { InternalPatchOptions } from '@/types' |
| 8 | +import { ensureFileContent } from '@/utils' |
53 | 9 |
|
54 | 10 | export function monkeyPatchForExposingContextV3(twDir: string, opt: InternalPatchOptions) {
|
55 | 11 | const processTailwindFeaturesFilePath = path.resolve(twDir, 'lib/processTailwindFeatures.js')
|
|
0 commit comments