f1f0e78428
Add `built-in-next-font` codemod that transforms `@next/font` imports to `next/font` and then uninstalls the `@next/font` package. Tested locally with npm, yarn and pnpm. Fixes NEXT-453 ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
29 lines
878 B
TypeScript
29 lines
878 B
TypeScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import execa from 'execa'
|
|
|
|
export type PackageManager = 'npm' | 'pnpm' | 'yarn'
|
|
|
|
function getPkgManager(baseDir: string): PackageManager {
|
|
for (const { lockFile, packageManager } of [
|
|
{ lockFile: 'yarn.lock', packageManager: 'yarn' },
|
|
{ lockFile: 'pnpm-lock.yaml', packageManager: 'pnpm' },
|
|
{ lockFile: 'package-lock.json', packageManager: 'npm' },
|
|
]) {
|
|
if (fs.existsSync(path.join(baseDir, lockFile))) {
|
|
return packageManager as PackageManager
|
|
}
|
|
}
|
|
}
|
|
|
|
export function uninstallPackage(packageToUninstall: string) {
|
|
const pkgManager = getPkgManager(process.cwd())
|
|
if (!pkgManager) throw new Error('Failed to find package manager')
|
|
|
|
let command = 'uninstall'
|
|
if (pkgManager === 'yarn') {
|
|
command = 'remove'
|
|
}
|
|
|
|
execa.sync(pkgManager, [command, packageToUninstall], { stdio: 'inherit' })
|
|
}
|