-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correctly find the latest version of create-cloudflare (#4771)
* fix: correctly find the latest version of create-cloudflare When create-cloudflare starts up, it checks to see if the version being run is the latest available on npm. Previously this check used `npm info` to look up the version. But was prone to failing if that command returned additional unexpected output such as warnings. Now we make a fetch request to the npm REST API directly for the latest version, which does not have the problem of unexpected warnings. Since the same approach is used to compute the latest version of workerd, the function to do this has been put into a helper. Fixes #4729 * Log C3 "more info" to console.error rather than console.log The yargs help info is set to error, so this makes it consistent and simpler to spy on in tests.
- Loading branch information
1 parent
6eb2b9d
commit f4f38fc
Showing
7 changed files
with
142 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
"create-cloudflare": patch | ||
--- | ||
|
||
fix: correctly find the latest version of create-cloudflare | ||
|
||
When create-cloudflare starts up, it checks to see if the version being run | ||
is the latest available on npm. | ||
|
||
Previously this check used `npm info` to look up the version. | ||
But was prone to failing if that command returned additional unexpected output | ||
such as warnings. | ||
|
||
Now we make a fetch request to the npm REST API directly for the latest version, | ||
which does not have the problem of unexpected warnings. | ||
|
||
Since the same approach is used to compute the latest version of workerd, the | ||
function to do this has been put into a helper. | ||
|
||
Fixes #4729 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/create-cloudflare/src/helpers/latestPackageVersion.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { fetch } from "undici"; | ||
|
||
type NpmInfoResponse = { | ||
"dist-tags": { latest: string }; | ||
}; | ||
|
||
/** | ||
* Get the latest version of an npm package by making a request to the npm REST API. | ||
*/ | ||
export async function getLatestPackageVersion(packageSpecifier: string) { | ||
const resp = await fetch(`https://registry.npmjs.org/${packageSpecifier}`); | ||
const npmInfo = (await resp.json()) as NpmInfoResponse; | ||
return npmInfo["dist-tags"].latest; | ||
} |