-
Notifications
You must be signed in to change notification settings - Fork 13
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
chore(cli): show warning when using deprecated version #102
base: main
Are you sure you want to change the base?
Conversation
packages/aws-cdk/lib/cli/util/npm.ts
Outdated
|
||
export async function checkIfDeprecated(version: string): Promise<string | null> { | ||
try { | ||
const { stdout, stderr } = await exec(`npm view aws-cdk@${version} deprecated --silent`, { timeout: 3000 }); |
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.
Can you work this into the existing version check in some way? (it may be that you will need to change that existing check to return information about more than 1 version at a time).
I'd like to avoid doing unnecessary calls to NPM.
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.
@rix0rrr
It's true that my implementation results in unnecessary NPM calls. But I couldn't find the logic of version check in existing source code. Which logic/file are you referring when you said work this into the existing version check
?
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.
We're doing upgrade notice work here already: https://github.com/aws/aws-cdk-cli/blob/huijbers/install-deps/packages/aws-cdk/lib/cli/version.ts/#L86
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.
@rix0rrr
Do you mean that calling checkIfDeprecated
out of if (laterVersion)
block is better?
Ref: https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/cli/version.ts#L125
try {
const laterVersion = await latestVersionIfHigher(currentVersion, versionCheckCache ?? new VersionCheckTTL());
+ const deprecationMessage = await checkIfDeprecated(currentVersion);
+ if (deprecationMessage) {
+ info(`You are using deprecated version(aws-cdk@${currentVersion}): ${deprecationMessage}`);
+ }
if (laterVersion) {
const versionMessage = await getVersionMessage(currentVersion, laterVersion);
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.
I mean I don't want 2 calls to npm view
. I would like a single call to npm view
to return both bits of information:
- What is the latest version?
- Is the current version deprecated?
It might be that that is not possible, but I would like that to be researched and confirmed first.
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.
It's somewhat possible to get this with a single request:
The downside is that this is a very large response object. Individual versions or latest can be fetched as well:
It might be prudent to change this feature over to use https calls anyway, to be less reliant on the npm
binary. If we download the huge file, we definitely need to cache the result. Making two smaller https requests in parallel migh be faster, not sure. Probably still want to have a cache of sort or at least ensure this isn't checked all the time.
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.
@rix0rrr @mrgrain
Thank you for your advice. I will try to retrieve the latest version and deprecation message in a single npm view
call.
$ npm view aws-cdk@1.204.0 deprecated name --json
{
"deprecated": "AWS CDK v1 has reached End-of-Support on 2023-06-01.\nThis package is no longer being updated, and users should migrate to AWS CDK v2.\n\nFor more information on how to migrate, see https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html",
"name": "aws-cdk"
}
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.
Hm. I don't think this single npm view
call will be able to retrieve both bits of information.
I guess the best solution would be then to do 2 parallel calls to npm view
for both bits of information, and run them in parallel with await Promise.all()
.
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.
Heyyy that's what you did 😆
- Refactored version checking logic to use `execNpmView` for retrieving package metadata - Updated version message generation to handle deprecated versions and upgrade recommendations - Simplified npm utility functions to return parsed JSON from npm view command - Updated tests to mock new npm view behavior and improve test coverage
Head branch was pushed to by a user without write access
packages/aws-cdk/lib/cli/util/npm.ts
Outdated
.catch(err => { | ||
throw new ToolkitError(`Failed to fetch latest version info: ${err.message}`); | ||
}), |
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.
I'm not super up on Promises syntax. Is catch
with a throw
inside the right way to do this?
Where are these errors handled?
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.
Is catch with a throw inside the right way to do this?
It’s not the wrong way in TypeScript, but this implementation is a little confusing. I used a single catch
to handle all thrown exceptions.
packages/aws-cdk/lib/cli/version.ts
Outdated
const latestVersion = await getLatestVersionFromNpm(); | ||
const isNewer = semver.gt(latestVersion, currentVersion); | ||
const packageInfo = await execNpmView(currentVersion); | ||
const latestVersion = packageInfo.latestVersion; | ||
await cacheFile.update(latestVersion); |
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.
I think we should probably stick both fields into the cachefile? Both latestVersion
and deprecated
?
The entire packageInfo
object therefore.
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.
I changed the logic to cache the entire packageInfo
.
if (semver.eq(latestVersion, currentVersion)) { | ||
return []; | ||
} |
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 is only correct if you assume the latest
pointer never points to a deprecated version. If that's something you assume, you should put it in a comment.
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.
I added the comment 👍
packages/aws-cdk/lib/cli/version.ts
Outdated
} | ||
|
||
const versionMessage = [ | ||
`${chalk.red(packageInfo.deprecated as string)}`, |
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.
Will this string ever be empty so that the filter
below removes it? I have a feeling it would contain ANSI escape characters without characters in between? Have you tested?
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.
Exactly. I changed it to check if packageInfo.deprecated
is undefined before calling chalk.red
.
Fixes aws/aws-cdk#298
What I changed
Show the warning message when Toolkit uses deprecated version of aws-cdk. The message is like below.
Additional information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license