Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
LichuAcu committed Sep 18, 2024
1 parent d7f5b3f commit d87a1ef
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
40 changes: 26 additions & 14 deletions packages/next-upgrade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,42 @@

Upgrade Next.js apps to newer or beta versions with one command.

# Build
```bash
npx @next/upgrade
```

## How to use it?

Simply run `npx @next/upgrade` in your project and follow the few prompts. This will let you choose between the latest canary, release candidate or stable version of Next.js.

To build the package locally, go to `packages/next-upgrade` and run:
You can also pass a specific Next.js version as an argument:

```bash
pnpm build && pnpm link --global
npx @next/upgrade 15.0.0-canary.148
```

In your Next.js app, add the following to your `package.json`:
`@next/upgrade` supports `pnpm`, `npm`, `yarn` and `bun`, and is compatible with monorepos.

```json
"dependencies": {
"@next/upgrade": "path/to/local/next.js/packages/next-upgrade"
}
```
## Why?

Finally, run:
Updating Next.js is not just merely running `pnpm update next` or its equivalent in your package manager of choice. It also involves updating `react`, `@types/react`, `react-dom`, `@types/react-dom`, and potentially other dependencies.

We noticed that trying out new or beta versions of Next.js was not as smooth as it could be, so we created this small tool that makes it easier.

## Contributing

To build the package locally, clone the [@vercel/next repo](https://github.com/vercel/next.js/), navigate to `packages/next-upgrade` and run:

```bash
pnpm i
pnpm build
```

Now you can use the package!
To test your local version of `@next/upgrade`, run `pnpm link --global` from the `@next/upgrade` directory and add the following to the `package.json` of your Next.js app:

```bash
npx @next/upgrade
```json
"dependencies": {
"@next/upgrade": "files:path/to/local/next.js/packages/next-upgrade"
}
```

Finally, run `pnpm i` and now you can use your local version of `@next/upgrade` with the standard `npx @next/upgrade` command.
11 changes: 4 additions & 7 deletions packages/next-upgrade/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,6 @@ async function run(): Promise<void> {
stdio: 'inherit',
})

appPackageJson = JSON.parse(fs.readFileSync(appPackageJsonPath, 'utf8'))
appPackageJson.dependencies['next'] = targetVersionSpecifier
fs.writeFileSync(appPackageJsonPath, JSON.stringify(appPackageJson, null, 2))

console.log(
`\n${chalk.green('✔')} Your Next.js project has been upgraded successfully. ${chalk.bold('Time to ship! 🚢')}`
)
Expand Down Expand Up @@ -223,7 +219,8 @@ async function getPackageManager(_packageJson: any): Promise<PackageManager> {
bun: 'bun.lockb',
}

function findLockFile(dir: string): PackageManager[] {
// Recursively looks for either a package.json with a packageManager field or a lock file
function resolvePackageManagerUpwards(dir: string): PackageManager[] {
const packageJsonPath = path.join(dir, 'package.json')
if (fs.existsSync(packageJsonPath)) {
let detectedPackageManagers: PackageManager[] = []
Expand Down Expand Up @@ -251,13 +248,13 @@ async function getPackageManager(_packageJson: any): Promise<PackageManager> {
}
const parentDir = path.dirname(dir)
if (parentDir !== dir) {
return findLockFile(parentDir)
return resolvePackageManagerUpwards(parentDir)
}
return []
}

let realPath = fs.realpathSync(process.cwd())
const detectedPackageManagers = findLockFile(realPath)
const detectedPackageManagers = resolvePackageManagerUpwards(realPath)

// Exactly one package manager detected
if (detectedPackageManagers.length === 1) {
Expand Down

0 comments on commit d87a1ef

Please sign in to comment.