Skip to content

Commit b75419d

Browse files
committed
allow upgrades in pnpm workspace root
When using pnpm with a workspace, if you happen to run the upgrade tool in the root because some Tailwind CSS dependencies live there, then you will get an error that you need the `--workspace-root` flag. However, if we _always_ add it, then the upgrade tool will add dependencies to the root, regardless of whether you are in a sub-packages. With this, the check doesn't happen and no error is thrown. This will just install/bump the dependencies where necessary.
1 parent 4999043 commit b75419d

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

integrations/upgrade/index.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3091,7 +3091,29 @@ test(
30913091
'Running this command will add the dependency to the workspace root',
30923092
)
30933093

3094-
expect(await fs.dumpFiles('./src/**/*.{css,html}')).toMatchInlineSnapshot()
3094+
expect(await fs.dumpFiles('./src/**/*.{css,html}')).toMatchInlineSnapshot(`
3095+
"
3096+
--- ./src/index.html ---
3097+
<!-- Migrating 'ring', 'rounded' and 'outline-none' are unsafe in v4 -> v4 migrations -->
3098+
<div class="ring rounded outline"></div>
3099+
3100+
<!-- Variant order is also unsafe to change in v4 projects -->
3101+
<div class="file:hover:flex *:hover:flex"></div>
3102+
<div class="hover:file:flex hover:*:flex"></div>
3103+
3104+
<!-- These are safe to migrate: -->
3105+
<div
3106+
class="flex! bg-red-500/(--my-opacity) pointer-fine:flex bg-bottom-right object-top-left"
3107+
></div>
3108+
3109+
--- ./src/input.css ---
3110+
@import 'tailwindcss';
3111+
3112+
.foo {
3113+
@apply bg-(--my-color)!;
3114+
}
3115+
"
3116+
`)
30953117
},
30963118
)
30973119

packages/@tailwindcss-upgrade/src/utils/packages.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ export function pkg(base: string) {
3131
args.push(SAVE_DEV[packageManager] || SAVE_DEV.default)
3232
}
3333

34+
// Allow running the `pnpm` command in the workspace root without
35+
// erroring. Can't just use `--workspace-root` because that will force
36+
// install dependencies in the workspace root.
37+
if (packageManager === 'pnpm') {
38+
args.push('--ignore-workspace-root-check')
39+
}
40+
3441
let command = `${packageManager} add ${args.join(' ')}`
3542
try {
3643
return await exec(command, { cwd: base })

0 commit comments

Comments
 (0)