-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Install @tailwindcss/postcss next to tailwindcss
#14830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| return { | ||
| async add(packages: string[], location: 'dependencies' | 'devDependencies' = 'dependencies') { | ||
| let packageManager = await detectPackageManager(base) | ||
| return packageManager.add(packages, location) | ||
| }, | ||
| async remove(packages: string[]) { | ||
| let packageManager = await detectPackageManager(base) | ||
| return packageManager.remove(packages) | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could return the packageManager directly, but then the API usage would look like this:
- pkg(base).add(['@tailwindcss/postcss@next'])
+ pkg(base).then(pm => pm.add(['@tailwindcss/postcss@next']))Which isn't as nice to work with.
We want to install `@tailwindcss/postcss` next to `tailwindcss` (in either `dependencies` or `devDependencies`), so we want to verify that is the case. We also add an explicit test where we have `tailwindcss` in `dependencies` and one in `devDependencies`.
To make sure we are installing in the correct location (`dependencies` vs `devDependencies`) we need to provide some flags to the package manager. In a perfect world the flags used by npm, pnpm, bun and yarn would be the same but that's not the case. This abstraction allows us to use a consistent interface where we can add and remove files and point the location we want.
57a28f9 to
49ed09a
Compare
| class PackageManager { | ||
| constructor(private base: string) {} | ||
|
|
||
| async exec(command: string) { | ||
| return exec(command, { cwd: this.base }) | ||
| } | ||
|
|
||
| async add( | ||
| packages: string[], | ||
| location: 'dependencies' | 'devDependencies', | ||
| ): ReturnType<typeof this.exec> { | ||
| throw new Error('Method not implemented.') | ||
| } | ||
|
|
||
| async remove(packages: string[]): ReturnType<typeof this.exec> { | ||
| throw new Error('Method not implemented.') | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we simplify all this subclassing stuff by just relying on the fact that {packageManager} add {library} -D works to save a dev dependency in npm, pnpm, yarn, and bun?
Then it's more like the old implementation which was a lot less code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess Bun doesn't support -D, sad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep was looking at the documentation for each and there are slight differences. But can still make it smaller and just encode the exceptions. Let me adjust.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamwathan simplified it by just encoding the exception right now: a8f54dd
Co-authored-by: Adam Wathan <[email protected]>
Instead of being explicit, let's just encode the exceptions for now.
thecrypticace
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this simplification is much nicer 👍
This PR improves the PostCSS migrations to make sure that we install
@tailwindcss/postcssin the same bucket astailwindcss.If
tailwindcssexists in thedependenciesbucket, we install@tailwindcss/postcssin the same bucket. Iftailwindcssexists in thedevDependenciesbucket, we install@tailwindcss/postcssin 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.