Skip to content

Commit 57f8ce3

Browse files
committed
chore: use tsx instead of jiti
1 parent 6635627 commit 57f8ce3

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

packages/tailwindcss-patch/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@
7979
"cac": "^6.7.14",
8080
"consola": "^3.2.3",
8181
"fs-extra": "^11.2.0",
82-
"jiti": "^2.3.3",
8382
"lilconfig": "^3.1.2",
8483
"pathe": "^1.1.2",
8584
"postcss": "^8.4.47",
8685
"resolve": "^1.22.8",
87-
"semver": "^7.6.3"
86+
"semver": "^7.6.3",
87+
"tsx": "^4.19.2"
8888
}
8989
}

packages/tailwindcss-patch/src/babel/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import _babelTraverse from '@babel/traverse'
33

44
export { parse, parseExpression } from '@babel/parser'
55

6-
function _interopDefaultCompat(e: any) {
6+
export function _interopDefaultCompat(e: any) {
77
return e && typeof e === 'object' && 'default' in e ? e.default : e
88
}
99

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import type { UserConfig } from '../config'
22
import type { CacheStrategy, InternalCacheOptions, InternalPatchOptions, PackageInfo, TailwindcssClassCache, TailwindcssPatcherOptions, TailwindcssRuntimeContext } from '../types'
3+
import { createRequire } from 'node:module'
34
import fs from 'fs-extra'
45
import path from 'pathe'
56
import { getPatchOptions } from '../defaults'
7+
import logger from '../logger'
68
import { getPackageInfoSync, isObject } from '../utils'
79
import { CacheManager, getCacheOptions } from './cache'
810
import { processTailwindcss } from './postcss'
911
import { internalPatch } from './runtime'
1012

13+
const require = createRequire(import.meta.url)
1114
export class TailwindcssPatcher {
1215
public rawOptions: TailwindcssPatcherOptions
1316
public cacheOptions: InternalCacheOptions
@@ -32,7 +35,7 @@ export class TailwindcssPatcher {
3235
return internalPatch(this.packageInfo?.packageJsonPath, this.patchOptions)
3336
}
3437
catch (error) {
35-
console.error(`patch tailwindcss failed: ${(<Error>error).message}`)
38+
logger.error(`patch tailwindcss failed: ${(<Error>error).message}`)
3639
}
3740
}
3841
}
@@ -61,7 +64,6 @@ export class TailwindcssPatcher {
6164
}
6265
}
6366
if (injectFilePath) {
64-
// eslint-disable-next-line ts/no-require-imports
6567
const mo = require(injectFilePath)
6668
if (mo.contextRef) {
6769
return mo.contextRef.value
@@ -130,7 +132,9 @@ export class TailwindcssPatcher {
130132
if (filename) {
131133
await fs.ensureDir(path.dirname(filename))
132134
const classList = [...set]
133-
fs.writeFileSync(filename, JSON.stringify(classList, null, loose ? 2 : undefined), 'utf8')
135+
await fs.outputJSON(filename, classList, {
136+
spaces: loose ? 2 : undefined,
137+
})
134138
return filename
135139
}
136140
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { createRequire } from 'node:module'
12
import process from 'node:process'
23
import { defu } from '@tailwindcss-mangle/shared'
34
import { lilconfig } from 'lilconfig'
45
import path from 'pathe'
56
import postcss from 'postcss'
6-
import { jiti } from '../jiti'
77
import { requireResolve } from '../utils'
88

9+
const require = createRequire(import.meta.url)
910
export interface ProcessTailwindcssOptions {
1011
cwd?: string
1112
config?: string
@@ -19,6 +20,7 @@ export async function processTailwindcss(options: ProcessTailwindcssOptions) {
1920
// 没有具体指定的话,就走下面的分支
2021
if (!(typeof config === 'string' && path.isAbsolute(config))) {
2122
const moduleName = 'tailwind'
23+
const tsx = (await import('tsx/cjs/api')).require
2224
const result = await lilconfig('tailwindcss', {
2325
searchPlaces: [
2426
`${moduleName}.config.js`,
@@ -30,12 +32,12 @@ export async function processTailwindcss(options: ProcessTailwindcssOptions) {
3032
],
3133
loaders: {
3234
// 默认支持 js 和 cjs 2种格式
33-
'.js': jiti,
34-
'.cjs': jiti,
35-
'.mjs': jiti,
36-
'.ts': jiti,
37-
'.cts': jiti,
38-
'.mts': jiti,
35+
'.js': tsx,
36+
'.cjs': tsx,
37+
'.mjs': tsx,
38+
'.ts': tsx,
39+
'.cts': tsx,
40+
'.mts': tsx,
3941
},
4042
}).search(cwd)
4143
if (!result) {
@@ -47,7 +49,6 @@ export async function processTailwindcss(options: ProcessTailwindcssOptions) {
4749
basedir: cwd,
4850
})
4951
return await postcss([
50-
// eslint-disable-next-line ts/no-require-imports
5152
require(id)({
5253
config,
5354
}),

packages/tailwindcss-patch/src/jiti.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)