@weapp-tailwindcss/merge 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-tailwindcss/merge",
3
3
  "type": "module",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "description": "weapp-tailwindcss",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -38,16 +38,18 @@
38
38
  }
39
39
  },
40
40
  "files": [
41
- "dist"
41
+ "dist",
42
+ "scripts"
42
43
  ],
43
44
  "dependencies": {
44
45
  "class-variance-authority": "^0.7.1",
45
46
  "clsx": "^2.1.1",
47
+ "semver": "^7.7.1",
46
48
  "tailwind-merge": "^3.0.2",
47
49
  "tailwind-merge-v2": "npm:tailwind-merge@^2.6.0"
48
50
  },
49
51
  "devDependencies": {
50
- "weapp-tailwindcss": "4.0.5"
52
+ "weapp-tailwindcss": "4.0.6"
51
53
  },
52
54
  "scripts": {
53
55
  "dev": "tsup --watch --sourcemap",
@@ -56,7 +58,8 @@
56
58
  "test:dev": "vitest",
57
59
  "release": "pnpm publish",
58
60
  "lint": "eslint .",
59
- "lint:fix": "eslint . --fix"
61
+ "lint:fix": "eslint . --fix",
62
+ "postinstall": "node scripts/postinstall.js"
60
63
  },
61
64
  "main": "./dist/index.cjs",
62
65
  "module": "./dist/index.js",
@@ -0,0 +1,64 @@
1
+ import fs from 'node:fs'
2
+ import { createRequire } from 'node:module'
3
+ import path from 'node:path'
4
+ import process from 'node:process'
5
+ import satisfies from 'semver/functions/satisfies.js'
6
+
7
+ const require = createRequire(import.meta.url)
8
+
9
+ function getPackageVersion(pkgName) {
10
+ try {
11
+ const pkgPath = path.join(process.cwd(), 'node_modules', pkgName, 'package.json')
12
+ if (fs.existsSync(pkgPath)) {
13
+ const pkg = require(pkgPath)
14
+ return pkg.version
15
+ }
16
+
17
+ // 尝试从 package.json 读取
18
+ const rootPkgPath = path.join(process.cwd(), 'package.json')
19
+ if (fs.existsSync(rootPkgPath)) {
20
+ const rootPkg = require(rootPkgPath)
21
+ return rootPkg.dependencies?.[pkgName] || rootPkg.devDependencies?.[pkgName] || null
22
+ }
23
+ }
24
+ catch (error) {
25
+ console.error(`Error reading ${pkgName} version:`, error)
26
+ }
27
+ return null
28
+ }
29
+
30
+ function main() {
31
+ const distDir = path.resolve(import.meta.dirname, '../dist')
32
+
33
+ if (!fs.existsSync(distDir)) {
34
+ return
35
+ }
36
+
37
+ const tailwindVersion = getPackageVersion('tailwindcss')
38
+
39
+ if (!tailwindVersion) {
40
+ console.warn('tailwindcss not found in the project. Skipping swicth version of tailwind-merge.')
41
+ return
42
+ }
43
+
44
+ let targetVersion = null
45
+
46
+ if (satisfies(tailwindVersion, '^4.0.0')) {
47
+ targetVersion = 4
48
+ }
49
+ else {
50
+ targetVersion = 3
51
+ }
52
+ console.log(`tailwindcss version: ${tailwindVersion}`)
53
+ console.log(`Switch version of tailwind-merge to v${targetVersion - 1}.`)
54
+ for (const ext of ['cjs', 'd.cts', 'd.ts', 'js']) {
55
+ const file = `v${targetVersion}.${ext}`
56
+ fs.copyFileSync(
57
+ path.resolve(distDir, file),
58
+ path.resolve(distDir, `index.${ext}`),
59
+ )
60
+ }
61
+ console.log('Switch version of tailwind-merge success.')
62
+ }
63
+
64
+ main()