|
1 | 1 | // @ts-check |
2 | 2 | import * as path from 'node:path' |
| 3 | +import { pathToFileURL } from 'node:url' |
3 | 4 | import clearModule from 'clear-module' |
| 5 | +import { createJiti } from 'jiti' |
4 | 6 | // @ts-ignore |
5 | 7 | import { generateRules as generateRulesFallback } from 'tailwindcss-v3/lib/lib/generateRules' |
6 | 8 | // @ts-ignore |
7 | 9 | import { createContext as createContextFallback } from 'tailwindcss-v3/lib/lib/setupContextUtils' |
8 | | -import loadConfigFallback from 'tailwindcss-v3/loadConfig' |
9 | 10 | import resolveConfigFallback from 'tailwindcss-v3/resolveConfig' |
10 | 11 | import type { RequiredConfig } from 'tailwindcss-v3/types/config.js' |
11 | 12 | import type { UnifiedApi } from '../types' |
@@ -36,24 +37,26 @@ export async function loadV3(pkgDir: string | null, jsConfig: string | null): Pr |
36 | 37 | let createContext = createContextFallback |
37 | 38 | let generateRules: GenerateRules = generateRulesFallback |
38 | 39 | let resolveConfig = resolveConfigFallback |
39 | | - let loadConfig = loadConfigFallback |
40 | 40 | let tailwindConfig: RequiredConfig = { content: [] } |
41 | 41 |
|
42 | 42 | try { |
43 | 43 | if (pkgDir) { |
44 | 44 | resolveConfig = require(path.join(pkgDir, 'resolveConfig')) |
45 | 45 | createContext = require(path.join(pkgDir, 'lib/lib/setupContextUtils')).createContext |
46 | 46 | generateRules = require(path.join(pkgDir, 'lib/lib/generateRules')).generateRules |
47 | | - // Prior to `tailwindcss@3.3.0` this won't exist so we load it last |
48 | | - loadConfig = require(path.join(pkgDir, 'loadConfig')) |
49 | 47 | } |
50 | 48 | } catch {} |
51 | 49 |
|
52 | 50 | try { |
53 | 51 | if (jsConfig) { |
54 | 52 | clearModule(jsConfig) |
55 | | - let loadedConfig = loadConfig(jsConfig) |
56 | | - tailwindConfig = loadedConfig.default ?? loadedConfig |
| 53 | + let jiti = createJiti(import.meta.url, { |
| 54 | + moduleCache: false, |
| 55 | + fsCache: false, |
| 56 | + interopDefault: true, |
| 57 | + }) |
| 58 | + let url = pathToFileURL(jsConfig) |
| 59 | + tailwindConfig = await jiti.import<RequiredConfig>(url.href, { default: true }) |
57 | 60 | } |
58 | 61 | } catch (err) { |
59 | 62 | console.error(`Unable to load your Tailwind CSS v3 config: ${jsConfig}`) |
|
0 commit comments