Unverified Commit a2d8421a authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

next-upgrade: Ensure path-like revisions are rejected (#70980)

`.` and `..` can hit valid API endpoints but are not valid revisions.
Instead of parsing the revision (which may become outdated as we add
dist-tags),
we can continue to let the registry handle that aspect.

## test plan

```bash
$ node ~/packages/next-codemod/bin/next-codemod.js  upgrade .
~/packages/next-codemod/bin/upgrade.js:42
        throw new Error(`${chalk_1.default.yellow(`next@${revision}`)} does not exist. Check available versions at ${chalk_1.default.underline('https://www.npmjs.com/package/next?activeTab=versions')}.`);
              ^

Error: next@. does not exist. Make sure you entered a valid Next.js version or dist-tag. Check available versions at https://www.npmjs.com/package/next?activeTab=versions.

$ node /Users/sebbie/repos/next.js/packages/next-codemod/bin/next-codemod.js  upgrade rc
# still works
```
parent 8ac04d84
...@@ -45,9 +45,15 @@ export async function runUpgrade( ...@@ -45,9 +45,15 @@ export async function runUpgrade(
const res = await fetch(`https://registry.npmjs.org/next/${revision}`) const res = await fetch(`https://registry.npmjs.org/next/${revision}`)
if (res.status === 200) { if (res.status === 200) {
targetNextPackageJson = await res.json() targetNextPackageJson = await res.json()
} else { }
const validRevision =
targetNextPackageJson !== null &&
typeof targetNextPackageJson === 'object' &&
'version' in targetNextPackageJson &&
'peerDependencies' in targetNextPackageJson
if (!validRevision) {
throw new Error( throw new Error(
`${chalk.yellow(`next@${revision}`)} does not exist. Check available versions at ${chalk.underline('https://www.npmjs.com/package/next?activeTab=versions')}.` `${chalk.yellow(`next@${revision}`)} does not exist. Make sure you entered a valid Next.js version or dist-tag. Check available versions at ${chalk.underline('https://www.npmjs.com/package/next?activeTab=versions')}.`
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment