Skip to content

Commit e73b989

Browse files
committed
chore: sync-template-deps
1 parent 86dd639 commit e73b989

File tree

31 files changed

+841
-82
lines changed

31 files changed

+841
-82
lines changed

scripts/sync-template-deps.ts

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ interface TargetPackage {
2828
name: string
2929
version: string
3030
range: string
31+
addIfMissing?: 'dependencies' | 'devDependencies'
32+
forceInclude?: boolean
3133
}
3234

3335
const TEMPLATES_DIR = path.join(ROOT, 'templates')
3436
const WORKSPACE_MANIFEST = path.join(ROOT, 'pnpm-workspace.yaml')
3537
const tailwindVersionCache = new Map<string, string>()
3638

37-
function readRootWeappTailwindcssVersion(): string {
38-
const pkgPath = path.join(ROOT, 'packages', 'weapp-tailwindcss', 'package.json')
39+
function readWorkspacePackageVersion(relativeDir: string): string {
40+
const pkgPath = path.join(ROOT, relativeDir, 'package.json')
3941
const pkgRaw = readFileSync(pkgPath, 'utf8')
4042
const pkg = JSON.parse(pkgRaw) as { version: string }
4143
return pkg.version
@@ -78,13 +80,22 @@ async function fetchTailwindVersion(pkgName: string, major: number): Promise<str
7880
}
7981

8082
async function resolveBaseTargets(): Promise<TargetPackage[]> {
81-
const weappTailwindcssVersion = readRootWeappTailwindcssVersion()
83+
const weappTailwindcssVersion = readWorkspacePackageVersion(path.join('packages', 'weapp-tailwindcss'))
84+
const mergeVersion = readWorkspacePackageVersion(path.join('packages', 'merge'))
8285
const weappIdeCliVersion = await fetchLatestVersion('weapp-ide-cli')
8386
return [
8487
{
8588
name: 'weapp-tailwindcss',
8689
version: weappTailwindcssVersion,
8790
range: `^${weappTailwindcssVersion}`,
91+
addIfMissing: 'devDependencies',
92+
},
93+
{
94+
name: '@weapp-tailwindcss/merge',
95+
version: mergeVersion,
96+
range: `^${mergeVersion}`,
97+
addIfMissing: 'dependencies',
98+
forceInclude: true,
8899
},
89100
{
90101
name: 'weapp-ide-cli',
@@ -144,21 +155,53 @@ function buildVersionRange(current: string | undefined, target: TargetPackage):
144155
return `${prefix || ''}${targetVersion}`
145156
}
146157

158+
function hasPackageReference(pkg: PackageJson, name: string): boolean {
159+
const deps = pkg.dependencies ?? {}
160+
const devDeps = pkg.devDependencies ?? {}
161+
return Boolean((deps as Record<string, string>)[name] ?? (devDeps as Record<string, string>)[name])
162+
}
163+
164+
function ensureSection(pkg: PackageJson, field: 'dependencies' | 'devDependencies'): Record<string, string> {
165+
const section = pkg[field]
166+
if (section && typeof section === 'object') {
167+
return section as Record<string, string>
168+
}
169+
const created: Record<string, string> = {}
170+
pkg[field] = created
171+
return created
172+
}
173+
147174
function updateDependencyRange(pkg: PackageJson, targets: TargetPackage[]): boolean {
148175
let updated = false
149176
for (const field of ['dependencies', 'devDependencies'] as const) {
150177
const section = pkg[field]
151178
if (!section || typeof section !== 'object') {
152179
continue
153180
}
181+
const typedSection = section as Record<string, string>
154182
for (const target of targets) {
155-
if (target.name in section) {
156-
const current = section[target.name]
157-
const next = buildVersionRange(current, target)
158-
if (current !== next) {
159-
section[target.name] = next
160-
updated = true
161-
}
183+
if (!(target.name in typedSection)) {
184+
continue
185+
}
186+
const current = typedSection[target.name]
187+
const next = buildVersionRange(current, target)
188+
if (current !== next) {
189+
typedSection[target.name] = next
190+
updated = true
191+
}
192+
}
193+
}
194+
195+
for (const target of targets) {
196+
const existsInDeps = hasPackageReference(pkg, target.name)
197+
if (existsInDeps) {
198+
continue
199+
}
200+
if (target.addIfMissing) {
201+
const newSection = ensureSection(pkg, target.addIfMissing)
202+
if (newSection[target.name] !== target.range) {
203+
newSection[target.name] = target.range
204+
updated = true
162205
}
163206
}
164207
}
@@ -243,14 +286,8 @@ function lockNeedsUpdate(templateDir: string, manager: ManagerInfo, targets: Tar
243286
}
244287
}
245288

246-
function hasPackageReference(pkg: PackageJson, name: string): boolean {
247-
const deps = pkg.dependencies ?? {}
248-
const devDeps = pkg.devDependencies ?? {}
249-
return Boolean((deps as Record<string, string>)[name] ?? (devDeps as Record<string, string>)[name])
250-
}
251-
252289
function filterTargetsForPackage(pkg: PackageJson, targets: TargetPackage[]): TargetPackage[] {
253-
return targets.filter(target => hasPackageReference(pkg, target.name))
290+
return targets.filter(target => target.forceInclude || hasPackageReference(pkg, target.name))
254291
}
255292

256293
function dedupeTargets(targets: TargetPackage[]): TargetPackage[] {

templates/mpx-tailwindcss-v4/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
"vue-demi": "^0.14.6",
2222
"vue-i18n": "^8.27.2",
2323
"vue-i18n-bridge": "^9.2.2",
24-
"vue-router": "^3.1.3"
24+
"vue-router": "^3.1.3",
25+
"@weapp-tailwindcss/merge": "^2.0.1"
2526
},
2627
"devDependencies": {
2728
"@babel/core": "^7.28.3",

templates/mpx-tailwindcss-v4/yarn.lock

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,16 +2734,16 @@
27342734
resolved "https://registry.npmmirror.com/@vue/web-component-wrapper/-/web-component-wrapper-1.3.0.tgz#b6b40a7625429d2bd7c2281ddba601ed05dc7f1a"
27352735
integrity sha512-Iu8Tbg3f+emIIMmI2ycSI8QcEuAUgPTgHwesDU1eKMLE4YC/c/sFbGc70QgMq31ijRftV0R7vCm9co6rldCeOA==
27362736

2737+
"@weapp-core/escape@^5.0.1", "@weapp-core/escape@~5.0.1":
2738+
version "5.0.1"
2739+
resolved "https://registry.yarnpkg.com/@weapp-core/escape/-/escape-5.0.1.tgz#b4b42ff03a552fce0fb7cdf0f998bcf639469ddb"
2740+
integrity sha512-BIHEQvlqWU+ofCdh+w08wzV9GjS+5Nw5Rf6XGxni5/15srShdcRPbSWpDAw00toTJkJDG4+UNjzOB+rHdcxCdg==
2741+
27372742
"@weapp-core/escape@~4.0.1":
27382743
version "4.0.1"
27392744
resolved "https://registry.npmmirror.com/@weapp-core/escape/-/escape-4.0.1.tgz#00f80bbdc5ac32456a4f180b8c6b2449854f292a"
27402745
integrity sha512-FuO9zTs/8VMhoZ+sZkMEMipcHd9FZhxstdhg9+Z3JlTgxMFAIvhBFOuFjM2bUyjDJ7O21nr9podHDjVjcVYu4Q==
27412746

2742-
"@weapp-core/escape@~5.0.1":
2743-
version "5.0.1"
2744-
resolved "https://registry.yarnpkg.com/@weapp-core/escape/-/escape-5.0.1.tgz#b4b42ff03a552fce0fb7cdf0f998bcf639469ddb"
2745-
integrity sha512-BIHEQvlqWU+ofCdh+w08wzV9GjS+5Nw5Rf6XGxni5/15srShdcRPbSWpDAw00toTJkJDG4+UNjzOB+rHdcxCdg==
2746-
27472747
"@weapp-core/logger@^2.0.0":
27482748
version "2.0.0"
27492749
resolved "https://registry.npmmirror.com/@weapp-core/logger/-/logger-2.0.0.tgz#4fede381ddc809d5e6c05f4e923701ebeb47a9f4"
@@ -2764,6 +2764,20 @@
27642764
consola "^3.4.2"
27652765
picocolors "^1.1.1"
27662766

2767+
"@weapp-tailwindcss/merge@^2.0.1":
2768+
version "2.0.1"
2769+
resolved "https://registry.yarnpkg.com/@weapp-tailwindcss/merge/-/merge-2.0.1.tgz#75a3ee5fefb16c99a968545caf1a55611fcbcaa7"
2770+
integrity sha512-TRzBDgrEw/pHAa5iDgPAlhbW3TNYy0zX7bLugokHJKyUlXbm+NH3JEGcOxI2EQAJTplHHRwz4J4ko3m0BCN2pw==
2771+
dependencies:
2772+
"@weapp-core/escape" "^5.0.1"
2773+
class-variance-authority "^0.7.1"
2774+
clsx "^2.1.1"
2775+
local-pkg "^1.1.2"
2776+
semver "^7.7.3"
2777+
tailwind-merge "^3.3.1"
2778+
tailwind-merge-v2 "npm:tailwind-merge@^2.6.0"
2779+
tailwind-variants "^3.1.1"
2780+
27672781
"@weapp-tailwindcss/postcss-calc@^1.0.0":
27682782
version "1.0.0"
27692783
resolved "https://registry.yarnpkg.com/@weapp-tailwindcss/postcss-calc/-/postcss-calc-1.0.0.tgz#8386ea653316580f7b35187601a415004968d144"
@@ -3586,6 +3600,13 @@ citty@^0.1.6:
35863600
dependencies:
35873601
consola "^3.2.3"
35883602

3603+
class-variance-authority@^0.7.1:
3604+
version "0.7.1"
3605+
resolved "https://registry.yarnpkg.com/class-variance-authority/-/class-variance-authority-0.7.1.tgz#4008a798a0e4553a781a57ac5177c9fb5d043787"
3606+
integrity sha512-Ka+9Trutv7G8M6WT6SeiRWz792K5qEqIGEGzXKhAE6xOWAY6pPH8U+9IY3oCMv6kqTmLsv7Xh/2w2RigkePMsg==
3607+
dependencies:
3608+
clsx "^2.1.1"
3609+
35893610
clean-css@4.2.x:
35903611
version "4.2.4"
35913612
resolved "https://registry.npmmirror.com/clean-css/-/clean-css-4.2.4.tgz#733bf46eba4e607c6891ea57c24a989356831178"
@@ -3663,6 +3684,11 @@ clone@^1.0.2:
36633684
resolved "https://registry.npmmirror.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e"
36643685
integrity sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==
36653686

3687+
clsx@^2.1.1:
3688+
version "2.1.1"
3689+
resolved "https://registry.yarnpkg.com/clsx/-/clsx-2.1.1.tgz#eed397c9fd8bd882bfb18deab7102049a2f32999"
3690+
integrity sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==
3691+
36663692
color-convert@^1.9.0:
36673693
version "1.9.3"
36683694
resolved "https://registry.npmmirror.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
@@ -8656,6 +8682,21 @@ svgo@^2.7.0:
86568682
picocolors "^1.0.0"
86578683
stable "^0.1.8"
86588684

8685+
"tailwind-merge-v2@npm:tailwind-merge@^2.6.0":
8686+
version "2.6.0"
8687+
resolved "https://registry.yarnpkg.com/tailwind-merge/-/tailwind-merge-2.6.0.tgz#ac5fb7e227910c038d458f396b7400d93a3142d5"
8688+
integrity sha512-P+Vu1qXfzediirmHOC3xKGAYeZtPcV9g76X+xg2FD4tYgR71ewMA35Y3sCz3zhiN/dwefRpJX0yBcgwi1fXNQA==
8689+
8690+
tailwind-merge@^3.3.1:
8691+
version "3.3.1"
8692+
resolved "https://registry.yarnpkg.com/tailwind-merge/-/tailwind-merge-3.3.1.tgz#a7e7db7c714f6020319e626ecfb7e7dac8393a4b"
8693+
integrity sha512-gBXpgUm/3rp1lMZZrM/w7D8GKqshif0zAymAhbCyIt8KMe+0v9DQ7cdYLR4FHH/cKpdTXb+A/tKKU3eolfsI+g==
8694+
8695+
tailwind-variants@^3.1.1:
8696+
version "3.1.1"
8697+
resolved "https://registry.yarnpkg.com/tailwind-variants/-/tailwind-variants-3.1.1.tgz#40a87a7f24a3c372faecedd23a9c40e40bb2033d"
8698+
integrity sha512-ftLXe3krnqkMHsuBTEmaVUXYovXtPyTK7ckEfDRXS8PBZx0bAUas+A0jYxuKA5b8qg++wvQ3d2MQ7l/xeZxbZQ==
8699+
86598700
tailwindcss-config@^1.1.2:
86608701
version "1.1.2"
86618702
resolved "https://registry.yarnpkg.com/tailwindcss-config/-/tailwindcss-config-1.1.2.tgz#d029449063e5ff2b469a3f67592c661e37148166"

templates/taro-react-tailwind-vscode-template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"@tarojs/taro": "4.1.5",
5555
"clsx": "^2.1.1",
5656
"react": "^18.3.1",
57-
"react-dom": "^18.3.1"
57+
"react-dom": "^18.3.1",
58+
"@weapp-tailwindcss/merge": "^2.0.1"
5859
},
5960
"devDependencies": {
6061
"@babel/core": "^7.28.3",

templates/taro-react-tailwind-vscode-template/pnpm-lock.yaml

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

templates/taro-vite-tailwindcss-v4/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
"@tarojs/shared": "4.1.6",
6262
"@tarojs/taro": "4.1.6",
6363
"react": "^18.0.0",
64-
"react-dom": "^18.0.0"
64+
"react-dom": "^18.0.0",
65+
"@weapp-tailwindcss/merge": "^2.0.1"
6566
},
6667
"devDependencies": {
6768
"@babel/core": "^7.28.3",

0 commit comments

Comments
 (0)