-
Notifications
You must be signed in to change notification settings - Fork 252
fix(migrate): remove scoped Prettier plugins and shareable configs #2557
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,7 +219,48 @@ function deletePrettierConfigFiles( | |
| }); | ||
| } | ||
|
|
||
| function rewritePrettierPackageJson(packageJsonPath: string): void { | ||
| // Bare names of packages whose sole purpose is to support Prettier. | ||
| const PRETTIER_ECOSYSTEM_NAMES = new Set<string>(['prettier']); | ||
|
|
||
| // Flat name prefixes that mark a Prettier-only package. | ||
| const PRETTIER_ECOSYSTEM_PREFIXES = ['prettier-plugin-', 'prettier-config-']; | ||
|
|
||
| // Scopes whose every package is part of the Prettier ecosystem. | ||
| // @prettier/* — official Prettier scope (@prettier/plugin-php, | ||
| // @prettier/plugin-xml, @prettier/plugin-ruby, @prettier/sync) | ||
| const PRETTIER_ECOSYSTEM_SCOPES = ['@prettier/']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a project imports Useful? React with 👍 / 👎. |
||
|
|
||
| /** | ||
| * Decide whether a dependency entry should be removed alongside `prettier` | ||
| * itself, mirroring `isEslintEcosystemDep` in `eslint.ts`. Plugins and | ||
| * shareable configs are dead weight once formatting moves to Oxfmt, and | ||
| * scoped names are as common as flat ones — `@trivago/prettier-plugin-sort-imports` | ||
| * is not less of a Prettier plugin than `prettier-plugin-tailwindcss`. | ||
| * `@types/<X>` packages are checked symmetrically with `<X>`. | ||
| */ | ||
| function isPrettierEcosystemDep(name: string): boolean { | ||
| const stripped = name.startsWith('@types/') ? name.slice('@types/'.length) : name; | ||
| if (PRETTIER_ECOSYSTEM_NAMES.has(stripped)) { | ||
| return true; | ||
| } | ||
| if (PRETTIER_ECOSYSTEM_PREFIXES.some((p) => stripped.startsWith(p))) { | ||
| return true; | ||
| } | ||
| if (PRETTIER_ECOSYSTEM_SCOPES.some((s) => stripped.startsWith(s))) { | ||
| return true; | ||
| } | ||
| // Scoped plugins/configs, e.g.: | ||
| // @trivago/prettier-plugin-sort-imports | ||
| // @ianvs/prettier-plugin-sort-imports | ||
| // @shopify/prettier-plugin-liquid | ||
| // @company/prettier-config | ||
| if (/^@[^/]+\/prettier-(plugin|config)(-.+)?$/.test(stripped)) { | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| export function rewritePrettierPackageJson(packageJsonPath: string): void { | ||
| if (!fs.existsSync(packageJsonPath)) { | ||
| return; | ||
| } | ||
|
|
@@ -230,18 +271,18 @@ function rewritePrettierPackageJson(packageJsonPath: string): void { | |
| 'lint-staged'?: Record<string, string | string[]>; | ||
| }>(packageJsonPath, (pkg) => { | ||
| let changed = false; | ||
| // Remove prettier and prettier-plugin-* dependencies | ||
| // Remove prettier and its plugins / shareable configs | ||
| if (pkg.devDependencies) { | ||
| for (const dep of Object.keys(pkg.devDependencies)) { | ||
| if (dep === 'prettier' || dep.startsWith('prettier-plugin-')) { | ||
| if (isPrettierEcosystemDep(dep)) { | ||
| delete pkg.devDependencies[dep]; | ||
| changed = true; | ||
| } | ||
| } | ||
| } | ||
| if (pkg.dependencies) { | ||
| for (const dep of Object.keys(pkg.dependencies)) { | ||
| if (dep === 'prettier' || dep.startsWith('prettier-plugin-')) { | ||
| if (isPrettierEcosystemDep(dep)) { | ||
| delete pkg.dependencies[dep]; | ||
| changed = true; | ||
| } | ||
|
|
||
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.
This expands destructive manifest rewriting to
prettier-config-*, scoped plugin/config packages, and the entire@prettier/*scope, but the documented migration contract was not updated:rfcs/migration-command.mdstep 4 still promises removal only ofprettierand unscopedprettier-plugin-*, while the canonicaldocs/guide/migrate-rules.mddoes not describe these additional removals. Update the migration documentation so users reviewing generated manifest changes can predict the new cleanup.AGENTS.md reference: AGENTS.md:L66-L67
Useful? React with 👍 / 👎.