Skip to content

Commit 93bc352

Browse files
committed
test(tailwindcss-patch): resolve local config package in packaged tests
1 parent 769dc3a commit 93bc352

1 file changed

Lines changed: 37 additions & 8 deletions

File tree

packages/tailwindcss-patch/test/packaged-runtime-dependency.test.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
88
const require = createRequire(import.meta.url)
99
const packageDir = path.resolve(__dirname, '..')
1010
const repoRoot = path.resolve(packageDir, '../..')
11+
const configPackageDir = path.resolve(repoRoot, 'packages/config')
1112

1213
let tempDir: string
1314

@@ -35,14 +36,27 @@ function run(command: string, args: string[], cwd: string, timeout = 180_000) {
3536
}
3637
}
3738

38-
async function packTailwindcssPatch() {
39+
async function packPackage(packageDirectory: string) {
3940
const packDir = path.join(tempDir, 'pack')
4041
await fs.mkdir(packDir, { recursive: true })
41-
const output = run('pnpm', ['--dir', packageDir, 'pack', '--json', '--pack-destination', packDir], repoRoot)
42+
const output = run('pnpm', ['--dir', packageDirectory, 'pack', '--json', '--pack-destination', packDir], repoRoot)
4243
const result = JSON.parse(output) as { filename: string }
4344
return result.filename
4445
}
4546

47+
async function packTailwindcssPatch() {
48+
return packPackage(packageDir)
49+
}
50+
51+
async function packConsumerInstallTarballs() {
52+
const configTarball = await packPackage(configPackageDir)
53+
const tailwindcssPatchTarball = await packTailwindcssPatch()
54+
return {
55+
config: configTarball,
56+
tailwindcssPatch: tailwindcssPatchTarball,
57+
}
58+
}
59+
4660
async function createProject(name: string) {
4761
const projectDir = path.join(tempDir, name)
4862
await fs.mkdir(projectDir, { recursive: true })
@@ -58,11 +72,26 @@ async function createProject(name: string) {
5872
return projectDir
5973
}
6074

61-
function installProject(projectDir: string, tarball: string, tailwindVersion: string) {
75+
function installProject(
76+
projectDir: string,
77+
tarballs: { config: string, tailwindcssPatch: string },
78+
tailwindVersion: string,
79+
) {
80+
const packageJsonPath = path.join(projectDir, 'package.json')
81+
const packageJson = JSON.parse(fsSync.readFileSync(packageJsonPath, 'utf8'))
82+
packageJson.pnpm = {
83+
...packageJson.pnpm,
84+
overrides: {
85+
...packageJson.pnpm?.overrides,
86+
'@tailwindcss-mangle/config': `file:${tarballs.config}`,
87+
},
88+
}
89+
fsSync.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf8')
90+
6291
run('pnpm', [
6392
'add',
6493
'--ignore-workspace',
65-
tarball,
94+
tarballs.tailwindcssPatch,
6695
`tailwindcss@${tailwindVersion}`,
6796
], projectDir)
6897
}
@@ -102,9 +131,9 @@ describe('packed tailwindcss-patch runtime dependencies', () => {
102131
})
103132

104133
it('runs source candidate scanning from a clean Tailwind CSS v3.4.19 project without explicitly installing oxide', async () => {
105-
const tarball = await packTailwindcssPatch()
134+
const tarballs = await packConsumerInstallTarballs()
106135
const projectDir = await createProject('tailwind-v3-consumer')
107-
installProject(projectDir, tarball, '3.4.19')
136+
installProject(projectDir, tarballs, '3.4.19')
108137

109138
const result = runProjectScript(projectDir, `
110139
import fs from 'node:fs/promises'
@@ -142,9 +171,9 @@ describe('packed tailwindcss-patch runtime dependencies', () => {
142171
})
143172

144173
it('keeps the Tailwind CSS v4 oxide source scanner path working from a clean project', async () => {
145-
const tarball = await packTailwindcssPatch()
174+
const tarballs = await packConsumerInstallTarballs()
146175
const projectDir = await createProject('tailwind-v4-consumer')
147-
installProject(projectDir, tarball, '4.2.4')
176+
installProject(projectDir, tarballs, '4.2.4')
148177

149178
const result = runProjectScript(projectDir, `
150179
import { createTailwindV4Engine, resolveTailwindV4Source } from 'tailwindcss-patch'

0 commit comments

Comments
 (0)