Install @tailwindcss/postcss next to tailwindcss (#14830)
This PR improves the PostCSS migrations to make sure that we install `@tailwindcss/postcss` in the same bucket as `tailwindcss`. If `tailwindcss` exists in the `dependencies` bucket, we install `@tailwindcss/postcss` in the same bucket. If `tailwindcss` exists in the `devDependencies` bucket, we install `@tailwindcss/postcss` in the same bucket. This also contains an internal refactor that normalizes the package manager to make sure we can install a package to the correct bucket depending on the package manager. --------- Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
This commit is contained in:
parent
840c9e65b9
commit
eb54dcdbfc
6 changed files with 150 additions and 27 deletions
|
|
@ -544,6 +544,100 @@ test(
|
|||
})
|
||||
expect(packageJson.dependencies).not.toHaveProperty('autoprefixer')
|
||||
expect(packageJson.dependencies).not.toHaveProperty('postcss-import')
|
||||
expect(packageJson.dependencies).toMatchObject({
|
||||
'@tailwindcss/postcss': expect.stringContaining('4.0.0'),
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'`@tailwindcss/postcss` should be installed in dependencies when `tailwindcss` exists in dependencies',
|
||||
{
|
||||
fs: {
|
||||
'package.json': json`
|
||||
{
|
||||
"dependencies": {
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3",
|
||||
"@tailwindcss/upgrade": "workspace:^"
|
||||
}
|
||||
}
|
||||
`,
|
||||
'tailwind.config.js': js`
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ['./src/**/*.{html,js}'],
|
||||
}
|
||||
`,
|
||||
'postcss.config.js': js`
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
},
|
||||
}
|
||||
`,
|
||||
'src/index.html': html`
|
||||
<div class="bg-[--my-red]"></div>
|
||||
`,
|
||||
'src/index.css': css`
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
`,
|
||||
},
|
||||
},
|
||||
async ({ fs, exec }) => {
|
||||
await exec('npx @tailwindcss/upgrade')
|
||||
|
||||
let packageJsonContent = await fs.read('package.json')
|
||||
let packageJson = JSON.parse(packageJsonContent)
|
||||
expect(packageJson.dependencies).toMatchObject({
|
||||
'@tailwindcss/postcss': expect.stringContaining('4.0.0'),
|
||||
})
|
||||
},
|
||||
)
|
||||
|
||||
test(
|
||||
'`@tailwindcss/postcss` should be installed in devDependencies when `tailwindcss` exists in dev dependencies',
|
||||
{
|
||||
fs: {
|
||||
'package.json': json`
|
||||
{
|
||||
"devDependencies": {
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3",
|
||||
"@tailwindcss/upgrade": "workspace:^"
|
||||
}
|
||||
}
|
||||
`,
|
||||
'tailwind.config.js': js`
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ['./src/**/*.{html,js}'],
|
||||
}
|
||||
`,
|
||||
'postcss.config.js': js`
|
||||
module.exports = {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
},
|
||||
}
|
||||
`,
|
||||
'src/index.html': html`
|
||||
<div class="bg-[--my-red]"></div>
|
||||
`,
|
||||
'src/index.css': css`
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
`,
|
||||
},
|
||||
},
|
||||
async ({ fs, exec }) => {
|
||||
await exec('npx @tailwindcss/upgrade')
|
||||
|
||||
let packageJsonContent = await fs.read('package.json')
|
||||
let packageJson = JSON.parse(packageJsonContent)
|
||||
expect(packageJson.devDependencies).toMatchObject({
|
||||
'@tailwindcss/postcss': expect.stringContaining('4.0.0'),
|
||||
})
|
||||
|
|
@ -617,7 +711,7 @@ test(
|
|||
})
|
||||
expect(packageJson.dependencies).not.toHaveProperty('autoprefixer')
|
||||
expect(packageJson.dependencies).not.toHaveProperty('postcss-import')
|
||||
expect(packageJson.devDependencies).toMatchObject({
|
||||
expect(packageJson.dependencies).toMatchObject({
|
||||
'@tailwindcss/postcss': expect.stringContaining('4.0.0'),
|
||||
})
|
||||
},
|
||||
|
|
@ -694,7 +788,7 @@ test(
|
|||
})
|
||||
expect(packageJson.dependencies).not.toHaveProperty('autoprefixer')
|
||||
expect(packageJson.dependencies).not.toHaveProperty('postcss-import')
|
||||
expect(packageJson.devDependencies).toMatchObject({
|
||||
expect(packageJson.dependencies).toMatchObject({
|
||||
'@tailwindcss/postcss': expect.stringContaining('4.0.0'),
|
||||
})
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue