|
| 1 | +import { execSync } from 'node:child_process' |
| 2 | +import fs from 'node:fs/promises' |
| 3 | +import path from 'node:path' |
| 4 | +import { fileURLToPath } from 'node:url' |
| 5 | + |
| 6 | +const __dirname = fileURLToPath(new URL('.', import.meta.url)) |
| 7 | +const cwd = path.join(__dirname, '..') |
| 8 | + |
| 9 | +let originalLockfile = await fs.readFile(path.join(cwd, '../../pnpm-lock.yaml'), 'utf-8') |
| 10 | + |
| 11 | +console.log('Overwriting dependencies for @tailwindcss/upgrade') |
| 12 | + |
| 13 | +// Apply package patches |
| 14 | +let json = JSON.parse(await fs.readFile('package.json', 'utf-8')) |
| 15 | +json.pnpm = { |
| 16 | + overrides: { |
| 17 | + '@tailwindcss/upgrade>tailwindcss': 'file:../../dist/tailwindcss.tgz', |
| 18 | + '@tailwindcss/upgrade>@tailwindcss/node': 'file:../../dist/tailwindcss-node.tgz', |
| 19 | + }, |
| 20 | +} |
| 21 | +json.devDependencies['@tailwindcss/upgrade'] = 'file:../../dist/tailwindcss-upgrade.tgz' |
| 22 | +await fs.writeFile('package.json', JSON.stringify(json, null, 2)) |
| 23 | + |
| 24 | +try { |
| 25 | + execSync('pnpm install --ignore-workspace', { cwd }) |
| 26 | +} catch (error) { |
| 27 | + console.error(error.stdout?.toString() ?? error) |
| 28 | +} |
| 29 | + |
| 30 | +execSync('npx @tailwindcss/upgrade --force', { cwd, stdio: 'inherit' }) |
| 31 | + |
| 32 | +// Undo package patches |
| 33 | +json = JSON.parse(await fs.readFile('package.json', 'utf-8')) |
| 34 | +delete json.pnpm |
| 35 | +delete json.devDependencies['@tailwindcss/upgrade'] |
| 36 | +await fs.writeFile('package.json', JSON.stringify(json, null, 2)) |
| 37 | + |
| 38 | +// Restore original lockfile (to avoid unnecessary changes in git diff) |
| 39 | +await fs.writeFile(path.join(cwd, '../../pnpm-lock.yaml'), originalLockfile) |
| 40 | +await fs.unlink(path.join(cwd, 'pnpm-lock.yaml')) |
0 commit comments